mirror of
https://github.com/achiez/NebulaAuth-Steam-Desktop-Authenticator-by-Achies.git
synced 2026-07-25 14:24:32 +00:00
8ff960189e
- Update: Added "Copy Password" to Mafile context menu (if available) - Update: "Save Password" now pre-fills the current password in the "Login Again" dialog when encryption is enabled - Fix: Prevented overlapping confirmation cycles in AutoConfirmer - Fix: Added a Snackbar notification when a confirmation cycle is skipped due to a too frequent timer interval - Fix: Fixed a rare bug where the previous proxy was used instead of the current one during session refresh - Fix: Corrected "Session Permanently Expired" message showing on unrelated errors (e.g. network issues) - UI-Fix: Fixed visual glitch where proxy input appeared non-empty when switching to a mafile-specific proxy - Cleanup: Refactored and cleaned up codebase, improved styling and formatting via ReSharper
111 lines
3.0 KiB
C#
111 lines
3.0 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
using CodingSeb.Localization;
|
|
using CodingSeb.Localization.Loaders;
|
|
|
|
namespace NebulaAuth.Core;
|
|
|
|
public static class LocManager
|
|
{
|
|
public const string CODE_BEHIND_PATH_PART = "CodeBehind";
|
|
public const string COMMON_PATH_PART = "Common";
|
|
|
|
public static void SetApplicationLocalization(LocalizationLanguage language)
|
|
{
|
|
Loc.Instance.CurrentLanguage = GetLanguageCode(language);
|
|
//Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(GetLanguageCode(language));
|
|
//Thread.CurrentThread.CurrentCulture= CultureInfo.GetCultureInfo(GetLanguageCode(language));
|
|
}
|
|
|
|
public static string GetCurrentLanguageCode()
|
|
{
|
|
return Loc.Instance.CurrentLanguage;
|
|
}
|
|
|
|
public static string GetLanguageCode(LocalizationLanguage language)
|
|
{
|
|
return language switch
|
|
{
|
|
LocalizationLanguage.English => "en",
|
|
LocalizationLanguage.Russian => "ru",
|
|
LocalizationLanguage.Ukrainian => "ua",
|
|
_ => throw new ArgumentOutOfRangeException(nameof(language), language, null)
|
|
};
|
|
}
|
|
|
|
|
|
public static void Init()
|
|
{
|
|
Loc.LogOutMissingTranslations = true;
|
|
|
|
LocalizationLoader.Instance.FileLanguageLoaders.Add(new JsonFileLoader());
|
|
|
|
ReloadFiles();
|
|
}
|
|
|
|
public static void ReloadFiles()
|
|
{
|
|
var exampleFileFileName = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!,
|
|
"localization.loc.json");
|
|
LocalizationLoader.Instance.ClearAllTranslations();
|
|
LocalizationLoader.Instance.AddFile(exampleFileFileName);
|
|
}
|
|
|
|
public static string? GetCodeBehind(params string[] path)
|
|
{
|
|
return GetConcat(CODE_BEHIND_PATH_PART, path);
|
|
}
|
|
|
|
public static string GetCodeBehindOrDefault(string def, params string[] path)
|
|
{
|
|
return GetCodeBehind(path) ?? def;
|
|
}
|
|
|
|
public static string? GetCommon(params string[] path)
|
|
{
|
|
return GetConcat(COMMON_PATH_PART, path);
|
|
}
|
|
|
|
public static string GetCommonOrDefault(string def, params string[] path)
|
|
{
|
|
return GetCommon(path) ?? def;
|
|
}
|
|
|
|
|
|
public static string? Get(params string[] path)
|
|
{
|
|
var sb = new StringBuilder();
|
|
foreach (var part in path)
|
|
{
|
|
sb.Append('.');
|
|
sb.Append(part);
|
|
}
|
|
|
|
sb.Remove(0, 1);
|
|
var fullPath = sb.ToString();
|
|
var message = Loc.Tr(fullPath, "~|*ABSENT|~");
|
|
return message == "~|*ABSENT|~" ? null : message;
|
|
}
|
|
|
|
public static string GetOrDefault(string def, params string[] path)
|
|
{
|
|
return Get(path) ?? def;
|
|
}
|
|
|
|
private static string? GetConcat(string first, string[] path)
|
|
{
|
|
var newArray = new string[path.Length + 1];
|
|
newArray[0] = first;
|
|
Array.Copy(path, 0, newArray, 1, path.Length);
|
|
return Get(newArray);
|
|
}
|
|
}
|
|
|
|
public enum LocalizationLanguage
|
|
{
|
|
English,
|
|
Russian,
|
|
Ukrainian
|
|
} |