2011-11-27 13:24:37 +00:00
|
|
|
/*
|
|
|
|
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
|
2012-01-23 06:36:15 +00:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2011-11-27 13:24:37 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "StdAfx.h"
|
2012-06-16 18:56:46 +00:00
|
|
|
#include "DialogPackage.h"
|
2012-06-08 12:53:33 +00:00
|
|
|
#include "DialogInstall.h"
|
2011-11-27 13:24:37 +00:00
|
|
|
#include "resource.h"
|
|
|
|
#include "Application.h"
|
|
|
|
|
2012-06-08 12:53:33 +00:00
|
|
|
GlobalData g_Data;
|
2011-11-27 13:24:37 +00:00
|
|
|
|
2012-06-16 18:56:46 +00:00
|
|
|
OsNameVersion g_OsNameVersions[] =
|
|
|
|
{
|
|
|
|
{ L"XP", L"5.1" },
|
|
|
|
{ L"Vista", L"6.0" },
|
|
|
|
{ L"7", L"6.1" },
|
|
|
|
// { L"8", L"6.2" }
|
|
|
|
};
|
|
|
|
|
2011-11-27 13:24:37 +00:00
|
|
|
/*
|
|
|
|
** Entry point
|
2012-02-21 09:03:16 +00:00
|
|
|
**
|
2011-11-27 13:24:37 +00:00
|
|
|
*/
|
|
|
|
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow)
|
|
|
|
{
|
|
|
|
// Avoid loading a dll from current directory
|
|
|
|
SetDllDirectory(L"");
|
|
|
|
|
2012-06-08 12:53:33 +00:00
|
|
|
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
|
|
|
|
InitCommonControls();
|
|
|
|
|
|
|
|
if (lpCmdLine[0] == L'"')
|
|
|
|
{
|
|
|
|
// Strip quotes
|
|
|
|
++lpCmdLine;
|
|
|
|
WCHAR* pos = wcsrchr(lpCmdLine, L'"');
|
|
|
|
if (pos)
|
|
|
|
{
|
|
|
|
*pos = L'\0';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-27 13:24:37 +00:00
|
|
|
WCHAR buffer[MAX_PATH];
|
|
|
|
GetModuleFileName(hInstance, buffer, MAX_PATH);
|
|
|
|
|
|
|
|
// Remove the module's name from the path
|
|
|
|
WCHAR* pos = wcsrchr(buffer, L'\\');
|
|
|
|
if (pos)
|
|
|
|
{
|
|
|
|
*(pos + 1) = L'\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
g_Data.programPath = g_Data.settingsPath = buffer;
|
|
|
|
wcscat(buffer, L"Rainmeter.ini");
|
|
|
|
|
|
|
|
// Find the settings file and read skins path off it
|
|
|
|
if (_waccess(buffer, 0) == 0)
|
|
|
|
{
|
2011-11-27 14:14:39 +00:00
|
|
|
g_Data.iniFile = buffer;
|
2011-11-27 13:24:37 +00:00
|
|
|
if (GetPrivateProfileString(L"Rainmeter", L"SkinPath", L"", buffer, MAX_LINE_LENGTH, buffer) > 0)
|
|
|
|
{
|
|
|
|
g_Data.skinsPath = buffer;
|
2012-06-28 07:24:30 +00:00
|
|
|
if (g_Data.skinsPath.back() != L'\\' && g_Data.skinsPath.back() != L'/')
|
2012-06-17 13:29:34 +00:00
|
|
|
{
|
|
|
|
g_Data.skinsPath += L'\\';
|
|
|
|
}
|
2011-11-27 13:24:37 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_Data.skinsPath = g_Data.programPath;
|
|
|
|
g_Data.skinsPath += L"Skins\\";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
HRESULT hr = SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, buffer);
|
|
|
|
wcscat(buffer, L"\\Rainmeter\\");
|
|
|
|
g_Data.settingsPath = buffer;
|
|
|
|
wcscat(buffer, L"Rainmeter.ini");
|
2011-11-27 14:14:39 +00:00
|
|
|
g_Data.iniFile = buffer;
|
2011-11-27 13:24:37 +00:00
|
|
|
if (SUCCEEDED(hr) && _waccess(buffer, 0) == 0)
|
|
|
|
{
|
|
|
|
if (GetPrivateProfileString(L"Rainmeter", L"SkinPath", L"", buffer, MAX_LINE_LENGTH, buffer) > 0)
|
|
|
|
{
|
|
|
|
g_Data.skinsPath = buffer;
|
2012-06-28 07:24:30 +00:00
|
|
|
if (g_Data.skinsPath.back() != L'\\' && g_Data.skinsPath.back() != L'/')
|
2012-06-26 17:20:36 +00:00
|
|
|
{
|
|
|
|
g_Data.skinsPath += L'\\';
|
|
|
|
}
|
2011-11-27 13:24:37 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::wstring error = L"SkinPath not found.\nMake sure that Rainmeter has been run at least once.";
|
2012-06-16 18:56:46 +00:00
|
|
|
MessageBox(NULL, error.c_str(), L"Rainmeter Skin Installer", MB_ERROR);
|
2011-11-27 13:24:37 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::wstring error = L"Rainmeter.ini not found.\nMake sure that Rainmeter has been run at least once.";
|
2012-06-16 18:56:46 +00:00
|
|
|
MessageBox(NULL, error.c_str(), L"Rainmeter Skin Installer", MB_ERROR);
|
2011-11-27 13:24:37 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-08 12:53:33 +00:00
|
|
|
if (_wcsnicmp(lpCmdLine, L"/LoadTheme ", 11) == 0)
|
2011-11-27 14:14:39 +00:00
|
|
|
{
|
2012-06-08 12:53:33 +00:00
|
|
|
// Skip "/LoadTheme "
|
2011-11-27 14:14:39 +00:00
|
|
|
lpCmdLine += 11;
|
|
|
|
|
2012-06-16 18:56:46 +00:00
|
|
|
if (*lpCmdLine && CloseRainmeterIfActive())
|
2011-11-27 14:14:39 +00:00
|
|
|
{
|
2012-06-08 12:53:33 +00:00
|
|
|
CDialogInstall::LoadTheme(lpCmdLine, true);
|
2011-11-27 14:14:39 +00:00
|
|
|
|
|
|
|
std::wstring file = g_Data.programPath + L"Rainmeter.exe";
|
|
|
|
SHELLEXECUTEINFO sei = {0};
|
|
|
|
sei.cbSize = sizeof(SHELLEXECUTEINFO);
|
|
|
|
sei.fMask = SEE_MASK_UNICODE;
|
|
|
|
sei.lpFile = file.c_str();
|
2012-06-08 12:53:33 +00:00
|
|
|
sei.lpDirectory = g_Data.programPath.c_str();
|
2011-11-27 14:14:39 +00:00
|
|
|
sei.nShow = SW_SHOWNORMAL;
|
|
|
|
ShellExecuteEx(&sei);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2012-06-16 18:56:46 +00:00
|
|
|
else if (wcscmp(lpCmdLine, L"/Packager") == 0)
|
2011-11-27 14:14:39 +00:00
|
|
|
{
|
2012-06-16 18:56:46 +00:00
|
|
|
CDialogPackage::Create(hInstance, lpCmdLine);
|
2012-06-08 12:53:33 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CDialogInstall::Create(hInstance, lpCmdLine);
|
2011-11-27 14:14:39 +00:00
|
|
|
}
|
|
|
|
|
2011-11-27 13:24:37 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-11-27 14:14:39 +00:00
|
|
|
bool CloseRainmeterIfActive()
|
|
|
|
{
|
|
|
|
// Close Rainmeter.exe
|
|
|
|
HWND hwnd = FindWindow(L"DummyRainWClass", L"Rainmeter control window");
|
|
|
|
if (hwnd)
|
|
|
|
{
|
|
|
|
DWORD pID, exitCode;
|
|
|
|
GetWindowThreadProcessId(hwnd, &pID);
|
|
|
|
HANDLE hProcess = OpenProcess(PROCESS_TERMINATE | SYNCHRONIZE, FALSE, pID);
|
|
|
|
PostMessage(hwnd, WM_DESTROY, 0, 0);
|
|
|
|
|
|
|
|
// Wait up to 5 seconds for Rainmeter to close
|
|
|
|
WaitForSingleObject(hProcess, 5000);
|
|
|
|
GetExitCodeProcess(hProcess, &exitCode);
|
|
|
|
CloseHandle(hProcess);
|
|
|
|
|
|
|
|
if (exitCode == STILL_ACTIVE)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------------------------
|
|
|
|
// Stolen functions from Rainmeter Litestep.cpp, System.cpp, and Application.cpp
|
|
|
|
// -----------------------------------------------------------------------------------------------
|
|
|
|
|
2011-11-27 13:24:37 +00:00
|
|
|
bool IsRunning(const WCHAR* name, HANDLE* hMutex)
|
|
|
|
{
|
|
|
|
// Create mutex
|
|
|
|
HANDLE hMutexTmp = CreateMutex(NULL, FALSE, name);
|
|
|
|
if (GetLastError() == ERROR_ALREADY_EXISTS)
|
|
|
|
{
|
|
|
|
*hMutex = NULL;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*hMutex = hMutexTmp;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-27 14:14:39 +00:00
|
|
|
bool CopyFiles(const std::wstring& strFrom, const std::wstring& strTo, bool bMove)
|
|
|
|
{
|
|
|
|
std::wstring tmpFrom(strFrom), tmpTo(strTo);
|
|
|
|
|
|
|
|
// The strings must end with double nul
|
|
|
|
tmpFrom.append(1, L'\0');
|
|
|
|
tmpTo.append(1, L'\0');
|
|
|
|
|
|
|
|
SHFILEOPSTRUCT fo =
|
|
|
|
{
|
|
|
|
NULL,
|
|
|
|
bMove ? FO_MOVE : FO_COPY,
|
|
|
|
tmpFrom.c_str(),
|
|
|
|
tmpTo.c_str(),
|
|
|
|
FOF_NO_UI | FOF_NOCONFIRMATION | FOF_ALLOWUNDO
|
|
|
|
};
|
|
|
|
|
2011-11-27 18:51:39 +00:00
|
|
|
return SHFileOperation(&fo) == 0;
|
2011-11-27 14:14:39 +00:00
|
|
|
}
|
|
|
|
|
2011-11-27 18:18:34 +00:00
|
|
|
OSPLATFORM GetOSPlatform()
|
|
|
|
{
|
|
|
|
OSVERSIONINFOEX osvi = {sizeof(OSVERSIONINFOEX)};
|
|
|
|
if (GetVersionEx((OSVERSIONINFO*)&osvi))
|
|
|
|
{
|
|
|
|
if (osvi.dwMajorVersion == 5)
|
|
|
|
{
|
|
|
|
// Not checking for osvi.dwMinorVersion >= 1 because Rainmeter won't run on pre-XP
|
|
|
|
return OSPLATFORM_XP;
|
|
|
|
}
|
|
|
|
else if (osvi.dwMajorVersion == 6)
|
|
|
|
{
|
|
|
|
if (osvi.dwMinorVersion == 0)
|
|
|
|
{
|
|
|
|
return OSPLATFORM_VISTA; // Vista, Server 2008
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return OSPLATFORM_7; // 7, Server 2008R2
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else // newer OS
|
|
|
|
{
|
|
|
|
return OSPLATFORM_7;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return OSPLATFORM_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
2011-11-27 13:24:37 +00:00
|
|
|
std::string ConvertToAscii(LPCTSTR str)
|
|
|
|
{
|
|
|
|
std::string szAscii;
|
|
|
|
|
|
|
|
if (str && *str)
|
|
|
|
{
|
|
|
|
int strLen = (int)wcslen(str);
|
|
|
|
int bufLen = WideCharToMultiByte(CP_ACP, 0, str, strLen, NULL, 0, NULL, NULL);
|
|
|
|
if (bufLen > 0)
|
|
|
|
{
|
|
|
|
szAscii.resize(bufLen);
|
|
|
|
WideCharToMultiByte(CP_ACP, 0, str, strLen, &szAscii[0], bufLen, NULL, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return szAscii;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::wstring ConvertToWide(LPCSTR str)
|
|
|
|
{
|
|
|
|
std::wstring szWide;
|
|
|
|
|
|
|
|
if (str && *str)
|
|
|
|
{
|
|
|
|
int strLen = (int)strlen(str);
|
|
|
|
int bufLen = MultiByteToWideChar(CP_ACP, 0, str, strLen, NULL, 0);
|
|
|
|
if (bufLen > 0)
|
|
|
|
{
|
|
|
|
szWide.resize(bufLen);
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, str, strLen, &szWide[0], bufLen);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return szWide;
|
|
|
|
}
|