From 986e67d7c54cb53bae5eebcebb313b58b9bf5566 Mon Sep 17 00:00:00 2001 From: Birunthan Mohanathas Date: Sun, 20 Oct 2013 12:28:59 +0300 Subject: [PATCH] SkinInstaller: Split into SkinInstaller.dll and SkinInstaller.exe to support 04e3376 --- Build/Build.bat | 2 +- Build/Installer/Installer.nsi | 2 + Rainmeter.sln | 13 ++ SkinInstaller/DialogInstall.cpp | 6 +- SkinInstaller/DialogPackage.cpp | 12 +- .../{Application.cpp => SkinInstaller.cpp} | 17 ++- SkinInstaller/SkinInstaller.def | 4 + SkinInstaller/SkinInstaller.h | 61 ++++++++ SkinInstaller/SkinInstaller.rc | 11 +- SkinInstaller/SkinInstaller.vcxproj | 41 ++---- SkinInstaller/SkinInstaller.vcxproj.filters | 19 ++- SkinInstaller/SkinInstallerLauncher.cpp | 130 ++++++++++++++++++ SkinInstaller/SkinInstallerLauncher.rc | 55 ++++++++ SkinInstaller/SkinInstallerLauncher.vcxproj | 98 +++++++++++++ .../SkinInstallerLauncher.vcxproj.filters | 27 ++++ 15 files changed, 434 insertions(+), 64 deletions(-) rename SkinInstaller/{Application.cpp => SkinInstaller.cpp} (92%) create mode 100644 SkinInstaller/SkinInstaller.def create mode 100644 SkinInstaller/SkinInstaller.h create mode 100644 SkinInstaller/SkinInstallerLauncher.cpp create mode 100644 SkinInstaller/SkinInstallerLauncher.rc create mode 100644 SkinInstaller/SkinInstallerLauncher.vcxproj create mode 100644 SkinInstaller/SkinInstallerLauncher.vcxproj.filters diff --git a/Build/Build.bat b/Build/Build.bat index 0ff4dbdd..5a40fba0 100644 --- a/Build/Build.bat +++ b/Build/Build.bat @@ -126,7 +126,7 @@ if "%1" == "BUILDLANGUAGES" ( :: Sign binaries if not "%CERTFILE%" == "" ( echo * Signing binaries - for %%Z in (Rainmeter.dll Rainmeter.exe SkinInstaller.exe) do ( + for %%Z in (Rainmeter.dll Rainmeter.exe SkinInstaller.exe SkinInstaller.dll) do ( %SIGNTOOL% ..\TestBench\x32\Release\%%Z > BuildLog.txt if not %ERRORLEVEL% == 0 echo ERROR %ERRORLEVEL%: Signing x32\%%Z failed & goto END %SIGNTOOL% ..\TestBench\x64\Release\%%Z > BuildLog.txt diff --git a/Build/Installer/Installer.nsi b/Build/Installer/Installer.nsi index c200321a..852b00e9 100644 --- a/Build/Installer/Installer.nsi +++ b/Build/Installer/Installer.nsi @@ -510,6 +510,7 @@ FunctionEnd File "..\..\TestBench\${DIR}\Release\Rainmeter.exe" File "..\..\TestBench\${DIR}\Release\Rainmeter.dll" File "..\..\TestBench\${DIR}\Release\SkinInstaller.exe" + File "..\..\TestBench\${DIR}\Release\SkinInstaller.dll" SetOutPath "$INSTDIR\Plugins" File /x *Example*.dll "..\..\TestBench\${DIR}\Release\Plugins\*.dll" @@ -916,6 +917,7 @@ Section Uninstall Delete "$INSTDIR\Rainmeter.exe" Delete "$INSTDIR\Rainmeter.exe.config" Delete "$INSTDIR\SkinInstaller.exe" + Delete "$INSTDIR\SkinInstaller.dll" Delete "$INSTDIR\uninst.exe" RMDir "$INSTDIR" diff --git a/Rainmeter.sln b/Rainmeter.sln index 5b45c60a..4e561b0d 100644 --- a/Rainmeter.sln +++ b/Rainmeter.sln @@ -17,6 +17,11 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Library", "Library\Library. EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SkinInstaller", "SkinInstaller\SkinInstaller.vcxproj", "{6F5D4C4A-C8C3-41DA-BF44-6D42B76464DA}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SkinInstallerLauncher", "SkinInstaller\SkinInstallerLauncher.vcxproj", "{2D8F1DDB-6470-45A1-B95A-3E2960641314}" + ProjectSection(ProjectDependencies) = postProject + {6F5D4C4A-C8C3-41DA-BF44-6D42B76464DA} = {6F5D4C4A-C8C3-41DA-BF44-6D42B76464DA} + EndProjectSection +EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DllExporter", "Plugins\API\DllExporter\DllExporter.csproj", "{49D56CA5-54AB-45C9-A245-EAE588FCBFE1}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PluginAdvancedCPU", "Plugins\PluginAdvancedCPU\PluginAdvancedCPU.vcxproj", "{EE8EC522-8430-4B46-86A3-D943D77F9E4B}" @@ -117,6 +122,14 @@ Global {6F5D4C4A-C8C3-41DA-BF44-6D42B76464DA}.Release|Win32.Build.0 = Release|Win32 {6F5D4C4A-C8C3-41DA-BF44-6D42B76464DA}.Release|x64.ActiveCfg = Release|x64 {6F5D4C4A-C8C3-41DA-BF44-6D42B76464DA}.Release|x64.Build.0 = Release|x64 + {2D8F1DDB-6470-45A1-B95A-3E2960641314}.Debug|Win32.ActiveCfg = Debug|Win32 + {2D8F1DDB-6470-45A1-B95A-3E2960641314}.Debug|Win32.Build.0 = Debug|Win32 + {2D8F1DDB-6470-45A1-B95A-3E2960641314}.Debug|x64.ActiveCfg = Debug|x64 + {2D8F1DDB-6470-45A1-B95A-3E2960641314}.Debug|x64.Build.0 = Debug|x64 + {2D8F1DDB-6470-45A1-B95A-3E2960641314}.Release|Win32.ActiveCfg = Release|Win32 + {2D8F1DDB-6470-45A1-B95A-3E2960641314}.Release|Win32.Build.0 = Release|Win32 + {2D8F1DDB-6470-45A1-B95A-3E2960641314}.Release|x64.ActiveCfg = Release|x64 + {2D8F1DDB-6470-45A1-B95A-3E2960641314}.Release|x64.Build.0 = Release|x64 {49D56CA5-54AB-45C9-A245-EAE588FCBFE1}.Debug|Win32.ActiveCfg = Debug|x86 {49D56CA5-54AB-45C9-A245-EAE588FCBFE1}.Debug|Win32.Build.0 = Debug|x86 {49D56CA5-54AB-45C9-A245-EAE588FCBFE1}.Debug|x64.ActiveCfg = Debug|x64 diff --git a/SkinInstaller/DialogInstall.cpp b/SkinInstaller/DialogInstall.cpp index dfae8582..63f7c015 100644 --- a/SkinInstaller/DialogInstall.cpp +++ b/SkinInstaller/DialogInstall.cpp @@ -17,7 +17,7 @@ */ #include "StdAfx.h" -#include "Application.h" +#include "SkinInstaller.h" #include "DialogInstall.h" #include "../Library/pcre-8.10/config.h" #include "../Library/pcre-8.10/pcre.h" @@ -220,7 +220,7 @@ INT_PTR DialogInstall::OnCommand(WPARAM wParam, LPARAM lParam) { RECT r; GetWindowRect((HWND)lParam, &r); - HMENU menu = LoadMenu(GetModuleHandle(nullptr), MAKEINTRESOURCE(IDR_INSTALL_MENU)); + HMENU menu = LoadMenu(GetInstanceHandle(), MAKEINTRESOURCE(IDR_INSTALL_MENU)); HMENU subMenu = GetSubMenu(menu, 0); if (m_PackageSkins.empty() || m_MergeSkins || m_BackupPackage) @@ -1312,7 +1312,7 @@ std::wstring DialogInstall::GetWindowsVersionString() ** Constructor. ** */ -DialogInstall::TabInstall::TabInstall(HWND wnd) : Tab(GetModuleHandle(nullptr), wnd, IDD_INSTALL_TAB, DlgProc) +DialogInstall::TabInstall::TabInstall(HWND wnd) : Tab(GetInstanceHandle(), wnd, IDD_INSTALL_TAB, DlgProc) { } diff --git a/SkinInstaller/DialogPackage.cpp b/SkinInstaller/DialogPackage.cpp index ffa53dbb..522ccb7c 100644 --- a/SkinInstaller/DialogPackage.cpp +++ b/SkinInstaller/DialogPackage.cpp @@ -18,7 +18,7 @@ #include "StdAfx.h" #include "../Common/StringUtil.h" -#include "Application.h" +#include "SkinInstaller.h" #include "DialogPackage.h" #include "DialogInstall.h" #include "resource.h" @@ -555,7 +555,7 @@ std::wstring DialogPackage::SelectFolder(HWND parent, const std::wstring& existi { LPCWSTR dialog = MAKEINTRESOURCE(IDD_PACKAGESELECTFOLDER_DIALOG); std::wstring folder = existingPath; - if (DialogBoxParam(GetModuleHandle(nullptr), dialog, parent, SelectFolderDlgProc, (LPARAM)&folder) != 1) + if (DialogBoxParam(GetInstanceHandle(), dialog, parent, SelectFolderDlgProc, (LPARAM)&folder) != 1) { folder.clear(); } @@ -714,7 +714,7 @@ std::pair DialogPackage::SelectPlugin(HWND parent) { LPCWSTR dialog = MAKEINTRESOURCE(IDD_PACKAGESELECTPLUGIN_DIALOG); std::pair plugins; - if (DialogBoxParam(GetModuleHandle(nullptr), dialog, parent, SelectPluginDlgProc, (LPARAM)&plugins) != 1) + if (DialogBoxParam(GetInstanceHandle(), dialog, parent, SelectPluginDlgProc, (LPARAM)&plugins) != 1) { plugins.first.clear(); plugins.second.clear(); @@ -819,7 +819,7 @@ INT_PTR CALLBACK DialogPackage::SelectPluginDlgProc(HWND hWnd, UINT uMsg, WPARAM // // ----------------------------------------------------------------------------------------------- -DialogPackage::TabInfo::TabInfo(HWND wnd) : Tab(GetModuleHandle(nullptr), wnd, IDD_PACKAGEINFO_TAB, DlgProc) +DialogPackage::TabInfo::TabInfo(HWND wnd) : Tab(GetInstanceHandle(), wnd, IDD_PACKAGEINFO_TAB, DlgProc) { } @@ -1071,7 +1071,7 @@ INT_PTR DialogPackage::TabInfo::OnNotify(WPARAM wParam, LPARAM lParam) // // ----------------------------------------------------------------------------------------------- -DialogPackage::TabOptions::TabOptions(HWND wnd) : Tab(GetModuleHandle(nullptr), wnd, IDD_PACKAGEOPTIONS_TAB, DlgProc) +DialogPackage::TabOptions::TabOptions(HWND wnd) : Tab(GetInstanceHandle(), wnd, IDD_PACKAGEOPTIONS_TAB, DlgProc) { } @@ -1311,7 +1311,7 @@ INT_PTR DialogPackage::TabOptions::OnCommand(WPARAM wParam, LPARAM lParam) // // ----------------------------------------------------------------------------------------------- -DialogPackage::TabAdvanced::TabAdvanced(HWND wnd) : Tab(GetModuleHandle(nullptr), wnd, IDD_PACKAGEADVANCED_TAB, DlgProc) +DialogPackage::TabAdvanced::TabAdvanced(HWND wnd) : Tab(GetInstanceHandle(), wnd, IDD_PACKAGEADVANCED_TAB, DlgProc) { } diff --git a/SkinInstaller/Application.cpp b/SkinInstaller/SkinInstaller.cpp similarity index 92% rename from SkinInstaller/Application.cpp rename to SkinInstaller/SkinInstaller.cpp index ca463e5b..29b19d27 100644 --- a/SkinInstaller/Application.cpp +++ b/SkinInstaller/SkinInstaller.cpp @@ -20,7 +20,9 @@ #include "DialogPackage.h" #include "DialogInstall.h" #include "resource.h" -#include "Application.h" +#include "SkinInstaller.h" + +EXTERN_C IMAGE_DOS_HEADER __ImageBase; GlobalData g_Data; @@ -36,7 +38,7 @@ OsNameVersion g_OsNameVersions[] = ** Entry point ** */ -int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow) +int SkinInstallerMain(LPWSTR lpCmdLine) { // Avoid loading a dll from current directory SetDllDirectory(L""); @@ -56,7 +58,7 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLi } WCHAR buffer[MAX_PATH]; - GetModuleFileName(hInstance, buffer, MAX_PATH); + GetModuleFileName(GetInstanceHandle(), buffer, MAX_PATH); // Remove the module's name from the path WCHAR* pos = wcsrchr(buffer, L'\\'); @@ -189,11 +191,11 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLi } else if (wcscmp(lpCmdLine, L"/Packager") == 0) { - DialogPackage::Create(hInstance, lpCmdLine); + DialogPackage::Create(GetInstanceHandle(), lpCmdLine); } else { - DialogInstall::Create(hInstance, lpCmdLine); + DialogInstall::Create(GetInstanceHandle(), lpCmdLine); } return 0; @@ -224,6 +226,11 @@ bool CloseRainmeterIfActive() return true; } +HINSTANCE GetInstanceHandle() +{ + return (HINSTANCE)&__ImageBase; +} + // ----------------------------------------------------------------------------------------------- // Stolen functions from Rainmeter Litestep.cpp, System.cpp, and Application.cpp // ----------------------------------------------------------------------------------------------- diff --git a/SkinInstaller/SkinInstaller.def b/SkinInstaller/SkinInstaller.def new file mode 100644 index 00000000..1bbfc2fc --- /dev/null +++ b/SkinInstaller/SkinInstaller.def @@ -0,0 +1,4 @@ +LIBRARY +EXPORTS + ; Private + SkinInstallerMain @1 NONAME diff --git a/SkinInstaller/SkinInstaller.h b/SkinInstaller/SkinInstaller.h new file mode 100644 index 00000000..47d3aef0 --- /dev/null +++ b/SkinInstaller/SkinInstaller.h @@ -0,0 +1,61 @@ +/* + Copyright (C) 2011 Birunthan Mohanathas + + 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef SKININSTALLER_UTIL_H_ +#define SKININSTALLER_UTIL_H_ + +#include +#include "zip.h" +#include "unzip.h" + +#define MAX_LINE_LENGTH 4096 +#define MB_ERROR MB_OK | MB_TOPMOST | MB_ICONERROR + +struct GlobalData +{ + std::wstring programPath; + std::wstring settingsPath; + std::wstring skinsPath; + std::wstring iniFile; +}; + +struct OsNameVersion +{ + const WCHAR* name; + const WCHAR* version; +}; + +enum OSPLATFORM +{ + OSPLATFORM_UNKNOWN = 0, + OSPLATFORM_XP, + OSPLATFORM_VISTA, + OSPLATFORM_7 +}; + +HINSTANCE GetInstanceHandle(); + +bool CloseRainmeterIfActive(); +OSPLATFORM GetOSPlatform(); + +bool IsRunning(const WCHAR* name, HANDLE* hMutex); +bool CopyFiles(const std::wstring& strFrom, const std::wstring& strTo, bool bMove = false); +std::string ConvertToAscii(LPCTSTR str); +std::wstring ConvertToWide(LPCSTR str); + +#endif diff --git a/SkinInstaller/SkinInstaller.rc b/SkinInstaller/SkinInstaller.rc index ab38dbad..a1b6494d 100644 --- a/SkinInstaller/SkinInstaller.rc +++ b/SkinInstaller/SkinInstaller.rc @@ -29,8 +29,8 @@ VS_VERSION_INFO VERSIONINFO { VALUE "FileDescription", "Rainmeter Skin Installer" VALUE "FileVersion", STRFILEVER - VALUE "LegalCopyright", "© 2012 - Birunthan Mohanathas" - VALUE "OriginalFilename", "SkinInstaller.exe" + VALUE "LegalCopyright", "© 2013 - All authors" + VALUE "OriginalFilename", "SkinInstaller.dll" VALUE "ProductName", "Rainmeter" #ifdef _WIN64 VALUE "ProductVersion", STRPRODUCTVER " (64-bit)" @@ -197,10 +197,3 @@ FONT 8, "MS Shell Dlg 2" LTEXT "Installing...", IDC_INSTALLTAB_INPROGRESS_TEXT, 0, 0, 236, 60, NOT WS_VISIBLE CONTROL "", IDC_INSTALLTAB_PROGRESS, "msctls_progress32", PBS_MARQUEE | NOT WS_VISIBLE | WS_BORDER, 0, 15, 236, 11 } - -///////////////////////////////////////////////////////////////////////////// -// -// Icon -// - -IDI_SKININSTALLER ICON DISCARDABLE "res/Rainstaller.ico" diff --git a/SkinInstaller/SkinInstaller.vcxproj b/SkinInstaller/SkinInstaller.vcxproj index 3b120bc4..3e17a30a 100644 --- a/SkinInstaller/SkinInstaller.vcxproj +++ b/SkinInstaller/SkinInstaller.vcxproj @@ -3,7 +3,7 @@ {6F5D4C4A-C8C3-41DA-BF44-6D42B76464DA} - Application + DynamicLibrary @@ -35,7 +35,7 @@ NOOLDPENTIUMCODE - ZLIB_WINAPI;NOUNCRYPT;NOCRYPT;ASMV;ASMINF;NOOLDPENTIUMCODE;HAVE_CONFIG_H;SUPPORT_UTF8;%(PreprocessorDefinitions) + ZLIB_WINAPI;NOCRYPT;NOUNCRYPT;NO_GZIP;ASMV;ASMINF;NOOLDPENTIUMCODE;HAVE_CONFIG_H;SUPPORT_UTF8;%(PreprocessorDefinitions) 4244;4267;4482;4530;4996 ./zlib;./zlib/minizip false @@ -43,23 +43,19 @@ Windows Imagehlp.lib;Wininet.lib;Comctl32.lib;Version.lib;UxTheme.lib;shlwapi.lib;%(AdditionalDependencies) - ..\Library\x32\$(Configuration);%(AdditionalLibraryDirectories) - wWinMainCRTStartup /SAFESEH:NO %(AdditionalOptions) + SkinInstaller.def $(IntDir)SkinInstaller.bsc - - ..\Application\Application.manifest - NOOLDPENTIUMCODE - ZLIB_WINAPI;NOUNCRYPT;NOCRYPT;ASMV;ASMINF;NOOLDPENTIUMCODE;HAVE_CONFIG_H;SUPPORT_UTF8;%(PreprocessorDefinitions) + ZLIB_WINAPI;NOCRYPT;NOUNCRYPT;NO_GZIP;ASMV;ASMINF;NOOLDPENTIUMCODE;HAVE_CONFIG_H;SUPPORT_UTF8;%(PreprocessorDefinitions) 4244;4267;4482;4530;4996 ./zlib;./zlib/minizip false @@ -67,67 +63,55 @@ Windows Imagehlp.lib;Wininet.lib;Comctl32.lib;Version.lib;UxTheme.lib;shlwapi.lib;%(AdditionalDependencies) - ..\Library\x64\$(Configuration);%(AdditionalLibraryDirectories) - wWinMainCRTStartup + SkinInstaller.def $(IntDir)SkinInstaller.bsc - - ..\Application\Application.manifest - NOOLDPENTIUMCODE - ZLIB_WINAPI;NOUNCRYPT;NOCRYPT;ASMV;ASMINF;NOOLDPENTIUMCODE;HAVE_CONFIG_H;SUPPORT_UTF8;%(PreprocessorDefinitions) + ZLIB_WINAPI;NOCRYPT;NOUNCRYPT;NO_GZIP;ASMV;ASMINF;NOOLDPENTIUMCODE;HAVE_CONFIG_H;SUPPORT_UTF8;%(PreprocessorDefinitions) ./zlib;./zlib/minizip 4244;4267;4482;4530;4996 Windows - wWinMainCRTStartup Imagehlp.lib;Wininet.lib;Comctl32.lib;Version.lib;UxTheme.lib;shlwapi.lib;%(AdditionalDependencies) - ..\Library\x32\$(Configuration);%(AdditionalLibraryDirectories) + SkinInstaller.def $(IntDir)SkinInstaller.bsc - - ..\Application\Application.manifest - NOOLDPENTIUMCODE - ZLIB_WINAPI;NOUNCRYPT;NOCRYPT;ASMV;ASMINF;NOOLDPENTIUMCODE;HAVE_CONFIG_H;SUPPORT_UTF8;%(PreprocessorDefinitions) + ZLIB_WINAPI;NOCRYPT;NOUNCRYPT;NO_GZIP;ASMV;ASMINF;NOOLDPENTIUMCODE;HAVE_CONFIG_H;SUPPORT_UTF8;%(PreprocessorDefinitions) ./zlib;./zlib/minizip 4244;4267;4482;4530;4996 Windows - wWinMainCRTStartup Imagehlp.lib;Wininet.lib;Comctl32.lib;Version.lib;UxTheme.lib;shlwapi.lib;%(AdditionalDependencies) - ..\Library\x64\$(Configuration);%(AdditionalLibraryDirectories) + SkinInstaller.def $(IntDir)SkinInstaller.bsc - - ..\Application\Application.manifest - - + @@ -159,11 +143,11 @@ - + @@ -204,8 +188,7 @@ - - + diff --git a/SkinInstaller/SkinInstaller.vcxproj.filters b/SkinInstaller/SkinInstaller.vcxproj.filters index ee92e48f..b4d3d8b7 100644 --- a/SkinInstaller/SkinInstaller.vcxproj.filters +++ b/SkinInstaller/SkinInstaller.vcxproj.filters @@ -24,9 +24,6 @@ - - Source Files - Source Files @@ -87,14 +84,14 @@ Common + + Source Files + Header Files - - Header Files - Header Files @@ -143,13 +140,13 @@ Header Files + + Header Files + - - Resource Files - - - Resource Files + + Source Files diff --git a/SkinInstaller/SkinInstallerLauncher.cpp b/SkinInstaller/SkinInstallerLauncher.cpp new file mode 100644 index 00000000..62aed047 --- /dev/null +++ b/SkinInstaller/SkinInstallerLauncher.cpp @@ -0,0 +1,130 @@ +/* + Copyright (C) 2011 Birunthan Mohanathas + + 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#define WIN32_LEAN_AND_MEAN +#include +#include + +EXTERN_C IMAGE_DOS_HEADER __ImageBase; + +typedef int (*SkinInstallerMainFunc)(LPWSTR cmdLine); + +WCHAR* GetCommandLineArguments() +{ + WCHAR* args = GetCommandLine(); + + // Skip past (quoted) application path in cmdLine. + if (*args == L'"') + { + ++args; // Skip leading quote. + while (*args && *args != L'"') + { + ++args; + } + ++args; // Skip trailing quote. + } + else + { + while (*args && *args != L' ') + { + ++args; + } + } + + // Skip leading whitespace (similar to CRT implementation). + while (*args && *args <= L' ') + { + ++args; + } + + return args; +} + +/* +** Attempts to load SkinInstaller.dll. If it fails, retries after loading our own copies of the +** CRT DLLs in the Runtime directory. +*/ +HINSTANCE LoadSkinInstallerLibrary() +{ + HINSTANCE rmDll = LoadLibrary(L"SkinInstaller.dll"); + if (!rmDll) + { + WCHAR path[MAX_PATH]; + if (GetModuleFileName(nullptr, path, MAX_PATH) > 0) + { + PathRemoveFileSpec(path); + PathAppend(path, L"Runtime"); + SetDllDirectory(path); + PathAppend(path, L"msvcp110.dll"); + + // Loading msvcpNNN.dll will load msvcrNNN.dll as well. + HINSTANCE msvcrDll = LoadLibrary(path); + SetDllDirectory(L""); + + if (msvcrDll) + { + rmDll = LoadLibrary(L"Rainmeter.dll"); + FreeLibrary(msvcrDll); + } + } + } + + return rmDll; +} + +/* +** Entry point. In Release builds, the entry point is Main() since the CRT is not used. +** +*/ +int APIENTRY wWinMain(HINSTANCE, HINSTANCE, LPWSTR, int) +{ + // Prevent system error message boxes. + UINT oldMode = SetErrorMode(0); + SetErrorMode(oldMode | SEM_FAILCRITICALERRORS); + + WCHAR* args = GetCommandLineArguments(); + + HINSTANCE skinInstallerDll = LoadSkinInstallerLibrary(); + if (skinInstallerDll) + { + auto skinInstallerMain = + (SkinInstallerMainFunc)GetProcAddress(skinInstallerDll, MAKEINTRESOURCEA(1)); + if (skinInstallerMain) + { + return skinInstallerMain(args); + } + } + + WCHAR message[128]; + wsprintf( + message, + L"SkinInstaller.dll load error %ld.", + GetLastError()); + MessageBox(nullptr, message, L"Rainmeter", MB_OK | MB_ICONERROR); + + return 1; +} + +#ifndef _DEBUG +EXTERN_C int WINAPI Main() +{ + int result = wWinMain(nullptr, nullptr, nullptr, 0); + ExitProcess(result); + return 0; // Never reached. +} +#endif diff --git a/SkinInstaller/SkinInstallerLauncher.rc b/SkinInstaller/SkinInstallerLauncher.rc new file mode 100644 index 00000000..efcdbb2e --- /dev/null +++ b/SkinInstaller/SkinInstallerLauncher.rc @@ -0,0 +1,55 @@ +#include +#include "resource.h" +#include "../Version.h" + +LANGUAGE LANG_ENGLISH, SUBLANG_DEFAULT +#pragma code_page(1252) + +///////////////////////////////////////////////////////////////////////////// +// +// Version +// + +VS_VERSION_INFO VERSIONINFO + FILEVERSION FILEVER + PRODUCTVERSION PRODUCTVER + FILEFLAGSMASK 0x17L +#ifdef _DEBUG + FILEFLAGS 0x1L +#else + FILEFLAGS 0x0L +#endif + FILEOS 0x4L + FILETYPE 0x1L + FILESUBTYPE 0x0L +{ + BLOCK "StringFileInfo" + { + BLOCK "040904E4" + { + VALUE "FileDescription", "Rainmeter Skin Installer" + VALUE "FileVersion", STRFILEVER + VALUE "LegalCopyright", "© 2013 - All authors" + VALUE "OriginalFilename", "SkinInstaller.exe" + VALUE "ProductName", "Rainmeter" +#ifdef _WIN64 + VALUE "ProductVersion", STRPRODUCTVER " (64-bit)" +#else + VALUE "ProductVersion", STRPRODUCTVER " (32-bit)" +#endif //_WIN64 + } + } + BLOCK "VarFileInfo" + { + VALUE "Translation", 0x409, 1252 + } +} + +///////////////////////////////////////////////////////////////////////////// +// +// Icon +// + +// Icon with lowest ID value placed first to ensure application icon +// remains consistent on all systems. +IDI_SKININSTALLER ICON DISCARDABLE "res/Rainstaller.ico" diff --git a/SkinInstaller/SkinInstallerLauncher.vcxproj b/SkinInstaller/SkinInstallerLauncher.vcxproj new file mode 100644 index 00000000..aa335ba6 --- /dev/null +++ b/SkinInstaller/SkinInstallerLauncher.vcxproj @@ -0,0 +1,98 @@ + + + + + {2D8F1DDB-6470-45A1-B95A-3E2960641314} + Application + SkinInstallerLauncher + + + + + + + + + + + + SkinInstaller + + + SkinInstaller + + + SkinInstaller + + + SkinInstaller + + + + 4018;4090;4114;4267;4351;4786;4800;4996 + + + Windows + wWinMainCRTStartup + Shlwapi.lib;%(AdditionalDependencies) + + + ..\Application\Application.manifest + + + + + 4018;4090;4114;4267;4351;4786;4800;4996 + + + Windows + wWinMainCRTStartup + Shlwapi.lib;%(AdditionalDependencies) + + + ..\Application\Application.manifest + + + + + 4018;4090;4114;4267;4351;4786;4800;4996 + MultiThreaded + false + + + Windows + Main + true + Shlwapi.lib;%(AdditionalDependencies) + + + ..\Application\Application.manifest + + + + + /GA %(AdditionalOptions) + 4018;4090;4114;4267;4351;4786;4800;4996 + MultiThreaded + false + + + Windows + Main + true + Shlwapi.lib;%(AdditionalDependencies) + + + ..\Application\Application.manifest + + + + + + + + + + + + \ No newline at end of file diff --git a/SkinInstaller/SkinInstallerLauncher.vcxproj.filters b/SkinInstaller/SkinInstallerLauncher.vcxproj.filters new file mode 100644 index 00000000..a5dc8c34 --- /dev/null +++ b/SkinInstaller/SkinInstallerLauncher.vcxproj.filters @@ -0,0 +1,27 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Resource Files + + + + + Source Files + + + \ No newline at end of file