Allow changing default language

This commit is contained in:
JustArchi
2017-01-08 05:32:59 +01:00
parent c636a2a5d5
commit 63bff8432a
6 changed files with 34 additions and 2 deletions

View File

@@ -54,6 +54,9 @@ namespace ArchiSteamFarm {
[JsonProperty(ObjectCreationHandling = ObjectCreationHandling.Replace, Required = Required.DisallowNull)]
internal readonly HashSet<uint> Blacklist = new HashSet<uint>(GlobalBlacklist);
[JsonProperty]
internal readonly string CurrentCulture = null;
[JsonProperty(Required = Required.DisallowNull)]
internal readonly bool Debug = false;

View File

@@ -765,6 +765,15 @@ namespace ArchiSteamFarm.Localization {
}
}
/// <summary>
/// Looks up a localized string similar to Your provided CurrentCulture is invalid, ASF will keep running with default one!.
/// </summary>
internal static string ErrorInvalidCurrentCulture {
get {
return ResourceManager.GetString("ErrorInvalidCurrentCulture", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to {0} is empty!.
/// </summary>

View File

@@ -690,4 +690,7 @@ StackTrace:
<data name="Welcome" xml:space="preserve">
<value>It looks like it's your first launch of the program, welcome!</value>
</data>
<data name="ErrorInvalidCurrentCulture" xml:space="preserve">
<value>Your provided CurrentCulture is invalid, ASF will keep running with default one!</value>
</data>
</root>

View File

@@ -25,6 +25,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
@@ -160,13 +161,13 @@ namespace ArchiSteamFarm {
Logging.InitLoggers();
ArchiLogger.LogGenericInfo("ASF V" + SharedInfo.Version);
await InitServices().ConfigureAwait(false);
if (!Runtime.IsRuntimeSupported) {
ArchiLogger.LogGenericError(Strings.WarningRuntimeUnsupported);
await Task.Delay(10 * 1000).ConfigureAwait(false);
}
await InitServices().ConfigureAwait(false);
// If debugging is on, we prepare debug directory prior to running
if (GlobalConfig.Debug) {
if (Directory.Exists(SharedInfo.DebugDirectory)) {
@@ -203,6 +204,17 @@ namespace ArchiSteamFarm {
ArchiLogger.LogGenericError(string.Format(Strings.ErrorGlobalConfigNotLoaded, globalConfigFile));
await Task.Delay(5 * 1000).ConfigureAwait(false);
Exit(1);
return;
}
if (!string.IsNullOrEmpty(GlobalConfig.CurrentCulture)) {
try {
// GetCultureInfo() would be better but we can't use it for specifying neutral cultures such as "en"
CultureInfo culture = CultureInfo.CreateSpecificCulture(GlobalConfig.CurrentCulture);
CultureInfo.DefaultThreadCurrentCulture = CultureInfo.DefaultThreadCurrentUICulture = culture;
} catch (CultureNotFoundException) {
ArchiLogger.LogGenericError(Strings.ErrorInvalidCurrentCulture);
}
}
string globalDatabaseFile = Path.Combine(SharedInfo.ConfigDirectory, SharedInfo.GlobalDatabaseFileName);
@@ -218,6 +230,7 @@ namespace ArchiSteamFarm {
ArchiLogger.LogGenericError(string.Format(Strings.ErrorDatabaseInvalid, globalDatabaseFile));
await Task.Delay(5 * 1000).ConfigureAwait(false);
Exit(1);
return;
}
ArchiWebHandler.Init();

View File

@@ -10,6 +10,7 @@
480730,
566020
],
"CurrentCulture": null,
"Debug": false,
"FarmingDelay": 15,
"GiftsLimiterDelay": 1,

View File

@@ -56,6 +56,9 @@ namespace ConfigGenerator {
[JsonProperty(ObjectCreationHandling = ObjectCreationHandling.Replace, Required = Required.DisallowNull)]
public List<uint> Blacklist { get; set; } = new List<uint>(GlobalBlacklist);
[JsonProperty]
public string CurrentCulture { get; set; } = null;
[Category("\tDebugging")]
[JsonProperty(Required = Required.DisallowNull)]
public bool Debug { get; set; } = false;