private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs args) { Exception ex = (Exception)args.ExceptionObject; ExceptionBox.ExceptionForm tmp = new ExceptionBox.ExceptionForm("Unhandled Exception", "An unhandled exception has occured.", ref ex); tmp.ShowDialog(); }
private string ReadWebPage(string url) { string result = String.Empty; try { //http://msdn.microsoft.com/en-us/library/system.net.webrequest.aspx // Create a request for the URL. WebRequest request = WebRequest.Create(url); // If required by the server, set the credentials. //request.Credentials = CredentialCache.DefaultCredentials; // Get the response. HttpWebResponse response = (HttpWebResponse)request.GetResponse(); // Get the stream containing content returned by the server. Stream data_stream = response.GetResponseStream(); // Open the stream using a StreamReader for easy access. StreamReader reader = new StreamReader(data_stream); // Read the content. result = reader.ReadToEnd(); // Cleanup the streams and the response. reader.Close(); data_stream.Close(); response.Close(); } catch (Exception ex) { ExceptionBox.ExceptionForm exb = new ExceptionBox.ExceptionForm(ref ex); exb.ShowDialog(this); } result = result.Replace("\n", Environment.NewLine); return(result); }
private static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e) { Exception ex = e.Exception; ExceptionBox.ExceptionForm tmp = new ExceptionBox.ExceptionForm("Unhandled Exception", "An unhandled thread exception has occured.", ref ex); tmp.ShowDialog(); }
public bool LoadSettings() { if (!File.Exists(_filepath)) { if (!MakeSettingsFile()) { throw new Exception("Could not create settings file."); } } try { TextReader tr = new StreamReader(_filepath); string line = ""; while (line != null) { line = tr.ReadLine(); if (line == null) { continue; } else if (line.Length < 1) { continue; } else if (line.StartsWith("#")) { continue; } else if (line.StartsWith("//")) { continue; } line = line.TrimStart(new char[] { ' ', '\t' }); string[] pair = line.Split(new char[] { '=' }, 2); pair[0] = pair[0].TrimEnd(new char[] { ' ', '\t' }); pair[1] = pair[1].TrimStart(new char[] { ' ', '\t' }); pair[1] = pair[1].TrimEnd(new char[] { ' ', '\t', '\n', '\r' }); _settings.Add(pair[0], pair[1]); } tr.Close(); } catch (Exception ex) { ExceptionBox.ExceptionForm tmp = new ExceptionBox.ExceptionForm(ref ex); tmp.ShowDialog(); return(false); } return(true); }
private bool MakeSettingsFile() { string cfgstring = String.Empty; try { TextWriter tw = new StreamWriter(Program.GetPath() + @"\settings.cfg"); tw.WriteLine(cfgstring); tw.Close(); } catch (Exception ex) { ExceptionBox.ExceptionForm tmp = new ExceptionBox.ExceptionForm(ref ex); tmp.ShowDialog(); return(false); } return(true); }
private void BTN_Start_Click(object sender, EventArgs e) { BTN_Start.Enabled = false; BTN_Pause.Enabled = BTN_Stop.Enabled = true; textBox2.Clear(); string url = (string)Settings.Global.settings["UpdateURL"]; try { if (Directory.Exists(Settings.Global.settings["GameDirectory"].ToString())) { _downloader.LocalDirectory = Settings.Global.settings["GameDirectory"].ToString(); } else { textBox2.AppendText("WARNING - Save directory \"" + Settings.Global.settings["GameDirectory"].ToString() + "\" does not exist! Please check settings." + Environment.NewLine); _downloader.LocalDirectory = Program.GetPath(); } textBox2.AppendText("Saving files to '" + _downloader.LocalDirectory + "'" + Environment.NewLine); _downloader.Files.Clear(); textBox2.AppendText("Downloading manifest file..." + Environment.NewLine); string manifest = ReadWebPage(url + "/manifest.txt"); textBox2.AppendText(manifest); textBox2.Select(0, 0); foreach (string line in manifest.Split('\n')) { String trimmed = line.Trim(' ', '\r'); if (trimmed.Length > 0) { _downloader.Files.Add(new FileDownloader.FileInfo(url + "/" + trimmed)); } } _downloader.Start(); } catch (Exception ex) { ExceptionBox.ExceptionForm exb = new ExceptionBox.ExceptionForm(ref ex); exb.ShowDialog(this); } }
public bool WriteSettingsFile() { string cfgstring = String.Empty; foreach (DictionaryEntry d in _settings) { cfgstring += d.Key + " = " + d.Value + Environment.NewLine; } try { TextWriter tw = new StreamWriter(_filepath); tw.Write(cfgstring); tw.Close(); } catch (Exception ex) { ExceptionBox.ExceptionForm tmp = new ExceptionBox.ExceptionForm(ref ex); tmp.ShowDialog(); return(false); } return(true); }
private void BTN_Start_Click(object sender, EventArgs e) { BTN_Start.Enabled = false; BTN_Pause.Enabled = BTN_Stop.Enabled = true; textBox2.Clear(); string url = (string)Settings.Global.settings["UpdateURL"]; try { if (Directory.Exists(Settings.Global.settings["GameDirectory"].ToString())) { _downloader.LocalDirectory = Settings.Global.settings["GameDirectory"].ToString(); } else { textBox2.AppendText("WARNING - Save directory \"" + Settings.Global.settings["GameDirectory"].ToString() + "\" does not exist! Please check settings." + Environment.NewLine); _downloader.LocalDirectory = Program.GetPath(); } textBox2.AppendText("Saving files to '" + _downloader.LocalDirectory + "'" + Environment.NewLine); _downloader.Files.Clear(); textBox2.AppendText("Downloading manifest file..." + Environment.NewLine); string manifest = ReadWebPage(url + "/manifest.txt"); textBox2.AppendText(manifest); textBox2.Select(0, 0); foreach (string line in manifest.Split('\n')) { String trimmed = line.Trim(' ', '\r'); if (trimmed.Length > 0) { _downloader.Files.Add(new FileDownloader.FileInfo(url+"/"+trimmed)); } } _downloader.Start(); } catch (Exception ex) { ExceptionBox.ExceptionForm exb = new ExceptionBox.ExceptionForm(ref ex); exb.ShowDialog(this); } }
private string ReadWebPage(string url) { string result = String.Empty; try { //http://msdn.microsoft.com/en-us/library/system.net.webrequest.aspx // Create a request for the URL. WebRequest request = WebRequest.Create(url); // If required by the server, set the credentials. //request.Credentials = CredentialCache.DefaultCredentials; // Get the response. HttpWebResponse response = (HttpWebResponse)request.GetResponse(); // Get the stream containing content returned by the server. Stream data_stream = response.GetResponseStream(); // Open the stream using a StreamReader for easy access. StreamReader reader = new StreamReader(data_stream); // Read the content. result = reader.ReadToEnd(); // Cleanup the streams and the response. reader.Close(); data_stream.Close(); response.Close(); } catch (Exception ex) { ExceptionBox.ExceptionForm exb = new ExceptionBox.ExceptionForm(ref ex); exb.ShowDialog(this); } result = result.Replace("\n", Environment.NewLine); return result; }
public bool LoadSettings() { if ( !File.Exists(_filepath) ) { if ( !MakeSettingsFile() ) { throw new Exception("Could not create settings file."); } } try { TextReader tr = new StreamReader(_filepath); string line = ""; while (line != null) { line = tr.ReadLine(); if (line == null) continue; else if (line.Length < 1) continue; else if (line.StartsWith("#")) continue; else if (line.StartsWith("//")) continue; line = line.TrimStart(new char[]{' ', '\t'}); string[] pair = line.Split(new char[] {'=' }, 2); pair[0] = pair[0].TrimEnd(new char[] {' ', '\t'}); pair[1] = pair[1].TrimStart(new char[] {' ', '\t'}); pair[1] = pair[1].TrimEnd(new char[] {' ', '\t', '\n', '\r' }); _settings.Add(pair[0], pair[1]); } tr.Close(); } catch (Exception ex) { ExceptionBox.ExceptionForm tmp = new ExceptionBox.ExceptionForm(ref ex); tmp.ShowDialog(); return false; } return true; }
private bool MakeSettingsFile() { string cfgstring = String.Empty; try { TextWriter tw = new StreamWriter(Program.GetPath() + @"\settings.cfg"); tw.WriteLine(cfgstring); tw.Close(); } catch (Exception ex) { ExceptionBox.ExceptionForm tmp = new ExceptionBox.ExceptionForm(ref ex); tmp.ShowDialog(); return false; } return true; }
public bool WriteSettingsFile() { string cfgstring = String.Empty; foreach (DictionaryEntry d in _settings) { cfgstring += d.Key + " = " + d.Value + Environment.NewLine; } try { TextWriter tw = new StreamWriter(_filepath); tw.Write(cfgstring); tw.Close(); } catch (Exception ex) { ExceptionBox.ExceptionForm tmp = new ExceptionBox.ExceptionForm(ref ex); tmp.ShowDialog(); return false; } return true; }