コード例 #1
0
 public void Save(string XMLfile = null)
 {
     XMLManager.Export(this, XMLfile ?? Program.SettingsFile);
 }
コード例 #2
0
        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))
            {
                MessageBox.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",
                                "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: " + UserFilePath);

            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"]);
            }
        }
コード例 #3
0
 public static void Load(string XMLfile = null)
 {
     Settings.Instance = XMLManager.Import <Settings>(XMLfile ?? Program.SettingsFile);
     log.Fine("User settings loaded.");
 }
コード例 #4
0
 public void Save(String XMLfile = null)
 {
     log.Info("Saving settings.");
     XMLManager.Export(this, XMLfile ?? ConfigFile);
 }
コード例 #5
0
        /// <summary>
        /// When an error is logged, check if user has chosen to upload logs or not
        /// </summary>
        protected override void Append(LoggingEvent loggingEvent)
        {
            if (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 = new Forms.ErrorReporting();
            DialogResult         dr  = frm.ShowDialog();

            if (dr == DialogResult.Cancel)
            {
                errorOccurred = false;
                return;
            }
            Boolean confirmative = dr == DialogResult.Yes;

            if (Settings.IsLoaded)
            {
                Settings.Instance.CloudLogging = confirmative;
            }
            else
            {
                XMLManager.ExportElement("CloudLogging", confirmative, Settings.ConfigFile);
            }
            Analytics.Send(Analytics.Category.ogcs, Analytics.Action.setting, "CloudLogging=" + confirmative.ToString());

            try {
                Forms.Main.Instance.SetControlPropertyThreadSafe(Forms.Main.Instance.cbCloudLogging, "Checked", confirmative);
            } catch { }

            if (confirmative)
            {
                replayLogs();
            }
        }
コード例 #6
0
        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.");
                    if (!Program.IsInstalled)
                    {
                        XMLManager.ExportElement("Portable", true, Path.Combine(appFilePath, settingsFilename));
                    }
                    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);
        }
コード例 #7
0
 public void Save(string XMLfile = null)
 {
     log.Info("Saving settings.");
     XMLManager.Export(this, XMLfile ?? Program.SettingsFile);
 }