static void Main() { AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(UnhandledExceptionHandler); string culture = Consts.enLanguage; try { string configFolder = Path.Combine(Application.StartupPath, Consts.DataFolder); string settingsFileFullPath = Path.Combine(configFolder, Consts.SettingsFileName); Settings settings = (Settings)Utils.LoadFromFile(settingsFileFullPath, typeof(Settings)); if (settings == null) { settings = new Settings(); settings.RefreshTime = Consts.DefaultRefreshTime; settings.ShowMinAmount = Consts.DefaultShowMinAmount; settings.ShowOrderNO = Consts.DefaultShowOrderNo; settings.WarnHighBuyPrice = Consts.DefaultHighestBuyPrice; settings.WarnLowSellPrice = Consts.DefaultLowestSellPrice; settings.Language = Consts.enLanguage; Utils.SaveToFile(settings, settingsFileFullPath); } culture = settings.Language; } catch (Exception ex) { } if (culture == Consts.cnLanguage) { ResourceFactory.ResourceCulture = ResourceFactory.CnCultureInfo; ResourceFactory.ResourceMan = ResourceFactory.CnResourceManager; Thread.CurrentThread.CurrentUICulture = ResourceFactory.CnCultureInfo; } else { ResourceFactory.ResourceCulture = ResourceFactory.EnCultureInfo; ResourceFactory.ResourceMan = ResourceFactory.EnResourceManager; Thread.CurrentThread.CurrentUICulture = ResourceFactory.EnCultureInfo; } ResourceFactory.Culture = culture; Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); string procName = System.Diagnostics.Process.GetCurrentProcess().ProcessName; string logFolder = Path.Combine(Application.StartupPath, Consts.logFolder); Trace.Listeners.Add(new LogTraceListener(Path.Combine(logFolder, Consts.logFileName))); Trace.AutoFlush = true; if ((System.Diagnostics.Process.GetProcessesByName(procName)).GetUpperBound(0) > 0) { MessageBox.Show(ResourceFactory.GetString("AlreadyRunning")); return; } Configure config = new Configure(); config.Show(); Application.Run(); }
private void SaveSettings(object sender, EventArgs e) { Settings settings = new Settings(); try { int refreshTime; if (!int.TryParse(this.txtRefresh.Text.Trim(), out refreshTime)) { refreshTime = Consts.DefaultRefreshTime; } double minAmount; if (!Double.TryParse(this.txtOrderMinAmount.Text.Trim(), out minAmount)) { minAmount = Consts.DefaultShowMinAmount; } int showOrders; if (!int.TryParse(this.comboShowNumber.SelectedItem.ToString(), out showOrders)) { showOrders = Consts.DefaultShowOrderNo; } double highestBuyPrice; if (!Double.TryParse(txtHighestBuyPrice.Text.Trim(), out highestBuyPrice)) { highestBuyPrice = Consts.DefaultHighestBuyPrice; } double lowestSellPrice; if (!Double.TryParse(txtLowestSellPrice.Text.Trim(), out lowestSellPrice)) { lowestSellPrice = Consts.DefaultLowestSellPrice; } settings.RefreshTime = refreshTime; settings.ShowMinAmount = minAmount; settings.ShowOrderNO = showOrders; settings.WarnHighBuyPrice = highestBuyPrice; settings.WarnLowSellPrice = lowestSellPrice; settings.Language = ResourceFactory.Culture; settings.AutoTrade = autoTradeSettingsList; string settingsFileFullPath = Path.Combine(configFolder, Consts.SettingsFileName); Utils.SaveToFile(settings, settingsFileFullPath); MessageBox.Show(ResourceFactory.GetString("SettingsSaved")); } catch (Exception ex) { Trace.WriteLine(string.Format("{0} \r\n stack:{1}", Utils.GetDetailedException(ex), Utils.GetStackTrace(ex))); } }
private void LoadSettings(object sender, EventArgs e) { try { string settingsFileFullPath = Path.Combine(configFolder, Consts.SettingsFileName); Settings settings = (Settings)Utils.LoadFromFile(settingsFileFullPath, typeof(Settings)); if (settings == null) { settings = new Settings(); settings.RefreshTime = Consts.DefaultRefreshTime; settings.ShowMinAmount = Consts.DefaultShowMinAmount; settings.ShowOrderNO = Consts.DefaultShowOrderNo; settings.WarnHighBuyPrice = Consts.DefaultHighestBuyPrice; settings.WarnLowSellPrice = Consts.DefaultLowestSellPrice; settings.Language = ResourceFactory.Culture; Utils.SaveToFile(settings, settingsFileFullPath); } this.txtRefresh.Text = settings.RefreshTime.ToString(); this.txtOrderMinAmount.Text = settings.ShowMinAmount.ToString(); if (settings.ShowOrderNO == 5) this.comboShowNumber.SelectedIndex = 0; else if (settings.ShowOrderNO == 10) this.comboShowNumber.SelectedIndex = 1; else if (settings.ShowOrderNO == 20) this.comboShowNumber.SelectedIndex = 2; this.txtHighestBuyPrice.Text = settings.WarnHighBuyPrice.ToString(); this.txtLowestSellPrice.Text = settings.WarnLowSellPrice.ToString(); if(settings.AutoTrade != null) this.autoTradeSettingsList = settings.AutoTrade; if (settings.Language != ResourceFactory.Culture) { if (settings.Language == Consts.cnLanguage) { ResourceFactory.ResourceCulture = ResourceFactory.CnCultureInfo; ResourceFactory.ResourceMan = ResourceFactory.CnResourceManager; Thread.CurrentThread.CurrentUICulture = ResourceFactory.CnCultureInfo; } else { ResourceFactory.ResourceCulture = ResourceFactory.EnCultureInfo; ResourceFactory.ResourceMan = ResourceFactory.EnResourceManager; Thread.CurrentThread.CurrentUICulture = ResourceFactory.EnCultureInfo; } ResourceFactory.Culture = settings.Language; InitializeControl(); reload(); } } catch (Exception ex) { } }