From 83f1b1ae0eee76c7a5af0c5a4e31ccc0a1bc7fd2 Mon Sep 17 00:00:00 2001 From: Birunthan Mohanathas Date: Sat, 9 Jun 2012 19:45:27 +0300 Subject: [PATCH] Added workaround for old plugins using relative path to Rainmeter.exe --- Application/Launcher/Launcher.cpp | 46 +++++ Application/Launcher/Launcher.vcxproj | 190 ++++++++++++++++++ Application/Launcher/Launcher.vcxproj.filters | 22 ++ Build/Installer/Installer.nsi | 5 + Library/Rainmeter.cpp | 42 ++-- Library/Rainmeter.h | 2 +- Rainmeter.sln | 10 + RainmeterCPP.sln | 10 + 8 files changed, 312 insertions(+), 15 deletions(-) create mode 100644 Application/Launcher/Launcher.cpp create mode 100644 Application/Launcher/Launcher.vcxproj create mode 100644 Application/Launcher/Launcher.vcxproj.filters diff --git a/Application/Launcher/Launcher.cpp b/Application/Launcher/Launcher.cpp new file mode 100644 index 00000000..307bb078 --- /dev/null +++ b/Application/Launcher/Launcher.cpp @@ -0,0 +1,46 @@ +/* + Copyright (C) 2012 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 +#include "../../Library/Rainmeter.h" + +/* +** Entry point. +** +*/ +int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow) +{ + HKEY hKey; + if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"Software\\Rainmeter", 0, KEY_QUERY_VALUE | KEY_WOW64_32KEY, &hKey) == ERROR_SUCCESS) + { + const DWORD size = MAX_PATH; + WCHAR buffer[size]; + DWORD type = 0; + if (RegQueryValueEx(hKey, NULL , NULL, &type, (LPBYTE)buffer, (LPDWORD)&size) == ERROR_SUCCESS && type == REG_SZ) + { + SetCurrentDirectory(buffer); + wcscat(buffer, L"\\Rainmeter.exe"); + ShellExecute(NULL, L"open", buffer, lpCmdLine, NULL, SW_SHOWNORMAL); + } + RegCloseKey(hKey); + } + + return 0; +} diff --git a/Application/Launcher/Launcher.vcxproj b/Application/Launcher/Launcher.vcxproj new file mode 100644 index 00000000..d2c85fea --- /dev/null +++ b/Application/Launcher/Launcher.vcxproj @@ -0,0 +1,190 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {A50FCF58-CDEA-41A9-B885-4C31E9E2859F} + + + + + Application + Unicode + true + + + Application + true + Unicode + + + Application + Unicode + $(COMPILER64) + true + + + Application + true + Unicode + $(COMPILER64) + + + + + + + + + + + + + + + + + + + <_ProjectFileVersion>10.0.30319.1 + $(SolutionDir)TestBench\x32\$(Configuration)\ + .\x32\$(Configuration)\ + true + $(SolutionDir)TestBench\x64\$(Configuration)\ + .\x64\$(Configuration)\ + true + $(SolutionDir)TestBench\x32\$(Configuration)\ + .\x32\$(Configuration)\ + $(SolutionDir)TestBench\x64\$(Configuration)\ + .\x64\$(Configuration)\ + Launcher + Launcher + Launcher + Launcher + + + + Disabled + WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) + EnableFastChecks + + + Level3 + EditAndContinue + 4018;4090;4114;4267;4351;4786;4800;4996 + false + + + _DEBUG;%(PreprocessorDefinitions) + 0x0409 + + + ../../TestBench/x32/Debug/Launcher.exe + true + Windows + wWinMainCRTStartup + MachineX86 + $(IntDir)$(TargetName).pdb + + + + + Disabled + WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) + EnableFastChecks + + + Level3 + ProgramDatabase + 4018;4090;4114;4267;4351;4786;4800;4996 + false + + + _DEBUG;_WIN64;%(PreprocessorDefinitions) + 0x0409 + + + ../../TestBench/x64/Debug/Launcher.exe + true + Windows + wWinMainCRTStartup + MachineX64 + $(IntDir)$(TargetName).pdb + + + + + MaxSpeed + WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) + + + Level3 + ProgramDatabase + 4018;4090;4114;4267;4351;4786;4800;4996 + false + + + NDEBUG;%(PreprocessorDefinitions) + 0x0409 + + + ../../TestBench/x32/Release/Launcher.exe + ..\Library\x32\Release;%(AdditionalLibraryDirectories) + Windows + wWinMainCRTStartup + MachineX86 + .rdata=.text + true + true + $(IntDir)$(TargetName).pdb + + + + + /GA %(AdditionalOptions) + MaxSpeed + WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) + Level3 + ProgramDatabase + 4018;4090;4114;4267;4351;4786;4800;4996 + false + + + NDEBUG;_WIN64;%(PreprocessorDefinitions) + 0x0409 + + + ../../TestBench/x64/Release/Launcher.exe + ..\Library\x64\Release;%(AdditionalLibraryDirectories) + Windows + wWinMainCRTStartup + MachineX64 + .rdata=.text + true + true + $(IntDir)$(TargetName).pdb + + + + + + + + + \ No newline at end of file diff --git a/Application/Launcher/Launcher.vcxproj.filters b/Application/Launcher/Launcher.vcxproj.filters new file mode 100644 index 00000000..2810dc83 --- /dev/null +++ b/Application/Launcher/Launcher.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {22670730-eb79-4df9-bed9-27fff1350132} + cpp;c;cxx;rc;def;r;odl;idl;hpj;bat + + + {774a1827-ac91-40b9-ad18-8a3d68983c64} + h;hpp;hxx;hm;inl + + + {a4963a10-e359-400f-86fa-bdce98dd5dc2} + ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe + + + + + Source Files + + + \ No newline at end of file diff --git a/Build/Installer/Installer.nsi b/Build/Installer/Installer.nsi index 8fb376dc..359356e8 100644 --- a/Build/Installer/Installer.nsi +++ b/Build/Installer/Installer.nsi @@ -506,6 +506,11 @@ FunctionEnd File "..\..\TestBench\${DIR}\Release\Rainmeter.dll" File "..\..\TestBench\${DIR}\Release\SkinInstaller.exe" + ${If} $InstallPortable != 1 + File "..\..\TestBench\${DIR}\Release\Launcher.exe" + SetFileAttributes "$INSTDIR\Launcher.exe" HIDDEN + ${EndIf} + SetOutPath "$INSTDIR\Plugins" File /x *Example*.dll "..\..\TestBench\${DIR}\Release\Plugins\*.dll" !macroend diff --git a/Library/Rainmeter.cpp b/Library/Rainmeter.cpp index aaee1bad..874d528a 100644 --- a/Library/Rainmeter.cpp +++ b/Library/Rainmeter.cpp @@ -911,7 +911,7 @@ int CRainmeter::Initialize(LPCWSTR iniPath) } // Create user skins, themes, addons, and plugins folders if needed - CreateComponentFolders(); + CreateComponentFolders(bDefaultIniLocation); // Create a default Rainmeter.ini file if needed if (_waccess(iniFile, 0) == -1) @@ -1180,7 +1180,7 @@ void CRainmeter::CreateDataFile() } } -void CRainmeter::CreateComponentFolders() +void CRainmeter::CreateComponentFolders(bool defaultIniLocation) { if (CreateDirectory(m_SkinPath.c_str(), NULL)) { @@ -1200,23 +1200,37 @@ void CRainmeter::CreateComponentFolders() } } - path = GetUserPluginPath(); - if (_waccess(path.c_str(), 0) == -1) + if (defaultIniLocation) { - std::wstring from = GetDefaultPluginPath(); - if (_waccess(from.c_str(), 0) != -1) + path = GetUserPluginPath(); + if (_waccess(path.c_str(), 0) == -1) { - CSystem::CopyFiles(from, m_SettingsPath); + std::wstring from = GetDefaultPluginPath(); + if (_waccess(from.c_str(), 0) != -1) + { + CSystem::CopyFiles(from, m_SettingsPath); + } } - } - path = GetAddonPath(); - if (_waccess(path.c_str(), 0) == -1) - { - std::wstring from = GetDefaultAddonPath(); - if (_waccess(from.c_str(), 0) != -1) + path = GetAddonPath(); + if (_waccess(path.c_str(), 0) == -1) { - CSystem::CopyFiles(from, m_SettingsPath); + std::wstring from = GetDefaultAddonPath(); + if (_waccess(from.c_str(), 0) != -1) + { + CSystem::CopyFiles(from, m_SettingsPath); + } + } + + path = m_SettingsPath; + path += L"Rainmeter.exe"; + if (_waccess(path.c_str(), 0) == -1) + { + // Create a hidden dummy Rainmeter.exe into SettingsPath for old addon + // using relative path to Rainmeter.exe + std::wstring from = m_Path + L"Launcher.exe"; + CSystem::CopyFiles(from, path); + SetFileAttributes(path.c_str(), FILE_ATTRIBUTE_HIDDEN); } } } diff --git a/Library/Rainmeter.h b/Library/Rainmeter.h index 4e6e567f..99873280 100644 --- a/Library/Rainmeter.h +++ b/Library/Rainmeter.h @@ -257,7 +257,7 @@ private: void CreateMonitorMenu(HMENU monitorMenu, CMeterWindow* meterWindow); void CreateOptionsFile(); void CreateDataFile(); - void CreateComponentFolders(); + void CreateComponentFolders(bool defaultIniLocation); void SetLogging(bool logging); void TestSettingsFile(bool bDefaultIniLocation); diff --git a/Rainmeter.sln b/Rainmeter.sln index c3f28afd..83472d0c 100644 --- a/Rainmeter.sln +++ b/Rainmeter.sln @@ -5,6 +5,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Application", "Application\ EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Language", "Language\Language.vcxproj", "{6BE6F228-B741-4DA9-9FBC-E9F2A7BD483A}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Launcher", "Application\Launcher\Launcher.vcxproj", "{A50FCF58-CDEA-41A9-B885-4C31E9E2859F}" +EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Library", "Library\Library.vcxproj", "{BE9D2400-7F1C-49D6-8498-5CE495491AD6}" ProjectSection(ProjectDependencies) = postProject {6BE6F228-B741-4DA9-9FBC-E9F2A7BD483A} = {6BE6F228-B741-4DA9-9FBC-E9F2A7BD483A} @@ -80,6 +82,14 @@ Global {6BE6F228-B741-4DA9-9FBC-E9F2A7BD483A}.Release|Win32.Build.0 = Release|Win32 {6BE6F228-B741-4DA9-9FBC-E9F2A7BD483A}.Release|x64.ActiveCfg = Release|x64 {6BE6F228-B741-4DA9-9FBC-E9F2A7BD483A}.Release|x64.Build.0 = Release|x64 + {A50FCF58-CDEA-41A9-B885-4C31E9E2859F}.Debug|Win32.ActiveCfg = Debug|Win32 + {A50FCF58-CDEA-41A9-B885-4C31E9E2859F}.Debug|Win32.Build.0 = Debug|Win32 + {A50FCF58-CDEA-41A9-B885-4C31E9E2859F}.Debug|x64.ActiveCfg = Debug|x64 + {A50FCF58-CDEA-41A9-B885-4C31E9E2859F}.Debug|x64.Build.0 = Debug|x64 + {A50FCF58-CDEA-41A9-B885-4C31E9E2859F}.Release|Win32.ActiveCfg = Release|Win32 + {A50FCF58-CDEA-41A9-B885-4C31E9E2859F}.Release|Win32.Build.0 = Release|Win32 + {A50FCF58-CDEA-41A9-B885-4C31E9E2859F}.Release|x64.ActiveCfg = Release|x64 + {A50FCF58-CDEA-41A9-B885-4C31E9E2859F}.Release|x64.Build.0 = Release|x64 {BE9D2400-7F1C-49D6-8498-5CE495491AD6}.Debug|Win32.ActiveCfg = Debug|Win32 {BE9D2400-7F1C-49D6-8498-5CE495491AD6}.Debug|Win32.Build.0 = Debug|Win32 {BE9D2400-7F1C-49D6-8498-5CE495491AD6}.Debug|x64.ActiveCfg = Debug|x64 diff --git a/RainmeterCPP.sln b/RainmeterCPP.sln index 1bb0857d..19551d62 100644 --- a/RainmeterCPP.sln +++ b/RainmeterCPP.sln @@ -4,6 +4,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Application", "Application\ EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Language", "Language\Language.vcxproj", "{6BE6F228-B741-4DA9-9FBC-E9F2A7BD483A}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Launcher", "Application\Launcher\Launcher.vcxproj", "{A50FCF58-CDEA-41A9-B885-4C31E9E2859F}" +EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Library", "Library\Library.vcxproj", "{BE9D2400-7F1C-49D6-8498-5CE495491AD6}" ProjectSection(ProjectDependencies) = postProject {6BE6F228-B741-4DA9-9FBC-E9F2A7BD483A} = {6BE6F228-B741-4DA9-9FBC-E9F2A7BD483A} @@ -75,6 +77,14 @@ Global {6BE6F228-B741-4DA9-9FBC-E9F2A7BD483A}.Release|Win32.Build.0 = Release|Win32 {6BE6F228-B741-4DA9-9FBC-E9F2A7BD483A}.Release|x64.ActiveCfg = Release|x64 {6BE6F228-B741-4DA9-9FBC-E9F2A7BD483A}.Release|x64.Build.0 = Release|x64 + {A50FCF58-CDEA-41A9-B885-4C31E9E2859F}.Debug|Win32.ActiveCfg = Debug|Win32 + {A50FCF58-CDEA-41A9-B885-4C31E9E2859F}.Debug|Win32.Build.0 = Debug|Win32 + {A50FCF58-CDEA-41A9-B885-4C31E9E2859F}.Debug|x64.ActiveCfg = Debug|x64 + {A50FCF58-CDEA-41A9-B885-4C31E9E2859F}.Debug|x64.Build.0 = Debug|x64 + {A50FCF58-CDEA-41A9-B885-4C31E9E2859F}.Release|Win32.ActiveCfg = Release|Win32 + {A50FCF58-CDEA-41A9-B885-4C31E9E2859F}.Release|Win32.Build.0 = Release|Win32 + {A50FCF58-CDEA-41A9-B885-4C31E9E2859F}.Release|x64.ActiveCfg = Release|x64 + {A50FCF58-CDEA-41A9-B885-4C31E9E2859F}.Release|x64.Build.0 = Release|x64 {BE9D2400-7F1C-49D6-8498-5CE495491AD6}.Debug|Win32.ActiveCfg = Debug|Win32 {BE9D2400-7F1C-49D6-8498-5CE495491AD6}.Debug|Win32.Build.0 = Debug|Win32 {BE9D2400-7F1C-49D6-8498-5CE495491AD6}.Debug|x64.ActiveCfg = Debug|x64