Make Rainmeter a singleton class

This change is part of making the Libray project more testable. The old g_Rainmeter global pointer has been replaced with a GetRainmeter() function to guarantee that the object exists in some state.
This commit is contained in:
Birunthan Mohanathas 2013-06-13 17:20:27 +03:00
parent a80c905be9
commit 04090b232a
26 changed files with 272 additions and 314 deletions

View File

@ -29,8 +29,6 @@
#include "TrayWindow.h" #include "TrayWindow.h"
#include "resource.h" #include "resource.h"
extern Rainmeter* g_Rainmeter;
namespace { namespace {
typedef void (* BangHandlerFunc)(std::vector<std::wstring>& args, MeterWindow* skin); typedef void (* BangHandlerFunc)(std::vector<std::wstring>& args, MeterWindow* skin);
@ -160,7 +158,7 @@ void DoBang(const BangInfo& bangInfo, std::vector<std::wstring>& args, MeterWind
const std::wstring& folderPath = args[bangInfo.argCount]; const std::wstring& folderPath = args[bangInfo.argCount];
if (!folderPath.empty() && (folderPath.length() != 1 || folderPath[0] != L'*')) if (!folderPath.empty() && (folderPath.length() != 1 || folderPath[0] != L'*'))
{ {
MeterWindow* skin = g_Rainmeter->GetMeterWindow(folderPath); MeterWindow* skin = GetRainmeter().GetMeterWindow(folderPath);
if (skin) if (skin)
{ {
skin->DoBang(bangInfo.bang, args); skin->DoBang(bangInfo.bang, args);
@ -174,7 +172,7 @@ void DoBang(const BangInfo& bangInfo, std::vector<std::wstring>& args, MeterWind
} }
// No skin defined -> apply to all. // No skin defined -> apply to all.
for (const auto& ip : g_Rainmeter->GetAllMeterWindows()) for (const auto& ip : GetRainmeter().GetAllMeterWindows())
{ {
ip.second->DoBang(bangInfo.bang, args); ip.second->DoBang(bangInfo.bang, args);
} }
@ -208,7 +206,7 @@ void DoGroupBang(const BangInfo& bangInfo, std::vector<std::wstring>& args, Mete
if (args.size() > bangInfo.argCount) if (args.size() > bangInfo.argCount)
{ {
std::multimap<int, MeterWindow*> windows; std::multimap<int, MeterWindow*> windows;
g_Rainmeter->GetMeterWindowsByLoadOrder(windows, args[bangInfo.argCount]); GetRainmeter().GetMeterWindowsByLoadOrder(windows, args[bangInfo.argCount]);
// Remove extra parameters (including group). // Remove extra parameters (including group).
args.resize(bangInfo.argCount); args.resize(bangInfo.argCount);
@ -579,24 +577,24 @@ void CommandHandler::DoActivateSkinBang(std::vector<std::wstring>& args, MeterWi
{ {
if (args.size() == 1) if (args.size() == 1)
{ {
int index = g_Rainmeter->FindSkinFolderIndex(args[0]); int index = GetRainmeter().FindSkinFolderIndex(args[0]);
if (index != -1) if (index != -1)
{ {
const Rainmeter::SkinFolder& skinFolder = g_Rainmeter->m_SkinFolders[index]; const Rainmeter::SkinFolder& skinFolder = GetRainmeter().m_SkinFolders[index];
if (!(skinFolder.active == 1 && skinFolder.files.size() == 1)) if (!(skinFolder.active == 1 && skinFolder.files.size() == 1))
{ {
// Activate the next index. // Activate the next index.
g_Rainmeter->ActivateSkin(index, (skinFolder.active < skinFolder.files.size()) ? skinFolder.active : 0); GetRainmeter().ActivateSkin(index, (skinFolder.active < skinFolder.files.size()) ? skinFolder.active : 0);
} }
return; return;
} }
} }
else if (args.size() > 1) else if (args.size() > 1)
{ {
std::pair<int, int> indexes = g_Rainmeter->GetMeterWindowIndex(args[0], args[1]); std::pair<int, int> indexes = GetRainmeter().GetMeterWindowIndex(args[0], args[1]);
if (indexes.first != -1 && indexes.second != -1) if (indexes.first != -1 && indexes.second != -1)
{ {
g_Rainmeter->ActivateSkin(indexes.first, indexes.second); GetRainmeter().ActivateSkin(indexes.first, indexes.second);
return; return;
} }
} }
@ -608,7 +606,7 @@ void CommandHandler::DoDeactivateSkinBang(std::vector<std::wstring>& args, Meter
{ {
if (!args.empty()) if (!args.empty())
{ {
skin = g_Rainmeter->GetMeterWindow(args[0]); skin = GetRainmeter().GetMeterWindow(args[0]);
if (!skin) if (!skin)
{ {
LogWarningF(L"!DeactivateConfig: \"%s\" not active", args[0].c_str()); LogWarningF(L"!DeactivateConfig: \"%s\" not active", args[0].c_str());
@ -618,7 +616,7 @@ void CommandHandler::DoDeactivateSkinBang(std::vector<std::wstring>& args, Meter
if (skin) if (skin)
{ {
g_Rainmeter->DeactivateSkin(skin, -1); GetRainmeter().DeactivateSkin(skin, -1);
} }
else else
{ {
@ -630,10 +628,10 @@ void CommandHandler::DoToggleSkinBang(std::vector<std::wstring>& args, MeterWind
{ {
if (args.size() >= 2) if (args.size() >= 2)
{ {
MeterWindow* skin = g_Rainmeter->GetMeterWindow(args[0]); MeterWindow* skin = GetRainmeter().GetMeterWindow(args[0]);
if (skin) if (skin)
{ {
g_Rainmeter->DeactivateSkin(skin, -1); GetRainmeter().DeactivateSkin(skin, -1);
return; return;
} }
@ -651,10 +649,10 @@ void CommandHandler::DoDeactivateSkinGroupBang(std::vector<std::wstring>& args,
if (!args.empty()) if (!args.empty())
{ {
std::multimap<int, MeterWindow*> windows; std::multimap<int, MeterWindow*> windows;
g_Rainmeter->GetMeterWindowsByLoadOrder(windows, args[0]); GetRainmeter().GetMeterWindowsByLoadOrder(windows, args[0]);
for (const auto& ip : windows) for (const auto& ip : windows)
{ {
g_Rainmeter->DeactivateSkin(ip.second, -1); GetRainmeter().DeactivateSkin(ip.second, -1);
} }
} }
else else
@ -673,12 +671,12 @@ void CommandHandler::DoLoadLayoutBang(std::vector<std::wstring>& args, MeterWind
std::wstring command = L"!LoadLayout \""; std::wstring command = L"!LoadLayout \"";
command += args[0]; command += args[0];
command += L'"'; command += L'"';
g_Rainmeter->DelayedExecuteCommand(command.c_str()); GetRainmeter().DelayedExecuteCommand(command.c_str());
} }
else else
{ {
// Not called from a skin (or called with delay). // Not called from a skin (or called with delay).
g_Rainmeter->LoadLayout(args[0]); GetRainmeter().LoadLayout(args[0]);
} }
} }
} }
@ -730,7 +728,7 @@ void CommandHandler::DoSkinMenuBang(std::vector<std::wstring>& args, MeterWindow
{ {
if (!args.empty()) if (!args.empty())
{ {
skin = g_Rainmeter->GetMeterWindow(args[0]); skin = GetRainmeter().GetMeterWindow(args[0]);
if (!skin) if (!skin)
{ {
LogWarningF(L"!SkinMenu: \"%s\" not active", args[0].c_str()); LogWarningF(L"!SkinMenu: \"%s\" not active", args[0].c_str());
@ -741,7 +739,7 @@ void CommandHandler::DoSkinMenuBang(std::vector<std::wstring>& args, MeterWindow
if (skin) if (skin)
{ {
POINT pos = System::GetCursorPosition(); POINT pos = System::GetCursorPosition();
g_Rainmeter->ShowContextMenu(pos, skin); GetRainmeter().ShowContextMenu(pos, skin);
} }
else else
{ {
@ -752,12 +750,12 @@ void CommandHandler::DoSkinMenuBang(std::vector<std::wstring>& args, MeterWindow
void CommandHandler::DoTrayMenuBang(std::vector<std::wstring>& args, MeterWindow* skin) void CommandHandler::DoTrayMenuBang(std::vector<std::wstring>& args, MeterWindow* skin)
{ {
POINT pos = System::GetCursorPosition(); POINT pos = System::GetCursorPosition();
g_Rainmeter->ShowContextMenu(pos, nullptr); GetRainmeter().ShowContextMenu(pos, nullptr);
} }
void CommandHandler::DoResetStatsBang(std::vector<std::wstring>& args, MeterWindow* meterWindow) void CommandHandler::DoResetStatsBang(std::vector<std::wstring>& args, MeterWindow* meterWindow)
{ {
g_Rainmeter->ResetStats(); GetRainmeter().ResetStats();
} }
void CommandHandler::DoWriteKeyValueBang(std::vector<std::wstring>& args, MeterWindow* skin) void CommandHandler::DoWriteKeyValueBang(std::vector<std::wstring>& args, MeterWindow* skin)
@ -787,8 +785,8 @@ void CommandHandler::DoWriteKeyValueBang(std::vector<std::wstring>& args, MeterW
return; return;
} }
if (_wcsnicmp(iniFile, g_Rainmeter->m_SkinPath.c_str(), g_Rainmeter->m_SkinPath.size()) != 0 && if (_wcsnicmp(iniFile, GetRainmeter().m_SkinPath.c_str(), GetRainmeter().m_SkinPath.size()) != 0 &&
_wcsnicmp(iniFile, g_Rainmeter->m_SettingsPath.c_str(), g_Rainmeter->m_SettingsPath.size()) != 0) _wcsnicmp(iniFile, GetRainmeter().m_SettingsPath.c_str(), GetRainmeter().m_SettingsPath.size()) != 0)
{ {
LogErrorF(L"!WriteKeyValue: Illegal path: %s", iniFile); LogErrorF(L"!WriteKeyValue: Illegal path: %s", iniFile);
return; return;
@ -821,14 +819,14 @@ void CommandHandler::DoWriteKeyValueBang(std::vector<std::wstring>& args, MeterW
if (temporary) if (temporary)
{ {
if (g_Rainmeter->GetDebug()) if (GetRainmeter().GetDebug())
{ {
LogDebugF(L"!WriteKeyValue: Writing to: %s (Temp: %s)", iniFile, strIniWrite.c_str()); LogDebugF(L"!WriteKeyValue: Writing to: %s (Temp: %s)", iniFile, strIniWrite.c_str());
} }
} }
else else
{ {
if (g_Rainmeter->GetDebug()) if (GetRainmeter().GetDebug())
{ {
LogDebugF(L"!WriteKeyValue: Writing to: %s", iniFile); LogDebugF(L"!WriteKeyValue: Writing to: %s", iniFile);
} }
@ -925,13 +923,13 @@ void CommandHandler::DoLogBang(std::vector<std::wstring>& args, MeterWindow* ski
void CommandHandler::DoRefreshApp(std::vector<std::wstring>& args, MeterWindow* meterWindow) void CommandHandler::DoRefreshApp(std::vector<std::wstring>& args, MeterWindow* meterWindow)
{ {
// Refresh needs to be delayed since it crashes if done during Update(). // Refresh needs to be delayed since it crashes if done during Update().
PostMessage(g_Rainmeter->m_Window, WM_RAINMETER_DELAYED_REFRESH_ALL, 0, 0); PostMessage(GetRainmeter().m_Window, WM_RAINMETER_DELAYED_REFRESH_ALL, 0, 0);
} }
void CommandHandler::DoQuitBang(std::vector<std::wstring>& args, MeterWindow* meterWindow) void CommandHandler::DoQuitBang(std::vector<std::wstring>& args, MeterWindow* meterWindow)
{ {
// Quit needs to be delayed since it crashes if done during Update(). // Quit needs to be delayed since it crashes if done during Update().
PostMessage(g_Rainmeter->GetTrayWindow()->GetWindow(), WM_COMMAND, MAKEWPARAM(IDM_QUIT, 0), 0); PostMessage(GetRainmeter().GetTrayWindow()->GetWindow(), WM_COMMAND, MAKEWPARAM(IDM_QUIT, 0), 0);
} }
void CommandHandler::DoLsBoxHookBang(std::vector<std::wstring>& args, MeterWindow* meterWindow) void CommandHandler::DoLsBoxHookBang(std::vector<std::wstring>& args, MeterWindow* meterWindow)

View File

@ -27,8 +27,6 @@
#include "Meter.h" #include "Meter.h"
#include "resource.h" #include "resource.h"
extern Rainmeter* g_Rainmeter;
using namespace Gdiplus; using namespace Gdiplus;
std::unordered_map<std::wstring, std::wstring> ConfigParser::c_MonitorVariables; std::unordered_map<std::wstring, std::wstring> ConfigParser::c_MonitorVariables;
@ -94,13 +92,13 @@ void ConfigParser::SetBuiltInVariables(const std::wstring& filename, const std::
return m_BuiltInVariables.insert(std::make_pair(name, value)); return m_BuiltInVariables.insert(std::make_pair(name, value));
}; };
insertVariable(L"PROGRAMPATH", g_Rainmeter->GetPath()); insertVariable(L"PROGRAMPATH", GetRainmeter().GetPath());
insertVariable(L"PROGRAMDRIVE", g_Rainmeter->GetDrive()); insertVariable(L"PROGRAMDRIVE", GetRainmeter().GetDrive());
insertVariable(L"SETTINGSPATH", g_Rainmeter->GetSettingsPath()); insertVariable(L"SETTINGSPATH", GetRainmeter().GetSettingsPath());
insertVariable(L"SKINSPATH", g_Rainmeter->GetSkinPath()); insertVariable(L"SKINSPATH", GetRainmeter().GetSkinPath());
insertVariable(L"PLUGINSPATH", g_Rainmeter->GetPluginPath()); insertVariable(L"PLUGINSPATH", GetRainmeter().GetPluginPath());
insertVariable(L"CURRENTPATH", PathUtil::GetFolderFromFilePath(filename)); insertVariable(L"CURRENTPATH", PathUtil::GetFolderFromFilePath(filename));
insertVariable(L"ADDONSPATH", g_Rainmeter->GetAddonPath()); insertVariable(L"ADDONSPATH", GetRainmeter().GetAddonPath());
if (meterWindow) if (meterWindow)
{ {
@ -1289,7 +1287,7 @@ void ConfigParser::ReadIniFile(const std::wstring& iniFile, LPCTSTR skinSection,
{ {
if (depth > 100) // Is 100 enough to assume the include loop never ends? if (depth > 100) // Is 100 enough to assume the include loop never ends?
{ {
g_Rainmeter->ShowMessage(nullptr, GetString(ID_STR_INCLUDEINFINITELOOP), MB_OK | MB_ICONERROR); GetRainmeter().ShowMessage(nullptr, GetString(ID_STR_INCLUDEINFINITELOOP), MB_OK | MB_ICONERROR);
return; return;
} }
@ -1306,11 +1304,11 @@ void ConfigParser::ReadIniFile(const std::wstring& iniFile, LPCTSTR skinSection,
if (temporary) if (temporary)
{ {
if (g_Rainmeter->GetDebug()) LogDebugF(L"Reading file: %s (Temp: %s)", iniFile.c_str(), iniRead.c_str()); if (GetRainmeter().GetDebug()) LogDebugF(L"Reading file: %s (Temp: %s)", iniFile.c_str(), iniRead.c_str());
} }
else else
{ {
if (g_Rainmeter->GetDebug()) LogDebugF(L"Reading file: %s", iniFile.c_str()); if (GetRainmeter().GetDebug()) LogDebugF(L"Reading file: %s", iniFile.c_str());
iniRead = iniFile; iniRead = iniFile;
} }

View File

@ -26,8 +26,6 @@
#include "DialogAbout.h" #include "DialogAbout.h"
#include "../Version.h" #include "../Version.h"
extern Rainmeter* g_Rainmeter;
WINDOWPLACEMENT DialogAbout::c_WindowPlacement = {0}; WINDOWPLACEMENT DialogAbout::c_WindowPlacement = {0};
DialogAbout* DialogAbout::c_Dialog = nullptr; DialogAbout* DialogAbout::c_Dialog = nullptr;
@ -63,7 +61,7 @@ void DialogAbout::Open(int tab)
0, 0, 400, 210, 0, 0, 400, 210,
DS_CENTER | WS_POPUP | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME, DS_CENTER | WS_POPUP | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME,
WS_EX_APPWINDOW | WS_EX_CONTROLPARENT | ((*GetString(ID_STR_ISRTL) == L'1') ? WS_EX_LAYOUTRTL : 0), WS_EX_APPWINDOW | WS_EX_CONTROLPARENT | ((*GetString(ID_STR_ISRTL) == L'1') ? WS_EX_LAYOUTRTL : 0),
g_Rainmeter->GetWindow()); GetRainmeter().GetWindow());
// Fake WM_NOTIFY to change tab // Fake WM_NOTIFY to change tab
NMHDR nm; NMHDR nm;
@ -702,7 +700,7 @@ void DialogAbout::TabSkins::UpdateSkinList()
// Add entries for each skin // Add entries for each skin
std::wstring::size_type maxLength = 0; std::wstring::size_type maxLength = 0;
const std::map<std::wstring, MeterWindow*>& windows = g_Rainmeter->GetAllMeterWindows(); const std::map<std::wstring, MeterWindow*>& windows = GetRainmeter().GetAllMeterWindows();
std::map<std::wstring, MeterWindow*>::const_iterator iter = windows.begin(); std::map<std::wstring, MeterWindow*>::const_iterator iter = windows.begin();
bool found = false; bool found = false;
for ( ; iter != windows.end(); ++iter) for ( ; iter != windows.end(); ++iter)
@ -756,7 +754,7 @@ void DialogAbout::TabSkins::UpdateMeasureList(MeterWindow* meterWindow)
HWND item = GetControl(Id_SkinsListBox); HWND item = GetControl(Id_SkinsListBox);
int selected = (int)SendMessage(item, LB_GETCURSEL, 0, 0); int selected = (int)SendMessage(item, LB_GETCURSEL, 0, 0);
const std::map<std::wstring, MeterWindow*>& windows = g_Rainmeter->GetAllMeterWindows(); const std::map<std::wstring, MeterWindow*>& windows = GetRainmeter().GetAllMeterWindows();
std::map<std::wstring, MeterWindow*>::const_iterator iter = windows.begin(); std::map<std::wstring, MeterWindow*>::const_iterator iter = windows.begin();
while (selected && iter != windows.end()) while (selected && iter != windows.end())
{ {
@ -1090,10 +1088,10 @@ void DialogAbout::TabPlugins::Initialize()
FindClose(hSearch); FindClose(hSearch);
}; };
findPlugins(g_Rainmeter->GetPluginPath()); findPlugins(GetRainmeter().GetPluginPath());
if (g_Rainmeter->HasUserPluginPath()) if (GetRainmeter().HasUserPluginPath())
{ {
findPlugins(g_Rainmeter->GetUserPluginPath()); findPlugins(GetRainmeter().GetUserPluginPath());
} }
m_Initialized = true; m_Initialized = true;
@ -1181,15 +1179,15 @@ void DialogAbout::TabVersion::Initialize()
SetWindowText(item, tmpSz); SetWindowText(item, tmpSz);
item = GetControl(Id_PathLabel); item = GetControl(Id_PathLabel);
std::wstring text = L"Path: " + g_Rainmeter->GetPath(); std::wstring text = L"Path: " + GetRainmeter().GetPath();
SetWindowText(item, text.c_str()); SetWindowText(item, text.c_str());
item = GetControl(Id_IniFileLabel); item = GetControl(Id_IniFileLabel);
text = L"IniFile: " + g_Rainmeter->GetIniFile(); text = L"IniFile: " + GetRainmeter().GetIniFile();
SetWindowText(item, text.c_str()); SetWindowText(item, text.c_str());
item = GetControl(Id_SkinPathLabel); item = GetControl(Id_SkinPathLabel);
text = L"SkinPath: " + g_Rainmeter->GetSkinPath(); text = L"SkinPath: " + GetRainmeter().GetSkinPath();
SetWindowText(item, text.c_str()); SetWindowText(item, text.c_str());
m_Initialized = true; m_Initialized = true;
@ -1228,11 +1226,11 @@ INT_PTR DialogAbout::TabVersion::OnCommand(WPARAM wParam, LPARAM lParam)
int len = _snwprintf_s(tmpSz, _TRUNCATE, L"%s%s r%i %s (%s)", APPVERSION, revision_beta ? L" beta" : L"", revision_number, APPBITS, APPDATE); int len = _snwprintf_s(tmpSz, _TRUNCATE, L"%s%s r%i %s (%s)", APPVERSION, revision_beta ? L" beta" : L"", revision_number, APPBITS, APPDATE);
std::wstring text(tmpSz, len); std::wstring text(tmpSz, len);
text += L"\nPath: "; text += L"\nPath: ";
text += g_Rainmeter->GetPath(); text += GetRainmeter().GetPath();
text += L"\nIniFile: "; text += L"\nIniFile: ";
text += g_Rainmeter->GetIniFile(); text += GetRainmeter().GetIniFile();
text += L"\nSkinPath: "; text += L"\nSkinPath: ";
text += g_Rainmeter->GetSkinPath(); text += GetRainmeter().GetSkinPath();
System::SetClipboardText(text); System::SetClipboardText(text);
} }
break; break;

View File

@ -29,8 +29,6 @@
#include "../Version.h" #include "../Version.h"
#include <Commdlg.h> #include <Commdlg.h>
extern Rainmeter* g_Rainmeter;
WINDOWPLACEMENT DialogManage::c_WindowPlacement = {0}; WINDOWPLACEMENT DialogManage::c_WindowPlacement = {0};
DialogManage* DialogManage::c_Dialog = nullptr; DialogManage* DialogManage::c_Dialog = nullptr;
@ -90,7 +88,7 @@ void DialogManage::Open(int tab)
0, 0, 500, 322, 0, 0, 500, 322,
DS_CENTER | WS_POPUP | WS_MINIMIZEBOX | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME, DS_CENTER | WS_POPUP | WS_MINIMIZEBOX | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME,
WS_EX_APPWINDOW | WS_EX_CONTROLPARENT | ((*GetString(ID_STR_ISRTL) == L'1') ? WS_EX_LAYOUTRTL : 0), WS_EX_APPWINDOW | WS_EX_CONTROLPARENT | ((*GetString(ID_STR_ISRTL) == L'1') ? WS_EX_LAYOUTRTL : 0),
g_Rainmeter->GetWindow()); GetRainmeter().GetWindow());
// Fake WM_NOTIFY to change tab // Fake WM_NOTIFY to change tab
NMHDR nm; NMHDR nm;
@ -256,11 +254,11 @@ INT_PTR DialogManage::OnCommand(WPARAM wParam, LPARAM lParam)
switch (LOWORD(wParam)) switch (LOWORD(wParam))
{ {
case Id_RefreshAllButton: case Id_RefreshAllButton:
g_Rainmeter->RefreshAll(); GetRainmeter().RefreshAll();
break; break;
case Id_EditSettingsButton: case Id_EditSettingsButton:
g_Rainmeter->EditSettings(); GetRainmeter().EditSettings();
break; break;
case Id_OpenLogButton: case Id_OpenLogButton:
@ -572,7 +570,7 @@ void DialogManage::TabSkins::Update(MeterWindow* meterWindow, bool deleted)
tvi.item.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE; tvi.item.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
tvi.item.iImage = tvi.item.iSelectedImage = 0; tvi.item.iImage = tvi.item.iSelectedImage = 0;
if (!g_Rainmeter->m_SkinFolders.empty()) if (!GetRainmeter().m_SkinFolders.empty())
{ {
PopulateTree(item, tvi); PopulateTree(item, tvi);
} }
@ -610,7 +608,7 @@ void DialogManage::TabSkins::SetControls()
EnableWindow(item, TRUE); EnableWindow(item, TRUE);
item = GetControl(Id_DraggableCheckBox); item = GetControl(Id_DraggableCheckBox);
if (g_Rainmeter->GetDisableDragging()) if (GetRainmeter().GetDisableDragging())
{ {
EnableWindow(item, FALSE); EnableWindow(item, FALSE);
Button_SetCheck(item, BST_UNCHECKED); Button_SetCheck(item, BST_UNCHECKED);
@ -650,7 +648,7 @@ void DialogManage::TabSkins::SetControls()
item = GetControl(Id_LoadOrderEdit); item = GetControl(Id_LoadOrderEdit);
EnableWindow(item, TRUE); EnableWindow(item, TRUE);
_itow_s(g_Rainmeter->GetLoadOrder(m_SkinFolderPath), buffer, 10); _itow_s(GetRainmeter().GetLoadOrder(m_SkinFolderPath), buffer, 10);
SetWindowText(item, buffer); SetWindowText(item, buffer);
item = GetControl(Id_OnHoverDropDownList); item = GetControl(Id_OnHoverDropDownList);
@ -763,10 +761,10 @@ void DialogManage::TabSkins::ReadSkin()
item = GetControl(Id_EditButton); item = GetControl(Id_EditButton);
EnableWindow(item, TRUE); EnableWindow(item, TRUE);
std::wstring file = g_Rainmeter->GetSkinPath() + m_SkinFolderPath; std::wstring file = GetRainmeter().GetSkinPath() + m_SkinFolderPath;
file += L'\\'; file += L'\\';
file += m_SkinFileName; file += m_SkinFileName;
m_SkinWindow = g_Rainmeter->GetMeterWindowByINI(file); m_SkinWindow = GetRainmeter().GetMeterWindowByINI(file);
if (!m_SkinWindow) if (!m_SkinWindow)
{ {
DisableControls(); DisableControls();
@ -883,12 +881,12 @@ std::wstring DialogManage::TabSkins::GetTreeSelectionPath(HWND tree)
*/ */
int DialogManage::TabSkins::PopulateTree(HWND tree, TVINSERTSTRUCT& tvi, int index) int DialogManage::TabSkins::PopulateTree(HWND tree, TVINSERTSTRUCT& tvi, int index)
{ {
int initialLevel = g_Rainmeter->m_SkinFolders[index].level; int initialLevel = GetRainmeter().m_SkinFolders[index].level;
const size_t max = g_Rainmeter->m_SkinFolders.size(); const size_t max = GetRainmeter().m_SkinFolders.size();
while (index < max) while (index < max)
{ {
const Rainmeter::SkinFolder& skinFolder = g_Rainmeter->m_SkinFolders[index]; const Rainmeter::SkinFolder& skinFolder = GetRainmeter().m_SkinFolders[index];
if (skinFolder.level != initialLevel) if (skinFolder.level != initialLevel)
{ {
return index - 1; return index - 1;
@ -903,7 +901,7 @@ int DialogManage::TabSkins::PopulateTree(HWND tree, TVINSERTSTRUCT& tvi, int ind
// Add subfolders // Add subfolders
if ((index + 1) < max && if ((index + 1) < max &&
g_Rainmeter->m_SkinFolders[index + 1].level == initialLevel + 1) GetRainmeter().m_SkinFolders[index + 1].level == initialLevel + 1)
{ {
index = PopulateTree(tree, tvi, index + 1); index = PopulateTree(tree, tvi, index + 1);
} }
@ -1007,9 +1005,9 @@ INT_PTR DialogManage::TabSkins::OnCommand(WPARAM wParam, LPARAM lParam)
HMENU menu = CreatePopupMenu(); HMENU menu = CreatePopupMenu();
// Add active skins to menu // Add active skins to menu
std::map<std::wstring, MeterWindow*>::const_iterator iter = g_Rainmeter->GetAllMeterWindows().begin(); std::map<std::wstring, MeterWindow*>::const_iterator iter = GetRainmeter().GetAllMeterWindows().begin();
int index = 0; int index = 0;
for ( ; iter != g_Rainmeter->GetAllMeterWindows().end(); ++iter) for ( ; iter != GetRainmeter().GetAllMeterWindows().end(); ++iter)
{ {
std::wstring name = ((*iter).second)->GetFolderPath() + L'\\'; std::wstring name = ((*iter).second)->GetFolderPath() + L'\\';
name += ((*iter).second)->GetFileName(); name += ((*iter).second)->GetFileName();
@ -1040,7 +1038,7 @@ INT_PTR DialogManage::TabSkins::OnCommand(WPARAM wParam, LPARAM lParam)
case Id_CreateSkinPackageButton: case Id_CreateSkinPackageButton:
{ {
std::wstring file = g_Rainmeter->GetPath() + L"SkinInstaller.exe"; std::wstring file = GetRainmeter().GetPath() + L"SkinInstaller.exe";
CommandHandler::RunFile(file.c_str(), L"/Packager"); CommandHandler::RunFile(file.c_str(), L"/Packager");
} }
break; break;
@ -1050,11 +1048,11 @@ INT_PTR DialogManage::TabSkins::OnCommand(WPARAM wParam, LPARAM lParam)
if (!m_SkinWindow) if (!m_SkinWindow)
{ {
// Skin not active, load // Skin not active, load
std::pair<int, int> indexes = g_Rainmeter->GetMeterWindowIndex(m_SkinFolderPath, m_SkinFileName); std::pair<int, int> indexes = GetRainmeter().GetMeterWindowIndex(m_SkinFolderPath, m_SkinFileName);
if (indexes.first != -1 && indexes.second != -1) if (indexes.first != -1 && indexes.second != -1)
{ {
m_HandleCommands = false; m_HandleCommands = false;
g_Rainmeter->ActivateSkin(indexes.first, indexes.second); GetRainmeter().ActivateSkin(indexes.first, indexes.second);
m_HandleCommands = true; m_HandleCommands = true;
// Fake selection change to update controls // Fake selection change to update controls
@ -1068,7 +1066,7 @@ INT_PTR DialogManage::TabSkins::OnCommand(WPARAM wParam, LPARAM lParam)
else else
{ {
m_HandleCommands = false; m_HandleCommands = false;
g_Rainmeter->DeactivateSkin(m_SkinWindow, -1); GetRainmeter().DeactivateSkin(m_SkinWindow, -1);
} }
} }
break; break;
@ -1081,7 +1079,7 @@ INT_PTR DialogManage::TabSkins::OnCommand(WPARAM wParam, LPARAM lParam)
break; break;
case Id_EditButton: case Id_EditButton:
g_Rainmeter->EditSkinFile(m_SkinFolderPath, m_SkinFileName); GetRainmeter().EditSkinFile(m_SkinFolderPath, m_SkinFileName);
break; break;
case Id_XPositionEdit: case Id_XPositionEdit:
@ -1148,14 +1146,14 @@ INT_PTR DialogManage::TabSkins::OnCommand(WPARAM wParam, LPARAM lParam)
// Reset selection // Reset selection
Edit_SetSel((HWND)lParam, LOWORD(sel), HIWORD(sel)); Edit_SetSel((HWND)lParam, LOWORD(sel), HIWORD(sel));
WritePrivateProfileString(m_SkinFolderPath.c_str(), L"LoadOrder", buffer, g_Rainmeter->GetIniFile().c_str()); WritePrivateProfileString(m_SkinFolderPath.c_str(), L"LoadOrder", buffer, GetRainmeter().GetIniFile().c_str());
std::pair<int, int> indexes = g_Rainmeter->GetMeterWindowIndex(m_SkinWindow); std::pair<int, int> indexes = GetRainmeter().GetMeterWindowIndex(m_SkinWindow);
if (indexes.first != -1) if (indexes.first != -1)
{ {
g_Rainmeter->SetLoadOrder(indexes.first, value); GetRainmeter().SetLoadOrder(indexes.first, value);
std::multimap<int, MeterWindow*> windows; std::multimap<int, MeterWindow*> windows;
g_Rainmeter->GetMeterWindowsByLoadOrder(windows); GetRainmeter().GetMeterWindowsByLoadOrder(windows);
System::PrepareHelperWindow(); System::PrepareHelperWindow();
@ -1185,7 +1183,7 @@ INT_PTR DialogManage::TabSkins::OnCommand(WPARAM wParam, LPARAM lParam)
HMENU menu = MenuTemplate::CreateMenu(s_Menu, _countof(s_Menu), GetString); HMENU menu = MenuTemplate::CreateMenu(s_Menu, _countof(s_Menu), GetString);
if (menu) if (menu)
{ {
g_Rainmeter->CreateMonitorMenu(menu, m_SkinWindow); GetRainmeter().CreateMonitorMenu(menu, m_SkinWindow);
RECT r; RECT r;
GetWindowRect((HWND)lParam, &r); GetWindowRect((HWND)lParam, &r);
@ -1269,17 +1267,17 @@ INT_PTR DialogManage::TabSkins::OnCommand(WPARAM wParam, LPARAM lParam)
case IDM_MANAGESKINSMENU_OPENFOLDER: case IDM_MANAGESKINSMENU_OPENFOLDER:
{ {
HWND tree = GetControl(Id_SkinsTreeView); HWND tree = GetControl(Id_SkinsTreeView);
g_Rainmeter->OpenSkinFolder(GetTreeSelectionPath(tree)); GetRainmeter().OpenSkinFolder(GetTreeSelectionPath(tree));
} }
break; break;
default: default:
if (wParam >= ID_CONFIG_FIRST && wParam <= ID_CONFIG_LAST) if (wParam >= ID_CONFIG_FIRST && wParam <= ID_CONFIG_LAST)
{ {
std::map<std::wstring, MeterWindow*>::const_iterator iter = g_Rainmeter->GetAllMeterWindows().begin(); std::map<std::wstring, MeterWindow*>::const_iterator iter = GetRainmeter().GetAllMeterWindows().begin();
int index = (int)wParam - ID_CONFIG_FIRST; int index = (int)wParam - ID_CONFIG_FIRST;
int i = 0; int i = 0;
for ( ; iter != g_Rainmeter->GetAllMeterWindows().end(); ++iter) for ( ; iter != GetRainmeter().GetAllMeterWindows().end(); ++iter)
{ {
if (i == index) if (i == index)
{ {
@ -1319,7 +1317,7 @@ INT_PTR DialogManage::TabSkins::OnNotify(WPARAM wParam, LPARAM lParam)
case NM_CLICK: case NM_CLICK:
if (nm->idFrom == Id_AddMetadataLink) if (nm->idFrom == Id_AddMetadataLink)
{ {
std::wstring file = g_Rainmeter->GetSkinPath() + m_SkinFolderPath; std::wstring file = GetRainmeter().GetSkinPath() + m_SkinFolderPath;
file += L'\\'; file += L'\\';
file += m_SkinFileName; file += m_SkinFileName;
const WCHAR* str = L"\r\n" // Hack to add below [Rainmeter]. const WCHAR* str = L"\r\n" // Hack to add below [Rainmeter].
@ -1548,7 +1546,7 @@ void DialogManage::TabLayouts::Create(HWND owner)
void DialogManage::TabLayouts::Initialize() void DialogManage::TabLayouts::Initialize()
{ {
HWND item = GetControl(Id_List); HWND item = GetControl(Id_List);
const std::vector<std::wstring>& layouts = g_Rainmeter->GetAllLayouts(); const std::vector<std::wstring>& layouts = GetRainmeter().GetAllLayouts();
for (int i = 0, isize = layouts.size(); i < isize; ++i) for (int i = 0, isize = layouts.size(); i < isize; ++i)
{ {
ListBox_AddString(item, layouts[i].c_str()); ListBox_AddString(item, layouts[i].c_str());
@ -1611,7 +1609,7 @@ INT_PTR DialogManage::TabLayouts::OnCommand(WPARAM wParam, LPARAM lParam)
item = GetControl(Id_EditButton); item = GetControl(Id_EditButton);
EnableWindow(item, TRUE); EnableWindow(item, TRUE);
const std::vector<std::wstring>& layouts = g_Rainmeter->GetAllLayouts(); const std::vector<std::wstring>& layouts = GetRainmeter().GetAllLayouts();
item = GetControl(Id_List); item = GetControl(Id_List);
int sel = ListBox_GetCurSel(item); int sel = ListBox_GetCurSel(item);
@ -1628,7 +1626,7 @@ INT_PTR DialogManage::TabLayouts::OnCommand(WPARAM wParam, LPARAM lParam)
Edit_GetText(item, buffer, MAX_PATH); Edit_GetText(item, buffer, MAX_PATH);
std::wstring layout = buffer; std::wstring layout = buffer;
std::wstring path = g_Rainmeter->GetLayoutPath(); std::wstring path = GetRainmeter().GetLayoutPath();
CreateDirectory(path.c_str(), 0); CreateDirectory(path.c_str(), 0);
path += layout; path += layout;
@ -1636,7 +1634,7 @@ INT_PTR DialogManage::TabLayouts::OnCommand(WPARAM wParam, LPARAM lParam)
if (alreadyExists) if (alreadyExists)
{ {
std::wstring text = GetFormattedString(ID_STR_THEMEALREADYEXISTS, layout.c_str()); std::wstring text = GetFormattedString(ID_STR_THEMEALREADYEXISTS, layout.c_str());
if (g_Rainmeter->ShowMessage(m_Window, text.c_str(), MB_ICONWARNING | MB_YESNO) != IDYES) if (GetRainmeter().ShowMessage(m_Window, text.c_str(), MB_ICONWARNING | MB_YESNO) != IDYES)
{ {
// Cancel // Cancel
break; break;
@ -1653,10 +1651,10 @@ INT_PTR DialogManage::TabLayouts::OnCommand(WPARAM wParam, LPARAM lParam)
item = GetControl(Id_SaveEmptyThemeCheckBox); item = GetControl(Id_SaveEmptyThemeCheckBox);
if (Button_GetCheck(item) != BST_CHECKED) if (Button_GetCheck(item) != BST_CHECKED)
{ {
if (!System::CopyFiles(g_Rainmeter->GetIniFile(), path)) if (!System::CopyFiles(GetRainmeter().GetIniFile(), path))
{ {
std::wstring text = GetFormattedString(ID_STR_THEMESAVEFAIL, path.c_str()); std::wstring text = GetFormattedString(ID_STR_THEMESAVEFAIL, path.c_str());
g_Rainmeter->ShowMessage(m_Window, text.c_str(), MB_OK | MB_ICONERROR); GetRainmeter().ShowMessage(m_Window, text.c_str(), MB_OK | MB_ICONERROR);
break; break;
} }
@ -1698,7 +1696,7 @@ INT_PTR DialogManage::TabLayouts::OnCommand(WPARAM wParam, LPARAM lParam)
if (file == INVALID_HANDLE_VALUE) if (file == INVALID_HANDLE_VALUE)
{ {
std::wstring text = GetFormattedString(ID_STR_THEMESAVEFAIL, path.c_str()); std::wstring text = GetFormattedString(ID_STR_THEMESAVEFAIL, path.c_str());
g_Rainmeter->ShowMessage(m_Window, text.c_str(), MB_OK | MB_ICONERROR); GetRainmeter().ShowMessage(m_Window, text.c_str(), MB_OK | MB_ICONERROR);
break; break;
} }
@ -1710,7 +1708,7 @@ INT_PTR DialogManage::TabLayouts::OnCommand(WPARAM wParam, LPARAM lParam)
item = GetControl(Id_List); item = GetControl(Id_List);
ListBox_AddString(item, layout.c_str()); ListBox_AddString(item, layout.c_str());
g_Rainmeter->ScanForLayouts(); GetRainmeter().ScanForLayouts();
} }
} }
break; break;
@ -1719,7 +1717,7 @@ INT_PTR DialogManage::TabLayouts::OnCommand(WPARAM wParam, LPARAM lParam)
{ {
HWND item = GetControl(Id_List); HWND item = GetControl(Id_List);
int sel = ListBox_GetCurSel(item); int sel = ListBox_GetCurSel(item);
g_Rainmeter->LoadLayout(g_Rainmeter->m_Layouts[sel]); GetRainmeter().LoadLayout(GetRainmeter().m_Layouts[sel]);
} }
break; break;
@ -1727,13 +1725,13 @@ INT_PTR DialogManage::TabLayouts::OnCommand(WPARAM wParam, LPARAM lParam)
{ {
HWND item = GetControl(Id_List); HWND item = GetControl(Id_List);
int sel = ListBox_GetCurSel(item); int sel = ListBox_GetCurSel(item);
const std::vector<std::wstring>& layouts = g_Rainmeter->GetAllLayouts(); const std::vector<std::wstring>& layouts = GetRainmeter().GetAllLayouts();
std::wstring args = L"\"" + g_Rainmeter->GetLayoutPath(); std::wstring args = L"\"" + GetRainmeter().GetLayoutPath();
args += layouts[sel]; args += layouts[sel];
args += L"\\Rainmeter.ini"; args += L"\\Rainmeter.ini";
args += L'"'; args += L'"';
CommandHandler::RunFile(g_Rainmeter->GetSkinEditor().c_str(), args.c_str()); CommandHandler::RunFile(GetRainmeter().GetSkinEditor().c_str(), args.c_str());
} }
break; break;
@ -1741,16 +1739,16 @@ INT_PTR DialogManage::TabLayouts::OnCommand(WPARAM wParam, LPARAM lParam)
{ {
HWND item = GetControl(Id_List); HWND item = GetControl(Id_List);
int sel = ListBox_GetCurSel(item); int sel = ListBox_GetCurSel(item);
std::vector<std::wstring>& layouts = const_cast<std::vector<std::wstring>&>(g_Rainmeter->GetAllLayouts()); std::vector<std::wstring>& layouts = const_cast<std::vector<std::wstring>&>(GetRainmeter().GetAllLayouts());
std::wstring text = GetFormattedString(ID_STR_THEMEDELETE, layouts[sel].c_str()); std::wstring text = GetFormattedString(ID_STR_THEMEDELETE, layouts[sel].c_str());
if (g_Rainmeter->ShowMessage(m_Window, text.c_str(), MB_ICONQUESTION | MB_YESNO) != IDYES) if (GetRainmeter().ShowMessage(m_Window, text.c_str(), MB_ICONQUESTION | MB_YESNO) != IDYES)
{ {
// Cancel // Cancel
break; break;
} }
std::wstring folder = g_Rainmeter->GetLayoutPath(); std::wstring folder = GetRainmeter().GetLayoutPath();
folder += layouts[sel]; folder += layouts[sel];
if (System::RemoveFolder(folder)) if (System::RemoveFolder(folder))
@ -1861,7 +1859,7 @@ void DialogManage::TabSettings::Initialize()
// Scan for languages // Scan for languages
HWND item = GetControl(Id_LanguageDropDownList); HWND item = GetControl(Id_LanguageDropDownList);
std::wstring files = g_Rainmeter->GetPath() + L"Languages\\*.dll"; std::wstring files = GetRainmeter().GetPath() + L"Languages\\*.dll";
WIN32_FIND_DATA fd; WIN32_FIND_DATA fd;
HANDLE hSearch = FindFirstFile(files.c_str(), &fd); HANDLE hSearch = FindFirstFile(files.c_str(), &fd);
if (hSearch != INVALID_HANDLE_VALUE) if (hSearch != INVALID_HANDLE_VALUE)
@ -1886,7 +1884,7 @@ void DialogManage::TabSettings::Initialize()
int index = ComboBox_AddString(item, text.c_str()); int index = ComboBox_AddString(item, text.c_str());
ComboBox_SetItemData(item, index, (LPARAM)lcid); ComboBox_SetItemData(item, index, (LPARAM)lcid);
if (lcid == g_Rainmeter->GetResourceLCID()) if (lcid == GetRainmeter().GetResourceLCID())
{ {
ComboBox_SetCurSel(item, index); ComboBox_SetCurSel(item, index);
} }
@ -1898,18 +1896,18 @@ void DialogManage::TabSettings::Initialize()
FindClose(hSearch); FindClose(hSearch);
} }
Button_SetCheck(GetControl(Id_CheckForUpdatesCheckBox), !g_Rainmeter->GetDisableVersionCheck()); Button_SetCheck(GetControl(Id_CheckForUpdatesCheckBox), !GetRainmeter().GetDisableVersionCheck());
Button_SetCheck(GetControl(Id_LockSkinsCheckBox), g_Rainmeter->GetDisableDragging()); Button_SetCheck(GetControl(Id_LockSkinsCheckBox), GetRainmeter().GetDisableDragging());
Button_SetCheck(GetControl(Id_LogToFileCheckBox), Logger::GetInstance().IsLogToFile()); Button_SetCheck(GetControl(Id_LogToFileCheckBox), Logger::GetInstance().IsLogToFile());
Button_SetCheck(GetControl(Id_VerboseLoggingCheckbox), g_Rainmeter->GetDebug()); Button_SetCheck(GetControl(Id_VerboseLoggingCheckbox), GetRainmeter().GetDebug());
BOOL isLogFile = (_waccess(Logger::GetInstance().GetLogFilePath().c_str(), 0) != -1); BOOL isLogFile = (_waccess(Logger::GetInstance().GetLogFilePath().c_str(), 0) != -1);
EnableWindow(GetControl(Id_ShowLogFileButton), isLogFile); EnableWindow(GetControl(Id_ShowLogFileButton), isLogFile);
EnableWindow(GetControl(Id_DeleteLogFileButton), isLogFile); EnableWindow(GetControl(Id_DeleteLogFileButton), isLogFile);
Edit_SetText(GetControl(Id_EditorEdit), g_Rainmeter->GetSkinEditor().c_str()); Edit_SetText(GetControl(Id_EditorEdit), GetRainmeter().GetSkinEditor().c_str());
bool iconEnabled = g_Rainmeter->GetTrayWindow()->IsTrayIconEnabled(); bool iconEnabled = GetRainmeter().GetTrayWindow()->IsTrayIconEnabled();
Button_SetCheck(GetControl(Id_ShowTrayIconCheckBox), iconEnabled); Button_SetCheck(GetControl(Id_ShowTrayIconCheckBox), iconEnabled);
m_Initialized = true; m_Initialized = true;
@ -1940,18 +1938,18 @@ INT_PTR DialogManage::TabSettings::OnCommand(WPARAM wParam, LPARAM lParam)
{ {
int sel = ComboBox_GetCurSel((HWND)lParam); int sel = ComboBox_GetCurSel((HWND)lParam);
LCID lcid = (LCID)ComboBox_GetItemData((HWND)lParam, sel); LCID lcid = (LCID)ComboBox_GetItemData((HWND)lParam, sel);
if (lcid != g_Rainmeter->m_ResourceLCID) if (lcid != GetRainmeter().m_ResourceLCID)
{ {
WCHAR buffer[16]; WCHAR buffer[16];
_ultow(lcid, buffer, 10); _ultow(lcid, buffer, 10);
WritePrivateProfileString(L"Rainmeter", L"Language", buffer, g_Rainmeter->GetIniFile().c_str()); WritePrivateProfileString(L"Rainmeter", L"Language", buffer, GetRainmeter().GetIniFile().c_str());
std::wstring resource = g_Rainmeter->GetPath() + L"Languages\\"; std::wstring resource = GetRainmeter().GetPath() + L"Languages\\";
resource += buffer; resource += buffer;
resource += L".dll"; resource += L".dll";
FreeLibrary(g_Rainmeter->m_ResourceInstance); FreeLibrary(GetRainmeter().m_ResourceInstance);
g_Rainmeter->m_ResourceInstance = LoadLibraryEx(resource.c_str(), nullptr, DONT_RESOLVE_DLL_REFERENCES | LOAD_LIBRARY_AS_DATAFILE); GetRainmeter().m_ResourceInstance = LoadLibraryEx(resource.c_str(), nullptr, DONT_RESOLVE_DLL_REFERENCES | LOAD_LIBRARY_AS_DATAFILE);
g_Rainmeter->m_ResourceLCID = lcid; GetRainmeter().m_ResourceLCID = lcid;
if (DialogAbout::GetDialog()) if (DialogAbout::GetDialog())
{ {
@ -1959,42 +1957,42 @@ INT_PTR DialogManage::TabSettings::OnCommand(WPARAM wParam, LPARAM lParam)
SendMessage(DialogAbout::GetDialog()->GetWindow(), WM_CLOSE, 0, 0); SendMessage(DialogAbout::GetDialog()->GetWindow(), WM_CLOSE, 0, 0);
if (sel == 0) if (sel == 0)
{ {
g_Rainmeter->DelayedExecuteCommand(L"!About"); GetRainmeter().DelayedExecuteCommand(L"!About");
} }
else if (sel == 1) else if (sel == 1)
{ {
g_Rainmeter->DelayedExecuteCommand(L"!About Skins"); GetRainmeter().DelayedExecuteCommand(L"!About Skins");
} }
else if (sel == 2) else if (sel == 2)
{ {
g_Rainmeter->DelayedExecuteCommand(L"!About Plugins"); GetRainmeter().DelayedExecuteCommand(L"!About Plugins");
} }
else //if (sel == 3) else //if (sel == 3)
{ {
g_Rainmeter->DelayedExecuteCommand(L"!About Version"); GetRainmeter().DelayedExecuteCommand(L"!About Version");
} }
} }
SendMessage(c_Dialog->GetWindow(), WM_CLOSE, 0, 0); SendMessage(c_Dialog->GetWindow(), WM_CLOSE, 0, 0);
g_Rainmeter->DelayedExecuteCommand(L"!Manage Settings"); GetRainmeter().DelayedExecuteCommand(L"!Manage Settings");
} }
} }
break; break;
case Id_CheckForUpdatesCheckBox: case Id_CheckForUpdatesCheckBox:
g_Rainmeter->SetDisableVersionCheck(!g_Rainmeter->GetDisableVersionCheck()); GetRainmeter().SetDisableVersionCheck(!GetRainmeter().GetDisableVersionCheck());
break; break;
case Id_LockSkinsCheckBox: case Id_LockSkinsCheckBox:
g_Rainmeter->SetDisableDragging(!g_Rainmeter->GetDisableDragging()); GetRainmeter().SetDisableDragging(!GetRainmeter().GetDisableDragging());
break; break;
case Id_ResetStatisticsButton: case Id_ResetStatisticsButton:
g_Rainmeter->ResetStats(); GetRainmeter().ResetStats();
break; break;
case Id_ShowLogFileButton: case Id_ShowLogFileButton:
g_Rainmeter->ShowLogFile(); GetRainmeter().ShowLogFile();
break; break;
case Id_DeleteLogFileButton: case Id_DeleteLogFileButton:
@ -2024,7 +2022,7 @@ INT_PTR DialogManage::TabSettings::OnCommand(WPARAM wParam, LPARAM lParam)
break; break;
case Id_VerboseLoggingCheckbox: case Id_VerboseLoggingCheckbox:
g_Rainmeter->SetDebug(!g_Rainmeter->GetDebug()); GetRainmeter().SetDebug(!GetRainmeter().GetDebug());
break; break;
case Id_EditorEdit: case Id_EditorEdit:
@ -2033,7 +2031,7 @@ INT_PTR DialogManage::TabSettings::OnCommand(WPARAM wParam, LPARAM lParam)
WCHAR buffer[MAX_PATH]; WCHAR buffer[MAX_PATH];
if (GetWindowText((HWND)lParam, buffer, _countof(buffer)) > 0) if (GetWindowText((HWND)lParam, buffer, _countof(buffer)) > 0)
{ {
g_Rainmeter->SetSkinEditor(buffer); GetRainmeter().SetSkinEditor(buffer);
} }
} }
break; break;
@ -2043,7 +2041,7 @@ INT_PTR DialogManage::TabSettings::OnCommand(WPARAM wParam, LPARAM lParam)
WCHAR buffer[MAX_PATH]; WCHAR buffer[MAX_PATH];
buffer[0] = L'\0'; buffer[0] = L'\0';
std::wstring editor = g_Rainmeter->GetSkinEditor(); std::wstring editor = GetRainmeter().GetSkinEditor();
editor = editor.substr(0, editor.find_last_of(L"/\\")).c_str(); editor = editor.substr(0, editor.find_last_of(L"/\\")).c_str();
OPENFILENAME ofn = { sizeof(OPENFILENAME) }; OPENFILENAME ofn = { sizeof(OPENFILENAME) };
@ -2067,7 +2065,7 @@ INT_PTR DialogManage::TabSettings::OnCommand(WPARAM wParam, LPARAM lParam)
break; break;
case Id_ShowTrayIconCheckBox: case Id_ShowTrayIconCheckBox:
g_Rainmeter->GetTrayWindow()->SetTrayIcon(!g_Rainmeter->GetTrayWindow()->IsTrayIconEnabled()); GetRainmeter().GetTrayWindow()->SetTrayIcon(!GetRainmeter().GetTrayWindow()->IsTrayIconEnabled());
break; break;
default: default:

View File

@ -25,8 +25,6 @@
#define NULLCHECK(str) { if ((str) == nullptr) { (str) = L""; } } #define NULLCHECK(str) { if ((str) == nullptr) { (str) = L""; } }
extern Rainmeter* g_Rainmeter;
static std::wstring g_Buffer; static std::wstring g_Buffer;
LPCWSTR __stdcall RmReadString(void* rm, LPCWSTR option, LPCWSTR defValue, BOOL replaceMeasures) LPCWSTR __stdcall RmReadString(void* rm, LPCWSTR option, LPCWSTR defValue, BOOL replaceMeasures)
@ -76,7 +74,7 @@ void* __stdcall RmGet(void* rm, int type)
case RMG_SETTINGSFILE: case RMG_SETTINGSFILE:
{ {
return (void*)g_Rainmeter->GetDataFile().c_str(); return (void*)GetRainmeter().GetDataFile().c_str();
} }
case RMG_SKINNAME: case RMG_SKINNAME:
@ -103,7 +101,7 @@ void __stdcall RmExecute(void* skin, LPCWSTR command)
if (command) if (command)
{ {
// WM_RAINMETER_EXECUTE used instead of ExecuteCommand for thread-safety // WM_RAINMETER_EXECUTE used instead of ExecuteCommand for thread-safety
SendMessage(g_Rainmeter->GetWindow(), WM_RAINMETER_EXECUTE, (WPARAM)mw, (LPARAM)command); SendMessage(GetRainmeter().GetWindow(), WM_RAINMETER_EXECUTE, (WPARAM)mw, (LPARAM)command);
} }
} }
@ -112,7 +110,7 @@ BOOL LSLog(int nLevel, LPCWSTR unused, LPCWSTR pszMessage)
NULLCHECK(pszMessage); NULLCHECK(pszMessage);
// Ignore Level::Debug messages from plugins unless in debug mode // Ignore Level::Debug messages from plugins unless in debug mode
if (nLevel != (int)Logger::Level::Debug || g_Rainmeter->GetDebug()) if (nLevel != (int)Logger::Level::Debug || GetRainmeter().GetDebug())
{ {
Logger::GetInstance().Log((Logger::Level)nLevel, pszMessage); Logger::GetInstance().Log((Logger::Level)nLevel, pszMessage);
} }
@ -127,7 +125,7 @@ LPCWSTR ReadConfigString(LPCWSTR section, LPCWSTR option, LPCWSTR defValue)
NULLCHECK(option); NULLCHECK(option);
NULLCHECK(defValue); NULLCHECK(defValue);
ConfigParser* parser = g_Rainmeter->GetCurrentParser(); ConfigParser* parser = GetRainmeter().GetCurrentParser();
if (parser) if (parser)
{ {
return parser->ReadString(section, option, defValue, false).c_str(); return parser->ReadString(section, option, defValue, false).c_str();
@ -148,7 +146,7 @@ LPCWSTR PluginBridge(LPCWSTR command, LPCWSTR data)
if (_wcsicmp(command, L"GetConfig") == 0) if (_wcsicmp(command, L"GetConfig") == 0)
{ {
MeterWindow* meterWindow = g_Rainmeter->GetMeterWindowByINI(data); MeterWindow* meterWindow = GetRainmeter().GetMeterWindowByINI(data);
if (meterWindow) if (meterWindow)
{ {
g_Buffer = L"\""; g_Buffer = L"\"";
@ -167,7 +165,7 @@ LPCWSTR PluginBridge(LPCWSTR command, LPCWSTR data)
{ {
const std::wstring& config = subStrings[0]; const std::wstring& config = subStrings[0];
MeterWindow* meterWindow = g_Rainmeter->GetMeterWindow(config); MeterWindow* meterWindow = GetRainmeter().GetMeterWindow(config);
if (meterWindow) if (meterWindow)
{ {
WCHAR buf1[64]; WCHAR buf1[64];
@ -187,7 +185,7 @@ LPCWSTR PluginBridge(LPCWSTR command, LPCWSTR data)
{ {
const std::wstring& config = subStrings[0]; const std::wstring& config = subStrings[0];
MeterWindow* meterWindow = g_Rainmeter->GetMeterWindow(config); MeterWindow* meterWindow = GetRainmeter().GetMeterWindow(config);
if (meterWindow) if (meterWindow)
{ {
const std::wstring& variable = subStrings[1]; const std::wstring& variable = subStrings[1];
@ -208,7 +206,7 @@ LPCWSTR PluginBridge(LPCWSTR command, LPCWSTR data)
if (subStrings.size() == 3) if (subStrings.size() == 3)
{ {
MeterWindow* meterWindow = g_Rainmeter->GetMeterWindow(subStrings[0]); MeterWindow* meterWindow = GetRainmeter().GetMeterWindow(subStrings[0]);
if (meterWindow) if (meterWindow)
{ {
meterWindow->SetVariable(subStrings[1], subStrings[2]); meterWindow->SetVariable(subStrings[1], subStrings[2]);

View File

@ -22,8 +22,6 @@
#include "DialogAbout.h" #include "DialogAbout.h"
#include "System.h" #include "System.h"
extern Rainmeter* g_Rainmeter;
UINT GetUniqueID() UINT GetUniqueID()
{ {
static UINT id = 0; static UINT id = 0;
@ -33,7 +31,7 @@ UINT GetUniqueID()
WCHAR* GetString(UINT id) WCHAR* GetString(UINT id)
{ {
LPWSTR pData; LPWSTR pData;
int len = LoadString(g_Rainmeter->GetResourceInstance(), id, (LPWSTR)&pData, 0); int len = LoadString(GetRainmeter().GetResourceInstance(), id, (LPWSTR)&pData, 0);
return len ? pData : L""; return len ? pData : L"";
} }

View File

@ -24,8 +24,6 @@
#include "System.h" #include "System.h"
#include "resource.h" #include "resource.h"
extern Rainmeter* g_Rainmeter;
namespace { namespace {
const size_t MAX_LOG_ENTIRES = 20; const size_t MAX_LOG_ENTIRES = 20;
@ -65,7 +63,7 @@ void Logger::StartLogFile()
else else
{ {
const std::wstring text = GetFormattedString(ID_STR_LOGFILECREATEFAIL, filePath); const std::wstring text = GetFormattedString(ID_STR_LOGFILECREATEFAIL, filePath);
g_Rainmeter->ShowMessage(nullptr, text.c_str(), MB_OK | MB_ICONERROR); GetRainmeter().ShowMessage(nullptr, text.c_str(), MB_OK | MB_ICONERROR);
SetLogToFile(false); SetLogToFile(false);
return; return;
} }
@ -85,7 +83,7 @@ void Logger::DeleteLogFile()
if (_waccess(filePath, 0) != -1) if (_waccess(filePath, 0) != -1)
{ {
const std::wstring text = GetFormattedString(ID_STR_LOGFILEDELETE, filePath); const std::wstring text = GetFormattedString(ID_STR_LOGFILEDELETE, filePath);
const int res = g_Rainmeter->ShowMessage(nullptr, text.c_str(), MB_YESNO | MB_ICONQUESTION); const int res = GetRainmeter().ShowMessage(nullptr, text.c_str(), MB_YESNO | MB_ICONQUESTION);
if (res == IDYES) if (res == IDYES)
{ {
SetLogToFile(false); SetLogToFile(false);
@ -98,7 +96,7 @@ void Logger::SetLogToFile(bool logToFile)
{ {
m_LogToFile = logToFile; m_LogToFile = logToFile;
WritePrivateProfileString( WritePrivateProfileString(
L"Rainmeter", L"Logging", logToFile ? L"1" : L"0", g_Rainmeter->GetIniFile().c_str()); L"Rainmeter", L"Logging", logToFile ? L"1" : L"0", GetRainmeter().GetIniFile().c_str());
} }
void Logger::LogInternal(Level level, ULONGLONG timestamp, const WCHAR* msg) void Logger::LogInternal(Level level, ULONGLONG timestamp, const WCHAR* msg)

View File

@ -63,8 +63,6 @@ static const double g_TblScale[2][4] = {
const int MEDIAN_SIZE = 3; const int MEDIAN_SIZE = 3;
extern Rainmeter* g_Rainmeter;
/* /*
** The constructor ** The constructor
** **
@ -501,7 +499,7 @@ bool Measure::Update()
if (!m_IfEqualCommitted) if (!m_IfEqualCommitted)
{ {
m_IfEqualCommitted = true; // To avoid infinite loop from !Update m_IfEqualCommitted = true; // To avoid infinite loop from !Update
g_Rainmeter->ExecuteCommand(m_IfEqualAction.c_str(), m_MeterWindow); GetRainmeter().ExecuteCommand(m_IfEqualAction.c_str(), m_MeterWindow);
} }
} }
else else
@ -517,7 +515,7 @@ bool Measure::Update()
if (!m_IfAboveCommitted) if (!m_IfAboveCommitted)
{ {
m_IfAboveCommitted = true; // To avoid infinite loop from !Update m_IfAboveCommitted = true; // To avoid infinite loop from !Update
g_Rainmeter->ExecuteCommand(m_IfAboveAction.c_str(), m_MeterWindow); GetRainmeter().ExecuteCommand(m_IfAboveAction.c_str(), m_MeterWindow);
} }
} }
else else
@ -533,7 +531,7 @@ bool Measure::Update()
if (!m_IfBelowCommitted) if (!m_IfBelowCommitted)
{ {
m_IfBelowCommitted = true; // To avoid infinite loop from !Update m_IfBelowCommitted = true; // To avoid infinite loop from !Update
g_Rainmeter->ExecuteCommand(m_IfBelowAction.c_str(), m_MeterWindow); GetRainmeter().ExecuteCommand(m_IfBelowAction.c_str(), m_MeterWindow);
} }
} }
else else
@ -771,7 +769,7 @@ void Measure::DoChangeAction(bool execute)
{ {
if (m_OldValue->IsChanged(newValue, newStringValue)) if (m_OldValue->IsChanged(newValue, newStringValue))
{ {
g_Rainmeter->ExecuteCommand(m_OnChangeAction.c_str(), m_MeterWindow); GetRainmeter().ExecuteCommand(m_OnChangeAction.c_str(), m_MeterWindow);
} }
} }
else else

View File

@ -29,8 +29,6 @@ std::vector<ULONG64> MeasureNet::c_OldStatValues;
FPGETIFTABLE2 MeasureNet::c_GetIfTable2 = nullptr; FPGETIFTABLE2 MeasureNet::c_GetIfTable2 = nullptr;
FPFREEMIBTABLE MeasureNet::c_FreeMibTable = nullptr; FPFREEMIBTABLE MeasureNet::c_FreeMibTable = nullptr;
extern Rainmeter* g_Rainmeter;
/* /*
** The constructor. This is the base class for the net-meters. ** The constructor. This is the base class for the net-meters.
** **
@ -78,7 +76,7 @@ void MeasureNet::UpdateIFTable()
logging = true; logging = true;
} }
if (g_Rainmeter->GetDebug() && logging) if (GetRainmeter().GetDebug() && logging)
{ {
LogDebug(L"------------------------------"); LogDebug(L"------------------------------");
LogDebugF(L"* NETWORK-INTERFACE: Count=%i", c_NumOfTables); LogDebugF(L"* NETWORK-INTERFACE: Count=%i", c_NumOfTables);
@ -171,7 +169,7 @@ void MeasureNet::UpdateIFTable()
logging = true; logging = true;
} }
if (g_Rainmeter->GetDebug() && logging) if (GetRainmeter().GetDebug() && logging)
{ {
LogDebug(L"------------------------------"); LogDebug(L"------------------------------");
LogDebugF(L"* NETWORK-INTERFACE: Count=%i", c_NumOfTables); LogDebugF(L"* NETWORK-INTERFACE: Count=%i", c_NumOfTables);
@ -465,17 +463,17 @@ void MeasureNet::ReadOptions(ConfigParser& parser, const WCHAR* section)
if (m_Net == NET_IN) if (m_Net == NET_IN)
{ {
netName = L"NetInSpeed"; netName = L"NetInSpeed";
value = g_Rainmeter->GetGlobalOptions().netInSpeed; value = GetRainmeter().GetGlobalOptions().netInSpeed;
} }
else if (m_Net == NET_OUT) else if (m_Net == NET_OUT)
{ {
netName = L"NetOutSpeed"; netName = L"NetOutSpeed";
value = g_Rainmeter->GetGlobalOptions().netOutSpeed; value = GetRainmeter().GetGlobalOptions().netOutSpeed;
} }
else // if (m_Net == NET_TOTAL) else // if (m_Net == NET_TOTAL)
{ {
netName = L"NetTotalSpeed"; netName = L"NetTotalSpeed";
value = g_Rainmeter->GetGlobalOptions().netInSpeed + g_Rainmeter->GetGlobalOptions().netOutSpeed; value = GetRainmeter().GetGlobalOptions().netInSpeed + GetRainmeter().GetGlobalOptions().netOutSpeed;
} }
double maxValue = parser.ReadFloat(section, L"MaxValue", -1); double maxValue = parser.ReadFloat(section, L"MaxValue", -1);
@ -493,7 +491,7 @@ void MeasureNet::ReadOptions(ConfigParser& parser, const WCHAR* section)
m_Cumulative = 0!=parser.ReadInt(section, L"Cumulative", 0); m_Cumulative = 0!=parser.ReadInt(section, L"Cumulative", 0);
if (m_Cumulative) if (m_Cumulative)
{ {
g_Rainmeter->SetNetworkStatisticsTimer(); GetRainmeter().SetNetworkStatisticsTimer();
} }
if (maxValue == 0.0) if (maxValue == 0.0)
@ -707,7 +705,7 @@ void MeasureNet::InitializeStatic()
} }
} }
if (g_Rainmeter->GetDebug()) if (GetRainmeter().GetDebug())
{ {
UpdateIFTable(); UpdateIFTable();
} }

View File

@ -23,8 +23,6 @@
#include "System.h" #include "System.h"
#include "Error.h" #include "Error.h"
extern Rainmeter* g_Rainmeter;
/* /*
** The constructor ** The constructor
** **
@ -129,15 +127,15 @@ void MeasurePlugin::ReadOptions(ConfigParser& parser, const WCHAR* section)
} }
// First try from program path // First try from program path
std::wstring pluginFile = g_Rainmeter->GetPluginPath(); std::wstring pluginFile = GetRainmeter().GetPluginPath();
pluginFile += pluginName; pluginFile += pluginName;
m_Plugin = System::RmLoadLibrary(pluginFile.c_str()); m_Plugin = System::RmLoadLibrary(pluginFile.c_str());
if (!m_Plugin) if (!m_Plugin)
{ {
if (g_Rainmeter->HasUserPluginPath()) if (GetRainmeter().HasUserPluginPath())
{ {
// Try from settings path // Try from settings path
pluginFile = g_Rainmeter->GetUserPluginPath(); pluginFile = GetRainmeter().GetUserPluginPath();
pluginFile += pluginName; pluginFile += pluginName;
m_Plugin = System::RmLoadLibrary(pluginFile.c_str()); m_Plugin = System::RmLoadLibrary(pluginFile.c_str());
} }

View File

@ -34,8 +34,6 @@
using namespace Gdiplus; using namespace Gdiplus;
extern Rainmeter* g_Rainmeter;
/* /*
** The constructor ** The constructor
** **
@ -528,7 +526,7 @@ bool Meter::ReplaceMeasures(std::wstring& str, AUTOSCALE autoScale, double scale
void Meter::CreateToolTip(MeterWindow* meterWindow) void Meter::CreateToolTip(MeterWindow* meterWindow)
{ {
HWND hMeterWindow = m_MeterWindow->GetWindow(); HWND hMeterWindow = m_MeterWindow->GetWindow();
HINSTANCE hInstance = g_Rainmeter->GetInstance(); HINSTANCE hInstance = GetRainmeter().GetModuleInstance();
DWORD style = WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP; DWORD style = WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP;
if (m_ToolTipType) if (m_ToolTipType)

View File

@ -26,8 +26,6 @@
using namespace Gdiplus; using namespace Gdiplus;
extern Rainmeter* g_Rainmeter;
/* /*
** The constructor ** The constructor
** **

View File

@ -26,8 +26,6 @@
using namespace Gdiplus; using namespace Gdiplus;
extern Rainmeter* g_Rainmeter;
/* /*
** The constructor ** The constructor
** **

View File

@ -23,8 +23,6 @@
#include "Error.h" #include "Error.h"
#include "../Common/Gfx/Canvas.h" #include "../Common/Gfx/Canvas.h"
extern Rainmeter* g_Rainmeter;
using namespace Gdiplus; using namespace Gdiplus;
enum BUTTON_STATE enum BUTTON_STATE
@ -257,7 +255,7 @@ bool MeterButton::MouseUp(POINT pos, bool execute)
{ {
if (execute && m_Clicked && m_Focus && HitTest2(pos.x, pos.y, true)) if (execute && m_Clicked && m_Focus && HitTest2(pos.x, pos.y, true))
{ {
g_Rainmeter->ExecuteCommand(m_Command.c_str(), m_MeterWindow); GetRainmeter().ExecuteCommand(m_Command.c_str(), m_MeterWindow);
} }
m_State = BUTTON_STATE_NORMAL; m_State = BUTTON_STATE_NORMAL;
m_Clicked = false; m_Clicked = false;

View File

@ -25,8 +25,6 @@
using namespace Gdiplus; using namespace Gdiplus;
extern Rainmeter* g_Rainmeter;
TintedImageHelper_DefineOptionArray(MeterHistogram::c_PrimaryOptionArray, L"Primary"); TintedImageHelper_DefineOptionArray(MeterHistogram::c_PrimaryOptionArray, L"Primary");
TintedImageHelper_DefineOptionArray(MeterHistogram::c_SecondaryOptionArray, L"Secondary"); TintedImageHelper_DefineOptionArray(MeterHistogram::c_SecondaryOptionArray, L"Secondary");
TintedImageHelper_DefineOptionArray(MeterHistogram::c_BothOptionArray, L"Both"); TintedImageHelper_DefineOptionArray(MeterHistogram::c_BothOptionArray, L"Both");

View File

@ -25,8 +25,6 @@
#include "../Common/PathUtil.h" #include "../Common/PathUtil.h"
#include "../Common/Gfx/Canvas.h" #include "../Common/Gfx/Canvas.h"
extern Rainmeter* g_Rainmeter;
using namespace Gdiplus; using namespace Gdiplus;
/* /*

View File

@ -29,8 +29,6 @@ using namespace Gdiplus;
#define PI (3.14159265358979323846) #define PI (3.14159265358979323846)
#define CONVERT_TO_DEGREES(X) ((X) * (180.0 / PI)) #define CONVERT_TO_DEGREES(X) ((X) * (180.0 / PI))
extern Rainmeter* g_Rainmeter;
/* /*
** The constructor ** The constructor
** **

View File

@ -28,8 +28,6 @@ using namespace Gdiplus;
#define PI (3.14159265f) #define PI (3.14159265f)
#define CONVERT_TO_DEGREES(X) ((X) * (180.0f / PI)) #define CONVERT_TO_DEGREES(X) ((X) * (180.0f / PI))
extern Rainmeter* g_Rainmeter;
void StringToUpper(std::wstring& str) void StringToUpper(std::wstring& str)
{ {
WCHAR* srcAndDest = &str[0]; WCHAR* srcAndDest = &str[0];
@ -650,7 +648,7 @@ void MeterString::EnumerateInstalledFontFamilies()
void MeterString::InitializeStatic() void MeterString::InitializeStatic()
{ {
if (g_Rainmeter->GetDebug()) if (GetRainmeter().GetDebug())
{ {
LogDebug(L"------------------------------"); LogDebug(L"------------------------------");
LogDebug(L"* Font families:"); LogDebug(L"* Font families:");

View File

@ -70,8 +70,6 @@ FPDWMGETCOLORIZATIONCOLOR MeterWindow::c_DwmGetColorizationColor = nullptr;
FPDWMSETWINDOWATTRIBUTE MeterWindow::c_DwmSetWindowAttribute = nullptr; FPDWMSETWINDOWATTRIBUTE MeterWindow::c_DwmSetWindowAttribute = nullptr;
FPDWMISCOMPOSITIONENABLED MeterWindow::c_DwmIsCompositionEnabled = nullptr; FPDWMISCOMPOSITIONENABLED MeterWindow::c_DwmIsCompositionEnabled = nullptr;
extern Rainmeter* g_Rainmeter;
/* /*
** Constructor ** Constructor
** **
@ -144,7 +142,7 @@ MeterWindow::MeterWindow(const std::wstring& folderPath, const std::wstring& fil
m_FontCollection(), m_FontCollection(),
m_ToolTipHidden(false) m_ToolTipHidden(false)
{ {
m_Canvas = (Platform::IsAtLeastWinVista() && g_Rainmeter->CanUseD2D()) ? m_Canvas = (Platform::IsAtLeastWinVista() && GetRainmeter().CanUseD2D()) ?
(Gfx::Canvas*)new Gfx::CanvasD2D() : (Gfx::Canvas*)new Gfx::CanvasGDIP(); (Gfx::Canvas*)new Gfx::CanvasD2D() : (Gfx::Canvas*)new Gfx::CanvasGDIP();
if (!c_DwmInstance && Platform::IsAtLeastWinVista()) if (!c_DwmInstance && Platform::IsAtLeastWinVista())
@ -164,7 +162,7 @@ MeterWindow::MeterWindow(const std::wstring& folderPath, const std::wstring& fil
WNDCLASSEX wc = {sizeof(WNDCLASSEX)}; WNDCLASSEX wc = {sizeof(WNDCLASSEX)};
wc.style = CS_NOCLOSE | CS_DBLCLKS; wc.style = CS_NOCLOSE | CS_DBLCLKS;
wc.lpfnWndProc = InitialWndProc; wc.lpfnWndProc = InitialWndProc;
wc.hInstance = g_Rainmeter->GetInstance(); wc.hInstance = GetRainmeter().GetModuleInstance();
wc.hCursor = nullptr; // The cursor should be controlled by using SetCursor() when needed. wc.hCursor = nullptr; // The cursor should be controlled by using SetCursor() when needed.
wc.lpszClassName = METERWINDOW_CLASS_NAME; wc.lpszClassName = METERWINDOW_CLASS_NAME;
RegisterClassEx(&wc); RegisterClassEx(&wc);
@ -181,7 +179,7 @@ MeterWindow::~MeterWindow()
{ {
if (!m_OnCloseAction.empty()) if (!m_OnCloseAction.empty())
{ {
g_Rainmeter->ExecuteCommand(m_OnCloseAction.c_str(), this); GetRainmeter().ExecuteCommand(m_OnCloseAction.c_str(), this);
} }
Dispose(false); Dispose(false);
@ -190,7 +188,7 @@ MeterWindow::~MeterWindow()
if (c_InstanceCount == 0) if (c_InstanceCount == 0)
{ {
UnregisterClass(METERWINDOW_CLASS_NAME, g_Rainmeter->GetInstance()); UnregisterClass(METERWINDOW_CLASS_NAME, GetRainmeter().GetModuleInstance());
if (c_DwmInstance) if (c_DwmInstance)
{ {
@ -289,7 +287,7 @@ void MeterWindow::Initialize()
CW_USEDEFAULT, CW_USEDEFAULT,
nullptr, nullptr,
nullptr, nullptr,
g_Rainmeter->GetInstance(), GetRainmeter().GetModuleInstance(),
this); this);
setlocale(LC_NUMERIC, "C"); setlocale(LC_NUMERIC, "C");
@ -387,8 +385,8 @@ void MeterWindow::Deactivate()
{ {
m_State = STATE_CLOSING; m_State = STATE_CLOSING;
g_Rainmeter->RemoveMeterWindow(this); GetRainmeter().RemoveMeterWindow(this);
g_Rainmeter->AddUnmanagedMeterWindow(this); GetRainmeter().AddUnmanagedMeterWindow(this);
HideFade(); HideFade();
SetTimer(m_Window, TIMER_DEACTIVATE, m_FadeDuration + 50, nullptr); SetTimer(m_Window, TIMER_DEACTIVATE, m_FadeDuration + 50, nullptr);
@ -403,7 +401,7 @@ void MeterWindow::Refresh(bool init, bool all)
if (m_State == STATE_CLOSING) return; if (m_State == STATE_CLOSING) return;
m_State = STATE_REFRESHING; m_State = STATE_REFRESHING;
g_Rainmeter->SetCurrentParser(&m_Parser); GetRainmeter().SetCurrentParser(&m_Parser);
std::wstring notice = L"Refreshing skin \"" + m_FolderPath; std::wstring notice = L"Refreshing skin \"" + m_FolderPath;
notice += L'\\'; notice += L'\\';
@ -422,7 +420,7 @@ void MeterWindow::Refresh(bool init, bool all)
if (!ReadSkin()) if (!ReadSkin())
{ {
g_Rainmeter->DeactivateSkin(this, -1); GetRainmeter().DeactivateSkin(this, -1);
return; return;
} }
@ -470,13 +468,13 @@ void MeterWindow::Refresh(bool init, bool all)
SetTimer(m_Window, TIMER_MOUSE, INTERVAL_MOUSE, nullptr); SetTimer(m_Window, TIMER_MOUSE, INTERVAL_MOUSE, nullptr);
g_Rainmeter->SetCurrentParser(nullptr); GetRainmeter().SetCurrentParser(nullptr);
m_State = STATE_RUNNING; m_State = STATE_RUNNING;
if (!m_OnRefreshAction.empty()) if (!m_OnRefreshAction.empty())
{ {
g_Rainmeter->ExecuteCommand(m_OnRefreshAction.c_str(), this); GetRainmeter().ExecuteCommand(m_OnRefreshAction.c_str(), this);
} }
} }
@ -634,7 +632,7 @@ void MeterWindow::ChangeZPos(ZPOSITION zPos, bool all)
break; break;
case ZPOSITION_NORMAL: case ZPOSITION_NORMAL:
if (all || !g_Rainmeter->IsNormalStayDesktop()) break; if (all || !GetRainmeter().IsNormalStayDesktop()) break;
case ZPOSITION_ONDESKTOP: case ZPOSITION_ONDESKTOP:
if (System::GetShowDesktop()) if (System::GetShowDesktop())
{ {
@ -685,7 +683,7 @@ void MeterWindow::ChangeZPos(ZPOSITION zPos, bool all)
*/ */
void MeterWindow::ChangeSingleZPos(ZPOSITION zPos, bool all) void MeterWindow::ChangeSingleZPos(ZPOSITION zPos, bool all)
{ {
if (zPos == ZPOSITION_NORMAL && g_Rainmeter->IsNormalStayDesktop() && (!all || System::GetShowDesktop())) if (zPos == ZPOSITION_NORMAL && GetRainmeter().IsNormalStayDesktop() && (!all || System::GetShowDesktop()))
{ {
m_WindowZPosition = zPos; m_WindowZPosition = zPos;
@ -1794,7 +1792,7 @@ void MeterWindow::ReadOptions()
const WCHAR* section = m_FolderPath.c_str(); const WCHAR* section = m_FolderPath.c_str();
ConfigParser parser; ConfigParser parser;
parser.Initialize(g_Rainmeter->GetIniFile(), nullptr, section); parser.Initialize(GetRainmeter().GetIniFile(), nullptr, section);
INT writeFlags = 0; INT writeFlags = 0;
auto addWriteFlag = [&](INT flag) auto addWriteFlag = [&](INT flag)
@ -1878,7 +1876,7 @@ void MeterWindow::ReadOptions()
*/ */
void MeterWindow::WriteOptions(INT setting) void MeterWindow::WriteOptions(INT setting)
{ {
const WCHAR* iniFile = g_Rainmeter->GetIniFile().c_str(); const WCHAR* iniFile = GetRainmeter().GetIniFile().c_str();
if (*iniFile) if (*iniFile)
{ {
@ -1974,7 +1972,7 @@ bool MeterWindow::ReadSkin()
if (_waccess(iniFile.c_str(), 0) == -1) if (_waccess(iniFile.c_str(), 0) == -1)
{ {
std::wstring message = GetFormattedString(ID_STR_UNABLETOREFRESHSKIN, m_FolderPath.c_str(), m_FileName.c_str()); std::wstring message = GetFormattedString(ID_STR_UNABLETOREFRESHSKIN, m_FolderPath.c_str(), m_FileName.c_str());
g_Rainmeter->ShowMessage(m_Window, message.c_str(), MB_OK | MB_ICONEXCLAMATION); GetRainmeter().ShowMessage(m_Window, message.c_str(), MB_OK | MB_ICONEXCLAMATION);
return false; return false;
} }
@ -2000,7 +1998,7 @@ bool MeterWindow::ReadSkin()
} }
std::wstring text = GetFormattedString(ID_STR_NEWVERSIONREQUIRED, m_FolderPath.c_str(), m_FileName.c_str(), buffer); std::wstring text = GetFormattedString(ID_STR_NEWVERSIONREQUIRED, m_FolderPath.c_str(), m_FileName.c_str(), buffer);
g_Rainmeter->ShowMessage(m_Window, text.c_str(), MB_OK | MB_ICONEXCLAMATION); GetRainmeter().ShowMessage(m_Window, text.c_str(), MB_OK | MB_ICONEXCLAMATION);
return false; return false;
} }
@ -2131,7 +2129,7 @@ bool MeterWindow::ReadSkin()
do do
{ {
// Try program folder first // Try program folder first
std::wstring szFontFile = g_Rainmeter->GetPath() + L"Fonts\\"; std::wstring szFontFile = GetRainmeter().GetPath() + L"Fonts\\";
szFontFile += localFont; szFontFile += localFont;
if (!m_FontCollection->AddFile(szFontFile.c_str())) if (!m_FontCollection->AddFile(szFontFile.c_str()))
{ {
@ -2209,7 +2207,7 @@ bool MeterWindow::ReadSkin()
if (m_Meters.empty()) if (m_Meters.empty())
{ {
std::wstring text = GetFormattedString(ID_STR_NOMETERSINSKIN, m_FolderPath.c_str(), m_FileName.c_str()); std::wstring text = GetFormattedString(ID_STR_NOMETERSINSKIN, m_FolderPath.c_str(), m_FileName.c_str());
g_Rainmeter->ShowMessage(m_Window, text.c_str(), MB_OK | MB_ICONEXCLAMATION); GetRainmeter().ShowMessage(m_Window, text.c_str(), MB_OK | MB_ICONEXCLAMATION);
return false; return false;
} }
@ -2697,7 +2695,7 @@ void MeterWindow::Update(bool refresh)
// If our option is to disable when in an RDP session, then check if in an RDP session. // If our option is to disable when in an RDP session, then check if in an RDP session.
// Only redraw if we are not in a remote session // Only redraw if we are not in a remote session
if (g_Rainmeter->IsRedrawable()) if (GetRainmeter().IsRedrawable())
{ {
Redraw(); Redraw();
} }
@ -2708,7 +2706,7 @@ void MeterWindow::Update(bool refresh)
if (!m_OnUpdateAction.empty()) if (!m_OnUpdateAction.empty())
{ {
g_Rainmeter->ExecuteCommand(m_OnUpdateAction.c_str(), this); GetRainmeter().ExecuteCommand(m_OnUpdateAction.c_str(), this);
} }
} }
@ -2769,7 +2767,7 @@ LRESULT MeterWindow::OnTimer(UINT uMsg, WPARAM wParam, LPARAM lParam)
break; break;
case TIMER_MOUSE: case TIMER_MOUSE:
if (!g_Rainmeter->IsMenuActive() && !m_Dragging) if (!GetRainmeter().IsMenuActive() && !m_Dragging)
{ {
ShowWindowIfAppropriate(); ShowWindowIfAppropriate();
@ -2874,7 +2872,7 @@ LRESULT MeterWindow::OnTimer(UINT uMsg, WPARAM wParam, LPARAM lParam)
if (m_FadeStartTime == 0) if (m_FadeStartTime == 0)
{ {
KillTimer(m_Window, TIMER_DEACTIVATE); KillTimer(m_Window, TIMER_DEACTIVATE);
g_Rainmeter->RemoveUnmanagedMeterWindow(this); GetRainmeter().RemoveUnmanagedMeterWindow(this);
delete this; delete this;
} }
break; break;
@ -3287,7 +3285,7 @@ LRESULT MeterWindow::OnCommand(UINT uMsg, WPARAM wParam, LPARAM lParam)
switch (wParam) switch (wParam)
{ {
case IDM_SKIN_EDITSKIN: case IDM_SKIN_EDITSKIN:
g_Rainmeter->EditSkinFile(m_FolderPath, m_FileName); GetRainmeter().EditSkinFile(m_FolderPath, m_FileName);
break; break;
case IDM_SKIN_REFRESH: case IDM_SKIN_REFRESH:
@ -3295,7 +3293,7 @@ LRESULT MeterWindow::OnCommand(UINT uMsg, WPARAM wParam, LPARAM lParam)
break; break;
case IDM_SKIN_OPENSKINSFOLDER: case IDM_SKIN_OPENSKINSFOLDER:
g_Rainmeter->OpenSkinFolder(m_FolderPath); GetRainmeter().OpenSkinFolder(m_FolderPath);
break; break;
case IDM_SKIN_MANAGESKIN: case IDM_SKIN_MANAGESKIN:
@ -3357,7 +3355,7 @@ LRESULT MeterWindow::OnCommand(UINT uMsg, WPARAM wParam, LPARAM lParam)
case IDM_CLOSESKIN: case IDM_CLOSESKIN:
if (m_State != STATE_CLOSING) if (m_State != STATE_CLOSING)
{ {
g_Rainmeter->DeactivateSkin(this, -1); GetRainmeter().DeactivateSkin(this, -1);
} }
break; break;
@ -3447,13 +3445,13 @@ LRESULT MeterWindow::OnCommand(UINT uMsg, WPARAM wParam, LPARAM lParam)
if (!action.empty()) if (!action.empty())
{ {
g_Rainmeter->ExecuteCommand(action.c_str(), this); GetRainmeter().ExecuteCommand(action.c_str(), this);
} }
} }
else else
{ {
// Forward to tray window, which handles all the other commands // Forward to tray window, which handles all the other commands
HWND tray = g_Rainmeter->GetTrayWindow()->GetWindow(); HWND tray = GetRainmeter().GetTrayWindow()->GetWindow();
if (wParam == IDM_QUIT) if (wParam == IDM_QUIT)
{ {
@ -3660,7 +3658,7 @@ LRESULT MeterWindow::OnExitSizeMove(UINT uMsg, WPARAM wParam, LPARAM lParam)
*/ */
LRESULT MeterWindow::OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam) LRESULT MeterWindow::OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam)
{ {
if (m_WindowDraggable && !g_Rainmeter->GetDisableDragging()) if (m_WindowDraggable && !GetRainmeter().GetDisableDragging())
{ {
POINT pos; POINT pos;
pos.x = GET_X_LPARAM(lParam); pos.x = GET_X_LPARAM(lParam);
@ -3700,7 +3698,7 @@ LRESULT MeterWindow::OnWindowPosChanging(UINT uMsg, WPARAM wParam, LPARAM lParam
if (m_State != STATE_REFRESHING) if (m_State != STATE_REFRESHING)
{ {
if (m_WindowZPosition == ZPOSITION_NORMAL && g_Rainmeter->IsNormalStayDesktop() && System::GetShowDesktop()) if (m_WindowZPosition == ZPOSITION_NORMAL && GetRainmeter().IsNormalStayDesktop() && System::GetShowDesktop())
{ {
if (!(wp->flags & (SWP_NOOWNERZORDER | SWP_NOACTIVATE))) if (!(wp->flags & (SWP_NOOWNERZORDER | SWP_NOACTIVATE)))
{ {
@ -3745,7 +3743,7 @@ LRESULT MeterWindow::OnWindowPosChanging(UINT uMsg, WPARAM wParam, LPARAM lParam
} }
// Snap to other windows // Snap to other windows
for (auto iter = g_Rainmeter->GetAllMeterWindows().cbegin(); iter != g_Rainmeter->GetAllMeterWindows().cend(); ++iter) for (auto iter = GetRainmeter().GetAllMeterWindows().cbegin(); iter != GetRainmeter().GetAllMeterWindows().cend(); ++iter)
{ {
if ((*iter).second != this) if ((*iter).second != this)
{ {
@ -4228,14 +4226,14 @@ LRESULT MeterWindow::OnSetWindowFocus(UINT uMsg, WPARAM wParam, LPARAM lParam)
case WM_SETFOCUS: case WM_SETFOCUS:
if (!m_OnFocusAction.empty()) if (!m_OnFocusAction.empty())
{ {
g_Rainmeter->ExecuteCommand(m_OnFocusAction.c_str(), this); GetRainmeter().ExecuteCommand(m_OnFocusAction.c_str(), this);
} }
break; break;
case WM_KILLFOCUS: case WM_KILLFOCUS:
if (!m_OnUnfocusAction.empty()) if (!m_OnUnfocusAction.empty())
{ {
g_Rainmeter->ExecuteCommand(m_OnUnfocusAction.c_str(), this); GetRainmeter().ExecuteCommand(m_OnUnfocusAction.c_str(), this);
} }
break; break;
} }
@ -4278,7 +4276,7 @@ LRESULT MeterWindow::OnContextMenu(UINT uMsg, WPARAM wParam, LPARAM lParam)
} }
} }
g_Rainmeter->ShowContextMenu(pos, this); GetRainmeter().ShowContextMenu(pos, this);
return 0; return 0;
} }
@ -4319,7 +4317,7 @@ bool MeterWindow::DoAction(int x, int y, MOUSEACTION action, bool test)
{ {
if (!test) if (!test)
{ {
g_Rainmeter->ExecuteCommand(command.c_str(), this); GetRainmeter().ExecuteCommand(command.c_str(), this);
} }
return true; return true;
@ -4355,7 +4353,7 @@ bool MeterWindow::DoMoveAction(int x, int y, MOUSEACTION action)
if (!m_Mouse.GetOverAction().empty()) if (!m_Mouse.GetOverAction().empty())
{ {
UINT currCounter = m_MouseMoveCounter; UINT currCounter = m_MouseMoveCounter;
g_Rainmeter->ExecuteCommand(m_Mouse.GetOverAction().c_str(), this); GetRainmeter().ExecuteCommand(m_Mouse.GetOverAction().c_str(), this);
return (currCounter == m_MouseMoveCounter); return (currCounter == m_MouseMoveCounter);
} }
} }
@ -4392,7 +4390,7 @@ bool MeterWindow::DoMoveAction(int x, int y, MOUSEACTION action)
if (!mouse.GetOverAction().empty()) if (!mouse.GetOverAction().empty())
{ {
UINT currCounter = m_MouseMoveCounter; UINT currCounter = m_MouseMoveCounter;
g_Rainmeter->ExecuteCommand(mouse.GetOverAction().c_str(), this); GetRainmeter().ExecuteCommand(mouse.GetOverAction().c_str(), this);
return (currCounter == m_MouseMoveCounter); return (currCounter == m_MouseMoveCounter);
} }
} }
@ -4418,7 +4416,7 @@ bool MeterWindow::DoMoveAction(int x, int y, MOUSEACTION action)
const Mouse& mouse = (*j)->GetMouse(); const Mouse& mouse = (*j)->GetMouse();
if (!mouse.GetLeaveAction().empty()) if (!mouse.GetLeaveAction().empty())
{ {
g_Rainmeter->ExecuteCommand(mouse.GetLeaveAction().c_str(), this); GetRainmeter().ExecuteCommand(mouse.GetLeaveAction().c_str(), this);
return true; return true;
} }
} }
@ -4441,7 +4439,7 @@ bool MeterWindow::DoMoveAction(int x, int y, MOUSEACTION action)
if (!m_Mouse.GetOverAction().empty()) if (!m_Mouse.GetOverAction().empty())
{ {
UINT currCounter = m_MouseMoveCounter; UINT currCounter = m_MouseMoveCounter;
g_Rainmeter->ExecuteCommand(m_Mouse.GetOverAction().c_str(), this); GetRainmeter().ExecuteCommand(m_Mouse.GetOverAction().c_str(), this);
return (currCounter == m_MouseMoveCounter); return (currCounter == m_MouseMoveCounter);
} }
} }
@ -4461,7 +4459,7 @@ bool MeterWindow::DoMoveAction(int x, int y, MOUSEACTION action)
if (!m_Mouse.GetLeaveAction().empty()) if (!m_Mouse.GetLeaveAction().empty())
{ {
g_Rainmeter->ExecuteCommand(m_Mouse.GetLeaveAction().c_str(), this); GetRainmeter().ExecuteCommand(m_Mouse.GetLeaveAction().c_str(), this);
return true; return true;
} }
} }
@ -4536,7 +4534,7 @@ LRESULT MeterWindow::OnWake(UINT uMsg, WPARAM wParam, LPARAM lParam)
{ {
if (wParam == PBT_APMRESUMEAUTOMATIC && !m_OnWakeAction.empty()) if (wParam == PBT_APMRESUMEAUTOMATIC && !m_OnWakeAction.empty())
{ {
g_Rainmeter->ExecuteCommand(m_OnWakeAction.c_str(), this); GetRainmeter().ExecuteCommand(m_OnWakeAction.c_str(), this);
} }
return 0; return 0;
@ -4661,10 +4659,10 @@ LRESULT MeterWindow::OnCopyData(UINT uMsg, WPARAM wParam, LPARAM lParam)
if (pCopyDataStruct && (pCopyDataStruct->dwData == 1) && (pCopyDataStruct->cbData > 0)) if (pCopyDataStruct && (pCopyDataStruct->dwData == 1) && (pCopyDataStruct->cbData > 0))
{ {
if (g_Rainmeter->HasMeterWindow(this)) if (GetRainmeter().HasMeterWindow(this))
{ {
const WCHAR* command = (const WCHAR*)pCopyDataStruct->lpData; const WCHAR* command = (const WCHAR*)pCopyDataStruct->lpData;
g_Rainmeter->ExecuteCommand(command, this); GetRainmeter().ExecuteCommand(command, this);
} }
else else
{ {
@ -4719,8 +4717,8 @@ void MeterWindow::MakePathAbsolute(std::wstring& path)
else else
{ {
std::wstring absolute; std::wstring absolute;
absolute.reserve(g_Rainmeter->GetSkinPath().size() + m_FolderPath.size() + 1 + path.size()); absolute.reserve(GetRainmeter().GetSkinPath().size() + m_FolderPath.size() + 1 + path.size());
absolute = g_Rainmeter->GetSkinPath(); absolute = GetRainmeter().GetSkinPath();
absolute += m_FolderPath; absolute += m_FolderPath;
absolute += L'\\'; absolute += L'\\';
absolute += path; absolute += path;
@ -4730,7 +4728,7 @@ void MeterWindow::MakePathAbsolute(std::wstring& path)
std::wstring MeterWindow::GetFilePath() std::wstring MeterWindow::GetFilePath()
{ {
std::wstring file = g_Rainmeter->GetSkinPath() + m_FolderPath; std::wstring file = GetRainmeter().GetSkinPath() + m_FolderPath;
file += L'\\'; file += L'\\';
file += m_FileName; file += m_FileName;
return file; return file;
@ -4738,7 +4736,7 @@ std::wstring MeterWindow::GetFilePath()
std::wstring MeterWindow::GetRootPath() std::wstring MeterWindow::GetRootPath()
{ {
std::wstring path = g_Rainmeter->GetSkinPath(); std::wstring path = GetRainmeter().GetSkinPath();
std::wstring::size_type loc; std::wstring::size_type loc;
if ((loc = m_FolderPath.find_first_of(L'\\')) != std::wstring::npos) if ((loc = m_FolderPath.find_first_of(L'\\')) != std::wstring::npos)

View File

@ -45,8 +45,6 @@ enum INTERVAL
INTERVAL_NETSTATS = 120000 INTERVAL_NETSTATS = 120000
}; };
Rainmeter* g_Rainmeter; // The module
/* /*
** Initializes Rainmeter. ** Initializes Rainmeter.
** **
@ -95,16 +93,13 @@ int RainmeterMain(LPWSTR cmdLine)
const WCHAR* iniFile = (*cmdLine && !layout) ? cmdLine : nullptr; const WCHAR* iniFile = (*cmdLine && !layout) ? cmdLine : nullptr;
g_Rainmeter = new Rainmeter; auto& rainmeter = GetRainmeter();
int ret = g_Rainmeter->Initialize(iniFile, layout); int ret = rainmeter.Initialize(iniFile, layout);
if (ret == 0) if (ret == 0)
{ {
ret = g_Rainmeter->MessagePump(); ret = rainmeter.MessagePump();
} }
delete g_Rainmeter;
g_Rainmeter = nullptr;
return ret; return ret;
} }
@ -179,6 +174,12 @@ Rainmeter::~Rainmeter()
GdiplusShutdown(m_GDIplusToken); GdiplusShutdown(m_GDIplusToken);
} }
Rainmeter& Rainmeter::GetInstance()
{
static Rainmeter s_Rainmeter;
return s_Rainmeter;
}
/* /*
** The main initialization function for the module. ** The main initialization function for the module.
** **
@ -538,7 +539,7 @@ LRESULT CALLBACK Rainmeter::MainWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPA
const WCHAR* data = (const WCHAR*)cds->lpData; const WCHAR* data = (const WCHAR*)cds->lpData;
if (cds->dwData == 1 && (cds->cbData > 0)) if (cds->dwData == 1 && (cds->cbData > 0))
{ {
g_Rainmeter->DelayedExecuteCommand(data); GetRainmeter().DelayedExecuteCommand(data);
} }
} }
} }
@ -549,12 +550,12 @@ LRESULT CALLBACK Rainmeter::MainWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPA
{ {
MeasureNet::UpdateIFTable(); MeasureNet::UpdateIFTable();
MeasureNet::UpdateStats(); MeasureNet::UpdateStats();
g_Rainmeter->WriteStats(false); GetRainmeter().WriteStats(false);
} }
break; break;
case WM_RAINMETER_DELAYED_REFRESH_ALL: case WM_RAINMETER_DELAYED_REFRESH_ALL:
g_Rainmeter->RefreshAll(); GetRainmeter().RefreshAll();
break; break;
case WM_RAINMETER_DELAYED_EXECUTE: case WM_RAINMETER_DELAYED_EXECUTE:
@ -562,15 +563,15 @@ LRESULT CALLBACK Rainmeter::MainWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPA
{ {
// Execute bang // Execute bang
WCHAR* bang = (WCHAR*)lParam; WCHAR* bang = (WCHAR*)lParam;
g_Rainmeter->ExecuteCommand(bang, nullptr); GetRainmeter().ExecuteCommand(bang, nullptr);
free(bang); // _wcsdup() free(bang); // _wcsdup()
} }
break; break;
case WM_RAINMETER_EXECUTE: case WM_RAINMETER_EXECUTE:
if (g_Rainmeter->HasMeterWindow((MeterWindow*)wParam)) if (GetRainmeter().HasMeterWindow((MeterWindow*)wParam))
{ {
g_Rainmeter->ExecuteCommand((const WCHAR*)lParam, (MeterWindow*)wParam); GetRainmeter().ExecuteCommand((const WCHAR*)lParam, (MeterWindow*)wParam);
} }
break; break;
@ -883,7 +884,7 @@ void Rainmeter::ToggleSkin(int folderIndex, int fileIndex)
{ {
if (m_SkinFolders[folderIndex].active == fileIndex + 1) if (m_SkinFolders[folderIndex].active == fileIndex + 1)
{ {
MeterWindow* meterWindow = g_Rainmeter->GetMeterWindow(GetFolderPath(folderIndex)); MeterWindow* meterWindow = GetRainmeter().GetMeterWindow(GetFolderPath(folderIndex));
DeactivateSkin(meterWindow, folderIndex); DeactivateSkin(meterWindow, folderIndex);
} }
else else
@ -2035,10 +2036,10 @@ int Rainmeter::CreateAllSkinsMenuRecursive(HMENU skinMenu, int index)
int initialLevel = m_SkinFolders[index].level; int initialLevel = m_SkinFolders[index].level;
int menuIndex = 0; int menuIndex = 0;
const size_t max = g_Rainmeter->m_SkinFolders.size(); const size_t max = GetRainmeter().m_SkinFolders.size();
while (index < max) while (index < max)
{ {
const SkinFolder& skinFolder = g_Rainmeter->m_SkinFolders[index]; const SkinFolder& skinFolder = GetRainmeter().m_SkinFolders[index];
if (skinFolder.level != initialLevel) if (skinFolder.level != initialLevel)
{ {
return index - 1; return index - 1;

View File

@ -90,8 +90,7 @@ public:
} }
}; };
Rainmeter(); static Rainmeter& GetInstance();
~Rainmeter();
int Initialize(LPCWSTR iniPath, LPCWSTR layout); int Initialize(LPCWSTR iniPath, LPCWSTR layout);
bool IsAlreadyRunning(); bool IsAlreadyRunning();
@ -156,7 +155,7 @@ public:
HWND GetWindow() { return m_Window; } HWND GetWindow() { return m_Window; }
HINSTANCE GetInstance() { return m_Instance; } HINSTANCE GetModuleInstance() { return m_Instance; }
HINSTANCE GetResourceInstance() { return m_ResourceInstance; } HINSTANCE GetResourceInstance() { return m_ResourceInstance; }
LCID GetResourceLCID() { return m_ResourceLCID; } LCID GetResourceLCID() { return m_ResourceLCID; }
@ -216,6 +215,9 @@ public:
friend class DialogManage; friend class DialogManage;
private: private:
Rainmeter();
~Rainmeter();
static LRESULT CALLBACK MainWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); static LRESULT CALLBACK MainWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
void ActivateActiveSkins(); void ActivateActiveSkins();
@ -305,6 +307,9 @@ private:
GlobalOptions m_GlobalOptions; GlobalOptions m_GlobalOptions;
}; };
// Convenience function.
inline Rainmeter& GetRainmeter() { return Rainmeter::GetInstance(); }
#ifdef LIBRARY_EXPORTS #ifdef LIBRARY_EXPORTS
#define EXPORT_PLUGIN EXTERN_C #define EXPORT_PLUGIN EXTERN_C
#else #else

View File

@ -21,8 +21,6 @@
#include "ConfigParser.h" #include "ConfigParser.h"
#include "Rainmeter.h" #include "Rainmeter.h"
extern Rainmeter* g_Rainmeter;
/* /*
** The constructor ** The constructor
** **
@ -84,6 +82,6 @@ void Section::DoUpdateAction()
{ {
if (!m_OnUpdateAction.empty()) if (!m_OnUpdateAction.empty())
{ {
g_Rainmeter->ExecuteCommand(m_OnUpdateAction.c_str(), m_MeterWindow); GetRainmeter().ExecuteCommand(m_OnUpdateAction.c_str(), m_MeterWindow);
} }
} }

View File

@ -56,8 +56,6 @@ std::wstring System::c_WorkingDirectory;
std::vector<std::wstring> System::c_IniFileMappings; std::vector<std::wstring> System::c_IniFileMappings;
extern Rainmeter* g_Rainmeter;
/* /*
** Creates a helper window to detect changes in the system. ** Creates a helper window to detect changes in the system.
** **
@ -160,7 +158,7 @@ BOOL CALLBACK MyInfoEnumProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonit
info.cbSize = sizeof(MONITORINFOEX); info.cbSize = sizeof(MONITORINFOEX);
GetMonitorInfo(hMonitor, &info); GetMonitorInfo(hMonitor, &info);
if (g_Rainmeter->GetDebug()) if (GetRainmeter().GetDebug())
{ {
LogDebug(info.szDevice); LogDebug(info.szDevice);
LogDebugF(L" Flags : %s(0x%08X)", (info.dwFlags & MONITORINFOF_PRIMARY) ? L"PRIMARY " : L"", info.dwFlags); LogDebugF(L" Flags : %s(0x%08X)", (info.dwFlags & MONITORINFOF_PRIMARY) ? L"PRIMARY " : L"", info.dwFlags);
@ -242,7 +240,7 @@ size_t System::GetMonitorCount()
void System::SetMultiMonitorInfo() void System::SetMultiMonitorInfo()
{ {
std::vector<MonitorInfo>& monitors = c_Monitors.monitors; std::vector<MonitorInfo>& monitors = c_Monitors.monitors;
bool logging = g_Rainmeter->GetDebug(); bool logging = GetRainmeter().GetDebug();
c_Monitors.vsT = GetSystemMetrics(SM_YVIRTUALSCREEN); c_Monitors.vsT = GetSystemMetrics(SM_YVIRTUALSCREEN);
c_Monitors.vsL = GetSystemMetrics(SM_XVIRTUALSCREEN); c_Monitors.vsL = GetSystemMetrics(SM_XVIRTUALSCREEN);
@ -530,7 +528,7 @@ void System::UpdateWorkareaInfo()
(*iter).work = info.rcWork; (*iter).work = info.rcWork;
if (g_Rainmeter->GetDebug()) if (GetRainmeter().GetDebug())
{ {
LogDebugF(L"WorkArea@%i : L=%i, T=%i, R=%i, B=%i (W=%i, H=%i)", LogDebugF(L"WorkArea@%i : L=%i, T=%i, R=%i, B=%i (W=%i, H=%i)",
i, i,
@ -635,7 +633,7 @@ HWND System::GetBackmostTopWindow()
// Skip all ZPOSITION_ONDESKTOP, ZPOSITION_BOTTOM, and ZPOSITION_NORMAL windows // Skip all ZPOSITION_ONDESKTOP, ZPOSITION_BOTTOM, and ZPOSITION_NORMAL windows
while (winPos = ::GetNextWindow(winPos, GW_HWNDPREV)) while (winPos = ::GetNextWindow(winPos, GW_HWNDPREV))
{ {
MeterWindow* wnd = g_Rainmeter->GetMeterWindow(winPos); MeterWindow* wnd = GetRainmeter().GetMeterWindow(winPos);
if (!wnd || if (!wnd ||
(wnd->GetWindowZPosition() != ZPOSITION_NORMAL && (wnd->GetWindowZPosition() != ZPOSITION_NORMAL &&
wnd->GetWindowZPosition() != ZPOSITION_ONDESKTOP && wnd->GetWindowZPosition() != ZPOSITION_ONDESKTOP &&
@ -668,7 +666,7 @@ bool System::BelongToSameProcess(HWND hwndA, HWND hwndB)
*/ */
BOOL CALLBACK MyEnumWindowsProc(HWND hwnd, LPARAM lParam) BOOL CALLBACK MyEnumWindowsProc(HWND hwnd, LPARAM lParam)
{ {
bool logging = g_Rainmeter->GetDebug() && DEBUG_VERBOSE; bool logging = GetRainmeter().GetDebug() && DEBUG_VERBOSE;
const int classLen = _countof(METERWINDOW_CLASS_NAME) + (DEBUG_VERBOSE ? 32 : 1); const int classLen = _countof(METERWINDOW_CLASS_NAME) + (DEBUG_VERBOSE ? 32 : 1);
WCHAR className[classLen]; WCHAR className[classLen];
MeterWindow* Window; MeterWindow* Window;
@ -676,11 +674,11 @@ BOOL CALLBACK MyEnumWindowsProc(HWND hwnd, LPARAM lParam)
if (GetClassName(hwnd, className, classLen) > 0 && if (GetClassName(hwnd, className, classLen) > 0 &&
wcscmp(className, METERWINDOW_CLASS_NAME) == 0 && wcscmp(className, METERWINDOW_CLASS_NAME) == 0 &&
(Window = g_Rainmeter->GetMeterWindow(hwnd))) (Window = GetRainmeter().GetMeterWindow(hwnd)))
{ {
ZPOSITION zPos = Window->GetWindowZPosition(); ZPOSITION zPos = Window->GetWindowZPosition();
if (zPos == ZPOSITION_ONDESKTOP || if (zPos == ZPOSITION_ONDESKTOP ||
(zPos == ZPOSITION_NORMAL && g_Rainmeter->IsNormalStayDesktop()) || (zPos == ZPOSITION_NORMAL && GetRainmeter().IsNormalStayDesktop()) ||
zPos == ZPOSITION_ONBOTTOM) zPos == ZPOSITION_ONBOTTOM)
{ {
if (lParam) if (lParam)
@ -719,7 +717,7 @@ BOOL CALLBACK MyEnumWindowsProc(HWND hwnd, LPARAM lParam)
*/ */
void System::ChangeZPosInOrder() void System::ChangeZPosInOrder()
{ {
bool logging = g_Rainmeter->GetDebug() && DEBUG_VERBOSE; bool logging = GetRainmeter().GetDebug() && DEBUG_VERBOSE;
std::vector<MeterWindow*> windowsInZOrder; std::vector<MeterWindow*> windowsInZOrder;
if (logging) LogDebug(L"1: ----- BEFORE -----"); if (logging) LogDebug(L"1: ----- BEFORE -----");
@ -740,7 +738,7 @@ void System::ChangeZPosInOrder()
} }
}; };
if (g_Rainmeter->IsNormalStayDesktop()) if (GetRainmeter().IsNormalStayDesktop())
{ {
resetZPos(ZPOSITION_NORMAL); resetZPos(ZPOSITION_NORMAL);
} }
@ -767,7 +765,7 @@ void System::ChangeZPosInOrder()
*/ */
void System::PrepareHelperWindow(HWND WorkerW) void System::PrepareHelperWindow(HWND WorkerW)
{ {
bool logging = g_Rainmeter->GetDebug() && DEBUG_VERBOSE; bool logging = GetRainmeter().GetDebug() && DEBUG_VERBOSE;
SetWindowPos(c_Window, HWND_BOTTOM, 0, 0, 0, 0, ZPOS_FLAGS); // always on bottom SetWindowPos(c_Window, HWND_BOTTOM, 0, 0, 0, 0, ZPOS_FLAGS); // always on bottom
@ -850,7 +848,7 @@ bool System::CheckDesktopState(HWND WorkerW)
{ {
c_ShowDesktop = !c_ShowDesktop; c_ShowDesktop = !c_ShowDesktop;
if (g_Rainmeter->GetDebug()) if (GetRainmeter().GetDebug())
{ {
LogDebugF(L"System: \"Show %s\" has been detected.", LogDebugF(L"System: \"Show %s\" has been detected.",
c_ShowDesktop ? L"desktop" : L"open windows"); c_ShowDesktop ? L"desktop" : L"open windows");
@ -945,10 +943,10 @@ LRESULT CALLBACK System::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPa
case TIMER_RESUME: case TIMER_RESUME:
KillTimer(hWnd, TIMER_RESUME); KillTimer(hWnd, TIMER_RESUME);
if (g_Rainmeter->IsRedrawable()) if (GetRainmeter().IsRedrawable())
{ {
std::map<std::wstring, MeterWindow*>::const_iterator iter = g_Rainmeter->GetAllMeterWindows().begin(); std::map<std::wstring, MeterWindow*>::const_iterator iter = GetRainmeter().GetAllMeterWindows().begin();
for ( ; iter != g_Rainmeter->GetAllMeterWindows().end(); ++iter) for ( ; iter != GetRainmeter().GetAllMeterWindows().end(); ++iter)
{ {
(*iter).second->RedrawWindow(); (*iter).second->RedrawWindow();
} }
@ -972,8 +970,8 @@ LRESULT CALLBACK System::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPa
} }
// Deliver WM_DISPLAYCHANGE / WM_SETTINGCHANGE message to all meter windows // Deliver WM_DISPLAYCHANGE / WM_SETTINGCHANGE message to all meter windows
std::map<std::wstring, MeterWindow*>::const_iterator iter = g_Rainmeter->GetAllMeterWindows().begin(); std::map<std::wstring, MeterWindow*>::const_iterator iter = GetRainmeter().GetAllMeterWindows().begin();
for ( ; iter != g_Rainmeter->GetAllMeterWindows().end(); ++iter) for ( ; iter != GetRainmeter().GetAllMeterWindows().end(); ++iter)
{ {
PostMessage((*iter).second->GetWindow(), WM_METERWINDOW_DELAYED_MOVE, (WPARAM)uMsg, (LPARAM)0); PostMessage((*iter).second->GetWindow(), WM_METERWINDOW_DELAYED_MOVE, (WPARAM)uMsg, (LPARAM)0);
} }
@ -1152,7 +1150,7 @@ void System::SetWallpaper(const std::wstring& wallpaper, const std::wstring& sty
Bitmap* bitmap = Bitmap::FromFile(wallpaper.c_str()); Bitmap* bitmap = Bitmap::FromFile(wallpaper.c_str());
if (bitmap && bitmap->GetLastStatus() == Ok) if (bitmap && bitmap->GetLastStatus() == Ok)
{ {
std::wstring file = g_Rainmeter->GetSettingsPath() + L"Wallpaper.bmp"; std::wstring file = GetRainmeter().GetSettingsPath() + L"Wallpaper.bmp";
const CLSID bmpClsid = { 0x557cf400, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } }; const CLSID bmpClsid = { 0x557cf400, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } };
if (bitmap->Save(file.c_str(), &bmpClsid) == Ok) if (bitmap->Save(file.c_str(), &bmpClsid) == Ok)

View File

@ -48,8 +48,6 @@ enum INTERVAL
const UINT WM_TASKBARCREATED = ::RegisterWindowMessage(L"TaskbarCreated"); const UINT WM_TASKBARCREATED = ::RegisterWindowMessage(L"TaskbarCreated");
extern Rainmeter* g_Rainmeter;
using namespace Gdiplus; using namespace Gdiplus;
TrayWindow::TrayWindow() : TrayWindow::TrayWindow() :
@ -89,7 +87,7 @@ void TrayWindow::Initialize()
{ {
WNDCLASS wc = {0}; WNDCLASS wc = {0};
wc.lpfnWndProc = (WNDPROC)WndProc; wc.lpfnWndProc = (WNDPROC)WndProc;
wc.hInstance = g_Rainmeter->GetInstance(); wc.hInstance = GetRainmeter().GetModuleInstance();
wc.lpszClassName = L"RainmeterTrayClass"; wc.lpszClassName = L"RainmeterTrayClass";
wc.hIcon = GetIcon(IDI_RAINMETER); wc.hIcon = GetIcon(IDI_RAINMETER);
@ -339,7 +337,7 @@ void TrayWindow::SetTrayIcon(bool enabled)
m_IconEnabled = enabled; m_IconEnabled = enabled;
// Save to Rainmeter.ini. // Save to Rainmeter.ini.
const std::wstring& iniFile = g_Rainmeter->GetIniFile(); const std::wstring& iniFile = GetRainmeter().GetIniFile();
WritePrivateProfileString(L"Rainmeter", L"TrayIcon", enabled ? nullptr : L"0", iniFile.c_str()); WritePrivateProfileString(L"Rainmeter", L"TrayIcon", enabled ? nullptr : L"0", iniFile.c_str());
} }
@ -372,8 +370,8 @@ void TrayWindow::ReadOptions(ConfigParser& parser)
if (!measureName.empty()) if (!measureName.empty())
{ {
ConfigParser* oldParser = g_Rainmeter->GetCurrentParser(); ConfigParser* oldParser = GetRainmeter().GetCurrentParser();
g_Rainmeter->SetCurrentParser(&parser); GetRainmeter().SetCurrentParser(&parser);
m_Measure = Measure::Create(measureName.c_str(), nullptr, L"TrayMeasure"); m_Measure = Measure::Create(measureName.c_str(), nullptr, L"TrayMeasure");
if (m_Measure) if (m_Measure)
@ -381,7 +379,7 @@ void TrayWindow::ReadOptions(ConfigParser& parser)
m_Measure->ReadOptions(parser); m_Measure->ReadOptions(parser);
} }
g_Rainmeter->SetCurrentParser(oldParser); GetRainmeter().SetCurrentParser(oldParser);
} }
const WCHAR* type = parser.ReadString(L"TrayMeasure", L"TrayMeter", m_Measure ? L"HISTOGRAM" : L"NONE").c_str(); const WCHAR* type = parser.ReadString(L"TrayMeasure", L"TrayMeter", m_Measure ? L"HISTOGRAM" : L"NONE").c_str();
@ -404,7 +402,7 @@ void TrayWindow::ReadOptions(ConfigParser& parser)
// Load the bitmaps if defined // Load the bitmaps if defined
if (!imageName.empty()) if (!imageName.empty())
{ {
imageName.insert(0, g_Rainmeter->GetSkinPath()); imageName.insert(0, GetRainmeter().GetSkinPath());
const WCHAR* imagePath = imageName.c_str(); const WCHAR* imagePath = imageName.c_str();
if (_wcsicmp(imagePath + (imageName.size() - 4), L".ico") == 0) if (_wcsicmp(imagePath + (imageName.size() - 4), L".ico") == 0)
{ {
@ -459,7 +457,7 @@ void TrayWindow::ReadOptions(ConfigParser& parser)
LRESULT CALLBACK TrayWindow::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) LRESULT CALLBACK TrayWindow::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{ {
TrayWindow* tray = g_Rainmeter->GetTrayWindow(); TrayWindow* tray = GetRainmeter().GetTrayWindow();
switch (uMsg) switch (uMsg)
{ {
@ -483,11 +481,11 @@ LRESULT CALLBACK TrayWindow::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM
break; break;
case IDM_REFRESH: case IDM_REFRESH:
PostMessage(g_Rainmeter->GetWindow(), WM_RAINMETER_DELAYED_REFRESH_ALL, (WPARAM)nullptr, (LPARAM)nullptr); PostMessage(GetRainmeter().GetWindow(), WM_RAINMETER_DELAYED_REFRESH_ALL, (WPARAM)nullptr, (LPARAM)nullptr);
break; break;
case IDM_SHOWLOGFILE: case IDM_SHOWLOGFILE:
g_Rainmeter->ShowLogFile(); GetRainmeter().ShowLogFile();
break; break;
case IDM_STARTLOG: case IDM_STARTLOG:
@ -503,15 +501,15 @@ LRESULT CALLBACK TrayWindow::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM
break; break;
case IDM_DEBUGLOG: case IDM_DEBUGLOG:
g_Rainmeter->SetDebug(!g_Rainmeter->GetDebug()); GetRainmeter().SetDebug(!GetRainmeter().GetDebug());
break; break;
case IDM_DISABLEDRAG: case IDM_DISABLEDRAG:
g_Rainmeter->SetDisableDragging(!g_Rainmeter->GetDisableDragging()); GetRainmeter().SetDisableDragging(!GetRainmeter().GetDisableDragging());
break; break;
case IDM_EDITCONFIG: case IDM_EDITCONFIG:
g_Rainmeter->EditSettings(); GetRainmeter().EditSettings();
break; break;
case IDM_QUIT: case IDM_QUIT:
@ -519,7 +517,7 @@ LRESULT CALLBACK TrayWindow::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM
break; break;
case IDM_OPENSKINSFOLDER: case IDM_OPENSKINSFOLDER:
g_Rainmeter->OpenSkinFolder(); GetRainmeter().OpenSkinFolder();
break; break;
default: default:
@ -530,25 +528,25 @@ LRESULT CALLBACK TrayWindow::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM
{ {
int pos = mID - ID_THEME_FIRST; int pos = mID - ID_THEME_FIRST;
const std::vector<std::wstring>& layouts = g_Rainmeter->GetAllLayouts(); const std::vector<std::wstring>& layouts = GetRainmeter().GetAllLayouts();
if (pos >= 0 && pos < (int)layouts.size()) if (pos >= 0 && pos < (int)layouts.size())
{ {
g_Rainmeter->LoadLayout(layouts[pos]); GetRainmeter().LoadLayout(layouts[pos]);
} }
} }
else if (mID >= ID_CONFIG_FIRST && mID <= ID_CONFIG_LAST) else if (mID >= ID_CONFIG_FIRST && mID <= ID_CONFIG_LAST)
{ {
std::pair<int, int> indexes = g_Rainmeter->GetMeterWindowIndex(mID); std::pair<int, int> indexes = GetRainmeter().GetMeterWindowIndex(mID);
if (indexes.first != -1 && indexes.second != -1) if (indexes.first != -1 && indexes.second != -1)
{ {
g_Rainmeter->ToggleSkin(indexes.first, indexes.second); GetRainmeter().ToggleSkin(indexes.first, indexes.second);
} }
} }
else else
{ {
// Forward the message to correct window // Forward the message to correct window
int index = (int)(wParam >> 16); int index = (int)(wParam >> 16);
const std::map<std::wstring, MeterWindow*>& windows = g_Rainmeter->GetAllMeterWindows(); const std::map<std::wstring, MeterWindow*>& windows = GetRainmeter().GetAllMeterWindows();
if (index < (int)windows.size()) if (index < (int)windows.size())
{ {
@ -579,19 +577,19 @@ LRESULT CALLBACK TrayWindow::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM
switch (uMouseMsg) switch (uMouseMsg)
{ {
case WM_MBUTTONDOWN: case WM_MBUTTONDOWN:
bang = g_Rainmeter->GetTrayExecuteM().c_str(); bang = GetRainmeter().GetTrayExecuteM().c_str();
break; break;
case WM_RBUTTONDOWN: case WM_RBUTTONDOWN:
bang = g_Rainmeter->GetTrayExecuteR().c_str(); bang = GetRainmeter().GetTrayExecuteR().c_str();
break; break;
case WM_MBUTTONDBLCLK: case WM_MBUTTONDBLCLK:
bang = g_Rainmeter->GetTrayExecuteDM().c_str(); bang = GetRainmeter().GetTrayExecuteDM().c_str();
break; break;
case WM_RBUTTONDBLCLK: case WM_RBUTTONDBLCLK:
bang = g_Rainmeter->GetTrayExecuteDR().c_str(); bang = GetRainmeter().GetTrayExecuteDR().c_str();
break; break;
default: default:
@ -602,7 +600,7 @@ LRESULT CALLBACK TrayWindow::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM
if (*bang && if (*bang &&
!IsCtrlKeyDown()) // Ctrl is pressed, so only run default action !IsCtrlKeyDown()) // Ctrl is pressed, so only run default action
{ {
g_Rainmeter->ExecuteCommand(bang, nullptr); GetRainmeter().ExecuteCommand(bang, nullptr);
tray->m_TrayContextMenuEnabled = (uMouseMsg != WM_RBUTTONDOWN); tray->m_TrayContextMenuEnabled = (uMouseMsg != WM_RBUTTONDOWN);
break; break;
} }
@ -618,7 +616,7 @@ LRESULT CALLBACK TrayWindow::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM
if (tray->m_TrayContextMenuEnabled) if (tray->m_TrayContextMenuEnabled)
{ {
POINT pos = System::GetCursorPosition(); POINT pos = System::GetCursorPosition();
g_Rainmeter->ShowContextMenu(pos, nullptr); GetRainmeter().ShowContextMenu(pos, nullptr);
} }
break; break;
@ -662,19 +660,19 @@ LRESULT CALLBACK TrayWindow::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM
switch (wParam) switch (wParam)
{ {
case RAINMETER_QUERY_ID_SKINS_PATH: case RAINMETER_QUERY_ID_SKINS_PATH:
sendCopyData(g_Rainmeter->GetSkinPath()); sendCopyData(GetRainmeter().GetSkinPath());
return 0; return 0;
case RAINMETER_QUERY_ID_SETTINGS_PATH: case RAINMETER_QUERY_ID_SETTINGS_PATH:
sendCopyData(g_Rainmeter->GetSettingsPath()); sendCopyData(GetRainmeter().GetSettingsPath());
return 0; return 0;
case RAINMETER_QUERY_ID_PLUGINS_PATH: case RAINMETER_QUERY_ID_PLUGINS_PATH:
sendCopyData(g_Rainmeter->GetPluginPath()); sendCopyData(GetRainmeter().GetPluginPath());
return 0; return 0;
case RAINMETER_QUERY_ID_PROGRAM_PATH: case RAINMETER_QUERY_ID_PROGRAM_PATH:
sendCopyData(g_Rainmeter->GetPath()); sendCopyData(GetRainmeter().GetPath());
return 0; return 0;
case RAINMETER_QUERY_ID_LOG_PATH: case RAINMETER_QUERY_ID_LOG_PATH:
@ -682,12 +680,12 @@ LRESULT CALLBACK TrayWindow::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM
return 0; return 0;
case RAINMETER_QUERY_ID_CONFIG_EDITOR: case RAINMETER_QUERY_ID_CONFIG_EDITOR:
sendCopyData(g_Rainmeter->GetSkinEditor()); sendCopyData(GetRainmeter().GetSkinEditor());
return 0; return 0;
case RAINMETER_QUERY_ID_IS_DEBUGGING: case RAINMETER_QUERY_ID_IS_DEBUGGING:
{ {
BOOL debug = g_Rainmeter->GetDebug(); BOOL debug = GetRainmeter().GetDebug();
SendMessage((HWND)lParam, WM_QUERY_RAINMETER_RETURN, (WPARAM)hWnd, (LPARAM)debug); SendMessage((HWND)lParam, WM_QUERY_RAINMETER_RETURN, (WPARAM)hWnd, (LPARAM)debug);
} }
return 0; return 0;
@ -701,7 +699,7 @@ LRESULT CALLBACK TrayWindow::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM
if (cds->dwData == RAINMETER_QUERY_ID_SKIN_WINDOWHANDLE) if (cds->dwData == RAINMETER_QUERY_ID_SKIN_WINDOWHANDLE)
{ {
LPCWSTR folderPath = (LPCWSTR)cds->lpData; LPCWSTR folderPath = (LPCWSTR)cds->lpData;
MeterWindow* mw = g_Rainmeter->GetMeterWindow(folderPath); MeterWindow* mw = GetRainmeter().GetMeterWindow(folderPath);
return (mw) ? (LRESULT)mw->GetWindow() : 0; return (mw) ? (LRESULT)mw->GetWindow() : 0;
} }
} }

View File

@ -22,8 +22,6 @@
#include "TrayWindow.h" #include "TrayWindow.h"
#include "../Version.h" #include "../Version.h"
extern Rainmeter* g_Rainmeter;
void CheckVersion(void* dummy) void CheckVersion(void* dummy)
{ {
HINTERNET hRootHandle = InternetOpen( HINTERNET hRootHandle = InternetOpen(
@ -72,17 +70,17 @@ void CheckVersion(void* dummy)
if (availableVersion > RAINMETER_VERSION || if (availableVersion > RAINMETER_VERSION ||
(revision_beta && availableVersion == RAINMETER_VERSION)) (revision_beta && availableVersion == RAINMETER_VERSION))
{ {
g_Rainmeter->SetNewVersion(); GetRainmeter().SetNewVersion();
WCHAR buffer[32]; WCHAR buffer[32];
const WCHAR* dataFile = g_Rainmeter->GetDataFile().c_str(); const WCHAR* dataFile = GetRainmeter().GetDataFile().c_str();
GetPrivateProfileString(L"Rainmeter", L"LastCheck", L"0", buffer, _countof(buffer), dataFile); GetPrivateProfileString(L"Rainmeter", L"LastCheck", L"0", buffer, _countof(buffer), dataFile);
// Show tray notification only once per new version // Show tray notification only once per new version
int lastVersion = parseVersion(buffer); int lastVersion = parseVersion(buffer);
if (availableVersion > lastVersion) if (availableVersion > lastVersion)
{ {
g_Rainmeter->GetTrayWindow()->ShowUpdateNotification(version); GetRainmeter().GetTrayWindow()->ShowUpdateNotification(version);
WritePrivateProfileString(L"Rainmeter", L"LastCheck", version, dataFile); WritePrivateProfileString(L"Rainmeter", L"LastCheck", version, dataFile);
} }
} }

View File

@ -22,8 +22,6 @@
#include "../../MeterWindow.h" #include "../../MeterWindow.h"
#include "../../MeterString.h" #include "../../MeterString.h"
extern Rainmeter* g_Rainmeter;
#define DECLARE_SELF(L) \ #define DECLARE_SELF(L) \
void* selfData = lua_touserdata(L, 1); \ void* selfData = lua_touserdata(L, 1); \
if (!selfData) return 0; \ if (!selfData) return 0; \
@ -40,7 +38,7 @@ static int Bang(lua_State* L)
if (top == 2) // 1 argument if (top == 2) // 1 argument
{ {
parser.ReplaceVariables(bang); parser.ReplaceVariables(bang);
g_Rainmeter->ExecuteCommand(bang.c_str(), self); GetRainmeter().ExecuteCommand(bang.c_str(), self);
} }
else else
{ {
@ -56,7 +54,7 @@ static int Bang(lua_State* L)
args.push_back(tmpSz); args.push_back(tmpSz);
} }
g_Rainmeter->ExecuteBang(bangSz, args, self); GetRainmeter().ExecuteBang(bangSz, args, self);
} }
} }