Add region-based sanctions

pull/965/head
Oleksii Holub 2 years ago
parent 9639b6c550
commit 001ea7e495

@ -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);
}
}

@ -9,37 +9,41 @@ using System.Windows;
using System.Windows.Threading;
#endif
namespace DiscordChatExporter.Gui
namespace DiscordChatExporter.Gui;
public class Bootstrapper : Bootstrapper<RootViewModel>
{
public class Bootstrapper : Bootstrapper<RootViewModel>
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<SettingsService>().ToSelf().InSingletonScope();
// Bind settings as singleton
builder.Bind<SettingsService>().ToSelf().InSingletonScope();
// Bind view model factory
builder.Bind<IViewModelFactory>().ToAbstractFactory();
}
// Bind view model factory
builder.Bind<IViewModelFactory>().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
}

@ -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);
}
}
Loading…
Cancel
Save