Changeset 8580
- Timestamp:
- Jun 1, 2009, 5:24:12 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gtk/conf.c
r8195 r8580 358 358 359 359 static char* 360 getCompat080PrefsFilename( void )361 {362 assert( gl_confdir != NULL );363 364 return g_build_filename( g_get_home_dir( ), ".transmission", "gtk", "prefs", NULL );365 }366 367 static char*368 360 getCompat090PrefsFilename( void ) 369 361 { … … 377 369 { 378 370 return g_build_filename( g_get_user_config_dir( ), "transmission", "gtk", "prefs.ini", NULL ); 379 }380 381 static void382 translate_08_to_09( const char* oldfile,383 const char* newfile )384 {385 static struct pref_entry {386 const char* oldkey;387 const char* newkey;388 } pref_table[] = {389 { "add-behavior-ipc", "add-behavior-ipc" },390 { "add-behavior-standard", "add-behavior-standard" },391 { "download-directory", "default-download-directory" },392 { "download-limit", "download-limit" },393 { "use-download-limit", "download-limit-enabled" },394 { "listening-port", "listening-port" },395 { "use-nat-traversal", "nat-traversal-enabled" },396 { "use-peer-exchange", "pex-enabled" },397 { "ask-quit", "prompt-before-exit" },398 { "ask-download-directory", "prompt-for-download-directory" },399 { "use-tray-icon", "system-tray-icon-enabled" },400 { "upload-limit", "upload-limit" },401 { "use-upload-limit", "upload-limit-enabled" }402 };403 404 GString * out = g_string_new( NULL );405 gchar * contents = NULL;406 gsize contents_len = 0;407 tr_benc top;408 409 memset( &top, 0, sizeof( tr_benc ) );410 411 if( g_file_get_contents( oldfile, &contents, &contents_len, NULL )412 && !tr_bencLoad( contents, contents_len, &top, NULL )413 && tr_bencIsDict( &top ) )414 {415 unsigned int i;416 g_string_append( out, "\n[general]\n" );417 for( i = 0; i < G_N_ELEMENTS( pref_table ); ++i )418 {419 const tr_benc * val = tr_bencDictFind( &top,420 pref_table[i].oldkey );421 if( val != NULL )422 {423 const char * valstr = val->val.s.s;424 if( !strcmp( valstr, "yes" ) ) valstr = "true";425 if( !strcmp( valstr, "no" ) ) valstr = "false";426 g_string_append_printf( out, "%s=%s\n",427 pref_table[i].newkey,428 valstr );429 }430 }431 }432 433 g_file_set_contents( newfile, out->str, out->len, NULL );434 g_string_free( out, TRUE );435 g_free( contents );436 371 } 437 372 … … 507 442 char * key1 = getCompat121PrefsFilename( ); 508 443 char * key2 = getCompat090PrefsFilename( ); 509 char * benc = getCompat080PrefsFilename( );510 444 511 445 if( g_file_test( key1, G_FILE_TEST_IS_REGULAR ) ) … … 519 453 translate_keyfile_to_json( key2, filename ); 520 454 } 521 else if( g_file_test( benc, G_FILE_TEST_IS_REGULAR ) ) 522 { 523 char * tmpfile; 524 int fd = g_file_open_tmp( "transmission-prefs-XXXXXX", &tmpfile, NULL ); 525 g_message( _( "Importing \"%s\"" ), benc ); 526 if( fd != -1 ) close( fd ); 527 translate_08_to_09( benc, tmpfile ); 528 translate_keyfile_to_json( tmpfile, filename ); 529 unlink( tmpfile ); 530 } 531 532 g_free( benc ); 455 533 456 g_free( key2 ); 534 457 g_free( key1 );
Note: See TracChangeset
for help on using the changeset viewer.