Example #1
0
        protected static Settings FromFile(Settings s, string FileName, bool IsUserSettings)
        {
            // Failsafe .. check for default settings
              if (s == null) return null;

              // Add 'save' event handler
              if (IsUserSettings) Application.ApplicationExit += new EventHandler(s.SaveSettingsHandler);

              // Load settings
              if (!File.Exists(FileName))
              {
            if (IsUserSettings)
            {
              // Notify first use
              if (MessageBox.Show("This is your first time using " + AppName + ".\n"
              + "Default settings will now be saved.\n",
              AppName + " Settings", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.Cancel)
            return null;

              // Save default settings
              try
              { s.SaveSettings(new StreamWriter(File.OpenWrite(FileName))); }
              catch (IOException)
              { return null; }

              s.m_SettingsFile = FileName;
              return s;
            }
              }

              try
              {
            if (s.LoadSettings(File.OpenText(FileName)) == false) return null;
            s.m_SettingsFile = FileName;
            return s;
              }
              catch (IOException)
              { return null; }
        }
Example #2
0
 protected static Settings FromUserSettings(Settings s)
 {
     return FromFile(s, Path.Combine(SettingsPath, "Config.ini"), true);
 }