Changeset 14490


Ignore:
Timestamp:
Apr 10, 2015, 10:15:41 PM (6 years ago)
Author:
mikedld
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/platform.c

    r14488 r14490  
    2424 #include <process.h> /* _beginthreadex (), _endthreadex () */
    2525 #include <windows.h>
    26  #include <shlobj.h> /* for CSIDL_APPDATA, CSIDL_MYDOCUMENTS */
     26 #include <shlobj.h> /* SHGetKnownFolderPath (), FOLDERID_... */
    2727#else
    2828#include <unistd.h> /* getuid() */
     
    226226
    227227static char *
    228 win32_get_special_folder (int folder_id)
    229 {
    230   wchar_t path[MAX_PATH]; /* SHGetFolderPath () requires MAX_PATH */
    231   *path = L'\0';
    232   SHGetFolderPathW (NULL, folder_id, NULL, 0, path);
    233   return tr_win32_native_to_utf8 (path, -1);
     228win32_get_known_folder (REFKNOWNFOLDERID folder_id)
     229{
     230  char * ret = NULL;
     231  PWSTR path;
     232
     233  if (SHGetKnownFolderPath (folder_id, KF_FLAG_DONT_UNEXPAND | KF_FLAG_DONT_VERIFY,
     234                            NULL, &path) == S_OK)
     235    {
     236      ret = tr_win32_native_to_utf8 (path, -1);
     237      CoTaskMemFree (path);
     238    }
     239
     240  return ret;
    234241}
    235242
     
    248255        {
    249256#ifdef _WIN32
    250           home = win32_get_special_folder (CSIDL_PERSONAL);
     257          home = win32_get_known_folder (&FOLDERID_Profile);
    251258#else
    252259          struct passwd * pw = getpwuid (getuid ());
     
    323330          s = tr_buildPath (getHomeDir (), "Library", "Application Support", appname, NULL);
    324331#elif defined (_WIN32)
    325           char * appdata = win32_get_special_folder (CSIDL_APPDATA);
     332          char * appdata = win32_get_known_folder (&FOLDERID_LocalAppData);
    326333          s = tr_buildPath (appdata, appname, NULL);
    327334          tr_free (appdata);
     
    393400        }
    394401
     402#ifdef _WIN32
     403      if (user_dir == NULL)
     404        user_dir = win32_get_known_folder (&FOLDERID_Downloads);
     405#endif
     406
    395407      if (user_dir == NULL)
    396408#ifdef __HAIKU__
     
    472484           * calling executable dir. */
    473485
    474           if (s == NULL) /* check personal AppData/Transmission/Web */
    475             {
    476               char * dir = win32_get_special_folder (CSIDL_COMMON_APPDATA);
    477               s = tr_buildPath (dir, "Transmission", "Web", NULL);
    478               tr_free (dir);
    479               if (!isWebClientDir (s))
    480                 {
    481                   tr_free (s);
    482                   s = NULL;
    483                 }
    484             }
    485 
    486           if (s == NULL) /* check personal AppData */
    487             {
    488               char * dir = win32_get_special_folder (CSIDL_APPDATA);
     486          static REFKNOWNFOLDERID known_folder_ids[] =
     487            {
     488              &FOLDERID_LocalAppData,
     489              &FOLDERID_RoamingAppData,
     490              &FOLDERID_ProgramData
     491            };
     492
     493          for (size_t i = 0; s == NULL && i < ARRAYSIZE (known_folder_ids); ++i)
     494            {
     495              char * dir = win32_get_known_folder (known_folder_ids[i]);
    489496              s = tr_buildPath (dir, "Transmission", "Web", NULL);
    490497              tr_free (dir);
Note: See TracChangeset for help on using the changeset viewer.