From 9482f765a00b1abf1e9cdc28a1854e0ab53809fe Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 25 Apr 2019 21:54:06 +0300 Subject: pu_stub: - fixes #1930 (crash when launching pu_stub under Windows 7); - unified project for all VS --- plugins/PluginUpdater/pu_stub/pu_stub.cpp | 127 ----------------- plugins/PluginUpdater/pu_stub/pu_stub.vcxproj | 37 +++++ .../PluginUpdater/pu_stub/pu_stub.vcxproj.filters | 4 + plugins/PluginUpdater/pu_stub/pu_stub_15.vcxproj | 157 --------------------- .../pu_stub/pu_stub_15.vcxproj.filters | 14 -- plugins/PluginUpdater/pu_stub/pu_stub_16.vcxproj | 157 --------------------- .../pu_stub/pu_stub_16.vcxproj.filters | 14 -- plugins/PluginUpdater/pu_stub/src/pu_stub.cpp | 116 +++++++++++++++ plugins/PluginUpdater/pu_stub/src/stdafx.cxx | 18 +++ plugins/PluginUpdater/pu_stub/src/stdafx.h | 31 ++++ 10 files changed, 206 insertions(+), 469 deletions(-) delete mode 100644 plugins/PluginUpdater/pu_stub/pu_stub.cpp create mode 100644 plugins/PluginUpdater/pu_stub/pu_stub.vcxproj create mode 100644 plugins/PluginUpdater/pu_stub/pu_stub.vcxproj.filters delete mode 100644 plugins/PluginUpdater/pu_stub/pu_stub_15.vcxproj delete mode 100644 plugins/PluginUpdater/pu_stub/pu_stub_15.vcxproj.filters delete mode 100644 plugins/PluginUpdater/pu_stub/pu_stub_16.vcxproj delete mode 100644 plugins/PluginUpdater/pu_stub/pu_stub_16.vcxproj.filters create mode 100644 plugins/PluginUpdater/pu_stub/src/pu_stub.cpp create mode 100644 plugins/PluginUpdater/pu_stub/src/stdafx.cxx create mode 100644 plugins/PluginUpdater/pu_stub/src/stdafx.h (limited to 'plugins/PluginUpdater') diff --git a/plugins/PluginUpdater/pu_stub/pu_stub.cpp b/plugins/PluginUpdater/pu_stub/pu_stub.cpp deleted file mode 100644 index fb4cd24462..0000000000 --- a/plugins/PluginUpdater/pu_stub/pu_stub.cpp +++ /dev/null @@ -1,127 +0,0 @@ -#define _CRT_SECURE_NO_WARNINGS - -#define WIN32_LEAN_AND_MEAN -#include - -// C RunTime Header Files -#include -#include -#include -#include -#include - -// Global Variables: -HINSTANCE hInst; // current instance - -void log(const wchar_t *tszFormat, ...) -{ - #if defined(_DEBUG) - FILE *out = fopen("c:\\temp\\pu.log", "a"); - if (out) { - va_list params; - va_start(params, tszFormat); - vfwprintf(out, tszFormat, params); - va_end(params); - fputc('\n', out); - fclose(out); - } - #endif -} - -int CreateDirectoryTreeW(const wchar_t* szDir) -{ - wchar_t szTestDir[MAX_PATH]; - lstrcpynW(szTestDir, szDir, MAX_PATH); - - DWORD dwAttributes = GetFileAttributesW(szTestDir); - if (dwAttributes != INVALID_FILE_ATTRIBUTES && (dwAttributes & FILE_ATTRIBUTE_DIRECTORY)) - return 0; - - wchar_t *pszLastBackslash = wcsrchr(szTestDir, '\\'); - if (pszLastBackslash == nullptr) - return 0; - - *pszLastBackslash = '\0'; - CreateDirectoryTreeW(szTestDir); - *pszLastBackslash = '\\'; - return (CreateDirectoryW(szTestDir, nullptr) == 0) ? GetLastError() : 0; -} - -void CreatePathToFileW(wchar_t *wszFilePath) -{ - wchar_t* pszLastBackslash = wcsrchr(wszFilePath, '\\'); - if (pszLastBackslash == nullptr) - return; - - *pszLastBackslash = '\0'; - CreateDirectoryTreeW(wszFilePath); - *pszLastBackslash = '\\'; -} - -int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE, LPTSTR lpCmdLine, int) -{ - DWORD dwError; - hInst = hInstance; - - wchar_t tszPipeName[MAX_PATH]; - #if _MSC_VER < 1400 - swprintf(tszPipeName, L"\\\\.\\pipe\\Miranda_Pu_%s", lpCmdLine); - #else - swprintf_s(tszPipeName, L"\\\\.\\pipe\\Miranda_Pu_%s", lpCmdLine); - #endif - log(L"Opening pipe %s...", tszPipeName); - HANDLE hPipe = CreateFile(tszPipeName, GENERIC_READ | GENERIC_WRITE, 0, nullptr, OPEN_EXISTING, 0, nullptr); - if (hPipe == INVALID_HANDLE_VALUE) { - dwError = GetLastError(); - log(L"Failed to open a pipe: error %d", dwError); - return dwError; - } - - log(L"Entering the reading cycle..."); - - BYTE szReadBuffer[1024] = { 0 }; - DWORD dwBytes; - while (ReadFile(hPipe, szReadBuffer, sizeof(szReadBuffer), &dwBytes, nullptr)) { - DWORD dwAction = *(DWORD*)szReadBuffer; - wchar_t *ptszFile1 = (wchar_t*)(szReadBuffer + sizeof(DWORD)); - wchar_t *ptszFile2 = ptszFile1 + wcslen(ptszFile1) + 1; - log(L"Received command: %d <%s> <%s>", dwAction, ptszFile1, ptszFile2); - switch (dwAction) { - case 1: // copy - dwError = CopyFile(ptszFile1, ptszFile2, FALSE); - break; - - case 2: // move - DeleteFile(ptszFile2); - if (MoveFile(ptszFile1, ptszFile2) == 0) // use copy on error - dwError = CopyFile(ptszFile1, ptszFile2, FALSE); - else - dwError = 0; - DeleteFile(ptszFile1); - break; - - case 3: // erase - dwError = DeleteFile(ptszFile1); - break; - - case 4: // create dir - dwError = CreateDirectoryTreeW(ptszFile1); - break; - - case 5: // create path to file - CreatePathToFileW(ptszFile1); - dwError = 0; - break; - - default: - dwError = ERROR_UNKNOWN_FEATURE; - } - - WriteFile(hPipe, &dwError, sizeof(DWORD), &dwBytes, nullptr); - } - - dwError = GetLastError(); - log(L"Pipe is closed (%d), exiting", dwError); - CloseHandle(hPipe); - return 0; -} diff --git a/plugins/PluginUpdater/pu_stub/pu_stub.vcxproj b/plugins/PluginUpdater/pu_stub/pu_stub.vcxproj new file mode 100644 index 0000000000..4501f5dae8 --- /dev/null +++ b/plugins/PluginUpdater/pu_stub/pu_stub.vcxproj @@ -0,0 +1,37 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {121D2EA6-9D3C-43F6-AC5C-44BDBF93E3E0} + Win32Proj + pu_stub + pu_stub + + + + + + + Windows + vcruntime140d.dll + api-ms-win-crt-heap-l1-1-0.dll;api-ms-win-crt-locale-l1-1-0.dll;api-ms-win-crt-math-l1-1-0.dll;api-ms-win-crt-runtime-l1-1-0.dll;api-ms-win-crt-stdio-l1-1-0.dll;VCRUNTIME140.dll + + + \ No newline at end of file diff --git a/plugins/PluginUpdater/pu_stub/pu_stub.vcxproj.filters b/plugins/PluginUpdater/pu_stub/pu_stub.vcxproj.filters new file mode 100644 index 0000000000..fcae13a9d8 --- /dev/null +++ b/plugins/PluginUpdater/pu_stub/pu_stub.vcxproj.filters @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/plugins/PluginUpdater/pu_stub/pu_stub_15.vcxproj b/plugins/PluginUpdater/pu_stub/pu_stub_15.vcxproj deleted file mode 100644 index fcb953c1b4..0000000000 --- a/plugins/PluginUpdater/pu_stub/pu_stub_15.vcxproj +++ /dev/null @@ -1,157 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - {121D2EA6-9D3C-43F6-AC5C-44BDBF93E3E0} - Win32Proj - pu_stub - pu_stub - false - - - - Application - true - v141_xp - Unicode - - - Application - true - v141_xp - Unicode - - - Application - false - v141_xp - true - Unicode - - - Application - false - true - Unicode - v141_xp - - - - - - - - - - - - - - - - - - - true - $(SolutionDir)$(Configuration)\Obj\$(ProjectName)\ - - - true - $(SolutionDir)$(Configuration)64\ - $(SolutionDir)$(Configuration)64\Obj\$(ProjectName)\ - - - false - $(SolutionDir)$(Configuration)\Obj\$(ProjectName)\ - - - false - $(SolutionDir)$(Configuration)64\ - $(SolutionDir)$(Configuration)64\Obj\$(ProjectName)\ - - - - Level4 - Disabled - _DEBUG;_WINDOWS;%(PreprocessorDefinitions) - MultiThreadedDebugDLL - - - Windows - true - false - ucrtbased.dll;vcruntime140.dll - - - - - Level4 - Disabled - _DEBUG;_WINDOWS;%(PreprocessorDefinitions) - MultiThreadedDebugDLL - - - Windows - true - ucrtbased.dll;vcruntime140.dll - - - - - NoExtensions - Level4 - MaxSpeed - true - true - NDEBUG;_WINDOWS;%(PreprocessorDefinitions) - MultiThreadedDLL - - - Windows - true - true - true - ucrtbase.dll;api-ms-win-crt-heap-l1-1-0.dll;api-ms-win-crt-locale-l1-1-0.dll;api-ms-win-crt-math-l1-1-0.dll;api-ms-win-crt-runtime-l1-1-0.dll;api-ms-win-crt-stdio-l1-1-0.dll;api-ms-win-crt-string-l1-1-0.dll;vcruntime140.DLL - - - - - Level4 - MinSpace - true - NDEBUG;_WINDOWS;%(PreprocessorDefinitions) - Size - MultiThreadedDLL - - - Windows - true - true - true - ucrtbase.dll;api-ms-win-crt-heap-l1-1-0.dll;api-ms-win-crt-locale-l1-1-0.dll;api-ms-win-crt-math-l1-1-0.dll;api-ms-win-crt-runtime-l1-1-0.dll;api-ms-win-crt-stdio-l1-1-0.dll;api-ms-win-crt-string-l1-1-0.dll;vcruntime140.DLL - - - - - - - - - \ No newline at end of file diff --git a/plugins/PluginUpdater/pu_stub/pu_stub_15.vcxproj.filters b/plugins/PluginUpdater/pu_stub/pu_stub_15.vcxproj.filters deleted file mode 100644 index fa14ef3d54..0000000000 --- a/plugins/PluginUpdater/pu_stub/pu_stub_15.vcxproj.filters +++ /dev/null @@ -1,14 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - - - Source Files - - - \ No newline at end of file diff --git a/plugins/PluginUpdater/pu_stub/pu_stub_16.vcxproj b/plugins/PluginUpdater/pu_stub/pu_stub_16.vcxproj deleted file mode 100644 index 59a24857ae..0000000000 --- a/plugins/PluginUpdater/pu_stub/pu_stub_16.vcxproj +++ /dev/null @@ -1,157 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - {121D2EA6-9D3C-43F6-AC5C-44BDBF93E3E0} - Win32Proj - pu_stub - pu_stub - false - - - - Application - true - v142 - Unicode - - - Application - true - v142 - Unicode - - - Application - false - v142 - true - Unicode - - - Application - false - true - Unicode - v142 - - - - - - - - - - - - - - - - - - - true - $(SolutionDir)$(Configuration)\Obj\$(ProjectName)\ - - - true - $(SolutionDir)$(Configuration)64\ - $(SolutionDir)$(Configuration)64\Obj\$(ProjectName)\ - - - false - $(SolutionDir)$(Configuration)\Obj\$(ProjectName)\ - - - false - $(SolutionDir)$(Configuration)64\ - $(SolutionDir)$(Configuration)64\Obj\$(ProjectName)\ - - - - Level4 - Disabled - _DEBUG;_WINDOWS;%(PreprocessorDefinitions) - MultiThreadedDebugDLL - - - Windows - true - false - ucrtbased.dll;vcruntime140.dll - - - - - Level4 - Disabled - _DEBUG;_WINDOWS;%(PreprocessorDefinitions) - MultiThreadedDebugDLL - - - Windows - true - ucrtbased.dll;vcruntime140.dll - - - - - NoExtensions - Level4 - MaxSpeed - true - true - NDEBUG;_WINDOWS;%(PreprocessorDefinitions) - MultiThreadedDLL - - - Windows - true - true - true - ucrtbase.dll;api-ms-win-crt-heap-l1-1-0.dll;api-ms-win-crt-locale-l1-1-0.dll;api-ms-win-crt-math-l1-1-0.dll;api-ms-win-crt-runtime-l1-1-0.dll;api-ms-win-crt-stdio-l1-1-0.dll;api-ms-win-crt-string-l1-1-0.dll;vcruntime140.DLL - - - - - Level4 - MinSpace - true - NDEBUG;_WINDOWS;%(PreprocessorDefinitions) - Size - MultiThreadedDLL - - - Windows - true - true - true - ucrtbase.dll;api-ms-win-crt-heap-l1-1-0.dll;api-ms-win-crt-locale-l1-1-0.dll;api-ms-win-crt-math-l1-1-0.dll;api-ms-win-crt-runtime-l1-1-0.dll;api-ms-win-crt-stdio-l1-1-0.dll;api-ms-win-crt-string-l1-1-0.dll;vcruntime140.DLL - - - - - - - - - \ No newline at end of file diff --git a/plugins/PluginUpdater/pu_stub/pu_stub_16.vcxproj.filters b/plugins/PluginUpdater/pu_stub/pu_stub_16.vcxproj.filters deleted file mode 100644 index fa14ef3d54..0000000000 --- a/plugins/PluginUpdater/pu_stub/pu_stub_16.vcxproj.filters +++ /dev/null @@ -1,14 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - - - Source Files - - - \ No newline at end of file diff --git a/plugins/PluginUpdater/pu_stub/src/pu_stub.cpp b/plugins/PluginUpdater/pu_stub/src/pu_stub.cpp new file mode 100644 index 0000000000..ff11fd3c11 --- /dev/null +++ b/plugins/PluginUpdater/pu_stub/src/pu_stub.cpp @@ -0,0 +1,116 @@ + +#include "stdafx.h" + +#pragma comment(lib, "delayimp.lib") + +void log(const wchar_t *tszFormat, ...) +{ + #if defined(_DEBUG) + FILE *out = fopen("c:\\temp\\pu.log", "a"); + if (out) { + va_list params; + va_start(params, tszFormat); + vfwprintf(out, tszFormat, params); + va_end(params); + fputc('\n', out); + fclose(out); + } + #endif +} + +int CreateDirectoryTreeW(const wchar_t* szDir) +{ + wchar_t szTestDir[MAX_PATH]; + lstrcpynW(szTestDir, szDir, MAX_PATH); + + DWORD dwAttributes = GetFileAttributesW(szTestDir); + if (dwAttributes != INVALID_FILE_ATTRIBUTES && (dwAttributes & FILE_ATTRIBUTE_DIRECTORY)) + return 0; + + wchar_t *pszLastBackslash = wcsrchr(szTestDir, '\\'); + if (pszLastBackslash == nullptr) + return 0; + + *pszLastBackslash = '\0'; + CreateDirectoryTreeW(szTestDir); + *pszLastBackslash = '\\'; + return (CreateDirectoryW(szTestDir, nullptr) == 0) ? GetLastError() : 0; +} + +void CreatePathToFileW(wchar_t *wszFilePath) +{ + wchar_t* pszLastBackslash = wcsrchr(wszFilePath, '\\'); + if (pszLastBackslash == nullptr) + return; + + *pszLastBackslash = '\0'; + CreateDirectoryTreeW(wszFilePath); + *pszLastBackslash = '\\'; +} + +int APIENTRY wWinMain(HINSTANCE /*hInstance*/, HINSTANCE, LPTSTR lpCmdLine, int) +{ + DWORD dwError; + + wchar_t tszPipeName[MAX_PATH]; + #if _MSC_VER < 1400 + swprintf(tszPipeName, L"\\\\.\\pipe\\Miranda_Pu_%s", lpCmdLine); + #else + swprintf_s(tszPipeName, L"\\\\.\\pipe\\Miranda_Pu_%s", lpCmdLine); + #endif + log(L"Opening pipe %s...", tszPipeName); + HANDLE hPipe = CreateFile(tszPipeName, GENERIC_READ | GENERIC_WRITE, 0, nullptr, OPEN_EXISTING, 0, nullptr); + if (hPipe == INVALID_HANDLE_VALUE) { + dwError = GetLastError(); + log(L"Failed to open a pipe: error %d", dwError); + return dwError; + } + + log(L"Entering the reading cycle..."); + + BYTE szReadBuffer[1024] = { 0 }; + DWORD dwBytes; + while (ReadFile(hPipe, szReadBuffer, sizeof(szReadBuffer), &dwBytes, nullptr)) { + DWORD dwAction = *(DWORD*)szReadBuffer; + wchar_t *ptszFile1 = (wchar_t*)(szReadBuffer + sizeof(DWORD)); + wchar_t *ptszFile2 = ptszFile1 + wcslen(ptszFile1) + 1; + log(L"Received command: %d <%s> <%s>", dwAction, ptszFile1, ptszFile2); + switch (dwAction) { + case 1: // copy + dwError = CopyFile(ptszFile1, ptszFile2, FALSE); + break; + + case 2: // move + DeleteFile(ptszFile2); + if (MoveFile(ptszFile1, ptszFile2) == 0) // use copy on error + dwError = CopyFile(ptszFile1, ptszFile2, FALSE); + else + dwError = 0; + DeleteFile(ptszFile1); + break; + + case 3: // erase + dwError = DeleteFile(ptszFile1); + break; + + case 4: // create dir + dwError = CreateDirectoryTreeW(ptszFile1); + break; + + case 5: // create path to file + CreatePathToFileW(ptszFile1); + dwError = 0; + break; + + default: + dwError = ERROR_UNKNOWN_FEATURE; + } + + WriteFile(hPipe, &dwError, sizeof(DWORD), &dwBytes, nullptr); + } + + dwError = GetLastError(); + log(L"Pipe is closed (%d), exiting", dwError); + CloseHandle(hPipe); + return 0; +} diff --git a/plugins/PluginUpdater/pu_stub/src/stdafx.cxx b/plugins/PluginUpdater/pu_stub/src/stdafx.cxx new file mode 100644 index 0000000000..66afad80f1 --- /dev/null +++ b/plugins/PluginUpdater/pu_stub/src/stdafx.cxx @@ -0,0 +1,18 @@ +/* +Copyright (C) 2012-19 Miranda NG team (https://miranda-ng.org) + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation version 2 +of the License. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +#include "stdafx.h" diff --git a/plugins/PluginUpdater/pu_stub/src/stdafx.h b/plugins/PluginUpdater/pu_stub/src/stdafx.h new file mode 100644 index 0000000000..b6f494b071 --- /dev/null +++ b/plugins/PluginUpdater/pu_stub/src/stdafx.h @@ -0,0 +1,31 @@ +/* +CmdLine plugin for Miranda IM + +Copyright © 2007 Cristian Libotean + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#pragma once + +#define WIN32_LEAN_AND_MEAN +#include + +// C RunTime Header Files +#include +#include +#include +#include +#include -- cgit v1.2.3