// WebUpdate.cpp : implementation file // #include "stdafx.h" #include "udpadmintool.h" #include "WebUpdate.h" #include #include "util.hpp" #include "util_path.hpp" #include "util_local.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CWebUpdate dialog CWebUpdate::CWebUpdate(CWnd* pParent /*=NULL*/) : CDialog(CWebUpdate::IDD, pParent) { //{{AFX_DATA_INIT(CWebUpdate) m_edSelectIP = _T(""); //}}AFX_DATA_INIT } void CWebUpdate::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CWebUpdate) DDX_Text(pDX, IDC_EDIT_SELECT_IP, m_edSelectIP); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CWebUpdate, CDialog) //{{AFX_MSG_MAP(CWebUpdate) ON_BN_CLICKED(IDC_BUTTON_BROWSE, OnButtonBrowse) ON_BN_CLICKED(IDC_BUTTON_UPDATE, OnButtonUpdate) ON_BN_CLICKED(IDC_BUTTON_BACKUP, OnButtonBackup) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CWebUpdate message handlers void CWebUpdate::OnButtonBrowse() { // TODO: Add your control notification handler code here BROWSEINFO bi; ZeroMemory(&bi, sizeof(bi)); TCHAR szDisplayName[MAX_PATH]; szDisplayName[0] = '\0'; bi.hwndOwner = NULL; bi.pidlRoot = NULL; bi.pszDisplayName = szDisplayName; bi.lpszTitle = TEXT("Æú´õ¸¦ ¼±ÅÃÇÏ¿© ÁÖ¼¼¿ä."); // bi.ulFlags = BIF_EDITBOX | BIF_VALIDATE ; bi.ulFlags = BIF_VALIDATE ; #ifndef SHOW_PROBLEM bi.lpfn = BrowseCallbackProc; #endif bi.lParam = (LPARAM)(LPSTR)(LPCTSTR)m_sFilePath; //À̺κÐÀÌ Ã³À½ Æú´õ¼±Åà ´ëÈ­»óÀÚ°¡ ÃʱâÈ­µÉ¶§ //¼±ÅõǴ Æú´õ¸íÀ» ³Ñ°ÜÁØ´Ù. bi.iImage = 0; // do LPITEMIDLIST pidl = SHBrowseForFolder(&bi); // result TCHAR szPath[MAX_PATH] = {0}; if(NULL != pidl) SHGetPathFromIDList(pidl, szPath); if(strlen(szPath) < 1) return; sprintf(m_sFilePath, "%s", szPath); GetDlgItem(IDC_EDIT_BROWSE)->SetWindowText(m_sFilePath); m_bFile = TRUE; theApp.set_web_path(m_sFilePath); // registry } void CWebUpdate::EnableControl(BOOL bEnable) { GetDlgItem(IDC_BUTTON_UPDATE)->EnableWindow(bEnable); GetDlgItem(IDC_BUTTON_BACKUP)->EnableWindow(bEnable); GetDlgItem(IDOK)->EnableWindow(bEnable); } int CALLBACK CWebUpdate::BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM dwData) { CWebUpdate* PDlg = (CWebUpdate *)AfxGetMainWnd(); TCHAR* szDir; TCHAR szText[MAX_PATH] = {0}; CString str; szDir = (TCHAR * )(LPSTR)(LPCTSTR) dwData; //dwData´Â ÄݹéÇÔ¼ö È£Ãâ½Ã LPARAMÀ¸·Î ³Ñ°ÜÁִ ƯÁ¤ µð·ºÆ®·Î Æнº ÀÔ´Ï´Ù. // ÀÌ ÀÎÀÚ¸¦ ÀÌ¿ëÇؼ­ Æú´õÁöÁ¤ÇÏ´Â ´ëÈ­»óÀÚ°¡ óÀ½ ÃʱâÈ­ µÉ¶§ //³Ñ°ÜÁØ ÀÎÀÚÀÇ Æú´õ°¡ ¼±ÅõǾîÁö°Ô ÇÕ´Ï´Ù. switch(uMsg) { case BFFM_INITIALIZED: ::SendMessage(hwnd, BFFM_SETSELECTION, TRUE, (LPARAM)szDir); //´ëÈ­»óÀÚ°¡ ÃʱâÈ­ µÉ¶§ szDir Æú´õ¸¦ ¼±ÅÃÇÏ°Ô ÇØÁØ´Ù. break; case BFFM_SELCHANGED: SHGetPathFromIDList(reinterpret_cast(lParam), szText); ::SendMessage(hwnd, BFFM_SETSTATUSTEXT, 0, reinterpret_cast(szText)); break; case BFFM_VALIDATEFAILED: str.Format("\"%s\" Æú´õ °æ·Î´Â À߸øµÇ¾ú½À´Ï´Ù.", reinterpret_cast(lParam)); AfxMessageBox(str); return 1; } return 0; } void CWebUpdate::OnButtonUpdate() { // TODO: Add your control notification handler code here //char filePath[512]; EnableControl(FALSE); //memset(filePath, 0x00, sizeof(filePath)); int hr = AfxMessageBox( //"You need to press 'OK' for Update Web Page(When updating, the old file will be deleted),\n otherwise press ¡°cancel¡±", "Press OK to update webpage and press Cancel to close the dialog. While updating, older files will be deleted.", //- cjy, 07_0810 09:59 MB_ICONEXCLAMATION|MB_OKCANCEL); if(hr == 1) { //GetCurrentDirectory(MAX_PATH, filePath); CString progPath = path_program(); // check folder exists int attr = GetFileAttributes(m_sFilePath); if(attr == -1) { CString msg; msg.Format("Entered path is invalid\n[%s]", m_sFilePath); AfxMessageBox(msg); goto EXIT; } else { if(!(attr & FILE_ATTRIBUTE_DIRECTORY)) { CString msg; msg.Format("Entered path is not directory\n[%s]", m_sFilePath); AfxMessageBox(msg); goto EXIT; } } _chdir(m_sFilePath); CString tarPath; tarPath.Format("%s\\www.tar", progPath); char command[512]; memset(command, 0x00, sizeof(command)); // sprintf(command, "\"%s\\tar\" cvf \"%s\" .", progPath, tarPath); sprintf(command, "\"%s\\tar.exe\"", progPath); char arg[512]; memset(arg, 0, sizeof(arg)); sprintf(arg, " cvf \"%s\" .", tarPath); // change unix path sep int i; //for(i=0; i<100; i++) //{ // if(command[i] == 92) // command[i] = '/'; //} for(i=0; i<100; i++) { if(arg[i] == 92) arg[i] = '/'; } strcat(command, arg); //int hr = WinExec(command, SW_HIDE); //Sleep(8000); // 5 -> 8 sec - cjy, 07_1011 16:32 //int hr = system(command); //sprintf(command, "%s\\www.tar", progPath); // Execute tar.exe for compress webpage files - cjy, 07_1011 18:29 //_chdir(progPath); PROCESS_INFORMATION pi; STARTUPINFO startInfo; // // child process // startInfo.cb = sizeof(STARTUPINFO); startInfo.lpReserved = NULL; startInfo.lpTitle = ""; startInfo.lpDesktop = NULL; startInfo.dwX = 0; startInfo.dwY = 0; startInfo.dwXSize = 0; startInfo.dwYSize = 0; startInfo.dwXCountChars = 0; startInfo.dwYCountChars = 0; startInfo.dwFlags = STARTF_USESTDHANDLES; startInfo.wShowWindow = 0; //SW_SHOWDEFAULT; startInfo.lpReserved2 = NULL; startInfo.cbReserved2 = 0; startInfo.hStdInput = GetStdHandle(STD_INPUT_HANDLE); startInfo.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE); startInfo.hStdError = GetStdHandle(STD_ERROR_HANDLE); BOOL bb = CreateProcess(NULL, command, NULL, NULL, FALSE, CREATE_NO_WINDOW, NULL, NULL, &startInfo, &pi); if(WaitForSingleObject(pi.hProcess, INFINITE) == WAIT_FAILED) { printf("WaitForSingleObject FAILED: err=%d\n", GetLastError()); return; } CloseHandle(pi.hProcess); CloseHandle(pi.hThread); int nn = UpGrade(theApp.m_info.sIp, tarPath, 0x70); // remove www.tar file -- cjy 07_0822 DeleteFile(tarPath); if(nn > 0) { AfxMessageBox("Uploading webpage completed"); } else { // > 0 : success // -1 : socket open error // < -10 - filesend()ÇÔ¼ö·Î ºÎÅÍ ¿À·ù // -11 : filenameÀÌ Á¸ÀçÇÏÁö ¾ÊÀ½ // -12 : can't send header packet // -13 : can't read file data // -14 : can't send data to socket // -15 : don't response from device(socket) // -16 : device response was fail(0x00) // -17 : device response was fail(0xff) // < -20 - FileBackup()ÇÔ¼ö ¿À·ù CString msg; msg.Format("UpdateData Fail... [ErrNo:%d]", nn); AfxMessageBox(msg); } } EXIT: EnableControl(TRUE); } void CWebUpdate::OnButtonBackup() { // TODO: Add your control notification handler code here unsigned long newTime; EnableControl(FALSE); CTime nTime; nTime = CTime::GetCurrentTime(); newTime = nTime.GetMinute(); #if 0 char name[1024]; // ÇöÀç µð·ºÅ丮¿¡ ÀúÀå GetCurrentDirectory(_MAX_PATH, name); // _chdir(filePath); char filePath[1024]; sprintf(filePath, "%s\\backup%02d.tar", name, newTime); #else // ½ÇÇàÆÄÀÏ °æ·Î¿¡ ÀúÀåÇϵµ·Ï... CString base = path_program2("backup"); CString extract = path_append(base, "extract"); // check folder exists? CreateDirectory(base, NULL); char filePath[1024]; sprintf(filePath, "%s\\backup%02d.tar", base, newTime); #endif // sprintf(filePath, "%s\\%s.tar", filePath, theApp.cinfo[theApp.m_iListNum[theApp.m_iNowDevice]].wwwroot); int nn = UpGrade(theApp.m_info.sIp, filePath, 0x80); if(nn > 0) { // program/backupÆú´õ¿¡ ÀúÀåµÊ // ½ÇÇà ÆÄÀÏ °æ·Î¿¡ ÀÖ´Â boawwwÆÄÀÏ Æú´õÁ¦°Å Çϱâ? DeleteDir(extract); // ¾ÐÃàǬ´Ù. program/backup/extract CreateDirectory(extract, NULL); // tar.exeÆÄÀÏÀÌ ÀÖ´ÂÁö üũ _chdir(base); sprintf(filePath, "..\\tar xvf backup%02d.tar -C extract", newTime); WinExec(filePath, SW_HIDE); Sleep(5); // system(filePath); AfxMessageBox("Backup webpage completed"); #if 1 int hr = AfxMessageBox("Do you want to open backup folder?", MB_YESNO|MB_ICONQUESTION, 0); if(hr == IDYES) { ShellExecute(NULL, NULL, extract, NULL, NULL, SW_SHOW); } #endif } else { CString msg; msg.Format("UpdateData Fail...(check \"TAR.exe\" File or Web File) [ErrNo:%d]", nn); AfxMessageBox(msg); } EnableControl(TRUE); } BOOL CWebUpdate::OnInitDialog() { CDialog::OnInitDialog(); // TODO: Add extra initialization here int i, flag=0; char temp[5]; memset(temp, 0x00, sizeof(temp)); // ui UpdateData(); m_edSelectIP = theApp.GetSelectDeviceName(); UpdateData(FALSE); // check firmware support for(i = 0; i < 50; i++) { if(theApp.m_info.FirmwareVersion[i] == '.') { flag++; if(flag == 2) { memcpy(temp, &theApp.m_info.FirmwareVersion[i+1], 3); if(atoi(temp) < 326) { AfxMessageBox("This firmware does not support \"Webpage upload\" function."); OnOK(); } break; } } } if(i > 45) { AfxMessageBox("This firmware does not support \"Webpage upload\" function."); OnOK(); } //GetCurrentDirectory(_MAX_PATH, m_sFilePath); strcpy(m_sFilePath, theApp.get_web_path()); // registry GetDlgItem(IDC_EDIT_BROWSE)->SetWindowText(m_sFilePath); if(theApp.m_info.wwwroot[0] == '(') GetDlgItem(IDC_EDIT_WWWROOT)->SetWindowText("/boawww"); else GetDlgItem(IDC_EDIT_WWWROOT)->SetWindowText(theApp.m_info.wwwroot); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } BOOL CWebUpdate::PreTranslateMessage(MSG* pMsg) { // TODO: Add your specialized code here and/or call the base class if(pMsg->wParam == VK_RETURN) { return TRUE; } return CDialog::PreTranslateMessage(pMsg); }