void OpenURL( LPCTSTR szURL ) { CWaitCursor wait; /* TCHAR key[MAX_PATH + MAX_PATH]; if (GetRegKey(HKEY_CLASSES_ROOT, _T(".htm"), key) == ERROR_SUCCESS) { lstrcat(key, _T("\\shell\\open\\command")); if (GetRegKey(HKEY_CLASSES_ROOT,key,key) == ERROR_SUCCESS) { TCHAR *pos; pos = _tcsstr(key, _T("\"%1\"")); if (pos == NULL) { // No quotes found pos = _tcsstr(key, _T("%1")); // Check for %1, without quotes if (pos == NULL) // No parameter at all... pos = key+_tcslen(key)-1; else *pos = _T('\0'); // Remove the parameter } else *pos = _T('\0'); // Remove the parameter lstrcat(pos, _T(" ")); lstrcat(pos, szURL); if (WinExec(key, SW_SHOW) >= HINSTANCE_ERROR) //all ok return; } } */ if ( int(ShellExecute (NULL, _T ("open"), szURL, NULL, NULL, SW_SHOW)) < HINSTANCE_ERROR ) { CString szText; szText.Format ("Failed to invoke URL: %s\n", szURL); MsgBoxEx ( NULL, szText ); } }
// Download thread void ViDownloadThread(THREAD *thread, void *param) { VI_INSTALL_DLG *d; VI_SETTING_ARCH *a; HWND hWnd; UINT num_files = 2; VI_DOWNLOAD_FILE files[2]; VI_DOWNLOAD_FILE *f; UINT i; // Validate arguments if (thread == NULL || param == NULL) { return; } d = (VI_INSTALL_DLG *)param; hWnd = d->hWnd; Zero(files, sizeof(files)); a = ViGetSuitableArchForCpu(); // File body f = &files[0]; StrCpy(f->SrcPath, sizeof(f->SrcPath), a->Path); // Configuration file if (IsEmptyStr(setting.SettingPath) == false) { f = &files[1]; StrCpy(f->SrcPath, sizeof(f->SrcPath), setting.SettingPath); } else { // No configuration file num_files = 1; } for (i = 0;i < num_files;i++) { bool b = true; if (i == 0 && setting.DownloadNotRequired) { b = false; } if (b) { wchar_t tmp[MAX_SIZE]; IO *dest = NULL; VI_FILE *down; UINT ret; UINT totalsize; UINT currentsize; wchar_t filename_w[MAX_PATH]; f = &files[i]; GetFileNameFromFilePath(f->FileName, sizeof(f->FileName), f->SrcPath); MakeSafeFileName(f->FileName, sizeof(f->FileName), f->FileName); StrToUni(filename_w, sizeof(filename_w), f->FileName); ConbinePathW(f->DestPathW, sizeof(f->DestPathW), MsGetMyTempDirW(), filename_w); ViInstallDlgSetPos(hWnd, 0); UniFormat(tmp, sizeof(tmp), _U(IDS_DOWNLOADSTART+skip), f->FileName); ViInstallDlgSetText(d, hWnd, S_STATUS, tmp); down = ViOpenFile(f->SrcPath); if (down == NULL) { MsgBoxEx(hWnd, MB_ICONSTOP, _U(IDS_DOWNLOAD_ERROR+skip), f->FileName); ViInstallDlgCancel(hWnd); return; } dest = FileCreateW(f->DestPathW); if (dest == NULL) { MsgBoxEx(hWnd, MB_ICONSTOP, _U(IDS_TEMP_ERROR+skip), f->DestPathW); ViCloseFile(down); ViInstallDlgCancel(hWnd); return; } totalsize = ViGetFileSize(down); currentsize = 0; UniFormat(tmp, sizeof(tmp), _U(IDS_DOWNLOADING3+skip), f->FileName); ViInstallDlgSetText(d, hWnd, S_STATUS, tmp); while (true) { UINT pos = 0; if (d->Halt) { // User cancel FileClose(dest); ViCloseFile(down); return; } UniFormat(tmp, sizeof(tmp), _U(IDS_DOWNLOADING3+skip), f->FileName); ViInstallDlgSetText(d, hWnd, IDS_DOWNLOADING3+skip, tmp); ret = ViReadFile(down, d->Buf, d->BufSize); if (ret == INFINITE) { // Communication error MsgBoxEx(hWnd, MB_ICONSTOP, _U(IDS_DOWNLOAD_ERROR+skip), f->FileName); FileClose(dest); ViCloseFile(down); ViInstallDlgCancel(hWnd); return; } // Draw progress currentsize += ret; if (totalsize != 0) { UniFormat(tmp, sizeof(tmp), _U(IDS_DOWNLOADING+skip), ((float)totalsize) / 1024.0f / 1024.0f, ((float)currentsize) / 1024.0f / 1024.0f); pos = (UINT)(((float)currentsize) * 100.0f / ((float)totalsize)); } else { UniFormat(tmp, sizeof(tmp), _U(IDS_DOWNLOADING2+skip), ((float)currentsize) / 1024.0f / 1024.0f); pos = (UINT)(((float)currentsize) * 100.0f / (1024.0f * 1024.0f * 10.0f)); } ViInstallDlgSetText(d, hWnd, S_SIZEINFO, tmp); ViInstallDlgSetPos(hWnd, pos); if (ret == 0) { // Download Complete break; } else { FileWrite(dest, d->Buf, ret); } } ViCloseFile(down); FileClose(dest); } } UniStrCpy(setting.DownloadedInstallerPathW, sizeof(setting.DownloadedInstallerPathW), files[0].DestPathW); if (num_files >= 2) { UniStrCpy(setting.DownloadedSettingPathW, sizeof(setting.DownloadedSettingPathW), files[1].DestPathW); } PostMessageA(hWnd, WM_VI_DOWNLOAD_FINISHED, 0, 0); }
// Main process void ViMain() { char tmp[MAX_PATH]; UINT ostype = GetOsInfo()->OsType; VI_SETTING_ARCH *suitable; TOKEN_LIST *t; UINT i; if (OS_IS_WINDOWS_NT(ostype) == false || GET_KETA(ostype, 100) <= 1) { // The OS is too old MsgBox(NULL, MB_ICONEXCLAMATION, _U(IDS_BAD_OS+skip)); return; } Zero(&setting, sizeof(setting)); // Read the inf file Format(tmp, sizeof(tmp), "%s\\%s", MsGetExeDirName(), VI_INF_FILENAME); if (ViLoadInf(&setting, tmp) == false) { // Failure MsgBoxEx(NULL, MB_ICONSTOP, _U(IDS_INF_LOAD_FAILED+skip), VI_INF_FILENAME); return; } ViSetSkip(); // Parse the command line options t = GetCommandLineToken(); for (i = 0;i < t->NumTokens;i++) { char *s = t->Token[i]; if (IsEmptyStr(s) == false) { if (StartWith(s, "/") || StartWith(s, "-")) { if (StrCmpi(&s[1], "web") == 0) { setting.WebMode = true; } } else { StrCpy(setting.SettingPath, sizeof(setting.SettingPath), s); } } } FreeToken(t); suitable = ViGetSuitableArchForCpu(); // Security check if (setting.WebMode) { bool ok = true; if (ViIsInternetFile(suitable->Path) == false) { ok = false; } if (IsEmptyStr(setting.SettingPath) == false) { if (ViIsInternetFile(setting.SettingPath) == false) { ok = false; } } if (ok == false) { // Security breach MsgBox(NULL, MB_ICONEXCLAMATION, _U(IDS_SECURITY_ERROR+skip)); return; } } // Get the current installation state ViLoadCurrentInstalledStates(); if (suitable->Supported == false) { // This CPU isn't supported MsgBox(NULL, MB_ICONEXCLAMATION, _U(IDS_CPU_NOT_SUPPORTED+skip)); return; } if (suitable->CurrentInstalled && suitable->Build <= suitable->CurrentInstalledBuild) { // Do not download client software since it has already been installed setting.DownloadNotRequired = true; } // Show the dialog ViInstallDlg(); }
bool SendMail (MapiMessage *pNote, HWND hWnd, bool bAddSysInfoToBody, const SendMailProdInfo *pProdInfo) { if (pNote == NULL) return false; TCHAR szBuffer[MAX_PATH]; LPTSTR lpFileStart; if (!SearchPath (NULL, SEND_MAIL_EXE_NAME, NULL, sizeof(szBuffer) / sizeof(szBuffer[0]), szBuffer, &lpFileStart)) { CString szMsg; szMsg.Format (IDS_COMMON_CANNOT_FIND_KAVSEND, SEND_MAIL_EXE_NAME); MsgBoxEx(hWnd, (LPCTSTR)szMsg, NULL, MB_OK | MB_ICONERROR); return false; } #ifndef _DEBUG if ( sign_check_file (szBuffer, 1, 0, 0, 0) != SIGN_OK ) { CString szMsg; szMsg.Format (IDS_COMMON_KAVSEND_CORRUPTED, szBuffer); MsgBoxEx(hWnd, (LPCTSTR)szMsg, NULL, MB_OK | MB_ICONERROR); return false; } #endif std::string szFullPath; if ( !GetAutoDelTempFileName( szFullPath ) ) { MsgBoxEx(hWnd, IDS_COMMON_CANNOT_SEND_MAIL, -1, MB_OK | MB_ICONERROR); return false; } CFileStorage fs; if ( !fs.attach_(szFullPath.c_str (), false) ) { MsgBoxEx(hWnd, IDS_COMMON_CANNOT_SEND_MAIL, -1, MB_OK | MB_ICONERROR); return false; } std::basic_string<TCHAR> szModulePath = szBuffer; STARTUPINFO si={sizeof(STARTUPINFO)}; PROCESS_INFORMATION pi={0}; std::basic_string<TCHAR> szwCommandLine = (_T("\"") + szModulePath + _T("\" \"")+ szFullPath + _T("\"")); if(::CreateProcess( NULL, (LPTSTR)(szwCommandLine.c_str()), NULL, NULL, FALSE, CREATE_DEFAULT_ERROR_MODE | CREATE_SUSPENDED, NULL, NULL, &si, &pi)) { std::string strBody (pNote->lpszNoteText); LPSTR lpszOldNoteText = pNote->lpszNoteText; if (pProdInfo) { strBody += "\n\n"; strBody += GetProdInfo (pProdInfo); } if (bAddSysInfoToBody) { strBody += "\n\n"; strBody += KLUTIL::GetSysInfo (); pNote->lpszNoteText = (LPSTR)strBody.c_str (); } MapiMessageSer ser = *pNote; DWORD dwMagic = MAPI_SERIALIZE_FILE_MAGIC_NUMBER; std::string strErr; if ( ser.CopyAttaches(strErr) ) { fs.write_ (&dwMagic, 4); dwMagic = MAPI_SEND; fs.write_ (&dwMagic, 4); PoliType pt (fs, false); pt<<ser; } else { fs.write_ (&dwMagic, 4); dwMagic = MAPI_DONTPROCESS; fs.write_ (&dwMagic, 4); CString szErrMsg; szErrMsg.Format ( IDS_COMMON_CANNOT_FIND_ATTACH, strErr.c_str () ); MsgBoxEx(hWnd, (LPCTSTR)szErrMsg, NULL, MB_OK | MB_ICONERROR); } pNote->lpszNoteText = lpszOldNoteText; fs.detach_ (); if ( ResumeThread (pi.hThread) == -1 ) { DeleteFile( szFullPath.c_str() ); ser.DeleteIfCopied(); TerminateProcess(pi.hProcess, 0); MsgBoxEx(hWnd, IDS_COMMON_CANNOT_SEND_MAIL, -1, MB_OK | MB_ICONERROR); } else { CloseHandle(pi.hThread); CloseHandle(pi.hProcess); } return true; } else { fs.detach_ (); DeleteFile( szFullPath.c_str() ); return false; } }