using Explorer.Domain; using Explorer.Domain.Abstractions; namespace Explorer.FileOperations; internal static class OperationAvailability { public static bool IsReady(IVolumeService volumes, TransferJob job) { foreach (var path in PathsToCheck(job)) { if (!IsVolumeReachable(volumes, path)) { return false; } } return true; } public static IEnumerable PathsToCheck(TransferJob job) { switch (job.Op) { case TransferOp.Delete: if (job.AdditionalSources.Count > 0) { foreach (var src in job.AdditionalSources) { yield return src; } yield break; } foreach (var src in job.SourcePath.Split('|', StringSplitOptions.RemoveEmptyEntries)) { yield return src; } yield break; case TransferOp.Copy: case TransferOp.Move: case TransferOp.Rename: case TransferOp.Extract: case TransferOp.Compress: case TransferOp.AddToArchive: if (!string.IsNullOrWhiteSpace(job.DestinationPath)) { yield return PathRules.Parent(job.DestinationPath); } yield break; case TransferOp.VerifyArchive: yield return job.SourcePath; yield break; case TransferOp.EmptyRecycleBin: yield break; } } public static bool IsVolumeReachable(IVolumeService volumes, string path) { if (string.IsNullOrWhiteSpace(path)) { return true; } if (volumes.IsPathReachable(path)) { return true; } var root = PathRules.VolumeRoot(path); if (string.IsNullOrWhiteSpace(root)) { return false; } if (!string.Equals(root, path, StringComparison.OrdinalIgnoreCase) && volumes.IsPathReachable(root)) { return true; } var slashed = root.EndsWith('\\') ? root : root + "\\"; return volumes.IsPathReachable(slashed); } }