Example #1
0
        private bool getMediaFiles(System.IO.FileInfo info, object state)
        {
            if (CancellationToken.IsCancellationRequested)
            {
                return(false);
            }

            ScanLocation location = (state as Tuple <ScanLocation, ObservableCollection <ScanLocation>, List <String> >).Item1;
            ObservableCollection <ScanLocation> excludeLocations = (state as Tuple <ScanLocation, ObservableCollection <ScanLocation>, List <String> >).Item2;
            List <String> items = (state as Tuple <ScanLocation, ObservableCollection <ScanLocation>, List <String> >).Item3;

            String addItem = null;

            switch (location.MediaType)
            {
            case Search.MediaType.All:
            {
                if (MediaViewer.Model.Utils.MediaFormatConvert.isMediaFile(info.Name))
                {
                    addItem = info.FullName;
                }
                break;
            }

            case Search.MediaType.Images:
            {
                if (MediaFormatConvert.isImageFile(info.Name))
                {
                    addItem = info.FullName;
                }
                break;
            }

            case Search.MediaType.Video:
            {
                if (MediaFormatConvert.isVideoFile(info.Name))
                {
                    addItem = info.FullName;
                }
                break;
            }
            }

            if (addItem != null)
            {
                String path = FileUtils.getPathWithoutFileName(addItem);

                bool excluded = false;

                foreach (ScanLocation excludeLocation in excludeLocations)
                {
                    if (excludeLocation.IsRecursive)
                    {
                        if (path.StartsWith(excludeLocation.Location))
                        {
                            if (excludeLocation.MediaType == Search.MediaType.All ||
                                (excludeLocation.MediaType == Search.MediaType.Images && MediaFormatConvert.isImageFile(addItem)) ||
                                (excludeLocation.MediaType == Search.MediaType.Video && MediaFormatConvert.isVideoFile(addItem)))
                            {
                                excluded = true;
                                break;
                            }
                        }
                    }
                    else
                    {
                        if (path.Equals(excludeLocation.Location))
                        {
                            if (excludeLocation.MediaType == Search.MediaType.All ||
                                (excludeLocation.MediaType == Search.MediaType.Images && MediaFormatConvert.isImageFile(addItem)) ||
                                (excludeLocation.MediaType == Search.MediaType.Video && MediaFormatConvert.isVideoFile(addItem)))
                            {
                                excluded = true;
                                break;
                            }
                        }
                    }
                }

                if (!items.Contains(addItem) && !excluded)
                {
                    items.Add(addItem);
                }
            }

            return(true);
        }
Example #2
0
        public ExportViewModel(MediaFileWatcher mediaFileWatcher)
        {
            Title = "Export Media";

            OkCommand = new Command(async() =>
            {
                CancellableOperationProgressView progress = new CancellableOperationProgressView();
                ExportProgressViewModel vm = new ExportProgressViewModel(mediaFileWatcher.MediaFileState);
                progress.DataContext       = vm;
                progress.Show();
                Task t = vm.exportAsync(IncludeLocations, ExcludeLocations);
                OnClosingRequest();
                await t;
            });

            CancelCommand = new Command(() =>
            {
                OnClosingRequest();
            });

            IncludeLocations = new ObservableCollection <ScanLocation>();

            IncludeLocations.Add(new ScanLocation(mediaFileWatcher.Path));

            AddIncludeLocationCommand = new Command(new Action(() =>
            {
                DirectoryPickerView directoryPicker = new DirectoryPickerView();
                DirectoryPickerViewModel vm         = (DirectoryPickerViewModel)directoryPicker.DataContext;

                if (SelectedIncludeLocation == null)
                {
                    vm.SelectedPath = mediaFileWatcher.Path;
                }
                else
                {
                    vm.SelectedPath = SelectedIncludeLocation.Location;
                }

                if (directoryPicker.ShowDialog() == true)
                {
                    ScanLocation newLocation = new ScanLocation(vm.SelectedPath);
                    if (!IncludeLocations.Contains(newLocation))
                    {
                        IncludeLocations.Add(newLocation);
                    }
                }

                if (IncludeLocations.Count > 0)
                {
                    OkCommand.IsExecutable = true;
                }
            }));

            RemoveIncludeLocationCommand = new Command(new Action(() =>
            {
                for (int i = IncludeLocations.Count() - 1; i >= 0; i--)
                {
                    if (IncludeLocations[i].IsSelected == true)
                    {
                        IncludeLocations.RemoveAt(i);
                    }
                }

                if (IncludeLocations.Count == 0)
                {
                    OkCommand.IsExecutable = false;
                }
            }));

            ClearIncludeLocationsCommand = new Command(new Action(() =>
            {
                IncludeLocations.Clear();
                OkCommand.IsExecutable = false;
            }));

            ExcludeLocations = new ObservableCollection <ScanLocation>();

            AddExcludeLocationCommand = new Command(new Action(() =>
            {
                DirectoryPickerView directoryPicker = new DirectoryPickerView();
                DirectoryPickerViewModel vm         = (DirectoryPickerViewModel)directoryPicker.DataContext;

                if (SelectedExcludeLocation == null)
                {
                    vm.SelectedPath = mediaFileWatcher.Path;
                }
                else
                {
                    vm.SelectedPath = SelectedExcludeLocation.Location;
                }

                if (directoryPicker.ShowDialog() == true)
                {
                    ScanLocation newLocation = new ScanLocation(vm.SelectedPath);
                    if (!ExcludeLocations.Contains(newLocation))
                    {
                        ExcludeLocations.Add(newLocation);
                    }
                }
            }));

            RemoveExcludeLocationCommand = new Command(new Action(() =>
            {
                for (int i = ExcludeLocations.Count() - 1; i >= 0; i--)
                {
                    if (ExcludeLocations[i].IsSelected == true)
                    {
                        ExcludeLocations.RemoveAt(i);
                    }
                }
            }));

            ClearExcludeLocationsCommand = new Command(new Action(() =>
            {
                ExcludeLocations.Clear();
            }));
        }
Example #3
0
        private bool iterateFiles(System.IO.DirectoryInfo location, object state)
        {
            if (CancellationToken.IsCancellationRequested)
            {
                return(false);
            }

            Tuple <ScanLocation, ObservableCollection <ScanLocation> > locationArgs = state as Tuple <ScanLocation, ObservableCollection <ScanLocation> >;

            ScanLocation scanLocation = locationArgs.Item1;
            ObservableCollection <ScanLocation> excludeLocations = locationArgs.Item2;

            FileInfo[] files = null;

            try
            {
                files = location.GetFiles("*.*");
            }
            catch (UnauthorizedAccessException e)
            {
                Logger.Log.Warn(e.Message);
            }
            catch (DirectoryNotFoundException e)
            {
                Logger.Log.Warn(e.Message);
            }

            List <BaseMetadata> staleItems = new List <BaseMetadata>();

            using (MetadataDbCommands metadataCommands = new MetadataDbCommands())
            {
                staleItems = metadataCommands.getAllMetadataInDirectory(location.FullName);
            }

            foreach (FileInfo info in files)
            {
                if (CancellationToken.IsCancellationRequested)
                {
                    return(false);
                }

                if (MediaViewer.Model.Utils.MediaFormatConvert.isMediaFile(info.Name))
                {
                    staleItems.RemoveAll(x => x.Name.Equals(info.Name));
                }

                String addItem = null;

                switch (scanLocation.MediaType)
                {
                case Search.MediaType.All:
                {
                    if (MediaViewer.Model.Utils.MediaFormatConvert.isMediaFile(info.Name))
                    {
                        addItem = info.FullName;
                    }
                    break;
                }

                case Search.MediaType.Images:
                {
                    if (MediaFormatConvert.isImageFile(info.Name))
                    {
                        addItem = info.FullName;
                    }
                    break;
                }

                case Search.MediaType.Video:
                {
                    if (MediaFormatConvert.isVideoFile(info.Name))
                    {
                        addItem = info.FullName;
                    }
                    break;
                }

                case Search.MediaType.Audio:
                {
                    if (MediaFormatConvert.isAudioFile(info.Name))
                    {
                        addItem = info.FullName;
                    }
                    break;
                }
                }

                if (addItem != null)
                {
                    String path = FileUtils.getPathWithoutFileName(addItem);

                    bool excluded = false;

                    foreach (ScanLocation excludeLocation in excludeLocations)
                    {
                        if (excludeLocation.IsRecursive)
                        {
                            if (path.StartsWith(excludeLocation.Location))
                            {
                                if (excludeLocation.MediaType == Search.MediaType.All ||
                                    (excludeLocation.MediaType == Search.MediaType.Images && MediaFormatConvert.isImageFile(addItem)) ||
                                    (excludeLocation.MediaType == Search.MediaType.Video && MediaFormatConvert.isVideoFile(addItem)))
                                {
                                    excluded = true;
                                    break;
                                }
                            }
                        }
                        else
                        {
                            if (path.Equals(excludeLocation.Location))
                            {
                                if (excludeLocation.MediaType == Search.MediaType.All ||
                                    (excludeLocation.MediaType == Search.MediaType.Images && MediaFormatConvert.isImageFile(addItem)) ||
                                    (excludeLocation.MediaType == Search.MediaType.Video && MediaFormatConvert.isVideoFile(addItem)))
                                {
                                    excluded = true;
                                    break;
                                }
                            }
                        }
                    }

                    if (!excluded)
                    {
                        importItem(info);
                    }
                }
            }

            if (staleItems.Count > 0)
            {
                using (MetadataDbCommands metadataCommands = new MetadataDbCommands())
                {
                    foreach (BaseMetadata staleItem in staleItems)
                    {
                        metadataCommands.delete(staleItem);
                    }
                }

                Logger.Log.Info("Removed " + staleItems.Count + " stale media items from " + location.FullName);
                InfoMessages.Add("Removed " + staleItems.Count + " stale media items from " + location.FullName);
            }

            return(true);
        }