1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-25 17:17:31 +00:00

Tune directory paths on Windows

Use %USERPROFILE% instead of %USERPROFILE%\Documents as home directory.
Don't roam configuration directory (I don't think we want that).
Use known Downloads folder (instead of %HOME%\Downloads) if set.
When searching for web interface files, let local user application data
directory override roaming one, and roaming one override common one.
Use Vista+ API (SHGetKnownFolderPath) to get known folder paths.
This commit is contained in:
Mike Gelfand 2015-04-10 22:15:41 +00:00
parent f1f2a8f0b7
commit 99e0f5bd63

View file

@ -23,7 +23,7 @@
#ifdef _WIN32 #ifdef _WIN32
#include <process.h> /* _beginthreadex (), _endthreadex () */ #include <process.h> /* _beginthreadex (), _endthreadex () */
#include <windows.h> #include <windows.h>
#include <shlobj.h> /* for CSIDL_APPDATA, CSIDL_MYDOCUMENTS */ #include <shlobj.h> /* SHGetKnownFolderPath (), FOLDERID_... */
#else #else
#include <unistd.h> /* getuid() */ #include <unistd.h> /* getuid() */
#ifdef BUILD_MAC_CLIENT #ifdef BUILD_MAC_CLIENT
@ -225,12 +225,19 @@ tr_lockUnlock (tr_lock * l)
#ifdef _WIN32 #ifdef _WIN32
static char * static char *
win32_get_special_folder (int folder_id) win32_get_known_folder (REFKNOWNFOLDERID folder_id)
{ {
wchar_t path[MAX_PATH]; /* SHGetFolderPath () requires MAX_PATH */ char * ret = NULL;
*path = L'\0'; PWSTR path;
SHGetFolderPathW (NULL, folder_id, NULL, 0, path);
return tr_win32_native_to_utf8 (path, -1); if (SHGetKnownFolderPath (folder_id, KF_FLAG_DONT_UNEXPAND | KF_FLAG_DONT_VERIFY,
NULL, &path) == S_OK)
{
ret = tr_win32_native_to_utf8 (path, -1);
CoTaskMemFree (path);
}
return ret;
} }
#endif #endif
@ -247,7 +254,7 @@ getHomeDir (void)
if (!home) if (!home)
{ {
#ifdef _WIN32 #ifdef _WIN32
home = win32_get_special_folder (CSIDL_PERSONAL); home = win32_get_known_folder (&FOLDERID_Profile);
#else #else
struct passwd * pw = getpwuid (getuid ()); struct passwd * pw = getpwuid (getuid ());
if (pw) if (pw)
@ -322,7 +329,7 @@ tr_getDefaultConfigDir (const char * appname)
#ifdef __APPLE__ #ifdef __APPLE__
s = tr_buildPath (getHomeDir (), "Library", "Application Support", appname, NULL); s = tr_buildPath (getHomeDir (), "Library", "Application Support", appname, NULL);
#elif defined (_WIN32) #elif defined (_WIN32)
char * appdata = win32_get_special_folder (CSIDL_APPDATA); char * appdata = win32_get_known_folder (&FOLDERID_LocalAppData);
s = tr_buildPath (appdata, appname, NULL); s = tr_buildPath (appdata, appname, NULL);
tr_free (appdata); tr_free (appdata);
#elif defined (__HAIKU__) #elif defined (__HAIKU__)
@ -392,6 +399,11 @@ tr_getDefaultDownloadDir (void)
} }
} }
#ifdef _WIN32
if (user_dir == NULL)
user_dir = win32_get_known_folder (&FOLDERID_Downloads);
#endif
if (user_dir == NULL) if (user_dir == NULL)
#ifdef __HAIKU__ #ifdef __HAIKU__
user_dir = tr_buildPath (getHomeDir (), "Desktop", NULL); user_dir = tr_buildPath (getHomeDir (), "Desktop", NULL);
@ -471,21 +483,16 @@ tr_getWebClientDir (const tr_session * session UNUSED)
/* Generally, Web interface should be stored in a Web subdir of /* Generally, Web interface should be stored in a Web subdir of
* calling executable dir. */ * calling executable dir. */
if (s == NULL) /* check personal AppData/Transmission/Web */ static REFKNOWNFOLDERID known_folder_ids[] =
{ {
char * dir = win32_get_special_folder (CSIDL_COMMON_APPDATA); &FOLDERID_LocalAppData,
s = tr_buildPath (dir, "Transmission", "Web", NULL); &FOLDERID_RoamingAppData,
tr_free (dir); &FOLDERID_ProgramData
if (!isWebClientDir (s)) };
{
tr_free (s);
s = NULL;
}
}
if (s == NULL) /* check personal AppData */ for (size_t i = 0; s == NULL && i < ARRAYSIZE (known_folder_ids); ++i)
{ {
char * dir = win32_get_special_folder (CSIDL_APPDATA); char * dir = win32_get_known_folder (known_folder_ids[i]);
s = tr_buildPath (dir, "Transmission", "Web", NULL); s = tr_buildPath (dir, "Transmission", "Web", NULL);
tr_free (dir); tr_free (dir);
if (!isWebClientDir (s)) if (!isWebClientDir (s))