Developer forums (C::B DEVELOPMENT STRICTLY!) > Development
New switch --user-config
dmoore:
New patch. This version does a simple check for the existence of the user-data-dir, creates if not, and errors out if that doesn't work.
I haven't yet made the protected members public and removed the friend class, but that's trivial if that's what we want to do.
dmoore:
--- Quote from: oBFusCATed on January 21, 2014, 10:14:48 pm ---I think you need to have it forward declared.
--- End quote ---
That's what I did, right? (In ConfigManager.h)
osdt:
--- Quote from: dmoore on January 21, 2014, 10:16:38 pm ---New patch. This version does a simple check for the existence of the user-data-dir, creates if not, and errors out if that doesn't work. ...
--- End quote ---
The patch doesn't work on Windows because of GetPortableConfigDir(). It is called 3 times and would always return $APPDATA/CodeBlocks on most Systems.
The patch below (on top of yours) works on Windows and Linux.
--- Code: ---diff --git src/sdk/configmanager.cpp src/sdk/configmanager.cpp
index 4f569a6..b7a30ac 100644
--- src/sdk/configmanager.cpp
+++ src/sdk/configmanager.cpp
@@ -68,18 +68,6 @@ wxString ConfigManager::temp_folder;
bool ConfigManager::relo = 0;
-
-#ifdef __WINDOWS__
-inline wxString GetPortableConfigDir()
-{
- TCHAR buffer[MAX_PATH];
- if (::GetEnvironmentVariable(_T("APPDATA"), buffer, MAX_PATH))
- return wxString::Format(_T("%s\\CodeBlocks"), buffer);
- else
- return ConfigManager::GetUserDataFolder();
-}
-#endif
-
namespace CfgMgrConsts
{
const wxString app_path(_T("app_path"));
@@ -196,11 +184,8 @@ CfgMgrBldr::CfgMgrBldr() : doc(nullptr), volatile_doc(nullptr), r(false)
if (cfg.IsEmpty())
{
- #ifdef __WINDOWS__
- cfg = GetPortableConfigDir() + wxFILE_SEP_PATH + personality + _T(".conf");
- #else
cfg = ConfigManager::GetUserDataFolder() + wxFILE_SEP_PATH + personality + _T(".conf");
- #endif
+
doc = new TiXmlDocument();
doc->InsertEndChild(TiXmlDeclaration("1.0", "UTF-8", "yes"));
doc->InsertEndChild(TiXmlElement("CodeBlocksConfig"));
@@ -215,11 +200,7 @@ wxString CfgMgrBldr::FindConfigFile(const wxString& filename)
{
wxPathList searchPaths;
-#ifdef __WINDOWS__
- wxString u(GetPortableConfigDir() + wxFILE_SEP_PATH + filename);
-#else
wxString u(ConfigManager::GetUserDataFolder() + wxFILE_SEP_PATH + filename);
-#endif
wxString e(::DetermineExecutablePath() + wxFILE_SEP_PATH + filename);
if (::wxFileExists(e))
@@ -560,6 +541,11 @@ inline wxString ConfigManager::GetUserDataFolder()
{
if (has_alternate_user_data_path)
return alternate_user_data_path;
+#ifdef __WXMSW__
+ TCHAR buffer[MAX_PATH];
+ if (::GetEnvironmentVariable(_T("APPDATA"), buffer, MAX_PATH))
+ return wxString::Format(_T("%s\\CodeBlocks"), buffer);
+#endif
return wxStandardPathsBase::Get().GetUserDataDir();
}
@@ -1462,11 +1448,7 @@ void ConfigManager::Write(const wxString& name, const ConfigManagerContainer::Se
void ConfigManager::InitPaths()
{
-#ifdef __WINDOWS__
- ConfigManager::config_folder = GetPortableConfigDir();
-#else
ConfigManager::config_folder = ConfigManager::GetUserDataFolder();
-#endif
ConfigManager::home_folder = wxStandardPathsBase::Get().GetUserConfigDir();
ConfigManager::app_path = ::DetermineExecutablePath();
wxString res_path = ::DetermineResourcesPath();
--- End code ---
Also as attachment.
Would be nice to see this new option in trunk.
- osdt
[attachment deleted by admin]
dmoore:
--- Quote from: osdt on January 22, 2014, 12:38:43 am ---
--- Quote from: dmoore on January 21, 2014, 10:16:38 pm ---New patch. This version does a simple check for the existence of the user-data-dir, creates if not, and errors out if that doesn't work. ...
--- End quote ---
The patch doesn't work on Windows because of GetPortableConfigDir(). It is called 3 times and would always return $APPDATA/CodeBlocks on most Systems.
--- End quote ---
I forgot that there was this issue to deal with as well. Thanks for testing and the patch. However, I think we want to preserve existing behavior of allowing the user to set APPDATA on windows (even though that might have weird interactions with other apps spawned by C::B), which I think is as simple as the following one liner:
--- Code: ---Index: src/sdk/configmanager.cpp
===================================================================
--- src/sdk/configmanager.cpp (revision 9594)
+++ src/sdk/configmanager.cpp (working copy)
@@ -68,10 +71,10 @@
inline wxString GetPortableConfigDir()
{
TCHAR buffer[MAX_PATH];
- if (::GetEnvironmentVariable(_T("APPDATA"), buffer, MAX_PATH))
+ if (!ConfigManager::has_alternate_user_data_path && ::GetEnvironmentVariable(_T("APPDATA"), buffer, MAX_PATH))
return wxString::Format(_T("%s\\CodeBlocks"), buffer);
else
--- End code ---
I also forgot to override the check for default.conf in the executable directory (I think it makes sense to obey the switch if it is specified). See the second change in this part of the patch.
--- Code: ---Index: src/sdk/configmanager.cpp
===================================================================
--- src/sdk/configmanager.cpp (revision 9594)
+++ src/sdk/configmanager.cpp (working copy)
@@ -213,11 +218,11 @@
#ifdef __WINDOWS__
wxString u(GetPortableConfigDir() + wxFILE_SEP_PATH + filename);
#else
- wxString u(wxStandardPathsBase::Get().GetUserDataDir() + wxFILE_SEP_PATH + filename);
+ wxString u(ConfigManager::GetUserDataFolder() + wxFILE_SEP_PATH + filename);
#endif
wxString e(::DetermineExecutablePath() + wxFILE_SEP_PATH + filename);
- if (::wxFileExists(e))
+ if (!ConfigManager::has_alternate_user_data_path && ::wxFileExists(e))
{
ConfigManager::relo = true;
return e;
--- End code ---
Revised complete patch is attached
dmoore:
--- Quote from: osdt on January 22, 2014, 12:38:43 am ---Would be nice to see this new option in trunk.
--- End quote ---
I think this patch is pretty close. One of the other devs should weigh in re oBFusCATed's concerns and on the change in general.
One last thing: what if the user specifies a relative path?
--- Code: ---codeblocks --user-data-dir=xyz
--- End code ---
Currently I think it will just return with error on all systems. Alternatively it could generate a directory relative to the (a) current working directory, or (b) the executable directory. Not clear either is all that useful.
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version