private async Task SetColorInPalette(Func <Point, int> indexFunc, Point controlPoint) { if (!SelectedImage.IsIndexed) { return; } var index = indexFunc(controlPoint); if (index < 0 || index >= SelectedImage.GetPalette(_progressContext).Count) { return; } if (clrDialog.ShowDialog() != DialogResult.OK) { return; } DisablePaletteControls(); DisableImageControls(); try { await Task.Run(() => { SelectedImage.SetColorInPalette(index, clrDialog.Color); _progressContext.ReportProgress("Done", 1, 1); }); } catch (Exception ex) { _formCommunicator.ReportStatus(false, ex.Message); UpdateFormInternal(); return; } UpdateFormInternal(); UpdatePreview(); UpdateImageList(); }
private async Task ExtractFiles(IList <IArchiveFileInfo> files) { if (files.Count <= 0) { _communicator.ReportStatus(true, "No files to extract."); return; } // Select folder var extractPath = SelectFolder(); if (extractPath.IsNull || extractPath.IsEmpty) { _communicator.ReportStatus(false, "No folder selected."); return; } // Extract elements _communicator.ReportStatus(true, string.Empty); var destinationFileSystem = FileSystemFactory.CreatePhysicalFileSystem(extractPath, _stateInfo.StreamManager); _progress.StartProgress(); await _asyncOperation.StartAsync(async cts => { var count = 0; foreach (var file in files) { if (cts.IsCancellationRequested) { break; } _progress.ReportProgress("Extract files", count++, files.Count); if (IsFileLocked(file, false)) { continue; } Stream newFileStream; try { newFileStream = destinationFileSystem.OpenFile(file.FilePath.GetName(), FileMode.Create, FileAccess.Write); } catch (IOException) { continue; } var currentFileStream = await file.GetFileData(); currentFileStream.CopyTo(newFileStream); newFileStream.Close(); } }); _progress.ReportProgress("Extract files", 1, 1); _progress.FinishProgress(); if (_asyncOperation.WasCancelled) { _communicator.ReportStatus(false, "File extraction cancelled."); } else { _communicator.ReportStatus(true, "File(s) extracted successfully."); } }