Exemplo n.º 1
0
 /// <summary>
 /// Loads the config file.
 /// </summary>
 public static void InitializeInstance()
 {
     logger.Debug("Starting to load configuration file.");
     if (instance == null)
     {
         var path = Path.Combine(Application.StartupPath, ConfigFilename);
         // Attemp to load the existing file first
         if (File.Exists(path))
         {
             logger.Trace("Configuration file found, attempting to load.");
             try
             {
                 using (var stream = new StreamEx(path))
                 {
                     instance = JsonUtils.Deserialize<StudioSettings>(stream);
                 }
                 logger.Info("Successfully loaded the configuration file.");
             }
             catch (Exception x)
             {
                 logger.Error("Failed to load existing configuration file. Exception Type: {0}; Message: {1}", x.GetType().Name, x.Message);
                 MessageBox.Show(String.Format("Failed to load the configuration file!\nYour settings will be restored to defaults.\n\nError info: {0}", x.Message),
                     "Error",
                     MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
         // If instance is still null, either no file exists or load failed.
         if (instance == null)
         {
             instance = new StudioSettings();
             instance.Save();
             logger.Info("Created new configuration file with default values.");
         }
     }
 }