mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
Bugfix
This commit is contained in:
parent
c1a04fe5bf
commit
4cb95731bf
6 changed files with 82 additions and 14 deletions
|
|
@ -42,6 +42,7 @@ namespace MinecraftClient
|
||||||
{
|
{
|
||||||
private static McClient? client;
|
private static McClient? client;
|
||||||
public static string[]? startupargs;
|
public static string[]? startupargs;
|
||||||
|
public static readonly CultureInfo ActualCulture = CultureInfo.CurrentCulture;
|
||||||
|
|
||||||
public const string Version = MCHighestVersion;
|
public const string Version = MCHighestVersion;
|
||||||
public const string MCLowestVersion = "1.4.6";
|
public const string MCLowestVersion = "1.4.6";
|
||||||
|
|
@ -57,6 +58,8 @@ namespace MinecraftClient
|
||||||
/// </summary>
|
/// </summary>
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
|
InitCulture();
|
||||||
|
|
||||||
Task.Run(() =>
|
Task.Run(() =>
|
||||||
{
|
{
|
||||||
// "ToLower" require "CultureInfo" to be initialized on first run, which can take a lot of time.
|
// "ToLower" require "CultureInfo" to be initialized on first run, which can take a lot of time.
|
||||||
|
|
@ -110,10 +113,10 @@ namespace MinecraftClient
|
||||||
}
|
}
|
||||||
|
|
||||||
//Process ini configuration file
|
//Process ini configuration file
|
||||||
bool needWriteDefaultSetting, newlyGenerated = false;
|
bool loadSucceed, needWriteDefaultSetting, newlyGenerated = false;
|
||||||
if (args.Length >= 1 && File.Exists(args[0]) && Settings.ToLowerIfNeed(Path.GetExtension(args[0])) == ".ini")
|
if (args.Length >= 1 && File.Exists(args[0]) && Settings.ToLowerIfNeed(Path.GetExtension(args[0])) == ".ini")
|
||||||
{
|
{
|
||||||
needWriteDefaultSetting = Settings.LoadFromFile(args[0]);
|
(loadSucceed, needWriteDefaultSetting) = Settings.LoadFromFile(args[0]);
|
||||||
settingsIniPath = args[0];
|
settingsIniPath = args[0];
|
||||||
|
|
||||||
//remove ini configuration file from arguments array
|
//remove ini configuration file from arguments array
|
||||||
|
|
@ -123,19 +126,59 @@ namespace MinecraftClient
|
||||||
}
|
}
|
||||||
else if (File.Exists("MinecraftClient.ini"))
|
else if (File.Exists("MinecraftClient.ini"))
|
||||||
{
|
{
|
||||||
needWriteDefaultSetting = Settings.LoadFromFile("MinecraftClient.ini");
|
(loadSucceed, needWriteDefaultSetting) = Settings.LoadFromFile("MinecraftClient.ini");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
loadSucceed = true;
|
||||||
needWriteDefaultSetting = true;
|
needWriteDefaultSetting = true;
|
||||||
newlyGenerated = true;
|
newlyGenerated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (needWriteDefaultSetting)
|
if (!loadSucceed)
|
||||||
|
{
|
||||||
|
ConsoleInteractive.ConsoleReader.StopReadThread();
|
||||||
|
string command = " ";
|
||||||
|
while (command.Length > 0)
|
||||||
|
{
|
||||||
|
ConsoleIO.WriteLine(string.Empty);
|
||||||
|
ConsoleIO.WriteLineFormatted(Translations.Get("mcc.invaild_config", Config.Main.Advanced.InternalCmdChar.ToLogString()));
|
||||||
|
Translations.WriteLineFormatted("mcc.press_exit");
|
||||||
|
command = ConsoleInteractive.ConsoleReader.RequestImmediateInput().Trim();
|
||||||
|
if (command.Length > 0)
|
||||||
|
{
|
||||||
|
if (Config.Main.Advanced.InternalCmdChar.ToChar() != ' '
|
||||||
|
&& command[0] == Config.Main.Advanced.InternalCmdChar.ToChar())
|
||||||
|
command = command[1..];
|
||||||
|
|
||||||
|
if (command.StartsWith("exit") || command.StartsWith("quit"))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if (command.StartsWith("new"))
|
||||||
|
{
|
||||||
|
(string gameLanguage, string[] langList) = Translations.GetTranslationPriority();
|
||||||
|
Config.Main.Advanced.Language = gameLanguage;
|
||||||
|
Translations.LoadTranslationFile(langList);
|
||||||
|
|
||||||
|
WriteBackSettings(true);
|
||||||
|
ConsoleIO.WriteLineFormatted(Translations.Get("mcc.gen_new_config", settingsIniPath));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if (needWriteDefaultSetting)
|
||||||
{
|
{
|
||||||
(string gameLanguage, string[] langList) = Translations.GetTranslationPriority();
|
(string gameLanguage, string[] langList) = Translations.GetTranslationPriority();
|
||||||
Translations.LoadTranslationFile(langList);
|
Translations.LoadTranslationFile(langList);
|
||||||
Config.Main.Advanced.Language = gameLanguage;
|
Config.Main.Advanced.Language = gameLanguage;
|
||||||
|
|
||||||
WriteBackSettings(false);
|
WriteBackSettings(false);
|
||||||
if (newlyGenerated)
|
if (newlyGenerated)
|
||||||
ConsoleIO.WriteLineFormatted(Translations.TryGet("mcc.settings_generated"));
|
ConsoleIO.WriteLineFormatted(Translations.TryGet("mcc.settings_generated"));
|
||||||
|
|
@ -618,7 +661,7 @@ namespace MinecraftClient
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static void ReloadSettings()
|
public static void ReloadSettings()
|
||||||
{
|
{
|
||||||
if(Settings.LoadFromFile(settingsIniPath))
|
if(Settings.LoadFromFile(settingsIniPath).Item1)
|
||||||
ConsoleIO.WriteLine(Translations.TryGet("config.loading", settingsIniPath));
|
ConsoleIO.WriteLine(Translations.TryGet("config.loading", settingsIniPath));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -818,6 +861,15 @@ namespace MinecraftClient
|
||||||
return assembly.GetTypes().Where(t => String.Equals(t.Namespace, nameSpace, StringComparison.Ordinal)).ToArray();
|
return assembly.GetTypes().Where(t => String.Equals(t.Namespace, nameSpace, StringComparison.Ordinal)).ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void InitCulture()
|
||||||
|
{
|
||||||
|
CultureInfo culture = CultureInfo.CreateSpecificCulture("en-US");
|
||||||
|
CultureInfo.DefaultThreadCurrentCulture = culture;
|
||||||
|
CultureInfo.DefaultThreadCurrentUICulture = culture;
|
||||||
|
Thread.CurrentThread.CurrentCulture = culture;
|
||||||
|
Thread.CurrentThread.CurrentUICulture = culture;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Static initialization of build information, read from assembly information
|
/// Static initialization of build information, read from assembly information
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,8 @@ mcc.realms_available=You have access to the following Realms worlds
|
||||||
mcc.realms_join=Use realms:<index> as server IP to join a Realms world
|
mcc.realms_join=Use realms:<index> as server IP to join a Realms world
|
||||||
mcc.generator.generating=Generating {0} palette using the dataset: {1}
|
mcc.generator.generating=Generating {0} palette using the dataset: {1}
|
||||||
mcc.generator.done=Succesfully generated {0} palette using the dataset: {1}
|
mcc.generator.done=Succesfully generated {0} palette using the dataset: {1}
|
||||||
|
mcc.invaild_config=Failed to parse the settings file, enter "{0}new" to generate a new configuration.
|
||||||
|
mcc.gen_new_config=New configuration file "{0}" is generated.
|
||||||
|
|
||||||
[debug]
|
[debug]
|
||||||
# Messages from MCC Debug Mode
|
# Messages from MCC Debug Mode
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,8 @@ mcc.realms_available==您可以访问以下Realms世界
|
||||||
mcc.realms_join=请使用"realms:<序号>"作为服务器IP加入Realms世界
|
mcc.realms_join=请使用"realms:<序号>"作为服务器IP加入Realms世界
|
||||||
mcc.generator.generating=正在从 {1} 生成 {0} 信息。
|
mcc.generator.generating=正在从 {1} 生成 {0} 信息。
|
||||||
mcc.generator.done=已完成从 {0} 信息生成,使用 {1}
|
mcc.generator.done=已完成从 {0} 信息生成,使用 {1}
|
||||||
|
mcc.invaild_config=解析配置文件失败,输入 "{0}new" 以生成一个新的配置。
|
||||||
|
mcc.gen_new_config=已生成新的配置文件 "{0}" 。
|
||||||
|
|
||||||
[debug]
|
[debug]
|
||||||
# Messages from MCC Debug Mode
|
# Messages from MCC Debug Mode
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,8 @@ mcc.realms_available==您可以訪問以下Realms世界
|
||||||
mcc.realms_join=請使用"realms:<序號>"作為伺服器IP加入Realms世界
|
mcc.realms_join=請使用"realms:<序號>"作為伺服器IP加入Realms世界
|
||||||
mcc.generator.generating=正在從 {1} 生成 {0} 資訊。
|
mcc.generator.generating=正在從 {1} 生成 {0} 資訊。
|
||||||
mcc.generator.done=已完成從 {0} 資訊生成,使用 {1}
|
mcc.generator.done=已完成從 {0} 資訊生成,使用 {1}
|
||||||
|
mcc.invaild_config=解析配置檔案失敗,輸入 "{0}new" 以生成一個新的配置。
|
||||||
|
mcc.gen_new_config=已生成新的配置檔案 "{0}" 。
|
||||||
|
|
||||||
[debug]
|
[debug]
|
||||||
# Messages from MCC Debug Mode
|
# Messages from MCC Debug Mode
|
||||||
|
|
|
||||||
|
|
@ -121,7 +121,7 @@ namespace MinecraftClient
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool LoadFromFile(string filepath)
|
public static Tuple<bool, bool> LoadFromFile(string filepath)
|
||||||
{
|
{
|
||||||
TomlDocument document;
|
TomlDocument document;
|
||||||
try
|
try
|
||||||
|
|
@ -141,16 +141,16 @@ namespace MinecraftClient
|
||||||
File.Copy(filepath, newFilePath, true);
|
File.Copy(filepath, newFilePath, true);
|
||||||
ConsoleIO.WriteLineFormatted("§cPlease use the newly generated MinecraftClient.ini");
|
ConsoleIO.WriteLineFormatted("§cPlease use the newly generated MinecraftClient.ini");
|
||||||
ConsoleIO.WriteLineFormatted("§cThe old MinecraftClient.ini has been backed up as " + newFilePath);
|
ConsoleIO.WriteLineFormatted("§cThe old MinecraftClient.ini has been backed up as " + newFilePath);
|
||||||
return true;
|
ConsoleIO.WriteLine(Translations.GetOrNull("mcc.run_with_default_settings") ?? "\nMCC is running with default settings.");
|
||||||
|
return new(false, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch { }
|
catch { }
|
||||||
ConsoleIO.WriteLineFormatted(Translations.GetOrNull("config.load.fail") ?? "§cFailed to load settings:§r");
|
ConsoleIO.WriteLineFormatted(Translations.GetOrNull("config.load.fail") ?? "§cFailed to load settings:§r");
|
||||||
ConsoleIO.WriteLine(ex.Message);
|
ConsoleIO.WriteLine(ex.GetFullMessage());
|
||||||
ConsoleIO.WriteLine(Translations.GetOrNull("mcc.run_with_default_settings") ?? "\nMCC is running with default settings.");
|
return new(false, false);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
return false;
|
return new(true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void WriteToFile(string filepath, bool backupOldFile)
|
public static void WriteToFile(string filepath, bool backupOldFile)
|
||||||
|
|
@ -1210,4 +1210,14 @@ namespace MinecraftClient
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class ExceptionExtensions
|
||||||
|
{
|
||||||
|
public static string GetFullMessage(this Exception ex)
|
||||||
|
{
|
||||||
|
return ex.InnerException == null
|
||||||
|
? ex.Message
|
||||||
|
: ex.Message + "\n --> " + ex.InnerException.GetFullMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -104,9 +104,9 @@ namespace MinecraftClient
|
||||||
string gameLanguage = "en_gb";
|
string gameLanguage = "en_gb";
|
||||||
List<string> name = new();
|
List<string> name = new();
|
||||||
|
|
||||||
string systemLanguage = string.IsNullOrWhiteSpace(CultureInfo.CurrentCulture.Name)
|
string systemLanguage = string.IsNullOrWhiteSpace(Program.ActualCulture.Name)
|
||||||
? CultureInfo.CurrentCulture.Parent.Name
|
? Program.ActualCulture.Parent.Name
|
||||||
: CultureInfo.CurrentCulture.Name;
|
: Program.ActualCulture.Name;
|
||||||
|
|
||||||
switch (systemLanguage)
|
switch (systemLanguage)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue