Moved user config files to personal directory.

git-svn-id: http://yate.null.ro/svn/yate/trunk@859 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
paulc 2006-06-11 16:50:04 +00:00
parent 0e44cd03e9
commit 82ac44663b
5 changed files with 52 additions and 12 deletions

View File

@ -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();
}

View File

@ -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<n; i++) {
@ -531,7 +531,7 @@ void Client::initClient()
}
}
s_history = Engine::configFile("client_history");
s_history = Engine::configFile("client_history",true);
s_history.load();
n = s_history.sections();
for (i=0; i<n; i++) {

View File

@ -22,7 +22,9 @@
#include "yatengine.h"
#include "yateversn.h"
#ifdef _WINDOWS
#include <process.h>
#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 <dirent.h>
#include <dlfcn.h>
#include <sys/wait.h>
typedef void* HMODULE;
#define PATH_SEP "/"
#define CFG_DIR ".yate"
#endif
#include <unistd.h>
@ -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()

View File

@ -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

View File

@ -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();