From 8f5a7b54eb953bbfc877ec915e26b3a95ec28d00 Mon Sep 17 00:00:00 2001 From: "(no author)" <(no author)@4f64403b-2f21-0410-a795-97e2b3489a10> Date: Sun, 21 Feb 2010 23:00:56 +0000 Subject: New updater with 3x reduced footprint and fully W7 and x64 compatible git-svn-id: https://server.scottellis.com.au/svn/mim_plugs@476 4f64403b-2f21-0410-a795-97e2b3489a10 --- updater/extern.cpp | 59 +++++++++++++++++++++++++----------------------------- 1 file changed, 27 insertions(+), 32 deletions(-) (limited to 'updater/extern.cpp') diff --git a/updater/extern.cpp b/updater/extern.cpp index eaaeb36..68b572a 100644 --- a/updater/extern.cpp +++ b/updater/extern.cpp @@ -52,30 +52,30 @@ int ExternProcess(bool restart) { char *nl = "\r\n"; TCHAR *tnl = _T("\r\n"); char buf[64]; - WriteFile(hDatFile, mir_exe, _tcslen(mir_exe) * sizeof(TCHAR), &bytes_written, FALSE); + WriteFile(hDatFile, mir_exe, (unsigned)_tcslen(mir_exe) * sizeof(TCHAR), &bytes_written, FALSE); WriteFile(hDatFile, tnl, 2 * sizeof(TCHAR), &bytes_written, FALSE); - WriteFile(hDatFile, plugins_folder, _tcslen(plugins_folder) * sizeof(TCHAR), &bytes_written, FALSE); + WriteFile(hDatFile, plugins_folder, (unsigned)_tcslen(plugins_folder) * sizeof(TCHAR), &bytes_written, FALSE); WriteFile(hDatFile, tnl, 2 * sizeof(TCHAR), &bytes_written, FALSE); - WriteFile(hDatFile, db_name, strlen(db_name), &bytes_written, FALSE); + WriteFile(hDatFile, db_name, (unsigned)strlen(db_name), &bytes_written, FALSE); WriteFile(hDatFile, nl, 2, &bytes_written, FALSE); - WriteFile(hDatFile, db_path, strlen(db_path), &bytes_written, FALSE); + WriteFile(hDatFile, db_path, (unsigned)strlen(db_path), &bytes_written, FALSE); WriteFile(hDatFile, nl, 2, &bytes_written, FALSE); - WriteFile(hDatFile, options.temp_folder, _tcslen(options.temp_folder) * sizeof(TCHAR), &bytes_written, FALSE); + WriteFile(hDatFile, options.temp_folder, (unsigned)_tcslen(options.temp_folder) * sizeof(TCHAR), &bytes_written, FALSE); WriteFile(hDatFile, tnl, 2 * sizeof(TCHAR), &bytes_written, FALSE); if(options.backup) { - WriteFile(hDatFile, options.backup_folder, _tcslen(options.backup_folder) * sizeof(TCHAR), &bytes_written, FALSE); + WriteFile(hDatFile, options.backup_folder, (unsigned)_tcslen(options.backup_folder) * sizeof(TCHAR), &bytes_written, FALSE); WriteFile(hDatFile, tnl, 2 * sizeof(TCHAR), &bytes_written, FALSE); } else { - WriteFile(hDatFile, _T("no backups"), _tcslen(_T("no backups")) * sizeof(TCHAR), &bytes_written, FALSE); + WriteFile(hDatFile, _T("no backups"),(unsigned) _tcslen(_T("no backups")) * sizeof(TCHAR), &bytes_written, FALSE); WriteFile(hDatFile, tnl, 2 * sizeof(TCHAR), &bytes_written, FALSE); } sprintf(buf, "%d", (unsigned int)GetCurrentProcessId()); //MessageBox(0, buf, "Writing process id", MB_OK); - WriteFile(hDatFile, buf, strlen(buf), &bytes_written, FALSE); + WriteFile(hDatFile, buf, (unsigned)strlen(buf), &bytes_written, FALSE); WriteFile(hDatFile, nl, 2, &bytes_written, FALSE); sprintf(buf, (restart ? "restart" : "no_restart")); - WriteFile(hDatFile, buf, strlen(buf), &bytes_written, FALSE); + WriteFile(hDatFile, buf, (unsigned)strlen(buf), &bytes_written, FALSE); WriteFile(hDatFile, nl, 2, &bytes_written, FALSE); CloseHandle(hDatFile); @@ -119,38 +119,32 @@ int ExternProcess(bool restart) { GetModuleFileName(hInst, szBuf, MAX_PATH); } - p = _tcsrchr(szBuf, _T('\\')); - if(p) *p = 0; +// p = _tcsrchr(szBuf, _T('\\')); +// if (p) *p = 0; // rundll32 hates spaces in the arg, but quotes aren't allowed in earlier versions... // GetShortPath can return paths with spaces (at least on XP with 8.3 filenames disabled)... // so we must 'CreateProcess' with the updater.dll location as the startup directory and pass only updater.dll as the arg -#ifdef _MSC_VER - // MSVC exports differently than gcc/mingw - _stprintf(szParams, _T("RUNDLL32.EXE .\\updater.dll,_ExternalUpdate@16 %s"), data_filename); -#else - _stprintf(szParams, _T("RUNDLL32.EXE .\\updater.dll,ExternalUpdate@16 %s"), data_filename); -#endif + mir_sntprintf(szParams, SIZEOF(szParams), _T("RUNDLL32.EXE \"%s\",ExternalUpdate %s"), szBuf, data_filename); PROCESS_INFORMATION pi = {0}; STARTUPINFO si = {0}; si.cb = sizeof(si); if(!CreateProcess(0, szParams, 0, 0, 0, - CREATE_NO_WINDOW|DETACHED_PROCESS|NORMAL_PRIORITY_CLASS, - 0, szBuf, &si, &pi)) + CREATE_NO_WINDOW | DETACHED_PROCESS | NORMAL_PRIORITY_CLASS, + 0, NULL, &si, &pi)) { int err = GetLastError(); TCHAR msg[256]; - _stprintf(msg, _T("Error code: %d"), err); + mir_sntprintf(msg, SIZEOF(msg), _T("Error code: %d"), err); MessageBox(0, msg, TranslateT("CreateProcess"), MB_OK | MB_ICONERROR); return 1; } else { - //PostMessage(hWndMiranda, WM_DESTROY, 0, 0); - //PostThreadMessage(mainThreadId, WM_QUIT, 0, 0); - //PostThreadMessage(mainThreadId, WM_COMMAND, ID_ICQ_EXIT, 0); + CloseHandle(pi.hThread); + CloseHandle(pi.hProcess); PostMessage((HWND)CallService(MS_CLUI_GETHWND, 0, 0), WM_COMMAND, ID_ICQ_EXIT, 0); return 0; } @@ -287,7 +281,8 @@ bool ReadTLine(HANDLE hDatFile, TCHAR *line, int bsize, int &offset) { return true; } -extern "C" void __declspec(dllexport) CALLBACK ExternalUpdate(HWND hwnd, HINSTANCE hInstance, LPSTR lpszCmdLine, int nCmdShow) { +void CALLBACK ExternalUpdate(HWND hwnd, HINSTANCE hInstance, LPSTR lpszCmdLine, int nCmdShow) +{ //MessageBox(0, _T("ExternalUpdate"), _T("Updater"), MB_OK); HANDLE hDatFile = CreateFileA(lpszCmdLine, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0); if(hDatFile == INVALID_HANDLE_VALUE) { @@ -297,13 +292,13 @@ extern "C" void __declspec(dllexport) CALLBACK ExternalUpdate(HWND hwnd, HINSTAN } else { TCHAR *mir_exe = (TCHAR *)malloc(MAX_PATH * sizeof(TCHAR)), - *plugins_folder = (TCHAR *)malloc(MAX_PATH * sizeof(TCHAR)), - *temp_folder = (TCHAR *)malloc(MAX_PATH * sizeof(TCHAR)), - *backup_folder = (TCHAR *)malloc(MAX_PATH * sizeof(TCHAR)), - *root_folder = (TCHAR *)malloc(MAX_PATH * sizeof(TCHAR)); - char *db_name = (char *)malloc(MAX_PATH), - *db_path = (char *)malloc(MAX_PATH), - *pid = (char *)malloc(64); + *plugins_folder = (TCHAR *)malloc(MAX_PATH * sizeof(TCHAR)), + *temp_folder = (TCHAR *)malloc(MAX_PATH * sizeof(TCHAR)), + *backup_folder = (TCHAR *)malloc(MAX_PATH * sizeof(TCHAR)), + *root_folder = (TCHAR *)malloc(MAX_PATH * sizeof(TCHAR)); + char *db_name = (char *)malloc(MAX_PATH), + *db_path = (char *)malloc(MAX_PATH), + *pid = (char *)malloc(64); bool restart = true; @@ -450,7 +445,7 @@ extern "C" void __declspec(dllexport) CALLBACK ExternalUpdate(HWND hwnd, HINSTAN #endif TCHAR szArgs[MAX_PATH], *temp_str; //wsprintf(szArgs, "\"%s\" \"%s\"", db_path, db_name); - _stprintf(szArgs, _T("\"%s\" \"%s\""), mir_exe, temp_str = GetTStringACP(db_path)); // includes name, dummy instead of executable? + mir_sntprintf(szArgs, SIZEOF(szArgs), _T("\"%s\" \"%s\""), mir_exe, temp_str = GetTStringACP(db_path)); // includes name, dummy instead of executable? free(temp_str); //wsprintf(szArgs, "\"%s\"", db_name); -- cgit v1.2.3