Changeset 7113


Ignore:
Timestamp:
Nov 15, 2008, 5:39:54 PM (12 years ago)
Author:
charles
Message:

#1406: need tr_getDefaultDownloadDir() for consistency between apps

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/cli/cli.c

    r7069 r7113  
    350350        configdir = tr_getDefaultConfigDir( );
    351351
    352     /* if no download directory specified, use cwd instead */
    353     if( !downloadDir )
    354         downloadDir = tr_strdup( tr_getcwd( ) );
     352    if( downloadDir == NULL )
     353        downloadDir = tr_getDefaultDownloadDir( );
    355354
    356355    /* Initialize libtransmission */
  • trunk/daemon/daemon.c

    r6978 r7113  
    168168              int          blocklistEnabled )
    169169{
    170     char        * mycwd;
    171170    tr_benc       state, *dict = NULL;
    172171    int           peerPort = -1, peers = -1;
     
    191190    ***/
    192191
    193     mycwd = tr_getcwd( );
    194     getConfigStr( dict, KEY_DOWNLOAD_DIR,    &downloadDir,       mycwd );
     192    getConfigStr( dict, KEY_DOWNLOAD_DIR,    &downloadDir,
     193                  TR_DEFAULT_DOWNLOAD_DIR );
    195194    getConfigInt( dict, KEY_PEX_ENABLED,     &pexEnabled,
    196195                  TR_DEFAULT_PEX_ENABLED );
     
    259258    if( dict )
    260259        tr_bencFree( &state );
    261 
    262     tr_free( mycwd );
    263260}
    264261
  • trunk/daemon/remote.c

    r7108 r7113  
    1515#include <stdlib.h>
    1616#include <string.h> /* strcmp */
     17
     18#ifdef WIN32
     19 #include <direct.h> /* getcwd */
     20#else
     21 #include <unistd.h> /* getcwd */
     22#endif
    1723
    1824#include <libevent/event.h>
     
    144150static char * auth = NULL;
    145151
     152static char*
     153tr_getcwd( void )
     154{
     155    char buf[2048];
     156    *buf = '\0';
     157#ifdef WIN32
     158    _getcwd( buf, sizeof( buf ) );
     159#else
     160    getcwd( buf, sizeof( buf ) );
     161#endif
     162    return tr_strdup( buf );
     163}
     164
    146165static char*
    147166absolutify( const char * path )
  • trunk/gtk/tr-prefs.c

    r7041 r7113  
    4949    str = NULL;
    5050    if( !str ) str = g_get_user_special_dir( G_USER_DIRECTORY_DESKTOP );
    51     if( !str ) str = g_get_home_dir( );
     51    if( !str ) str = tr_getDefaultDownloadDir( );
    5252    pref_string_set_default ( PREF_KEY_DIR_WATCH, str );
    5353    pref_flag_set_default   ( PREF_KEY_DIR_WATCH_ENABLED, FALSE );
  • trunk/libtransmission/platform.c

    r7019 r7113  
    484484}
    485485
     486const char*
     487tr_getDefaultDownloadDir( void )
     488{
     489    static char * s = NULL;
     490
     491    if( s == NULL )
     492        s = tr_buildPath( getHomeDir( ), "Downloads", NULL );
     493
     494    return s;
     495}
     496
    486497/***
    487498****
  • trunk/libtransmission/session.c

    r7069 r7113  
    311311tr_handle *
    312312tr_sessionInit( const char * configDir,
    313                 const char * downloadDir,
    314313                const char * tag )
    315314{
    316315    return tr_sessionInitFull( configDir,
    317                                downloadDir,
     316                               TR_DEFAULT_DOWNLOAD_DIR,
    318317                               tag,
    319318                               TR_DEFAULT_PEX_ENABLED,
  • trunk/libtransmission/transmission.h

    r7069 r7113  
    5858 *
    5959 * The default configuration directory is determined this way:
    60  * - If the TRANSMISSION_HOME environmental variable is set,
    61  *   its value is returned.
    62  * - otherwise, if we're running on Darwin,
    63  *   "$HOME/Library/Application Support/Transmission" is returned.
    64  * - otherwise, if we're running on WIN32,
    65  *   "$EXE_FOLDER/Transmission" is returned.
    66  * - otherwise, if XDG_CONFIG_HOME is set,
    67  *   "$XDG_CONFIG_HOME/transmission" is returned.
    68  * - lastly, $HOME/.config/transmission" is used.
     60 * 1. If the TRANSMISSION_HOME environmental variable is set, its value is used.
     61 * 2. On Darwin, "${HOME}/Library/Application Support/Transmission" is used.
     62 * 3. On Windows, "${CSIDL_APPDATA}/Transmission" is used.
     63 * 4. If XDG_CONFIG_HOME is set, "${XDG_CONFIG_HOME}/transmission" is used.
     64 * 5. ${HOME}/.config/transmission" is used as a last resort.
    6965 */
    7066const char* tr_getDefaultConfigDir( void );
     67
     68/**
     69 * @brief returns Transmisson's default download directory.
     70 *
     71 * The default download directory is determined this way:
     72 * 1. If the HOME environmental variable is set, "${HOME}/Downloads" is used.
     73 * 2. On Windows, "${CSIDL_MYDOCUMENTS}/Downloads" is used.
     74 * 3. Otherwise, getpwuid(getuid())->pw_dir + "/Downloads" is used.
     75 */
     76const char* tr_getDefaultDownloadDir( void );
    7177
    7278typedef struct tr_ctor tr_ctor;
     
    98104/** @see tr_sessionInitFull */
    99105#define TR_DEFAULT_CONFIG_DIR               tr_getDefaultConfigDir( )
     106/** @see tr_sessionInitFull */
     107#define TR_DEFAULT_DOWNLOAD_DIR             tr_getDefaultDownloadDir( )
    100108/** @see tr_sessionInitFull */
    101109#ifdef TR_EMBEDDED
     
    286294    @deprecated Use tr_sessionInitFull() instead. */
    287295tr_session *  tr_sessionInit( const char * configDir,
    288                               const char * downloadDir,
    289296                              const char * tag );
    290297
  • trunk/libtransmission/utils.c

    r6993 r7113  
    489489    *size = sb.st_size;
    490490    return buf;
    491 }
    492 
    493 char*
    494 tr_getcwd( void )
    495 {
    496     char buf[2048];
    497     *buf = '\0';
    498 #ifdef WIN32
    499     _getcwd( buf, sizeof( buf ) );
    500 #else
    501     getcwd( buf, sizeof( buf ) );
    502 #endif
    503     return tr_strdup( buf );
    504491}
    505492
  • trunk/libtransmission/utils.h

    r6961 r7113  
    144144char*          tr_getLogTimeStr( char * buf,
    145145                                 int    buflen );
    146 
    147 /** a portability wrapper for getcwd(). */
    148 char*          tr_getcwd( void ) TR_GNUC_MALLOC;
    149146
    150147/** a portability wrapper for basename(). */
Note: See TracChangeset for help on using the changeset viewer.