コード例 #1
0
        private void importLocalSettingsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (openSettingsFileDialog.ShowDialog() == DialogResult.OK)
                try
                {
                    LocalSettings sett = Program.Settings;
                    string originalHost = sett.Current.Host;
                    int originalPort = sett.Current.Port;
                    FileLocalSettingsStore store = new FileLocalSettingsStore();
                    JsonObject jo = store.Load(openSettingsFileDialog.FileName);
                    LocalSettings newsettings = new LocalSettings(jo);

                    // if no error, load to right place
                    Program.Settings.LoadFromJson(jo);
                    if (Program.Connected && (sett.Current.Host != originalHost || sett.Current.Port != originalPort))
                    {
                        Program.Connected = false;
                        Connect();
                    }
                }
                catch (Exception ee)
                {
                    MessageBox.Show(ee.Message, OtherStrings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
                };
        }
コード例 #2
0
        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;
        }
コード例 #3
0
        private static void Main(string[] args)
        {
            startupTime = DateTime.Now;
#if DEBUG
            // In debug builds we'd prefer to have it dump us into the debugger
#else
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.Automatic);
            Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);
#endif

            culturechanger.ApplyHelp = culturechanger.ApplyText = culturechanger.ApplyToolTip = true;
            culturechanger.ApplyLocation = culturechanger.ApplySize = false;
            settings = LocalSettings.TryLoad();
            uploadPrompt = settings.UploadPrompt;
            args = Array.FindAll(args, delegate (string str) { return !str.Equals("/m"); });
            Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(settings.Locale, true);
#if DOTNET35
            using (NamedPipeSingleInstance singleInstance = new TCPSingleInstance(TCP_SINGLE_INSTANCE_PORT))
#else
            using (TCPSingleInstance singleInstance = new TCPSingleInstance(TCP_SINGLE_INSTANCE_PORT))
#endif
            {
                if (singleInstance.IsFirstInstance)
                {
                    try
                    {
                        ServicePointManager.ServerCertificateValidationCallback = TransmissionWebClient.ValidateServerCertificate;
                    }
                    catch
                    {
#if MONO
#pragma warning disable 618
                        ServicePointManager.CertificatePolicy = new PromiscuousCertificatePolicy();
#pragma warning restore 618
#endif
                    }
                    ServicePointManager.Expect100Continue = false;

                    /* Store a list of torrents to upload after connect? */
                    if (args.Length > 0)
                    {
                        singleInstance.PassArgumentsToFirstInstance(args);
                    }
                    singleInstance.ArgumentsReceived += singleInstance_ArgumentsReceived;
                    SystemEvents.PowerModeChanged += new PowerModeChangedEventHandler(SystemEvents_PowerModeChanged);
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    form = new MainWindow();
                    form.Load += new EventHandler(delegate (object sender, EventArgs e)
                    {
                        singleInstance.ListenForArgumentsFromSuccessiveInstances();
                    });
                    Application.Run(form);
                }
                else
                {
                    try
                    {
                        singleInstance.PassArgumentsToFirstInstance(args);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Unable to communicate with first instance", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }