コード例 #1
0
        // In-box device drivers = drivers that are shipped with Windows
        public static void DisableInBoxDeviceDrivers(string setupDirectory, string architectureIdentifier, int minorOSVersion, int productType, string hardwareID)
        {
            Console.WriteLine();
            Console.WriteLine("Looking for drivers for your device (" + hardwareID + ") in Windows setup directory (to disable them):");
            var filePaths = Directory.GetFiles(setupDirectory, "*.in_");

            foreach (var filePath in filePaths)
            {
                var packedFileName   = FileSystemUtils.GetNameFromPath(filePath);
                var unpackedFileName = packedFileName.Substring(0, packedFileName.Length - 1) + "F";                 // the filename inside the archive ends with .INF and not with .IN_

                var cabInfo = new CabInfo(filePath);

                ArchiveFileInfo fileInfo = null;
                try
                {
                    // some files do not contain an inf file
                    // for instance, netmon.in_ contains netmon.ini
                    fileInfo = cabInfo.GetFile(unpackedFileName);
                }
                catch (CabException ex)
                {
                    // file is invalid / unsupported
                    Console.WriteLine("Cannot examine file '{0}': {1}", packedFileName, ex.Message);
                }

                if (fileInfo != null)
                {
                    var driverInf = new PNPDriverINFFile(unpackedFileName);
                    try
                    {
                        driverInf.ReadPackedFromDirectory(setupDirectory);
                    }
                    catch (CabException ex)
                    {
                        // the archive is a cab and it contains the file we are looking for, but the file is corrupted
                        Console.WriteLine("Cannot unpack file '{0}': {1}", driverInf.PackedFileName, ex.Message);
                        continue;
                    }

                    // Windows will pick up it's own signed drivers even if the added driver also match the SUBSYS,
                    // so we have to disable in-box drivers regardless of the presence of &SUBSYS
                    var found = driverInf.DisableMatchingHardwareID(hardwareID, architectureIdentifier, minorOSVersion, productType);

                    if (found)
                    {
                        Console.WriteLine("Device driver for '{0}' found in file '{1}'.", hardwareID, packedFileName);
                        driverInf.SavePackedToDirectory(setupDirectory);
                    }
                }
            }
            Console.WriteLine("Finished looking for drivers for your device in Windows setup directory.");
        }
コード例 #2
0
        public void UseMultiprocessorHal()
        {
            if (m_multiprocessorHalEnabled)
            {
                return;
            }
            if (m_installation.ArchitectureIdentifier != "x86")
            {
                // amd64 and presumably ia64 use a single HAL for both uni and multiprocessor kernel)
                return;
            }

            Console.WriteLine();
            Console.WriteLine("By default, text-mode setup will use a multiprocessor OS kernel");
            Console.WriteLine("with a uniprocessor HAL. This configuration cannot support network adapters");
            Console.WriteLine("(setup will hang).");
            Console.WriteLine("IntegrateDrv will try to enable multiprocessor HAL:");

            if (m_installation.IsTargetContainsTemporaryInstallation)
            {
                if (System.IO.File.Exists(m_installation.BootDirectory + "halmacpi.dl_"))
                {
                    m_installation.TextSetupInf.UseMultiprocessorHal();
                    m_multiprocessorHalEnabled = true;
                    Console.WriteLine("Multiprocessor HAL has been enabled.");
                    return;
                }
                else if (System.IO.File.Exists(m_installation.SetupDirectory + "halmacpi.dl_"))
                {
                    ProgramUtils.CopyCriticalFile(m_installation.SetupDirectory + "halmacpi.dl_", m_installation.BootDirectory + "halmacpi.dl_");
                    m_installation.TextSetupInf.UseMultiprocessorHal();
                    Console.WriteLine("halmacpi.dl_ was copied from local source directory.");
                    m_multiprocessorHalEnabled = true;
                    Console.WriteLine("Multiprocessor HAL has been enabled.");
                }
                else
                {
                    int index;
                    for (index = 3; index >= 1; index--)
                    {
                        string spFilename = string.Format("sp{0}.cab", index);
                        if (File.Exists(m_installation.SetupDirectory + spFilename))
                        {
                            CabInfo cabInfo = new CabInfo(m_installation.SetupDirectory + spFilename);
                            if (cabInfo.GetFile("halmacpi.dll") != null)
                            {
                                cabInfo.UnpackFile("halmacpi.dll", m_installation.BootDirectory + "halmacpi.dll");
                                // setup is expecting a packed "halmacpi.dl_"
                                //cabInfo = new CabInfo(m_installation.BootDirectory + "halmacpi.dl_");
                                //Dictionary<string, string> files = new Dictionary<string, string>();
                                //files.Add("halmacpi.dll", "halmacpi.dll");
                                //cabInfo.PackFileSet(m_installation.BootDirectory, files);
                                Console.WriteLine("halmacpi.dl_ was extracted from local source directory.");
                                m_installation.TextSetupInf.UseMultiprocessorHal();
                                m_multiprocessorHalEnabled = true;
                                Console.WriteLine("Multiprocessor HAL has been enabled.");
                            }
                            break;
                        }
                    }

                    if (index == 0)
                    {
                        Console.WriteLine("Warning: could not locate halmacpi.dll, multiprocessor HAL has not been enabled!");
                    }
                }
            }
            else // integration to installation media
            {
                m_installation.TextSetupInf.UseMultiprocessorHal();
                m_installation.DosNetInf.InstructSetupToCopyFileFromSetupDirectoryToBootDirectory("halmacpi.dl_");
                m_multiprocessorHalEnabled = true;
                Console.WriteLine("Multiprocessor HAL has been enabled.");
                return;
            }
        }