diff --git a/clio/Command/CompressAppCommand.cs b/clio/Command/CompressAppCommand.cs index 195d9088..6814fa29 100644 --- a/clio/Command/CompressAppCommand.cs +++ b/clio/Command/CompressAppCommand.cs @@ -32,15 +32,18 @@ internal class CompressAppCommand : Command private IJsonConverter _jsonConverter; private readonly IPackageArchiver _packageArchiver; + private readonly IPackageUtilities _packageUtilities; - public CompressAppCommand(IJsonConverter jsonConverter, IPackageArchiver packageArchiver) { + public CompressAppCommand(IJsonConverter jsonConverter, IPackageArchiver packageArchiver, + IPackageUtilities packageUtilities) { _jsonConverter = jsonConverter; _packageArchiver = packageArchiver; + _packageUtilities = packageUtilities; } public override int Execute(CompressAppOptions options) { FolderPackageRepository folderPackageRepository = - new FolderPackageRepository(options.RepositoryFolderPath, _jsonConverter); + new FolderPackageRepository(options.RepositoryFolderPath, _jsonConverter, _packageUtilities); var appPackageNames = folderPackageRepository.GetRelatedPackagesNames(options.RootPackageNames); string destinationPath = options.DestinationPath; if (!Directory.Exists(destinationPath)) { @@ -60,10 +63,13 @@ internal class FolderPackageRepository { private readonly string _repositoryFolderPath; private readonly IJsonConverter _jsonConverter; + private readonly IPackageUtilities _packageUtilities; - public FolderPackageRepository(string repositoryFolderPath, IJsonConverter jsonConverter) { + public FolderPackageRepository(string repositoryFolderPath, IJsonConverter jsonConverter, + IPackageUtilities packageUtilities) { _jsonConverter = jsonConverter; _repositoryFolderPath = repositoryFolderPath; + _packageUtilities = packageUtilities; } @@ -93,7 +99,7 @@ private Stack GetStackPackageDescriptors(IEnumerable } public string GetPackageContentFolderPath(string packageName) { - return PackageUtilities.GetPackageContentFolderPath(_repositoryFolderPath, packageName); + return _packageUtilities.GetPackageContentFolderPath(_repositoryFolderPath, packageName); } private PackageDescriptor GetPackageDescriptor(string packageName) { diff --git a/clio/Command/RfsEnvironment.cs b/clio/Command/RfsEnvironment.cs index 2b47d8bf..fa4ccfe0 100644 --- a/clio/Command/RfsEnvironment.cs +++ b/clio/Command/RfsEnvironment.cs @@ -37,7 +37,8 @@ internal static void Link2Repo(string environmentPackagePath, string repositoryP Console.WriteLine($"Package '{environmentPackageName}' found in repository."); environmentPackageFolder.Delete(true); string repositoryPackageFolderPath = repositoryPackageFolder.FullName; - string packageContentFolderPath = PackageUtilities.GetPackageContentFolderPath(repositoryPackageFolderPath); + var packageUtilities = new PackageUtilities(new FileSystem(new System.IO.Abstractions.FileSystem())); + string packageContentFolderPath = packageUtilities.GetPackageContentFolderPath(repositoryPackageFolderPath); FileSystem.CreateLink(packageContentFolderPath, repositoryPackageFolderPath); } else { Console.WriteLine($"Package '{environmentPackageName}' not found in repository."); @@ -78,8 +79,9 @@ internal static void Link4Repo(string environmentPackagePath, string repositoryP environmentPackageDirectoryPath = Path.Combine(environmentPackagePath, packageName); } var repositoryPackageFolder = repositoryPackageFolders.FirstOrDefault(s => s.Name == packageName); + var packageUtilities = new PackageUtilities(new FileSystem(new System.IO.Abstractions.FileSystem())); string repositoryPackageContentFolderPath = - PackageUtilities.GetPackageContentFolderPath(repositoryPackageFolder.FullName); + packageUtilities.GetPackageContentFolderPath(repositoryPackageFolder.FullName); FileSystem.CreateLink(environmentPackageDirectoryPath, repositoryPackageContentFolderPath); } diff --git a/clio/Common/FileSystem.cs b/clio/Common/FileSystem.cs index 68b0aa89..66c346ba 100644 --- a/clio/Common/FileSystem.cs +++ b/clio/Common/FileSystem.cs @@ -18,6 +18,9 @@ public class FileSystem : IFileSystem public FileSystem(Ms.IFileSystem msFileSystem){ _msFileSystem = msFileSystem; } + + #region Methods: Public + public byte[] ReadAllBytes(string filePath) => _msFileSystem.File.ReadAllBytes(filePath); public Ms.FileSystemStream CreateFile(string filePath){ @@ -27,8 +30,6 @@ public Ms.FileSystemStream CreateFile(string filePath){ public Ms.FileSystemStream FileOpenStream(string filePath, FileMode mode, FileAccess access, FileShare share) => _msFileSystem.File.Open(filePath, mode, access, share); - #region Methods: Public - public static void CreateLink(string link, string target) { Process mklinkProcess = Process.Start( new ProcessStartInfo("cmd", $"/c mklink /D \"{link}\" \"{target}\"") { diff --git a/clio/ComposableApplication/ComposableApplicationManager.cs b/clio/ComposableApplication/ComposableApplicationManager.cs index 51f7c7a8..a010f4d8 100644 --- a/clio/ComposableApplication/ComposableApplicationManager.cs +++ b/clio/ComposableApplication/ComposableApplicationManager.cs @@ -1,4 +1,5 @@ using System; +using System.Collections; using System.IO; using System.IO.Abstractions; using System.Json; @@ -99,10 +100,17 @@ public void SetIcon(string appPath, string iconPath, string appName) { bool isArchive = _fileSystem.File.Exists(appPath); string unzipAppPath = string.Empty; if (isArchive) { - unzipAppPath = _directoriesProvider.CreateTempDirectory(); - _archiver.ExtractPackages(appPath, true, true, true, false, unzipAppPath); - ChangeIcon(unzipAppPath, iconPath, appName); - _archiver.ZipPackages(unzipAppPath, appPath, true); + _directoriesProvider.CreateTempDirectory(unzipAppPath => { + _archiver.ExtractPackages(appPath, true, true, true, false, unzipAppPath); + ChangeIcon(unzipAppPath, iconPath, appName); + string[] packageFolders = _fileSystem.Directory.GetDirectories(unzipAppPath); + _directoriesProvider.CreateTempDirectory(gzPkgFolder => { + foreach (var packagePath in packageFolders) { + _archiver.Pack(packagePath, Path.Combine(gzPkgFolder, $"{Path.GetFileName(packagePath)}.gz"), false); + } + _archiver.ZipPackages(gzPkgFolder, appPath, true); + }); + }); return; } ChangeIcon(appPath, iconPath, appName); diff --git a/clio/Package/IPackageUtilities.cs b/clio/Package/IPackageUtilities.cs index 6f64c4ca..dbf627d4 100644 --- a/clio/Package/IPackageUtilities.cs +++ b/clio/Package/IPackageUtilities.cs @@ -11,6 +11,8 @@ public interface IPackageUtilities #region Methods: Public void CopyPackageElements(string sourcePath, string destinationPath, bool overwrite); + string GetPackageContentFolderPath(string repositoryPackageFolderPath); + string GetPackageContentFolderPath(string repositoryFolderPath, string packageName); #endregion diff --git a/clio/Package/PackageArchiver.cs b/clio/Package/PackageArchiver.cs index fbfe1c6a..9e9d9570 100644 --- a/clio/Package/PackageArchiver.cs +++ b/clio/Package/PackageArchiver.cs @@ -134,10 +134,6 @@ private void DeletePackedPackages(string[] packedPackagesPaths) { } private string[] ExtractPackedPackages(string zipFilePath, string targetDirectoryPath) { - // var zipBytes = _msFileSystem.File.ReadAllBytes(zipFilePath); - // MemoryStream stream = new MemoryStream(zipBytes); - // ZipArchive zipArchive = new ZipArchive(stream, ZipArchiveMode.Read); - // zipArchive.ExtractToDirectory(targetDirectoryPath, true); _zipFile.ExtractToDirectory(zipFilePath, targetDirectoryPath); string[] packedPackagesPaths = _msFileSystem.Directory.GetFiles(targetDirectoryPath, "*.gz"); return packedPackagesPaths; diff --git a/clio/Package/PackageUtilities.cs b/clio/Package/PackageUtilities.cs index 2e38dde4..bff9624c 100644 --- a/clio/Package/PackageUtilities.cs +++ b/clio/Package/PackageUtilities.cs @@ -39,7 +39,7 @@ public PackageUtilities(IFileSystem fileSystem) { private void CopyPackageElement(string sourcePath, string destinationPath, string name) { string fromAssembliesPath = Path.Combine(sourcePath, name); - if (Directory.Exists(fromAssembliesPath)) { + if (_fileSystem.ExistsDirectory(fromAssembliesPath)) { string toAssembliesPath = Path.Combine(destinationPath, name); _fileSystem.CopyDirectory(fromAssembliesPath, toAssembliesPath, true); } @@ -57,13 +57,13 @@ public void CopyPackageElements(string sourcePath, string destinationPath, bool foreach (string packageElementName in PackageElementNames) { CopyPackageElement(packageContentPath, destinationPath, packageElementName); } - File.Copy(Path.Combine(packageContentPath, "descriptor.json"), - Path.Combine(destinationPath, "descriptor.json")); + _fileSystem.CopyFile(Path.Combine(packageContentPath, "descriptor.json"), + Path.Combine(destinationPath, "descriptor.json"), overwrite); } - public static string GetPackageContentFolderPath(string repositoryPackageFolderPath) { + public string GetPackageContentFolderPath(string repositoryPackageFolderPath) { string repositoryPackageFolderBranchesPath = Path.Combine(repositoryPackageFolderPath, "branches"); - if (Directory.Exists(repositoryPackageFolderBranchesPath)) { + if (_fileSystem.ExistsDirectory(repositoryPackageFolderBranchesPath)) { DirectoryInfo[] directories = new DirectoryInfo(repositoryPackageFolderBranchesPath).GetDirectories(); if (directories.Count() == 1) { return directories[0].FullName; @@ -75,7 +75,7 @@ public static string GetPackageContentFolderPath(string repositoryPackageFolderP return repositoryPackageFolderPath; } - public static string GetPackageContentFolderPath(string repositoryFolderPath, string packageName) { + public string GetPackageContentFolderPath(string repositoryFolderPath, string packageName) { string fullPackagePath = Path.Combine(repositoryFolderPath, packageName); return GetPackageContentFolderPath(fullPackagePath); }