mirror of
https://github.com/ZoiteChat/zoitechat.git
synced 2026-05-16 21:50:20 +00:00
Add .hct support to colors.conf import
This commit is contained in:
@@ -1221,6 +1221,94 @@ extract_archive (const char *source, GError **error)
|
||||
#endif
|
||||
}
|
||||
|
||||
static char *
|
||||
path_find_first_file_recursive (const char *root, const char *name, int depth)
|
||||
{
|
||||
GDir *dir;
|
||||
const char *entry;
|
||||
|
||||
if (!root || !name || depth < 0 || !g_file_test (root, G_FILE_TEST_IS_DIR))
|
||||
return NULL;
|
||||
|
||||
{
|
||||
char *candidate = g_build_filename (root, name, NULL);
|
||||
if (g_file_test (candidate, G_FILE_TEST_IS_REGULAR))
|
||||
return candidate;
|
||||
g_free (candidate);
|
||||
}
|
||||
|
||||
if (depth == 0)
|
||||
return NULL;
|
||||
|
||||
dir = g_dir_open (root, 0, NULL);
|
||||
if (!dir)
|
||||
return NULL;
|
||||
|
||||
while ((entry = g_dir_read_name (dir)) != NULL)
|
||||
{
|
||||
char *child = g_build_filename (root, entry, NULL);
|
||||
char *found = NULL;
|
||||
|
||||
if (g_file_test (child, G_FILE_TEST_IS_DIR))
|
||||
found = path_find_first_file_recursive (child, name, depth - 1);
|
||||
g_free (child);
|
||||
if (found)
|
||||
{
|
||||
g_dir_close (dir);
|
||||
return found;
|
||||
}
|
||||
}
|
||||
|
||||
g_dir_close (dir);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gboolean
|
||||
zoitechat_gtk3_theme_service_read_archive_text_file (const char *archive_path, const char *name, char **contents, GError **error)
|
||||
{
|
||||
char *root;
|
||||
char *path;
|
||||
gboolean ok;
|
||||
GError *local_error = NULL;
|
||||
|
||||
if (contents)
|
||||
*contents = NULL;
|
||||
if (!archive_path || !*archive_path)
|
||||
return g_set_error_literal (error, G_FILE_ERROR, G_FILE_ERROR_INVAL, "No archive path provided."), FALSE;
|
||||
if (!name || !*name)
|
||||
return g_set_error_literal (error, G_FILE_ERROR, G_FILE_ERROR_INVAL, "No file name provided."), FALSE;
|
||||
if (!contents)
|
||||
return g_set_error_literal (error, G_FILE_ERROR, G_FILE_ERROR_INVAL, "No output buffer provided."), FALSE;
|
||||
|
||||
root = extract_archive (archive_path, error);
|
||||
if (!root)
|
||||
return FALSE;
|
||||
|
||||
path = path_find_first_file_recursive (root, name, 8);
|
||||
if (!path)
|
||||
{
|
||||
remove_tree (root);
|
||||
g_free (root);
|
||||
return g_set_error_literal (error, G_FILE_ERROR, G_FILE_ERROR_NOENT, "Requested file was not found in archive."), FALSE;
|
||||
}
|
||||
|
||||
ok = g_file_get_contents (path, contents, NULL, &local_error);
|
||||
g_free (path);
|
||||
remove_tree (root);
|
||||
g_free (root);
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
if (error)
|
||||
*error = local_error;
|
||||
else
|
||||
g_clear_error (&local_error);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
zoitechat_gtk3_theme_service_import (const char *source_path, char **imported_id, GError **error)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user