mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
Automatically download en_GB.lang from Mojang
- Removed en_US.lang checking since it does not exist anymore in assets - If Minecraft 1.6+ is not installed, download en_GB.lang from Mojang's servers
This commit is contained in:
parent
f6de2e4aee
commit
c826dd3b79
2 changed files with 50 additions and 8 deletions
|
|
@ -96,14 +96,37 @@ namespace MinecraftClient
|
||||||
TranslationRules["commands.message.display.outgoing"] = "§7You whisper to %s: %s";
|
TranslationRules["commands.message.display.outgoing"] = "§7You whisper to %s: %s";
|
||||||
|
|
||||||
//Use translations from Minecraft assets if translation file is not found but a copy of the game is installed?
|
//Use translations from Minecraft assets if translation file is not found but a copy of the game is installed?
|
||||||
if (!System.IO.File.Exists(Settings.TranslationsFile) //Try en_US.lang
|
if (!System.IO.File.Exists(Settings.TranslationsFile) //Try en_GB.lang
|
||||||
&& System.IO.File.Exists(Settings.TranslationsFile_FromMCDir))
|
&& System.IO.File.Exists(Settings.TranslationsFile_FromMCDir))
|
||||||
{ Settings.TranslationsFile = Settings.TranslationsFile_FromMCDir; }
|
{
|
||||||
if (!System.IO.File.Exists(Settings.TranslationsFile) //Still not found? try en_GB.lang
|
Settings.TranslationsFile = Settings.TranslationsFile_FromMCDir;
|
||||||
&& System.IO.File.Exists(Settings.TranslationsFile_FromMCDir_Alt))
|
Console.ForegroundColor = ConsoleColor.DarkGray;
|
||||||
{ Settings.TranslationsFile = Settings.TranslationsFile_FromMCDir_Alt; }
|
ConsoleIO.WriteLine("Using en_GB.lang from your Minecraft directory.");
|
||||||
|
Console.ForegroundColor = ConsoleColor.Gray;
|
||||||
|
}
|
||||||
|
|
||||||
//Load an external dictionnary of translation rules
|
//Still not found? try downloading en_GB from Mojang's servers?
|
||||||
|
if (!System.IO.File.Exists(Settings.TranslationsFile))
|
||||||
|
{
|
||||||
|
Console.ForegroundColor = ConsoleColor.DarkGray;
|
||||||
|
ConsoleIO.WriteLine("Downloading en_GB.lang from Mojang's servers...");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string assets_index = downloadString(Settings.TranslationsFile_Website_Index);
|
||||||
|
string[] tmp = assets_index.Split(new string[] { "lang/en_GB.lang" }, StringSplitOptions.None);
|
||||||
|
tmp = tmp[1].Split(new string[] { "hash\": \"" }, StringSplitOptions.None);
|
||||||
|
string hash = tmp[1].Split('"')[0]; //Translations file identifier on Mojang's servers
|
||||||
|
System.IO.File.WriteAllText(Settings.TranslationsFile, downloadString(Settings.TranslationsFile_Website_Download + '/' + hash.Substring(0, 2) + '/' + hash));
|
||||||
|
ConsoleIO.WriteLine("Done. File saved as \"" + Settings.TranslationsFile + '"');
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
ConsoleIO.WriteLine("Failed to download the file.");
|
||||||
|
}
|
||||||
|
Console.ForegroundColor = ConsoleColor.Gray;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Load the external dictionnary of translation rules or display an error message
|
||||||
if (System.IO.File.Exists(Settings.TranslationsFile))
|
if (System.IO.File.Exists(Settings.TranslationsFile))
|
||||||
{
|
{
|
||||||
string[] translations = System.IO.File.ReadAllLines(Settings.TranslationsFile);
|
string[] translations = System.IO.File.ReadAllLines(Settings.TranslationsFile);
|
||||||
|
|
@ -343,5 +366,23 @@ namespace MinecraftClient
|
||||||
/// <returns>True if hexadecimal</returns>
|
/// <returns>True if hexadecimal</returns>
|
||||||
|
|
||||||
private static bool isHex(char c) { return ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f')); }
|
private static bool isHex(char c) { return ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f')); }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Do a HTTP request to get a webpage or text data from a server file
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="url">URL of resource</param>
|
||||||
|
/// <returns>Returns resource data if success, otherwise a WebException is raised</returns>
|
||||||
|
|
||||||
|
private static string downloadString(string url)
|
||||||
|
{
|
||||||
|
System.Net.HttpWebRequest myRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url);
|
||||||
|
myRequest.Method = "GET";
|
||||||
|
System.Net.WebResponse myResponse = myRequest.GetResponse();
|
||||||
|
System.IO.StreamReader sr = new System.IO.StreamReader(myResponse.GetResponseStream(), System.Text.Encoding.UTF8);
|
||||||
|
string result = sr.ReadToEnd();
|
||||||
|
sr.Close();
|
||||||
|
myResponse.Close();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,9 @@ namespace MinecraftClient
|
||||||
public static string SingleCommand = "";
|
public static string SingleCommand = "";
|
||||||
|
|
||||||
//Other Settings
|
//Other Settings
|
||||||
public static string TranslationsFile_FromMCDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\.minecraft\assets\virtual\legacy\lang\en_US.lang";
|
public static string TranslationsFile_FromMCDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\.minecraft\assets\virtual\legacy\lang\en_GB.lang";
|
||||||
public static string TranslationsFile_FromMCDir_Alt = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\.minecraft\assets\virtual\legacy\lang\en_GB.lang";
|
public static string TranslationsFile_Website_Index = "https://s3.amazonaws.com/Minecraft.Download/indexes/1.7.4.json";
|
||||||
|
public static string TranslationsFile_Website_Download = "http://resources.download.minecraft.net";
|
||||||
public static string TranslationsFile = "translations.lang";
|
public static string TranslationsFile = "translations.lang";
|
||||||
public static string Bots_OwnersFile = "bot-owners.txt";
|
public static string Bots_OwnersFile = "bot-owners.txt";
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue