private void Window_Loaded(object sender, RoutedEventArgs e) { #if DEBUG LanguageEngine.SaveDummy(); #endif NotifyIcon.Icon = new System.Drawing.Icon("Assets/icon-16.ico"); this.Icon = new BitmapImage(new Uri("Assets/icon-allsizes.ico", UriKind.Relative)); this.Icon.Freeze(); var cts = new CancellationTokenSource(); state = new State { uiContext = uiContext, MainTaskCancellationTokenSource = cts }; Task.Run(() => Update(cts.Token), cts.Token); this.DataContext = new NiceDataContext <MainWindow>(this); this.mainlist.ItemsSource = this.state.Torrents; itemselector = ShowAll; graph = new GraphDrawer(graph_canvas); foreach (string str in App.to_add) { if (Utility.IsMagnetLink(str)) { state.AddTorrentByMagnet(str); } else { state.AddTorrentByPath(str); } } feeds_tree_item.ItemsSource = FeedsManager.EntriesList; if (!App.Settings.ImportedTorrents) { ImportTorrents(); } Utility.ReloadTheme(App.Settings.Theme); if (App.Settings.CheckForUpdates) { StartAutoUpdater(); } }
private static LanguageEngine GetDummyLanguageEngine() { var le = new LanguageEngine(); Type t = typeof(LanguageEngine); var props = t.GetProperties(); foreach (var prop in props) { prop.SetValue(le, prop.Name.Split('_').Last()); } return(le); }
protected override void OnStartup(StartupEventArgs e) { Environment.CurrentDirectory = new DirectoryInfo(Assembly.GetExecutingAssembly().Location).Parent.FullName; if (e.Args.Length != 0) { try { TcpClient tcp = new TcpClient(); tcp.Connect("127.0.0.1", 65432); NetworkStream ns = tcp.GetStream(); Random rnd = new Random(); StreamWriter sw = new StreamWriter(ns); foreach (string str in e.Args) { JsonObject jo = new JsonObject(); jo.Add("id", rnd.Next()); jo.Add("method", "addtorrentbypath"); jo.Add("params", new JsonArray() { str }); sw.WriteLine(jo.ToString()); sw.Flush(); } tcp.Close(); Environment.Exit(0); } catch (Exception ex) { Console.WriteLine(ex.Message); to_add = e.Args; } } else { to_add = new string[0]; } base.OnStartup(e); Settings = Settings.Load("./config.xml"); CurrentLanguage = LanguageEngine.LoadDefault(); LoadTheme(Settings.Theme); }
public static LanguageEngine LoadDefault() { string dictionary_path = string.Format("./Assets/Languages/{0}.xml", App.Settings.DefaultLanguage); LanguageEngine le = null; if (System.IO.File.Exists(dictionary_path)) { try { le = Utility.Deserialize <LanguageEngine>(dictionary_path); } catch (System.Xml.XmlException) { //bad file, try to find another working file foreach (string lang in Utility.GetAvailableLanguages()) { if (lang.Equals(App.Settings.DefaultLanguage, StringComparison.OrdinalIgnoreCase)) { continue; } try { le = Utility.Deserialize <LanguageEngine>(string.Format("./Assets/Languages/{0}.xml", lang)); } catch { continue; } //end of try-catch } // loop } // end of the fallback-try-catch catch { } } if (le == null) { le = LanguageEngine.GetDummyLanguageEngine(); } return(le); }
private void SaveSettings(object sender, RoutedEventArgs e) { local.TrayIconClickBehavior = TrayIconBehaviors[tcb.SelectedIndex]; local.TrayIconRightClickBehavior = TrayIconBehaviors[trcb.SelectedIndex]; local.TrayIconDoubleClickBehavior = TrayIconBehaviors[tdcb.SelectedIndex]; local.MinimizeBehavior = WindowBehaviors[mb.SelectedIndex]; local.ExitBehavior = WindowBehaviors[cb.SelectedIndex]; local.EncryptionType = (EncryptionTypeEnum)enctype.SelectedIndex; MainWindow mw = (App.Current.MainWindow as MainWindow); local.Theme = (Theme)themeCombox.SelectedItem; if (this.langCombox.SelectedIndex > -1) { string new_choice = this.langCombox.SelectedValue.ToString(); if (new_choice != local.DefaultLanguage) { local.DefaultLanguage = new_choice; if (App.CurrentLanguage != null) { App.CurrentLanguage.ReloadLang(local.DefaultLanguage); } else { App.CurrentLanguage = LanguageEngine.LoadDefault(); } } } if (local.CheckForUpdates) { mw.StartAutoUpdater(); } else { mw.StopAutoUpdater(); } if (local.EnableDHT) { mw.state.LibtorrentSession.StartDht(); } else { mw.state.LibtorrentSession.StopDht(); } if (local.EnableLSD) { mw.state.LibtorrentSession.StartLsd(); } else { mw.state.LibtorrentSession.StopLsd(); } if (local.EnableNAT_PMP) { mw.state.LibtorrentSession.StartNatPmp(); } else { mw.state.LibtorrentSession.StopNatPmp(); } if (local.Enable_UPNP) { mw.state.LibtorrentSession.StartUpnp(); } else { mw.state.LibtorrentSession.StopUpnp(); } App.Settings = (Settings)Utility.CloneObject(local); this.Close(); }
/// <summary> /// Save an empty .xml file on the desktop to be used by translators. /// </summary> public static void SaveDummy() { Utility.Serialize <LanguageEngine>(LanguageEngine.GetDummyLanguageEngine(), Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), "byteflood_lang_empty.xml"), true); }
private static LanguageEngine GetDummyLanguageEngine() { var le = new LanguageEngine(); Type t = typeof(LanguageEngine); var props = t.GetProperties(); foreach (var prop in props) { prop.SetValue(le, prop.Name.Split('_').Last()); } return le; }