[Tomoe-cvs 1009] CVS update: tomoe/lib

Back to archive index

Takuro Ashie makei****@users*****
2006年 11月 25日 (土) 19:43:24 JST


Index: tomoe/lib/tomoe-config.c
diff -u tomoe/lib/tomoe-config.c:1.34 tomoe/lib/tomoe-config.c:1.35
--- tomoe/lib/tomoe-config.c:1.34	Sat Nov 25 12:32:19 2006
+++ tomoe/lib/tomoe-config.c	Sat Nov 25 19:43:24 2006
@@ -17,13 +17,14 @@
  *  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  *  Boston, MA  02111-1307  USA
  *
- *  $Id: tomoe-config.c,v 1.34 2006/11/25 03:32:19 kous Exp $
+ *  $Id: tomoe-config.c,v 1.35 2006/11/25 10:43:24 makeinu Exp $
  */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif /* HAVE_CONFIG_H */
 
+#include <stdio.h>
 #include <string.h>
 #include <sys/stat.h>
 #include <glib.h>
@@ -130,16 +131,37 @@
 
             priv->filename = g_build_filename (home, "."PACKAGE,
                                                default_config_file, NULL);
-            /* if not found, use system config file */
-            if (!g_file_test (priv->filename, G_FILE_TEST_EXISTS) &&
-                g_file_test (system_config_file, G_FILE_TEST_EXISTS) &&
-                g_file_get_contents (system_config_file, &src, &length, NULL)) {
-                g_file_set_contents (priv->filename, src, length, NULL);
+
+            /* if not found, ensure to initialize the file */
+            if (!g_file_test (priv->filename, G_FILE_TEST_EXISTS)) {
+                FILE *f;
+                gboolean success = FALSE;
+
+                if (g_file_test (system_config_file, G_FILE_TEST_EXISTS))
+                    success = g_file_get_contents (system_config_file,
+                                                   &src, &length, NULL);
+                if (!success) {
+                    src = (gchar*) default_config;
+                    length = strlen (src);
+                }
+
+#warning FIXME: need mkdir
+
+                f = fopen(priv->filename, "wb");
+                if (f) {
+                    fwrite (src, length, 1, f);
+                    fclose (f);
+                } else {
+                    g_warning ("Faild to open %s for write.", priv->filename);
+                }
+
+                if (src != default_config)
+                    g_free (src);
             }
         }
     }
 
-	return object;
+    return object;
 }
 
 static void
@@ -406,17 +428,21 @@
     gdir = g_dir_open (TOMOEDATADIR, 0, NULL);
     while ((filename = g_dir_read_name (gdir))) {
         TomoeDict *dict;
+        gchar *path;
 
         if (!g_str_has_suffix (filename, ".xml"))
             continue;
-        if (tomoe_shelf_has_dict (shelf, filename))
+		path = g_build_filename(TOMOEDATADIR, filename, NULL);
+        if (tomoe_shelf_has_dict (shelf, path))
             continue;
 
-        dict = tomoe_dict_new (filename, FALSE);
+        dict = tomoe_dict_new (path, FALSE);
         if (dict) {
             tomoe_shelf_add_dict (shelf, dict);
             g_object_unref (dict);
         }
+
+        g_free (path);
     }
     g_dir_close (gdir);
 }


tomoe-cvs メーリングリストの案内
Back to archive index