2009-02-10 18:37:48 +00:00
|
|
|
/*
|
|
|
|
Copyright (C) 2001 Kimmo Pekkola
|
|
|
|
|
|
|
|
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.
|
2009-02-10 18:37:48 +00:00
|
|
|
*/
|
|
|
|
|
2009-10-07 16:45:14 +00:00
|
|
|
#include "StdAfx.h"
|
2013-06-12 18:14:55 +00:00
|
|
|
#include "../Common/PathUtil.h"
|
2009-02-10 18:37:48 +00:00
|
|
|
#include "Rainmeter.h"
|
2011-02-07 08:02:12 +00:00
|
|
|
#include "TrayWindow.h"
|
2010-03-20 19:40:30 +00:00
|
|
|
#include "System.h"
|
2009-02-10 18:37:48 +00:00
|
|
|
#include "Error.h"
|
2011-08-28 10:58:26 +00:00
|
|
|
#include "DialogAbout.h"
|
|
|
|
#include "DialogManage.h"
|
2009-02-10 18:37:48 +00:00
|
|
|
#include "MeasureNet.h"
|
2012-11-12 02:10:40 +00:00
|
|
|
#include "MeasureCPU.h"
|
2009-10-07 16:45:14 +00:00
|
|
|
#include "MeterString.h"
|
2009-02-10 18:37:48 +00:00
|
|
|
#include "UpdateCheck.h"
|
2011-02-07 08:02:12 +00:00
|
|
|
#include "../Version.h"
|
2009-02-10 18:37:48 +00:00
|
|
|
|
|
|
|
using namespace Gdiplus;
|
|
|
|
|
2012-02-15 02:51:27 +00:00
|
|
|
enum TIMER
|
|
|
|
{
|
|
|
|
TIMER_NETSTATS = 1
|
|
|
|
};
|
|
|
|
enum INTERVAL
|
|
|
|
{
|
|
|
|
INTERVAL_NETSTATS = 120000
|
|
|
|
};
|
|
|
|
|
2011-09-29 06:04:20 +00:00
|
|
|
/*
|
2012-02-14 17:00:07 +00:00
|
|
|
** Initializes Rainmeter.
|
2011-09-29 06:04:20 +00:00
|
|
|
**
|
|
|
|
*/
|
2012-02-16 17:38:45 +00:00
|
|
|
int RainmeterMain(LPWSTR cmdLine)
|
2011-09-29 06:04:20 +00:00
|
|
|
{
|
2012-10-06 17:12:40 +00:00
|
|
|
// Avoid loading a dll from current directory
|
|
|
|
SetDllDirectory(L"");
|
|
|
|
|
2013-05-31 14:28:39 +00:00
|
|
|
const WCHAR* layout = nullptr;
|
2012-10-06 17:12:40 +00:00
|
|
|
|
2012-05-24 06:19:52 +00:00
|
|
|
if (cmdLine[0] == L'!' || cmdLine[0] == L'[')
|
2011-09-29 06:04:20 +00:00
|
|
|
{
|
2012-05-24 06:19:52 +00:00
|
|
|
HWND wnd = FindWindow(RAINMETER_CLASS_NAME, RAINMETER_WINDOW_NAME);
|
|
|
|
if (wnd)
|
2012-02-14 17:00:07 +00:00
|
|
|
{
|
|
|
|
// Deliver bang to existing Rainmeter instance
|
2012-05-24 06:19:52 +00:00
|
|
|
COPYDATASTRUCT cds;
|
2012-02-14 17:00:07 +00:00
|
|
|
cds.dwData = 1;
|
|
|
|
cds.cbData = (DWORD)((wcslen(cmdLine) + 1) * sizeof(WCHAR));
|
|
|
|
cds.lpData = (PVOID)cmdLine;
|
2013-05-31 14:28:39 +00:00
|
|
|
SendMessage(wnd, WM_COPYDATA, 0, (LPARAM)&cds);
|
2012-02-14 17:00:07 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2012-05-24 09:19:32 +00:00
|
|
|
|
2012-10-06 17:12:40 +00:00
|
|
|
// Disallow everything except !LoadLayout.
|
2012-10-06 17:20:39 +00:00
|
|
|
if (_wcsnicmp(cmdLine, L"!LoadLayout ", 12) == 0)
|
2012-10-06 17:12:40 +00:00
|
|
|
{
|
2012-10-06 17:27:19 +00:00
|
|
|
layout = cmdLine + 12; // Skip "!LoadLayout ".
|
2012-10-06 17:12:40 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2012-05-24 09:19:32 +00:00
|
|
|
}
|
|
|
|
else if (cmdLine[0] == L'"')
|
|
|
|
{
|
|
|
|
// Strip quotes
|
|
|
|
++cmdLine;
|
|
|
|
WCHAR* pos = wcsrchr(cmdLine, L'"');
|
|
|
|
if (pos)
|
2011-09-29 06:04:20 +00:00
|
|
|
{
|
2012-05-24 09:19:32 +00:00
|
|
|
*pos = L'\0';
|
2011-09-29 06:04:20 +00:00
|
|
|
}
|
|
|
|
}
|
2012-02-14 17:00:07 +00:00
|
|
|
|
2013-05-31 14:28:39 +00:00
|
|
|
const WCHAR* iniFile = (*cmdLine && !layout) ? cmdLine : nullptr;
|
2012-05-24 09:19:32 +00:00
|
|
|
|
2013-06-13 14:20:27 +00:00
|
|
|
auto& rainmeter = GetRainmeter();
|
|
|
|
int ret = rainmeter.Initialize(iniFile, layout);
|
2012-07-18 06:22:47 +00:00
|
|
|
if (ret == 0)
|
2011-09-29 06:04:20 +00:00
|
|
|
{
|
2013-06-13 14:20:27 +00:00
|
|
|
ret = rainmeter.MessagePump();
|
2011-09-29 06:04:20 +00:00
|
|
|
}
|
2013-06-14 13:58:42 +00:00
|
|
|
rainmeter.Finalize();
|
2011-09-29 06:04:20 +00:00
|
|
|
|
2012-02-14 17:00:07 +00:00
|
|
|
return ret;
|
2010-12-11 16:30:49 +00:00
|
|
|
}
|
2009-02-10 18:37:48 +00:00
|
|
|
|
2011-03-29 19:21:57 +00:00
|
|
|
/*
|
2009-02-10 18:37:48 +00:00
|
|
|
** Constructor
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
Rainmeter::Rainmeter() :
|
2011-01-29 00:11:01 +00:00
|
|
|
m_TrayWindow(),
|
2013-03-25 16:00:53 +00:00
|
|
|
m_UseD2D(false),
|
2011-09-28 18:28:35 +00:00
|
|
|
m_Debug(false),
|
2011-08-28 10:58:26 +00:00
|
|
|
m_DisableVersionCheck(false),
|
|
|
|
m_NewVersion(false),
|
2011-01-29 00:11:01 +00:00
|
|
|
m_DesktopWorkAreaChanged(false),
|
|
|
|
m_DesktopWorkAreaType(false),
|
2011-11-10 11:50:47 +00:00
|
|
|
m_NormalStayDesktop(true),
|
2011-01-29 00:11:01 +00:00
|
|
|
m_DisableRDP(false),
|
|
|
|
m_DisableDragging(false),
|
|
|
|
m_CurrentParser(),
|
2012-02-22 10:03:51 +00:00
|
|
|
m_Window(),
|
2012-05-24 11:15:03 +00:00
|
|
|
m_Mutex(),
|
2011-01-29 00:11:01 +00:00
|
|
|
m_Instance(),
|
2011-09-23 16:28:38 +00:00
|
|
|
m_ResourceInstance(),
|
2012-02-22 10:03:51 +00:00
|
|
|
m_ResourceLCID(),
|
2011-09-28 18:28:35 +00:00
|
|
|
m_GDIplusToken(),
|
2012-06-01 13:06:36 +00:00
|
|
|
m_GlobalOptions()
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2013-05-31 14:28:39 +00:00
|
|
|
CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
|
2010-12-05 23:33:51 +00:00
|
|
|
|
2011-08-28 10:58:26 +00:00
|
|
|
InitCommonControls();
|
2009-02-10 18:37:48 +00:00
|
|
|
|
2011-03-29 19:21:57 +00:00
|
|
|
// Initialize GDI+.
|
|
|
|
GdiplusStartupInput gdiplusStartupInput;
|
2013-05-31 14:28:39 +00:00
|
|
|
GdiplusStartup(&m_GDIplusToken, &gdiplusStartupInput, nullptr);
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
|
2011-03-29 19:21:57 +00:00
|
|
|
/*
|
2009-02-10 18:37:48 +00:00
|
|
|
** Destructor
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
Rainmeter::~Rainmeter()
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2011-08-31 11:06:35 +00:00
|
|
|
CoUninitialize();
|
2010-09-19 09:21:25 +00:00
|
|
|
|
2009-02-10 18:37:48 +00:00
|
|
|
GdiplusShutdown(m_GDIplusToken);
|
|
|
|
}
|
|
|
|
|
2013-06-13 14:20:27 +00:00
|
|
|
Rainmeter& Rainmeter::GetInstance()
|
|
|
|
{
|
|
|
|
static Rainmeter s_Rainmeter;
|
|
|
|
return s_Rainmeter;
|
|
|
|
}
|
|
|
|
|
2011-03-29 19:21:57 +00:00
|
|
|
/*
|
2009-02-10 18:37:48 +00:00
|
|
|
** The main initialization function for the module.
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
int Rainmeter::Initialize(LPCWSTR iniPath, LPCWSTR layout)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2012-06-11 13:15:03 +00:00
|
|
|
m_Instance = GetModuleHandle(L"Rainmeter");
|
|
|
|
|
2012-03-22 21:16:41 +00:00
|
|
|
WCHAR* buffer = new WCHAR[MAX_LINE_LENGTH];
|
|
|
|
GetModuleFileName(m_Instance, buffer, MAX_LINE_LENGTH);
|
2009-02-10 18:37:48 +00:00
|
|
|
|
|
|
|
// Remove the module's name from the path
|
2012-03-22 21:16:41 +00:00
|
|
|
WCHAR* pos = wcsrchr(buffer, L'\\');
|
|
|
|
m_Path.assign(buffer, pos ? pos - buffer + 1 : 0);
|
2013-06-12 18:14:55 +00:00
|
|
|
m_Drive = PathUtil::GetVolume(m_Path);
|
2010-09-11 19:39:45 +00:00
|
|
|
|
2011-05-02 11:58:02 +00:00
|
|
|
bool bDefaultIniLocation = false;
|
2012-10-06 17:12:40 +00:00
|
|
|
if (iniPath)
|
2009-07-26 21:08:46 +00:00
|
|
|
{
|
|
|
|
// The command line defines the location of Rainmeter.ini (or whatever it calls it).
|
2012-05-24 09:19:32 +00:00
|
|
|
std::wstring iniFile = iniPath;
|
2013-06-12 18:14:55 +00:00
|
|
|
PathUtil::ExpandEnvironmentVariables(iniFile);
|
2009-07-26 21:08:46 +00:00
|
|
|
|
2013-06-12 18:14:55 +00:00
|
|
|
if (iniFile.empty() || PathUtil::IsSeparator(iniFile[iniFile.length() - 1]))
|
2009-07-26 21:08:46 +00:00
|
|
|
{
|
|
|
|
iniFile += L"Rainmeter.ini";
|
|
|
|
}
|
2011-11-10 13:44:19 +00:00
|
|
|
else if (iniFile.length() <= 4 || _wcsicmp(iniFile.c_str() + (iniFile.length() - 4), L".ini") != 0)
|
2009-07-26 21:08:46 +00:00
|
|
|
{
|
|
|
|
iniFile += L"\\Rainmeter.ini";
|
|
|
|
}
|
|
|
|
|
2013-06-12 18:14:55 +00:00
|
|
|
if (!PathUtil::IsSeparator(iniFile[0]) && iniFile.find_first_of(L':') == std::wstring::npos)
|
2010-08-05 10:46:04 +00:00
|
|
|
{
|
|
|
|
// Make absolute path
|
|
|
|
iniFile.insert(0, m_Path);
|
|
|
|
}
|
|
|
|
|
2009-07-26 21:08:46 +00:00
|
|
|
m_IniFile = iniFile;
|
2011-05-02 11:58:02 +00:00
|
|
|
bDefaultIniLocation = true;
|
2009-07-26 21:08:46 +00:00
|
|
|
}
|
2011-09-28 18:28:35 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
m_IniFile = m_Path;
|
|
|
|
m_IniFile += L"Rainmeter.ini";
|
|
|
|
|
|
|
|
// If the ini file doesn't exist in the program folder store it to the %APPDATA% instead so that things work better in Vista/Win7
|
|
|
|
if (_waccess(m_IniFile.c_str(), 0) == -1)
|
|
|
|
{
|
|
|
|
m_IniFile = L"%APPDATA%\\Rainmeter\\Rainmeter.ini";
|
2013-06-12 18:14:55 +00:00
|
|
|
PathUtil::ExpandEnvironmentVariables(m_IniFile);
|
2011-09-28 18:28:35 +00:00
|
|
|
bDefaultIniLocation = true;
|
|
|
|
}
|
|
|
|
}
|
2009-07-26 21:08:46 +00:00
|
|
|
|
2012-05-24 11:15:03 +00:00
|
|
|
if (IsAlreadyRunning())
|
|
|
|
{
|
|
|
|
// Instance already running with same .ini file
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
WNDCLASS wc = {0};
|
|
|
|
wc.lpfnWndProc = (WNDPROC)MainWndProc;
|
|
|
|
wc.hInstance = m_Instance;
|
|
|
|
wc.lpszClassName = RAINMETER_CLASS_NAME;
|
2012-06-01 13:21:25 +00:00
|
|
|
ATOM className = RegisterClass(&wc);
|
2012-05-24 11:15:03 +00:00
|
|
|
|
|
|
|
m_Window = CreateWindowEx(
|
|
|
|
WS_EX_TOOLWINDOW,
|
2012-06-01 13:21:25 +00:00
|
|
|
MAKEINTATOM(className),
|
2012-05-24 11:15:03 +00:00
|
|
|
RAINMETER_WINDOW_NAME,
|
|
|
|
WS_POPUP | WS_DISABLED,
|
|
|
|
CW_USEDEFAULT,
|
|
|
|
CW_USEDEFAULT,
|
|
|
|
CW_USEDEFAULT,
|
|
|
|
CW_USEDEFAULT,
|
2013-05-31 14:28:39 +00:00
|
|
|
nullptr,
|
|
|
|
nullptr,
|
2012-05-24 11:15:03 +00:00
|
|
|
m_Instance,
|
2013-05-31 14:28:39 +00:00
|
|
|
nullptr);
|
2012-05-24 11:15:03 +00:00
|
|
|
|
|
|
|
if (!m_Window) return 1;
|
|
|
|
|
2013-06-13 14:22:42 +00:00
|
|
|
Logger& logger = GetLogger();
|
2012-05-05 11:45:34 +00:00
|
|
|
const WCHAR* iniFile = m_IniFile.c_str();
|
|
|
|
|
|
|
|
// Set file locations
|
2010-07-07 23:46:44 +00:00
|
|
|
{
|
2013-06-12 18:14:55 +00:00
|
|
|
m_SettingsPath = PathUtil::GetFolderFromFilePath(m_IniFile);
|
2012-06-09 15:38:45 +00:00
|
|
|
|
2012-05-05 11:45:34 +00:00
|
|
|
size_t len = m_IniFile.length();
|
2012-05-29 16:02:20 +00:00
|
|
|
if (len > 4 && _wcsicmp(iniFile + (len - 4), L".ini") == 0)
|
2012-05-05 11:45:34 +00:00
|
|
|
{
|
|
|
|
len -= 4;
|
|
|
|
}
|
|
|
|
|
2013-05-29 19:05:41 +00:00
|
|
|
std::wstring logFile(m_IniFile, 0, len);
|
|
|
|
m_DataFile = m_StatsFile = logFile;
|
|
|
|
logFile += L".log";
|
2012-05-05 11:45:34 +00:00
|
|
|
m_StatsFile += L".stats";
|
|
|
|
m_DataFile += L".data";
|
2013-05-29 19:05:41 +00:00
|
|
|
|
|
|
|
logger.SetLogFilePath(logFile);
|
2010-07-07 23:46:44 +00:00
|
|
|
}
|
2012-05-05 11:45:34 +00:00
|
|
|
|
2012-06-25 07:29:50 +00:00
|
|
|
// Create a default Rainmeter.ini file if needed
|
|
|
|
if (_waccess(iniFile, 0) == -1)
|
|
|
|
{
|
|
|
|
CreateOptionsFile();
|
|
|
|
}
|
|
|
|
|
2012-05-05 11:45:34 +00:00
|
|
|
bool dataFileCreated = false;
|
|
|
|
if (_waccess(m_DataFile.c_str(), 0) == -1)
|
2010-07-07 23:46:44 +00:00
|
|
|
{
|
2012-05-05 11:45:34 +00:00
|
|
|
dataFileCreated = true;
|
|
|
|
CreateDataFile();
|
2010-07-07 23:46:44 +00:00
|
|
|
}
|
|
|
|
|
2012-06-19 11:31:59 +00:00
|
|
|
// Reset log file
|
2013-05-31 14:18:52 +00:00
|
|
|
System::RemoveFile(logger.GetLogFilePath());
|
2012-06-19 11:31:59 +00:00
|
|
|
|
|
|
|
m_Debug = 0!=GetPrivateProfileInt(L"Rainmeter", L"Debug", 0, iniFile);
|
|
|
|
|
2013-05-29 19:05:41 +00:00
|
|
|
const bool logging = GetPrivateProfileInt(L"Rainmeter", L"Logging", 0, iniFile) != 0;
|
|
|
|
logger.SetLogToFile(logging);
|
|
|
|
if (logging)
|
2012-06-19 11:31:59 +00:00
|
|
|
{
|
2013-05-29 19:05:41 +00:00
|
|
|
logger.StartLogFile();
|
2012-06-19 11:31:59 +00:00
|
|
|
}
|
|
|
|
|
2011-10-01 17:39:09 +00:00
|
|
|
// Determine the language resource to load
|
|
|
|
std::wstring resource = m_Path + L"Languages\\";
|
2012-05-05 11:45:34 +00:00
|
|
|
if (GetPrivateProfileString(L"Rainmeter", L"Language", L"", buffer, MAX_LINE_LENGTH, iniFile) == 0)
|
2011-10-01 17:39:09 +00:00
|
|
|
{
|
|
|
|
// Use whatever the user selected for the installer
|
2011-10-14 14:53:02 +00:00
|
|
|
DWORD size = MAX_LINE_LENGTH;
|
|
|
|
HKEY hKey;
|
|
|
|
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"Software\\Rainmeter", 0, KEY_QUERY_VALUE | KEY_WOW64_32KEY, &hKey) == ERROR_SUCCESS)
|
2011-10-01 17:39:09 +00:00
|
|
|
{
|
2011-10-14 14:53:02 +00:00
|
|
|
DWORD type = 0;
|
2013-05-31 14:28:39 +00:00
|
|
|
if (RegQueryValueEx(hKey, L"Language", nullptr, &type, (LPBYTE)buffer, (LPDWORD)&size) != ERROR_SUCCESS ||
|
2011-10-14 14:53:02 +00:00
|
|
|
type != REG_SZ)
|
|
|
|
{
|
2012-03-22 21:16:41 +00:00
|
|
|
buffer[0] = L'\0';
|
2011-10-14 14:53:02 +00:00
|
|
|
}
|
|
|
|
RegCloseKey(hKey);
|
2011-10-01 17:39:09 +00:00
|
|
|
}
|
|
|
|
}
|
2012-03-22 21:16:41 +00:00
|
|
|
if (buffer[0] != L'\0')
|
2011-10-29 11:15:58 +00:00
|
|
|
{
|
|
|
|
// Try selected language
|
2013-05-31 14:28:39 +00:00
|
|
|
m_ResourceLCID = wcstoul(buffer, nullptr, 10);
|
2012-03-22 21:16:41 +00:00
|
|
|
resource += buffer;
|
2011-10-29 11:15:58 +00:00
|
|
|
resource += L".dll";
|
2011-10-01 17:39:09 +00:00
|
|
|
|
2013-05-31 14:28:39 +00:00
|
|
|
m_ResourceInstance = LoadLibraryEx(resource.c_str(), nullptr, DONT_RESOLVE_DLL_REFERENCES | LOAD_LIBRARY_AS_DATAFILE);
|
2011-10-29 11:15:58 +00:00
|
|
|
}
|
2011-10-01 17:39:09 +00:00
|
|
|
if (!m_ResourceInstance)
|
|
|
|
{
|
|
|
|
// Try English
|
2011-10-29 11:15:58 +00:00
|
|
|
resource = m_Path;
|
|
|
|
resource += L"Languages\\1033.dll";
|
2013-05-31 14:28:39 +00:00
|
|
|
m_ResourceInstance = LoadLibraryEx(resource.c_str(), nullptr, DONT_RESOLVE_DLL_REFERENCES | LOAD_LIBRARY_AS_DATAFILE);
|
2011-10-01 17:39:09 +00:00
|
|
|
m_ResourceLCID = 1033;
|
|
|
|
if (!m_ResourceInstance)
|
|
|
|
{
|
2013-05-31 14:28:39 +00:00
|
|
|
MessageBox(nullptr, L"Unable to load language library", APPNAME, MB_OK | MB_TOPMOST | MB_ICONERROR);
|
2012-05-24 09:19:32 +00:00
|
|
|
return 1;
|
2011-10-01 17:39:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-30 05:33:32 +00:00
|
|
|
// Get skin folder path
|
2012-05-05 11:45:34 +00:00
|
|
|
size_t len = GetPrivateProfileString(L"Rainmeter", L"SkinPath", L"", buffer, MAX_LINE_LENGTH, iniFile);
|
2012-06-12 12:27:40 +00:00
|
|
|
if (len > 0 &&
|
|
|
|
_waccess(buffer, 0) != -1) // Temporary fix
|
2009-07-24 07:56:37 +00:00
|
|
|
{
|
2012-05-30 05:33:32 +00:00
|
|
|
// Try Rainmeter.ini first
|
2012-03-22 21:16:41 +00:00
|
|
|
m_SkinPath.assign(buffer, len);
|
2013-06-12 18:14:55 +00:00
|
|
|
PathUtil::ExpandEnvironmentVariables(m_SkinPath);
|
|
|
|
PathUtil::AppendBacklashIfMissing(m_SkinPath);
|
2011-05-01 17:10:49 +00:00
|
|
|
}
|
2012-05-30 05:33:32 +00:00
|
|
|
else if (bDefaultIniLocation &&
|
2013-05-31 14:28:39 +00:00
|
|
|
SUCCEEDED(SHGetFolderPath(nullptr, CSIDL_MYDOCUMENTS, nullptr, SHGFP_TYPE_CURRENT, buffer)))
|
2011-05-01 17:10:49 +00:00
|
|
|
{
|
2012-05-30 05:33:32 +00:00
|
|
|
// Use My Documents/Rainmeter/Skins
|
|
|
|
m_SkinPath = buffer;
|
|
|
|
m_SkinPath += L"\\Rainmeter\\";
|
2013-05-31 14:28:39 +00:00
|
|
|
CreateDirectory(m_SkinPath.c_str(), nullptr);
|
2012-05-30 05:33:32 +00:00
|
|
|
m_SkinPath += L"Skins\\";
|
2011-05-02 11:58:02 +00:00
|
|
|
|
2012-05-05 11:45:34 +00:00
|
|
|
WritePrivateProfileString(L"Rainmeter", L"SkinPath", m_SkinPath.c_str(), iniFile);
|
2009-07-24 07:56:37 +00:00
|
|
|
}
|
2012-05-30 05:33:32 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
m_SkinPath = m_Path + L"Skins\\";
|
|
|
|
}
|
|
|
|
|
2012-10-02 14:44:47 +00:00
|
|
|
// Create user skins, layouts, addons, and plugins folders if needed
|
2012-06-10 09:17:47 +00:00
|
|
|
CreateComponentFolders(bDefaultIniLocation);
|
|
|
|
|
2012-03-22 21:16:41 +00:00
|
|
|
delete [] buffer;
|
2013-05-31 14:28:39 +00:00
|
|
|
buffer = nullptr;
|
2011-02-15 13:22:19 +00:00
|
|
|
|
2013-05-30 14:19:42 +00:00
|
|
|
LogNoticeF(L"Path: %s", m_Path.c_str());
|
|
|
|
LogNoticeF(L"IniFile: %s", iniFile);
|
|
|
|
LogNoticeF(L"SkinPath: %s", m_SkinPath.c_str());
|
2009-02-10 18:37:48 +00:00
|
|
|
|
2009-07-24 07:56:37 +00:00
|
|
|
// Test that the Rainmeter.ini file is writable
|
2011-05-02 11:58:02 +00:00
|
|
|
TestSettingsFile(bDefaultIniLocation);
|
2009-07-24 07:56:37 +00:00
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
System::Initialize(m_Instance);
|
2010-03-20 19:40:30 +00:00
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
MeasureNet::InitializeStatic();
|
|
|
|
MeasureCPU::InitializeStatic();
|
|
|
|
MeterString::InitializeStatic();
|
2010-03-20 19:40:30 +00:00
|
|
|
|
2012-06-01 13:06:36 +00:00
|
|
|
// Tray must exist before skins are read
|
2013-05-31 14:18:52 +00:00
|
|
|
m_TrayWindow = new TrayWindow();
|
2012-05-05 12:59:35 +00:00
|
|
|
m_TrayWindow->Initialize();
|
2009-02-10 18:37:48 +00:00
|
|
|
|
2011-11-09 08:52:32 +00:00
|
|
|
ReloadSettings();
|
2009-07-24 07:56:37 +00:00
|
|
|
|
2013-06-16 16:14:59 +00:00
|
|
|
if (m_SkinRegistry.IsEmpty())
|
2009-07-24 07:56:37 +00:00
|
|
|
{
|
2011-09-23 16:28:38 +00:00
|
|
|
std::wstring error = GetFormattedString(ID_STR_NOAVAILABLESKINS, m_SkinPath.c_str());
|
2013-05-31 14:28:39 +00:00
|
|
|
ShowMessage(nullptr, error.c_str(), MB_OK | MB_ICONERROR);
|
2009-07-24 07:56:37 +00:00
|
|
|
}
|
|
|
|
|
2009-02-10 18:37:48 +00:00
|
|
|
ResetStats();
|
|
|
|
ReadStats();
|
|
|
|
|
|
|
|
// Change the work area if necessary
|
|
|
|
if (m_DesktopWorkAreaChanged)
|
|
|
|
{
|
2010-07-10 12:56:37 +00:00
|
|
|
UpdateDesktopWorkArea(false);
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
|
2012-10-06 17:12:40 +00:00
|
|
|
bool layoutLoaded = false;
|
|
|
|
if (layout)
|
|
|
|
{
|
2013-05-31 14:18:52 +00:00
|
|
|
std::vector<std::wstring> args = CommandHandler::ParseString(layout);
|
2012-10-06 17:12:40 +00:00
|
|
|
layoutLoaded = (args.size() == 1 && LoadLayout(args[0]));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!layoutLoaded)
|
|
|
|
{
|
|
|
|
ActivateActiveSkins();
|
|
|
|
}
|
2009-02-10 18:37:48 +00:00
|
|
|
|
2012-05-05 11:45:34 +00:00
|
|
|
if (dataFileCreated)
|
|
|
|
{
|
|
|
|
m_TrayWindow->ShowWelcomeNotification();
|
|
|
|
}
|
|
|
|
else if (!m_DisableVersionCheck)
|
2011-11-09 08:52:32 +00:00
|
|
|
{
|
|
|
|
CheckUpdate();
|
|
|
|
}
|
|
|
|
|
2012-05-24 09:19:32 +00:00
|
|
|
return 0; // All is OK
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
|
2013-06-14 13:58:42 +00:00
|
|
|
void Rainmeter::Finalize()
|
|
|
|
{
|
|
|
|
KillTimer(m_Window, TIMER_NETSTATS);
|
|
|
|
|
|
|
|
DeleteAllUnmanagedMeterWindows();
|
|
|
|
DeleteAllMeterWindows();
|
2013-07-09 12:59:37 +00:00
|
|
|
DeleteAllUnmanagedMeterWindows(); // Redelete unmanaged windows caused by OnCloseAction
|
2013-06-14 13:58:42 +00:00
|
|
|
|
|
|
|
delete m_TrayWindow;
|
|
|
|
|
|
|
|
System::Finalize();
|
|
|
|
|
|
|
|
MeasureNet::UpdateIFTable();
|
|
|
|
MeasureNet::UpdateStats();
|
|
|
|
WriteStats(true);
|
|
|
|
|
|
|
|
MeasureNet::FinalizeStatic();
|
|
|
|
MeasureCPU::FinalizeStatic();
|
|
|
|
MeterString::FinalizeStatic();
|
|
|
|
|
|
|
|
// Change the work area back
|
|
|
|
if (m_DesktopWorkAreaChanged)
|
|
|
|
{
|
|
|
|
UpdateDesktopWorkArea(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_ResourceInstance) FreeLibrary(m_ResourceInstance);
|
|
|
|
if (m_Mutex) ReleaseMutex(m_Mutex);
|
|
|
|
}
|
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
bool Rainmeter::IsAlreadyRunning()
|
2012-05-24 06:19:52 +00:00
|
|
|
{
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
ULONG i[2];
|
|
|
|
ULONG buf[4];
|
|
|
|
unsigned char in[64];
|
|
|
|
unsigned char digest[16];
|
|
|
|
} MD5_CTX;
|
|
|
|
|
|
|
|
typedef void (WINAPI * FPMD5INIT)(MD5_CTX* context);
|
|
|
|
typedef void (WINAPI * FPMD5UPDATE)(MD5_CTX* context, const unsigned char* input, unsigned int inlen);
|
|
|
|
typedef void (WINAPI * FPMD5FINAL)(MD5_CTX* context);
|
|
|
|
|
2012-05-24 11:15:03 +00:00
|
|
|
bool alreadyRunning = false;
|
|
|
|
|
2012-05-24 06:19:52 +00:00
|
|
|
// Create MD5 digest from command line
|
2013-05-31 14:18:52 +00:00
|
|
|
HMODULE cryptDll = System::RmLoadLibrary(L"cryptdll.dll");
|
2012-05-24 06:19:52 +00:00
|
|
|
if (cryptDll)
|
|
|
|
{
|
|
|
|
FPMD5INIT MD5Init = (FPMD5INIT)GetProcAddress(cryptDll, "MD5Init");
|
|
|
|
FPMD5UPDATE MD5Update = (FPMD5UPDATE)GetProcAddress(cryptDll, "MD5Update");
|
|
|
|
FPMD5FINAL MD5Final = (FPMD5FINAL)GetProcAddress(cryptDll, "MD5Final");
|
|
|
|
if (MD5Init && MD5Update && MD5Final)
|
|
|
|
{
|
2012-05-24 11:15:03 +00:00
|
|
|
std::wstring data = m_IniFile;
|
|
|
|
_wcsupr(&data[0]);
|
2012-05-24 06:19:52 +00:00
|
|
|
|
|
|
|
MD5_CTX ctx = {0};
|
|
|
|
MD5Init(&ctx);
|
2012-05-24 11:15:03 +00:00
|
|
|
MD5Update(&ctx, (LPBYTE)&data[0], data.length() * sizeof(WCHAR));
|
2012-05-24 06:19:52 +00:00
|
|
|
MD5Final(&ctx);
|
|
|
|
FreeLibrary(cryptDll);
|
|
|
|
|
|
|
|
// Convert MD5 digest to mutex string (e.g. "Rainmeter0123456789abcdef0123456789abcdef")
|
|
|
|
const WCHAR hexChars[] = L"0123456789abcdef";
|
|
|
|
WCHAR mutexName[64] = L"Rainmeter";
|
|
|
|
WCHAR* pos = mutexName + (_countof(L"Rainmeter") - 1);
|
|
|
|
for (size_t i = 0; i < 16; ++i)
|
|
|
|
{
|
|
|
|
*(pos++) = hexChars[ctx.digest[i] >> 4];
|
|
|
|
*(pos++) = hexChars[ctx.digest[i] & 0xF];
|
|
|
|
}
|
|
|
|
*pos = L'\0';
|
|
|
|
|
2013-05-31 14:28:39 +00:00
|
|
|
m_Mutex = CreateMutex(nullptr, FALSE, mutexName);
|
2012-05-24 11:15:03 +00:00
|
|
|
if (GetLastError() == ERROR_ALREADY_EXISTS)
|
2012-05-24 06:19:52 +00:00
|
|
|
{
|
2012-05-24 11:15:03 +00:00
|
|
|
alreadyRunning = true;
|
2013-05-31 14:28:39 +00:00
|
|
|
m_Mutex = nullptr;
|
2012-05-24 06:19:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FreeLibrary(cryptDll);
|
|
|
|
}
|
|
|
|
|
2012-05-24 11:15:03 +00:00
|
|
|
return alreadyRunning;
|
2012-05-24 06:19:52 +00:00
|
|
|
}
|
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
int Rainmeter::MessagePump()
|
2012-02-14 17:00:07 +00:00
|
|
|
{
|
|
|
|
MSG msg;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
// Run the standard window message loop
|
2013-05-31 14:28:39 +00:00
|
|
|
while ((ret = GetMessage(&msg, nullptr, 0, 0)) != 0)
|
2012-02-14 17:00:07 +00:00
|
|
|
{
|
|
|
|
if (ret == -1)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2012-12-13 09:12:25 +00:00
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
if (!Dialog::HandleMessage(msg))
|
2012-02-14 17:00:07 +00:00
|
|
|
{
|
|
|
|
TranslateMessage(&msg);
|
|
|
|
DispatchMessage(&msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (int)msg.wParam;
|
|
|
|
}
|
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
LRESULT CALLBACK Rainmeter::MainWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
2012-02-14 17:00:07 +00:00
|
|
|
{
|
|
|
|
switch (uMsg)
|
|
|
|
{
|
|
|
|
case WM_DESTROY:
|
|
|
|
PostQuitMessage(0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_COPYDATA:
|
|
|
|
{
|
|
|
|
COPYDATASTRUCT* cds = (COPYDATASTRUCT*)lParam;
|
|
|
|
if (cds)
|
|
|
|
{
|
|
|
|
const WCHAR* data = (const WCHAR*)cds->lpData;
|
|
|
|
if (cds->dwData == 1 && (cds->cbData > 0))
|
|
|
|
{
|
2013-06-13 14:20:27 +00:00
|
|
|
GetRainmeter().DelayedExecuteCommand(data);
|
2012-02-14 17:00:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2012-02-15 02:51:27 +00:00
|
|
|
case WM_TIMER:
|
|
|
|
if (wParam == TIMER_NETSTATS)
|
|
|
|
{
|
2013-05-31 14:18:52 +00:00
|
|
|
MeasureNet::UpdateIFTable();
|
|
|
|
MeasureNet::UpdateStats();
|
2013-06-13 14:20:27 +00:00
|
|
|
GetRainmeter().WriteStats(false);
|
2012-02-15 02:51:27 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2012-02-14 17:58:03 +00:00
|
|
|
case WM_RAINMETER_DELAYED_REFRESH_ALL:
|
2013-06-13 14:20:27 +00:00
|
|
|
GetRainmeter().RefreshAll();
|
2012-02-15 02:51:27 +00:00
|
|
|
break;
|
2012-02-14 17:58:03 +00:00
|
|
|
|
|
|
|
case WM_RAINMETER_DELAYED_EXECUTE:
|
|
|
|
if (lParam)
|
|
|
|
{
|
|
|
|
// Execute bang
|
|
|
|
WCHAR* bang = (WCHAR*)lParam;
|
2013-06-13 14:20:27 +00:00
|
|
|
GetRainmeter().ExecuteCommand(bang, nullptr);
|
2012-02-14 17:58:03 +00:00
|
|
|
free(bang); // _wcsdup()
|
|
|
|
}
|
2012-02-15 02:51:27 +00:00
|
|
|
break;
|
2012-02-14 17:58:03 +00:00
|
|
|
|
2012-02-22 06:42:52 +00:00
|
|
|
case WM_RAINMETER_EXECUTE:
|
2013-06-13 14:20:27 +00:00
|
|
|
if (GetRainmeter().HasMeterWindow((MeterWindow*)wParam))
|
2013-03-21 12:29:59 +00:00
|
|
|
{
|
2013-06-13 14:20:27 +00:00
|
|
|
GetRainmeter().ExecuteCommand((const WCHAR*)lParam, (MeterWindow*)wParam);
|
2013-03-21 12:29:59 +00:00
|
|
|
}
|
2012-02-22 06:42:52 +00:00
|
|
|
break;
|
|
|
|
|
2012-02-14 17:00:07 +00:00
|
|
|
default:
|
|
|
|
return DefWindowProc(hWnd, uMsg, wParam, lParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
void Rainmeter::SetNetworkStatisticsTimer()
|
2012-02-15 02:51:27 +00:00
|
|
|
{
|
2013-05-31 14:28:39 +00:00
|
|
|
static bool set = SetTimer(m_Window, TIMER_NETSTATS, INTERVAL_NETSTATS, nullptr);
|
2012-02-15 02:51:27 +00:00
|
|
|
}
|
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
void Rainmeter::CreateOptionsFile()
|
2009-07-21 12:26:50 +00:00
|
|
|
{
|
2013-05-31 14:28:39 +00:00
|
|
|
CreateDirectory(m_SettingsPath.c_str(), nullptr);
|
2009-07-21 12:26:50 +00:00
|
|
|
|
2012-10-02 14:44:47 +00:00
|
|
|
std::wstring defaultIni = GetDefaultLayoutPath();
|
|
|
|
defaultIni += L"illustro default\\Rainmeter.ini";
|
2013-05-31 14:18:52 +00:00
|
|
|
System::CopyFiles(defaultIni, m_IniFile);
|
2009-07-21 12:26:50 +00:00
|
|
|
}
|
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
void Rainmeter::CreateDataFile()
|
2012-05-05 11:45:34 +00:00
|
|
|
{
|
2012-06-10 09:17:47 +00:00
|
|
|
std::wstring tmpSz = m_SettingsPath + L"Plugins.ini";
|
2012-05-05 11:45:34 +00:00
|
|
|
|
|
|
|
const WCHAR* pluginsFile = tmpSz.c_str();
|
|
|
|
const WCHAR* dataFile = m_DataFile.c_str();
|
|
|
|
|
|
|
|
if (_waccess(pluginsFile, 0) == 0)
|
|
|
|
{
|
2012-05-13 09:30:20 +00:00
|
|
|
MoveFile(pluginsFile, dataFile);
|
2012-05-05 11:45:34 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Create empty file
|
2013-05-31 14:28:39 +00:00
|
|
|
HANDLE file = CreateFile(dataFile, GENERIC_WRITE, 0, nullptr, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, nullptr);
|
2012-05-05 11:45:34 +00:00
|
|
|
if (file != INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
CloseHandle(file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
void Rainmeter::CreateComponentFolders(bool defaultIniLocation)
|
2012-06-09 15:38:45 +00:00
|
|
|
{
|
2012-06-15 08:58:07 +00:00
|
|
|
std::wstring path;
|
|
|
|
|
2013-05-31 14:28:39 +00:00
|
|
|
if (CreateDirectory(m_SkinPath.c_str(), nullptr))
|
2012-06-09 15:38:45 +00:00
|
|
|
{
|
|
|
|
// Folder just created, so copy default skins there
|
|
|
|
std::wstring from = GetDefaultSkinPath();
|
|
|
|
from += L"*.*";
|
2013-05-31 14:18:52 +00:00
|
|
|
System::CopyFiles(from, m_SkinPath);
|
2012-06-09 15:38:45 +00:00
|
|
|
}
|
2012-06-15 08:58:07 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
path = m_SkinPath;
|
|
|
|
path += L"Backup";
|
|
|
|
if (_waccess(path.c_str(), 0) != -1)
|
|
|
|
{
|
|
|
|
std::wstring newPath = m_SkinPath + L"@Backup";
|
|
|
|
MoveFile(path.c_str(), newPath.c_str());
|
|
|
|
}
|
|
|
|
}
|
2012-06-09 15:38:45 +00:00
|
|
|
|
2012-10-02 14:44:47 +00:00
|
|
|
path = GetLayoutPath();
|
2012-06-09 15:38:45 +00:00
|
|
|
if (_waccess(path.c_str(), 0) == -1)
|
|
|
|
{
|
2012-10-02 14:44:47 +00:00
|
|
|
std::wstring themesPath = m_SettingsPath + L"Themes";
|
|
|
|
if (_waccess(themesPath.c_str(), 0) != -1)
|
|
|
|
{
|
|
|
|
// Migrate Themes into Layouts for backwards compatibility and rename
|
|
|
|
// Rainmeter.thm to Rainmeter.ini and RainThemes.bmp to Wallpaper.bmp.
|
|
|
|
MoveFile(themesPath.c_str(), path.c_str());
|
|
|
|
|
|
|
|
path += L'*'; // For FindFirstFile.
|
|
|
|
WIN32_FIND_DATA fd;
|
|
|
|
HANDLE hFind = FindFirstFile(path.c_str(), &fd);
|
|
|
|
path.pop_back(); // Remove '*'.
|
|
|
|
|
|
|
|
if (hFind != INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY &&
|
2013-06-12 18:14:55 +00:00
|
|
|
PathUtil::IsDotOrDotDot(fd.cFileName))
|
2012-10-02 14:44:47 +00:00
|
|
|
{
|
|
|
|
std::wstring layoutFolder = path + fd.cFileName;
|
|
|
|
layoutFolder += L'\\';
|
|
|
|
|
|
|
|
std::wstring file = layoutFolder + L"Rainmeter.thm";
|
|
|
|
if (_waccess(file.c_str(), 0) != -1)
|
|
|
|
{
|
|
|
|
std::wstring newFile = layoutFolder + L"Rainmeter.ini";
|
|
|
|
MoveFile(file.c_str(), newFile.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
file = layoutFolder + L"RainThemes.bmp";
|
|
|
|
if (_waccess(file.c_str(), 0) != -1)
|
|
|
|
{
|
2012-10-02 18:01:40 +00:00
|
|
|
std::wstring newFile = layoutFolder + L"Wallpaper.bmp";
|
2012-10-02 14:44:47 +00:00
|
|
|
MoveFile(file.c_str(), newFile.c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (FindNextFile(hFind, &fd));
|
|
|
|
|
|
|
|
FindClose(hFind);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2012-06-09 15:38:45 +00:00
|
|
|
{
|
2012-10-02 14:44:47 +00:00
|
|
|
std::wstring from = GetDefaultLayoutPath();
|
|
|
|
if (_waccess(from.c_str(), 0) != -1)
|
|
|
|
{
|
2013-05-31 14:18:52 +00:00
|
|
|
System::CopyFiles(from, m_SettingsPath);
|
2012-10-02 14:44:47 +00:00
|
|
|
}
|
2012-06-09 15:38:45 +00:00
|
|
|
}
|
|
|
|
}
|
2012-06-15 08:58:07 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
path += L"Backup";
|
|
|
|
if (_waccess(path.c_str(), 0) != -1)
|
|
|
|
{
|
2012-10-02 14:44:47 +00:00
|
|
|
std::wstring newPath = GetLayoutPath();
|
2012-06-15 08:58:07 +00:00
|
|
|
newPath += L"@Backup";
|
|
|
|
MoveFile(path.c_str(), newPath.c_str());
|
|
|
|
}
|
|
|
|
}
|
2012-06-09 15:38:45 +00:00
|
|
|
|
2012-06-09 16:45:27 +00:00
|
|
|
if (defaultIniLocation)
|
2012-06-09 15:38:45 +00:00
|
|
|
{
|
2012-06-09 16:45:27 +00:00
|
|
|
path = GetUserPluginPath();
|
|
|
|
if (_waccess(path.c_str(), 0) == -1)
|
2012-06-09 15:38:45 +00:00
|
|
|
{
|
2012-06-09 16:45:27 +00:00
|
|
|
std::wstring from = GetDefaultPluginPath();
|
|
|
|
if (_waccess(from.c_str(), 0) != -1)
|
|
|
|
{
|
2013-05-31 14:18:52 +00:00
|
|
|
System::CopyFiles(from, m_SettingsPath);
|
2012-06-09 16:45:27 +00:00
|
|
|
}
|
2012-06-09 15:38:45 +00:00
|
|
|
}
|
|
|
|
|
2012-06-09 16:45:27 +00:00
|
|
|
path = GetAddonPath();
|
|
|
|
if (_waccess(path.c_str(), 0) == -1)
|
2012-06-09 15:38:45 +00:00
|
|
|
{
|
2012-06-09 16:45:27 +00:00
|
|
|
std::wstring from = GetDefaultAddonPath();
|
|
|
|
if (_waccess(from.c_str(), 0) != -1)
|
|
|
|
{
|
2013-05-31 14:18:52 +00:00
|
|
|
System::CopyFiles(from, m_SettingsPath);
|
2012-06-09 16:45:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
path = m_SettingsPath;
|
|
|
|
path += L"Rainmeter.exe";
|
2012-06-11 13:15:03 +00:00
|
|
|
const WCHAR* pathSz = path.c_str();
|
|
|
|
if (_waccess(pathSz, 0) == -1)
|
2012-06-09 16:45:27 +00:00
|
|
|
{
|
2012-06-11 13:15:03 +00:00
|
|
|
// Create a hidden stub Rainmeter.exe into SettingsPath for old addon
|
2012-06-09 16:45:27 +00:00
|
|
|
// using relative path to Rainmeter.exe
|
2012-06-11 13:15:03 +00:00
|
|
|
std::wstring from = m_Path + L"Rainmeter.exe";
|
2013-05-31 14:18:52 +00:00
|
|
|
System::CopyFiles(from, path);
|
2012-06-11 13:15:03 +00:00
|
|
|
|
|
|
|
// Get rid of all resources from the stub executable
|
|
|
|
HANDLE stub = BeginUpdateResource(pathSz, TRUE);
|
|
|
|
|
|
|
|
// Add the manifest of Rainmeter.dll to the stub
|
|
|
|
HRSRC manifest = FindResource(m_Instance, MAKEINTRESOURCE(2), RT_MANIFEST);
|
|
|
|
DWORD manifestSize = SizeofResource(m_Instance, manifest);
|
|
|
|
HGLOBAL manifestLoad = LoadResource(m_Instance, manifest);
|
|
|
|
void* manifestLoadData = LockResource(manifestLoad);
|
|
|
|
if (manifestLoadData)
|
|
|
|
{
|
|
|
|
LANGID langID = MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT);
|
|
|
|
UpdateResource(stub, RT_MANIFEST, MAKEINTRESOURCE(1), langID, manifestLoadData, manifestSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
EndUpdateResource(stub, FALSE);
|
|
|
|
SetFileAttributes(pathSz, FILE_ATTRIBUTE_HIDDEN);
|
2012-06-09 15:38:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
void Rainmeter::ReloadSettings()
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2012-06-10 09:17:47 +00:00
|
|
|
ScanForSkins();
|
2012-10-02 14:44:47 +00:00
|
|
|
ScanForLayouts();
|
2009-02-10 18:37:48 +00:00
|
|
|
ReadGeneralSettings(m_IniFile);
|
|
|
|
}
|
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
void Rainmeter::EditSettings()
|
2012-02-21 19:15:10 +00:00
|
|
|
{
|
2012-08-18 15:02:20 +00:00
|
|
|
std::wstring file = L'"' + m_IniFile;
|
|
|
|
file += L'"';
|
2013-05-31 14:18:52 +00:00
|
|
|
CommandHandler::RunFile(m_SkinEditor.c_str(), file.c_str());
|
2012-02-21 19:15:10 +00:00
|
|
|
}
|
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
void Rainmeter::EditSkinFile(const std::wstring& name, const std::wstring& iniFile)
|
2012-02-21 19:15:10 +00:00
|
|
|
{
|
2012-08-18 15:02:20 +00:00
|
|
|
std::wstring args = L'"' + m_SkinPath;
|
2012-08-18 06:45:16 +00:00
|
|
|
args += name;
|
2012-05-29 16:02:20 +00:00
|
|
|
args += L'\\';
|
|
|
|
args += iniFile;
|
2012-08-18 15:02:20 +00:00
|
|
|
args += L'"';
|
2013-05-31 14:18:52 +00:00
|
|
|
CommandHandler::RunFile(m_SkinEditor.c_str(), args.c_str());
|
2012-02-21 19:15:10 +00:00
|
|
|
}
|
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
void Rainmeter::OpenSkinFolder(const std::wstring& name)
|
2012-02-21 19:15:10 +00:00
|
|
|
{
|
2012-06-01 13:06:36 +00:00
|
|
|
std::wstring folderPath = m_SkinPath + name;
|
2013-05-31 14:18:52 +00:00
|
|
|
CommandHandler::RunFile(folderPath.c_str());
|
2012-02-21 19:15:10 +00:00
|
|
|
}
|
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
void Rainmeter::ActivateActiveSkins()
|
2011-09-04 18:06:19 +00:00
|
|
|
{
|
2012-06-01 13:06:36 +00:00
|
|
|
std::multimap<int, int>::const_iterator iter = m_SkinOrders.begin();
|
|
|
|
for ( ; iter != m_SkinOrders.end(); ++iter)
|
2011-09-04 18:06:19 +00:00
|
|
|
{
|
2013-06-16 16:14:59 +00:00
|
|
|
const SkinRegistry::Folder& skinFolder = m_SkinRegistry.GetFolder((*iter).second);
|
|
|
|
if (skinFolder.active > 0 && skinFolder.active <= (uint16_t)skinFolder.files.size())
|
2011-09-04 18:06:19 +00:00
|
|
|
{
|
2012-06-01 13:06:36 +00:00
|
|
|
ActivateSkin((*iter).second, skinFolder.active - 1);
|
2011-09-04 18:06:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-16 16:14:59 +00:00
|
|
|
/*
|
|
|
|
** Activates the skin, or, if it is already active, the next variant of the skin. Returns true
|
|
|
|
** if the skin was activated (or was already active).
|
|
|
|
*/
|
|
|
|
bool Rainmeter::ActivateSkin(const std::wstring& folderPath)
|
|
|
|
{
|
|
|
|
const int index = m_SkinRegistry.FindFolderIndex(folderPath);
|
|
|
|
if (index != -1)
|
|
|
|
{
|
|
|
|
const SkinRegistry::Folder& skinFolder = m_SkinRegistry.GetFolder(index);
|
|
|
|
if (!(skinFolder.active == 1 && skinFolder.files.size() == 1))
|
|
|
|
{
|
|
|
|
// Activate the next index.
|
|
|
|
ActivateSkin(
|
|
|
|
index, (skinFolder.active < skinFolder.files.size()) ? skinFolder.active : 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Activates the skin, or, if it is already active, the next variant of the skin. Returns true
|
|
|
|
** if the skin was activated (or was already active).
|
|
|
|
*/
|
|
|
|
bool Rainmeter::ActivateSkin(const std::wstring& folderPath, const std::wstring& file)
|
|
|
|
{
|
|
|
|
const SkinRegistry::Indexes indexes = m_SkinRegistry.FindIndexes(folderPath, file);
|
|
|
|
if (indexes.IsValid())
|
|
|
|
{
|
|
|
|
ActivateSkin(indexes.folder, indexes.file);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
void Rainmeter::ActivateSkin(int folderIndex, int fileIndex)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2013-06-16 16:14:59 +00:00
|
|
|
if (folderIndex >= 0 && folderIndex < m_SkinRegistry.GetFolderCount() &&
|
|
|
|
fileIndex >= 0 && fileIndex < m_SkinRegistry.GetFolder(folderIndex).files.size())
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2013-06-16 16:14:59 +00:00
|
|
|
auto& skinFolder = m_SkinRegistry.GetFolder(folderIndex);
|
2012-06-01 13:06:36 +00:00
|
|
|
const std::wstring& file = skinFolder.files[fileIndex];
|
|
|
|
const WCHAR* fileSz = file.c_str();
|
2012-06-01 10:05:25 +00:00
|
|
|
|
2013-06-16 16:14:59 +00:00
|
|
|
std::wstring folderPath = m_SkinRegistry.GetFolderPath(folderIndex);
|
2009-02-10 18:37:48 +00:00
|
|
|
|
2012-06-01 13:06:36 +00:00
|
|
|
// Verify that the skin is not already active
|
2013-05-31 14:18:52 +00:00
|
|
|
std::map<std::wstring, MeterWindow*>::const_iterator iter = m_MeterWindows.find(folderPath);
|
2012-02-03 10:15:18 +00:00
|
|
|
if (iter != m_MeterWindows.end())
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2012-06-01 13:06:36 +00:00
|
|
|
if (wcscmp(((*iter).second)->GetFileName().c_str(), fileSz) == 0)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2013-06-29 16:59:18 +00:00
|
|
|
LogWarningF((*iter).second, L"!ActivateConfig: \"%s\" already active", folderPath.c_str());
|
2009-02-10 18:37:48 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-06-01 13:06:36 +00:00
|
|
|
// Deactivate the existing skin
|
|
|
|
DeactivateSkin((*iter).second, folderIndex);
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-22 00:31:59 +00:00
|
|
|
// Verify whether the ini-file exists
|
2012-06-01 13:06:36 +00:00
|
|
|
std::wstring skinIniPath = m_SkinPath + folderPath;
|
2011-12-04 22:18:40 +00:00
|
|
|
skinIniPath += L'\\';
|
2012-06-01 13:06:36 +00:00
|
|
|
skinIniPath += file;
|
2010-07-22 00:31:59 +00:00
|
|
|
|
|
|
|
if (_waccess(skinIniPath.c_str(), 0) == -1)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2012-06-01 13:06:36 +00:00
|
|
|
std::wstring message = GetFormattedString(ID_STR_UNABLETOACTIVATESKIN, folderPath.c_str(), fileSz);
|
2013-05-31 14:28:39 +00:00
|
|
|
ShowMessage(nullptr, message.c_str(), MB_OK | MB_ICONEXCLAMATION);
|
2010-07-22 00:31:59 +00:00
|
|
|
return;
|
|
|
|
}
|
2009-02-10 18:37:48 +00:00
|
|
|
|
2012-07-18 10:44:03 +00:00
|
|
|
if (skinFolder.active != fileIndex + 1)
|
|
|
|
{
|
|
|
|
// Write only if changed.
|
|
|
|
skinFolder.active = fileIndex + 1;
|
|
|
|
WriteActive(folderPath, fileIndex);
|
|
|
|
}
|
2009-10-18 13:31:55 +00:00
|
|
|
|
2012-06-01 13:06:36 +00:00
|
|
|
CreateMeterWindow(folderPath, file);
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
void Rainmeter::DeactivateSkin(MeterWindow* meterWindow, int folderIndex, bool save)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2013-06-16 16:14:59 +00:00
|
|
|
if (folderIndex >= 0 && folderIndex < m_SkinRegistry.GetFolderCount())
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2013-06-16 16:14:59 +00:00
|
|
|
m_SkinRegistry.GetFolder(folderIndex).active = 0; // Deactivate the skin
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
2012-06-01 10:05:25 +00:00
|
|
|
else if (folderIndex == -1 && meterWindow)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2013-06-16 16:14:59 +00:00
|
|
|
SkinRegistry::Folder* folder = m_SkinRegistry.FindFolder(meterWindow->GetFolderPath());
|
|
|
|
if (folder)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2013-06-16 16:14:59 +00:00
|
|
|
folder->active = 0;
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (meterWindow)
|
|
|
|
{
|
2011-08-28 10:58:26 +00:00
|
|
|
if (save)
|
|
|
|
{
|
2012-06-01 13:06:36 +00:00
|
|
|
// Disable the skin in the ini-file
|
|
|
|
WriteActive(meterWindow->GetFolderPath(), -1);
|
2011-08-28 10:58:26 +00:00
|
|
|
}
|
2009-02-10 18:37:48 +00:00
|
|
|
|
2012-02-02 12:05:14 +00:00
|
|
|
meterWindow->Deactivate();
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
void Rainmeter::ToggleSkin(int folderIndex, int fileIndex)
|
2011-10-29 10:36:07 +00:00
|
|
|
{
|
2013-06-16 16:14:59 +00:00
|
|
|
if (folderIndex >= 0 && folderIndex < m_SkinRegistry.GetFolderCount() &&
|
|
|
|
fileIndex >= 0 && fileIndex < m_SkinRegistry.GetFolder(folderIndex).files.size())
|
2011-10-29 10:36:07 +00:00
|
|
|
{
|
2013-06-16 16:14:59 +00:00
|
|
|
if (m_SkinRegistry.GetFolder(folderIndex).active == fileIndex + 1)
|
2011-10-29 10:36:07 +00:00
|
|
|
{
|
2013-06-16 16:14:59 +00:00
|
|
|
MeterWindow* meterWindow = GetMeterWindow(m_SkinRegistry.GetFolderPath(folderIndex));
|
2012-06-01 13:06:36 +00:00
|
|
|
DeactivateSkin(meterWindow, folderIndex);
|
2011-10-29 10:36:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-06-01 13:06:36 +00:00
|
|
|
ActivateSkin(folderIndex, fileIndex);
|
2011-10-29 10:36:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-16 16:14:59 +00:00
|
|
|
void Rainmeter::ToggleSkinWithID(UINT id)
|
|
|
|
{
|
|
|
|
const SkinRegistry::Indexes indexes = m_SkinRegistry.FindIndexesForID(id);
|
|
|
|
if (indexes.IsValid())
|
|
|
|
{
|
|
|
|
ToggleSkin(indexes.folder, indexes.file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
void Rainmeter::SetSkinPath(const std::wstring& skinPath)
|
2012-11-12 20:02:01 +00:00
|
|
|
{
|
|
|
|
WritePrivateProfileString(L"Rainmeter", L"SkinPath", skinPath.c_str(), m_IniFile.c_str());
|
|
|
|
}
|
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
void Rainmeter::SetSkinEditor(const std::wstring& path)
|
2012-11-12 20:02:01 +00:00
|
|
|
{
|
2012-11-13 16:39:54 +00:00
|
|
|
if (!path.empty())
|
2012-11-12 20:02:01 +00:00
|
|
|
{
|
2012-11-13 16:39:54 +00:00
|
|
|
m_SkinEditor = path;
|
|
|
|
WritePrivateProfileString(L"Rainmeter", L"ConfigEditor", path.c_str(), m_IniFile.c_str());
|
2012-11-12 20:02:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
void Rainmeter::WriteActive(const std::wstring& folderPath, int fileIndex)
|
2010-07-22 00:31:59 +00:00
|
|
|
{
|
2010-12-13 09:00:02 +00:00
|
|
|
WCHAR buffer[32];
|
2012-06-01 10:05:25 +00:00
|
|
|
_itow_s(fileIndex + 1, buffer, 10);
|
2012-06-01 13:06:36 +00:00
|
|
|
WritePrivateProfileString(folderPath.c_str(), L"Active", buffer, m_IniFile.c_str());
|
2010-07-22 00:31:59 +00:00
|
|
|
}
|
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
void Rainmeter::CreateMeterWindow(const std::wstring& folderPath, const std::wstring& file)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2013-05-31 14:18:52 +00:00
|
|
|
MeterWindow* mw = new MeterWindow(folderPath, file);
|
2009-02-10 18:37:48 +00:00
|
|
|
|
2012-07-18 06:22:47 +00:00
|
|
|
// Note: May modify existing key
|
|
|
|
m_MeterWindows[folderPath] = mw;
|
2010-08-30 22:51:58 +00:00
|
|
|
|
2012-07-18 06:22:47 +00:00
|
|
|
mw->Initialize();
|
2011-09-10 22:04:51 +00:00
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
DialogAbout::UpdateSkins();
|
|
|
|
DialogManage::UpdateSkins(mw);
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
void Rainmeter::DeleteAllMeterWindows()
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2013-06-03 20:58:30 +00:00
|
|
|
auto it = m_MeterWindows.cbegin();
|
|
|
|
while (it != m_MeterWindows.cend())
|
2009-10-17 06:43:18 +00:00
|
|
|
{
|
2013-06-03 20:58:30 +00:00
|
|
|
MeterWindow* mw = (*it).second;
|
2013-07-09 12:59:37 +00:00
|
|
|
m_MeterWindows.erase(it); // Remove before deleting MeterWindow
|
2013-06-03 20:58:30 +00:00
|
|
|
|
|
|
|
DialogManage::UpdateSkins(mw, true);
|
|
|
|
delete mw;
|
2013-07-09 12:59:37 +00:00
|
|
|
|
|
|
|
// Get next valid iterator (Fix for iterator invalidation caused by OnCloseAction)
|
|
|
|
it = m_MeterWindows.cbegin();
|
2012-02-02 12:05:14 +00:00
|
|
|
}
|
2009-02-10 18:37:48 +00:00
|
|
|
|
2013-03-10 10:14:40 +00:00
|
|
|
m_MeterWindows.clear();
|
2013-05-31 14:18:52 +00:00
|
|
|
DialogAbout::UpdateSkins();
|
2013-03-10 10:14:40 +00:00
|
|
|
}
|
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
void Rainmeter::DeleteAllUnmanagedMeterWindows()
|
2013-03-10 21:06:02 +00:00
|
|
|
{
|
2013-06-03 20:58:30 +00:00
|
|
|
for (auto it = m_UnmanagedMeterWindows.cbegin(); it != m_UnmanagedMeterWindows.cend(); ++it)
|
2013-03-10 21:06:02 +00:00
|
|
|
{
|
|
|
|
delete (*it);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_UnmanagedMeterWindows.clear();
|
|
|
|
}
|
|
|
|
|
2013-03-10 10:14:40 +00:00
|
|
|
/*
|
2013-03-10 21:06:02 +00:00
|
|
|
** Removes the skin from m_MeterWindows. The skin should delete itself.
|
2013-03-10 10:14:40 +00:00
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
void Rainmeter::RemoveMeterWindow(MeterWindow* meterWindow)
|
2013-03-10 10:14:40 +00:00
|
|
|
{
|
2013-06-03 20:58:30 +00:00
|
|
|
for (auto it = m_MeterWindows.cbegin(); it != m_MeterWindows.cend(); ++it)
|
2012-02-03 10:15:18 +00:00
|
|
|
{
|
2013-03-10 10:14:40 +00:00
|
|
|
if ((*it).second == meterWindow)
|
|
|
|
{
|
|
|
|
m_MeterWindows.erase(it);
|
2013-05-31 14:18:52 +00:00
|
|
|
DialogManage::UpdateSkins(meterWindow, true);
|
|
|
|
DialogAbout::UpdateSkins();
|
2013-03-10 10:14:40 +00:00
|
|
|
break;
|
|
|
|
}
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-10 21:06:02 +00:00
|
|
|
/*
|
|
|
|
** Adds the skin to m_UnmanagedMeterWindows. The skin should remove itself by calling RemoveUnmanagedMeterWindow().
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
void Rainmeter::AddUnmanagedMeterWindow(MeterWindow* meterWindow)
|
2013-03-10 21:06:02 +00:00
|
|
|
{
|
|
|
|
for (auto it = m_UnmanagedMeterWindows.cbegin(); it != m_UnmanagedMeterWindows.cend(); ++it)
|
|
|
|
{
|
|
|
|
if ((*it) == meterWindow) // already added
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_UnmanagedMeterWindows.push_back(meterWindow);
|
|
|
|
}
|
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
void Rainmeter::RemoveUnmanagedMeterWindow(MeterWindow* meterWindow)
|
2013-03-10 21:06:02 +00:00
|
|
|
{
|
|
|
|
for (auto it = m_UnmanagedMeterWindows.cbegin(); it != m_UnmanagedMeterWindows.cend(); ++it)
|
|
|
|
{
|
|
|
|
if ((*it) == meterWindow)
|
|
|
|
{
|
|
|
|
m_UnmanagedMeterWindows.erase(it);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
bool Rainmeter::HasMeterWindow(const MeterWindow* meterWindow) const
|
2013-03-21 12:29:59 +00:00
|
|
|
{
|
|
|
|
for (auto it = m_MeterWindows.begin(); it != m_MeterWindows.end(); ++it)
|
|
|
|
{
|
|
|
|
if ((*it).second == meterWindow)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
MeterWindow* Rainmeter::GetMeterWindow(const std::wstring& folderPath)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2012-06-01 13:06:36 +00:00
|
|
|
const WCHAR* folderSz = folderPath.c_str();
|
2013-05-31 14:18:52 +00:00
|
|
|
std::map<std::wstring, MeterWindow*>::const_iterator iter = m_MeterWindows.begin();
|
2012-02-03 10:15:18 +00:00
|
|
|
for (; iter != m_MeterWindows.end(); ++iter)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2012-06-01 13:06:36 +00:00
|
|
|
if (_wcsicmp((*iter).first.c_str(), folderSz) == 0)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
|
|
|
return (*iter).second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-31 14:28:39 +00:00
|
|
|
return nullptr;
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
2010-03-23 16:15:07 +00:00
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
MeterWindow* Rainmeter::GetMeterWindowByINI(const std::wstring& ini_searching)
|
2010-12-16 17:04:14 +00:00
|
|
|
{
|
2011-02-15 13:22:19 +00:00
|
|
|
if (_wcsnicmp(m_SkinPath.c_str(), ini_searching.c_str(), m_SkinPath.length()) == 0)
|
2010-12-16 17:04:14 +00:00
|
|
|
{
|
2011-02-15 13:22:19 +00:00
|
|
|
const std::wstring config_searching = ini_searching.substr(m_SkinPath.length());
|
2010-12-16 17:04:14 +00:00
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
std::map<std::wstring, MeterWindow*>::const_iterator iter = m_MeterWindows.begin();
|
2012-02-03 10:15:18 +00:00
|
|
|
for (; iter != m_MeterWindows.end(); ++iter)
|
2010-12-16 17:04:14 +00:00
|
|
|
{
|
2012-06-01 13:06:36 +00:00
|
|
|
std::wstring config_current = (*iter).second->GetFolderPath() + L'\\';
|
|
|
|
config_current += (*iter).second->GetFileName();
|
2011-02-15 13:22:19 +00:00
|
|
|
|
|
|
|
if (_wcsicmp(config_current.c_str(), config_searching.c_str()) == 0)
|
|
|
|
{
|
|
|
|
return (*iter).second;
|
|
|
|
}
|
2010-12-16 17:04:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-31 14:28:39 +00:00
|
|
|
return nullptr;
|
2010-12-16 17:04:14 +00:00
|
|
|
}
|
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
MeterWindow* Rainmeter::GetMeterWindow(HWND hwnd)
|
2010-03-23 16:15:07 +00:00
|
|
|
{
|
2013-05-31 14:18:52 +00:00
|
|
|
std::map<std::wstring, MeterWindow*>::const_iterator iter = m_MeterWindows.begin();
|
2012-02-03 10:15:18 +00:00
|
|
|
for (; iter != m_MeterWindows.end(); ++iter)
|
2010-03-23 16:15:07 +00:00
|
|
|
{
|
|
|
|
if ((*iter).second->GetWindow() == hwnd)
|
|
|
|
{
|
|
|
|
return (*iter).second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-31 14:28:39 +00:00
|
|
|
return nullptr;
|
2010-03-23 16:15:07 +00:00
|
|
|
}
|
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
void Rainmeter::GetMeterWindowsByLoadOrder(std::multimap<int, MeterWindow*>& windows, const std::wstring& group)
|
2010-07-17 13:02:34 +00:00
|
|
|
{
|
2013-05-31 14:18:52 +00:00
|
|
|
std::map<std::wstring, MeterWindow*>::const_iterator iter = m_MeterWindows.begin();
|
2012-02-03 10:15:18 +00:00
|
|
|
for (; iter != m_MeterWindows.end(); ++iter)
|
2010-07-17 13:02:34 +00:00
|
|
|
{
|
2013-05-31 14:18:52 +00:00
|
|
|
MeterWindow* mw = (*iter).second;
|
2010-07-17 13:02:34 +00:00
|
|
|
if (mw && (group.empty() || mw->BelongsToGroup(group)))
|
|
|
|
{
|
2013-05-31 14:18:52 +00:00
|
|
|
windows.insert(std::pair<int, MeterWindow*>(GetLoadOrder((*iter).first), mw));
|
2010-07-17 13:02:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
void Rainmeter::SetLoadOrder(int folderIndex, int order)
|
2010-03-29 21:50:05 +00:00
|
|
|
{
|
2012-06-01 13:06:36 +00:00
|
|
|
std::multimap<int, int>::iterator iter = m_SkinOrders.begin();
|
|
|
|
for ( ; iter != m_SkinOrders.end(); ++iter)
|
2010-03-29 21:50:05 +00:00
|
|
|
{
|
2012-06-01 10:05:25 +00:00
|
|
|
if ((*iter).second == folderIndex) // already exists
|
2010-03-29 21:50:05 +00:00
|
|
|
{
|
2010-07-17 13:02:34 +00:00
|
|
|
if ((*iter).first != order)
|
2010-03-29 21:50:05 +00:00
|
|
|
{
|
2012-06-01 13:06:36 +00:00
|
|
|
m_SkinOrders.erase(iter);
|
2010-03-29 21:50:05 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-01 13:06:36 +00:00
|
|
|
m_SkinOrders.insert(std::pair<int, int>(order, folderIndex));
|
2010-03-29 21:50:05 +00:00
|
|
|
}
|
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
int Rainmeter::GetLoadOrder(const std::wstring& folderPath)
|
2010-03-29 21:50:05 +00:00
|
|
|
{
|
2013-06-16 16:14:59 +00:00
|
|
|
const int index = m_SkinRegistry.FindFolderIndex(folderPath);
|
2012-06-01 10:05:25 +00:00
|
|
|
if (index != -1)
|
2010-03-29 21:50:05 +00:00
|
|
|
{
|
2012-06-01 13:06:36 +00:00
|
|
|
std::multimap<int, int>::const_iterator iter = m_SkinOrders.begin();
|
|
|
|
for ( ; iter != m_SkinOrders.end(); ++iter)
|
2010-03-29 21:50:05 +00:00
|
|
|
{
|
2012-06-01 10:05:25 +00:00
|
|
|
if ((*iter).second == index)
|
|
|
|
{
|
|
|
|
return (*iter).first;
|
|
|
|
}
|
2010-03-29 21:50:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-08 14:39:25 +00:00
|
|
|
// LoadOrder not specified
|
2010-03-29 21:50:05 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-03-29 19:21:57 +00:00
|
|
|
/*
|
2009-02-10 18:37:48 +00:00
|
|
|
** Scans all the subfolders and locates the ini-files.
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
void Rainmeter::ScanForSkins()
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2013-06-16 16:14:59 +00:00
|
|
|
m_SkinRegistry.Populate(m_SkinPath);
|
2012-06-01 13:06:36 +00:00
|
|
|
m_SkinOrders.clear();
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
|
2011-03-29 19:21:57 +00:00
|
|
|
/*
|
2012-10-02 14:44:47 +00:00
|
|
|
** Scans the given folder for layouts
|
2009-08-12 17:11:52 +00:00
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
void Rainmeter::ScanForLayouts()
|
2009-08-12 17:11:52 +00:00
|
|
|
{
|
2012-10-02 14:44:47 +00:00
|
|
|
m_Layouts.clear();
|
2009-08-12 17:11:52 +00:00
|
|
|
|
|
|
|
WIN32_FIND_DATA fileData; // Data structure describes the file found
|
2011-03-29 19:21:57 +00:00
|
|
|
HANDLE hSearch; // Search handle returned by FindFirstFile
|
2009-08-12 17:11:52 +00:00
|
|
|
|
|
|
|
// Scan for folders
|
2012-10-02 14:44:47 +00:00
|
|
|
std::wstring folders = GetLayoutPath();
|
2012-06-10 09:17:47 +00:00
|
|
|
folders += L'*';
|
2009-08-12 17:11:52 +00:00
|
|
|
|
2011-07-15 11:48:50 +00:00
|
|
|
hSearch = FindFirstFileEx(
|
|
|
|
folders.c_str(),
|
2013-03-12 15:48:47 +00:00
|
|
|
(Platform::IsAtLeastWin7()) ? FindExInfoBasic : FindExInfoStandard,
|
2011-07-15 11:48:50 +00:00
|
|
|
&fileData,
|
|
|
|
FindExSearchNameMatch,
|
2013-05-31 14:28:39 +00:00
|
|
|
nullptr,
|
2011-07-15 11:48:50 +00:00
|
|
|
0);
|
|
|
|
|
|
|
|
if (hSearch != INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
do
|
2009-08-12 17:11:52 +00:00
|
|
|
{
|
2011-07-15 11:48:50 +00:00
|
|
|
if (fileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY &&
|
2013-06-12 18:14:55 +00:00
|
|
|
!PathUtil::IsDotOrDotDot(fileData.cFileName))
|
2011-07-15 11:48:50 +00:00
|
|
|
{
|
2012-10-02 14:44:47 +00:00
|
|
|
m_Layouts.push_back(fileData.cFileName);
|
2011-07-15 11:48:50 +00:00
|
|
|
}
|
2011-11-08 10:32:57 +00:00
|
|
|
}
|
|
|
|
while (FindNextFile(hSearch, &fileData));
|
2009-08-12 17:11:52 +00:00
|
|
|
|
2011-07-15 11:48:50 +00:00
|
|
|
FindClose(hSearch);
|
|
|
|
}
|
2009-08-12 17:11:52 +00:00
|
|
|
}
|
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
void Rainmeter::ExecuteBang(const WCHAR* bang, std::vector<std::wstring>& args, MeterWindow* meterWindow)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2013-05-30 16:51:05 +00:00
|
|
|
m_CommandHandler.ExecuteBang(bang, args, meterWindow);
|
2012-05-06 19:27:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Runs the given command or bang
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
void Rainmeter::ExecuteCommand(const WCHAR* command, MeterWindow* meterWindow, bool multi)
|
2012-05-06 19:27:59 +00:00
|
|
|
{
|
2013-05-30 16:51:05 +00:00
|
|
|
m_CommandHandler.ExecuteCommand(command, meterWindow, multi);
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
|
2012-02-14 17:00:07 +00:00
|
|
|
/*
|
|
|
|
** Executes command when current processing is done.
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
void Rainmeter::DelayedExecuteCommand(const WCHAR* command)
|
2012-02-14 17:00:07 +00:00
|
|
|
{
|
|
|
|
WCHAR* bang = _wcsdup(command);
|
2013-05-31 14:28:39 +00:00
|
|
|
PostMessage(m_Window, WM_RAINMETER_DELAYED_EXECUTE, (WPARAM)nullptr, (LPARAM)bang);
|
2012-02-14 17:00:07 +00:00
|
|
|
}
|
|
|
|
|
2009-02-10 18:37:48 +00:00
|
|
|
/*
|
|
|
|
** Reads the general settings from the Rainmeter.ini file
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
void Rainmeter::ReadGeneralSettings(const std::wstring& iniFile)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2010-12-21 04:49:01 +00:00
|
|
|
WCHAR buffer[MAX_PATH];
|
|
|
|
|
2010-07-10 12:56:37 +00:00
|
|
|
// Clear old settings
|
|
|
|
m_DesktopWorkAreas.clear();
|
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
ConfigParser parser;
|
2013-05-31 14:28:39 +00:00
|
|
|
parser.Initialize(iniFile, nullptr, nullptr);
|
2009-02-10 18:37:48 +00:00
|
|
|
|
2013-03-25 16:00:53 +00:00
|
|
|
m_UseD2D = 0!=parser.ReadInt(L"Rainmeter", L"UseD2D", 0);
|
|
|
|
|
2011-09-28 18:28:35 +00:00
|
|
|
m_Debug = 0!=parser.ReadInt(L"Rainmeter", L"Debug", 0);
|
2013-05-29 19:05:41 +00:00
|
|
|
|
|
|
|
// Read Logging settings
|
2013-06-13 14:22:42 +00:00
|
|
|
Logger& logger = GetLogger();
|
2013-05-29 19:05:41 +00:00
|
|
|
const bool logging = parser.ReadInt(L"Rainmeter", L"Logging", 0) != 0;
|
|
|
|
logger.SetLogToFile(logging);
|
|
|
|
if (logging)
|
2010-07-08 10:59:06 +00:00
|
|
|
{
|
2013-05-29 19:05:41 +00:00
|
|
|
logger.StartLogFile();
|
2010-07-08 10:59:06 +00:00
|
|
|
}
|
|
|
|
|
2009-02-10 18:37:48 +00:00
|
|
|
if (m_TrayWindow)
|
|
|
|
{
|
2012-05-30 18:53:44 +00:00
|
|
|
m_TrayWindow->ReadOptions(parser);
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
|
2012-06-01 13:06:36 +00:00
|
|
|
m_GlobalOptions.netInSpeed = parser.ReadFloat(L"Rainmeter", L"NetInSpeed", 0.0);
|
|
|
|
m_GlobalOptions.netOutSpeed = parser.ReadFloat(L"Rainmeter", L"NetOutSpeed", 0.0);
|
2009-02-10 18:37:48 +00:00
|
|
|
|
2010-11-27 10:57:59 +00:00
|
|
|
m_DisableDragging = 0!=parser.ReadInt(L"Rainmeter", L"DisableDragging", 0);
|
2010-11-25 22:00:34 +00:00
|
|
|
m_DisableRDP = 0!=parser.ReadInt(L"Rainmeter", L"DisableRDP", 0);
|
|
|
|
|
2012-06-01 13:06:36 +00:00
|
|
|
m_SkinEditor = parser.ReadString(L"Rainmeter", L"ConfigEditor", L"");
|
|
|
|
if (m_SkinEditor.empty())
|
2010-06-23 12:36:39 +00:00
|
|
|
{
|
|
|
|
// Get the program path associated with .ini files
|
|
|
|
DWORD cchOut = MAX_PATH;
|
|
|
|
HRESULT hr = AssocQueryString(ASSOCF_NOTRUNCATE, ASSOCSTR_EXECUTABLE, L".ini", L"open", buffer, &cchOut);
|
2012-06-01 13:06:36 +00:00
|
|
|
m_SkinEditor = (SUCCEEDED(hr) && cchOut > 0) ? buffer : L"Notepad";
|
2010-06-23 12:36:39 +00:00
|
|
|
}
|
2010-07-07 23:46:44 +00:00
|
|
|
|
2011-09-28 18:28:35 +00:00
|
|
|
if (m_Debug)
|
2010-07-07 23:46:44 +00:00
|
|
|
{
|
2013-05-30 14:19:42 +00:00
|
|
|
LogNoticeF(L"ConfigEditor: %s", m_SkinEditor.c_str());
|
2010-07-07 23:46:44 +00:00
|
|
|
}
|
2010-06-23 12:36:39 +00:00
|
|
|
|
2010-05-30 07:02:46 +00:00
|
|
|
m_TrayExecuteR = parser.ReadString(L"Rainmeter", L"TrayExecuteR", L"", false);
|
|
|
|
m_TrayExecuteM = parser.ReadString(L"Rainmeter", L"TrayExecuteM", L"", false);
|
|
|
|
m_TrayExecuteDR = parser.ReadString(L"Rainmeter", L"TrayExecuteDR", L"", false);
|
|
|
|
m_TrayExecuteDM = parser.ReadString(L"Rainmeter", L"TrayExecuteDM", L"", false);
|
|
|
|
|
2010-07-17 13:02:34 +00:00
|
|
|
m_DisableVersionCheck = 0!=parser.ReadInt(L"Rainmeter", L"DisableVersionCheck", 0);
|
2010-07-10 12:56:37 +00:00
|
|
|
|
2011-11-16 16:47:20 +00:00
|
|
|
const std::wstring& area = parser.ReadString(L"Rainmeter", L"DesktopWorkArea", L"");
|
2009-02-10 18:37:48 +00:00
|
|
|
if (!area.empty())
|
|
|
|
{
|
2010-12-04 15:07:28 +00:00
|
|
|
m_DesktopWorkAreas[0] = parser.ParseRECT(area.c_str());
|
2009-02-10 18:37:48 +00:00
|
|
|
m_DesktopWorkAreaChanged = true;
|
|
|
|
}
|
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
for (UINT i = 1, isize = System::GetMonitorCount(); i <= isize; ++i)
|
2010-07-10 12:56:37 +00:00
|
|
|
{
|
2010-12-16 20:35:44 +00:00
|
|
|
_snwprintf_s(buffer, _TRUNCATE, L"DesktopWorkArea@%i", i);
|
2011-11-16 16:47:20 +00:00
|
|
|
const std::wstring& area = parser.ReadString(L"Rainmeter", buffer, L"");
|
2010-07-10 12:56:37 +00:00
|
|
|
if (!area.empty())
|
|
|
|
{
|
2010-12-04 15:07:28 +00:00
|
|
|
m_DesktopWorkAreas[i] = parser.ParseRECT(area.c_str());
|
2010-07-10 12:56:37 +00:00
|
|
|
m_DesktopWorkAreaChanged = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-17 13:02:34 +00:00
|
|
|
m_DesktopWorkAreaType = 0!=parser.ReadInt(L"Rainmeter", L"DesktopWorkAreaType", 0);
|
|
|
|
|
2011-11-10 11:50:47 +00:00
|
|
|
m_NormalStayDesktop = 0!=parser.ReadInt(L"Rainmeter", L"NormalStayDesktop", 1);
|
|
|
|
|
2012-06-01 10:05:25 +00:00
|
|
|
for (auto iter = parser.GetSections().cbegin(); iter != parser.GetSections().end(); ++iter)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2012-06-01 10:05:25 +00:00
|
|
|
const WCHAR* section = (*iter).c_str();
|
|
|
|
|
|
|
|
if (wcscmp(section, L"Rainmeter") == 0 ||
|
|
|
|
wcscmp(section, L"TrayMeasure") == 0)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-06-16 16:14:59 +00:00
|
|
|
const int index = m_SkinRegistry.FindFolderIndex(*iter);
|
2012-06-01 10:05:25 +00:00
|
|
|
if (index == -1)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-06-16 16:14:59 +00:00
|
|
|
SkinRegistry::Folder& skinFolder = m_SkinRegistry.GetFolder(index);
|
2009-02-10 18:37:48 +00:00
|
|
|
|
|
|
|
// Make sure there is a ini file available
|
2012-06-01 10:05:25 +00:00
|
|
|
int active = parser.ReadInt(section, L"Active", 0);
|
2012-06-01 13:06:36 +00:00
|
|
|
if (active > 0 && active <= (int)skinFolder.files.size())
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2012-06-01 13:06:36 +00:00
|
|
|
skinFolder.active = active;
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
2010-07-17 13:02:34 +00:00
|
|
|
|
2012-06-01 10:05:25 +00:00
|
|
|
int order = parser.ReadInt(section, L"LoadOrder", 0);
|
|
|
|
SetLoadOrder(index, order);
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-29 19:21:57 +00:00
|
|
|
/*
|
2010-03-29 21:50:05 +00:00
|
|
|
** Refreshes all active meter windows.
|
2013-05-31 14:18:52 +00:00
|
|
|
** Note: This function calls MeterWindow::Refresh() directly for synchronization. Be careful about crash.
|
2009-02-10 18:37:48 +00:00
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
void Rainmeter::RefreshAll()
|
2010-03-29 21:50:05 +00:00
|
|
|
{
|
|
|
|
// Read skins and settings
|
|
|
|
ReloadSettings();
|
|
|
|
|
2010-07-17 13:02:34 +00:00
|
|
|
// Change the work area if necessary
|
|
|
|
if (m_DesktopWorkAreaChanged)
|
2010-03-29 21:50:05 +00:00
|
|
|
{
|
2010-07-17 13:02:34 +00:00
|
|
|
UpdateDesktopWorkArea(false);
|
2010-03-29 21:50:05 +00:00
|
|
|
}
|
|
|
|
|
2010-07-17 13:02:34 +00:00
|
|
|
// Make the sending order by using LoadOrder
|
2013-05-31 14:18:52 +00:00
|
|
|
std::multimap<int, MeterWindow*> windows;
|
2010-07-17 13:02:34 +00:00
|
|
|
GetMeterWindowsByLoadOrder(windows);
|
|
|
|
|
2010-03-29 21:50:05 +00:00
|
|
|
// Prepare the helper window
|
2013-05-31 14:18:52 +00:00
|
|
|
System::PrepareHelperWindow();
|
2010-03-29 21:50:05 +00:00
|
|
|
|
|
|
|
// Refresh all
|
2013-05-31 14:18:52 +00:00
|
|
|
std::multimap<int, MeterWindow*>::const_iterator iter = windows.begin();
|
2010-07-17 13:02:34 +00:00
|
|
|
for ( ; iter != windows.end(); ++iter)
|
2010-03-29 21:50:05 +00:00
|
|
|
{
|
2013-05-31 14:18:52 +00:00
|
|
|
MeterWindow* mw = (*iter).second;
|
2010-07-22 00:31:59 +00:00
|
|
|
if (mw)
|
2010-03-29 21:50:05 +00:00
|
|
|
{
|
2010-07-22 00:31:59 +00:00
|
|
|
// Verify whether the cached information is valid
|
2013-06-16 16:14:59 +00:00
|
|
|
const int index = m_SkinRegistry.FindFolderIndex(mw->GetFolderPath());
|
2012-06-01 10:05:25 +00:00
|
|
|
if (index != -1)
|
2010-07-22 00:31:59 +00:00
|
|
|
{
|
2013-06-16 16:14:59 +00:00
|
|
|
SkinRegistry::Folder& skinFolder = m_SkinRegistry.GetFolder(index);
|
2012-06-01 13:06:36 +00:00
|
|
|
const WCHAR* skinIniFile = mw->GetFileName().c_str();
|
2012-06-01 10:05:25 +00:00
|
|
|
|
|
|
|
bool found = false;
|
2012-06-01 13:06:36 +00:00
|
|
|
for (int i = 0, isize = (int)skinFolder.files.size(); i < isize; ++i)
|
2010-07-22 00:31:59 +00:00
|
|
|
{
|
2012-06-01 13:06:36 +00:00
|
|
|
if (_wcsicmp(skinIniFile, skinFolder.files[i].c_str()) == 0)
|
2010-07-22 00:31:59 +00:00
|
|
|
{
|
2012-06-01 10:05:25 +00:00
|
|
|
found = true;
|
2012-06-01 13:06:36 +00:00
|
|
|
if (skinFolder.active != i + 1)
|
2010-07-22 00:31:59 +00:00
|
|
|
{
|
2012-06-01 10:05:25 +00:00
|
|
|
// Switch to new ini-file order
|
2012-06-01 13:06:36 +00:00
|
|
|
skinFolder.active = i + 1;
|
|
|
|
WriteActive(mw->GetFolderPath(), i);
|
2010-07-22 00:31:59 +00:00
|
|
|
}
|
2012-06-01 10:05:25 +00:00
|
|
|
break;
|
2010-07-22 00:31:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-01 10:05:25 +00:00
|
|
|
if (!found)
|
2010-07-22 00:31:59 +00:00
|
|
|
{
|
2012-07-11 03:46:08 +00:00
|
|
|
const WCHAR* skinFolderPath = mw->GetFolderPath().c_str();
|
|
|
|
std::wstring error = GetFormattedString(ID_STR_UNABLETOREFRESHSKIN, skinFolderPath, skinIniFile);
|
|
|
|
|
2012-06-01 13:06:36 +00:00
|
|
|
DeactivateSkin(mw, index);
|
2010-07-22 00:31:59 +00:00
|
|
|
|
2013-05-31 14:28:39 +00:00
|
|
|
ShowMessage(nullptr, error.c_str(), MB_OK | MB_ICONEXCLAMATION);
|
2012-07-11 03:46:08 +00:00
|
|
|
continue;
|
2010-07-22 00:31:59 +00:00
|
|
|
}
|
2012-06-01 10:05:25 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-07-11 03:46:08 +00:00
|
|
|
const WCHAR* skinFolderPath = mw->GetFolderPath().c_str();
|
|
|
|
std::wstring error = GetFormattedString(ID_STR_UNABLETOREFRESHSKIN, skinFolderPath, L"");
|
|
|
|
|
2012-06-01 13:06:36 +00:00
|
|
|
DeactivateSkin(mw, -2); // -2 = Force deactivate
|
2012-06-01 10:05:25 +00:00
|
|
|
|
2013-05-31 14:28:39 +00:00
|
|
|
ShowMessage(nullptr, error.c_str(), MB_OK | MB_ICONEXCLAMATION);
|
2012-07-11 03:46:08 +00:00
|
|
|
continue;
|
2010-07-22 00:31:59 +00:00
|
|
|
}
|
|
|
|
|
2012-08-12 14:02:08 +00:00
|
|
|
mw->Refresh(false, true);
|
2010-03-29 21:50:05 +00:00
|
|
|
}
|
|
|
|
}
|
2011-08-28 12:28:00 +00:00
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
DialogAbout::UpdateSkins();
|
2013-05-31 14:28:39 +00:00
|
|
|
DialogManage::UpdateSkins(nullptr);
|
2010-03-29 21:50:05 +00:00
|
|
|
}
|
2009-02-10 18:37:48 +00:00
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
bool Rainmeter::LoadLayout(const std::wstring& name)
|
2011-09-04 07:40:12 +00:00
|
|
|
{
|
2012-10-06 17:12:40 +00:00
|
|
|
// Replace Rainmeter.ini with layout
|
|
|
|
std::wstring layout = GetLayoutPath();
|
|
|
|
layout += name;
|
|
|
|
std::wstring wallpaper = layout + L"\\Wallpaper.bmp";
|
|
|
|
layout += L"\\Rainmeter.ini";
|
|
|
|
|
|
|
|
if (_waccess(layout.c_str(), 0) == -1)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-03-10 21:06:02 +00:00
|
|
|
DeleteAllUnmanagedMeterWindows();
|
2013-03-10 10:14:40 +00:00
|
|
|
DeleteAllMeterWindows();
|
2011-09-04 07:40:12 +00:00
|
|
|
|
2012-10-02 14:44:47 +00:00
|
|
|
std::wstring backup = GetLayoutPath();
|
2012-06-15 08:58:07 +00:00
|
|
|
backup += L"@Backup";
|
2013-05-31 14:28:39 +00:00
|
|
|
CreateDirectory(backup.c_str(), nullptr);
|
2012-10-02 14:44:47 +00:00
|
|
|
backup += L"\\Rainmeter.ini";
|
2011-09-18 07:38:14 +00:00
|
|
|
|
2012-10-06 17:12:40 +00:00
|
|
|
bool backupLayout = (_wcsicmp(name.c_str(), L"@Backup") == 0);
|
|
|
|
if (!backupLayout)
|
2011-09-18 07:38:14 +00:00
|
|
|
{
|
|
|
|
// Make a copy of current Rainmeter.ini
|
2013-05-31 14:18:52 +00:00
|
|
|
System::CopyFiles(m_IniFile, backup);
|
2012-10-06 17:12:40 +00:00
|
|
|
}
|
2011-09-18 07:38:14 +00:00
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
System::CopyFiles(layout, m_IniFile);
|
2011-09-18 07:38:14 +00:00
|
|
|
|
2012-10-06 17:12:40 +00:00
|
|
|
if (!backupLayout)
|
|
|
|
{
|
2011-09-18 07:38:14 +00:00
|
|
|
PreserveSetting(backup, L"SkinPath");
|
|
|
|
PreserveSetting(backup, L"ConfigEditor");
|
|
|
|
PreserveSetting(backup, L"LogViewer");
|
|
|
|
PreserveSetting(backup, L"Logging");
|
|
|
|
PreserveSetting(backup, L"DisableVersionCheck");
|
2011-10-01 17:55:33 +00:00
|
|
|
PreserveSetting(backup, L"Language");
|
2011-11-16 16:47:20 +00:00
|
|
|
PreserveSetting(backup, L"NormalStayDesktop");
|
2011-09-18 07:38:14 +00:00
|
|
|
PreserveSetting(backup, L"TrayExecuteM", false);
|
|
|
|
PreserveSetting(backup, L"TrayExecuteR", false);
|
|
|
|
PreserveSetting(backup, L"TrayExecuteDM", false);
|
|
|
|
PreserveSetting(backup, L"TrayExecuteDR", false);
|
2013-03-31 16:33:36 +00:00
|
|
|
PreserveSetting(backup, L"UseD2D");
|
2011-09-18 07:38:14 +00:00
|
|
|
|
|
|
|
// Set wallpaper if it exists
|
|
|
|
if (_waccess(wallpaper.c_str(), 0) != -1)
|
|
|
|
{
|
2011-10-14 14:53:02 +00:00
|
|
|
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, (void*)wallpaper.c_str(), SPIF_UPDATEINIFILE);
|
2011-09-18 07:38:14 +00:00
|
|
|
}
|
2011-09-04 07:40:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ReloadSettings();
|
|
|
|
|
2012-06-01 13:06:36 +00:00
|
|
|
// Create meter windows for active skins
|
|
|
|
ActivateActiveSkins();
|
2012-10-06 17:12:40 +00:00
|
|
|
|
|
|
|
return true;
|
2011-09-04 07:40:12 +00:00
|
|
|
}
|
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
void Rainmeter::PreserveSetting(const std::wstring& from, LPCTSTR key, bool replace)
|
2011-09-04 07:40:12 +00:00
|
|
|
{
|
|
|
|
WCHAR* buffer = new WCHAR[MAX_LINE_LENGTH];
|
|
|
|
|
|
|
|
if ((replace || GetPrivateProfileString(L"Rainmeter", key, L"", buffer, 4, m_IniFile.c_str()) == 0) &&
|
|
|
|
GetPrivateProfileString(L"Rainmeter", key, L"", buffer, MAX_LINE_LENGTH, from.c_str()) > 0)
|
|
|
|
{
|
|
|
|
WritePrivateProfileString(L"Rainmeter", key, buffer, m_IniFile.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
delete [] buffer;
|
|
|
|
}
|
|
|
|
|
2011-03-29 19:21:57 +00:00
|
|
|
/*
|
2010-07-10 12:56:37 +00:00
|
|
|
** Applies given DesktopWorkArea and DesktopWorkArea@n.
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
void Rainmeter::UpdateDesktopWorkArea(bool reset)
|
2010-07-10 12:56:37 +00:00
|
|
|
{
|
|
|
|
bool changed = false;
|
|
|
|
|
|
|
|
if (reset)
|
|
|
|
{
|
|
|
|
if (!m_OldDesktopWorkAreas.empty())
|
|
|
|
{
|
2013-02-08 16:52:41 +00:00
|
|
|
int i = 1;
|
|
|
|
for (auto iter = m_OldDesktopWorkAreas.cbegin(); iter != m_OldDesktopWorkAreas.cend(); ++iter, ++i)
|
2010-07-10 12:56:37 +00:00
|
|
|
{
|
2013-02-08 16:52:41 +00:00
|
|
|
RECT r = (*iter);
|
2010-07-17 13:02:34 +00:00
|
|
|
|
|
|
|
BOOL result = SystemParametersInfo(SPI_SETWORKAREA, 0, &r, 0);
|
|
|
|
|
2011-09-28 18:28:35 +00:00
|
|
|
if (m_Debug)
|
2010-07-17 13:02:34 +00:00
|
|
|
{
|
|
|
|
std::wstring format = L"Resetting WorkArea@%i: L=%i, T=%i, R=%i, B=%i (W=%i, H=%i)";
|
|
|
|
if (!result)
|
|
|
|
{
|
2011-09-08 14:39:25 +00:00
|
|
|
format += L" => FAIL";
|
2010-07-17 13:02:34 +00:00
|
|
|
}
|
2013-05-30 14:19:42 +00:00
|
|
|
LogDebugF(format.c_str(), i, r.left, r.top, r.right, r.bottom, r.right - r.left, r.bottom - r.top);
|
2010-07-17 13:02:34 +00:00
|
|
|
}
|
2010-07-10 12:56:37 +00:00
|
|
|
}
|
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-05-31 14:18:52 +00:00
|
|
|
const size_t numOfMonitors = System::GetMonitorCount();
|
|
|
|
const MultiMonitorInfo& monitorsInfo = System::GetMultiMonitorInfo();
|
2013-02-08 16:52:41 +00:00
|
|
|
const std::vector<MonitorInfo>& monitors = monitorsInfo.monitors;
|
2010-07-17 13:02:34 +00:00
|
|
|
|
2010-07-10 12:56:37 +00:00
|
|
|
if (m_OldDesktopWorkAreas.empty())
|
|
|
|
{
|
|
|
|
// Store old work areas for changing them back
|
2013-02-08 16:52:41 +00:00
|
|
|
for (size_t i = 0; i < numOfMonitors; ++i)
|
2010-07-10 12:56:37 +00:00
|
|
|
{
|
2010-07-17 13:02:34 +00:00
|
|
|
m_OldDesktopWorkAreas.push_back(monitors[i].work);
|
2010-07-10 12:56:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-28 18:28:35 +00:00
|
|
|
if (m_Debug)
|
2010-07-17 13:02:34 +00:00
|
|
|
{
|
2013-05-30 14:19:42 +00:00
|
|
|
LogDebugF(L"DesktopWorkAreaType: %s", m_DesktopWorkAreaType ? L"Margin" : L"Default");
|
2010-07-17 13:02:34 +00:00
|
|
|
}
|
|
|
|
|
2013-02-08 16:52:41 +00:00
|
|
|
for (UINT i = 0; i <= numOfMonitors; ++i)
|
2010-07-10 12:56:37 +00:00
|
|
|
{
|
|
|
|
std::map<UINT, RECT>::const_iterator it = m_DesktopWorkAreas.find(i);
|
|
|
|
if (it != m_DesktopWorkAreas.end())
|
|
|
|
{
|
2013-02-08 16:52:41 +00:00
|
|
|
RECT r = (*it).second;
|
2010-07-17 13:02:34 +00:00
|
|
|
|
|
|
|
// Move rect to correct offset
|
|
|
|
if (m_DesktopWorkAreaType)
|
|
|
|
{
|
|
|
|
RECT margin = r;
|
2013-02-08 16:52:41 +00:00
|
|
|
r = (i == 0) ? monitors[monitorsInfo.primary - 1].screen : monitors[i - 1].screen;
|
2010-07-17 13:02:34 +00:00
|
|
|
r.left += margin.left;
|
|
|
|
r.top += margin.top;
|
|
|
|
r.right -= margin.right;
|
|
|
|
r.bottom -= margin.bottom;
|
|
|
|
}
|
|
|
|
else
|
2010-07-10 12:56:37 +00:00
|
|
|
{
|
2010-07-17 13:02:34 +00:00
|
|
|
if (i != 0)
|
|
|
|
{
|
|
|
|
const RECT screenRect = monitors[i - 1].screen;
|
|
|
|
r.left += screenRect.left;
|
|
|
|
r.top += screenRect.top;
|
|
|
|
r.right += screenRect.left;
|
|
|
|
r.bottom += screenRect.top;
|
|
|
|
}
|
2010-07-10 12:56:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL result = SystemParametersInfo(SPI_SETWORKAREA, 0, &r, 0);
|
|
|
|
if (result)
|
|
|
|
{
|
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
|
2011-09-28 18:28:35 +00:00
|
|
|
if (m_Debug)
|
2010-07-10 12:56:37 +00:00
|
|
|
{
|
|
|
|
std::wstring format = L"Applying DesktopWorkArea";
|
|
|
|
if (i != 0)
|
|
|
|
{
|
2010-09-13 20:06:52 +00:00
|
|
|
WCHAR buffer[64];
|
2011-12-09 19:49:06 +00:00
|
|
|
size_t len = _snwprintf_s(buffer, _TRUNCATE, L"@%i", i);
|
|
|
|
format.append(buffer, len);
|
2010-07-10 12:56:37 +00:00
|
|
|
}
|
2010-07-17 13:02:34 +00:00
|
|
|
format += L": L=%i, T=%i, R=%i, B=%i (W=%i, H=%i)";
|
2010-07-10 12:56:37 +00:00
|
|
|
if (!result)
|
|
|
|
{
|
2011-09-08 14:39:25 +00:00
|
|
|
format += L" => FAIL";
|
2010-07-10 12:56:37 +00:00
|
|
|
}
|
2013-05-30 14:19:42 +00:00
|
|
|
LogDebugF(format.c_str(), r.left, r.top, r.right, r.bottom, r.right - r.left, r.bottom - r.top);
|
2010-07-10 12:56:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
if (changed && System::GetWindow())
|
2010-07-10 12:56:37 +00:00
|
|
|
{
|
2013-05-31 14:18:52 +00:00
|
|
|
// Update System::MultiMonitorInfo for for work area variables
|
2013-05-31 14:28:39 +00:00
|
|
|
SendMessageTimeout(System::GetWindow(), WM_SETTINGCHANGE, SPI_SETWORKAREA, 0, SMTO_ABORTIFHUNG, 1000, nullptr);
|
2010-07-10 12:56:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-10 18:37:48 +00:00
|
|
|
/*
|
|
|
|
** Reads the statistics from the ini-file
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
void Rainmeter::ReadStats()
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2011-12-01 08:40:37 +00:00
|
|
|
const WCHAR* statsFile = m_StatsFile.c_str();
|
|
|
|
|
2011-04-16 20:05:14 +00:00
|
|
|
// If m_StatsFile doesn't exist, create it and copy the stats section from m_IniFile
|
2011-12-01 08:40:37 +00:00
|
|
|
if (_waccess(statsFile, 0) == -1)
|
2011-04-16 20:05:14 +00:00
|
|
|
{
|
2011-12-01 08:40:37 +00:00
|
|
|
const WCHAR* iniFile = m_IniFile.c_str();
|
2011-04-16 20:05:14 +00:00
|
|
|
WCHAR* tmpSz = new WCHAR[SHRT_MAX]; // Max size returned by GetPrivateProfileSection()
|
|
|
|
|
2011-12-01 08:40:37 +00:00
|
|
|
if (GetPrivateProfileSection(L"Statistics", tmpSz, SHRT_MAX, iniFile) > 0)
|
|
|
|
{
|
2013-05-31 14:28:39 +00:00
|
|
|
WritePrivateProfileString(L"Statistics", nullptr, nullptr, iniFile);
|
2011-12-01 08:40:37 +00:00
|
|
|
}
|
|
|
|
else
|
2011-04-16 20:05:14 +00:00
|
|
|
{
|
2011-12-01 08:40:37 +00:00
|
|
|
tmpSz[0] = tmpSz[1] = L'\0';
|
2011-04-16 20:05:14 +00:00
|
|
|
}
|
2011-12-01 08:40:37 +00:00
|
|
|
WritePrivateProfileSection(L"Statistics", tmpSz, statsFile);
|
2011-04-16 20:05:14 +00:00
|
|
|
|
|
|
|
delete [] tmpSz;
|
|
|
|
}
|
|
|
|
|
2009-02-10 18:37:48 +00:00
|
|
|
// Only Net measure has stats at the moment
|
2013-05-31 14:18:52 +00:00
|
|
|
MeasureNet::ReadStats(m_StatsFile, m_StatsDate);
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-02-15 02:51:27 +00:00
|
|
|
** Writes the statistics to the ini-file. If bForce is false the stats are written only once per an appropriate interval.
|
2009-02-10 18:37:48 +00:00
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
void Rainmeter::WriteStats(bool bForce)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2011-06-05 12:32:18 +00:00
|
|
|
static ULONGLONG lastWrite = 0;
|
2009-02-10 18:37:48 +00:00
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
ULONGLONG ticks = System::GetTickCount64();
|
2011-06-05 12:32:18 +00:00
|
|
|
|
2012-02-15 02:51:27 +00:00
|
|
|
if (bForce || (lastWrite + INTERVAL_NETSTATS < ticks))
|
2009-07-27 12:30:28 +00:00
|
|
|
{
|
2011-06-05 12:32:18 +00:00
|
|
|
lastWrite = ticks;
|
2009-07-27 12:30:28 +00:00
|
|
|
|
|
|
|
// Only Net measure has stats at the moment
|
2011-12-01 08:40:37 +00:00
|
|
|
const WCHAR* statsFile = m_StatsFile.c_str();
|
2013-05-31 14:18:52 +00:00
|
|
|
MeasureNet::WriteStats(statsFile, m_StatsDate);
|
2009-07-27 12:30:28 +00:00
|
|
|
|
2013-05-31 14:28:39 +00:00
|
|
|
WritePrivateProfileString(nullptr, nullptr, nullptr, statsFile);
|
2009-07-27 12:30:28 +00:00
|
|
|
}
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Clears the statistics
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
void Rainmeter::ResetStats()
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
|
|
|
// Set the stats-date string
|
2012-06-01 13:13:01 +00:00
|
|
|
tm* newtime;
|
2011-03-29 19:21:57 +00:00
|
|
|
time_t long_time;
|
|
|
|
time(&long_time);
|
|
|
|
newtime = localtime(&long_time);
|
2009-02-10 18:37:48 +00:00
|
|
|
m_StatsDate = _wasctime(newtime);
|
2011-07-14 00:26:53 +00:00
|
|
|
m_StatsDate.erase(m_StatsDate.size() - 1);
|
2011-03-29 19:21:57 +00:00
|
|
|
|
2009-02-10 18:37:48 +00:00
|
|
|
// Only Net measure has stats at the moment
|
2013-05-31 14:18:52 +00:00
|
|
|
MeasureNet::ResetStats();
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
|
2012-06-19 11:31:08 +00:00
|
|
|
/*
|
|
|
|
** Wraps MessageBox(). Sets RTL flag if necessary.
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
int Rainmeter::ShowMessage(HWND parent, const WCHAR* text, UINT type)
|
2012-06-19 11:31:08 +00:00
|
|
|
{
|
|
|
|
type |= MB_TOPMOST;
|
|
|
|
|
|
|
|
if (*GetString(ID_STR_ISRTL) == L'1')
|
|
|
|
{
|
|
|
|
type |= MB_RTLREADING;
|
|
|
|
}
|
|
|
|
|
|
|
|
return MessageBox(parent, text, APPNAME, type);
|
|
|
|
};
|
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
void Rainmeter::ShowLogFile()
|
2012-02-21 19:15:10 +00:00
|
|
|
{
|
2013-06-13 14:22:42 +00:00
|
|
|
std::wstring logFile = L'"' + GetLogger().GetLogFilePath();
|
2012-08-18 15:02:20 +00:00
|
|
|
logFile += L'"';
|
2012-08-18 14:39:28 +00:00
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
CommandHandler::RunFile(m_SkinEditor.c_str(), logFile.c_str());
|
2012-02-21 19:15:10 +00:00
|
|
|
}
|
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
void Rainmeter::SetDebug(bool debug)
|
2010-07-07 23:46:44 +00:00
|
|
|
{
|
2011-09-28 18:28:35 +00:00
|
|
|
m_Debug = debug;
|
2010-07-07 23:46:44 +00:00
|
|
|
WritePrivateProfileString(L"Rainmeter", L"Debug", debug ? L"1" : L"0", m_IniFile.c_str());
|
|
|
|
}
|
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
void Rainmeter::SetDisableDragging(bool dragging)
|
2010-11-24 15:34:07 +00:00
|
|
|
{
|
2010-11-27 10:57:59 +00:00
|
|
|
m_DisableDragging = dragging;
|
|
|
|
WritePrivateProfileString(L"Rainmeter", L"DisableDragging", dragging ? L"1" : L"0", m_IniFile.c_str());
|
2010-11-24 15:34:07 +00:00
|
|
|
}
|
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
void Rainmeter::SetDisableVersionCheck(bool check)
|
2011-08-28 10:58:26 +00:00
|
|
|
{
|
|
|
|
m_DisableVersionCheck = check;
|
|
|
|
WritePrivateProfileString(L"Rainmeter", L"DisableVersionCheck", check ? L"1" : L"0" , m_IniFile.c_str());
|
|
|
|
}
|
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
void Rainmeter::TestSettingsFile(bool bDefaultIniLocation)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2012-05-30 04:08:50 +00:00
|
|
|
const WCHAR* iniFile = m_IniFile.c_str();
|
2013-05-31 14:18:52 +00:00
|
|
|
if (!System::IsFileWritable(iniFile))
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2011-09-24 09:13:13 +00:00
|
|
|
std::wstring error = GetString(ID_STR_SETTINGSNOTWRITABLE);
|
2009-02-10 18:37:48 +00:00
|
|
|
|
2011-05-02 11:58:02 +00:00
|
|
|
if (!bDefaultIniLocation)
|
2009-07-24 07:56:37 +00:00
|
|
|
{
|
2009-08-26 17:37:15 +00:00
|
|
|
std::wstring strTarget = L"%APPDATA%\\Rainmeter\\";
|
2013-06-12 18:14:55 +00:00
|
|
|
PathUtil::ExpandEnvironmentVariables(strTarget);
|
2009-07-24 07:56:37 +00:00
|
|
|
|
2012-05-30 04:08:50 +00:00
|
|
|
error += GetFormattedString(ID_STR_SETTINGSMOVEFILE, iniFile, strTarget.c_str());
|
2009-07-24 07:56:37 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-05-30 04:08:50 +00:00
|
|
|
error += GetFormattedString(ID_STR_SETTINGSREADONLY, iniFile);
|
2009-07-24 07:56:37 +00:00
|
|
|
}
|
2009-02-10 18:37:48 +00:00
|
|
|
|
2013-05-31 14:28:39 +00:00
|
|
|
ShowMessage(nullptr, error.c_str(), MB_OK | MB_ICONERROR);
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
2009-07-26 21:08:46 +00:00
|
|
|
}
|
2013-07-25 22:44:06 +00:00
|
|
|
|
|
|
|
void Rainmeter::SetUseD2D(bool enabled)
|
|
|
|
{
|
|
|
|
m_UseD2D = enabled;
|
|
|
|
|
|
|
|
// Save to Rainmeter.ini
|
|
|
|
WritePrivateProfileString(L"Rainmeter", L"UseD2D", enabled ? L"1" : L"0", m_IniFile.c_str());
|
|
|
|
|
|
|
|
RefreshAll();
|
|
|
|
}
|