forked from microsoft/winget-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
92 lines (81 loc) · 3.16 KB
/
Copy pathProgram.cs
File metadata and controls
92 lines (81 loc) · 3.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
namespace IndexCreationTool
{
using System;
using System.Diagnostics;
using System.IO;
class Program
{
public const string IndexName = @"index.db";
public const string IndexPathInPackage = @"Public\index.db";
public const string IndexPackageName = @"source.msix";
static void Main(string[] args)
{
string rootDir = string.Empty;
string appxManifestPath = string.Empty;
string certPath = string.Empty;
for (int i = 0; i < args.Length; i++)
{
if (args[i] == "-d" && ++i < args.Length)
{
rootDir = args[i];
}
else if (args[i] == "-m" && ++i < args.Length)
{
appxManifestPath = args[i];
}
else if (args[i] == "-c" && ++i < args.Length)
{
certPath = args[i];
}
}
if (string.IsNullOrEmpty(rootDir))
{
Console.WriteLine("Usage: IndexCreationTool.exe -d <Path to search for yaml> [-m <appxmanifest for index package> [-c <cert for signing index package>]]");
return;
}
try
{
if (File.Exists(IndexName))
{
File.Delete(IndexName);
}
using (var indexHelper = WinGetUtilWrapper.Create(IndexName))
{
foreach (string file in Directory.EnumerateFiles(rootDir, "*.yaml", SearchOption.AllDirectories))
{
indexHelper.AddManifest(file, Path.GetRelativePath(rootDir, file));
}
indexHelper.PrepareForPackaging();
}
if (!string.IsNullOrEmpty(appxManifestPath))
{
using (StreamWriter outputFile = new StreamWriter("MappingFile.txt"))
{
outputFile.WriteLine("[Files]");
outputFile.WriteLine($"\"{IndexName}\" \"{IndexPathInPackage}\"");
outputFile.WriteLine($"\"{appxManifestPath}\" \"AppxManifest.xml\"");
}
RunCommand("makeappx.exe", $"pack /f MappingFile.txt /o /nv /p {IndexPackageName}");
if (!string.IsNullOrEmpty(certPath))
{
RunCommand("signtool.exe", $"sign /a /fd sha256 /f {certPath} {IndexPackageName}");
}
}
}
catch (Exception e)
{
Console.WriteLine("Failed. Reason: " + e.Message);
}
Environment.Exit(0);
}
static void RunCommand(string command, string args)
{
Process p = new Process();
p.StartInfo = new ProcessStartInfo(command, args);
p.Start();
p.WaitForExit();
}
}
}