Skip to content

Commit

Permalink
Fixes SetIcon
Browse files Browse the repository at this point in the history
  • Loading branch information
MakarchukPavel committed Sep 20, 2024
1 parent 82b6f22 commit 0f51a56
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 22 deletions.
14 changes: 10 additions & 4 deletions clio/Command/CompressAppCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,18 @@ internal class CompressAppCommand : Command<CompressAppOptions>

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)) {
Expand All @@ -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;
}


Expand Down Expand Up @@ -93,7 +99,7 @@ private Stack<PackageDescriptor> GetStackPackageDescriptors(IEnumerable<string>
}

public string GetPackageContentFolderPath(string packageName) {
return PackageUtilities.GetPackageContentFolderPath(_repositoryFolderPath, packageName);
return _packageUtilities.GetPackageContentFolderPath(_repositoryFolderPath, packageName);
}

private PackageDescriptor GetPackageDescriptor(string packageName) {
Expand Down
6 changes: 4 additions & 2 deletions clio/Command/RfsEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down Expand Up @@ -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);
}

Expand Down
5 changes: 3 additions & 2 deletions clio/Common/FileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand All @@ -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}\"") {
Expand Down
16 changes: 12 additions & 4 deletions clio/ComposableApplication/ComposableApplicationManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections;
using System.IO;
using System.IO.Abstractions;
using System.Json;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions clio/Package/IPackageUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 0 additions & 4 deletions clio/Package/PackageArchiver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions clio/Package/PackageUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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;
Expand All @@ -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);
}
Expand Down

0 comments on commit 0f51a56

Please sign in to comment.