private bool AddThread(string pageUrl, string pageAuth, string imageAuth, int checkIntervalSeconds, bool oneTimeDownload, string description, UrlTransformResult urlTransformResult)
        {
            if (urlTransformResult != null)
            {
                pageUrl = urlTransformResult.TransformedUrl;
            }
            SiteHelper    siteHelper     = SiteHelper.CreateByUrl(pageUrl);
            string        globalThreadID = siteHelper.GetGlobalThreadID();
            ThreadWatcher watcher        = ThreadList.Items.FirstOrDefault(w => w.GlobalThreadID.Equals(globalThreadID, StringComparison.OrdinalIgnoreCase));

            if (watcher == null)
            {
                description ??= urlTransformResult?.DefaultDescription ?? siteHelper.GetDefaultDescription();
                watcher = ThreadWatcher.Create(siteHelper, pageUrl, pageAuth, imageAuth, oneTimeDownload, checkIntervalSeconds, description);

                AttachWatcherToUI(watcher);
                DisplayDescription(watcher);
                DisplayAddedOn(watcher);

                ThreadList.Add(watcher);
            }
            else
            {
                if (watcher.IsRunning)
                {
                    return(false);
                }

                watcher.PageAuth             = pageAuth;
                watcher.ImageAuth            = imageAuth;
                watcher.CheckIntervalSeconds = checkIntervalSeconds;
                watcher.OneTimeDownload      = oneTimeDownload;

                if (description != null)
                {
                    watcher.Description = description;
                    DisplayDescription(watcher);
                }
            }

            watcher.Start();

            _saveThreadList = true;

            return(true);
        }
Ejemplo n.º 2
0
        public static void Load(Action <ThreadWatcher> onThreadLoad)
        {
            if (_watchers != null)
            {
                throw new Exception("Threads have already been loaded.");
            }

            _watchers = new List <ThreadWatcher>();

            string path = Path.Combine(Settings.GetSettingsDirectory(), Settings.ThreadsFileName);

            if (!File.Exists(path))
            {
                return;
            }

            ThreadListData data = JsonConvert.DeserializeObject <ThreadListData>(File.ReadAllText(path));

            if (data.FileVersion > _currentFileVersion)
            {
                throw new Exception("Threads file was created with a newer version of this program.");
            }
            else if (data.FileVersion <= 1)
            {
                // Skip loading if not backwards compatible
                return;
            }

            foreach (ThreadWatcherConfig config in data.Threads)
            {
                ThreadWatcher watcher = ThreadWatcher.Create(config);

                onThreadLoad(watcher);

                if (!watcher.IsStopping)
                {
                    watcher.Start();
                }

                _watchers.Add(watcher);
            }
        }