Improved the layering of the plugin archive file extension constant

This commit is contained in:
Thorsten Sommer 2026-08-06 10:04:35 +02:00
parent 76b7c588de
commit 1095417301
Signed by untrusted user who does not match committer: tsommer
GPG Key ID: 371BBA77A02C0108
4 changed files with 15 additions and 12 deletions

View File

@ -559,7 +559,7 @@ public partial class Plugins : MSGComponentBase
switch (archivePaths.Count)
{
case 0:
await this.MessageBus.SendWarning(new(Icons.Material.Filled.ReportProblem, string.Format(this.T("Please drop a plugin archive with the extension {0} or .zip."), PluginShareService.PLUGIN_FILE_EXTENSION)));
await this.MessageBus.SendWarning(new(Icons.Material.Filled.ReportProblem, string.Format(this.T("Please drop a plugin archive with the extension {0} or .zip."), PluginArchive.PLUGIN_FILE_EXTENSION)));
return;
case > 1:

View File

@ -4,6 +4,16 @@ namespace AIStudio.Tools.PluginSystem;
public static class PluginArchive
{
/// <summary>
/// The file extension of plugin archives.
/// </summary>
/// <remarks>
/// Keep in sync with SHARE_FILE_EXTENSION in runtime/src/share_sheet.rs: the runtime only hands
/// archives with this extension to the native share sheet.
/// </remarks>
public const string PLUGIN_FILE_EXTENSION = ".mwplugin";
// Compatibility shim for Windows-created ZIPs with backslashes in entry names (dotnet/runtime#27620);
// remove after dotnet/runtime#27620 and #41914 are fixed.
// See documentation/compatibility-shims/2026-07-plugin-archive-zip-backslashes.md.

View File

@ -1,5 +1,4 @@
using AIStudio.Tools.PluginSystem;
using AIStudio.Tools.Services;
// ReSharper disable MemberCanBePrivate.Global
@ -83,7 +82,7 @@ public static class FileTypes
// Other standalone types
public static readonly FileTypeFilter CERTIFICATE_BUNDLE = FileTypeFilter.Leaf(TB("Certificate bundle"), "pem", "crt", "cer");
public static readonly FileTypeFilter EXECUTABLES = FileTypeFilter.Leaf(TB("Executable"), "exe", "app", "bin", "appimage");
public static readonly FileTypeFilter PLUGIN_ARCHIVE = FileTypeFilter.Leaf(TB("Plugin archive"), PluginShareService.PLUGIN_FILE_EXTENSION.TrimStart('.'), "zip");
public static readonly FileTypeFilter PLUGIN_ARCHIVE = FileTypeFilter.Leaf(TB("Plugin archive"), PluginArchive.PLUGIN_FILE_EXTENSION.TrimStart('.'), "zip");
public static FileTypeFilter? AsOneFileType(params FileTypeFilter[]? types)
{

View File

@ -11,12 +11,6 @@ public sealed class PluginShareService(NativeShareService nativeShareService, Ru
private static string TB(string fallbackEN) => I18N.I.T(fallbackEN, typeof(PluginShareService).Namespace, nameof(PluginShareService));
/// <remarks>
/// Keep in sync with SHARE_FILE_EXTENSION in runtime/src/share_sheet.rs: the runtime only hands
/// archives with this extension to the native share sheet.
/// </remarks>
public const string PLUGIN_FILE_EXTENSION = ".mwplugin";
private const string PLUGIN_FILE_NAME = "plugin.lua";
/// <remarks>
@ -69,7 +63,7 @@ public sealed class PluginShareService(NativeShareService nativeShareService, Ru
/// <returns>The share result, including the chosen archive path when successful.</returns>
private async Task<PluginShareResult> ExportAsync(IAvailablePlugin plugin, string pluginRoot, CancellationToken token)
{
var suggestedFileName = $"{CreateSafeFileNamePrefix(plugin.Name)}{PLUGIN_FILE_EXTENSION}";
var suggestedFileName = $"{CreateSafeFileNamePrefix(plugin.Name)}{PluginArchive.PLUGIN_FILE_EXTENSION}";
var saveResponse = await rustService.SaveFile(TB("Export plugin archive"), [FileTypes.PLUGIN_ARCHIVE], suggestedFileName);
if (saveResponse.UserCancelled)
return new(false, plugin.Name, string.Empty, string.Empty, true);
@ -116,7 +110,7 @@ public sealed class PluginShareService(NativeShareService nativeShareService, Ru
private async Task<PluginShareResult> ShareViaNativeSheetAsync(IAvailablePlugin plugin, string pluginRoot, CancellationToken token)
{
var archiveDirectory = Path.Join(Path.GetTempPath(), TEMPORARY_ARCHIVE_DIRECTORY);
var archivePath = Path.Join(archiveDirectory, $"{CreateSafeFileNamePrefix(plugin.Name)}-{plugin.Id:N}-{Guid.NewGuid():N}{PLUGIN_FILE_EXTENSION}");
var archivePath = Path.Join(archiveDirectory, $"{CreateSafeFileNamePrefix(plugin.Name)}-{plugin.Id:N}-{Guid.NewGuid():N}{PluginArchive.PLUGIN_FILE_EXTENSION}");
try
{
@ -193,7 +187,7 @@ public sealed class PluginShareService(NativeShareService nativeShareService, Ru
private void CleanUpExpiredArchives(string archiveDirectory)
{
var expiry = DateTime.UtcNow.AddHours(-TEMPORARY_ARCHIVE_RETENTION_HOURS);
foreach (var archivePath in Directory.EnumerateFiles(archiveDirectory, $"*{PLUGIN_FILE_EXTENSION}", SearchOption.TopDirectoryOnly))
foreach (var archivePath in Directory.EnumerateFiles(archiveDirectory, $"*{PluginArchive.PLUGIN_FILE_EXTENSION}", SearchOption.TopDirectoryOnly))
{
try
{