Exemple #1
0
        public override void DeleteWithoutConfirmation(SharpTreeNode[] nodes)
        {
            CancellationTokenSource tokenSource        = new CancellationTokenSource();
            List <MediaFileItem>    mediaFilesToDelete = new List <MediaFileItem>();

            foreach (Location location in nodes)
            {
                try
                {
                    FileUtils.iterateFilesInDirectory(new DirectoryInfo(location.FullName), getFiles, mediaFilesToDelete, true);

                    MediaFileState.delete(mediaFilesToDelete, tokenSource.Token);

                    FileUtils fileUtils = new FileUtils();
                    fileUtils.deleteDirectory(location.FullName);

                    location.Parent.Children.Remove(location);
                }
                catch (Exception e)
                {
                    Logger.Log.Error("Error deleting directory: " + location.FullName, e);
                    MessageBox.Show("Error deleting directory: " + location.FullName + "\n\n" + e.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
            }
        }
Exemple #2
0
        protected MediaFileWatcher()
        {
            watcher        = new FileSystemWatcher();
            MediaFileState = new MediaFileState();

            // Watch for changes in LastAccess and LastWrite times, and
            //the renaming of files or directories.
            //watcher.NotifyFilter = (NotifyFilters)(NotifyFilters.LastAccess |
            //    NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName | NotifyFilters.Attributes);

            watcher.NotifyFilter = (NotifyFilters)(NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.Attributes);

            // Only watch text files.
            watcher.Filter = "*.*";

            // Add event handlers.
            watcher.Changed += new FileSystemEventHandler(FileChanged);
            watcher.Created += new FileSystemEventHandler(FileCreated);
            watcher.Deleted += new FileSystemEventHandler(FileDeleted);
            watcher.Renamed += new System.IO.RenamedEventHandler(FileRenamed);

            fileWatcherQueue = new MediaFileWatcherQueue(this);

            DebugOutput = false;
        }
        protected MediaFileWatcher()
        {
            watcher = new FileSystemWatcher();
            MediaFileState = new MediaFileState();
                               
            // Watch for changes in LastAccess and LastWrite times, and 
            //the renaming of files or directories. 
            //watcher.NotifyFilter = (NotifyFilters)(NotifyFilters.LastAccess |
            //    NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName | NotifyFilters.Attributes);

            watcher.NotifyFilter = (NotifyFilters)(NotifyFilters.LastWrite | NotifyFilters.FileName |  NotifyFilters.Attributes);

            // Only watch text files.
            watcher.Filter = "*.*";

            // Add event handlers.
            watcher.Changed += new FileSystemEventHandler(FileChanged);
            watcher.Created += new FileSystemEventHandler(FileCreated);
            watcher.Deleted += new FileSystemEventHandler(FileDeleted);
            watcher.Renamed += new System.IO.RenamedEventHandler(FileRenamed);

            fileWatcherQueue = new MediaFileWatcherQueue(this);

            DebugOutput = false;
         
        }
Exemple #4
0
        protected Location(InfoGatherTask infoGatherTask, MediaFileState state)
        {
            MediaFileState      = state;
            this.infoGatherTask = infoGatherTask;

            //state.NrImportedItemsChanged += new EventHandler<MediaStateChangedEventArgs>(importStateChanged);
        }
        public MediaFileGridViewModel(MediaFileState mediaState, IEventAggregator eventAggregator)
        {
            EventAggregator = eventAggregator;
            NrColumns       = 4;

            MediaStateCollectionView = new MediaFileStateCollectionView(mediaState);


            ViewCommand = new Command <SelectableMediaItem>((selectableItem) =>
            {
                MediaItem item = selectableItem.Item;

                if (item.Metadata is ImageMetadata)
                {
                    Shell.ShellViewModel.navigateToImageView(item);
                }
                else if (item.Metadata is VideoMetadata ||
                         item.Metadata is AudioMetadata)
                {
                    Shell.ShellViewModel.navigateToVideoView(item);
                }
            });

            SelectAllCommand = new Command(() =>
            {
                MediaStateCollectionView.selectAll();
            }, false);

            DeselectAllCommand = new Command(() =>
            {
                MediaStateCollectionView.deselectAll();
            });

            BrowseLocationCommand = new Command <SelectableMediaItem>((selectableItem) =>
            {
                MediaItem item = selectableItem.Item;

                String location = FileUtils.getPathWithoutFileName(item.Location);

                EventAggregator.GetEvent <MediaBrowserPathChangedEvent>().Publish(location);
            });

            OpenLocationCommand = new Command <SelectableMediaItem>((selectableItem) =>
            {
                MediaItem item = selectableItem.Item;

                String location = FileUtils.getPathWithoutFileName(item.Location);

                Process.Start(location);
            });

            WeakEventManager <MediaLockedCollection, EventArgs> .AddHandler(MediaStateCollectionView.MediaState.UIMediaCollection, "IsLoadingChanged", mediaCollection_IsLoadingChanged);

            PrevFilterMode = MediaFilterMode.None;
        }
Exemple #6
0
        public ExportProgressViewModel(MediaFileState mediaFileState)
        {
            MediaFileState = mediaFileState;

            WindowTitle = "Exporting Media";
            WindowIcon  = "pack://application:,,,/Resources/Icons/export.ico";

            ItemInfo = "";

            OkCommand.IsExecutable     = false;
            CancelCommand.IsExecutable = true;
        }
Exemple #7
0
        public DirectoryLocation(DirectoryInfo info, InfoGatherTask infoGatherTask, MediaFileState mediaFileState)
            : base(infoGatherTask, mediaFileState)
        {
            Name         = info.Name;
            CreationDate = info.CreationTime;

            VolumeLabel = "";

            //ImageUrl = "pack://application:,,,/Resources/Icons/mediafolder.ico";
            NrImported = 0;

            LazyLoading = true;

            PropertyChanged += propertyChanged;
        }
Exemple #8
0
        private void listMediaFiles(string path)
        {
            DirectoryInfo imageDirInfo = new DirectoryInfo(path);

            FileInfo[] fileInfo = imageDirInfo.GetFiles();

            List <MediaFileItem> items = new List <MediaFileItem>();

            for (int i = 0; i < fileInfo.Length; i++)
            {
                if (MediaFormatConvert.isMediaFile(fileInfo[i].FullName))
                {
                    items.Add(MediaFileItem.Factory.create(fileInfo[i].FullName));
                }
            }

            MediaFileState.clearUIState(imageDirInfo.Name, imageDirInfo.CreationTime, MediaStateType.Directory);
            MediaFileState.addUIState(items);
        }
Exemple #9
0
        protected virtual void Dispose(bool safe)
        {
            if (safe)
            {
                if (fileWatcherQueue != null)
                {
                    fileWatcherQueue.Dispose();
                }

                if (watcher != null)
                {
                    watcher.Dispose();
                }

                if (MediaFileState != null)
                {
                    MediaFileState.Dispose();
                }
            }
        }
Exemple #10
0
        void writeMetaData(MetaDataUpdateViewModelAsyncState state)
        {
            List <Counter> counters = new List <Counter>();
            String         oldPath = "", newPath = "";
            String         oldFilename = "", newFilename = "", ext = "";

            foreach (MediaFileItem item in state.ItemList)
            {
                if (CancellationToken.IsCancellationRequested)
                {
                    return;
                }

                ItemProgress = 0;
                ItemInfo     = "Opening: " + item.Location;
                bool isModified = false;


                // Update Metadata values
                item.EnterWriteLock();
                try
                {
                    isModified = updateMetadata(item, state);
                }
                catch (Exception e)
                {
                    string info = "Error updating Metadata: " + item.Location;

                    InfoMessages.Add(info);
                    Logger.Log.Error(info, e);
                    MessageBox.Show(info + "\n\n" + e.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
                finally
                {
                    item.ExitWriteLock();
                }

                // Save Metadata to disk
                if (isModified)
                {
                    String info;
                    ItemInfo = "Saving MetaData: " + item.Location;

                    item.EnterUpgradeableReadLock();
                    try
                    {
                        item.writeMetadata_URLock(MetadataFactory.WriteOptions.AUTO, this);
                    }
                    catch (Exception e)
                    {
                        info = "Error saving Metadata: " + item.Location;

                        InfoMessages.Add(info);
                        Logger.Log.Error(info, e);
                        MessageBox.Show(info + "\n\n" + e.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);

                        // reload metaData, exceptions are caught in readMetadata
                        if (item.Metadata != null)
                        {
                            item.Metadata.clear();
                        }

                        item.readMetadata_URLock(MetadataFactory.ReadOptions.AUTO |
                                                 MetadataFactory.ReadOptions.GENERATE_THUMBNAIL, CancellationToken);

                        return;
                    }
                    finally
                    {
                        item.ExitUpgradeableReadLock();
                    }

                    info = "Completed updating Metadata for: " + item.Location;

                    InfoMessages.Add(info);
                    Logger.Log.Info(info);
                }
                else
                {
                    string info = "Skipped updating Metadata (no changes) for: " + item.Location;

                    InfoMessages.Add(info);
                    Logger.Log.Info(info);
                }

                // Export if requested
                if (state.ImportedEnabled == true && state.IsImported == false)
                {
                    bool success = MediaFileState.export(item, CancellationToken);

                    if (success)
                    {
                        string info = "Exported: " + item.Location;

                        InfoMessages.Add(info);
                        Logger.Log.Info(info);
                    }
                }

                //rename and/or move
                item.EnterReadLock();
                try
                {
                    oldPath     = FileUtils.getPathWithoutFileName(item.Location);
                    oldFilename = Path.GetFileNameWithoutExtension(item.Location);
                    ext         = Path.GetExtension(item.Location);

                    newFilename = parseNewFilename(state.Filename, state.ReplaceFilename, state.IsRegexEnabled, oldFilename, item.Metadata);
                    newPath     = String.IsNullOrEmpty(state.Location) ? oldPath : state.Location;
                    newPath     = newPath.TrimEnd('\\');
                }
                finally
                {
                    item.ExitReadLock();
                }

                try
                {
                    MediaFileState.move(item, newPath + "\\" + newFilename + ext, this);
                }
                catch (Exception e)
                {
                    string info = "Error moving/renaming: " + item.Location;

                    InfoMessages.Add(info);
                    Logger.Log.Error(info, e);
                    MessageBox.Show(info + "\n\n" + e.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }

                // import if requested
                if (state.ImportedEnabled == true && state.IsImported == true)
                {
                    bool success = false;
                    try
                    {
                        success = MediaFileState.import(item, CancellationToken);
                    }
                    catch (Exception e)
                    {
                        string info = "Error importing media: " + item.Location;

                        InfoMessages.Add(info);
                        Logger.Log.Error(info, e);
                        MessageBox.Show(info + "\n\n" + e.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        return;
                    }

                    if (success)
                    {
                        string info = "Imported: " + item.Location;

                        InfoMessages.Add(info);
                        Logger.Log.Info(info);
                    }
                }

                ItemProgress = 100;
                TotalProgress++;
            }

            if (state.BatchMode == true)
            {
                App.Current.Dispatcher.BeginInvoke(new Action(() =>
                {
                    MiscUtils.insertIntoHistoryCollection(Settings.Default.FilenameHistory, state.Filename);
                }));
            }
            else if (!oldFilename.Equals(newFilename))
            {
                App.Current.Dispatcher.BeginInvoke(new Action(() =>
                {
                    MiscUtils.insertIntoHistoryCollection(Settings.Default.FilenameHistory, newFilename);
                }));
            }

            if (!oldPath.Equals(newPath))
            {
                App.Current.Dispatcher.BeginInvoke(new Action(() =>
                {
                    MiscUtils.insertIntoHistoryCollection(Settings.Default.MetaDataUpdateDirectoryHistory, newPath);
                }));
            }
        }
Exemple #11
0
        public RootLocation(InfoGatherTask infoGatherTask, MediaFileState mediaFileState) : base(infoGatherTask, mediaFileState)
        {
            LazyLoading = true;

            mediaFileState.NrImportedItemsChanged += mediaFileState_NrImportedItemsChanged;
        }
        public MediaFileStackPanelViewModel(MediaFileState mediaState, IEventAggregator eventAggregator)
        {
            MediaStateCollectionView = new MediaFileStateCollectionView(mediaState);

            initialize(eventAggregator);
        }
Exemple #13
0
        public DriveLocation(DriveInfo info, InfoGatherTask infoGatherTask, MediaFileState mediaFileState)
            : base(infoGatherTask, mediaFileState)
        {
            switch (info.DriveType)
            {
            case DriveType.CDRom:
            {
                ImageUrl    = "pack://application:,,,/Resources/Icons/CD_Drive.ico";
                VolumeLabel = "CD ROM";
                break;
            }

            case DriveType.Fixed:
            {
                ImageUrl = "pack://application:,,,/Resources/Icons/Hard_Drive.ico";

                try
                {
                    VolumeLabel = !String.IsNullOrEmpty(info.VolumeLabel) ? info.VolumeLabel : "Local Disk";
                }
                catch (Exception)
                {
                }

                break;
            }

            case DriveType.Network:
            {
                ImageUrl    = "pack://application:,,,/Resources/Icons/Network_Drive.ico";
                VolumeLabel = "Network Drive";
                break;
            }

            case DriveType.NoRootDirectory:
            {
                break;
            }

            case DriveType.Ram:
            {
                ImageUrl    = "pack://application:,,,/Resources/Icons/ram.ico";
                VolumeLabel = "Ram Drive";
                break;
            }

            case DriveType.Removable:
            {
                ImageUrl    = "pack://application:,,,/Resources/Icons/Removable_Drive.ico";
                VolumeLabel = "Removable Drive";
                break;
            }

            case DriveType.Unknown:
            {
                ImageUrl    = "pack://application:,,,/Resources/Icons/UnknownDrive.ico";
                VolumeLabel = "Unknown Drive";
                break;
            }
            }

            Name = info.Name.TrimEnd(new char[] { '\\' });

            if (driveIdleMonitor.DrivesMonitored.Contains(Name))
            {
                FreeSpaceBytes = info.TotalFreeSpace;
                driveIdleMonitor.DriveInUse += new EventHandler <string>(driveIdleMonitor_driveInUse);
            }
            else
            {
                FreeSpaceBytes = 0;
            }

            infoGatherTask.addLocation(this);

            LazyLoading = true;
        }