Add .hct support to colors.conf import

This commit is contained in:
2026-04-08 17:47:51 -06:00
parent 73733e4176
commit 4f2938d957
4 changed files with 129 additions and 10 deletions

View File

@@ -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)
{

View File

@@ -48,5 +48,6 @@ gboolean zoitechat_gtk3_theme_service_remove_user_theme (const char *theme_id, G
char *zoitechat_gtk3_theme_pick_css_dir_for_minor (const char *theme_root, int preferred_minor);
char *zoitechat_gtk3_theme_pick_css_dir (const char *theme_root);
GPtrArray *zoitechat_gtk3_theme_build_inheritance_chain (const char *theme_root);
gboolean zoitechat_gtk3_theme_service_read_archive_text_file (const char *archive_path, const char *name, char **contents, GError **error);
#endif