/// <summary> /// Perform GTK-specific initialization. /// </summary> partial void OSInitialize() { ////_sortColumn = RomListColumn.None; ////_sortDirection = ListSortDirection.Ascending; var configuration = SingleInstanceApplication.Instance.GetConfiguration <RomListConfiguration>(); var romListFilePath = configuration.RomFilesPath; _filePath = romListFilePath; Model = LoadRomList(romListFilePath); Model.SaveFailed += HandleSaveFailed; ((INotifyPropertyChanged)Model).PropertyChanged += HandleProgramCollectionPropertyChanged; _searchDirectories = Properties.Settings.Default.RomListSearchDirectories; if (_searchDirectories == null) { _searchDirectories = new SearchDirectories(); Properties.Settings.Default.RomListSearchDirectories = _searchDirectories; } if (Properties.Settings.Default.RomListSearchForRomsAtStartup && CanRefreshRoms(null)) { var options = RomDiscoveryOptions.AddNewRoms; if (Properties.Settings.Default.RomListValidateAtStartup) { options |= RomDiscoveryOptions.DetectChanges | RomDiscoveryOptions.DetectMissingRoms | RomDiscoveryOptions.DetectNewRoms; } var taskData = new RomDiscoveryData(Properties.Settings.Default.RomListSearchDirectories, _programs.ModelCollection, -1, Resources.Strings.RomListViewModel_ScanningForRoms_Title, options); SingleInstanceApplication.Instance.AddStartupAction("ScanForRoms", () => RefreshRoms(taskData), StartupTaskPriority.HighestAsyncTaskPriority); } // TODO: Initialize sorting! // TODO: Drag/Drop? }
private void FilesDropped(object dropEventArgs) { List <string> files = new List <string>(); var insertLocation = GetFilesDropped(dropEventArgs, files); if (files.Any()) { var options = RomDiscoveryOptions.AddNewRoms | RomDiscoveryOptions.AccumulateRejectedRoms; var args = new RomDiscoveryData(files, Programs.ModelCollection, insertLocation, Resources.Strings.RomListViewModel_Progress_Title, options) { SelectNewRoms = true }; AddPrograms(args); bool updatedSearchDirectories = false; foreach (var file in files) { if (System.IO.Directory.Exists(file)) { updatedSearchDirectories |= _searchDirectories.Add(file); } } if (updatedSearchDirectories) { INTV.Shared.ComponentModel.CommandManager.InvalidateRequerySuggested(); } } }
private void FilesDropped(object dragEventArgs) { var dragDropArgs = dragEventArgs as DragEventArgs; var data = dragDropArgs.Data as IDataObject; var dataFormats = data.GetFormats(true); if (data.GetDataPresent(DataFormats.FileDrop)) { var files = data.GetData(DataFormats.FileDrop) as IEnumerable <string>; var options = RomDiscoveryOptions.AddNewRoms | RomDiscoveryOptions.AccumulateRejectedRoms; var args = new RomDiscoveryData(files, Programs.ModelCollection, -1, Resources.Strings.RomListViewModel_Progress_Title, options); AddPrograms(args); bool updatedSearchDirectories = false; foreach (var file in files) { if (System.IO.Directory.Exists(file)) { updatedSearchDirectories |= _searchDirectories.Add(file); } } if (updatedSearchDirectories) { CommandManager.InvalidateRequerySuggested(); } } }
/// <summary> /// Add ROMs to the ROM list given a list of files or directories. /// </summary> /// <param name="fileNames">An enumerable of absolute paths to files or directories.</param> /// <param name="insertLocation">Location to insert new ROMs. A value of <c>-1</c> indicates to append to the end.</param> /// <param name="addingStarterRoms">If set to <c>true</c>, the method is invoked to add "starter ROMs".</param> internal void AddRoms(IEnumerable <string> fileNames, int insertLocation, bool addingStarterRoms) { var options = RomDiscoveryOptions.AddNewRoms | RomDiscoveryOptions.AccumulateRejectedRoms; var taskData = new RomDiscoveryData(fileNames, Programs.ModelCollection, insertLocation, Resources.Strings.RomListViewModel_Progress_Title, options) { AddingStarterRoms = addingStarterRoms }; AddPrograms(taskData); }
/// <summary> /// Refresh the ROM list by visiting the directories saved in preferences. /// </summary> /// <param name="parameter">If this value is a valid <see cref="RomDiscoveryData"/>, it defines /// customized behavior for searching for ROMs.</param> internal void RefreshRoms(object parameter) { var taskData = parameter as RomDiscoveryData; if (taskData == null) { var options = RomDiscoveryOptions.AddNewRoms | RomDiscoveryOptions.DetectNewRoms | RomDiscoveryOptions.DetectChanges | RomDiscoveryOptions.DetectMissingRoms; taskData = new RomDiscoveryData(Properties.Settings.Default.RomListSearchDirectories, _programs.ModelCollection, -1, Resources.Strings.RomListViewModel_ScanningForRoms_Title, options); } AddPrograms(taskData); }
/// <summary> /// WPF-specific implementation. /// </summary> partial void OSInitialize() { _sortColumn = RomListColumn.None; _sortDirection = ListSortDirection.Ascending; // This null check keeps the WPF XAML designer output clean. if (INTV.Shared.Utility.SingleInstanceApplication.Instance != null) { var configuration = SingleInstanceApplication.Instance.GetConfiguration <RomListConfiguration>(); var romListFilePath = configuration.RomFilesPath; _filePath = romListFilePath; Model = LoadRomList(romListFilePath); Model.SaveFailed += HandleSaveFailed; ((INotifyPropertyChanged)Model).PropertyChanged += HandleProgramCollectionPropertyChanged; Sort(Properties.Settings.Default.SortDirection, Properties.Settings.Default.SortColumn); _nameColumnWidth = Properties.Settings.Default.RomListNameColWidth; _vendorColumnWidth = Properties.Settings.Default.RomListVendorColWidth; _yearColumnWidth = Properties.Settings.Default.RomListYearColWidth; _featuresColumnWidth = Properties.Settings.Default.RomListFeaturesColWidth; _romPathColumnWidth = Properties.Settings.Default.RomListPathColWidth; _searchDirectories = Properties.Settings.Default.RomListSearchDirectories; if (_searchDirectories == null) { _searchDirectories = new SearchDirectories(); Properties.Settings.Default.RomListSearchDirectories = _searchDirectories; } _dragProgramsStartCommand = new StartDragProgramsCommand(ExecuteStartSelectedProgramsDrag); if (Properties.Settings.Default.RomListSearchForRomsAtStartup && CanRefreshRoms(null)) { var options = RomDiscoveryOptions.AddNewRoms; if (Properties.Settings.Default.RomListValidateAtStartup) { options |= RomDiscoveryOptions.DetectChanges | RomDiscoveryOptions.DetectMissingRoms | RomDiscoveryOptions.DetectNewRoms; } var taskData = new RomDiscoveryData(Properties.Settings.Default.RomListSearchDirectories, _programs.ModelCollection, -1, Resources.Strings.RomListViewModel_ScanningForRoms_Title, options); SingleInstanceApplication.Instance.AddStartupAction("ScanForRoms", () => RefreshRoms(taskData), StartupTaskPriority.HighestAsyncTaskPriority); } } else { Model = INTV.Shared.Model.Program.ProgramCollection.EmptyDummyList; _nameColumnWidth = Properties.Settings.Default.RomListNameColWidth; _vendorColumnWidth = Properties.Settings.Default.RomListVendorColWidth; _yearColumnWidth = Properties.Settings.Default.RomListYearColWidth; _featuresColumnWidth = Properties.Settings.Default.RomListFeaturesColWidth; _romPathColumnWidth = Properties.Settings.Default.RomListPathColWidth; } }
private void AddPrograms(RomDiscoveryData taskData) { var cancel = Model.BeginAddRomsFromFiles(taskData.AddingStarterRoms); if (!cancel) { var gatherRomsTask = new AsyncTaskWithProgress(taskData.Title, true, true); gatherRomsTask.RunTask(taskData, GatherRoms, GatherRomsComplete); // EndAddRomsFromFiles is called in GatherRomsComplete(). } else { Model.EndAddRomsFromFiles(Enumerable.Empty <string>()); } }