]> granicus.if.org Git - transmission/commitdiff
#1406: need tr_getDefaultDownloadDir() for consistency between apps
authorCharles Kerr <charles@transmissionbt.com>
Sat, 15 Nov 2008 17:39:54 +0000 (17:39 +0000)
committerCharles Kerr <charles@transmissionbt.com>
Sat, 15 Nov 2008 17:39:54 +0000 (17:39 +0000)
cli/cli.c
daemon/daemon.c
daemon/remote.c
gtk/tr-prefs.c
libtransmission/platform.c
libtransmission/session.c
libtransmission/transmission.h
libtransmission/utils.c
libtransmission/utils.h

index b240adee83314202aeaee44e073cf394dc507ff6..66e18d7668e743684afad804617894df174a8f9c 100644 (file)
--- a/cli/cli.c
+++ b/cli/cli.c
@@ -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(
index 3428bb6aa5c2ea71787d8f4c0ee8633c74a6604f..fad29becee490c8fc9bb9d76749c6089cceb27e7 100644 (file)
@@ -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 *
index 5522e4b825bbcfbdbded8ebed8bd29120c0483e0..387e5056c6d23be0565ffd074ef8bd34f9f6137c 100644 (file)
 #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 )
 {
index b3f297358e9b713acc6c0419aac6ebd1cf41d710..fd8d9c9a166a9a8ae19378283401e6b73725f4ee 100644 (file)
@@ -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
index 70c9372210d2f84d85d19c0d29ef65b194303519..e05865da1094b08c1a441cc93afcd449cea8e814 100644 (file)
@@ -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;
+}
+
 /***
 ****
 ***/
index 1a1439ff11246808731e028475d1f5dad13c9cee..f3450abe476d35602f01c0e123a8fcc0f73e9228 100644 (file)
@@ -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,
index aacbf57c8a7953e19aab75138360dff88b3cda02..20d034dae0bb3f59b645d001b6732e0661aef843 100644 (file)
@@ -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
index 27b82687fc4d766710046594d51604fedfc98098..bfda5d87092a0a013634f30d04d4333427de0b89 100644 (file)
@@ -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 )
 {
index 5d90d610a49a1e4d1bd35c26f534c503d3a6da37..84cb57467bce532c6e542681a0c349553b7055ea 100644 (file)
@@ -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;