fixes for importing themes.

This commit is contained in:
2026-01-16 22:42:18 -07:00
parent 2c349deee2
commit f473f3d4b9

View File

@@ -259,7 +259,6 @@ zoitechat_import_theme (const char *path, GError **error)
#ifdef WIN32 #ifdef WIN32
char *command = NULL; char *command = NULL;
char *powershell = NULL; char *powershell = NULL;
char *extractor = NULL;
#endif #endif
if (!path) if (!path)
@@ -295,17 +294,7 @@ zoitechat_import_theme (const char *path, GError **error)
return FALSE; return FALSE;
} }
argv[4] = theme_dir;
#ifdef WIN32 #ifdef WIN32
extractor = g_find_program_in_path ("unzip");
if (extractor)
{
argv[0] = extractor;
ok = g_spawn_sync (NULL, argv, NULL, 0, NULL, NULL,
NULL, NULL, &status, error);
}
else
{
powershell = g_find_program_in_path ("powershell.exe"); powershell = g_find_program_in_path ("powershell.exe");
if (!powershell) if (!powershell)
powershell = g_find_program_in_path ("powershell"); powershell = g_find_program_in_path ("powershell");
@@ -340,7 +329,26 @@ zoitechat_import_theme (const char *path, GError **error)
} }
g_string_append_c (escaped_dir, '\''); g_string_append_c (escaped_dir, '\'');
command = g_strdup_printf ("Expand-Archive -LiteralPath %s -DestinationPath %s -Force", command = g_strdup_printf (
"Add-Type -AssemblyName WindowsBase; "
"$ErrorActionPreference='Stop'; "
"$package=[System.IO.Packaging.Package]::Open(%s); "
"try { "
"foreach ($part in $package.GetParts()) { "
"$relative=$part.Uri.OriginalString.TrimStart('/'); "
"if ([string]::IsNullOrEmpty($relative)) { continue }; "
"$destPath=[System.IO.Path]::Combine(%s, $relative); "
"$destDir=[System.IO.Path]::GetDirectoryName($destPath); "
"if ($destDir -and -not (Test-Path -LiteralPath $destDir)) { "
"[System.IO.Directory]::CreateDirectory($destDir) | Out-Null "
"}; "
"$partStream=$part.GetStream(); "
"$fileStream=[System.IO.File]::Open($destPath,[System.IO.FileMode]::Create,[System.IO.FileAccess]::Write); "
"$partStream.CopyTo($fileStream); "
"$fileStream.Dispose(); "
"$partStream.Dispose(); "
"} "
"} finally { $package.Close(); }",
escaped_path->str, escaped_path->str,
escaped_dir->str); escaped_dir->str);
g_string_free (escaped_path, TRUE); g_string_free (escaped_path, TRUE);
@@ -352,8 +360,8 @@ zoitechat_import_theme (const char *path, GError **error)
NULL, NULL, &status, error); NULL, NULL, &status, error);
} }
} }
}
#else #else
argv[4] = theme_dir;
ok = g_spawn_sync (NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, ok = g_spawn_sync (NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL,
NULL, NULL, &status, error); NULL, NULL, &status, error);
#endif #endif
@@ -362,7 +370,6 @@ zoitechat_import_theme (const char *path, GError **error)
#ifdef WIN32 #ifdef WIN32
g_free (command); g_free (command);
g_free (powershell); g_free (powershell);
g_free (extractor);
#endif #endif
g_free (theme_dir); g_free (theme_dir);
g_free (basename); g_free (basename);
@@ -375,7 +382,6 @@ zoitechat_import_theme (const char *path, GError **error)
#ifdef WIN32 #ifdef WIN32
g_free (command); g_free (command);
g_free (powershell); g_free (powershell);
g_free (extractor);
#endif #endif
g_free (theme_dir); g_free (theme_dir);
g_free (basename); g_free (basename);
@@ -386,7 +392,6 @@ zoitechat_import_theme (const char *path, GError **error)
#ifdef WIN32 #ifdef WIN32
g_free (command); g_free (command);
g_free (powershell); g_free (powershell);
g_free (extractor);
#endif #endif
g_free (theme_dir); g_free (theme_dir);