Skip to content

Commit

Permalink
Improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
gus33000 committed Feb 25, 2024
1 parent 9ce08a8 commit 42b7e8c
Show file tree
Hide file tree
Showing 7 changed files with 231 additions and 71 deletions.
1 change: 0 additions & 1 deletion DefinitionMigrator/DefinitionMigrator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<OutputType>Exe</OutputType>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<RuntimeIdentifiers>win-x86;win-x64;win-arm64</RuntimeIdentifiers>
<ApplicationManifest>app.manifest</ApplicationManifest>
<Platforms>AnyCPU;x64;x86;arm64</Platforms>
</PropertyGroup>

Expand Down
32 changes: 0 additions & 32 deletions DefinitionMigrator/app.manifest

This file was deleted.

14 changes: 7 additions & 7 deletions DriverUpdater/CksLicensing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public CksLicensing(string DrivePath)
this.DrivePath = DrivePath;
}

private static readonly int[] Empty = new int[0];
private static readonly int[] Empty = [];

private static int[] Locate(byte[] self, byte[] candidate)
{
Expand Down Expand Up @@ -78,8 +78,8 @@ public void SetLicensedState()
RegistryKey key = hive.Root.OpenSubKey("ControlSet001\\Control\\ProductOptions");
byte[] value = (byte[])key.GetValue("ProductPolicy");

byte[] oldValue = new byte[]
{
byte[] oldValue =
[
0x43, 0x00, 0x6F, 0x00, 0x64, 0x00, 0x65, 0x00, 0x49, 0x00, 0x6E,
0x00, 0x74, 0x00, 0x65, 0x00, 0x67, 0x00, 0x72, 0x00, 0x69, 0x00,
0x74, 0x00, 0x79, 0x00, 0x2D, 0x00, 0x41, 0x00, 0x6C, 0x00, 0x6C,
Expand All @@ -91,10 +91,10 @@ public void SetLicensedState()
0x4B, 0x00, 0x65, 0x00, 0x72, 0x00, 0x6E, 0x00, 0x65, 0x00, 0x6C,
0x00, 0x53, 0x00, 0x69, 0x00, 0x67, 0x00, 0x6E, 0x00, 0x65, 0x00,
0x72, 0x00, 0x73, 0x00, 0x00, 0x00, 0x00, 0x00
};
];

byte[] newValue = new byte[]
{
byte[] newValue =
[
0x43, 0x00, 0x6F, 0x00, 0x64, 0x00, 0x65, 0x00, 0x49, 0x00, 0x6E,
0x00, 0x74, 0x00, 0x65, 0x00, 0x67, 0x00, 0x72, 0x00, 0x69, 0x00,
0x74, 0x00, 0x79, 0x00, 0x2D, 0x00, 0x41, 0x00, 0x6C, 0x00, 0x6C,
Expand All @@ -106,7 +106,7 @@ public void SetLicensedState()
0x4B, 0x00, 0x65, 0x00, 0x72, 0x00, 0x6E, 0x00, 0x65, 0x00, 0x6C,
0x00, 0x53, 0x00, 0x69, 0x00, 0x67, 0x00, 0x6E, 0x00, 0x65, 0x00,
0x72, 0x00, 0x73, 0x00, 0x01, 0x00, 0x00, 0x00
};
];

int[] positions = Locate(value, oldValue);

Expand Down
12 changes: 6 additions & 6 deletions DriverUpdater/DismProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ internal class DismProvider : IDisposable
public DismProvider(string DrivePath)
{
// Workaround for issue in DISM api
if (!DrivePath.EndsWith("\\"))
if (!DrivePath.EndsWith('\\'))
{
DrivePath += "\\";
}
Expand Down Expand Up @@ -144,7 +144,7 @@ public bool InstallApplications(IEnumerable<(string, string)> applicationPaths)
Logging.Log("");
Logging.Log($"DismApi->AddProvisionedAppxPackage: ntStatus=0x{ntStatus:X8}, app={app.AppXFilePath}", Logging.LoggingLevel.Error);

return false;
//return false;
}
}

Expand Down Expand Up @@ -175,7 +175,7 @@ private bool UninstallDrivers(string[] existingOEMDrivers)
Logging.Log("");
Logging.Log($"RemoveOfflineDriver: ntStatus=0x{ntStatus:X8}, driver={driver}", Logging.LoggingLevel.Error);

return false;
//return false;
}
}
Logging.ShowProgress(existingOEMDrivers.Length, existingOEMDrivers.Length, startTime, false);
Expand All @@ -193,7 +193,7 @@ public bool UninstallExistingDrivers()
if ((ntStatus & 0x80000000) != 0)
{
Logging.Log($"DriverStoreOfflineEnumDriverPackage: ntStatus=0x{ntStatus:X8}", Logging.LoggingLevel.Error);
return false;
//return false;
}

if (!UninstallDrivers(existingOEMDrivers))
Expand Down Expand Up @@ -243,7 +243,7 @@ public bool InstallDrivers(IEnumerable<string> infFiles)
Logging.Log("");
Logging.Log($"DismApi->AddDriver: ntStatus=0x{ntStatus:X8}, driverInf={inf}", Logging.LoggingLevel.Error);

return false;
//return false;
}
}
Logging.ShowProgress(infFiles.Count(), infFiles.Count(), startTime, false);
Expand Down Expand Up @@ -298,7 +298,7 @@ public bool InstallFrameworkDependencies(IEnumerable<(string AppXFilePath, strin
Logging.Log("");
Logging.Log($"DismApi->AddProvisionedAppxPackage: ntStatus=0x{ntStatus:X8}, app={app.AppXFilePath}", Logging.LoggingLevel.Error);

return false;
//return false;
}
}

Expand Down
2 changes: 1 addition & 1 deletion DriverUpdater/DriverUpdater.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.9.1" />
<PackageReference Include="Microsoft.Dism" Version="3.0.0" />
<PackageReference Include="Microsoft.Dism" Version="3.1.0" />
<PackageReference Include="Quamotion.DiscUtils.Registry" Version="0.15.4" />
</ItemGroup>

Expand Down
70 changes: 50 additions & 20 deletions DriverUpdater/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,19 +112,26 @@ private static void DriverUpdaterAction(string Definition, string DriverRepo, st
Logging.Log("The device has not been booted yet. Installing Board Support Package for the first time prior to first boot.");
}

bool result = Install(Definition, DriverRepo, DevicePart, upgrade);
if (upgrade)
{
UninstallDrivers(DevicePart, upgrade);

Logging.Log("Fixing potential registry left overs");
RegistryFixer.FixLeftOvers(DevicePart);
}

InstallDrivers(Definition, DriverRepo, DevicePart);

if (result)
if (upgrade)
{
if (upgrade)
{
Logging.Log("Fixing potential registry left overs");
new RegistryFixer(DevicePart).FixRegistryPaths();
}

Logging.Log("Enabling Cks");
new CksLicensing(DevicePart).SetLicensedState();
Logging.Log("Fixing potential registry left overs");
RegistryFixer.FixRegistryPaths(DevicePart);
}

Logging.Log("Enabling Cks");
new CksLicensing(DevicePart).SetLicensedState();

InstallApps(Definition, DriverRepo, DevicePart, upgrade);
}
catch (Exception ex)
{
Expand Down Expand Up @@ -215,7 +222,7 @@ private static bool ResealForPnPFirstBootUx(string DevicePart)
return result;
}

private static bool Install(string Definition, string DriverRepo, string DrivePath, bool IsUpgrade)
private static bool InstallDrivers(string Definition, string DriverRepo, string DrivePath)
{
Logging.Log("Reading definition file...");
DefinitionParser definitionParser = new(Definition);
Expand Down Expand Up @@ -244,6 +251,37 @@ private static bool Install(string Definition, string DriverRepo, string DrivePa
}
}

if (!everythingExists)
{
return false;
}

using DismProvider dismProvider = new(DrivePath);
return dismProvider.InstallDrivers(driverPathsToInstall);
}

private static bool UninstallDrivers(string DrivePath, bool IsUpgrade)
{
using DismProvider dismProvider = new(DrivePath);

if (IsUpgrade)
{
if (!dismProvider.UninstallExistingDrivers())
{
return false;
}
}

return true;
}

private static bool InstallApps(string Definition, string DriverRepo, string DrivePath, bool IsUpgrade)
{
Logging.Log("Reading definition file...");
DefinitionParser definitionParser = new(Definition);

bool everythingExists = true;

IEnumerable<(string, string)> applicationPaths = [];

if (definitionParser.FeatureManifest.AppX != null)
Expand Down Expand Up @@ -288,15 +326,7 @@ private static bool Install(string Definition, string DriverRepo, string DrivePa

using DismProvider dismProvider = new(DrivePath);

if (IsUpgrade)
{
if (!dismProvider.UninstallExistingDrivers())
{
return false;
}
}

return dismProvider.InstallDrivers(driverPathsToInstall) && dismProvider.InstallFrameworkDependencies(applicationPaths) && dismProvider.InstallApplications(applicationPaths);
return dismProvider.InstallFrameworkDependencies(applicationPaths) && dismProvider.InstallApplications(applicationPaths);
}

private static bool OnlineInstall(string Definition, string DriverRepo)
Expand Down
Loading

0 comments on commit 42b7e8c

Please sign in to comment.