Ejemplo n.º 1
0
 public PNPDriverIntegrator(PNPDriverDirectory driverDirectory, WindowsInstallation installation, string hardwareID, bool useLocalHardwareConfig, string enumExportPath, bool preconfigure)
     : base(driverDirectory, installation.ArchitectureIdentifier, installation.MinorOSVersion, installation.ProductType, hardwareID)
 {
     m_installation           = installation;
     m_useLocalHardwareConfig = useLocalHardwareConfig;
     m_enumExportPath         = enumExportPath;
     m_preconfigure           = preconfigure;
 }
Ejemplo n.º 2
0
        public static string UISelectMatchingHardwareID(PNPDriverDirectory driverDirectory, string architectureIdentifier, int minorOSVersion, int productType)
        {
            List <KeyValuePair <string, string> > devices = driverDirectory.ListDevices(architectureIdentifier, minorOSVersion, productType);

            Console.WriteLine();
            Console.WriteLine("Looking for matching device drivers in directory '{0}':", driverDirectory.Path);
            return(UISelectMatchingHardwareID(devices));
        }
Ejemplo n.º 3
0
 public PNPDriverIntegratorBase(PNPDriverDirectory driverDirectory, string architectureIdentifier, int minorOSVersion, int productType, string hardwareID)
 {
     m_driverDirectory        = driverDirectory;
     m_architectureIdentifier = architectureIdentifier;
     m_minorOSVersion         = minorOSVersion;
     m_productType            = productType;
     m_hardwareID             = hardwareID;
 }
        public static List <string> DetectMatchingExportedHardware(string path, PNPDriverDirectory driverDirectory, string architectureIdentifier, int minorOSVersion, int productType)
        {
            List <KeyValuePair <string, string> > devices = driverDirectory.ListDevices(architectureIdentifier, minorOSVersion, productType);
            List <string> driverHardwareID = new List <string>();

            foreach (KeyValuePair <string, string> device in devices)
            {
                driverHardwareID.Add(device.Key);
            }
            return(DetectMatchingExportedHardware(path, driverHardwareID));
        }
Ejemplo n.º 5
0
        public static string UISelectHardwareID(PNPDriverDirectory pnpDriverDirectory, WindowsInstallation installation, bool useLocalHardwareConfig, string enumExportPath)
        {
            string hardwareID;
            bool   containsRootDevices = pnpDriverDirectory.ContainsRootDevices(installation.ArchitectureIdentifier, installation.MinorOSVersion, installation.ProductType);

            // We should not use our detection mechanism if a driver directory contains a root device.
            if (!containsRootDevices && (useLocalHardwareConfig || enumExportPath != String.Empty))
            {
                List <string> matchingHardwareIDs;
                if (useLocalHardwareConfig)
                {
                    matchingHardwareIDs = PNPLocalHardwareDetector.DetectMatchingLocalHardware(pnpDriverDirectory, installation.ArchitectureIdentifier, installation.MinorOSVersion, installation.ProductType);
                }
                else
                {
                    matchingHardwareIDs = PNPExportedHardwareDetector.DetectMatchingExportedHardware(enumExportPath, pnpDriverDirectory, installation.ArchitectureIdentifier, installation.MinorOSVersion, installation.ProductType);
                }
                List <KeyValuePair <string, string> > devices = pnpDriverDirectory.ListDevices(installation.ArchitectureIdentifier, installation.MinorOSVersion, installation.ProductType);
                // We now have a list of hardware IDs that matches (some of) our devices, let's found out which of the devices match
                List <KeyValuePair <string, string> > matchingDevices = new List <KeyValuePair <string, string> >();
                foreach (KeyValuePair <string, string> device in devices)
                {
                    if (matchingHardwareIDs.Contains(device.Key))
                    {
                        matchingDevices.Add(device);
                    }
                }
                Console.WriteLine();
                Console.WriteLine("Looking for matching device drivers in directory '{0}':", pnpDriverDirectory.Path);
                hardwareID = UISelectMatchingHardwareID(matchingDevices);
            }
            else
            {
                hardwareID = UISelectMatchingHardwareID(pnpDriverDirectory, installation.ArchitectureIdentifier, installation.MinorOSVersion, installation.ProductType);
            }

            return(hardwareID);
        }
Ejemplo n.º 6
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);
            }
        }
Ejemplo n.º 7
0
 public PNPDriverGUIModeIntegrator(PNPDriverDirectory driverDirectory, WindowsInstallation installation, string hardwareID)
     : base(driverDirectory, installation.ArchitectureIdentifier, installation.MinorOSVersion, installation.ProductType, hardwareID)
 {
     m_installation = installation;
 }
Ejemplo n.º 8
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);
        }