Пример #1
0
        protected override void InternalRunWorker(object arg)
        {
            try
            {
                _log.Info("Processing: " + arg);
                using (var path = new PowerPath(arg.ToString()))
                {
                    if (!FileExtensions.Contains(path.GetExtension()))
                    {
                        return;
                    }

                    var newDir = Path.Combine(path.GetDirectoryPath(), path.GetFileNameWithoutExtension());
                    Directory.CreateDirectory(newDir);

                    var newFile = Path.Combine(newDir, path.GetFileName());
                    File.Move(path.GetFullPath(), newFile);

                    _log.Info("Processed: " + arg);
                    OnProgressChanged(this, new ProgressChangedEventArgs(-1, newFile));
                }
            }
            catch (Exception e)
            {
                _log.Error(e, "Error processing: " + arg);
            }
        }
Пример #2
0
        protected override void InternalRunWorker(object arg)
        {
            var movieEntry = (MovieEntryFacade)arg;

            _log.Info("Processing: " + movieEntry.Title);

            try
            {
                var url = _tmdb.GetPosterUrl(movieEntry.InternalMovieData.PosterPath, PosterSize.original);

                var destFolder = new PowerPath(movieEntry.FullPath).GetDirectoryPath();
                var destFile   = Path.Combine(destFolder, FileName);

                var isExist = File.Exists(destFile);
                if (isExist && OverwritePoster)
                {
                    File.Delete(destFile);
                }
                if (!isExist || OverwritePoster)
                {
                    _wc.DownloadFile(url, destFile);
                }

                _log.Info("Processed: " + movieEntry.Title);
                IncrementWorkDone();
                OnProgressChanged(this, new ProgressChangedEventArgs(GetPercentage(), null));
            }
            catch (Exception e)
            {
                _log.Error(e, "Error processing: " + movieEntry.Title);
            }
        }
Пример #3
0
        public void TestRenamePath()
        {
            var path = new PowerPath(TestDirPath);

            path.RenameLastDirectory(TestDirName);
            Assert.AreEqual(TestDirRenamedPath, path);
        }
Пример #4
0
        public void TestSwapFileName()
        {
            var name = new PowerPath("E:\\fahmi\\The Fah.jpg");

            name.SwapFileName("The");

            Assert.AreEqual("E:\\fahmi\\Fah, The.jpg", name);
        }
Пример #5
0
        public void TestSwapDirName()
        {
            var name = new PowerPath("E:\\Nya fahmi\\The Fah.jpg");

            name.SwapLastDirectoryName("Nya");

            Assert.AreEqual("E:\\fahmi, Nya\\The Fah.jpg", name);
        }
Пример #6
0
        public TmdbResult LoadData(PowerPath info)
        {
            var persistFile = Path.Combine(info.GetDirectoryPath(), PersistentFileName);

            return(HasPersistentData(info.GetDirectoryPath())
                ? JsonConvert.DeserializeObject <TmdbResult>(File.ReadAllText(persistFile))
                : null);
        }
Пример #7
0
        public void TestPatternRename()
        {
            string org = "E:\\coba1\\coba.html";

            var fullPathObj = new PowerPath(org);
            var values      = ValueObject.CreateMock();
            var result      = fullPathObj.RenameFileByPattern("{Name}{Value}", values);

            Assert.AreEqual("Fahmit.html", result.GetFileName());
        }
Пример #8
0
        public void TestMultiRename()
        {
            string org = "E:\\[Inbox]\\1.png";

            var fullPathObj = new PowerPath(org);

            fullPathObj.RenameFile("DD").RenameLastDirectory("DD");

            Assert.AreEqual("E:\\DD\\DD.png", fullPathObj);
        }
Пример #9
0
 private void Worker_ProgressChanged(object sender, ProgressChangedEventArgs e)
 {
     _synchronizationContext.Post(d =>
     {
         using (var path = new PowerPath(e.UserState.ToString()))
         {
             Interlocked.Increment(ref _processed);
             lblCount.Text = string.Format(StringResources.MoveMoviesCount, Interlocked.CompareExchange(ref _processed, 0, 0));
             var item      = lvMovies.Items.Add(path.GetFileName());
             item.SubItems.Add(path.GetDirectoryPath());
         }
     }, null);
 }
Пример #10
0
        protected override void InternalRunWorker(object arg)
        {
            try
            {
                _log.Info("Processing: " + arg);
                var currentFolder = new PowerPath(arg.ToString());

                // check for ignore pattern
                var lastName = currentFolder.GetLastDirectoryName();
                if (lastName.StartsWith("[") && lastName.EndsWith("]"))
                {
                    _log.Debug("Process skipped due to directory name.");
                    return;
                }

                // find first movie
                var currentMoviePath = _persistentDataManager.FindFirstMovieFile(arg.ToString());
                if (currentMoviePath == null)
                {
                    _log.Debug("Process skipped due to unavaliable movie file.");
                    return;
                }

                // find metadata
                TmdbResult entry;
                if (_persistentDataManager.HasPersistentData(currentMoviePath.GetDirectoryPath()))
                {
                    _log.Debug("Using saved presist data.");
                    entry = _persistentDataManager.LoadData(currentMoviePath);
                }
                else
                {
                    _log.Debug("Creating new data using GetByFilename.");
                    entry = _tmdb.GetByFilename(currentMoviePath.GetFileNameWithoutExtension());
                }

                // pop to event
                var result = new MovieEntryFacade(entry, currentMoviePath);
                OnProgressChanged(this, new ProgressChangedEventArgs(-1, new DirectoryAnalyzeWorkerState
                {
                    Entry = result
                }));

                _log.Info("Processed: " + arg);
            }
            catch (Exception e)
            {
                _log.Error(e, "Process error. Path: " + arg);
            }
        }
Пример #11
0
        public void InternalOrganizeDirectory(string path)
        {
            // enumerate
            UpdateUi(UiState.Working);
            var extensions         = new List <string>(Settings.Default.MovieExtensions.Split(';'));
            var dirEnumbEnumerable = Directory.EnumerateFiles(path, "*", SearchOption.TopDirectoryOnly);

            // walk
            foreach (var basePath in dirEnumbEnumerable)
            {
                try
                {
                    var currentPath = new PowerPath(basePath);
                    if (!extensions.Contains(currentPath.GetExtension()))
                    {
                        return;
                    }

                    var newDir  = Path.Combine(currentPath.GetDirectoryPath(), currentPath.GetFileNameWithoutExtension());
                    var newFile = Path.Combine(newDir, currentPath.GetFileName());

                    Directory.CreateDirectory(newDir);
                    File.Move(currentPath.GetFullPath(), newFile);
                    Model.Invoke(() => Model.DataView.Add(new MovedMovieEntry
                    {
                        Title = Path.GetFileName(path),
                        Path  = Path.GetDirectoryName(path)
                    }));
                }
                catch (Exception e)
                {
                    Debug.Print("Organize error: {0}. {1}", basePath, e.Message);
                }

                if (CancellationToken.IsCancellationRequested)
                {
                    break;
                }
            }

            // finish
            UpdateUi(UiState.Ready);
        }
Пример #12
0
        private void RenameFile(PowerPath fileInfo, MovieEntryFacade entry)
        {
            var originalFilePath = fileInfo.GetFullPath();
            var renamedFile      = fileInfo.RenameFileByPattern(FileRenamePattern, entry);

            if (SwapThe)
            {
                renamedFile.SwapFileName(Commons.TheName);
            }
            var name = renamedFile.GetFileName();

            var destFilePath = Path.Combine(fileInfo.GetDirectoryPath(), name);

            if (originalFilePath == destFilePath)
            {
                return;
            }
            File.Move(originalFilePath, destFilePath);
            entry.FullPath = destFilePath;
        }
Пример #13
0
        private void HelperRenameFile(string path, MovieEntry entry)
        {
            // store original path
            var fileInfo         = new PowerPath(path);
            var originalFilePath = fileInfo.GetFullPath();

            // rename path
            var renamedFile = fileInfo.RenameFileByPattern(_settings.FileRenamePattern, entry);

            if (_settings.SwapThe)
            {
                renamedFile.SwapFileName(Commons.TheName);
            }

            // rename
            if (originalFilePath == renamedFile)
            {
                return;
            }
            File.Move(originalFilePath, renamedFile);
        }
Пример #14
0
        protected override void InternalRunWorker(object arg)
        {
            var entry = (MovieEntryFacade)arg;

            try
            {
                _log.Info("Processing: " + entry.Title);
                using (var fileInfo = new PowerPath(entry.FullPath))
                {
                    RenameFile(fileInfo, entry);
                    RenameDirectory(fileInfo, entry);
                }

                _log.Info("Processed: " + entry.Title);
                IncrementWorkDone();
                OnProgressChanged(this, new ProgressChangedEventArgs(GetPercentage(), null));
            }
            catch (Exception e)
            {
                _log.Error(e, "Error processing: " + entry.Title);
            }
        }
Пример #15
0
        private void RenameDirectory(PowerPath fileInfo, MovieEntryFacade entry)
        {
            var originalFilePath = fileInfo.GetDirectoryPath();
            var renamedPath      = fileInfo.RenameLastDirectoryByPattern(FolderRenamePattern, entry);

            if (SwapThe)
            {
                renamedPath.SwapLastDirectoryName(Commons.TheName);
            }
            var directoryPath = renamedPath.GetDirectoryPath();

            if (originalFilePath == directoryPath)
            {
                return;
            }
            Directory.Move(originalFilePath, directoryPath);

            var name = Path.GetFileName(entry.FullPath);

            Debug.Assert(name != null);
            entry.FullPath = Path.Combine(directoryPath, name);
        }
Пример #16
0
        private void HelperRenameDirectory(string path, MovieEntry entry)
        {
            // store original path
            var fileInfo     = new PowerPath(path);
            var originalPath = fileInfo.GetDirectoryPath();

            // rename path
            var renamedPath = fileInfo.RenameLastDirectoryByPattern(_settings.FolderRenamePattern, entry);

            if (_settings.SwapThe)
            {
                renamedPath.SwapLastDirectoryName(Commons.TheName);
            }
            var directoryPath = renamedPath.GetDirectoryPath();

            // rename
            if (originalPath == directoryPath)
            {
                return;
            }
            Directory.Move(originalPath, directoryPath);
        }
Пример #17
0
        public void TestFilePathCreation()
        {
            var path = new PowerPath(TestFilePath);

            Assert.AreEqual(TestFilePath, path);
        }
Пример #18
0
        public void TestIsDirectoryFromFilePath()
        {
            var path = new PowerPath(TestFilePath);

            Assert.IsFalse(path.IsDirectory);
        }
Пример #19
0
        public void TestDirUp()
        {
            var path = new PowerPath(TestDirPath).UpOneLevel();

            Assert.AreEqual(TestDirPathUpOneLevel, path);
        }
Пример #20
0
        private async void InternalOpenDirectory(string path)
        {
            // save states
            UpdateUi(UiState.Working);
            _settings.LastOpenDirectory = path;
            _settings.Save();

            // clear data
            Model.Invoke(() => Model.DataView.Clear());

            // enumerate
            var tmdb = _kernel.Get <ITmdb>();
            var persistFileManager = _kernel.Get <IPersistFileManager>();
            var dirEnumbEnumerable = Directory.EnumerateDirectories(path, "*", SearchOption.TopDirectoryOnly).ToList();
            var calc = new PercentageCalculator(dirEnumbEnumerable.Count);

            // walk
            foreach (var basePath in dirEnumbEnumerable)
            {
                try
                {
                    string currentMoviePath;
                    var    currentFolder = new PowerPath(basePath);

                    // check for ignore pattern
                    var lastName = currentFolder.GetLastDirectoryName();
                    if (lastName.StartsWith("[") && lastName.EndsWith("]"))
                    {
                        continue;
                    }

                    // find first movie
                    if ((currentMoviePath = HelperFindFirstFile(basePath)) == null)
                    {
                        continue;
                    }

                    // find metadata
                    MovieEntry entry;
                    if (persistFileManager.HasPersistentData(Path.GetDirectoryName(currentMoviePath)))
                    {
                        entry = persistFileManager.Load(currentMoviePath);
                    }
                    else
                    {
                        var currentResult = await tmdb.GetByFilename(currentMoviePath);

                        entry = new MovieEntry();
                        entry.SetFullPath(currentMoviePath);
                        entry.SetData(currentResult);
                    }

                    // push to collection
                    Model.Invoke(() => Model.DataView.Add(entry));
                }
                catch (Exception e)
                {
                    Debug.Print("Analyze error: {0}. {1}", basePath, e.Message);
                }

                // sync
                _lastSelectedIndex = -1;
                UpdateUi(UiState.StatusUpdate, calc.Increment());
                if (IsCancellationRequested)
                {
                    break;
                }
            }

            // finish
            UpdateUi(UiState.Ready);
        }
Пример #21
0
        public void TestIsDirectoryFromPath()
        {
            var path = new PowerPath(TestDirPath);

            Assert.IsTrue(path.IsDirectory);
        }
Пример #22
0
        public void TestFileExist()
        {
            var path = new PowerPath(TestFilePath);

            Assert.IsTrue(path.IsFile);
        }