/// <summary> /// Adds item to the working items list /// </summary> /// <param name="item"></param> public void AddItemToWorkingList(WorkingItemVm item) { // Return if the item already exists if (WorkingItemsList.ToList().Find(x => x.DisplayName == item.DisplayName) != null) { return; } // Add it to and re-order list (TODO: change this, it's ugly and potentially slow) WorkingItemsList.Add(item); WorkingItemsList = new ObservableImmutableList <WorkingItemVm>(WorkingItemsList.OrderBy(x => x.DisplayName)); }
/// <summary> /// Called when an action is done (unpack or pack) /// </summary> /// <param name="processedItem"></param> public void ProcessQueueUponActionFinalization(WorkingItemVm processedItem) { // Force view to update UpdateListViewOnWorkingItemProcessed(); // Decrement one on concurrent files being processed CcFiles--; // No items to be processed, return if (Queue.Count <= 0) { // Enable user to change profile MainWindowVm.Instance.CanChangeProfile = true; return; } // Get max files at a time var loopTop = Math.Max(ConstantsBase.MaxSimFiles - CcFiles, 0); // Loop through them for (int i = 0; i < loopTop; i++) { WorkingItemVm result; Queue.TryDequeue(out result); switch (result.QueueActionType) { case WorkingItemVm.ActionType.Unpack: if (result.UnpackFileCommand.CanExecute(null)) { result.UnpackFileCommand.Execute(null); } break; case WorkingItemVm.ActionType.Pack: if (result.PackFileCommand.CanExecute(null)) { result.PackFileCommand.Execute(null); } break; } } }
/// <summary> /// /// </summary> /// <param name="data"></param> public void OnFileDropped(object data) { var dataObject = (System.Windows.IDataObject)data; var items = (string[])dataObject.GetData(DataFormats.FileDrop); foreach (var item in items) { if (File.Exists(item)) // File, then unpack it { // File info object var fi = new FileInfo(item); if (fi.Extension != MainWindowVm.Instance.SelectedWorkingProfile.IndexExtension) { UserInput.ShowMessage("DROP_EIX_OR_DIR"); continue; } var workingItem = WorkingItemsList.FirstOrDefault(x => x.Filename == fi.Name); // Create working item if (workingItem == null) { workingItem = new WorkingItemVm(Path.GetFileNameWithoutExtension(fi.Name), fi.Name, fi.FullName, fi.DirectoryName); // Add it to the list AddItemToWorkingList(workingItem); } // Unpack it if (workingItem.UnpackFileCommand.CanExecute(null)) { workingItem.UnpackFileCommand.Execute(null); } } else if (Directory.Exists(item)) // Directory, then pack it { // Dir info var di = new DirectoryInfo(item); var workingItem = WorkingItemsList.FirstOrDefault(x => x.DisplayName == di.Name); // Create working item if (workingItem == null) { workingItem = new WorkingItemVm(di.Name, di.Name + MainWindowVm.Instance.SelectedWorkingProfile.IndexExtension, di.FullName + MainWindowVm.Instance.SelectedWorkingProfile.IndexExtension, di.FullName); // Add it to the list AddItemToWorkingList(workingItem); } // Pack it if (workingItem.PackFileCommand.CanExecute(null)) { workingItem.PackFileCommand.Execute(null); } } } }