#1406: need tr_getDefaultDownloadDir() for consistency between apps
This commit is contained in:
parent
af91ad11eb
commit
f8a7c4b347
|
@ -349,9 +349,8 @@ main( int argc,
|
|||
if( configdir == NULL )
|
||||
configdir = tr_getDefaultConfigDir( );
|
||||
|
||||
/* if no download directory specified, use cwd instead */
|
||||
if( !downloadDir )
|
||||
downloadDir = tr_strdup( tr_getcwd( ) );
|
||||
if( downloadDir == NULL )
|
||||
downloadDir = tr_getDefaultDownloadDir( );
|
||||
|
||||
/* Initialize libtransmission */
|
||||
h = tr_sessionInitFull(
|
||||
|
|
|
@ -167,7 +167,6 @@ session_init( const char * configDir,
|
|||
const char * password,
|
||||
int blocklistEnabled )
|
||||
{
|
||||
char * mycwd;
|
||||
tr_benc state, *dict = NULL;
|
||||
int peerPort = -1, peers = -1;
|
||||
int whitelistEnabled = -1;
|
||||
|
@ -190,8 +189,8 @@ session_init( const char * configDir,
|
|||
**** If neither of those can be found, the TR_DEFAULT fields are used .
|
||||
***/
|
||||
|
||||
mycwd = tr_getcwd( );
|
||||
getConfigStr( dict, KEY_DOWNLOAD_DIR, &downloadDir, mycwd );
|
||||
getConfigStr( dict, KEY_DOWNLOAD_DIR, &downloadDir,
|
||||
TR_DEFAULT_DOWNLOAD_DIR );
|
||||
getConfigInt( dict, KEY_PEX_ENABLED, &pexEnabled,
|
||||
TR_DEFAULT_PEX_ENABLED );
|
||||
getConfigInt( dict, KEY_PORT_FORWARDING, &fwdEnabled,
|
||||
|
@ -258,8 +257,6 @@ session_init( const char * configDir,
|
|||
|
||||
if( dict )
|
||||
tr_bencFree( &state );
|
||||
|
||||
tr_free( mycwd );
|
||||
}
|
||||
|
||||
static const char *
|
||||
|
|
|
@ -15,6 +15,12 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h> /* strcmp */
|
||||
|
||||
#ifdef WIN32
|
||||
#include <direct.h> /* getcwd */
|
||||
#else
|
||||
#include <unistd.h> /* getcwd */
|
||||
#endif
|
||||
|
||||
#include <libevent/event.h>
|
||||
#include <curl/curl.h>
|
||||
|
||||
|
@ -143,6 +149,19 @@ static int reqCount = 0;
|
|||
static int debug = 0;
|
||||
static char * auth = NULL;
|
||||
|
||||
static char*
|
||||
tr_getcwd( void )
|
||||
{
|
||||
char buf[2048];
|
||||
*buf = '\0';
|
||||
#ifdef WIN32
|
||||
_getcwd( buf, sizeof( buf ) );
|
||||
#else
|
||||
getcwd( buf, sizeof( buf ) );
|
||||
#endif
|
||||
return tr_strdup( buf );
|
||||
}
|
||||
|
||||
static char*
|
||||
absolutify( const char * path )
|
||||
{
|
||||
|
|
|
@ -48,7 +48,7 @@ tr_prefs_init_global( void )
|
|||
#if HAVE_GIO
|
||||
str = NULL;
|
||||
if( !str ) str = g_get_user_special_dir( G_USER_DIRECTORY_DESKTOP );
|
||||
if( !str ) str = g_get_home_dir( );
|
||||
if( !str ) str = tr_getDefaultDownloadDir( );
|
||||
pref_string_set_default ( PREF_KEY_DIR_WATCH, str );
|
||||
pref_flag_set_default ( PREF_KEY_DIR_WATCH_ENABLED, FALSE );
|
||||
#endif
|
||||
|
|
|
@ -483,6 +483,17 @@ tr_getDefaultConfigDir( void )
|
|||
return s;
|
||||
}
|
||||
|
||||
const char*
|
||||
tr_getDefaultDownloadDir( void )
|
||||
{
|
||||
static char * s = NULL;
|
||||
|
||||
if( s == NULL )
|
||||
s = tr_buildPath( getHomeDir( ), "Downloads", NULL );
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
/***
|
||||
****
|
||||
***/
|
||||
|
|
|
@ -310,11 +310,10 @@ tr_sessionInitFull( const char * configDir,
|
|||
|
||||
tr_handle *
|
||||
tr_sessionInit( const char * configDir,
|
||||
const char * downloadDir,
|
||||
const char * tag )
|
||||
{
|
||||
return tr_sessionInitFull( configDir,
|
||||
downloadDir,
|
||||
TR_DEFAULT_DOWNLOAD_DIR,
|
||||
tag,
|
||||
TR_DEFAULT_PEX_ENABLED,
|
||||
TR_DEFAULT_PORT_FORWARDING_ENABLED,
|
||||
|
|
|
@ -57,18 +57,24 @@ typedef uint64_t tr_block_index_t;
|
|||
* @brief returns Transmission's default configuration file directory.
|
||||
*
|
||||
* The default configuration directory is determined this way:
|
||||
* - If the TRANSMISSION_HOME environmental variable is set,
|
||||
* its value is returned.
|
||||
* - otherwise, if we're running on Darwin,
|
||||
* "$HOME/Library/Application Support/Transmission" is returned.
|
||||
* - otherwise, if we're running on WIN32,
|
||||
* "$EXE_FOLDER/Transmission" is returned.
|
||||
* - otherwise, if XDG_CONFIG_HOME is set,
|
||||
* "$XDG_CONFIG_HOME/transmission" is returned.
|
||||
* - lastly, $HOME/.config/transmission" is used.
|
||||
* 1. If the TRANSMISSION_HOME environmental variable is set, its value is used.
|
||||
* 2. On Darwin, "${HOME}/Library/Application Support/Transmission" is used.
|
||||
* 3. On Windows, "${CSIDL_APPDATA}/Transmission" is used.
|
||||
* 4. If XDG_CONFIG_HOME is set, "${XDG_CONFIG_HOME}/transmission" is used.
|
||||
* 5. ${HOME}/.config/transmission" is used as a last resort.
|
||||
*/
|
||||
const char* tr_getDefaultConfigDir( void );
|
||||
|
||||
/**
|
||||
* @brief returns Transmisson's default download directory.
|
||||
*
|
||||
* The default download directory is determined this way:
|
||||
* 1. If the HOME environmental variable is set, "${HOME}/Downloads" is used.
|
||||
* 2. On Windows, "${CSIDL_MYDOCUMENTS}/Downloads" is used.
|
||||
* 3. Otherwise, getpwuid(getuid())->pw_dir + "/Downloads" is used.
|
||||
*/
|
||||
const char* tr_getDefaultDownloadDir( void );
|
||||
|
||||
typedef struct tr_ctor tr_ctor;
|
||||
typedef struct tr_handle tr_handle;
|
||||
typedef struct tr_info tr_info;
|
||||
|
@ -98,6 +104,8 @@ tr_proxy_type;
|
|||
/** @see tr_sessionInitFull */
|
||||
#define TR_DEFAULT_CONFIG_DIR tr_getDefaultConfigDir( )
|
||||
/** @see tr_sessionInitFull */
|
||||
#define TR_DEFAULT_DOWNLOAD_DIR tr_getDefaultDownloadDir( )
|
||||
/** @see tr_sessionInitFull */
|
||||
#ifdef TR_EMBEDDED
|
||||
#define TR_DEFAULT_ENCRYPTION TR_CLEAR_PREFERRED
|
||||
#else
|
||||
|
@ -285,7 +293,6 @@ tr_session * tr_sessionInitFull( const char * configDir,
|
|||
/** @brief Shorter form of tr_sessionInitFull()
|
||||
@deprecated Use tr_sessionInitFull() instead. */
|
||||
tr_session * tr_sessionInit( const char * configDir,
|
||||
const char * downloadDir,
|
||||
const char * tag );
|
||||
|
||||
/** @brief End a libtransmission session
|
||||
|
|
|
@ -490,19 +490,6 @@ tr_loadFile( const char * path,
|
|||
return buf;
|
||||
}
|
||||
|
||||
char*
|
||||
tr_getcwd( void )
|
||||
{
|
||||
char buf[2048];
|
||||
*buf = '\0';
|
||||
#ifdef WIN32
|
||||
_getcwd( buf, sizeof( buf ) );
|
||||
#else
|
||||
getcwd( buf, sizeof( buf ) );
|
||||
#endif
|
||||
return tr_strdup( buf );
|
||||
}
|
||||
|
||||
char*
|
||||
tr_basename( const char * path )
|
||||
{
|
||||
|
|
|
@ -144,9 +144,6 @@ void tr_deepLog( const char * file,
|
|||
char* tr_getLogTimeStr( char * buf,
|
||||
int buflen );
|
||||
|
||||
/** a portability wrapper for getcwd(). */
|
||||
char* tr_getcwd( void ) TR_GNUC_MALLOC;
|
||||
|
||||
/** a portability wrapper for basename(). */
|
||||
char* tr_basename( const char * path ) TR_GNUC_MALLOC;
|
||||
|
||||
|
|
Loading…
Reference in New Issue