From 82ac44663bac6983aad7eb440c1459859c1e3e70 Mon Sep 17 00:00:00 2001 From: paulc Date: Sun, 11 Jun 2006 16:50:04 +0000 Subject: [PATCH] Moved user config files to personal directory. git-svn-id: http://yate.null.ro/svn/yate/trunk@859 acf43c95-373e-0410-b603-e72c3f656dc1 --- contrib/gtk2/gtk2client.cpp | 2 +- engine/Client.cpp | 6 +++--- engine/Engine.cpp | 36 ++++++++++++++++++++++++++++++++++-- yateclass.h | 1 + yatengine.h | 19 +++++++++++++------ 5 files changed, 52 insertions(+), 12 deletions(-) diff --git a/contrib/gtk2/gtk2client.cpp b/contrib/gtk2/gtk2client.cpp index 5ba7c96d..e7342864 100644 --- a/contrib/gtk2/gtk2client.cpp +++ b/contrib/gtk2/gtk2client.cpp @@ -1982,7 +1982,7 @@ GTKClient::GTKClient() s_skinPath << Engine::pathSeparator(); s_cfg = s_skinPath + "gtk2client.ui"; s_cfg.load(); - s_save = Engine::configFile("gtk2client"); + s_save = Engine::configFile("gtk2client",true); s_save.load(); } diff --git a/engine/Client.cpp b/engine/Client.cpp index 5f0dd0f7..ae7e4931 100644 --- a/engine/Client.cpp +++ b/engine/Client.cpp @@ -487,7 +487,7 @@ void Client::initWindows() void Client::initClient() { - s_accounts = Engine::configFile("client_accounts"); + s_accounts = Engine::configFile("client_accounts",true); s_accounts.load(); unsigned int n = s_accounts.sections(); unsigned int i; @@ -509,7 +509,7 @@ void Client::initClient() } } - s_contacts = Engine::configFile("client_contacts"); + s_contacts = Engine::configFile("client_contacts",true); s_contacts.load(); n = s_contacts.sections(); for (i=0; i #define RTLD_NOW 0 #define dlopen(name,flags) LoadLibrary(name) @@ -32,13 +34,22 @@ #define YSERV_INS 2 #define YSERV_DEL 4 #define PATH_SEP "\\" +#define CFG_DIR "Yate" + +#ifndef SHGetSpecialFolderPath +__declspec(dllimport) BOOL WINAPI SHGetSpecialFolderPathA(HWND,LPSTR,INT,BOOL); +#endif + #else + #include "yatepaths.h" #include #include #include typedef void* HMODULE; #define PATH_SEP "/" +#define CFG_DIR ".yate" + #endif #include @@ -638,9 +649,30 @@ const char* Engine::pathSeparator() return PATH_SEP; } -String Engine::configFile(const char* name) +String Engine::configFile(const char* name, bool user) { - return s_cfgpath + PATH_SEP + name + s_cfgsuffix; + String path; + if (user) { +#ifdef _WINDOWS + // we force using the ANSI version + char szPath[MAX_PATH]; + if (SHGetSpecialFolderPathA(NULL,szPath,CSIDL_APPDATA,TRUE)) + path = szPath; +#else + path = ::getenv("HOME"); +#endif + } + if (path.null()) + path = s_cfgpath; + else { + if (!path.endsWith(PATH_SEP)) + path += PATH_SEP; + path += CFG_DIR; + ::mkdir(path,S_IRWXU); + } + if (!path.endsWith(PATH_SEP)) + path += PATH_SEP; + return path + name + s_cfgsuffix; } const Configuration& Engine::config() diff --git a/yateclass.h b/yateclass.h index a6d8f5d7..9fd07199 100644 --- a/yateclass.h +++ b/yateclass.h @@ -94,6 +94,7 @@ typedef unsigned long in_addr_t; #define close _close #define getpid _getpid #define chdir _chdir +#define mkdir(p,m) _mkdir(p) #define unlink _unlink #define O_RDWR _O_RDWR diff --git a/yatengine.h b/yatengine.h index 9f6b4da3..5b937840 100644 --- a/yatengine.h +++ b/yatengine.h @@ -732,18 +732,23 @@ public: static bool Register(const Plugin* plugin, bool reg = true); /** - * The configuration directory path + * Get the filename for a specific configuration + * @param name Name of the configuration requested + * @param user True to build a user settings path + * @return A full path configuration file name */ - static String configFile(const char* name); + static String configFile(const char* name, bool user = false); /** - * The configuration directory path + * Get the system configuration directory path + * @return The directory path for system configuration files */ inline static String& configPath() { return s_cfgpath; } /** - * The configuration file suffix + * Get the configuration file suffix + * @return The suffix for configuration files */ inline static String& configSuffix() { return s_cfgsuffix; } @@ -762,13 +767,15 @@ public: { return s_extramod; } /** - * The module suffix + * Get the module filename suffix + * @return The suffix for module files */ inline static String& moduleSuffix() { return s_modsuffix; } /** - * The operating system specific path element separator + * Get the canonical path element separator for the operating system + * @return The operating system specific path element separator */ static const char* pathSeparator();