mirror of
https://github.com/chibicitiberiu/rainmeter-studio.git
synced 2024-02-24 04:33:31 +00:00
Minor tweaks and cleanup.
This commit is contained in:
parent
f945bacfb7
commit
2a166b520f
@ -591,45 +591,41 @@ const std::wstring& CConfigParser::ReadString(LPCTSTR section, LPCTSTR key, LPCT
|
||||
|
||||
const std::wstring strSection = section;
|
||||
const std::wstring strKey = key;
|
||||
std::wstring strDefault = defValue;
|
||||
|
||||
// If the template is defined read the value first from there.
|
||||
if (m_StyleTemplate.size() > 0)
|
||||
{
|
||||
std::vector<std::wstring>::const_reverse_iterator iter = m_StyleTemplate.rbegin();
|
||||
for ( ; iter != m_StyleTemplate.rend(); ++iter)
|
||||
{
|
||||
const std::wstring& strStyle = GetValue((*iter), strKey, strDefault);
|
||||
|
||||
//LogWithArgs(LOG_DEBUG, L"[%s] %s (from [%s]) : strDefault=%s (0x%p), strStyle=%s (0x%p)",
|
||||
// section, key, (*iter).c_str(), strDefault.c_str(), &strDefault, strStyle.c_str(), &strStyle);
|
||||
|
||||
if (&strStyle != &strDefault)
|
||||
{
|
||||
strDefault = strStyle;
|
||||
m_LastUsedStyle = (*iter);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
const std::wstring strDefault = defValue;
|
||||
|
||||
const std::wstring& strValue = GetValue(strSection, strKey, strDefault);
|
||||
result = strValue;
|
||||
|
||||
if (m_LastUsedStyle.size() > 0)
|
||||
if (&strValue == &strDefault)
|
||||
{
|
||||
if (&strValue != &strDefault)
|
||||
// If the template is defined read the value from there.
|
||||
if (m_StyleTemplate.size() > 0)
|
||||
{
|
||||
m_LastUsedStyle.clear();
|
||||
std::vector<std::wstring>::const_reverse_iterator iter = m_StyleTemplate.rbegin();
|
||||
for ( ; iter != m_StyleTemplate.rend(); ++iter)
|
||||
{
|
||||
const std::wstring& strStyleValue = GetValue((*iter), strKey, strDefault);
|
||||
|
||||
//LogWithArgs(LOG_DEBUG, L"StyleTemplate: [%s] %s (from [%s]) : strDefault=%s (0x%p), strStyleValue=%s (0x%p)",
|
||||
// section, key, (*iter).c_str(), strDefault.c_str(), &strDefault, strStyleValue.c_str(), &strStyleValue);
|
||||
|
||||
if (&strStyleValue != &strDefault)
|
||||
{
|
||||
result = strStyleValue;
|
||||
m_LastUsedStyle = (*iter);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (m_LastUsedStyle.size() == 0) // No template found
|
||||
{
|
||||
result = strDefault;
|
||||
m_LastDefaultUsed = true;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (&strValue == &strDefault)
|
||||
{
|
||||
m_LastDefaultUsed = true;
|
||||
return result;
|
||||
}
|
||||
result = strValue;
|
||||
}
|
||||
|
||||
if (result.size() > 0)
|
||||
@ -1144,6 +1140,7 @@ void CConfigParser::ReadIniFile(const std::vector<std::wstring>& iniFileMappings
|
||||
{
|
||||
std::unordered_set<std::wstring> foundKeys;
|
||||
bool isVariables = (_wcsicmp((*iter).c_str(), L"Variables") == 0);
|
||||
bool isMetadata = (config == NULL && _wcsicmp((*iter).c_str(), L"Metadata") == 0);
|
||||
|
||||
// Read all "key=value" from the section
|
||||
while (true)
|
||||
@ -1190,8 +1187,7 @@ void CConfigParser::ReadIniFile(const std::vector<std::wstring>& iniFileMappings
|
||||
{
|
||||
ReadVariables();
|
||||
ReplaceVariables(value);
|
||||
if (value.find(L':') == std::wstring::npos &&
|
||||
(valueLen < 2 || (value[0] != L'\\' && value[0] != L'/') || (value[1] != L'\\' && value[1] != L'/')))
|
||||
if (!CSystem::IsAbsolutePath(value))
|
||||
{
|
||||
// It's a relative path so add the current path as a prefix
|
||||
value.insert(0, CRainmeter::ExtractPath(iniFile));
|
||||
@ -1200,7 +1196,10 @@ void CConfigParser::ReadIniFile(const std::vector<std::wstring>& iniFileMappings
|
||||
}
|
||||
else
|
||||
{
|
||||
SetValue((*iter), key, value);
|
||||
if (!isMetadata) // Uncache Metadata's key-value pair in the skin
|
||||
{
|
||||
SetValue((*iter), key, value);
|
||||
}
|
||||
|
||||
if (isVariables)
|
||||
{
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include "StdAfx.h"
|
||||
#include "MeasureDiskSpace.h"
|
||||
#include "Rainmeter.h"
|
||||
#include "System.h"
|
||||
|
||||
/*
|
||||
** CMeasureDiskSpace
|
||||
@ -156,7 +157,7 @@ void CMeasureDiskSpace::ReadConfig(CConfigParser& parser, const WCHAR* section)
|
||||
m_OldTotalBytes = 0;
|
||||
m_LabelName = L"";
|
||||
}
|
||||
else if (m_Drive[m_Drive.length() - 1] != L'\\') // E.g. "C:"
|
||||
else if (!CSystem::IsPathSeparator(m_Drive[m_Drive.length() - 1])) // E.g. "C:"
|
||||
{
|
||||
m_Drive += L"\\"; // A trailing backslash is required.
|
||||
}
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "Measure.h"
|
||||
#include "Error.h"
|
||||
#include "Rainmeter.h"
|
||||
#include "System.h"
|
||||
|
||||
extern CRainmeter* Rainmeter;
|
||||
|
||||
@ -129,8 +130,7 @@ void CMeterImage::ReadConfig(CConfigParser& parser, const WCHAR* section)
|
||||
m_Path = parser.ReadString(section, L"Path", L"");
|
||||
if (!m_Path.empty())
|
||||
{
|
||||
WCHAR ch = m_Path[m_Path.length() - 1];
|
||||
if (ch != L'\\' && ch != L'/')
|
||||
if (!CSystem::IsPathSeparator(m_Path[m_Path.length() - 1]))
|
||||
{
|
||||
m_Path += L"\\";
|
||||
}
|
||||
|
@ -5094,9 +5094,7 @@ std::wstring CMeterWindow::MakePathAbsolute(const std::wstring& path)
|
||||
{
|
||||
std::wstring absolute;
|
||||
|
||||
if (path.empty() ||
|
||||
path.find(L":\\") != std::wstring::npos || path.find(L":/") != std::wstring::npos ||
|
||||
(path.length() >= 2 && (path[0] == L'\\' || path[0] == L'/') && (path[1] == L'\\' || path[1] == L'/'))) // UNC
|
||||
if (path.empty() || CSystem::IsAbsolutePath(path))
|
||||
{
|
||||
absolute = path; // It's already absolute path (or it's empty)
|
||||
}
|
||||
|
@ -865,7 +865,7 @@ int CRainmeter::Initialize(HWND hParent, HINSTANCE hInstance, LPCWSTR szPath)
|
||||
|
||||
ExpandEnvironmentVariables(iniFile);
|
||||
|
||||
if (iniFile.empty() || iniFile[iniFile.length() - 1] == L'\\')
|
||||
if (iniFile.empty() || CSystem::IsPathSeparator(iniFile[iniFile.length() - 1]))
|
||||
{
|
||||
iniFile += L"Rainmeter.ini";
|
||||
}
|
||||
@ -874,7 +874,7 @@ int CRainmeter::Initialize(HWND hParent, HINSTANCE hInstance, LPCWSTR szPath)
|
||||
iniFile += L"\\Rainmeter.ini";
|
||||
}
|
||||
|
||||
if (iniFile[0] != L'\\' && iniFile[0] != L'/' && iniFile.find_first_of(L':') == std::wstring::npos)
|
||||
if (!CSystem::IsPathSeparator(iniFile[0]) && iniFile.find_first_of(L':') == std::wstring::npos)
|
||||
{
|
||||
// Make absolute path
|
||||
iniFile.insert(0, m_Path);
|
||||
@ -990,8 +990,7 @@ int CRainmeter::Initialize(HWND hParent, HINSTANCE hInstance, LPCWSTR szPath)
|
||||
|
||||
if (!m_SkinPath.empty())
|
||||
{
|
||||
WCHAR ch = m_SkinPath[m_SkinPath.size() - 1];
|
||||
if (ch != L'\\' && ch != L'/')
|
||||
if (!CSystem::IsPathSeparator(m_SkinPath[m_SkinPath.size() - 1]))
|
||||
{
|
||||
m_SkinPath += L"\\";
|
||||
}
|
||||
@ -1054,7 +1053,7 @@ int CRainmeter::Initialize(HWND hParent, HINSTANCE hInstance, LPCWSTR szPath)
|
||||
{
|
||||
m_Drive.assign(m_Path, 0, loc + 1);
|
||||
}
|
||||
else if (m_Path.length() >= 2 && (m_Path[0] == L'\\' || m_Path[0] == L'/') && (m_Path[1] == L'\\' || m_Path[1] == L'/'))
|
||||
else if (CSystem::IsUNCPath(m_Path))
|
||||
{
|
||||
if ((loc = m_Path.find_first_of(L"\\/", 2)) != std::wstring::npos)
|
||||
{
|
||||
|
@ -72,6 +72,10 @@ public:
|
||||
static OSPLATFORM GetOSPlatform();
|
||||
static ULONGLONG GetTickCount64();
|
||||
|
||||
static bool IsPathSeparator(WCHAR ch) { return (ch == L'\\' || ch == L'/'); }
|
||||
static bool IsUNCPath(const std::wstring& path) { return (path.length() >= 2 && IsPathSeparator(path[0]) && IsPathSeparator(path[1])); }
|
||||
static bool IsAbsolutePath(const std::wstring& path) { return (path.find(L":\\") != std::wstring::npos || path.find(L":/") != std::wstring::npos || IsUNCPath(path)); }
|
||||
|
||||
static HMODULE RmLoadLibrary(LPCWSTR lpLibFileName, DWORD* dwError = NULL, bool ignoreErrors = false);
|
||||
static void ResetWorkingDirectory();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user