Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: src/plugin/PluginSettings.cpp

Issue 10836037: Share code for data path retrieval in engine and plugin (Closed)
Patch Set: Fixed issues in previous patch Created June 4, 2013, 10:14 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/plugin/PluginSettings.h ('k') | src/plugin/abp.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"\\" + (LPCWSTR)filename;
Felix Dahlke 2013/06/04 10:18:09 Shouldn't this be filename.c_str()? I'd prefer a C
Wladimir Palant 2013/06/04 10:39:03 It's CString so - no. Changed it into static_cast.
+ return CString(path.c_str());
}
CString CPluginSettings::GetSystemLanguage()
{
CString language;
CString country;
DWORD bufSize = 256;
« no previous file with comments | « src/plugin/PluginSettings.h ('k') | src/plugin/abp.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld