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(
const char * password,
int blocklistEnabled )
{
- char * mycwd;
tr_benc state, *dict = NULL;
int peerPort = -1, peers = -1;
int whitelistEnabled = -1;
**** 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,
if( dict )
tr_bencFree( &state );
-
- tr_free( mycwd );
}
static const char *
#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>
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 )
{
#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
return s;
}
+const char*
+tr_getDefaultDownloadDir( void )
+{
+ static char * s = NULL;
+
+ if( s == NULL )
+ s = tr_buildPath( getHomeDir( ), "Downloads", NULL );
+
+ return s;
+}
+
/***
****
***/
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,
* @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;
/** @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
/** @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
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 )
{
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;