driver-updater

Windows app that checks Windows Update and hardware vendors for newer drivers and silently installs the driver.
git clone https://dittus.dev/git/driver-updater.git
Log | Files | Refs | README | Download

commit 83f4b40eb59f65a45d4ffefe64d03d094b819efb
parent a6799efb2bf5f7f0c07b610cbb6804bf4939c095
Author: dittus <dittus@pm.me>
Date:   Tue, 27 Oct 2026 16:09:06 -0400

Wait for AMD's chipset setup to finish, and wrap long status text

Diffstat:
MDriverUpdater.csproj | 2+-
MMainWindow.xaml | 10+++++-----
MREADME.md | 4++--
MUnpack.cs | 65+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
4 files changed, 71 insertions(+), 10 deletions(-)

diff --git a/DriverUpdater.csproj b/DriverUpdater.csproj @@ -7,7 +7,7 @@ <ImplicitUsings>enable</ImplicitUsings> <UseWPF>true</UseWPF> <ApplicationManifest>app.manifest</ApplicationManifest> - <Version>0.1.0</Version> + <Version>0.1.1</Version> </PropertyGroup> <!-- dotnet publish -c Release makes one exe that runs without .NET installed. --> diff --git a/MainWindow.xaml b/MainWindow.xaml @@ -9,10 +9,10 @@ <Style x:Key="CellText" TargetType="TextBlock" BasedOn="{x:Static DataGridTextColumn.DefaultElementStyle}"> <Setter Property="VerticalAlignment" Value="Center" /> </Style> - <!-- Failure messages can run long, so the full status also shows on hover. --> + <!-- Failure messages can run long, so the status wraps onto as many lines as it needs. --> <Style x:Key="StatusText" TargetType="TextBlock" BasedOn="{StaticResource CellText}"> - <Setter Property="TextTrimming" Value="CharacterEllipsis" /> - <Setter Property="ToolTip" Value="{Binding Status}" /> + <Setter Property="TextWrapping" Value="Wrap" /> + <Setter Property="Margin" Value="0,4" /> </Style> </Window.Resources> @@ -43,7 +43,7 @@ </DataTemplate> </DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn> - <DataGridTextColumn Header="Device" Binding="{Binding Device}" Width="1.4*" IsReadOnly="True" + <DataGridTextColumn Header="Device" Binding="{Binding Device}" Width="*" MinWidth="180" IsReadOnly="True" ElementStyle="{StaticResource CellText}" /> <DataGridTextColumn Header="Source" Binding="{Binding Source}" Width="Auto" IsReadOnly="True" ElementStyle="{StaticResource CellText}" /> @@ -55,7 +55,7 @@ ElementStyle="{StaticResource CellText}" /> <DataGridTextColumn Header="Size" Binding="{Binding SizeText}" Width="Auto" IsReadOnly="True" ElementStyle="{StaticResource CellText}" /> - <DataGridTextColumn Header="Status" Binding="{Binding Status}" Width="*" MinWidth="130" IsReadOnly="True" + <DataGridTextColumn Header="Status" Binding="{Binding Status}" Width="1.6*" MinWidth="160" IsReadOnly="True" ElementStyle="{StaticResource StatusText}" /> <DataGridTemplateColumn Header="Notes" Width="Auto"> <DataGridTemplateColumn.CellTemplate> diff --git a/README.md b/README.md @@ -111,9 +111,9 @@ Each vendor numbers drivers differently from Windows. | `Windows Update error 0x80240044` | The app isn't running as admin | Start it through UAC | | `Windows Update error 0x8024402C` | Windows Update can't reach Microsoft | Check the network and proxy | | `Couldn't create a restore point` | System Protection is off for the system drive | Turn it on in System Properties, or clear the checkbox | -| A row like `NVIDIA check` with `Failed: ...` | The vendor changed or blocked its endpoint, or doesn't know the device | Hover the status for the full error | +| A row like `NVIDIA check` with `Failed: ...` | The vendor changed or blocked its endpoint, or doesn't know the device | The status shows the full error | | `The download isn't signed by ..., so it was deleted` | The download's signature is invalid or belongs to someone else | Get the driver from the vendor's site | -| `tar.exe failed` or `7z.exe failed` | The vendor changed its package format | Hover the status for the tool's error | +| `tar.exe failed` or `7z.exe failed` | The vendor changed its package format | The status shows the tool's error | | `Nothing in the package matches this device` | The package has no INF listing any of the device's IDs | The vendor dropped the device, or the feed picked the wrong package | | `Windows kept the current driver` | Windows ranks the installed driver as good or better | Nothing to do | | `Install 7-Zip to check these` | AMD chipset drivers need 7-Zip to unpack | Install 7-Zip and scan again | diff --git a/Unpack.cs b/Unpack.cs @@ -1,6 +1,8 @@ using System.Diagnostics; using System.IO; +using System.Runtime.InteropServices; using Microsoft.Win32; +using Microsoft.Win32.SafeHandles; namespace DriverUpdater; @@ -8,6 +10,9 @@ namespace DriverUpdater; // running the vendor's setup. static class Unpack { + // A tool that's still running after this long is treated as hung. + static readonly TimeSpan Timeout = TimeSpan.FromMinutes(10); + // The tar.exe built into Windows reads 7z archives, including the ones behind a small exe like // NVIDIA's and AMD's graphics packages. public static Task WithTarAsync(string package, string folder) @@ -29,8 +34,9 @@ static class Unpack return File.Exists(sevenZip) ? sevenZip : null; } - // Runs a tool with no window, waits for it, and throws with its error output if it fails. Both - // output streams are read at once, so a tool that fills one can't stall waiting on the other. + // Runs a tool with no window, waits for it and every process it starts, and throws with its error + // output if it fails. Both output streams are read at once, so a tool that fills one can't stall + // waiting on the other. public static async Task RunAsync(string exe, string arguments) { var start = new ProcessStartInfo(exe, arguments) @@ -40,14 +46,69 @@ static class Unpack RedirectStandardOutput = true, RedirectStandardError = true, }; + + // AMD's chipset setup hands its work to a second copy of itself and exits right away, so + // waiting on the first process isn't enough. A job object holds every process the tool + // starts. The tool joins it a moment after it starts, which is long before a setup program + // gets around to starting anything. + using var job = CreateJobObjectW(IntPtr.Zero, null); using var process = Process.Start(start)!; + if (job.IsInvalid || !AssignProcessToJobObject(job, process.Handle)) + throw new InvalidOperationException($"Couldn't track the processes {Path.GetFileName(exe)} starts"); + var output = process.StandardOutput.ReadToEndAsync(); string errors = await process.StandardError.ReadToEndAsync(); await output; await process.WaitForExitAsync(); + await WaitUntilEmptyAsync(job, Path.GetFileName(exe)); if (process.ExitCode != 0) throw new InvalidOperationException( $"{Path.GetFileName(exe)} failed with exit code {process.ExitCode}. {errors.Trim()}".Trim()); } + + static async Task WaitUntilEmptyAsync(SafeFileHandle job, string tool) + { + var watch = Stopwatch.StartNew(); + while (ActiveProcesses(job) > 0) + { + if (watch.Elapsed > Timeout) + throw new TimeoutException($"{tool} was still running after {Timeout.TotalMinutes} minutes"); + await Task.Delay(250); + } + } + + static uint ActiveProcesses(SafeFileHandle job) + { + if (!QueryInformationJobObject(job, JobObjectBasicAccountingInformation, out var info, + Marshal.SizeOf<JobAccounting>(), IntPtr.Zero)) + throw new InvalidOperationException("Couldn't read the tool's process list"); + return info.ActiveProcesses; + } + + const int JobObjectBasicAccountingInformation = 1; + + [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)] + static extern SafeFileHandle CreateJobObjectW(IntPtr attributes, string? name); + + [DllImport("kernel32.dll", SetLastError = true)] + static extern bool AssignProcessToJobObject(SafeFileHandle job, IntPtr process); + + [DllImport("kernel32.dll", SetLastError = true)] + static extern bool QueryInformationJobObject( + SafeFileHandle job, int infoClass, out JobAccounting info, int length, IntPtr returnLength); + + // JOBOBJECT_BASIC_ACCOUNTING_INFORMATION + [StructLayout(LayoutKind.Sequential)] + struct JobAccounting + { + public long TotalUserTime; + public long TotalKernelTime; + public long ThisPeriodTotalUserTime; + public long ThisPeriodTotalKernelTime; + public uint TotalPageFaultCount; + public uint TotalProcesses; + public uint ActiveProcesses; + public uint TotalTerminatedProcesses; + } }