pidgin/win32/winpidgin.c

changeset 39079
f77c547e07c6
parent 39078
bbaab5d6a8d5
child 39081
e84ed81142f8
equal deleted inserted replaced
39078:bbaab5d6a8d5 39079:f77c547e07c6
39 typedef int (__cdecl* LPFNPIDGINMAIN)(HINSTANCE, int, char**); 39 typedef int (__cdecl* LPFNPIDGINMAIN)(HINSTANCE, int, char**);
40 typedef BOOL (WINAPI* LPFNSETDLLDIRECTORY)(LPCWSTR); 40 typedef BOOL (WINAPI* LPFNSETDLLDIRECTORY)(LPCWSTR);
41 typedef BOOL (WINAPI* LPFNATTACHCONSOLE)(DWORD); 41 typedef BOOL (WINAPI* LPFNATTACHCONSOLE)(DWORD);
42 typedef BOOL (WINAPI* LPFNSETPROCESSDEPPOLICY)(DWORD); 42 typedef BOOL (WINAPI* LPFNSETPROCESSDEPPOLICY)(DWORD);
43 43
44 static BOOL portable_mode = FALSE;
45
46 /* 44 /*
47 * PROTOTYPES 45 * PROTOTYPES
48 */ 46 */
49 static LPFNPIDGINMAIN pidgin_main = NULL; 47 static LPFNPIDGINMAIN pidgin_main = NULL;
50 48
56 NULL, err, 54 NULL, err,
57 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), 55 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
58 (LPWSTR) &err_msg, sizeof(err_msg) / sizeof(wchar_t), NULL); 56 (LPWSTR) &err_msg, sizeof(err_msg) / sizeof(wchar_t), NULL);
59 57
60 return err_msg; 58 return err_msg;
61 }
62
63 static void portable_mode_dll_prep(const wchar_t *pidgin_dir) {
64 /* need to be able to fit MAX_PATH + "PURPLEHOME=" in path2 */
65 wchar_t path[MAX_PATH + 1];
66 wchar_t path2[MAX_PATH + 12];
67 const wchar_t *prev = NULL;
68
69 /* We want settings to go into \\path\to\Pidgin\'s parent directory
70 * First we find \\path\to
71 */
72 if (*pidgin_dir)
73 /* pidgin_dir points to \\path\to\Pidgin */
74 prev = wcsrchr(pidgin_dir, L'\\');
75
76 if (prev) {
77 int cnt = (prev - pidgin_dir);
78 wcsncpy(path, pidgin_dir, cnt);
79 path[cnt] = L'\0';
80 } else {
81 printf("Unable to determine current executable path. \n"
82 "This will prevent the settings dir from being set.\n");
83 return;
84 }
85
86 /* Set $HOME so that the GTK+ settings get stored in the right place */
87 _snwprintf(path2, sizeof(path2) / sizeof(wchar_t), L"HOME=%s", path);
88 _wputenv(path2);
89
90 /* Set up the settings dir base to be \\path\to
91 * The actual settings dir will be \\path\to\.purple */
92 _snwprintf(path2, sizeof(path2) / sizeof(wchar_t), L"PURPLEHOME=%s", path);
93 wprintf(L"Setting settings dir: %s\n", path2);
94 _wputenv(path2);
95 } 59 }
96 60
97 #define PIDGIN_WM_FOCUS_REQUEST (WM_APP + 13) 61 #define PIDGIN_WM_FOCUS_REQUEST (WM_APP + 13)
98 #define PIDGIN_WM_PROTOCOL_HANDLE (WM_APP + 14) 62 #define PIDGIN_WM_PROTOCOL_HANDLE (WM_APP + 14)
99 63
385 wprintf(L"%s\n", errbuf); 349 wprintf(L"%s\n", errbuf);
386 MessageBoxW(NULL, errbuf, NULL, MB_OK | MB_TOPMOST); 350 MessageBoxW(NULL, errbuf, NULL, MB_OK | MB_TOPMOST);
387 pidgin_dir[0] = L'\0'; 351 pidgin_dir[0] = L'\0';
388 } 352 }
389 353
390 /* Determine if we're running in portable mode */
391 if (wcsstr(cmdLine, L"--portable-mode")
392 || (exe_name != NULL && wcsstr(exe_name, L"-portable.exe"))) {
393 printf("Running in PORTABLE mode.\n");
394 portable_mode = TRUE;
395 }
396
397 if (portable_mode)
398 portable_mode_dll_prep(pidgin_dir);
399
400 /* If help, version or multiple flag used, do not check Mutex */ 354 /* If help, version or multiple flag used, do not check Mutex */
401 if (!help && !version) 355 if (!help && !version)
402 if (!winpidgin_set_running(getenv("PIDGIN_MULTI_INST") == NULL && !multiple)) 356 if (!winpidgin_set_running(getenv("PIDGIN_MULTI_INST") == NULL && !multiple))
403 return 0; 357 return 0;
404 358

mercurial