/// <summary> /// Creates a <see cref="Configuration"/> from the specified file. /// </summary> /// <param name="path">The path to the file to load.</param> /// <returns>A new <see cref="Configuration"/> class.</returns> public static Configuration FromFile(string path) { var config = new Configuration(); if (File.Exists(path)) { var json = File.ReadAllText(path); config = JsonConvert.DeserializeObject<Configuration>(json); } config.FileName = path; return config; }
/// <summary> /// Checks whether the specified configuration is valid and can be used. /// If the configurationnis invalid, an appropiate exception is thrown. /// Otherwise, the function simply returns. /// </summary> /// <param name="config"> /// The <see cref="Configuration"/> object to check. /// </param> private static void CheckSettings(Configuration config) { if (!Directory.Exists(config.BaseDir)) { string foundDir = FindBaseDir(); if (foundDir != null && Directory.Exists(foundDir)) config.BaseDir = foundDir; else throw new Exception("No screenshot folder has been set."); } config.Save(); }