-
Notifications
You must be signed in to change notification settings - Fork 0
/
WinVFSServiceProgram.cs
88 lines (77 loc) · 2.91 KB
/
WinVFSServiceProgram.cs
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
using System;
using System.IO;
using System.Threading;
using CommandLine;
using CommandLine.Text;
using WinVfs.VirtualFilesystem;
namespace WinVfs.Service;
internal sealed class WinVfsServiceProgram
{
static int Main(string[] args)
{
int retCode = (int)ReturnCode.Success;
try
{
using var parser = new Parser(
settings =>
{
settings.AutoHelp = true;
settings.CaseSensitive = false;
settings.CaseInsensitiveEnumValues = true;
});
ParserResult<CommandLineOptions> parserResult = parser.ParseArguments<CommandLineOptions>(args);
parserResult
.WithParsed(opts => retCode = Run(opts))
.WithNotParsed(_ => retCode = (int)DisplayHelp(parserResult));
}
catch (Exception ex)
{
Console.Error.WriteLine($"Unexpected top-level exception: {ex}");
retCode = (int)ReturnCode.GeneralException;
}
return retCode;
}
private static int Run(CommandLineOptions opts)
{
Console.WriteLine($"Mirroring source dir '{opts.SourceDir}' to '{opts.VirtualizationRoot}");
Console.WriteLine();
var logger = new ConsoleLogger { IsFinestLoggingEnabled = opts.Verbose };
var callbacks = new MirroredDirectoryVfsCallbacks(opts.SourceDir);
Directory.CreateDirectory(opts.VirtualizationRoot);
using var projFsSession = new ProjFsVirtualizationSession(
opts.VirtualizationRoot,
callbacks,
logger,
DateTime.UtcNow,
new ProjFsOptions { EnableDetailedTrace = opts.Verbose },
CancellationToken.None);
Console.WriteLine();
Console.WriteLine("Press Enter to stop virtualization");
Console.WriteLine();
Console.ReadLine();
return 0;
}
private static ReturnCode DisplayHelp(ParserResult<CommandLineOptions> parserResult)
{
HelpText helpText = HelpText.AutoBuild(parserResult, maxDisplayWidth: ConsoleUtils.GetConsoleWidthForHelpText());
Console.Error.WriteLine(helpText);
return ReturnCode.InvalidArguments;
}
private enum ReturnCode
{
Success = 0,
InvalidArguments = 1,
GeneralException = 2,
}
}
internal sealed class CommandLineOptions
{
[Option('r', nameof(VirtualizationRoot), Required = true,
HelpText = "The directory in which to mount the virtual filesystem")]
public string VirtualizationRoot { get; set; } = string.Empty;
[Option('s', nameof(SourceDir), Required = true,
HelpText = "The source directory to mirror into the virtualization root")]
public string SourceDir { get; set; } = string.Empty;
[Option('v', nameof(Verbose), Required = false, HelpText = "Output verbose/finest logging level.")]
public bool Verbose { get; set; }
}