public TmdbResult LoadData(PowerPath info) { var persistFile = Path.Combine(info.GetDirectoryPath(), PersistentFileName); return(HasPersistentData(info.GetDirectoryPath()) ? JsonConvert.DeserializeObject <TmdbResult>(File.ReadAllText(persistFile)) : null); }
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); } }
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); }
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); }
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; }
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); }
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); }