Skip to content
This repository has been archived by the owner on Oct 3, 2021. It is now read-only.

Commit

Permalink
Fix Packed Files Error #4
Browse files Browse the repository at this point in the history
  • Loading branch information
daryllabar committed Sep 24, 2019
1 parent d76ff03 commit 2a82df4
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 8 deletions.
2 changes: 1 addition & 1 deletion CanvasAppPackager/Args/Args.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public OptionSet Options
{"c|Clobber|clobber", "Optional. This argument is used only during an extraction. When /clobber is specified, files that have the read-only attribute set are overwritten or deleted. When not specified, files with the read-only attribute aren’t overwritten or deleted.", v => Clobber = v != null },
{"z=|ZipFile", "Required. The path and name of an application package .zip file. When extracting, the file must exist and will be read from, or must be 'Latest' to use the latest downloaded file. When packing, the file is replaced.", v => PackageZip = v?.Trim() },
{"f=|folder", "Required. The path to a folder. When extracting, this folder is created and populated with component files. When packing, this folder must already exist and contain previously extracted component files.", v => UnpackPath = v?.Trim()},
{"l:|log", "Optional. A path and name to a log file. If the file already exists, new logging information is appended to the file..", v => LogPath = v?.Trim()},
{"l:|log", "Optional. A path and name to a log file. If the file already exists, new logging information is appended to the file.", v => LogPath = v?.Trim()},
{"h|?|help", v => Help = v != null}
};
}
Expand Down
2 changes: 2 additions & 0 deletions CanvasAppPackager/CanvasAppPackager.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.2</TargetFramework>
<AssemblyVersion>1.0.0.1</AssemblyVersion>
<FileVersion>1.0.0.1</FileVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
40 changes: 40 additions & 0 deletions CanvasAppPackager/MsAppHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;

namespace CanvasAppPackager
{
public class MsAppHelper
{
public static void CreateFromDirectory(string sourcePath, string outputName)
{
var files = new List<string>(Directory.GetFiles(sourcePath, "", SearchOption.AllDirectories));

using (var zipToOpen = new FileStream(outputName, FileMode.Create))
using (var archive = new ZipArchive(zipToOpen, ZipArchiveMode.Create))
{
foreach (var file in files)
{
var name = Path.GetRelativePath(sourcePath, file);
ZipFileExtensions.CreateEntryFromFile(archive, file, name);
}
}
}

public static void AddFiles(Dictionary<string, List<string>> filesByRootPath, string outputName)
{
using (var zipToOpen = new FileStream(outputName, FileMode.Create))
using (var archive = new ZipArchive(zipToOpen, ZipArchiveMode.Create))
{
foreach (var files in filesByRootPath)
{
foreach (var file in files.Value)
{
var name = Path.GetRelativePath(files.Key, file);
ZipFileExtensions.CreateEntryFromFile(archive, file, name);
}
}
}
}
}
}
15 changes: 9 additions & 6 deletions CanvasAppPackager/PackLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,10 @@ public static void Pack(Args.Args options)
private static void PackApp(string appPath, string mainAppPath)
{
Logger.Log("Processing App at: " + appPath);
var sourcePath = Path.Combine(appPath, UnpackLogic.Paths.Metadata);
var metadataFiles = Directory.GetFiles(sourcePath);
Logger.Log("Parsing AppInfo");
var appInfo = AppInfo.Parse(File.ReadAllText(metadataFiles.Single(f => Path.GetExtension(f) == ".json")));
var destinationPath = Path.Combine(mainAppPath, UnpackLogic.Paths.MsPowerApps, "apps", appInfo.AppId);
var zipPath = GetTemporaryDirectory();
try
{
Logger.Log("Copying app files for zip creation.");
CopyFilesToZipFolder(appPath, zipPath, "MsApp", UnpackLogic.Paths.Code, UnpackLogic.Paths.Metadata);
Logger.Log("Packaging Code files");
foreach (var codeDirectory in Directory.GetDirectories(Path.Combine(appPath, UnpackLogic.Paths.Code)))
Expand All @@ -59,8 +55,15 @@ private static void PackApp(string appPath, string mainAppPath)
File.WriteAllText(Path.Combine(dir, screen.TopParent.ControlUniqueId) + ".json", screen.Serialize());
}

Logger.Log("Parsing AppInfo");
var sourcePath = Path.Combine(appPath, UnpackLogic.Paths.Metadata);
var metadataFiles = Directory.GetFiles(sourcePath);
var appInfo = AppInfo.Parse(File.ReadAllText(metadataFiles.Single(f => Path.GetExtension(f) == ".json")));
var destinationPath = Path.Combine(mainAppPath, UnpackLogic.Paths.MsPowerApps, "apps", appInfo.AppId);
MoveMetadataFilesFromExtract(sourcePath, destinationPath, metadataFiles);
ZipFile.CreateFromDirectory(zipPath, Path.Combine(destinationPath, Path.GetFileName(appInfo.MsAppPath)));
var msAppZipPath = Path.Combine(destinationPath, Path.GetFileName(appInfo.MsAppPath));
Logger.Log($"Packing file {msAppZipPath}");
MsAppHelper.CreateFromDirectory(zipPath, msAppZipPath);
}
finally
{
Expand Down
2 changes: 1 addition & 1 deletion CanvasAppPackager/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ static void Main(string[] args)
"/f", @"C:\Temp\PowerFlappy\Extract"
};

var options = Args.Args.Parse(pack);
var options = Args.Args.Parse(args);
if (!string.IsNullOrWhiteSpace(options.LogPath))
{
Logger.Error("Log Path not implemented!");
Expand Down

0 comments on commit 2a82df4

Please sign in to comment.