This commit is contained in:
Birunthan Mohanathas 2011-11-08 19:02:31 +00:00
parent dfd53fb158
commit 852163bf68
4 changed files with 25 additions and 23 deletions

View File

@ -957,22 +957,14 @@ INT_PTR CDialogManage::CTabSkins::OnCommand(WPARAM wParam, LPARAM lParam)
std::wstring command = Rainmeter->GetSkinPath() + m_SkinName;
command += L"\\";
command += m_FileName;
HANDLE file = CreateFile(command.c_str(), GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
bool writable = CSystem::IsFileWritable(command.c_str());
command.insert(0, L" \"");
command.insert(0, Rainmeter->GetConfigEditor());
command += L"\"";
if (file == INVALID_HANDLE_VALUE)
{
// File is in protected location, so execute as admin
RunCommand(NULL, command.c_str(), SW_SHOWNORMAL, L"runas");
}
else
{
CloseHandle(file);
RunCommand(NULL, command.c_str(), SW_SHOWNORMAL);
}
// Execute as admin if in protected location
RunCommand(NULL, command.c_str(), SW_SHOWNORMAL, !writable);
}
break;
@ -1746,7 +1738,7 @@ INT_PTR CDialogManage::CTabSettings::OnCommand(WPARAM wParam, LPARAM lParam)
{
WCHAR buffer[16];
int sel = ComboBox_GetCurSel((HWND)lParam);
LCID lcid = ComboBox_GetItemData((HWND)lParam, sel);
LCID lcid = (LCID)ComboBox_GetItemData((HWND)lParam, sel);
_ultow(lcid, buffer, 10);
WritePrivateProfileString(L"Rainmeter", L"Language", buffer, Rainmeter->GetIniFile().c_str());

View File

@ -3143,17 +3143,7 @@ void CRainmeter::SetDisableVersionCheck(bool check)
void CRainmeter::TestSettingsFile(bool bDefaultIniLocation)
{
WritePrivateProfileString(L"Rainmeter", L"WriteTest", L"TRUE", m_IniFile.c_str());
WritePrivateProfileString(NULL, NULL, NULL, m_IniFile.c_str()); // FLUSH
WCHAR tmpSz[5];
bool bSuccess = (GetPrivateProfileString(L"Rainmeter", L"WriteTest", L"", tmpSz, 5, m_IniFile.c_str()) > 0);
if (bSuccess)
{
bSuccess = (wcscmp(L"TRUE", tmpSz) == 0);
WritePrivateProfileString(L"Rainmeter", L"WriteTest", NULL, m_IniFile.c_str());
}
if (!bSuccess)
if (!CSystem::IsFileWritable(m_IniFile.c_str()))
{
std::wstring error = GetString(ID_STR_SETTINGSNOTWRITABLE);

View File

@ -1034,6 +1034,24 @@ ULONGLONG CSystem::GetTickCount64()
}
}
/*
** IsFileWritable
**
** Checks if file is writable.
**
*/
bool CSystem::IsFileWritable(LPCWSTR file)
{
HANDLE hFile = CreateFile(file, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
if (hFile == INVALID_HANDLE_VALUE)
{
return false;
}
CloseHandle(hFile);
return true;
}
/*
** RmLoadLibrary
**

View File

@ -76,6 +76,8 @@ public:
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 bool IsFileWritable(LPCWSTR file);
static HMODULE RmLoadLibrary(LPCWSTR lpLibFileName, DWORD* dwError = NULL, bool ignoreErrors = false);
static void ResetWorkingDirectory();