Пример #1
0
        private async Task <bool> ProcessDirectory(LocalFolder folder)
        {
            if (m_CancellationToken.IsCancellationRequested)
            {
                return(false);
            }

            OnProgress();

            var x = 0;

            foreach (var file in folder.Files)
            {
                if (!await ProcessFile(file))
                {
                    return(false);
                }

                if (++x % 10 == 0)
                {
                    OnProgress();
                }
            }

            foreach (var subDir in folder.Folders)
            {
                if (!await ProcessDirectory(subDir))
                {
                    return(false);
                }
            }

            m_FoldersProcessed++;
            OnProgress();

            return(true);
        }
Пример #2
0
        public CleanupJob(LocalFolder rootFolder, CleanupJobSettings settings, CancellationToken cancellationToken)
        {
            if (!rootFolder.IsRootFolder)
            {
                throw new ArgumentException("Folder must be Root Folder", nameof(rootFolder));
            }

            m_Settings          = settings;
            m_CancellationToken = cancellationToken;

            RootFolder = rootFolder;

            /*
             * Cycle through all folders and files and:
             *
             * - Flag up unknown file types (non-video/image: e.g. https://developers.google.com/photos/library/guides/upload-media#file-types-sizes) and prompt to delete?
             *     > Ignore known files like Thumbs.db ?
             * - Build up list of filenames across the whole tree and then detect dupes and suggest renaming by prefixing date taken?
             * - Detect missing Date Taken?
             * - Detect Date Taken which looks partial (1st month, no time etc?)
             * - Detect files with invalid format of Date Taken: yyyy:MM:dd:HH:mm:ss
             * - Update file Create Date from Date Taken             *
             */
        }
Пример #3
0
        public async Task Load(CancellationToken cancellationToken)
        {
            TotalFolders = 1; // This folder
            AllFiles     = new List <LocalFile>();

            try
            {
                await Task.Run(() =>
                {
                    var files = new List <LocalFile>();
                    foreach (var file in Dir.EnumerateFiles())
                    {
                        if (cancellationToken.IsCancellationRequested)
                        {
                            return;
                        }

                        if (Settings.IsFileIgnored(file))
                        {
                            continue;
                        }

                        files.Add(new LocalFile(file, Settings));

                        TotalFiles++;
                        TotalFileSize += file.Length;

                        if (files.Count % 10 == 0)
                        {
                            OnLoadProgress();
                        }
                    }

                    Files = files;
                }, cancellationToken);

                await Task.Run(async() =>
                {
                    var folders = new List <LocalFolder>();

                    foreach (var dir in Dir.EnumerateDirectories().OrderBy(d => d.Name))
                    {
                        if (cancellationToken.IsCancellationRequested)
                        {
                            return;
                        }

                        if (Settings.IsFolderIgnored(dir))
                        {
                            continue;
                        }

                        var folder = new LocalFolder(dir, Settings);
                        folders.Add(folder);
                        await folder.Load(cancellationToken);

                        TotalFiles    += folder.TotalFiles;
                        TotalFileSize += folder.TotalFileSize;
                        TotalFolders  += folder.TotalFolders;

                        AllFiles.AddRange(folder.Files);

                        OnLoadProgress();
                    }

                    Folders = folders;
                }, cancellationToken);
            }
            catch (TaskCanceledException)
            {
                return;
            }

            m_LoadCompleted = IsRootFolder && !cancellationToken.IsCancellationRequested;
            OnLoadProgress();
        }