/// <summary> /// Handles the OnSelectionChanged event of the Level control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="SelectionChangedEventArgs"/> instance containing the event data.</param> /// <exception cref="System.NotImplementedException"></exception> private void LevelOnSelectionChanged(object sender, SelectionChangedEventArgs e) { if (!_loaded) { return; } var log = Log.Level.None; switch (level.SelectedIndex) { case 0: log = Log.Level.Trace; break; case 1: log = Log.Level.Debug; break; case 2: log = Log.Level.Info; break; case 3: log = Log.Level.Warn; break; case 4: log = Log.Level.Error; break; case 5: log = Log.Level.Fatal; break; case 6: log = Log.Level.None; break; } Log.SetLevel(log); Log.Trace("Setting logging level to " + log + "..."); Settings.Set("Logging Level", log); }
/// <summary> /// Loads the settings. /// </summary> public static void LoadSettings() { Log.Info("Loading settings..."); var st = DateTime.Now; try { Keys = (Dictionary <string, object>)ConvertJToNet( JObject.Parse( File.ReadAllText(_jsFile) ) ); } catch (Exception ex) { Log.Error("Error while loading settings file, resetting all settings to default.", ex); Keys = new Dictionary <string, object> { { "Revision", 2 } }; } try { Log.SetLevel(Get("Logging Level", Log.Level.Info)); } catch (Exception ex) { Log.Warn("Error while getting logging level from settings. Level will remain on Trace.", ex); } Log.Debug("Settings loaded in " + (DateTime.Now - st).TotalSeconds + "s, containing " + Keys.Count + " entries."); // set defaults, if they're missing if (!Keys.ContainsKey("Active Trackers")) { Keys["Active Trackers"] = new List <string> { "The Pirate Bay", "DirectDownload.tv", "Zunox", "NBIndex", "NZBClub" }; } if (!Keys.ContainsKey("Tracker Order")) { Keys["Tracker Order"] = new List <string> { "BroadcasTheNet", "Tv Torrents Ro", "TvStore", "BitMeTV", "TvTorrents", "FileList", "nCore", "bitHUmen" }; } if (!Keys.ContainsKey("Active Subtitle Sites")) { Keys["Active Subtitle Sites"] = Extensibility.GetNewInstances <SubtitleSearchEngine>(inclExternal: false, inclScripts: false) .Select(inst => inst.Name) .ToList(); } if (!Keys.ContainsKey("Active Subtitle Languages")) { Keys["Active Subtitle Languages"] = new List <string> { "en" }; } // update download path to an array // -> revision bd869ed9836a6d1c846a17586855d51b5ce092c2 if (Keys.ContainsKey("Download Path")) { Log.Info("Updating settings file to revision 0..."); Keys["Download Paths"] = new List <string> { (string)Keys["Download Path"] }; Keys.Remove("Download Path"); } // update encryption on logins and encrypt cookies // -> revision 9465c36466739ade0ad556d498d7e17aec379bbb if (!Keys.ContainsKey("Revision") || (int)Keys["Revision"] < 1) { Log.Info("Updating settings file to revision 1..."); var keys = Keys.Keys.ToList(); var plugins = Extensibility.GetNewInstances <IPlugin>().ToList(); foreach (var key in keys) { if (key.EndsWith(" Login")) { try { var plugin = plugins.FirstOrDefault(p => p.Name == key.Substring(0, key.Length - 6)); if (plugin == null) { Keys.Remove(key); continue; } var ua = Utils.Decrypt((string)Keys[key], plugin.GetType().FullName + Environment.NewLine + Utils.GetUUID()).Split(new[] { '\0' }, 2); Keys[key] = Utils.Encrypt(plugin, ua[0], ua[1]); } catch { continue; } } else if (key.EndsWith(" Cookies")) { try { var plugin = plugins.FirstOrDefault(p => p.Name == key.Substring(0, key.Length - 8)); if (plugin == null) { Keys.Remove(key); continue; } Keys[key] = Utils.Encrypt(plugin, (string)Keys[key]); } catch { continue; } } } Set("Revision", 1); } if ((int)Keys["Revision"] < 2) { Log.Info("Updating settings file to revision 2..."); var altdl = Get <Dictionary <string, List <string> > >("Alternative Associations"); if (Keys.ContainsKey("Torrent Downloader") && !string.IsNullOrWhiteSpace((string)Keys["Torrent Downloader"])) { if (altdl.ContainsKey(".torrent")) { altdl[".torrent"].Add((string)Keys["Torrent Downloader"]); } else { altdl[".torrent"] = new List <string> { (string)Keys["Torrent Downloader"] }; } Keys.Remove("Torrent Downloader"); } if (Keys.ContainsKey("Usenet Downloader") && !string.IsNullOrWhiteSpace((string)Keys["Usenet Downloader"])) { if (altdl.ContainsKey(".nzb")) { altdl[".nzb"].Add((string)Keys["Usenet Downloader"]); } else { altdl[".nzb"] = new List <string> { (string)Keys["Usenet Downloader"] }; } Keys.Remove("Usenet Downloader"); } if (Keys.ContainsKey("JDownloader") && !string.IsNullOrWhiteSpace((string)Keys["JDownloader"])) { if (altdl.ContainsKey(".dlc")) { altdl[".dlc"].Add((string)Keys["JDownloader"]); } else { altdl[".dlc"] = new List <string> { (string)Keys["JDownloader"] }; } Keys.Remove("JDownloader"); } Set("Alternative Associations", altdl); Set("Revision", 2); } }