From 54a3e811096ed39c1776e01e0ebf28a5dbca8826 Mon Sep 17 00:00:00 2001 From: AlastorFox MAC Date: Thu, 1 Oct 2026 02:53:02 +0300 Subject: [PATCH] Finally install extension on local folder --- Core/ExtensionManager.cs | 3 +-- Core/WebView2EnvironmentFactory.cs | 32 ++++++++++++++++++++++++++++++ UI/ExtensionsSettingsWindow.xaml | 2 +- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/Core/ExtensionManager.cs b/Core/ExtensionManager.cs index be5896d..ef4fb71 100644 --- a/Core/ExtensionManager.cs +++ b/Core/ExtensionManager.cs @@ -26,8 +26,7 @@ public sealed class ExtensionManager private readonly Dictionary _uiMetadata; private readonly HashSet _pinnedIds; - public static string ExtensionsRootPath => Path.Combine( - Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "FoxBrowser", "Extensions"); + public static string ExtensionsRootPath => WebView2EnvironmentFactory.PortableExtensionsPath; public ExtensionManager(CoreWebView2Profile profile) { diff --git a/Core/WebView2EnvironmentFactory.cs b/Core/WebView2EnvironmentFactory.cs index 804ddce..b4ad3d3 100644 --- a/Core/WebView2EnvironmentFactory.cs +++ b/Core/WebView2EnvironmentFactory.cs @@ -13,6 +13,8 @@ public sealed class WebView2EnvironmentFactory private const string ProductFolderName = "FoxBrowser"; private const string ProfileFolderName = "Profile"; private const string LegacyProfileFolderName = "WebView2"; + private const string ExtensionsFolderName = "Extensions"; + private const string LegacyExtensionsFolderName = "Extensions"; private const string ProtectedFolderNoticeMarker = "portable-profile-fallback-notified"; private readonly string _applicationDataRoot = Path.Combine( @@ -21,6 +23,9 @@ public sealed class WebView2EnvironmentFactory public string PortableProfilePath => Path.Combine(AppContext.BaseDirectory, ProfileFolderName); public string LegacyProfilePath => Path.Combine(_applicationDataRoot, LegacyProfileFolderName); + public static string PortableExtensionsPath => Path.Combine(AppContext.BaseDirectory, ExtensionsFolderName); + public static string LegacyExtensionsPath => Path.Combine( + Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), ProductFolderName, LegacyExtensionsFolderName); public bool UsingLegacyProfile { get; private set; } public string? MigrationError { get; private set; } @@ -88,6 +93,7 @@ public sealed class WebView2EnvironmentFactory } } + MigrateLegacyExtensionsIfNeeded(); return PortableProfilePath; } @@ -162,6 +168,32 @@ public sealed class WebView2EnvironmentFactory } } + private static void MigrateLegacyExtensionsIfNeeded() + { + if (!Directory.Exists(LegacyExtensionsPath) || !Directory.EnumerateFileSystemEntries(LegacyExtensionsPath).Any()) + return; + + if (Directory.Exists(PortableExtensionsPath) && Directory.EnumerateFileSystemEntries(PortableExtensionsPath).Any()) + return; + + try + { + CopyDirectoryContents(LegacyExtensionsPath, PortableExtensionsPath); + } + catch (IOException) + { + // Keep the legacy folder intact. A later startup can retry the migration. + } + catch (UnauthorizedAccessException) + { + // Keep the legacy folder intact and let the normal profile startup continue. + } + catch (SecurityException) + { + // Keep the legacy folder intact and let the normal profile startup continue. + } + } + private static void TryDeleteDirectory(string path) { try diff --git a/UI/ExtensionsSettingsWindow.xaml b/UI/ExtensionsSettingsWindow.xaml index 86e64a1..52b82c8 100644 --- a/UI/ExtensionsSettingsWindow.xaml +++ b/UI/ExtensionsSettingsWindow.xaml @@ -15,7 +15,7 @@ - +