public static string UISelectDeviceID(TextModeDriverDirectory driverDirectory)
        {
            TextModeDriverSetupINIFile driverINI = driverDirectory.TextModeDriverSetupINI;

            string deviceID = String.Empty;

            if (driverINI.Devices.Count > 1)
            {
                Console.WriteLine("The directory specified contains drivers for the following devices:");
                for (int index = 0; index < driverINI.Devices.Count; index++)
                {
                    Console.WriteLine("{0}. {1}", index + 1, driverINI.Devices[index].Value);
                }
                Console.Write("Select the device driver you wish to integrate: ");
                // driver number could be double-digit, so we use ReadLine()
                int selection = Conversion.ToInt32(Console.ReadLine()) - 1;
                if (selection >= 0 && selection < driverINI.Devices.Count)
                {
                    deviceID = driverINI.Devices[selection].Key;
                    return(deviceID);
                }
                else
                {
                    Console.WriteLine("Error: No driver has been selected, exiting.");
                    return(String.Empty);
                }
            }
            else if (driverINI.Devices.Count == 1)
            {
                deviceID = driverINI.Devices[0].Key;
                string deviceName = driverINI.Devices[0].Value;
                Console.WriteLine("Found one driver:");
                Console.WriteLine("1. " + deviceName);
                return(deviceID);
            }
            else
            {
                Console.WriteLine("Mass storage device driver has not been found.");
                return(String.Empty);
            }
        }
Example #2
0
        /// <summary>
        /// return false if args are invalid
        /// </summary>
        private static bool ParseCommandLineSwitches(string[] args, out WindowsInstallation installation, out List <TextModeDriverDirectory> textModeDriverDirectories, out List <PNPDriverDirectory> pnpDriverDirectories, out bool useLocalHardwareConfig, out string enumExportPath, out bool preconfigure, out bool staticIP, out bool usbBoot)
        {
            installation = null;
            textModeDriverDirectories = new List <TextModeDriverDirectory>();
            pnpDriverDirectories      = new List <PNPDriverDirectory>();
            enumExportPath            = String.Empty;
            useLocalHardwareConfig    = false;
            preconfigure = false;
            staticIP     = true;
            usbBoot      = false;

            List <string> pnpDriverPaths      = new List <string>();
            List <string> textModeDriverPaths = new List <string>();
            string        targetPath          = "C:\\";

            if (args.Length == 0)
            {
                ShowHelp();
                return(false);
            }
            else
            {
                foreach (string arg in args)
                {
                    string switchName      = arg;
                    string switchParameter = String.Empty;
                    if (arg.StartsWith("/"))
                    {
                        switchName = arg.Substring(1);
                        int index = switchName.IndexOfAny(new char[] { ':', '=' });
                        if (index >= 0)
                        {
                            switchParameter = switchName.Substring(index + 1);
                            switchParameter = switchParameter.Trim('"');
                            switchName      = switchName.Substring(0, index);
                        }
                    }

                    switch (switchName.ToLower())
                    {
                    case "driver":
                        string pnpDriverPath = switchParameter;
                        if (!pnpDriverPath.EndsWith("\\") && !pnpDriverPath.EndsWith(":"))
                        {
                            pnpDriverPath = pnpDriverPath + "\\";
                        }
                        pnpDriverPaths.Add(pnpDriverPath);
                        break;

                    case "textmodedriver":
                        string textModeDriverPath = switchParameter;
                        if (!textModeDriverPath.EndsWith("\\") && !textModeDriverPath.EndsWith(":"))
                        {
                            textModeDriverPath = textModeDriverPath + "\\";
                        }
                        textModeDriverPaths.Add(textModeDriverPath);
                        break;

                    case "target":
                        targetPath = switchParameter;
                        if (!targetPath.EndsWith("\\") && !targetPath.EndsWith(":"))
                        {
                            targetPath = targetPath + "\\";
                        }
                        break;

                    case "local":
                        useLocalHardwareConfig = true;
                        break;

                    case "enum":
                        enumExportPath = switchParameter;
                        break;

                    case "preconf":
                        preconfigure = true;
                        break;

                    case "dhcp":
                        staticIP = false;
                        break;

                    case "usbboot":
                        usbBoot = true;
                        break;

                    case "?":
                    case "help":
                        ShowHelp();
                        return(false);

                    default:
                        Console.WriteLine("Error: Invalid command-line switch: " + switchName);
                        return(false);
                    }
                }

                installation = new WindowsInstallation(targetPath);
                if (!installation.IsTargetValid)
                {
                    Console.WriteLine("Error: Could not find installation directory");
                    Console.WriteLine("- if you are using winnt32.exe, you should use the /makelocalsource switch.");
                    return(false);
                }

                if (!installation.IsWindows2000 && !installation.IsWindowsXP && !installation.IsWindowsServer2003)
                {
                    Console.WriteLine("Error: Unsupported operating system version");
                    return(false);
                }

                if (enumExportPath == String.Empty && !useLocalHardwareConfig && preconfigure)
                {
                    Console.WriteLine("Error: The /preconf switch can only be present with the /local or /enum switch.");
                    return(false);
                }

                foreach (string textModeDriverPath in textModeDriverPaths)
                {
                    TextModeDriverDirectory textModeDriverDirectory = new TextModeDriverDirectory(textModeDriverPath);
                    if (!textModeDriverDirectory.ContainsOEMSetupFile)
                    {
                        Console.WriteLine("Error: Could not find the OEM driver setup file (txtsetup.oem). Directory: " + textModeDriverPath);
                        return(false);
                    }
                    textModeDriverDirectories.Add(textModeDriverDirectory);
                }

                foreach (string pnpDriverPath in pnpDriverPaths)
                {
                    PNPDriverDirectory driverDirectory = new PNPDriverDirectory(pnpDriverPath);
                    if (!driverDirectory.ContainsINFFiles)
                    {
                        Console.WriteLine("Error: Could not find any .inf file in driver directory: " + pnpDriverPath);
                        return(false);
                    }
                    pnpDriverDirectories.Add(driverDirectory);
                }

                if (enumExportPath != String.Empty && !FileSystemUtils.IsFileExist(enumExportPath))
                {
                    Console.WriteLine("Error: the file '{0}' does not exist.", enumExportPath);
                    return(false);
                }

                if (usbBoot && installation.IsWindows2000 && installation.ServicePackVersion < 4)
                {
                    Console.WriteLine("Error: the /usbboot switch is only supported with Windows 2000 SP4.");
                    Console.WriteLine("Note that earlier versions of Windows 2000 do not support USB 2.0.");
                    return(false);
                }
                return(true);
            }
        }
 public TextModeDriverIntegrator(TextModeDriverDirectory driverDirectory, WindowsInstallation installation, string deviceID)
 {
     m_driverDirectory = driverDirectory;
     m_installation    = installation;
     m_deviceID        = deviceID;
 }
Example #4
0
        /// <summary>
        /// return false if args are invalid
        /// </summary>
        private static bool ParseCommandLineSwitches(string[] args, out WindowsInstallation installation, out List <TextModeDriverDirectory> textModeDriverDirectories, out List <PNPDriverDirectory> pnpDriverDirectories, out bool useLocalHardwareConfig, out string enumExportPath, out bool preconfigure, out IPAddress staticIP, out IPAddress staticSubnetMask, out IPAddress staticGateway, out bool usbBoot)
        {
            installation = null;
            textModeDriverDirectories = new List <TextModeDriverDirectory>();
            pnpDriverDirectories      = new List <PNPDriverDirectory>();
            enumExportPath            = string.Empty;
            useLocalHardwareConfig    = false;
            preconfigure     = false;
            staticIP         = null;
            staticSubnetMask = null;
            staticGateway    = null;
            usbBoot          = false;

            var pnpDriverPaths      = new List <string>();
            var textModeDriverPaths = new List <string>();
            var targetPath          = "C:\\";

            if (args.Length == 0)
            {
                ShowHelp();
                return(false);
            }

            foreach (var arg in args)
            {
                var switchName      = arg;
                var switchParameter = string.Empty;
                if (arg.StartsWith("/"))
                {
                    switchName = arg.Substring(1);
                    var index = switchName.IndexOfAny(new[] { ':', '=' });
                    if (index >= 0)
                    {
                        switchParameter = switchName.Substring(index + 1);
                        switchParameter = switchParameter.Trim('"');
                        switchName      = switchName.Substring(0, index);
                    }
                }

                switch (switchName.ToLower())
                {
                case "driver":
                {
                    var pnpDriverPath = switchParameter;
                    if (!pnpDriverPath.EndsWith("\\") && !pnpDriverPath.EndsWith(":"))
                    {
                        pnpDriverPath = pnpDriverPath + "\\";
                    }
                    pnpDriverPaths.Add(pnpDriverPath);
                    break;
                }

                case "textmodedriver":
                {
                    var textModeDriverPath = switchParameter;
                    if (!textModeDriverPath.EndsWith("\\") && !textModeDriverPath.EndsWith(":"))
                    {
                        textModeDriverPath = textModeDriverPath + "\\";
                    }
                    textModeDriverPaths.Add(textModeDriverPath);
                    break;
                }

                case "target":
                {
                    targetPath = switchParameter;
                    if (!targetPath.EndsWith("\\") && !targetPath.EndsWith(":"))
                    {
                        targetPath = targetPath + "\\";
                    }
                    break;
                }

                case "local":
                {
                    useLocalHardwareConfig = true;
                    break;
                }

                case "enum":
                {
                    enumExportPath = switchParameter;
                    break;
                }

                case "preconf":
                {
                    preconfigure = true;
                    break;
                }

                case "dhcp":
                {
                    staticIP = null;
                    break;
                }

                case "ip":
                {
                    if (!IPAddress.TryParse(switchParameter, out staticIP))
                    {
                        ShowHelp();
                        return(false);
                    }
                    staticIP = IPAddress.Parse(switchParameter);
                    break;
                }

                case "subnet":
                {
                    int subnet;

                    if (!int.TryParse(switchParameter, out subnet) || subnet > 32 || subnet < 0)
                    {
                        ShowHelp();
                        return(false);
                    }

                    // Calculate a subnet mask from the CIDR
                    var subnetMask = 0xFFFFFFFF ^ (1 << 32 - subnet) - 1;

                    // Then flip the bytes and make an IP address
                    var b1 = (subnetMask >> 0) & 0xff;
                    var b2 = (subnetMask >> 8) & 0xff;
                    var b3 = (subnetMask >> 16) & 0xff;
                    var b4 = (subnetMask >> 24) & 0xff;
                    staticSubnetMask = new IPAddress(b1 << 24 | b2 << 16 | b3 << 8 | b4 << 0);

                    break;
                }

                case "gateway":
                {
                    if (!IPAddress.TryParse(switchParameter, out staticGateway))
                    {
                        ShowHelp();
                        return(false);
                    }
                    staticGateway = IPAddress.Parse(switchParameter);
                    break;
                }

                case "usbboot":
                {
                    usbBoot = true;
                    break;
                }

                case "?":
                case "help":
                {
                    ShowHelp();
                    return(false);
                }

                default:
                {
                    Console.WriteLine("Error: Invalid command-line switch: " + switchName);
                    return(false);
                }
                }
            }

            installation = new WindowsInstallation(targetPath);
            if (!installation.IsTargetValid)
            {
                Console.WriteLine("Error: Could not find installation directory");
                Console.WriteLine("- if you are using winnt32.exe, you should use the /makelocalsource switch.");
                return(false);
            }

            if (!installation.IsWindows2000 && !installation.IsWindowsXP && !installation.IsWindowsServer2003)
            {
                Console.WriteLine("Error: Unsupported operating system version");
                return(false);
            }

            if (enumExportPath == string.Empty && !useLocalHardwareConfig && preconfigure)
            {
                Console.WriteLine("Error: The /preconf switch can only be present with the /local or /enum switch.");
                return(false);
            }

            foreach (var textModeDriverPath in textModeDriverPaths)
            {
                var textModeDriverDirectory = new TextModeDriverDirectory(textModeDriverPath);
                if (!textModeDriverDirectory.ContainsOEMSetupFile)
                {
                    Console.WriteLine("Error: Could not find the OEM driver setup file (txtsetup.oem). Directory: " + textModeDriverPath);
                    return(false);
                }
                textModeDriverDirectories.Add(textModeDriverDirectory);
            }

            foreach (var pnpDriverPath in pnpDriverPaths)
            {
                var driverDirectory = new PNPDriverDirectory(pnpDriverPath);
                if (!driverDirectory.ContainsINFFiles)
                {
                    Console.WriteLine("Error: Could not find any .inf file in driver directory: " + pnpDriverPath);
                    return(false);
                }
                pnpDriverDirectories.Add(driverDirectory);
            }

            if (enumExportPath != string.Empty && !FileSystemUtils.IsFileExist(enumExportPath))
            {
                Console.WriteLine("Error: the file '{0}' does not exist.", enumExportPath);
                return(false);
            }

            if (usbBoot && installation.IsWindows2000 && installation.ServicePackVersion < 4)
            {
                Console.WriteLine("Error: the /usbboot switch is only supported with Windows 2000 SP4.");
                Console.WriteLine("Note that earlier versions of Windows 2000 do not support USB 2.0.");
                return(false);
            }
            return(true);
        }