mirror of
https://github.com/ZoiteChat/zoitechat.git
synced 2026-03-19 12:10:19 +00:00
refactor: coord prefs/theme saves in one staged path; drop broken manager wrappers
This commit is contained in:
@@ -1009,15 +1009,51 @@ load_config (void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
save_config (void)
|
||||
static int
|
||||
save_config_write_to_fd (int fh)
|
||||
{
|
||||
int fh, i;
|
||||
char *config, *new_config;
|
||||
int i;
|
||||
|
||||
if (!cfg_put_str (fh, "version", PACKAGE_VERSION))
|
||||
return 0;
|
||||
|
||||
i = 0;
|
||||
do
|
||||
{
|
||||
switch (vars[i].type)
|
||||
{
|
||||
case TYPE_STR:
|
||||
if (!cfg_put_str (fh, vars[i].name, (char *) &prefs + vars[i].offset))
|
||||
return 0;
|
||||
break;
|
||||
case TYPE_INT:
|
||||
case TYPE_BOOL:
|
||||
if (!cfg_put_int (fh, *((int *) &prefs + vars[i].offset), vars[i].name))
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (vars[i].after_update != NULL)
|
||||
vars[i].after_update();
|
||||
i++;
|
||||
}
|
||||
while (vars[i].name);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
save_config_prepare (char **temp_path)
|
||||
{
|
||||
int fh;
|
||||
char *config;
|
||||
char *new_config;
|
||||
|
||||
if (check_config_dir () != 0)
|
||||
make_config_dirs ();
|
||||
|
||||
if (!temp_path)
|
||||
return 0;
|
||||
|
||||
config = default_file ();
|
||||
new_config = g_strconcat (config, ".new", NULL);
|
||||
|
||||
@@ -1028,63 +1064,67 @@ save_config (void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!cfg_put_str (fh, "version", PACKAGE_VERSION))
|
||||
if (!save_config_write_to_fd (fh))
|
||||
{
|
||||
close (fh);
|
||||
g_free (new_config);
|
||||
return 0;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
do
|
||||
{
|
||||
switch (vars[i].type)
|
||||
{
|
||||
case TYPE_STR:
|
||||
if (!cfg_put_str (fh, vars[i].name, (char *) &prefs + vars[i].offset))
|
||||
{
|
||||
close (fh);
|
||||
g_free (new_config);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case TYPE_INT:
|
||||
case TYPE_BOOL:
|
||||
if (!cfg_put_int (fh, *((int *) &prefs + vars[i].offset), vars[i].name))
|
||||
{
|
||||
close (fh);
|
||||
g_free (new_config);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (vars[i].after_update != NULL)
|
||||
{
|
||||
vars[i].after_update();
|
||||
}
|
||||
i++;
|
||||
}
|
||||
while (vars[i].name);
|
||||
|
||||
if (close (fh) == -1)
|
||||
{
|
||||
g_free (new_config);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
g_unlink (config); /* win32 can't rename to an existing file */
|
||||
#endif
|
||||
if (g_rename (new_config, config) == -1)
|
||||
{
|
||||
g_free (new_config);
|
||||
*temp_path = new_config;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
save_config_finalize (const char *temp_path)
|
||||
{
|
||||
char *config;
|
||||
|
||||
if (!temp_path)
|
||||
return 0;
|
||||
|
||||
config = default_file ();
|
||||
#ifdef WIN32
|
||||
g_unlink (config);
|
||||
#endif
|
||||
if (g_rename (temp_path, config) == -1)
|
||||
return 0;
|
||||
}
|
||||
g_free (new_config);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void
|
||||
save_config_discard (const char *temp_path)
|
||||
{
|
||||
if (!temp_path)
|
||||
return;
|
||||
|
||||
g_unlink (temp_path);
|
||||
}
|
||||
|
||||
int
|
||||
save_config (void)
|
||||
{
|
||||
char *temp_path = NULL;
|
||||
int result;
|
||||
|
||||
if (!save_config_prepare (&temp_path))
|
||||
return 0;
|
||||
|
||||
result = save_config_finalize (temp_path);
|
||||
if (!result)
|
||||
save_config_discard (temp_path);
|
||||
g_free (temp_path);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static void
|
||||
set_showval (session *sess, const struct prefs *var, char *tbuf)
|
||||
{
|
||||
|
||||
@@ -43,6 +43,9 @@ int make_config_dirs (void);
|
||||
int make_dcc_dirs (void);
|
||||
int load_config (void);
|
||||
int save_config (void);
|
||||
int save_config_prepare (char **temp_path);
|
||||
int save_config_finalize (const char *temp_path);
|
||||
void save_config_discard (const char *temp_path);
|
||||
void list_free (GSList ** list);
|
||||
void list_loadconf (char *file, GSList ** list, char *defaultconf);
|
||||
int list_delentry (GSList ** list, char *name);
|
||||
|
||||
Reference in New Issue
Block a user