mirror of
https://github.com/transmission/transmission
synced 2025-03-04 10:38:13 +00:00
added backwards compatability for 0.8x configuration files. modified from a patch originally written by poolshark.
This commit is contained in:
parent
7f6b34a426
commit
57e36bffeb
3 changed files with 81 additions and 0 deletions
77
gtk/conf.c
77
gtk/conf.c
|
@ -38,6 +38,7 @@
|
|||
#include <glib/gstdio.h>
|
||||
|
||||
#include <libtransmission/transmission.h>
|
||||
#include <libtransmission/bencode.h>
|
||||
|
||||
#include "conf.h"
|
||||
#include "util.h"
|
||||
|
@ -249,3 +250,79 @@ pref_save(char **errstr)
|
|||
g_free( path );
|
||||
g_free( filename );
|
||||
}
|
||||
|
||||
/***
|
||||
****
|
||||
***/
|
||||
|
||||
static char*
|
||||
getCompat08PrefsFilename( void )
|
||||
{
|
||||
assert( gl_confdir != NULL );
|
||||
return g_build_filename( gl_confdir, "prefs", NULL );
|
||||
}
|
||||
|
||||
static void
|
||||
translate_08_to_09( const char* oldfile, const char* newfile )
|
||||
{
|
||||
static struct pref_entry {
|
||||
const char* oldkey;
|
||||
const char* newkey;
|
||||
} pref_table[] = {
|
||||
{ "add-behavior-ipc", "add-behavior-ipc"},
|
||||
{ "add-behavior-standard", "add-behavior-standard"},
|
||||
{ "download-directory", "default-download-directory"},
|
||||
{ "download-limit", "download-limit"},
|
||||
{ "use-download-limit", "download-limit-enabled" },
|
||||
{ "listening-port", "listening-port"},
|
||||
{ "use-nat-traversal", "nat-traversal-enabled"},
|
||||
{ "use-peer-exchange", "pex-enabled"},
|
||||
{ "ask-quit", "prompt-before-exit"},
|
||||
{ "ask-download-directory", "prompt-for-download-directory"},
|
||||
{ "use-tray-icon", "system-tray-icon-enabled"},
|
||||
{ "upload-limit", "upload-limit"},
|
||||
{ "use-upload-limit", "upload-limit-enabled"}
|
||||
};
|
||||
|
||||
GString * out = g_string_new( NULL );
|
||||
gchar * contents = NULL;
|
||||
gsize contents_len = 0;
|
||||
benc_val_t top;
|
||||
|
||||
memset( &top, 0, sizeof(benc_val_t) );
|
||||
|
||||
if( g_file_get_contents( oldfile, &contents, &contents_len, NULL )
|
||||
&& !tr_bencLoad( contents, contents_len, &top, NULL )
|
||||
&& top.type==TYPE_DICT )
|
||||
{
|
||||
unsigned int i;
|
||||
g_string_append( out, "\n[general]\n" );
|
||||
for ( i=0; i<G_N_ELEMENTS(pref_table); ++i ) {
|
||||
const benc_val_t * val = tr_bencDictFind( &top, pref_table[i].oldkey );
|
||||
if( val != NULL ) {
|
||||
const char * valstr = val->val.s.s;
|
||||
if( !strcmp( valstr, "yes" ) ) valstr = "true";
|
||||
if( !strcmp( valstr, "no" ) ) valstr = "false";
|
||||
g_string_append_printf( out, "%s=%s\n", pref_table[i].newkey, valstr );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
g_file_set_contents( newfile, out->str, out->len, NULL );
|
||||
g_string_free( out, TRUE );
|
||||
g_free( contents );
|
||||
}
|
||||
|
||||
void
|
||||
cf_check_older_configs( void )
|
||||
{
|
||||
char * cfn = getPrefsFilename( );
|
||||
char * cfn08 = getCompat08PrefsFilename( );
|
||||
|
||||
if( !g_file_test( cfn, G_FILE_TEST_IS_REGULAR )
|
||||
&& g_file_test( cfn08, G_FILE_TEST_IS_REGULAR ) )
|
||||
translate_08_to_09( cfn08, cfn );
|
||||
|
||||
g_free( cfn08 );
|
||||
g_free( cfn );
|
||||
}
|
||||
|
|
|
@ -55,5 +55,7 @@ gboolean
|
|||
cf_lock(char **errstr);
|
||||
char *
|
||||
cf_sockname(void);
|
||||
void
|
||||
cf_check_older_configs(void);
|
||||
|
||||
#endif /* TG_CONF_H */
|
||||
|
|
|
@ -26,6 +26,8 @@
|
|||
void
|
||||
tr_prefs_init_global( void )
|
||||
{
|
||||
cf_check_older_configs( );
|
||||
|
||||
pref_flag_set_default ( PREF_KEY_DL_LIMIT_ENABLED, FALSE );
|
||||
pref_int_set_default ( PREF_KEY_DL_LIMIT, 100 );
|
||||
pref_flag_set_default ( PREF_KEY_UL_LIMIT_ENABLED, FALSE );
|
||||
|
|
Loading…
Add table
Reference in a new issue