From: Herman B. <her...@us...> - 2003-09-15 21:30:41
|
Update of /cvsroot/gaim/gaim/src/win32 In directory sc8-pr-cvs1:/tmp/cvs-serv6513/src/win32 Modified Files: win32dep.c win32dep.h Log Message: Using SHGetFolderPath to determine windows gaim home directory Index: win32dep.c =================================================================== RCS file: /cvsroot/gaim/gaim/src/win32/win32dep.c,v retrieving revision 1.30 retrieving revision 1.31 diff -u -d -p -r1.30 -r1.31 --- win32dep.c 12 Sep 2003 19:04:52 -0000 1.30 +++ win32dep.c 15 Sep 2003 21:30:37 -0000 1.31 @@ -60,6 +60,7 @@ typedef struct _WGAIM_FLASH_INFO WGAIM_F /* * LOCALS */ +static char app_data_dir[MAX_PATH]; static char install_dir[MAXPATHLEN]; static char lib_dir[MAXPATHLEN]; static char locale_dir[MAXPATHLEN]; @@ -75,6 +76,8 @@ HINSTANCE gaimdll_hInstance = 0; * PROTOS */ BOOL (*MyFlashWindowEx)(PFLASHWINFO pfwi)=NULL; +HRESULT (*SHGetFolderPath)(HWND, int, HANDLE, DWORD, LPTSTR) = NULL; + FARPROC wgaim_find_and_loadproc(char*, char*); extern void wgaim_gtkspell_init(); @@ -208,6 +211,10 @@ char* wgaim_locale_dir(void) { return (char*)&locale_dir; } +char* wgaim_data_dir(void) { + return (char*)&app_data_dir; +} + /* Miscellaneous */ gboolean wgaim_read_reg_string(HKEY key, char* sub_key, char* val_name, LPBYTE data, LPDWORD data_len) { @@ -411,6 +418,12 @@ void wgaim_set_locale() { } /* Windows Initializations */ +typedef enum { + SHGFP_TYPE_CURRENT = 0, // current value for user, verify it exists + SHGFP_TYPE_DEFAULT = 1, // default value, may not exist +} SHGFP_TYPE; + +#define CSIDL_APPDATA 0x001a void wgaim_pre_plugin_init(void) { char *perlenv, *newenv; @@ -425,6 +438,42 @@ void wgaim_pre_plugin_init(void) { if(putenv(newenv)<0) gaim_debug(GAIM_DEBUG_WARNING, "wgaim", "putenv failed\n"); g_free(newenv); + + /* Set app data dir, where to save Gaim user settings */ + newenv = (char*)g_getenv("HOME"); + if(!newenv) { + SHGetFolderPath = (void*)wgaim_find_and_loadproc("shfolder.dll", "SHGetFolderPathA"); + if(SHGetFolderPath) { + HRESULT hrResult = SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, app_data_dir); + if(hrResult != S_FALSE && hrResult != E_FAIL && hrResult != E_INVALIDARG) { + gaim_debug(GAIM_DEBUG_INFO, "wgaim", "APP DATA PATH set to: %s\n", app_data_dir); + } + else + strcpy(app_data_dir, "C:"); + } + + /* As of 0.69, using SHGetFolderPath to determine app settings directory. + Move app settings to new location if need be. */ + { + char *old_home = g_strdup_printf("%s%s", g_get_home_dir() ? g_get_home_dir() : "C:", "\\.gaim"); + char *new_home = g_strdup_printf("%s\\.gaim", wgaim_data_dir()); + GDir *dir_old, *dir_new; + + dir_old = g_dir_open(old_home, 0, NULL); + dir_new = g_dir_open(new_home, 0, NULL); + if(dir_old && !dir_new) { + if(MoveFile(old_home, new_home) != 0) + gaim_debug(GAIM_DEBUG_INFO, "wgaim", "Success moving '.gaim' directory\n"); + } + g_free(new_home); + g_free(old_home); + g_dir_close(dir_old); + g_dir_close(dir_new); + } + } + else { + strcpy(app_data_dir, newenv); + } } void wgaim_init(void) { Index: win32dep.h =================================================================== RCS file: /cvsroot/gaim/gaim/src/win32/win32dep.h,v retrieving revision 1.21 retrieving revision 1.22 diff -u -d -p -r1.21 -r1.22 --- win32dep.h 12 Sep 2003 19:04:52 -0000 1.21 +++ win32dep.h 15 Sep 2003 21:30:37 -0000 1.22 @@ -44,6 +44,7 @@ gboolean wgaim_read_reg_string(HKEY key, extern char* wgaim_install_dir(void); extern char* wgaim_lib_dir(void); extern char* wgaim_locale_dir(void); +extern char* wgaim_data_dir(void); extern char* wgaim_escape_dirsep(char*); /* UI related */ extern void wgaim_im_blink(GtkWidget*); |