private const string USBDK_DOWNLOAD_URL = "https://github.com/daynix/UsbDk/releases/download/v1.0.22/UsbDk_1.0.22_x64.msi"; private const string INSTALLER_FILENAME = "UsbDk_1.0.22_x64.msi"; private readonly string _downloadPath; private readonly ILogger _logger;
using (Process process = Process.Start(psi)) if (process == null) throw new InvalidOperationException("Failed to start msiexec"); if (!process.WaitForExit(300000)) // 5 minute timeout process.Kill(); throw new TimeoutException("Installation timed out"); return process.ExitCode == 0; catch (Exception ex) _logger.LogError($"Installation error: ex.Message"); return false; 2-download and install usbdk-1.0.22-x64.msi
public void LogWarning(string message) Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine($"[WARNING] DateTime.Now:HH:mm:ss - message"); Console.ResetColor(); private const string USBDK_DOWNLOAD_URL = "https://github
void LogInfo(string message); void LogError(string message); void LogWarning(string message); void LogSuccess(string message); private readonly string _downloadPath
public void LogSuccess(string message) Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine($"[SUCCESS] DateTime.Now:HH:mm:ss - message"); Console.ResetColor();
// Check Windows registry string uninstallKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"; using (Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(uninstallKey)) if (key != null) foreach (string subkeyName in key.GetSubKeyNames()) using (Microsoft.Win32.RegistryKey subkey = key.OpenSubKey(subkeyName)) if (subkey?.GetValue("DisplayName")?.ToString()?.Contains("UsbDk") == true) return true; return false; catch return false;
public async Task<bool> InstallAsync(bool forceReinstall = false) try // Step 1: Check for administrative privileges if (!IsAdministrator()) _logger.LogError("Administrator privileges required for installation"); return false;