/// <summary> /// When an error is logged, check if user has chosen to upload logs or not /// </summary> protected override void Append(LoggingEvent loggingEvent) { if (!GoogleOgcs.ErrorReporting.Initialised || errorOccurred) { return; } errorOccurred = true; String configSetting = null; if (Settings.IsLoaded) { configSetting = Settings.Instance.CloudLogging.ToString(); } else { configSetting = XMLManager.ImportElement("CloudLogging", Settings.ConfigFile); } if (!string.IsNullOrEmpty(configSetting)) { if (configSetting == "true" && GoogleOgcs.ErrorReporting.GetThreshold().ToString().ToUpper() != "ALL") { GoogleOgcs.ErrorReporting.SetThreshold(true); replayLogs(); } else if (configSetting == "false" && GoogleOgcs.ErrorReporting.GetThreshold().ToString().ToUpper() != "OFF") { GoogleOgcs.ErrorReporting.SetThreshold(false); } return; } //Cloud logging value not set yet - let's ask the user Forms.ErrorReporting frm = Forms.ErrorReporting.Instance; DialogResult dr = frm.ShowDialog(); if (dr == DialogResult.Cancel) { errorOccurred = false; return; } Boolean confirmative = dr == DialogResult.Yes; if (Settings.IsLoaded) { Settings.Instance.CloudLogging = confirmative; } Telemetry.Send(Analytics.Category.ogcs, Analytics.Action.setting, "CloudLogging=" + confirmative.ToString()); try { Forms.Main.Instance.SetControlPropertyThreadSafe(Forms.Main.Instance.cbCloudLogging, "CheckState", confirmative ? CheckState.Checked : CheckState.Unchecked); } catch { } if (confirmative) { replayLogs(); } }
private static void initialiseFiles() { string appFilePath = System.Windows.Forms.Application.StartupPath; string roamingAppData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); roamingOGCS = Path.Combine(roamingAppData, Application.ProductName); //Don't know where to write log file to yet. If settings.xml exists in Roaming profile, //then log should go there too. if (File.Exists(Path.Combine(roamingOGCS, settingsFilename))) { UserFilePath = roamingOGCS; initialiseLogger(UserFilePath, true); log.Info("Storing user files in roaming directory: " + UserFilePath); } else { UserFilePath = appFilePath; initialiseLogger(UserFilePath, true); log.Info("Storing user files in application directory: " + appFilePath); if (!File.Exists(Path.Combine(appFilePath, settingsFilename))) { log.Info("No settings.xml file found in " + appFilePath); Settings.Instance.Save(Path.Combine(appFilePath, settingsFilename)); log.Info("New blank template created."); startingTab = "Help"; } } log.Info("Running from " + System.Windows.Forms.Application.ExecutablePath); //Now let's confirm the actual setting settingsFile = Path.Combine(UserFilePath, settingsFilename); Boolean keepPortable = (XMLManager.ImportElement("Portable", settingsFile) ?? "false").Equals("true"); if (keepPortable) { if (UserFilePath != appFilePath) { log.Info("File storage location is incorrect according to " + settingsFilename); MakePortable(true); } } else { if (UserFilePath != roamingOGCS) { log.Info("File storage location is incorrect according to " + settingsFilename); MakePortable(false); } } string logLevel = XMLManager.ImportElement("LoggingLevel", settingsFile); Settings.configureLoggingLevel(logLevel ?? "FINE"); purgeLogFiles(30); }
private static void doShowSplash() { try { if (splash == null) { splash = new Splash(); } splash.lVersion.Text = "v" + Application.ProductVersion; String completedSyncs = XMLManager.ImportElement("CompletedSyncs", Program.SettingsFile) ?? "0"; if (completedSyncs == "0") { splash.lSyncCount.Visible = false; } else { splash.lSyncCount.Text = splash.lSyncCount.Text.Replace("{syncs}", String.Format("{0:n0}", completedSyncs)); splash.lSyncCount.Left = (splash.panel1.Width - (splash.lSyncCount.Width)) / 2; } //Load settings directly from XML donor = (XMLManager.ImportElement("Donor", Program.SettingsFile) ?? "false") == "true"; String subscribedDate = XMLManager.ImportElement("Subscribed", Program.SettingsFile); if (string.IsNullOrEmpty(subscribedDate)) { subscribedDate = "01-Jan-2000"; } subscribed = DateTime.Parse(subscribedDate); Boolean hideSplash = (XMLManager.ImportElement("HideSplashScreen", Program.SettingsFile) ?? "false") == "true"; initialised = true; splash.cbHideSplash.Checked = hideSplash; if (subscribed == DateTime.Parse("01-Jan-2000") && !donor) { ToolTips = new ToolTip(); ToolTips.AutoPopDelay = 10000; ToolTips.InitialDelay = 500; ToolTips.ReshowDelay = 200; ToolTips.ShowAlways = true; ToolTips.SetToolTip(splash.cbHideSplash, "Donate £10 or more to enable this feature."); } else if (hideSplash) { log.Debug("Suppressing splash screen."); return; } splash.TopLevel = true; splash.TopMost = true; log.Debug("Showing splash screen."); Application.Run(splash); log.Debug("Disposed of splash screen."); splashThread.Abort(); } finally { initialised = true; } }
public Splash() { InitializeComponent(); lVersion.Text = "v" + Application.ProductVersion; String completedSyncs = XMLManager.ImportElement("CompletedSyncs", Program.SettingsFile) ?? "0"; if (completedSyncs == "0") { lSyncCount.Visible = false; } else { lSyncCount.Text = lSyncCount.Text.Replace("{syncs}", String.Format("{0:n0}", completedSyncs)); lSyncCount.Left = (panel1.Width - (lSyncCount.Width)) / 2; } }
private static void doShowSplash() { if (splash == null) { splash = new Splash(); } splash.lVersion.Text = "v" + Application.ProductVersion; String completedSyncs = XMLManager.ImportElement("CompletedSyncs", Program.SettingsFile) ?? "0"; if (completedSyncs == "0") { splash.lSyncCount.Visible = false; } else { splash.lSyncCount.Text = splash.lSyncCount.Text.Replace("{syncs}", String.Format("{0:n0}", completedSyncs)); splash.lSyncCount.Left = (splash.panel1.Width - (splash.lSyncCount.Width)) / 2; } log.Debug("Showing splash screen."); Application.Run(splash); log.Debug("Disposed of splash screen."); splashThread.Abort(); }
private static void parseArgumentsAndInitialise(string[] args) { //We're interested in non-Squirrel arguments here, ie ones which don't start with Linux-esque dashes (--squirrel) StartedWithFileArgs = (args.Length != 0 && args.Count(a => a.StartsWith("/") && !a.StartsWith("/d")) != 0); if (args.Contains("/?") || args.Contains("/help", StringComparer.OrdinalIgnoreCase)) { OgcsMessageBox.Show("Command line parameters:-\r\n" + " /?\t\tShow options\r\n" + " /l:OGcalsync.log\tFile to log to\r\n" + " /s:settings.xml\tSettings file to use.\r\n\t\tFile created with defaults if it doesn't exist\r\n" + " /d:60\t\tSeconds startup delay\r\n" + " /t:\"Config A\"\tAppend custom text to application title", "OGCS command line parameters", MessageBoxButtons.OK, MessageBoxIcon.Information); Environment.Exit(0); } Dictionary <String, String> loggingArg = parseArgument(args, 'l'); initialiseLogger(loggingArg["Filename"], loggingArg["Directory"], bootstrap: true); Dictionary <String, String> settingsArg = parseArgument(args, 's'); Settings.InitialiseConfigFile(settingsArg["Filename"], settingsArg["Directory"]); log.Info("Storing user files in directory: " + MaskFilePath(UserFilePath)); //Before settings have been loaded, early config of cloud logging GoogleOgcs.ErrorReporting.UpdateLogUuId(); Boolean cloudLogSetting = false; String cloudLogXmlSetting = XMLManager.ImportElement("CloudLogging", Settings.ConfigFile); if (!string.IsNullOrEmpty(cloudLogXmlSetting)) { cloudLogSetting = Boolean.Parse(cloudLogXmlSetting); } GoogleOgcs.ErrorReporting.SetThreshold(cloudLogSetting); if (!StartedWithFileArgs) { //Now let's confirm files are actually in the right place Boolean keepPortable = (XMLManager.ImportElement("Portable", Settings.ConfigFile) ?? "false").Equals("true"); if (keepPortable) { if (UserFilePath != System.Windows.Forms.Application.StartupPath) { log.Info("File storage location is incorrect according to " + Settings.ConfigFile); MakePortable(true); } } else { if (UserFilePath != Program.RoamingProfileOGCS) { log.Info("File storage location is incorrect according to " + Settings.ConfigFile); MakePortable(false); } } } string logLevel = XMLManager.ImportElement("LoggingLevel", Settings.ConfigFile); Settings.configureLoggingLevel(logLevel ?? "FINE"); if (args.Contains("--delay")) //Format up to and including v2.7.1 { log.Info("Converting old --delay parameter to /d"); try { String delay = args[Array.IndexOf(args, "--delay") + 1]; log.Debug("Delay of " + delay + "s being migrated."); addRegKey(delay); delayStartup(delay); } catch (System.Exception ex) { log.Error(ex.Message); } } Dictionary <String, String> delayArg = parseArgument(args, 'd'); if (delayArg["Value"] != null) { delayStartup(delayArg["Value"]); } Dictionary <String, String> titleArg = parseArgument(args, 't'); Title = titleArg["Value"]; }