示例#1
0
        private void CheckPath(string syncthingPath)
        {
            btnStart.Enabled          = false;
            btnStop.Enabled           = false;
            timerCheckSync.Enabled    = false;
            groupBoxSyncthing.Enabled = false;

            if (string.IsNullOrEmpty(syncthingPath) || !File.Exists(syncthingPath))
            {
                return;
            }
            txtPath.Text = syncthingPath;
            Settings.Default.SyncthingPath = syncthingPath;
            Settings.Default.Save();

            var isRunning = IsSyncthingRunning();

            btnStart.Enabled       = !isRunning;
            btnStop.Enabled        = isRunning;
            timerCheckSync.Enabled = true;

            _syncthingConfig = SyncthingConfig.Load();
            if (_syncthingConfig != null)
            {
                _syncthingConfig.Watcher.Changed += Watcher_Changed;
                ReloadConfig();
                groupBoxSyncthing.Enabled = true;
            }
        }
示例#2
0
        internal static SyncthingConfig Load()
        {
            if (string.IsNullOrEmpty(ConfigPath))
            {
                return(null);
            }

            var conf = new SyncthingConfig();

            using (var reader = XmlReader.Create(ConfigPath))
            {
                while (reader.Read())
                {
                    if (!reader.IsStartElement())
                    {
                        continue;
                    }
                    switch (reader.Name)
                    {
                    case "configuration":
                        conf.Version = reader.GetAttribute("version");
                        break;

                    case "gui":
                        conf.GuiEnabled   = Convert.ToBoolean(reader.GetAttribute("enabled"));
                        conf.HttpsEnabled = Convert.ToBoolean(reader.GetAttribute("tls"));
                        if (reader.ReadToDescendant("address") && reader.Read())
                        {
                            conf.GuiAddress = reader.Value;
                        }
                        break;

                    case "options":
                        if (reader.ReadToDescendant("startBrowser") && reader.Read())
                        {
                            conf.StartBrowser = Convert.ToBoolean(reader.Value);
                        }
                        if (reader.ReadToDescendant("upnpEnabled") && reader.Read())
                        {
                            conf.UpnpEnabled = Convert.ToBoolean(reader.Value);
                        }
                        break;
                    }
                }
            }

            conf.Watcher = new FileSystemWatcher(Path.GetDirectoryName(ConfigPath))
            {
                NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite,
                Filter       = "*.xml"
            };

            return(conf);
        }
示例#3
0
 public SynchtingConfigEventArgs(SyncthingConfig configuration)
 {
     this.Configuration = configuration;
 }
示例#4
0
 private void SyncthingConfigOnConfigurationChanged(object sender, SynchtingConfigEventArgs args)
 {
     _syncthingConfig = args.Configuration;
     Invoke(new MethodInvoker(ReloadConfig));
 }