Ignore:
Timestamp:
Sep 21, 2014, 6:03:13 PM (6 years ago)
Author:
jordan
Message:

#4160: mike.dld patch: 4160-06-misc.patch

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/platform.c

    r14331 r14335  
    1414
    1515#include <assert.h>
    16 #include <stdio.h>
    1716#include <stdlib.h>
    1817#include <string.h>
    19 #include <unistd.h> /* getuid(), close() */
     18#include <unistd.h> /* getuid() */
     19
     20#ifdef __HAIKU__
     21 #include <limits.h> /* PATH_MAX */
     22#endif
    2023
    2124#ifdef _WIN32
     
    4447#include "platform.h"
    4548#include "session.h"
     49#include "utils.h"
    4650
    4751/***
     
    224228#endif
    225229
     230#ifdef _WIN32
     231
     232char *
     233win32_get_special_folder (int folder_id)
     234{
     235  wchar_t path[MAX_PATH]; /* SHGetFolderPath () requires MAX_PATH */
     236  *path = L'\0';
     237  SHGetFolderPathW (NULL, folder_id, NULL, 0, path);
     238  return tr_win32_native_to_utf8 (path, -1);
     239}
     240
     241#endif
     242
    226243static const char *
    227244getHomeDir (void)
     
    236253        {
    237254#ifdef _WIN32
    238           char appdata[MAX_PATH]; /* SHGetFolderPath () requires MAX_PATH */
    239           *appdata = '\0';
    240           SHGetFolderPath (NULL, CSIDL_PERSONAL, NULL, 0, appdata);
    241           home = tr_strdup (appdata);
     255          home = win32_get_special_folder (CSIDL_PERSONAL);
    242256#else
    243257          struct passwd * pw = getpwuid (getuid ());
     
    316330          s = tr_buildPath (getHomeDir (), "Library", "Application Support", appname, NULL);
    317331#elif defined (_WIN32)
    318           char appdata[TR_PATH_MAX]; /* SHGetFolderPath () requires MAX_PATH */
    319           SHGetFolderPath (NULL, CSIDL_APPDATA, NULL, 0, appdata);
     332          char * appdata = win32_get_special_folder (CSIDL_APPDATA);
    320333          s = tr_buildPath (appdata, appname, NULL);
     334          tr_free (appdata);
    321335#elif defined (__HAIKU__)
    322           char buf[TR_PATH_MAX];
     336          char buf[PATH_MAX];
    323337          find_directory (B_USER_SETTINGS_DIRECTORY, -1, true, buf, sizeof (buf));
    324338          s = tr_buildPath (buf, appname, NULL);
     
    397411***/
    398412
    399 static int
     413static bool
    400414isWebClientDir (const char * path)
    401415{
     
    460474#elif defined (_WIN32)
    461475
    462           /* SHGetFolderPath explicitly requires MAX_PATH length */
    463           char dir[MAX_PATH];
    464 
    465476          /* Generally, Web interface should be stored in a Web subdir of
    466477           * calling executable dir. */
     
    468479          if (s == NULL) /* check personal AppData/Transmission/Web */
    469480            {
    470               SHGetFolderPath (NULL, CSIDL_COMMON_APPDATA, NULL, 0, dir);
     481              char * dir = win32_get_special_folder (CSIDL_COMMON_APPDATA);
    471482              s = tr_buildPath (dir, "Transmission", "Web", NULL);
     483              tr_free (dir);
    472484              if (!isWebClientDir (s))
    473485                {
     
    479491          if (s == NULL) /* check personal AppData */
    480492            {
    481               SHGetFolderPath (NULL, CSIDL_APPDATA, NULL, 0, dir);
     493              char * dir = win32_get_special_folder (CSIDL_APPDATA);
    482494              s = tr_buildPath (dir, "Transmission", "Web", NULL);
     495              tr_free (dir);
    483496              if (!isWebClientDir (s))
    484497                {
     
    490503            if (s == NULL) /* check calling module place */
    491504              {
    492                 char * tmp;
    493                 GetModuleFileName (GetModuleHandle (NULL), dir, sizeof (dir));
    494                 tmp = tr_sys_path_dirname (dir, NULL);
    495                 s = tr_buildPath (tmp, "Web", NULL);
    496                 tr_free (tmp);
     505                wchar_t wide_module_path[MAX_PATH];
     506                char * module_path;
     507                char * dir;
     508                GetModuleFileNameW (NULL, wide_module_path,
     509                                    sizeof (wide_module_path) / sizeof (*wide_module_path));
     510                module_path = tr_win32_native_to_utf8 (wide_module_path, -1);
     511                dir = tr_sys_path_dirname (module_path, NULL);
     512                tr_free (module_path);
     513                s = tr_buildPath (dir, "Web", NULL);
     514                tr_free (dir);
    497515                if (!isWebClientDir (s))
    498516                  {
Note: See TracChangeset for help on using the changeset viewer.