From 2974b2a91e2e7a88ed0107211f839ad876690b6d Mon Sep 17 00:00:00 2001 From: Birunthan Mohanathas Date: Sat, 5 May 2012 14:45:34 +0300 Subject: [PATCH] Added Rainmeter.data --- Library/Export.cpp | 4 +-- Library/Rainmeter.cpp | 73 ++++++++++++++++++++++++++++++++----------- Library/Rainmeter.h | 17 +++++----- 3 files changed, 65 insertions(+), 29 deletions(-) diff --git a/Library/Export.cpp b/Library/Export.cpp index 97230b2a..fd14da40 100644 --- a/Library/Export.cpp +++ b/Library/Export.cpp @@ -76,9 +76,7 @@ void* __stdcall RmGet(void* rm, int type) case RMG_SETTINGSFILE: { - g_Buffer = Rainmeter->GetSettingsPath(); - g_Buffer += L"Plugins.ini"; - return (void*)g_Buffer.c_str(); + return (void*)Rainmeter->GetDataFile().c_str(); } } diff --git a/Library/Rainmeter.cpp b/Library/Rainmeter.cpp index d03b02d2..0241374b 100644 --- a/Library/Rainmeter.cpp +++ b/Library/Rainmeter.cpp @@ -856,27 +856,37 @@ int CRainmeter::Initialize(LPCWSTR szPath) } } - // Set the log file and stats file location - m_LogFile = m_StatsFile = m_IniFile; - size_t len = m_LogFile.length(); - if (len > 4 && _wcsicmp(m_LogFile.c_str() + (len - 4), L".ini") == 0) + const WCHAR* iniFile = m_IniFile.c_str(); + + // Set file locations { - m_LogFile.replace(len - 4, 4, L".log"); - m_StatsFile.replace(len - 4, 4, L".stats"); - } - else - { - m_LogFile += L".log"; // Append the extension so that we don't accidentally overwrite the ini file + size_t len = m_IniFile.length(); + if (len > 4 && _wcsicmp(m_IniFile.c_str() + (len - 4), L".ini") == 0) + { + len -= 4; + } + + m_LogFile.assign(m_IniFile, 0, len); + m_DataFile = m_StatsFile = m_LogFile; + m_LogFile += L".log"; m_StatsFile += L".stats"; + m_DataFile += L".data"; + } + + bool dataFileCreated = false; + if (_waccess(m_DataFile.c_str(), 0) == -1) + { + dataFileCreated = true; + CreateDataFile(); } // Read Logging settings beforehand - m_Logging = 0!=GetPrivateProfileInt(L"Rainmeter", L"Logging", 0, m_IniFile.c_str()); - m_Debug = 0!=GetPrivateProfileInt(L"Rainmeter", L"Debug", 0, m_IniFile.c_str()); + m_Logging = 0!=GetPrivateProfileInt(L"Rainmeter", L"Logging", 0, iniFile); + m_Debug = 0!=GetPrivateProfileInt(L"Rainmeter", L"Debug", 0, iniFile); // Determine the language resource to load std::wstring resource = m_Path + L"Languages\\"; - if (GetPrivateProfileString(L"Rainmeter", L"Language", L"", buffer, MAX_LINE_LENGTH, m_IniFile.c_str()) == 0) + if (GetPrivateProfileString(L"Rainmeter", L"Language", L"", buffer, MAX_LINE_LENGTH, iniFile) == 0) { // Use whatever the user selected for the installer DWORD size = MAX_LINE_LENGTH; @@ -928,7 +938,7 @@ int CRainmeter::Initialize(LPCWSTR szPath) m_SkinPath += L"Skins\\"; // Read the skin folder from the ini file - len = GetPrivateProfileString(L"Rainmeter", L"SkinPath", L"", buffer, MAX_LINE_LENGTH, m_IniFile.c_str()); + size_t len = GetPrivateProfileString(L"Rainmeter", L"SkinPath", L"", buffer, MAX_LINE_LENGTH, iniFile); if (len > 0) { m_SkinPath.assign(buffer, len); @@ -977,14 +987,14 @@ int CRainmeter::Initialize(LPCWSTR szPath) Log(LOG_WARNING, L"Documents folder not found"); } - WritePrivateProfileString(L"Rainmeter", L"SkinPath", m_SkinPath.c_str(), m_IniFile.c_str()); + WritePrivateProfileString(L"Rainmeter", L"SkinPath", m_SkinPath.c_str(), iniFile); } delete [] buffer; buffer = NULL; LogWithArgs(LOG_NOTICE, L"Path: %s", m_Path.c_str()); - LogWithArgs(LOG_NOTICE, L"IniFile: %s", m_IniFile.c_str()); + LogWithArgs(LOG_NOTICE, L"IniFile: %s", iniFile); LogWithArgs(LOG_NOTICE, L"SkinPath: %s", m_SkinPath.c_str()); // Extract volume path from program path @@ -1033,8 +1043,6 @@ int CRainmeter::Initialize(LPCWSTR szPath) MessageBox(NULL, error.c_str(), APPNAME, MB_OK | MB_TOPMOST | MB_ICONERROR); } - WritePrivateProfileString(L"Rainmeter", L"CheckUpdate", NULL , m_IniFile.c_str()); - ResetStats(); ReadStats(); @@ -1047,7 +1055,11 @@ int CRainmeter::Initialize(LPCWSTR szPath) // Create meter windows for active configs ActivateActiveConfigs(); - if (!m_DisableVersionCheck) + if (dataFileCreated) + { + m_TrayWindow->ShowWelcomeNotification(); + } + else if (!m_DisableVersionCheck) { CheckUpdate(); } @@ -1170,6 +1182,29 @@ void CRainmeter::CreateDefaultConfigFile() } } +void CRainmeter::CreateDataFile() +{ + std::wstring tmpSz = GetSettingsPath(); + tmpSz += L"Plugins.ini"; + + const WCHAR* pluginsFile = tmpSz.c_str(); + const WCHAR* dataFile = m_DataFile.c_str(); + + if (_waccess(pluginsFile, 0) == 0) + { + _wrename(pluginsFile, dataFile); + } + else + { + // Create empty file + HANDLE file = CreateFile(dataFile, GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL); + if (file != INVALID_HANDLE_VALUE) + { + CloseHandle(file); + } + } +} + void CRainmeter::ReloadSettings() { ScanForConfigs(m_SkinPath); diff --git a/Library/Rainmeter.h b/Library/Rainmeter.h index babcfb83..1f72f20a 100644 --- a/Library/Rainmeter.h +++ b/Library/Rainmeter.h @@ -151,6 +151,7 @@ public: const std::wstring& GetPath() { return m_Path; } const std::wstring& GetIniFile() { return m_IniFile; } + const std::wstring& GetDataFile() { return m_DataFile; } const std::wstring& GetLogFile() { return m_LogFile; } const std::wstring& GetSkinPath() { return m_SkinPath; } const std::wstring& GetPluginPath() { return m_PluginPath; } @@ -263,6 +264,7 @@ private: void CreateThemeMenu(HMENU themeMenu); void CreateMonitorMenu(HMENU monitorMenu, CMeterWindow* meterWindow); void CreateDefaultConfigFile(); + void CreateDataFile(); void SetLogging(bool logging); void TestSettingsFile(bool bDefaultIniLocation); @@ -274,13 +276,14 @@ private: std::map m_MeterWindows; std::vector m_Themes; - std::wstring m_Path; // Path to the main folder - std::wstring m_IniFile; // The main ini file - std::wstring m_StatsFile; // The statistics ini file - std::wstring m_LogFile; // The log file - std::wstring m_SkinPath; // Path to the folder where the skins are - std::wstring m_PluginPath; // Path to the folder where the plugins are - std::wstring m_AddonPath; // Path to the folder where the addons are + std::wstring m_Path; + std::wstring m_IniFile; + std::wstring m_DataFile; + std::wstring m_StatsFile; + std::wstring m_LogFile; + std::wstring m_SkinPath; + std::wstring m_PluginPath; + std::wstring m_AddonPath; std::wstring m_Drive;