public async Task generatePreviews() { await Task.Factory.StartNew(() => { try { TotalProgressMax = asyncState.Media.Count; for (TotalProgress = 0; TotalProgress < TotalProgressMax; TotalProgress++) { MediaFileItem item = asyncState.Media.ElementAt(TotalProgress); if (CancellationToken.IsCancellationRequested) { return; } if (!MediaFormatConvert.isVideoFile(item.Location)) { InfoMessages.Add("Skipping: " + item.Location + " is not a video file."); continue; } if (item.Metadata == null) { item.EnterUpgradeableReadLock(); try { item.readMetadata_URLock(MetadataFactory.ReadOptions.AUTO, CancellationToken); if (item.ItemState != MediaItemState.LOADED) { InfoMessages.Add("Skipping: " + item.Location + " could not read metadata."); continue; } } finally { item.ExitUpgradeableReadLock(); } } generatePreview(item); } } finally { App.Current.Dispatcher.Invoke(() => { OkCommand.IsExecutable = true; CancelCommand.IsExecutable = false; }); } }); }
private void requestNavigateEvent(object sender, RoutedEventArgs e) { RequestNavigateEventArgs args = e as RequestNavigateEventArgs; Uri uri = args.Uri; if (uri.IsFile) { String location = null; location = HttpUtility.UrlDecode(uri.AbsolutePath); if (MediaFormatConvert.isVideoFile(location)) { NameValueCollection values = HttpUtility.ParseQueryString(uri.Query); String[] formats = { @"h'h'm'm's's'", @"m'm's's'", @"s's'" }; String timeOffsetString = values["t"]; TimeSpan time = new TimeSpan(); if (timeOffsetString != null) { try { bool success = TimeSpan.TryParseExact(timeOffsetString, formats, null, out time); } catch (Exception ex) { Logger.Log.Error("Error parsing timestring: " + timeOffsetString + " for " + location, ex); } } MediaItem item = MediaItemFactory.create(location); Shell.ShellViewModel.navigateToVideoView(item, (int)time.TotalSeconds); } e.Handled = true; } }
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); }
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); }
public void OnImportsSatisfied() { ShellViewModel = new ShellViewModel(MediaFileWatcher.Instance, RegionManager, EventAggregator); DataContext = ShellViewModel; this.RegionManager.RegisterViewWithRegion(RegionNames.MainNavigationToolBarRegion, typeof(ImageNavigationItemView)); this.RegionManager.RegisterViewWithRegion(RegionNames.MainNavigationToolBarRegion, typeof(VideoNavigationItemView)); this.RegionManager.RegisterViewWithRegion(RegionNames.MainNavigationToolBarRegion, typeof(MediaFileBrowserNavigationItemView)); this.RegionManager.RegisterViewWithRegion(RegionNames.MainNavigationToolBarRegion, typeof(SettingsNavigationItemView)); EventAggregator.GetEvent <TitleChangedEvent>().Subscribe((title) => { if (!String.IsNullOrEmpty(title)) { this.Title = "MediaViewer - " + title; } else { this.Title = "MediaViewer"; } }, ThreadOption.UIThread); EventAggregator.GetEvent <ToggleFullScreenEvent>().Subscribe((isFullscreen) => { if (isFullscreen) { prevWindowState = WindowState; WindowState = System.Windows.WindowState.Maximized; WindowStyle = System.Windows.WindowStyle.None; toolBarPanel.Visibility = Visibility.Collapsed; } else { WindowState = prevWindowState; WindowStyle = System.Windows.WindowStyle.SingleBorderWindow; toolBarPanel.Visibility = Visibility.Visible; } }, ThreadOption.UIThread); // initialize several settings ServiceLocator.Current.GetInstance(typeof(DbSettingsViewModel)); ServiceLocator.Current.GetInstance(typeof(AboutViewModel)); try { String location = App.Args.Count() > 0 ? FileUtils.getProperFilePathCapitalization(App.Args[0]) : ""; if (MediaViewer.Model.Utils.MediaFormatConvert.isImageFile(location)) { MediaFileWatcher.Instance.Path = FileUtils.getPathWithoutFileName(location); MediaItem item = MediaItemFactory.create(location); ShellViewModel.navigateToImageView(item); } else if (MediaFormatConvert.isVideoFile(location)) { MediaFileWatcher.Instance.Path = FileUtils.getPathWithoutFileName(location); MediaItem item = MediaItemFactory.create(location); ShellViewModel.navigateToVideoView(item); } else { ShellViewModel.navigateToMediaFileBrowser(); } } catch (Exception e) { Logger.Log.Error("Error in command line argument: " + App.Args[0], e); ShellViewModel.navigateToMediaFileBrowser(); } }