This repository was archived by the owner on Oct 26, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
133 lines (102 loc) · 4.53 KB
/
Program.cs
File metadata and controls
133 lines (102 loc) · 4.53 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
using System.Reflection;
using System.Runtime.InteropServices;
using Serilog;
using Wizard.Application;
using Wizard.Application.DirectoryManipulator;
using Wizard.Application.InstallFinder;
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.WriteTo.File("logs/app.txt", rollingInterval: RollingInterval.Day)
.WriteTo.Console()
.CreateLogger();
try
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
Log.Error("Unable to start software. Invalid platform.");
Environment.Exit(1);
}
Log.Information("wizard - the little helper");
var applicationDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!;
var tempPatchFileDirectory = Path.Combine(applicationDirectory, "TempPatchFiles");
var installFinder = GetInstallFinder();
var installPath = installFinder.GetInstallationPath();
if (installPath == null)
{
Log.Error("Unable to find Wizard101 installation.");
Environment.Exit(1);
}
var directoryManipulator = GetDirectoryManipulator(installPath);
var wizard101Version = await directoryManipulator.GetWizard101Version();
if (wizard101Version == null)
{
Log.Error("Unable to extract Wizard101 version.");
Environment.Exit(1);
}
Log.Information("Found Wizard101 installation at location {InstallPath}", installPath);
Log.Information("Wizard101 data version is: {Wizard101Version}", wizard101Version);
directoryManipulator.DestroyGameData();
Log.Information("Deleted previously installed GameData and ObjectCache for a fresh installation.");
Log.Information("Downloading LatestFileList.bin to discover all Wizard101 files.");
var patchClientDownloader = new PatchClientDownloader(wizard101Version);
await patchClientDownloader.DownloadLatestFileListAsync(tempPatchFileDirectory);
Log.Information("Downloaded LatestFileList.bin successfully!");
var latestFileListExtractor =
new LatestFileListExtractor(Path.Combine(tempPatchFileDirectory, "LatestFileList.bin"));
var filesDiscovered = await latestFileListExtractor.ExtractStringsAsync();
Log.Information("Discovered {FilesDiscoveredCount} downloadable objects from the LatestFileList.bin file.",
filesDiscovered.Count);
var additionalFilesParser = new AdditionalFilesParser(Path.Combine(applicationDirectory, "AdditionalFiles.txt"));
var additionalFiles = await additionalFilesParser.GetAdditionalFilesAsync();
Log.Information("Discovered {AdditionalFilesCount} downloadable objects from the AdditionalFiles.txt file.",
additionalFiles.Count);
var allFiles = new List<string>();
allFiles.AddRange(filesDiscovered);
allFiles.AddRange(additionalFiles);
allFiles = allFiles.Distinct().ToList();
allFiles.Sort();
Log.Information(
"Discovered a total of {AllFilesCount} files to download after merging and removing duplicates.",
allFiles.Count);
await directoryManipulator.OverrideLocalPackagesListAsync(allFiles);
Log.Information(
"Deleted previously installed LocalPackagesList for a fresh installation and override with complete list.");
var currentFile = 1;
foreach (var file in allFiles)
{
Log.Information("[{CurrentFile:D4}/{AllFilesCount:D4}] BEGIN {File}", currentFile, allFiles.Count, file);
var fileSize = await patchClientDownloader.GetFileSizeAsync(file);
Log.Information(
"[{CurrentFile:D4}/{AllFilesCount:D4}] BEGIN {File} | File size: {FileSize:F2}MB", currentFile,
allFiles.Count, file, fileSize / (1024.0 * 1024.0));
await patchClientDownloader.DownloadFileAsync(file, Path.Combine(installPath, "Data", "GameData"));
currentFile++;
}
Log.Information(
"The files were successfully downloaded to the Wizard101 client. Please start up your game and enjoy!~");
}
catch (Exception ex)
{
Log.Error(ex, "Something went wrong.");
}
finally
{
await Log.CloseAndFlushAsync();
}
return;
IInstallFinder GetInstallFinder()
{
return RuntimeInformation.OSDescription switch
{
_ when RuntimeInformation.IsOSPlatform(OSPlatform.Windows) => new InstallFinderWindows(),
_ => throw new PlatformNotSupportedException()
};
}
IDirectoryManipulator GetDirectoryManipulator(string directoryPath)
{
return RuntimeInformation.OSDescription switch
{
_ when RuntimeInformation.IsOSPlatform(OSPlatform.Windows) => new DirectoryManipulatorWindows(directoryPath),
_ => throw new PlatformNotSupportedException()
};
}