private static void ExecuteSubTaskCore(OperationListBaseModel Model) { Interlocked.Increment(ref RunningTaskCounter); try { CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => { Model.UpdateStatus(OperationStatus.Preparing); }).AsTask().Wait(); Model.PrepareSizeDataAsync().Wait(); CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => { Model.UpdateStatus(OperationStatus.Processing); Model.UpdateProgress(0); }).AsTask().Wait(); switch (Model) { case OperationListRemoteModel: { using (FullTrustProcessController.ExclusiveUsage Exclusive = FullTrustProcessController.GetAvailableController().Result) { if (!Exclusive.Controller.PasteRemoteFile(Model.ToPath).Result) { CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => { Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_CopyFailUnexpectError_Content")); }).AsTask().Wait(); } } break; } case OperationListCopyModel: { try { CollisionOptions Option = CollisionOptions.None; if (Model.FromPath.All((Item) => Path.GetDirectoryName(Item).Equals(Model.ToPath, StringComparison.OrdinalIgnoreCase))) { Option = CollisionOptions.RenameOnCollision; } else if (Model.FromPath.Select((SourcePath) => Path.Combine(Model.ToPath, Path.GetFileName(SourcePath))) .Any((DestPath) => FileSystemStorageItemBase.CheckExistAsync(DestPath).Result)) { CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => { Model.UpdateStatus(OperationStatus.NeedAttention, Globalization.GetString("NameCollision")); }).AsTask().Wait(); switch (Model.WaitForButtonAction()) { case 0: { Option = CollisionOptions.OverrideOnCollision; break; } case 1: { Option = CollisionOptions.RenameOnCollision; break; } } } if (Model.Status == OperationStatus.Cancelled) { return; } using (FullTrustProcessController.ExclusiveUsage Exclusive = FullTrustProcessController.GetAvailableController().Result) { Exclusive.Controller.CopyAsync(Model.FromPath, Model.ToPath, Option, ProgressHandler: (s, e) => { CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => { Model.UpdateProgress(e.ProgressPercentage); }).AsTask().Wait(); }).Wait(); } } catch (AggregateException Ae) when(Ae.InnerException is FileNotFoundException) { CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => { Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_CopyFailForNotExist_Content")); }).AsTask().Wait(); } catch (AggregateException Ae) when(Ae.InnerException is InvalidOperationException) { CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => { Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_UnauthorizedPaste_Content")); }).AsTask().Wait(); } catch (Exception ex) { LogTracer.Log(ex, "Copy failed for unexpected error"); CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => { Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_CopyFailUnexpectError_Content")); }).AsTask().Wait(); } break; } case OperationListMoveModel: { try { CollisionOptions Option = CollisionOptions.None; if (Model.FromPath.Select((SourcePath) => Path.Combine(Model.ToPath, Path.GetFileName(SourcePath))) .Any((DestPath) => FileSystemStorageItemBase.CheckExistAsync(DestPath).Result)) { CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => { Model.UpdateStatus(OperationStatus.NeedAttention, Globalization.GetString("NameCollision")); }).AsTask().Wait(); switch (Model.WaitForButtonAction()) { case 0: { Option = CollisionOptions.OverrideOnCollision; break; } case 1: { Option = CollisionOptions.RenameOnCollision; break; } } } if (Model.Status == OperationStatus.Cancelled) { return; } using (FullTrustProcessController.ExclusiveUsage Exclusive = FullTrustProcessController.GetAvailableController().Result) { Exclusive.Controller.MoveAsync(Model.FromPath, Model.ToPath, Option, ProgressHandler: (s, e) => { CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => { Model.UpdateProgress(e.ProgressPercentage); }).AsTask().Wait(); }).Wait(); } } catch (AggregateException Ae) when(Ae.InnerException is FileNotFoundException) { CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => { Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_MoveFailForNotExist_Content")); }).AsTask().Wait(); } catch (AggregateException Ae) when(Ae.InnerException is FileCaputureException) { CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => { Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_Item_Captured_Content")); }).AsTask().Wait(); } catch (AggregateException Ae) when(Ae.InnerException is InvalidOperationException) { CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => { Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_UnauthorizedPaste_Content")); }).AsTask().Wait(); } catch (Exception ex) { LogTracer.Log(ex, "Move failed for unexpected error"); CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => { Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_MoveFailUnexpectError_Content")); }).AsTask().Wait(); } break; } case OperationListDeleteModel DeleteModel: { try { using (FullTrustProcessController.ExclusiveUsage Exclusive = FullTrustProcessController.GetAvailableController().Result) { Exclusive.Controller.DeleteAsync(DeleteModel.FromPath, DeleteModel.IsPermanentDelete, (s, e) => { CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => { Model.UpdateProgress(e.ProgressPercentage); }).AsTask().Wait(); }).Wait(); } } catch (AggregateException Ae) when(Ae.InnerException is FileNotFoundException) { CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => { Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_DeleteItemError_Content")); }).AsTask().Wait(); } catch (AggregateException Ae) when(Ae.InnerException is FileCaputureException) { CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => { Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_Item_Captured_Content")); }).AsTask().Wait(); } catch (AggregateException Ae) when(Ae.InnerException is InvalidOperationException) { CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => { Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_UnauthorizedDelete_Content")); }).AsTask().Wait(); } catch (Exception ex) { LogTracer.Log(ex, "Delete failed for unexpected error"); CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => { Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_DeleteFailUnexpectError_Content")); }).AsTask().Wait(); } break; } case OperationListUndoModel UndoModel: { try { using (FullTrustProcessController.ExclusiveUsage Exclusive = FullTrustProcessController.GetAvailableController().Result) { switch (UndoModel.UndoOperationKind) { case OperationKind.Copy: { Exclusive.Controller.DeleteAsync(Model.FromPath, true, (s, e) => { CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => { Model.UpdateProgress(e.ProgressPercentage); }).AsTask().Wait(); }).Wait(); break; } case OperationKind.Move: { Exclusive.Controller.MoveAsync(Model.FromPath, Model.ToPath, IsUndoOperation: true, ProgressHandler: (s, e) => { CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => { Model.UpdateProgress(e.ProgressPercentage); }).AsTask().Wait(); }).Wait(); break; } case OperationKind.Delete: { if (!Exclusive.Controller.RestoreItemInRecycleBinAsync(Model.FromPath).Result) { throw new Exception(); } break; } } } } catch (AggregateException Ae) when(Ae.InnerException is FileNotFoundException) { CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => { Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_UndoFailForNotExist_Content")); }).AsTask().Wait(); } catch (AggregateException Ae) when(Ae.InnerException is FileCaputureException) { CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => { Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_Item_Captured_Content")); }).AsTask().Wait(); } catch (AggregateException Ae) when(Ae.InnerException is InvalidOperationException) { CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => { Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_UnauthorizedUndo_Content")); }).AsTask().Wait(); } catch (Exception ex) { LogTracer.Log(ex, "Undo failed for unexpected error"); CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => { Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_UndoFailure_Content")); }).AsTask().Wait(); } break; } case OperationListCompressionModel CModel: { try { CompressionUtil.SetEncoding(Encoding.Default); switch (CModel.Type) { case CompressionType.Zip: { CompressionUtil.CreateZipAsync(CModel.FromPath, CModel.ToPath, CModel.Level, CModel.Algorithm, (s, e) => { CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => { Model.UpdateProgress(e.ProgressPercentage); }).AsTask().Wait(); }).Wait(); break; } case CompressionType.Tar: { CompressionUtil.CreateTarAsync(CModel.FromPath, CModel.ToPath, CModel.Level, CModel.Algorithm, (s, e) => { CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => { Model.UpdateProgress(e.ProgressPercentage); }).AsTask().Wait(); }).Wait(); break; } case CompressionType.Gzip: { if (CModel.FromPath.Length == 1) { CompressionUtil.CreateGzipAsync(CModel.FromPath.First(), CModel.ToPath, CModel.Level, (s, e) => { CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => { Model.UpdateProgress(e.ProgressPercentage); }).AsTask().Wait(); }).Wait(); } else { throw new ArgumentException("Gzip could not contains more than one item"); } break; } case CompressionType.BZip2: { if (CModel.FromPath.Length == 1) { CompressionUtil.CreateBZip2Async(CModel.FromPath.First(), CModel.ToPath, (s, e) => { CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => { Model.UpdateProgress(e.ProgressPercentage); }).AsTask().Wait(); }).Wait(); } else { throw new ArgumentException("Gzip could not contains more than one item"); } break; } } } catch (AggregateException Ae) when(Ae.InnerException is UnauthorizedAccessException) { CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => { Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_UnauthorizedCompression_Content")); }).AsTask().Wait(); } catch (AggregateException Ae) when(Ae.InnerException is FileNotFoundException) { CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => { Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_LocateFileFailure_Content")); }).AsTask().Wait(); } catch (Exception ex) { LogTracer.Log(ex, "Compression error"); CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => { Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_CompressionError_Content")); }).AsTask().Wait(); } break; } case OperationListDecompressionModel DModel: { try { CompressionUtil.SetEncoding(DModel.Encoding); if (Model.FromPath.All((Item) => Item.EndsWith(".zip", StringComparison.OrdinalIgnoreCase) || Item.EndsWith(".tar", StringComparison.OrdinalIgnoreCase) || Item.EndsWith(".tar.gz", StringComparison.OrdinalIgnoreCase) || Item.EndsWith(".tgz", StringComparison.OrdinalIgnoreCase) || Item.EndsWith(".tar.bz2", StringComparison.OrdinalIgnoreCase) || Item.EndsWith(".bz2", StringComparison.OrdinalIgnoreCase) || Item.EndsWith(".gz", StringComparison.OrdinalIgnoreCase) || Item.EndsWith(".rar", StringComparison.OrdinalIgnoreCase))) { CompressionUtil.ExtractAllAsync(Model.FromPath, Model.ToPath, DModel.ShouldCreateFolder, (s, e) => { CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => { Model.UpdateProgress(e.ProgressPercentage); }).AsTask().Wait(); }).Wait(); } else { throw new Exception(Globalization.GetString("QueueDialog_FileTypeIncorrect_Content")); } } catch (AggregateException Ae) when(Ae.InnerException is UnauthorizedAccessException) { CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => { Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_UnauthorizedDecompression_Content")); }).AsTask().Wait(); } catch (AggregateException Ae) when(Ae.InnerException is FileNotFoundException) { CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => { Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_LocateFileFailure_Content")); }).AsTask().Wait(); } catch (Exception ex) { LogTracer.Log(ex, "Decompression error"); CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => { Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_DecompressionError_Content")); }).AsTask().Wait(); } break; } } CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => { if (Model.Status != OperationStatus.Error) { Model.UpdateProgress(100); Model.UpdateStatus(OperationStatus.Completed); } }).AsTask().Wait(); } catch (Exception ex) { LogTracer.Log(ex, "A subthread in Task List threw an exception"); } finally { Interlocked.Decrement(ref RunningTaskCounter); } }
public static async IAsyncEnumerable <string[]> GetAllPathAsync(StartupMode Mode) { if (Mode == StartupMode.CreateNewTab) { yield break; } switch (Mode) { case StartupMode.CreateNewTab: { yield break; } case StartupMode.SpecificTab: { if (ApplicationData.Current.LocalSettings.Values["StartupWithSpecificPath"] is string RawData) { if (string.IsNullOrWhiteSpace(RawData)) { yield break; } foreach (string Path in JsonSerializer.Deserialize <List <string> >(RawData)) { if (await FileSystemStorageItemBase.CheckExistAsync(Path).ConfigureAwait(false)) { yield return(new string[] { Path }); } } } else { yield break; } break; } case StartupMode.LastOpenedTab: { if (ApplicationData.Current.LocalSettings.Values["StartupWithLastOpenedPath"] is string RawData) { if (string.IsNullOrWhiteSpace(RawData)) { yield break; } foreach (string[] PathList in JsonSerializer.Deserialize <List <string[]> >(RawData)) { List <string> ValidPathList = new List <string>(PathList.Length); foreach (string ValidPath in PathList) { if (await FileSystemStorageItemBase.CheckExistAsync(ValidPath).ConfigureAwait(false)) { ValidPathList.Add(ValidPath); } } yield return(ValidPathList.ToArray()); } } else { yield break; } break; } } }