Index: src/plugin/PluginSettings.cpp |
=================================================================== |
--- a/src/plugin/PluginSettings.cpp |
+++ b/src/plugin/PluginSettings.cpp |
@@ -9,16 +9,17 @@ |
#include "PluginClient.h" |
#include "PluginChecksum.h" |
#include "PluginSystem.h" |
#ifdef SUPPORT_FILTER |
#include "PluginFilter.h" |
#endif |
#include "PluginMutex.h" |
#include "PluginHttpRequest.h" |
+#include "../shared/Utils.h" |
#include <memory> |
// IE functions |
#pragma comment(lib, "iepmapi.lib") |
#include <knownfolders.h> |
@@ -52,19 +53,16 @@ class CPluginSettingsWhitelistLock : pub |
{ |
public: |
CPluginSettingsWhitelistLock() : CPluginMutex("SettingsFileWhitelist", PLUGIN_ERROR_MUTEX_SETTINGS_FILE_WHITELIST) {} |
~CPluginSettingsWhitelistLock() {} |
}; |
#endif |
-WCHAR* CPluginSettings::s_dataPath; |
-WCHAR* CPluginSettings::s_dataPathParent; |
- |
CPluginSettings* CPluginSettings::s_instance = NULL; |
bool CPluginSettings::s_isLightOnly = false; |
CComAutoCriticalSection CPluginSettings::s_criticalSectionLocal; |
#ifdef SUPPORT_WHITELIST |
CComAutoCriticalSection CPluginSettings::s_criticalSectionDomainHistory; |
#endif |
@@ -144,21 +142,16 @@ CPluginSettings::CPluginSettings() : |
this->SetWorkingThreadId(lightInstance->m_dwWorkingThreadId); |
} |
Write(); |
} |
CPluginSettings::~CPluginSettings() |
{ |
- |
- if (s_dataPathParent != NULL) |
- { |
- delete s_dataPathParent; |
- } |
s_instance = NULL; |
} |
CPluginSettings* CPluginSettings::GetInstance() |
{ |
CPluginSettings* instance = NULL; |
@@ -311,120 +304,20 @@ bool CPluginSettings::MakeRequestForUpda |
m_isDirty = true; |
DEBUG_SETTINGS("Settings::Configuration plugin update version:" + it->second); |
} |
} |
return true; |
} |
-CString CPluginSettings::GetDataPathParent() |
-{ |
- if (s_dataPathParent == NULL) |
- { |
- WCHAR* lpData = new WCHAR[MAX_PATH]; |
- |
- OSVERSIONINFO osVersionInfo; |
- ::ZeroMemory(&osVersionInfo, sizeof(OSVERSIONINFO)); |
- |
- osVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); |
- |
- ::GetVersionEx(&osVersionInfo); |
- |
- //Windows Vista - 6.0 |
- //Windows Server 2003 R2 - 5.2 |
- //Windows Server 2003 - 5.2 |
- //Windows XP - 5.1 |
- if (osVersionInfo.dwMajorVersion >= 6) |
- { |
- if (::SHGetSpecialFolderPath(NULL, lpData, CSIDL_LOCAL_APPDATA, TRUE)) |
- { |
- wcscat(lpData, L"Low"); |
- } |
- else |
- { |
- DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_SYSINFO, PLUGIN_ERROR_SYSINFO_GET_SPECIAL_FOLDER_LOCAL, "Settings::GetDataPath failed"); |
- } |
- } |
- else |
- { |
- if (!SHGetSpecialFolderPath(NULL, lpData, CSIDL_APPDATA, TRUE)) |
- { |
- DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_SYSINFO, PLUGIN_ERROR_SYSINFO_GET_SPECIAL_FOLDER, "Settings::GetDataPath failed"); |
- } |
- } |
- |
- ::PathAddBackslash(lpData); |
- |
- s_dataPathParent = lpData; |
- |
- if (!::CreateDirectory(s_dataPathParent, NULL)) |
- { |
- DWORD errorCode = ::GetLastError(); |
- if (errorCode != ERROR_ALREADY_EXISTS) |
- { |
- DEBUG_ERROR_LOG(errorCode, PLUGIN_ERROR_SETTINGS, PLUGIN_ERROR_SETTINGS_CREATE_FOLDER, "Settings::CreateDirectory failed"); |
- } |
- } |
- } |
- |
- return s_dataPathParent; |
-} |
- |
CString CPluginSettings::GetDataPath(const CString& filename) |
{ |
- if (s_dataPath == NULL) |
- { |
- WCHAR* lpData = new WCHAR[MAX_PATH]; |
- |
- OSVERSIONINFO osVersionInfo; |
- ::ZeroMemory(&osVersionInfo, sizeof(OSVERSIONINFO)); |
- |
- osVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); |
- |
- ::GetVersionEx(&osVersionInfo); |
- |
- //Windows Vista - 6.0 |
- //Windows Server 2003 R2 - 5.2 |
- //Windows Server 2003 - 5.2 |
- //Windows XP - 5.1 |
- if (osVersionInfo.dwMajorVersion >= 6) |
- { |
- if (::SHGetSpecialFolderPath(NULL, lpData, CSIDL_LOCAL_APPDATA, TRUE)) |
- { |
- wcscat(lpData, L"Low"); |
- } |
- else |
- { |
- DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_SYSINFO, PLUGIN_ERROR_SYSINFO_GET_SPECIAL_FOLDER_LOCAL, "Settings::GetDataPath failed"); |
- } |
- } |
- else |
- { |
- if (!SHGetSpecialFolderPath(NULL, lpData, CSIDL_APPDATA, TRUE)) |
- { |
- DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_SYSINFO, PLUGIN_ERROR_SYSINFO_GET_SPECIAL_FOLDER, "Settings::GetDataPath failed"); |
- } |
- } |
- |
- ::PathAddBackslash(lpData); |
- |
- s_dataPath = lpData; |
- |
- if (!::CreateDirectory(s_dataPath + CString(USER_DIR), NULL)) |
- { |
- DWORD errorCode = ::GetLastError(); |
- if (errorCode != ERROR_ALREADY_EXISTS) |
- { |
- DEBUG_ERROR_LOG(errorCode, PLUGIN_ERROR_SETTINGS, PLUGIN_ERROR_SETTINGS_CREATE_FOLDER, "Settings::CreateDirectory failed"); |
- } |
- } |
- } |
- |
- return s_dataPath + CString(USER_DIR) + filename; |
+ std::wstring path = ::GetAppDataPath() + L"\\" + static_cast<LPCWSTR>(filename); |
+ return CString(path.c_str()); |
} |
CString CPluginSettings::GetSystemLanguage() |
{ |
CString language; |
CString country; |
DWORD bufSize = 256; |