private void OpenTranslationDownloadGithub(object sender, EventArgs e) { string list = string.Empty; LoadingBarGUI loadingBarGui = new LoadingBarGUI( Translation.GetTranslation("LOADING"), Translation.GetTranslation("TL_LIST_LOADING"), true, g => { HttpWebRequest webRequest = (HttpWebRequest) WebRequest.Create($"{MaidFiddler.RESOURCE_URL}/Resources/Translations/translation_list.txt"); g.Timer.Start(); Debugger.WriteLine(LogLevel.Info, "Getting translation list..."); webRequest.BeginGetResponse( ar => { try { HttpWebResponse response = (HttpWebResponse) webRequest.EndGetResponse(ar); Debugger.WriteLine(LogLevel.Info, "Got response!"); Debugger.WriteLine(LogLevel.Info, $"Response: {response.StatusCode}"); if (response.StatusCode == HttpStatusCode.NotFound) { MessageBox.Show( "Failed to retreive translation list: List not found.", "Boop!", MessageBoxButtons.OK, MessageBoxIcon.Error); } Stream s = response.GetResponseStream(); Debugger.WriteLine(LogLevel.Info, "Reading response"); StringBuilder sb = new StringBuilder(); byte[] responseBuffer = new byte[1024]; int read; do { read = s.Read(responseBuffer, 0, responseBuffer.Length); sb.Append(Encoding.UTF8.GetString(responseBuffer, 0, read)); } while (read > 0); list = sb.ToString(); g.DialogResult = DialogResult.OK; } catch (WebException we) { MessageBox.Show( $"Failed to retreive translation list.\nResponse: {we.Message}", "Boop!", MessageBoxButtons.OK, MessageBoxIcon.Error); g.DialogResult = DialogResult.Abort; } catch (Exception ex) { MessageBox.Show( $"Unknown error occurred.\nInfo: {ex.ToString()}", "Boop!", MessageBoxButtons.OK, MessageBoxIcon.Error); g.DialogResult = DialogResult.Abort; } finally { g.Timer.Stop(); g.Close(); } }, null); }); DialogResult result = loadingBarGui.ShowDialog(this); loadingBarGui.Dispose(); if (result != DialogResult.OK) return; GithubTranslationsGUI tlGui = new GithubTranslationsGUI(list.Remove(0, 1)); tlGui.ShowDialog(this); tlGui.Dispose(); LoadTranslations(Translation.CurrentTranslationFile); }
private void OpenTranslationDownloadGithub(object sender, EventArgs e) { string list = string.Empty; LoadingBarGUI loadingBarGui = new LoadingBarGUI( Translation.GetTranslation("LOADING"), Translation.GetTranslation("TL_LIST_LOADING"), true, g => { HttpWebRequest webRequest = (HttpWebRequest) WebRequest.Create($"{MaidFiddler.RESOURCE_URL}/Resources/Translations/translation_list.txt"); g.Timer.Start(); Debugger.WriteLine(LogLevel.Info, "Getting translation list..."); webRequest.BeginGetResponse( ar => { try { HttpWebResponse response = (HttpWebResponse)webRequest.EndGetResponse(ar); Debugger.WriteLine(LogLevel.Info, "Got response!"); Debugger.WriteLine(LogLevel.Info, $"Response: {response.StatusCode}"); if (response.StatusCode == HttpStatusCode.NotFound) { MessageBox.Show( "Failed to retreive translation list: List not found.", "Boop!", MessageBoxButtons.OK, MessageBoxIcon.Error); } Stream s = response.GetResponseStream(); Debugger.WriteLine(LogLevel.Info, "Reading response"); byte[] responseBuffer = new byte[1024]; List <byte> byteBuffer = new List <byte>(); int read; do { read = s.Read(responseBuffer, 0, responseBuffer.Length); byteBuffer.AddRange(responseBuffer, 0, read); } while (read > 0); list = Encoding.UTF8.GetString(byteBuffer.ToArray()); g.DialogResult = DialogResult.OK; } catch (WebException we) { MessageBox.Show( $"Failed to retreive translation list.\nResponse: {we.Message}", "Boop!", MessageBoxButtons.OK, MessageBoxIcon.Error); g.DialogResult = DialogResult.Abort; } catch (Exception ex) { MessageBox.Show( $"Unknown error occurred.\nInfo: {ex.ToString()}", "Boop!", MessageBoxButtons.OK, MessageBoxIcon.Error); g.DialogResult = DialogResult.Abort; } finally { g.Timer.Stop(); g.Close(); } }, null); }); DialogResult result = loadingBarGui.ShowDialog(this); loadingBarGui.Dispose(); if (result != DialogResult.OK) { return; } GithubTranslationsGUI tlGui = new GithubTranslationsGUI(list.Remove(0, 1)); tlGui.ShowDialog(this); tlGui.Dispose(); LoadTranslations(Translation.CurrentTranslationFile); }