#include <glib.h>
Go to the source code of this file.
Functions | |
G_BEGIN_DECLS gboolean | export_registry (GConfClient *client, const char *filename, const char **paths, gboolean force_defaults) |
Export configuration to INI file. |
G_BEGIN_DECLS gboolean export_registry | ( | GConfClient * | client, | |
const char * | filename, | |||
const char ** | paths, | |||
gboolean | force_defaults | |||
) |
Export configuration to INI file.
Description: Copyright (C) 2008 iRex Technologies B.V. All rights reserved.---------------------------------------------------------------------------
Name : export_registry
client | GConf client handle | |
filename | Fully qualified name of config file | |
paths | Array of paths | |
force_defaults | Set to TRUE to force writing schema defaults, FALSE otherwise |
--------------------------------------------------------------------------
Definition at line 88 of file export.c.
References create_registry(), export_device_info(), and export_gconf().
Referenced by main().
00089 { 00090 GKeyFile *key_file = NULL; 00091 FILE *inifile = NULL; 00092 GError *error = NULL; 00093 00094 // load ini file from disk 00095 // 00096 key_file = g_key_file_new(); 00097 if (!g_key_file_load_from_file(key_file, filename, G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS, &error)) 00098 { 00099 if (error->code == G_KEY_FILE_ERROR_PARSE) 00100 { 00101 g_error_free(error); 00102 error = NULL; 00103 00104 g_print("Error parsing file, backup as: %s.old\n", filename); 00105 // parse error loading ini, backup old 00106 gchar *filename_old = g_strconcat(filename, ".old", NULL); 00107 unlink(filename_old); 00108 rename(filename, filename_old); 00109 g_free(filename_old); 00110 } 00111 00112 g_print("File does not exist, create new: %s\n", filename); 00113 if (!create_registry(filename)) 00114 { 00115 g_print("Error creating new file: %s\n", filename); 00116 return FALSE; 00117 } 00118 } 00119 00120 // write system information 00121 // 00122 export_device_info(key_file); 00123 00124 // recurse through registry to load current entries 00125 // 00126 gint i; 00127 for (i = 0; paths[i]; i++) 00128 { 00129 export_gconf(client, key_file, paths[i], force_defaults); 00130 } 00131 00132 // read pointercal to load calibation settings 00133 #if 0 // disabled see PR3439 00134 export_pointercal(key_file); 00135 #endif 00136 00137 // write updated ini file back to disk 00138 // 00139 inifile = fopen(filename, "w"); 00140 if (inifile == NULL) 00141 { 00142 g_print("Error writing file: %s\n", filename); 00143 g_key_file_free(key_file); 00144 return FALSE; 00145 } 00146 else 00147 { 00148 fprintf(inifile, "%s", g_key_file_to_data(key_file, NULL, NULL)); 00149 fclose(inifile); 00150 } 00151 00152 g_key_file_free(key_file); 00153 00154 return TRUE; 00155 }