diff --git a/IntroSkipper/Helper/LegacyMigrations.cs b/IntroSkipper/Helper/LegacyMigrations.cs
index 7007c79..8f51976 100644
--- a/IntroSkipper/Helper/LegacyMigrations.cs
+++ b/IntroSkipper/Helper/LegacyMigrations.cs
@@ -108,55 +108,81 @@ internal static class LegacyMigrations
private static void InjectSkipButton(Plugin plugin, string webPath, ILogger logger)
{
- string pattern;
+ string pattern = @"";
-
- if (contents.Contains(scriptTag, StringComparison.OrdinalIgnoreCase))
- {
- logger.LogInformation("The skip button has already been injected.");
- return;
- }
-
- pattern = @"";
+ if (contents.Contains(scriptTag, StringComparison.OrdinalIgnoreCase))
+ {
+ logger.LogInformation("The skip button has already been injected.");
+ return;
+ }
+
+ contents = Regex.Replace(contents, pattern, string.Empty, RegexOptions.IgnoreCase);
+
+ Regex headEnd = new Regex(@"", RegexOptions.IgnoreCase, TimeSpan.FromSeconds(1));
+ contents = headEnd.Replace(contents, scriptTag + "", 1);
+
+ File.WriteAllText(indexPath, contents);
+ logger.LogInformation("Skip button added successfully.");
+ }
+ catch (UnauthorizedAccessException)
{
WarningManager.SetFlag(PluginWarning.UnableToAddSkipButton);
- logger.LogError("Failed to add skip button to web interface. See https://github.com/intro-skipper/intro-skipper/wiki/Troubleshooting#skip-button-is-not-visible for the most common issues. Error: {Error}", ex);
+ logger.LogError("Failed to add skip button to web interface. See https://github.com/intro-skipper/intro-skipper/wiki/Troubleshooting#skip-button-is-not-visible for the most common issues.");
+ }
+ catch (IOException)
+ {
+ WarningManager.SetFlag(PluginWarning.UnableToAddSkipButton);
+ logger.LogError("Failed to add skip button to web interface. See https://github.com/intro-skipper/intro-skipper/wiki/Troubleshooting#skip-button-is-not-visible for the most common issues.");
}
}
diff --git a/IntroSkipper/Helper/OperatingSystem.cs b/IntroSkipper/Helper/OperatingSystem.cs
new file mode 100644
index 0000000..995caac
--- /dev/null
+++ b/IntroSkipper/Helper/OperatingSystem.cs
@@ -0,0 +1,42 @@
+// Copyright (C) 2024 Intro-Skipper contributors
+// SPDX-License-Identifier: GPL-3.0-only.
+
+using System.IO;
+using System.Runtime.InteropServices;
+
+namespace IntroSkipper.Helper
+{
+ ///
+ /// Provides methods to determine the operating system.
+ ///
+ public static class OperatingSystem
+ {
+ ///
+ /// Determines if the current operating system is Windows.
+ ///
+ /// True if the current operating system is Windows; otherwise, false.
+ public static bool IsWindows() =>
+ RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
+
+ ///
+ /// Determines if the current operating system is macOS.
+ ///
+ /// True if the current operating system is macOS; otherwise, false.
+ public static bool IsMacOS() =>
+ RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
+
+ ///
+ /// Determines if the current operating system is Linux.
+ ///
+ /// True if the current operating system is Linux; otherwise, false.
+ public static bool IsLinux() =>
+ RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
+
+ ///
+ /// Determines if the current environment is running in Docker.
+ ///
+ /// True if running in a Docker container; otherwise, false.
+ public static bool IsDocker() =>
+ File.Exists("/.dockerenv") || File.Exists("/run/.containerenv");
+ }
+}