/// <summary>
        /// Search through all sub-folders and attempt to assign each one to content.
        /// </summary>
        /// <param name="fastUpdate">Whether update is fast, skips detailed updating(e.g. episodes for shows)</param>
        /// <param name="idsToUpdate">List of dtabase IDs that need updating</param>
        /// <param name="cancel">Cancelation flag</param>
        /// <param name="serverTime">Time on online database server</param>
        /// <returns>Whether update was completed without cancelation</returns>
        public bool UpdateContent(bool fastUpdate, ref bool cancel)
        {
            updateCancelled = false;

            // Update progress
            string progressMsg = "Update of '" + this.FullPath + "' started - Building threads";

            OnUpdateProgressChange(this, false, 0, progressMsg);

            // Initialize processing - First pass
            OrgProcessing firstPass = new OrgProcessing(UpdateProcess);

            updateNumber = firstPass.ProcessNumber;

            // Run 1st pass (build of sub-dirs is recursive, so all child root folder sub-dirs will be included)
            firstPass.Run(BuildSubDirectories(this.ContentType), ref cancel, true, Settings.General.NumProcessingThreads);
            updateCancelled = cancel;

            // Initialize processing - Second pass
            OrgProcessing secondPass = new OrgProcessing(UpdateProcess);

            updateNumber = secondPass.ProcessNumber;

            // Run 2nd pass (build of sub-dirs is recursive, so all child root folder sub-dirs will be included)
            secondPass.Run(BuildSubDirectories(this.ContentType), ref cancel, false, Settings.General.NumProcessingThreads);
            updateCancelled = cancel;

            // Get content collection to add content to
            ContentCollection content = GetContentCollection();

            // Remove shows that no longer exists
            if (!cancel)
            {
                content.RemoveMissing();
            }

            // Save changes
            //content.Sort();
            content.Save();

            // Set progress to completed
            progressMsg = "Update of '" + this.FullPath + "' complete!";
            OnUpdateProgressChange(this, false, 100, progressMsg);
            OnUpdateProgressComplete(this);

            // Return whether update was completed without cancelation
            return(!cancel);
        }
Exemple #2
0
        /// <summary>
        /// Searchs through a single folder and builds a list of files and actions to perform
        /// for those files. Performs recursively on sub-directories if folder has recursive
        /// property set.
        /// </summary>
        /// <param name="folder">Folder to search through</param>
        /// <param name="queuedItems">Items currenlty in the queue (to be skipped)</param>
        /// <param name="progressAmount">Percentage that directory scan represents of total scan</param>
        /// <param name="tvOnly">Whether ignore all files that aren't TV video files</param>
        /// <param name="background">Whether scan is running in background (ignores user cancellations)</param>
        public void RunScan(List<OrgFolder> folders, List<OrgItem> queuedItems, double progressAmount, bool tvOnly, bool skipDatabaseMatching, bool fast, bool reuseResults)
        {
            // Cleanup director scan log
            for (int i = Organization.DirScanLog.Count - 1; i >= 0; i--)
                if (!File.Exists(Organization.DirScanLog[i].SourcePath) && !Directory.Exists(Organization.DirScanLog[i].SourcePath))
                    Organization.DirScanLog.RemoveAt(i);
            Organization.SaveDirScanLog();

            // Set scan to running
            scanRunning = true;
            cancelRequested = false;
            IncrementScanNumber();

            // Update progress
            OnProgressChange(ScanProcess.FileCollect, string.Empty, 0);
            dirScanProgressAmount = progressAmount;

            // Clear update variables
            processStarted = 0;
            processCompletes = 0;

            // Initialize variables used in scan
            List<OrgPath> paths;
            lock (directoryScanLock)
            {
                itemsInQueue = queuedItems;
                temporaryShows = new List<TvShow>();

                // Create items
                List<OrgItem> autoMoves;
                paths = GetFolderFiles(folders, fast, skipDatabaseMatching, out autoMoves);
                this.Items.Clear();
                foreach(OrgPath path in paths)
                    this.Items.Add(new OrgItem(OrgAction.TBD, path.Path, FileCategory.Unknown, path.OrgFolder));
                foreach (OrgItem autoMove in autoMoves)
                    this.Items.Add(autoMove);
            }
            if (!cancelRequested)
                OnItemsInitialized(ScanProcess.Directory, this.Items);

            // Create processing object
            OrgProcessing processing = new OrgProcessing(ThreadProcess);
            int directoryScanNumber = processing.ProcessNumber;

            // Build arguments for 1st pass
            object[] args = new object[] { tvOnly, skipDatabaseMatching, fast, scanNumber, 0, reuseResults };

            // Run 1st pass
            if (this.background)
            {
                bool cancel = false;
                processing.Run(paths, ref cancel, args, 1);
            }
            else
                processing.Run(paths, ref cancelRequested, args, Settings.General.NumProcessingThreads);

            // Second pass
            if(!fast && !skipDatabaseMatching && !scanCanceled)
            {
                // Build arguments for 2nd pass
                args = new object[] { tvOnly, skipDatabaseMatching, fast, scanNumber, 1, reuseResults };

                // Run 2nd pass
                if (this.background)
                {
                    bool cancel = false;
                    processing.Run(paths, ref cancel, args, 1);
                }
                else
                    processing.Run(paths, ref cancelRequested, args, Settings.General.NumProcessingThreads);

            }

            // Set items to new object
            if (scanCanceled)
            {
                lock (directoryScanLock)
                {
                    int count = this.Items.Count;
                    this.Items = new List<OrgItem>();
                    for (int i = 0; i < count; i++)
                        this.Items.Add(new OrgItem());
                }
            }
            else
                OnProgressChange(ScanProcess.Directory, string.Empty, (int)progressAmount);

            scanRunning = false;
        }
Exemple #3
0
        /// <summary>
        /// Searchs through a single folder and builds a list of files and actions to perform
        /// for those files. Performs recursively on sub-directories if folder has recursive
        /// property set.
        /// </summary>
        /// <param name="folder">Folder to search through</param>
        /// <param name="queuedItems">Items currenlty in the queue (to be skipped)</param>
        /// <param name="progressAmount">Percentage that directory scan represents of total scan</param>
        /// <param name="tvOnly">Whether ignore all files that aren't TV video files</param>
        /// <param name="background">Whether scan is running in background (ignores user cancellations)</param>
        public void RunScan(List <OrgFolder> folders, List <OrgItem> queuedItems, double progressAmount, bool tvOnly, bool skipDatabaseMatching, bool fast, bool reuseResults)
        {
            // Cleanup director scan log
            for (int i = Organization.DirScanLog.Count - 1; i >= 0; i--)
            {
                if (!File.Exists(Organization.DirScanLog[i].SourcePath) && !Directory.Exists(Organization.DirScanLog[i].SourcePath))
                {
                    Organization.DirScanLog.RemoveAt(i);
                }
            }
            Organization.SaveDirScanLog();

            // Set scan to running
            scanRunning     = true;
            cancelRequested = false;
            IncrementScanNumber();

            // Update progress
            OnProgressChange(ScanProcess.FileCollect, string.Empty, 0);
            dirScanProgressAmount = progressAmount;

            // Clear update variables
            processStarted   = 0;
            processCompletes = 0;

            // Initialize variables used in scan
            List <OrgPath> paths;

            lock (directoryScanLock)
            {
                itemsInQueue   = queuedItems;
                temporaryShows = new List <TvShow>();

                // Create items
                List <OrgItem> autoMoves;
                paths = GetFolderFiles(folders, fast, skipDatabaseMatching, out autoMoves);
                this.Items.Clear();
                foreach (OrgPath path in paths)
                {
                    this.Items.Add(new OrgItem(OrgAction.TBD, path.Path, FileCategory.Unknown, path.OrgFolder));
                }
                foreach (OrgItem autoMove in autoMoves)
                {
                    this.Items.Add(autoMove);
                }
            }
            if (!cancelRequested)
            {
                OnItemsInitialized(ScanProcess.Directory, this.Items);
            }


            // Create processing object
            OrgProcessing processing          = new OrgProcessing(ThreadProcess);
            int           directoryScanNumber = processing.ProcessNumber;

            // Build arguments for 1st pass
            object[] args = new object[] { tvOnly, skipDatabaseMatching, fast, scanNumber, 0, reuseResults };

            // Run 1st pass
            if (this.background)
            {
                bool cancel = false;
                processing.Run(paths, ref cancel, args, 1);
            }
            else
            {
                processing.Run(paths, ref cancelRequested, args, Settings.General.NumProcessingThreads);
            }

            // Second pass
            if (!fast && !skipDatabaseMatching && !scanCanceled)
            {
                // Build arguments for 2nd pass
                args = new object[] { tvOnly, skipDatabaseMatching, fast, scanNumber, 1, reuseResults };

                // Run 2nd pass
                if (this.background)
                {
                    bool cancel = false;
                    processing.Run(paths, ref cancel, args, 1);
                }
                else
                {
                    processing.Run(paths, ref cancelRequested, args, Settings.General.NumProcessingThreads);
                }
            }

            // Set items to new object
            if (scanCanceled)
            {
                lock (directoryScanLock)
                {
                    int count = this.Items.Count;
                    this.Items = new List <OrgItem>();
                    for (int i = 0; i < count; i++)
                    {
                        this.Items.Add(new OrgItem());
                    }
                }
            }
            else
            {
                OnProgressChange(ScanProcess.Directory, string.Empty, (int)progressAmount);
            }

            scanRunning = false;
        }
        /// <summary>
        /// Search through all sub-folders and attempt to assign each one to content.
        /// </summary>
        /// <param name="fastUpdate">Whether update is fast, skips detailed updating(e.g. episodes for shows)</param>
        /// <param name="idsToUpdate">List of dtabase IDs that need updating</param>
        /// <param name="cancel">Cancelation flag</param>
        /// <param name="serverTime">Time on online database server</param>
        /// <returns>Whether update was completed without cancelation</returns>
        public bool UpdateContent(bool fastUpdate, ref bool cancel)
        {
            updateCancelled = false;

            // Update progress
            string progressMsg = "Update of '" + this.FullPath + "' started - Building threads";
            OnUpdateProgressChange(this, false, 0, progressMsg);

            // Initialize processing - First pass
            OrgProcessing firstPass = new OrgProcessing(UpdateProcess);
            updateNumber = firstPass.ProcessNumber;

            // Run 1st pass (build of sub-dirs is recursive, so all child root folder sub-dirs will be included)
            firstPass.Run(BuildSubDirectories(this.ContentType), ref cancel, true, Settings.General.NumProcessingThreads);
            updateCancelled = cancel;

            // Initialize processing - Second pass
            OrgProcessing secondPass = new OrgProcessing(UpdateProcess);
            updateNumber = secondPass.ProcessNumber;

            // Run 2nd pass (build of sub-dirs is recursive, so all child root folder sub-dirs will be included)
            secondPass.Run(BuildSubDirectories(this.ContentType), ref cancel, false, Settings.General.NumProcessingThreads);
            updateCancelled = cancel;

            // Get content collection to add content to
            ContentCollection content = GetContentCollection();

            // Remove shows that no longer exists
            if (!cancel)
                content.RemoveMissing();

            // Save changes
            //content.Sort();
            content.Save();

            // Set progress to completed
            progressMsg = "Update of '" + this.FullPath + "' complete!";
            OnUpdateProgressChange(this, false, 100, progressMsg);
            OnUpdateProgressComplete(this);

            // Return whether update was completed without cancelation
            return !cancel;
        }