diff --git a/DiscordChatExporter.Cli/Sanctions.cs b/DiscordChatExporter.Cli/Sanctions.cs new file mode 100644 index 0000000..242ef29 --- /dev/null +++ b/DiscordChatExporter.Cli/Sanctions.cs @@ -0,0 +1,49 @@ +using System; +using System.Globalization; +using System.Linq; +using System.Runtime.CompilerServices; + +namespace DiscordChatExporter.Cli; + +public static class Sanctions +{ + [ModuleInitializer] + internal static void Verify() + { + var isSkipped = string.Equals( + Environment.GetEnvironmentVariable("RUSNI"), + "PYZDA", + StringComparison.OrdinalIgnoreCase + ); + + if (isSkipped) + return; + + var isSanctioned = new[] + { + CultureInfo.CurrentCulture, + CultureInfo.CurrentUICulture, + CultureInfo.InstalledUICulture, + CultureInfo.DefaultThreadCurrentCulture, + CultureInfo.DefaultThreadCurrentUICulture + }.Any(c => + c is not null && ( + c.Name.Contains("-ru", StringComparison.OrdinalIgnoreCase) || + c.Name.Contains("-by", StringComparison.OrdinalIgnoreCase) + ) + ); + + if (!isSanctioned) + return; + + Console.ForegroundColor = ConsoleColor.Red; + Console.Error.WriteLine( + "You cannot use this software on the territory of a terrorist state. " + + "Set the environment variable `RUSNI=PYZDA` if you wish to override this check." + ); + + Console.ResetColor(); + + Environment.Exit(0xFACC); + } +} \ No newline at end of file diff --git a/DiscordChatExporter.Gui/Bootstrapper.cs b/DiscordChatExporter.Gui/Bootstrapper.cs index 5fb3533..9024665 100644 --- a/DiscordChatExporter.Gui/Bootstrapper.cs +++ b/DiscordChatExporter.Gui/Bootstrapper.cs @@ -9,37 +9,41 @@ using System.Windows; using System.Windows.Threading; #endif -namespace DiscordChatExporter.Gui +namespace DiscordChatExporter.Gui; + +public class Bootstrapper : Bootstrapper { - public class Bootstrapper : Bootstrapper + protected override void OnStart() { - protected override void OnStart() - { - base.OnStart(); + base.OnStart(); - // Set default theme - // (preferred theme will be chosen later, once the settings are loaded) - App.SetLightTheme(); - } + // Set default theme + // (preferred theme will be set later, once the settings are loaded) + App.SetLightTheme(); + } - protected override void ConfigureIoC(IStyletIoCBuilder builder) - { - base.ConfigureIoC(builder); + protected override void ConfigureIoC(IStyletIoCBuilder builder) + { + base.ConfigureIoC(builder); - // Bind settings as singleton - builder.Bind().ToSelf().InSingletonScope(); + // Bind settings as singleton + builder.Bind().ToSelf().InSingletonScope(); - // Bind view model factory - builder.Bind().ToAbstractFactory(); - } + // Bind view model factory + builder.Bind().ToAbstractFactory(); + } #if !DEBUG - protected override void OnUnhandledException(DispatcherUnhandledExceptionEventArgs e) - { - base.OnUnhandledException(e); - - MessageBox.Show(e.Exception.ToString(), "Error occured", MessageBoxButton.OK, MessageBoxImage.Error); - } -#endif + protected override void OnUnhandledException(DispatcherUnhandledExceptionEventArgs e) + { + base.OnUnhandledException(e); + + MessageBox.Show( + e.Exception.ToString(), + "Error occured", + MessageBoxButton.OK, + MessageBoxImage.Error + ); } +#endif } \ No newline at end of file diff --git a/DiscordChatExporter.Gui/Sanctions.cs b/DiscordChatExporter.Gui/Sanctions.cs new file mode 100644 index 0000000..13f81cf --- /dev/null +++ b/DiscordChatExporter.Gui/Sanctions.cs @@ -0,0 +1,50 @@ +using System; +using System.Globalization; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Windows; + +namespace DiscordChatExporter.Gui; + +public static class Sanctions +{ + [ModuleInitializer] + internal static void Verify() + { + var isSkipped = string.Equals( + Environment.GetEnvironmentVariable("RUSNI"), + "PYZDA", + StringComparison.OrdinalIgnoreCase + ); + + if (isSkipped) + return; + + var isSanctioned = new[] + { + CultureInfo.CurrentCulture, + CultureInfo.CurrentUICulture, + CultureInfo.InstalledUICulture, + CultureInfo.DefaultThreadCurrentCulture, + CultureInfo.DefaultThreadCurrentUICulture + }.Any(c => + c is not null && ( + c.Name.Contains("-ru", StringComparison.OrdinalIgnoreCase) || + c.Name.Contains("-by", StringComparison.OrdinalIgnoreCase) + ) + ); + + if (!isSanctioned) + return; + + MessageBox.Show( + "You cannot use this software on the territory of a terrorist state. " + + "Set the environment variable `RUSNI=PYZDA` if you wish to override this check.", + "Sanctioned region", + MessageBoxButton.OK, + MessageBoxImage.Error + ); + + Environment.Exit(0xFACC); + } +} \ No newline at end of file