mirror of
https://github.com/chibicitiberiu/rainmeter-studio.git
synced 2024-02-24 04:33:31 +00:00
- Fixed the issue that the check marks of all menu items in configs/root/variants menu are cleared if !RainmeterDeactivateConfig/!RainmeterToggleConfig is used.
- Fixed the issue that %APPDATA% isn't replaced if Rainmeter runs as different user. - Some stability improvements for activating/deactivating configs.
This commit is contained in:
parent
dc7ccdd7ed
commit
4965f3859f
@ -864,6 +864,13 @@ void CConfigParser::ReadIniFile(const std::wstring& iniFile, int depth)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Verify whether the file exists
|
||||||
|
if (_waccess(iniFile.c_str(), 0) == -1)
|
||||||
|
{
|
||||||
|
DebugLog(L"Unable to read file: %s", iniFile.c_str());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Avoid "IniFileMapping"
|
// Avoid "IniFileMapping"
|
||||||
std::wstring iniRead = GetAlternateFileName(iniFile);
|
std::wstring iniRead = GetAlternateFileName(iniFile);
|
||||||
bool alternate = false;
|
bool alternate = false;
|
||||||
|
@ -523,16 +523,12 @@ void RainmeterDeactivateConfig(HWND, const char* arg)
|
|||||||
|
|
||||||
if (subStrings.size() > 0)
|
if (subStrings.size() > 0)
|
||||||
{
|
{
|
||||||
std::map<std::wstring, CMeterWindow*>::const_iterator iter = Rainmeter->GetAllMeterWindows().begin();
|
CMeterWindow* mw = Rainmeter->GetMeterWindow(subStrings[0]);
|
||||||
for (; iter != Rainmeter->GetAllMeterWindows().end(); ++iter)
|
if (mw)
|
||||||
{
|
{
|
||||||
CMeterWindow* mw = ((*iter).second);
|
Rainmeter->DeactivateConfig(mw, -1);
|
||||||
if (wcsicmp(subStrings[0].c_str(), mw->GetSkinName().c_str()) == 0)
|
|
||||||
{
|
|
||||||
Rainmeter->DeactivateConfig(mw, -1); // -1 = Deactivate all ini-files
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
DebugLog(L"The config is not active: \"%s\"", subStrings[0].c_str());
|
DebugLog(L"The config is not active: \"%s\"", subStrings[0].c_str());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -556,16 +552,12 @@ void RainmeterToggleConfig(HWND, const char* arg)
|
|||||||
|
|
||||||
if (subStrings.size() >= 2)
|
if (subStrings.size() >= 2)
|
||||||
{
|
{
|
||||||
std::map<std::wstring, CMeterWindow*>::const_iterator iter = Rainmeter->GetAllMeterWindows().begin();
|
CMeterWindow* mw = Rainmeter->GetMeterWindow(subStrings[0]);
|
||||||
for (; iter != Rainmeter->GetAllMeterWindows().end(); ++iter)
|
if (mw)
|
||||||
{
|
{
|
||||||
CMeterWindow* mw = ((*iter).second);
|
Rainmeter->DeactivateConfig(mw, -1);
|
||||||
if (wcsicmp(subStrings[0].c_str(), mw->GetSkinName().c_str()) == 0)
|
|
||||||
{
|
|
||||||
Rainmeter->DeactivateConfig(mw, -1); // -1 = Deactivate all ini-files
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// If the config wasn't active, activate it
|
// If the config wasn't active, activate it
|
||||||
RainmeterActivateConfig(NULL, arg);
|
RainmeterActivateConfig(NULL, arg);
|
||||||
@ -795,7 +787,7 @@ void RainmeterDeactivateConfigGroup(HWND, const char* arg)
|
|||||||
std::multimap<int, CMeterWindow*>::const_iterator iter = windows.begin();
|
std::multimap<int, CMeterWindow*>::const_iterator iter = windows.begin();
|
||||||
for (; iter != windows.end(); ++iter)
|
for (; iter != windows.end(); ++iter)
|
||||||
{
|
{
|
||||||
Rainmeter->DeactivateConfig((*iter).second, -1); // -1 = Deactivate all ini-files
|
Rainmeter->DeactivateConfig((*iter).second, -1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -874,18 +866,14 @@ void RainmeterSkinMenu(HWND, const char* arg)
|
|||||||
|
|
||||||
if (subStrings.size() > 0)
|
if (subStrings.size() > 0)
|
||||||
{
|
{
|
||||||
std::map<std::wstring, CMeterWindow*>::const_iterator iter = Rainmeter->GetAllMeterWindows().begin();
|
CMeterWindow* mw = Rainmeter->GetMeterWindow(subStrings[0]);
|
||||||
for (; iter != Rainmeter->GetAllMeterWindows().end(); ++iter)
|
if (mw)
|
||||||
{
|
|
||||||
CMeterWindow* mw = ((*iter).second);
|
|
||||||
if (wcsicmp(subStrings[0].c_str(), mw->GetSkinName().c_str()) == 0)
|
|
||||||
{
|
{
|
||||||
POINT pos;
|
POINT pos;
|
||||||
GetCursorPos(&pos);
|
GetCursorPos(&pos);
|
||||||
Rainmeter->ShowContextMenu(pos, mw);
|
Rainmeter->ShowContextMenu(pos, mw);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
DebugLog(L"The config is not active: \"%s\"", subStrings[0].c_str());
|
DebugLog(L"The config is not active: \"%s\"", subStrings[0].c_str());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -1256,7 +1244,7 @@ int CRainmeter::Initialize(HWND Parent, HINSTANCE Instance, LPCSTR szPath)
|
|||||||
|
|
||||||
if (c_Debug)
|
if (c_Debug)
|
||||||
{
|
{
|
||||||
LSLog(LOG_DEBUG, L"Rainmeter", L"Enumerating installed font families ...");
|
LSLog(LOG_DEBUG, APPNAME, L"Enumerating installed font families ...");
|
||||||
CMeterString::EnumerateInstalledFontFamilies();
|
CMeterString::EnumerateInstalledFontFamilies();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1603,10 +1591,9 @@ void CRainmeter::ActivateConfig(int configIndex, int iniIndex)
|
|||||||
{
|
{
|
||||||
if (configIndex >= 0 && configIndex < (int)m_ConfigStrings.size())
|
if (configIndex >= 0 && configIndex < (int)m_ConfigStrings.size())
|
||||||
{
|
{
|
||||||
WCHAR buffer[256];
|
const std::wstring skinIniFile = m_ConfigStrings[configIndex].iniFiles[iniIndex];
|
||||||
std::wstring skinIniFile = m_ConfigStrings[configIndex].iniFiles[iniIndex];
|
const std::wstring skinConfig = m_ConfigStrings[configIndex].config;
|
||||||
std::wstring skinConfig = m_ConfigStrings[configIndex].config;
|
const std::wstring skinPath = m_ConfigStrings[configIndex].path;
|
||||||
std::wstring skinPath = m_ConfigStrings[configIndex].path;
|
|
||||||
|
|
||||||
// Verify that the config is not already active
|
// Verify that the config is not already active
|
||||||
std::map<std::wstring, CMeterWindow*>::const_iterator iter = m_Meters.find(skinConfig);
|
std::map<std::wstring, CMeterWindow*>::const_iterator iter = m_Meters.find(skinConfig);
|
||||||
@ -1624,13 +1611,29 @@ void CRainmeter::ActivateConfig(int configIndex, int iniIndex)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Verify whether the ini-file exists
|
||||||
|
std::wstring skinIniPath = skinPath;
|
||||||
|
skinIniPath += skinConfig;
|
||||||
|
skinIniPath += L"\\";
|
||||||
|
skinIniPath += skinIniFile;
|
||||||
|
|
||||||
|
if (_waccess(skinIniPath.c_str(), 0) == -1)
|
||||||
|
{
|
||||||
|
std::wstring message = L"Unable to activate config \"";
|
||||||
|
message += skinConfig.c_str();
|
||||||
|
message += L"\": Ini-file not found: \"";
|
||||||
|
message += skinIniFile.c_str();
|
||||||
|
message += L"\"";
|
||||||
|
LSLog(LOG_DEBUG, APPNAME, message.c_str());
|
||||||
|
MessageBox(NULL, message.c_str(), APPNAME, MB_OK | MB_TOPMOST | MB_ICONEXCLAMATION);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_ConfigStrings[configIndex].active = iniIndex + 1;
|
||||||
|
WriteActive(skinConfig, iniIndex);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
m_ConfigStrings[configIndex].active = iniIndex + 1;
|
|
||||||
|
|
||||||
wsprintf(buffer, L"%i", iniIndex + 1);
|
|
||||||
WritePrivateProfileString(skinConfig.c_str(), L"Active", buffer, m_IniFile.c_str());
|
|
||||||
|
|
||||||
CreateMeterWindow(skinPath, skinConfig, skinIniFile);
|
CreateMeterWindow(skinPath, skinConfig, skinIniFile);
|
||||||
}
|
}
|
||||||
catch(CError& error)
|
catch(CError& error)
|
||||||
@ -1646,25 +1649,37 @@ bool CRainmeter::DeactivateConfig(CMeterWindow* meterWindow, int configIndex)
|
|||||||
{
|
{
|
||||||
m_ConfigStrings[configIndex].active = 0; // Deactivate the config
|
m_ConfigStrings[configIndex].active = 0; // Deactivate the config
|
||||||
}
|
}
|
||||||
else
|
else if (configIndex == -1 && meterWindow)
|
||||||
{
|
{
|
||||||
// Deactive all
|
// Deactivate the config by using the meter window's config name
|
||||||
|
const std::wstring skinConfig = meterWindow->GetSkinName();
|
||||||
for (size_t i = 0; i < m_ConfigStrings.size(); ++i)
|
for (size_t i = 0; i < m_ConfigStrings.size(); ++i)
|
||||||
|
{
|
||||||
|
if (wcsicmp(skinConfig.c_str(), m_ConfigStrings[i].config.c_str()) == 0)
|
||||||
{
|
{
|
||||||
m_ConfigStrings[i].active = 0;
|
m_ConfigStrings[i].active = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (meterWindow)
|
if (meterWindow)
|
||||||
{
|
{
|
||||||
// Disable the config in the ini-file
|
// Disable the config in the ini-file
|
||||||
WritePrivateProfileString(meterWindow->GetSkinName().c_str(), L"Active", L"0", m_IniFile.c_str());
|
WriteActive(meterWindow->GetSkinName(), -1);
|
||||||
|
|
||||||
return DeleteMeterWindow(meterWindow, true);
|
return DeleteMeterWindow(meterWindow, true);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CRainmeter::WriteActive(const std::wstring& config, int iniIndex)
|
||||||
|
{
|
||||||
|
WCHAR buffer[256];
|
||||||
|
wsprintf(buffer, L"%i", iniIndex + 1);
|
||||||
|
WritePrivateProfileString(config.c_str(), L"Active", buffer, m_IniFile.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
void CRainmeter::CreateMeterWindow(std::wstring path, std::wstring config, std::wstring iniFile)
|
void CRainmeter::CreateMeterWindow(std::wstring path, std::wstring config, std::wstring iniFile)
|
||||||
{
|
{
|
||||||
CMeterWindow* mw = new CMeterWindow(path, config, iniFile);
|
CMeterWindow* mw = new CMeterWindow(path, config, iniFile);
|
||||||
@ -1706,7 +1721,6 @@ bool CRainmeter::DeleteMeterWindow(CMeterWindow* meterWindow, bool bLater)
|
|||||||
{
|
{
|
||||||
m_DelayDeleteList.push_back(meterWindow);
|
m_DelayDeleteList.push_back(meterWindow);
|
||||||
meterWindow->RunBang(BANG_HIDEFADE, NULL); // Fade out the window
|
meterWindow->RunBang(BANG_HIDEFADE, NULL); // Fade out the window
|
||||||
//meterWindow->FadeWindow(meterWindow->GetAlphaValue(), 0); // Fade out the window
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -1744,7 +1758,7 @@ CMeterWindow* CRainmeter::GetMeterWindow(const std::wstring& config)
|
|||||||
|
|
||||||
for (; iter != m_Meters.end(); ++iter)
|
for (; iter != m_Meters.end(); ++iter)
|
||||||
{
|
{
|
||||||
if ((*iter).first == config)
|
if (wcsicmp((*iter).first.c_str(), config.c_str()) == 0)
|
||||||
{
|
{
|
||||||
return (*iter).second;
|
return (*iter).second;
|
||||||
}
|
}
|
||||||
@ -2454,7 +2468,7 @@ void CRainmeter::ReadGeneralSettings(std::wstring& iniFile)
|
|||||||
if (m_ConfigEditor.empty())
|
if (m_ConfigEditor.empty())
|
||||||
{
|
{
|
||||||
// Get the program path associated with .ini files
|
// Get the program path associated with .ini files
|
||||||
WCHAR buffer[MAX_PATH+1] = {0};
|
WCHAR buffer[MAX_PATH] = {0};
|
||||||
DWORD cchOut = MAX_PATH;
|
DWORD cchOut = MAX_PATH;
|
||||||
|
|
||||||
HRESULT hr = AssocQueryString(ASSOCF_NOTRUNCATE, ASSOCSTR_EXECUTABLE, L".ini", L"open", buffer, &cchOut);
|
HRESULT hr = AssocQueryString(ASSOCF_NOTRUNCATE, ASSOCSTR_EXECUTABLE, L".ini", L"open", buffer, &cchOut);
|
||||||
@ -2477,7 +2491,7 @@ void CRainmeter::ReadGeneralSettings(std::wstring& iniFile)
|
|||||||
if (m_LogViewer.empty())
|
if (m_LogViewer.empty())
|
||||||
{
|
{
|
||||||
// Get the program path associated with .log files
|
// Get the program path associated with .log files
|
||||||
WCHAR buffer[MAX_PATH+1] = {0};
|
WCHAR buffer[MAX_PATH] = {0};
|
||||||
DWORD cchOut = MAX_PATH;
|
DWORD cchOut = MAX_PATH;
|
||||||
|
|
||||||
HRESULT hr = AssocQueryString(ASSOCF_NOTRUNCATE, ASSOCSTR_EXECUTABLE, L".log", L"open", buffer, &cchOut);
|
HRESULT hr = AssocQueryString(ASSOCF_NOTRUNCATE, ASSOCSTR_EXECUTABLE, L".log", L"open", buffer, &cchOut);
|
||||||
@ -2636,15 +2650,71 @@ void CRainmeter::RefreshAll()
|
|||||||
std::multimap<int, CMeterWindow*>::const_iterator iter = windows.begin();
|
std::multimap<int, CMeterWindow*>::const_iterator iter = windows.begin();
|
||||||
for ( ; iter != windows.end(); ++iter)
|
for ( ; iter != windows.end(); ++iter)
|
||||||
{
|
{
|
||||||
if ((*iter).second)
|
CMeterWindow* mw = (*iter).second;
|
||||||
|
if (mw)
|
||||||
{
|
{
|
||||||
|
// Verify whether the cached information is valid
|
||||||
|
int found = 0;
|
||||||
|
std::wstring skinConfig = mw->GetSkinName();
|
||||||
|
for (size_t i = 0; i < m_ConfigStrings.size(); ++i)
|
||||||
|
{
|
||||||
|
if (wcsicmp(skinConfig.c_str(), m_ConfigStrings[i].config.c_str()) == 0)
|
||||||
|
{
|
||||||
|
found = 1;
|
||||||
|
std::wstring skinIniFile = mw->GetSkinIniFile();
|
||||||
|
for (size_t j = 0; j < m_ConfigStrings[i].iniFiles.size(); ++j)
|
||||||
|
{
|
||||||
|
if (wcsicmp(skinIniFile.c_str(), m_ConfigStrings[i].iniFiles[j].c_str()) == 0)
|
||||||
|
{
|
||||||
|
found = 2;
|
||||||
|
if (m_ConfigStrings[i].active != j + 1)
|
||||||
|
{
|
||||||
|
// Switch to new ini-file order
|
||||||
|
m_ConfigStrings[i].active = j + 1;
|
||||||
|
WriteActive(skinConfig, j);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (found == 1) // Not found in ini-files
|
||||||
|
{
|
||||||
|
DeactivateConfig(mw, i);
|
||||||
|
|
||||||
|
std::wstring message = L"Unable to refresh config \"";
|
||||||
|
message += skinConfig.c_str();
|
||||||
|
message += L"\": Ini-file not found: \"";
|
||||||
|
message += skinIniFile.c_str();
|
||||||
|
message += L"\"";
|
||||||
|
LSLog(LOG_DEBUG, APPNAME, message.c_str());
|
||||||
|
MessageBox(NULL, message.c_str(), APPNAME, MB_OK | MB_TOPMOST | MB_ICONEXCLAMATION);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (found != 2)
|
||||||
|
{
|
||||||
|
if (found == 0) // Not found in configs
|
||||||
|
{
|
||||||
|
DeactivateConfig(mw, -2); // -2 = Deactivate the config forcibly
|
||||||
|
|
||||||
|
std::wstring message = L"Unable to refresh config \"";
|
||||||
|
message += skinConfig.c_str();
|
||||||
|
message += L"\": Config not found";
|
||||||
|
LSLog(LOG_DEBUG, APPNAME, message.c_str());
|
||||||
|
MessageBox(NULL, message.c_str(), APPNAME, MB_OK | MB_TOPMOST | MB_ICONEXCLAMATION);
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
(*iter).second->Refresh(false, true);
|
mw->Refresh(false, true);
|
||||||
}
|
}
|
||||||
catch (CError& error)
|
catch (CError& error)
|
||||||
{
|
{
|
||||||
MessageBox((*iter).second->GetWindow(), error.GetString().c_str(), APPNAME, MB_OK | MB_TOPMOST | MB_ICONEXCLAMATION);
|
MessageBox(mw->GetWindow(), error.GetString().c_str(), APPNAME, MB_OK | MB_TOPMOST | MB_ICONEXCLAMATION);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3221,7 +3291,7 @@ HMENU CRainmeter::CreateSkinMenu(CMeterWindow* meterWindow, int index, HMENU con
|
|||||||
|
|
||||||
for (int i = 0; i < itemCount; ++i)
|
for (int i = 0; i < itemCount; ++i)
|
||||||
{
|
{
|
||||||
WCHAR buffer[MAX_PATH+1] = {0};
|
WCHAR buffer[MAX_PATH] = {0};
|
||||||
MENUITEMINFO itemInfo = {sizeof(MENUITEMINFO)};
|
MENUITEMINFO itemInfo = {sizeof(MENUITEMINFO)};
|
||||||
itemInfo.fMask = MIIM_STRING;
|
itemInfo.fMask = MIIM_STRING;
|
||||||
itemInfo.dwTypeData = buffer;
|
itemInfo.dwTypeData = buffer;
|
||||||
@ -3464,6 +3534,19 @@ void CRainmeter::ExpandEnvironmentVariables(std::wstring& strPath)
|
|||||||
{
|
{
|
||||||
WCHAR buffer[4096]; // lets hope the buffer is large enough...
|
WCHAR buffer[4096]; // lets hope the buffer is large enough...
|
||||||
|
|
||||||
|
// %APPDATA% is a special case
|
||||||
|
std::wstring::size_type pos = strPath.find(L"%APPDATA%");
|
||||||
|
if (pos != std::wstring::npos)
|
||||||
|
{
|
||||||
|
HRESULT hr = SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, buffer);
|
||||||
|
if (SUCCEEDED(hr))
|
||||||
|
{
|
||||||
|
strPath.replace(pos, 9, buffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strPath.find(L'%') != std::wstring::npos)
|
||||||
|
{
|
||||||
// Expand the environment variables
|
// Expand the environment variables
|
||||||
DWORD ret = ExpandEnvironmentStrings(strPath.c_str(), buffer, 4096);
|
DWORD ret = ExpandEnvironmentStrings(strPath.c_str(), buffer, 4096);
|
||||||
if (ret != 0 && ret < 4096)
|
if (ret != 0 && ret < 4096)
|
||||||
@ -3476,3 +3559,4 @@ void CRainmeter::ExpandEnvironmentVariables(std::wstring& strPath)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
@ -215,6 +215,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
void CreateMeterWindow(std::wstring path, std::wstring config, std::wstring iniFile);
|
void CreateMeterWindow(std::wstring path, std::wstring config, std::wstring iniFile);
|
||||||
bool DeleteMeterWindow(CMeterWindow* meterWindow, bool bLater);
|
bool DeleteMeterWindow(CMeterWindow* meterWindow, bool bLater);
|
||||||
|
void WriteActive(const std::wstring& config, int iniIndex);
|
||||||
void ScanForConfigs(std::wstring& path);
|
void ScanForConfigs(std::wstring& path);
|
||||||
void ScanForThemes(std::wstring& path);
|
void ScanForThemes(std::wstring& path);
|
||||||
void ReadGeneralSettings(std::wstring& path);
|
void ReadGeneralSettings(std::wstring& path);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user