Repository navigation
Expand file tree
/
Copy pathProgram.cs
More file actions
75 lines (64 loc) · 2.45 KB
/
Copy pathProgram.cs
File metadata and controls
75 lines (64 loc) · 2.45 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
using System;
using System.Diagnostics;
using System.IO;
using Imaging;
using VirtualHardDiskLib;
namespace LayerConverter
{
class Program
{
private static readonly WIMGImaging wim = new();
static void Main(string[] args)
{
if (args.Length != 2)
//if (args.Length != 3)
{
Console.WriteLine("Usage: tool.exe <path to downloaded file from winlayers> <path to output wim>"); //<short temp path>");
return;
}
string archivePath = args[0];
string outPath = args[1];
//string tempPath = args[2];
using (VirtualDiskSession session = new())
{
try
{
string tempPath = Path.Combine(session.GetMountedPath(), "C");
LayerExpander.ApplyLayer(archivePath, tempPath);
int prevperc = -1;
string prevop = "";
void callback(string SubOperation, int ProgressInPercentage, bool IsIndeterminate)
{
if (prevperc == ProgressInPercentage && SubOperation == prevop)
return;
prevop = SubOperation;
prevperc = ProgressInPercentage;
string progress = IsIndeterminate ? "" : $" [Progress: {ProgressInPercentage}%]";
Console.WriteLine($"{progress} {SubOperation}");
}
wim.CaptureImage(outPath, "ContainerOS", "ContainerOS", "ContainerOS", Path.Combine(tempPath, "Files"), progressCallback: callback);
wim.CaptureImage(outPath, "UtilityVM", "UtilityVM", "UtilityVM", Path.Combine(tempPath, "UtilityVM", "Files"), progressCallback: callback);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
/*TakeOwnDirectory(tempPath);
TakeOwnDirectory(tempPath);
try
{
Directory.Delete(tempPath, true);
}
catch { }*/
}
}
static void TakeOwnDirectory(string path)
{
Process proc = new();
proc.StartInfo = new ProcessStartInfo("cmd.exe", "/c takeown /f \"" + path + "\" && icacls \"" + path + "\" /grant *S-1-3-4:F /t /c /l");
proc.StartInfo.UseShellExecute = false;
proc.Start();
proc.WaitForExit();
}
}
}