Fixed: SkinPath is read from Rainmeter.ini in portable installations.

This commit is contained in:
Birunthan Mohanathas 2011-05-01 13:29:09 +00:00
parent 3d9fc72776
commit 710bce5ca4

View File

@ -1726,6 +1726,7 @@ int CRainmeter::Initialize(HWND Parent, HINSTANCE Instance, LPCSTR szPath)
if (!c_DummyLitestep) InitalizeLitestep(); if (!c_DummyLitestep) InitalizeLitestep();
bool bDefaultIniLocation = false; bool bDefaultIniLocation = false;
bool bPortableInstallation = false;
if (c_CmdLine.empty()) if (c_CmdLine.empty())
{ {
@ -1745,6 +1746,10 @@ int CRainmeter::Initialize(HWND Parent, HINSTANCE Instance, LPCSTR szPath)
CreateDefaultConfigFile(m_IniFile); CreateDefaultConfigFile(m_IniFile);
} }
} }
else
{
bPortableInstallation = true;
}
} }
else else
{ {
@ -1819,56 +1824,59 @@ int CRainmeter::Initialize(HWND Parent, HINSTANCE Instance, LPCSTR szPath)
m_SkinPath += L"Skins\\"; m_SkinPath += L"Skins\\";
// Read the skin folder from the ini file // Read the skin folder from the ini file
tmpSzPath[0] = L'\0'; if (!bPortableInstallation)
if (GetPrivateProfileString(L"Rainmeter", L"SkinPath", L"", tmpSzPath, MAX_LINE_LENGTH, m_IniFile.c_str()) > 0)
{ {
m_SkinPath = tmpSzPath;
ExpandEnvironmentVariables(m_SkinPath);
if (!m_SkinPath.empty())
{
WCHAR ch = m_SkinPath[m_SkinPath.size() - 1];
if (ch != L'\\' && ch != L'/')
{
m_SkinPath += L"\\";
}
}
}
else if (bDefaultIniLocation)
{
// If the skin path is not defined in the Rainmeter.ini file use My Documents/Rainmeter/Skins
tmpSzPath[0] = L'\0'; tmpSzPath[0] = L'\0';
HRESULT hr = SHGetFolderPath(NULL, CSIDL_MYDOCUMENTS, NULL, SHGFP_TYPE_CURRENT, tmpSzPath); if (GetPrivateProfileString(L"Rainmeter", L"SkinPath", L"", tmpSzPath, MAX_LINE_LENGTH, m_IniFile.c_str()) > 0)
if (SUCCEEDED(hr))
{ {
// Make the folders if they don't exist yet
m_SkinPath = tmpSzPath; m_SkinPath = tmpSzPath;
m_SkinPath += L"\\Rainmeter"; ExpandEnvironmentVariables(m_SkinPath);
CreateDirectory(m_SkinPath.c_str(), NULL);
m_SkinPath += L"\\Skins\\"; if (!m_SkinPath.empty())
DWORD result = CreateDirectory(m_SkinPath.c_str(), NULL);
if (result != 0)
{ {
// The folder was created successfully which means that it wasn't available yet. WCHAR ch = m_SkinPath[m_SkinPath.size() - 1];
// Copy the default skin to the Skins folder if (ch != L'\\' && ch != L'/')
std::wstring strFrom(m_Path + L"Skins\\*.*"); {
std::wstring strTo(m_SkinPath); m_SkinPath += L"\\";
CSystem::CopyFiles(strFrom, strTo); }
// This shouldn't be copied
std::wstring strNote = strTo + L"Read me before copying skins here.txt";
CSystem::RemoveFile(strNote);
// Copy also the themes to the %APPDATA%
strFrom = std::wstring(m_Path + L"Themes\\*.*");
strTo = std::wstring(GetSettingsPath() + L"Themes\\");
CreateDirectory(strTo.c_str(), NULL);
CSystem::CopyFiles(strFrom, strTo);
} }
} }
else else if (bDefaultIniLocation)
{ {
Log(LOG_WARNING, L"Unable to get the My Documents location."); // If the skin path is not defined in the Rainmeter.ini file use My Documents/Rainmeter/Skins
tmpSzPath[0] = L'\0';
HRESULT hr = SHGetFolderPath(NULL, CSIDL_MYDOCUMENTS, NULL, SHGFP_TYPE_CURRENT, tmpSzPath);
if (SUCCEEDED(hr))
{
// Make the folders if they don't exist yet
m_SkinPath = tmpSzPath;
m_SkinPath += L"\\Rainmeter";
CreateDirectory(m_SkinPath.c_str(), NULL);
m_SkinPath += L"\\Skins\\";
DWORD result = CreateDirectory(m_SkinPath.c_str(), NULL);
if (result != 0)
{
// The folder was created successfully which means that it wasn't available yet.
// Copy the default skin to the Skins folder
std::wstring strFrom(m_Path + L"Skins\\*.*");
std::wstring strTo(m_SkinPath);
CSystem::CopyFiles(strFrom, strTo);
// This shouldn't be copied
std::wstring strNote = strTo + L"Read me before copying skins here.txt";
CSystem::RemoveFile(strNote);
// Copy also the themes to the %APPDATA%
strFrom = std::wstring(m_Path + L"Themes\\*.*");
strTo = std::wstring(GetSettingsPath() + L"Themes\\");
CreateDirectory(strTo.c_str(), NULL);
CSystem::CopyFiles(strFrom, strTo);
}
}
else
{
Log(LOG_WARNING, L"Unable to get the My Documents location.");
}
} }
} }
WritePrivateProfileString(L"Rainmeter", L"SkinPath", m_SkinPath.c_str(), m_IniFile.c_str()); WritePrivateProfileString(L"Rainmeter", L"SkinPath", m_SkinPath.c_str(), m_IniFile.c_str());