Changeset 214 for trunk/gtk


Ignore:
Timestamp:
Apr 7, 2006, 3:41:28 PM (16 years ago)
Author:
joshe
Message:

Instead of storing files specific to the gtk frontend directly
in ~/.transmission/, store them in a gtk subdirectory.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/conf.c

    r162 r214  
    4343#include "util.h"
    4444
    45 #define FILE_LOCK               "gtk_lock"
    46 #define FILE_PREFS              "gtk_prefs"
    47 #define FILE_PREFS_TMP          "gtk_prefs.tmp"
    48 #define FILE_STATE              "gtk_state"
    49 #define FILE_STATE_TMP          "gtk_state.tmp"
     45#define CONF_SUBDIR             "gtk"
     46#define FILE_LOCK               "lock"
     47#define FILE_PREFS              "prefs"
     48#define FILE_PREFS_TMP          "prefs.tmp"
     49#define FILE_STATE              "state"
     50#define FILE_STATE_TMP          "state.tmp"
     51#define OLD_FILE_LOCK           "gtk_lock" /* remove this after next release */
     52#define OLD_FILE_PREFS          "gtk_prefs"
     53#define OLD_FILE_STATE          "gtk_state"
    5054#define PREF_SEP_KEYVAL         '\t'
    5155#define PREF_SEP_LINE           '\n'
     
    6064
    6165static char *confdir = NULL;
     66static char *old_confdir = NULL;
    6267static GTree *prefs = NULL;
    6368
     
    100105gboolean
    101106cf_init(const char *dir, char **errstr) {
    102   struct stat sb;
    103 
    104107  *errstr = NULL;
    105   confdir = g_strdup(dir);
    106 
    107   if(0 > stat(dir, &sb)) {
    108     if(ENOENT != errno)
    109       *errstr = g_strdup_printf(_("Failed to check the directory %s:\n%s"),
    110         dir, strerror(errno));
    111     else {
    112       if(0 == mkdir(dir, 0777))
    113         return TRUE;
    114       else
    115         *errstr = g_strdup_printf(_("Failed to create the directory %s:\n%s"),
    116           dir, strerror(errno));
    117     }
    118     return FALSE;
    119   }
    120 
    121   if(S_IFDIR & sb.st_mode)
     108  old_confdir = g_strdup(dir);
     109  confdir = g_build_filename(dir, CONF_SUBDIR, NULL);
     110
     111  if(mkdir_p(confdir, 0777))
    122112    return TRUE;
    123113
    124   *errstr = g_strdup_printf(_("%s is not a directory"), dir);
     114  *errstr = g_strdup_printf(_("Failed to create the directory %s:\n%s"),
     115                            confdir, strerror(errno));
    125116  return FALSE;
    126117}
     
    128119gboolean
    129120cf_lock(char **errstr) {
    130   char *path = g_build_filename(confdir, FILE_LOCK, NULL);
     121  char *path = g_build_filename(old_confdir, OLD_FILE_LOCK, NULL);
    131122  int fd = lockfile(path, errstr);
     123
     124  if(0 <= fd) {
     125    g_free(path);
     126    path = g_build_filename(confdir, FILE_LOCK, NULL);
     127    fd = lockfile(path, errstr);
     128  }
    132129
    133130  g_free(path);
     
    138135cf_loadprefs(char **errstr) {
    139136  char *path = g_build_filename(confdir, FILE_PREFS, NULL);
     137  char *oldpath;
    140138  GIOChannel *io;
    141139  GError *err;
     
    158156      *errstr = g_strdup_printf(
    159157        _("Failed to open the file %s for reading:\n%s"), path, err->message);
    160     goto done;
     158    else {
     159      g_error_free(err);
     160      err = NULL;
     161      oldpath = g_build_filename(old_confdir, OLD_FILE_PREFS, NULL);
     162      io = g_io_channel_new_file(oldpath, "r", &err);
     163      g_free(oldpath);
     164    }
     165    if(NULL != err)
     166      goto done;
    161167  }
    162168  g_io_channel_set_line_term(io, &term, 1);
     
    194200  if(NULL != io) 
    195201    g_io_channel_unref(io);
     202  g_free(path);
    196203  return NULL == *errstr;
    197204}
     
    307314cf_loadstate(char **errstr) {
    308315  char *path = g_build_filename(confdir, FILE_STATE, NULL);
     316  char *oldpath;
    309317  GIOChannel *io;
    310318  GError *err;
     
    321329      *errstr = g_strdup_printf(
    322330        _("Failed to open the file %s for reading:\n%s"), path, err->message);
    323     goto done;
     331    else {
     332      g_error_free(err);
     333      err = NULL;
     334      oldpath = g_build_filename(old_confdir, OLD_FILE_STATE, NULL);
     335      io = g_io_channel_new_file(oldpath, "r", &err);
     336      g_free(oldpath);
     337    }
     338    if(NULL != err)
     339      goto done;
    324340  }
    325341  g_io_channel_set_line_term(io, &term, 1);
     
    366382    ret = NULL;
    367383  }
     384  g_free(path);
    368385  return ret;
    369386}
Note: See TracChangeset for help on using the changeset viewer.