private ListViewItem CreateServerItem(string name, TransmissionServer ts) { ListViewItem lv = new ListViewItem(); lv.Name = lv.Text = name; lv.SubItems.Add(ts.Host); lv.SubItems.Add(ts.Port.ToString()); lv.Tag = ts; return lv; }
public static void SetupWebRequest(HttpWebRequest request, bool rpc, bool authenticate) { request.KeepAlive = false; request.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip, deflate"); request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate; request.UserAgent = string.Format("{0}/{1}", AboutDialog.AssemblyProduct, AboutDialog.AssemblyVersion); if (x_transmission_session_id != null && authenticate && rpc) { request.Headers["X-Transmission-Session-Id"] = x_transmission_session_id; } if (!rpc) { request.CookieContainer = PersistentCookies.GetCookieContainerForUrl(request.RequestUri); } Settings.TransmissionServer settings = Program.Settings.Current; if (settings.AuthEnabled && authenticate) { request.Credentials = new NetworkCredential(settings.Username, settings.ValidPassword); request.PreAuthenticate = Program.DaemonDescriptor.Version < 1.40 || Program.DaemonDescriptor.Version >= 1.6; } if (settings.Proxy.ProxyMode == ProxyMode.Enabled) { request.Proxy = new WebProxy(settings.Proxy.Host, settings.Proxy.Port); if (settings.Proxy.AuthEnabled) { string[] user = settings.Proxy.Username.Split("\\".ToCharArray(), 2); if (user.Length > 1) { request.Proxy.Credentials = new NetworkCredential(user[1], settings.Proxy.ValidPassword, user[0]); } else { request.Proxy.Credentials = new NetworkCredential(settings.Proxy.Username, settings.Proxy.ValidPassword); } } } else if (settings.Proxy.ProxyMode == ProxyMode.Disabled) { request.Proxy = null; } }
public static LocalSettings TryLoad() { LocalSettings newsettings = null; ILocalSettingsStore[] SettingsSource = new ILocalSettingsStore[] { #if !PORTABLE new RegistryLocalSettingsStore(), new RegistryJsonLocalSettingsStore(), #endif new FileLocalSettingsStore() }; foreach (ILocalSettingsStore ls in SettingsSource) { try { JsonObject jo = ls.Load(); newsettings = new LocalSettings(jo); newsettings.DefaultLocalStore = ls; break; } catch { }; } if (newsettings == null) { // not load from any source :(, try old mode try { LocalSettings tempsettings = new LocalSettings(); #if !PORTABLE LocalSettingsSingleton oldsettings = LocalSettingsSingleton.OneInstance(); tempsettings.Locale = oldsettings.Locale; tempsettings.CompletedBaloon = oldsettings.CompletedBaloon; tempsettings.MinOnClose = oldsettings.MinOnClose; tempsettings.MinToTray = oldsettings.MinToTray; tempsettings.PlinkPath = oldsettings.PlinkPath; tempsettings.StartedBalloon = oldsettings.StartedBalloon; tempsettings.UploadPrompt = oldsettings.UploadPrompt; tempsettings.AutoCheckupdate = oldsettings.AutoCheckupdate; string origcurrentprofile = oldsettings.CurrentProfile; foreach (string p in oldsettings.Profiles) { oldsettings.CurrentProfile = p; TransmissionServer ts = new TransmissionServer(); ts.CustomPath = oldsettings.CustomPath; ts.DownLimit = oldsettings.DownLimit; ts.UpLimit = oldsettings.UpLimit; ts.Host = oldsettings.Host; ts.Password = oldsettings.Pass; ts.PlinkCmd = oldsettings.PlinkCmd; ts.PlinkEnable = oldsettings.PlinkEnable; ts.Port = oldsettings.Port; ts.RefreshRate = oldsettings.RefreshRate; ts.RefreshRateTray = oldsettings.RefreshRate * 10; ts.StartPaused = oldsettings.StartPaused; ts.Username = oldsettings.User; ts.UseSSL = oldsettings.UseSSL; JsonObject mappings = oldsettings.SambaShareMappings; foreach (string key in mappings.Names) { ts.AddSambaMapping(key, (string)mappings[key]); } ts.destpathhistory.AddRange(oldsettings.DestPathHistory); ProxyServer ps = new ProxyServer(); ps.Host = oldsettings.ProxyHost; ps.Password = oldsettings.ProxyPass; ps.Port = oldsettings.ProxyPort; ps.Username = oldsettings.ProxyUser; ps.ProxyMode = (ProxyMode)oldsettings.ProxyMode; ts.Proxy = ps; tempsettings.Servers.Add(p, ts); if (origcurrentprofile.Equals(p)) { tempsettings.CurrentProfile = p; } } if (tempsettings.CurrentProfile.Equals("") && tempsettings.Servers.Count > 0) { tempsettings.CurrentProfile = "aa"; //tempsettings.Servers. . Key; } foreach (string s in oldsettings.ListObject(true)) { if (s.StartsWith("mainwindow-") || s.StartsWith("listview-")) { tempsettings.Misc[s] = oldsettings.GetObject(s, true); } } // move old stuff to backup! //oldsettings.BackupSettings(); #endif /* Only use the old settings, if we can read completely */ newsettings = tempsettings; } catch { newsettings = new LocalSettings(); }; newsettings.Commit(); } return(newsettings); }
public static LocalSettings TryLoad() { LocalSettings newsettings = null; ILocalSettingsStore[] SettingsSource = new ILocalSettingsStore[] { #if !PORTABLE new RegistryLocalSettingsStore(), new RegistryJsonLocalSettingsStore(), #endif new FileLocalSettingsStore() }; foreach (ILocalSettingsStore ls in SettingsSource) { try { JsonObject jo = ls.Load(); newsettings = new LocalSettings(jo); newsettings.DefaultLocalStore = ls; break; } catch { }; } if (newsettings == null) { // not load from any source :(, try old mode try { LocalSettings tempsettings = new LocalSettings(); #if !PORTABLE LocalSettingsSingleton oldsettings = LocalSettingsSingleton.OneInstance(); tempsettings.Locale = oldsettings.Locale; tempsettings.CompletedBaloon = oldsettings.CompletedBaloon; tempsettings.MinOnClose = oldsettings.MinOnClose; tempsettings.MinToTray = oldsettings.MinToTray; tempsettings.PlinkPath = oldsettings.PlinkPath; tempsettings.StartedBalloon = oldsettings.StartedBalloon; tempsettings.UploadPrompt = oldsettings.UploadPrompt; tempsettings.AutoCheckupdate = oldsettings.AutoCheckupdate; string origcurrentprofile = oldsettings.CurrentProfile; foreach (string p in oldsettings.Profiles) { oldsettings.CurrentProfile = p; TransmissionServer ts = new TransmissionServer(); ts.CustomPath = oldsettings.CustomPath; ts.DownLimit = oldsettings.DownLimit; ts.UpLimit = oldsettings.UpLimit; ts.Host = oldsettings.Host; ts.Password = oldsettings.Pass; ts.PlinkCmd = oldsettings.PlinkCmd; ts.PlinkEnable = oldsettings.PlinkEnable; ts.Port = oldsettings.Port; ts.RefreshRate = oldsettings.RefreshRate; ts.RefreshRateTray = oldsettings.RefreshRate * 10; ts.StartPaused = oldsettings.StartPaused; ts.Username = oldsettings.User; ts.UseSSL = oldsettings.UseSSL; JsonObject mappings = oldsettings.SambaShareMappings; foreach (string key in mappings.Names) { ts.AddSambaMapping(key, (string)mappings[key]); } ts.destpathhistory.AddRange(oldsettings.DestPathHistory); ProxyServer ps = new ProxyServer(); ps.Host = oldsettings.ProxyHost; ps.Password = oldsettings.ProxyPass; ps.Port = oldsettings.ProxyPort; ps.Username = oldsettings.ProxyUser; ps.ProxyMode = (ProxyMode)oldsettings.ProxyMode; ts.Proxy = ps; tempsettings.Servers.Add(p, ts); if (origcurrentprofile.Equals(p)) tempsettings.CurrentProfile = p; } if (tempsettings.CurrentProfile.Equals("") && tempsettings.Servers.Count > 0) tempsettings.CurrentProfile = "aa"; //tempsettings.Servers. . Key; foreach (string s in oldsettings.ListObject(true)) { if (s.StartsWith("mainwindow-") || s.StartsWith("listview-")) tempsettings.Misc[s] = oldsettings.GetObject(s, true); } // move old stuff to backup! //oldsettings.BackupSettings(); #endif /* Only use the old settings, if we can read completely */ newsettings = tempsettings; } catch { newsettings = new LocalSettings(); }; newsettings.Commit(); } return newsettings; }
private void addServerToolStripMenuItem_Click(object sender, EventArgs e) { TransmissionServer ts = new TransmissionServer(); string name; int counter = 0; do { name = "Server " + (counter++); } while (listServers.Items.ContainsKey(name)); listServers.Items.Add(CreateServerItem(name, ts)); CurrentProfileComboBox.Items.Add(name); AutoConnectComboBox.Items.Add(name); }