Minor tweaks.

This commit is contained in:
spx 2011-11-14 14:32:11 +00:00
parent 1869dc467a
commit e119672f1c
4 changed files with 39 additions and 31 deletions

View File

@ -696,14 +696,8 @@ std::vector<Gdiplus::REAL> CConfigParser::ReadFloats(LPCTSTR section, LPCTSTR ke
const std::wstring& string = ReadString(section, key, L""); const std::wstring& string = ReadString(section, key, L"");
if (!string.empty()) if (!string.empty())
{ {
std::wstring tmp = string;
if (tmp[tmp.length() - 1] != L';')
{
tmp += L";";
}
// Tokenize and parse the floats // Tokenize and parse the floats
std::vector<std::wstring> tokens = Tokenize(tmp, L";"); std::vector<std::wstring> tokens = Tokenize(string, L";");
std::vector<std::wstring>::const_iterator iter = tokens.begin(); std::vector<std::wstring>::const_iterator iter = tokens.begin();
for ( ; iter != tokens.end(); ++iter) for ( ; iter != tokens.end(); ++iter)
{ {

View File

@ -51,7 +51,7 @@ public:
void SetValue(const std::wstring& strSection, const std::wstring& strKey, const std::wstring& strValue); void SetValue(const std::wstring& strSection, const std::wstring& strKey, const std::wstring& strValue);
void DeleteValue(const std::wstring& strSection, const std::wstring& strKey); void DeleteValue(const std::wstring& strSection, const std::wstring& strKey);
void SetStyleTemplate(const std::wstring& strStyle) { m_StyleTemplate = Tokenize(strStyle, L"|"); Shrink(m_StyleTemplate); } void SetStyleTemplate(const std::wstring& strStyle) { Tokenize(strStyle, L"|").swap(m_StyleTemplate); Shrink(m_StyleTemplate); }
void ClearStyleTemplate() { m_StyleTemplate.clear(); } void ClearStyleTemplate() { m_StyleTemplate.clear(); }
const std::wstring& GetLastUsedStyle() { return m_LastUsedStyle; } const std::wstring& GetLastUsedStyle() { return m_LastUsedStyle; }

View File

@ -323,7 +323,7 @@ BOOL LogInternal(int nLevel, ULONGLONG elapsed, LPCTSTR pszMessage)
// The stub implementation // The stub implementation
if (Rainmeter->GetLogging()) if (Rainmeter->GetLogging())
{ {
std::wstring logfile = Rainmeter->GetLogFile(); const std::wstring& logfile = Rainmeter->GetLogFile();
if (logFound == 0) if (logFound == 0)
{ {
// Check if the file exists // Check if the file exists

View File

@ -1180,11 +1180,14 @@ bool CSystem::CopyFiles(const std::wstring& strFrom, const std::wstring& strTo,
tmpFrom.append(1, L'\0'); tmpFrom.append(1, L'\0');
tmpTo.append(1, L'\0'); tmpTo.append(1, L'\0');
SHFILEOPSTRUCT fo = {0}; SHFILEOPSTRUCT fo =
fo.wFunc = bMove ? FO_MOVE : FO_COPY; {
fo.pFrom = tmpFrom.c_str(); NULL,
fo.pTo = tmpTo.c_str(); bMove ? FO_MOVE : FO_COPY,
fo.fFlags = FOF_NO_UI | FOF_NOCONFIRMATION | FOF_ALLOWUNDO; tmpFrom.c_str(),
tmpTo.c_str(),
FOF_NO_UI | FOF_NOCONFIRMATION | FOF_ALLOWUNDO
};
int result = SHFileOperation(&fo); int result = SHFileOperation(&fo);
if (result != 0) if (result != 0)
@ -1226,10 +1229,14 @@ bool CSystem::RemoveFolder(const std::wstring& strFolder)
// The strings must end with double nul // The strings must end with double nul
tmpFolder.append(1, L'\0'); tmpFolder.append(1, L'\0');
SHFILEOPSTRUCT fo = {0}; SHFILEOPSTRUCT fo =
fo.wFunc = FO_DELETE; {
fo.pFrom = tmpFolder.c_str(); NULL,
fo.fFlags = FOF_NO_UI | FOF_NOCONFIRMATION | FOF_ALLOWUNDO; FO_DELETE,
tmpFolder.c_str(),
NULL,
FOF_NO_UI | FOF_NOCONFIRMATION | FOF_ALLOWUNDO
};
int result = SHFileOperation(&fo); int result = SHFileOperation(&fo);
if (result != 0) if (result != 0)
@ -1287,7 +1294,7 @@ void CSystem::UpdateIniFileMappingList()
c_IniFileMappings.clear(); c_IniFileMappings.clear();
} }
WCHAR buffer[MAX_PATH]; WCHAR* buffer = new WCHAR[MAX_PATH];
DWORD index = 0, cch = MAX_PATH; DWORD index = 0, cch = MAX_PATH;
while ((ret = RegEnumKeyEx(hKey, index++, buffer, &cch, NULL, NULL, NULL, NULL)) != ERROR_NO_MORE_ITEMS) while ((ret = RegEnumKeyEx(hKey, index++, buffer, &cch, NULL, NULL, NULL, NULL)) != ERROR_NO_MORE_ITEMS)
@ -1298,6 +1305,8 @@ void CSystem::UpdateIniFileMappingList()
} }
cch = MAX_PATH; cch = MAX_PATH;
} }
delete [] buffer;
} }
RegCloseKey(hKey); RegCloseKey(hKey);
@ -1326,31 +1335,36 @@ std::wstring CSystem::GetTemporaryFile(const std::wstring& iniFile)
{ {
if (_wcsicmp((*iter).c_str(), filename) == 0) if (_wcsicmp((*iter).c_str(), filename) == 0)
{ {
WCHAR buffer[MAX_PATH]; WCHAR* buffer = new WCHAR[MAX_PATH];
GetTempPath(MAX_PATH, buffer); if (GetTempPath(MAX_PATH, buffer) != 0 &&
temporary = buffer; GetTempFileName(buffer, L"cfg", 0, buffer) != 0)
if (GetTempFileName(temporary.c_str(), L"cfg", 0, buffer) != 0)
{ {
temporary = buffer; temporary = buffer;
std::wstring tmp = GetTemporaryFile(temporary); std::wstring tmp = GetTemporaryFile(temporary);
if (tmp.empty() && CopyFiles(iniFile, temporary)) if (!tmp.empty() || !CopyFiles(iniFile, temporary)) // temporary is reserved or failed
{
return temporary;
}
else // temporary is reserved or failed
{ {
RemoveFile(temporary); RemoveFile(temporary);
if (tmp.empty()) tmp = L"?";
return tmp; if (tmp.empty())
{
temporary = L"?";
}
else
{
temporary.swap(tmp);
}
} }
} }
else // failed else // failed
{ {
LogWithArgs(LOG_ERROR, L"Unable to create temporary file to: %s", temporary.c_str()); LogWithArgs(LOG_ERROR, L"Unable to create temporary file to: %s", temporary.c_str());
return L"?"; temporary = L"?";
} }
delete [] buffer;
break;
} }
} }
} }