示例#1
0
        protected void ProcessCoInstallersSection(PNPDriverINFFile pnpDriverInf, string installSectionName)
        {
            string matchingInstallSectionName = pnpDriverInf.GetMatchingInstallSectionName(installSectionName, m_architectureIdentifier, m_minorOSVersion);

            if (matchingInstallSectionName == String.Empty)
            {
                return;
            }
            string        matchingCoInstallersSectionName = matchingInstallSectionName + ".CoInstallers";
            List <string> coinstallersSection             = pnpDriverInf.GetSection(matchingCoInstallersSectionName);

            foreach (string line in coinstallersSection)
            {
                KeyValuePair <string, List <string> > keyAndValues = INIFile.GetKeyAndValues(line);
                switch (keyAndValues.Key)
                {
                case "CopyFiles":
                    if (keyAndValues.Value[0].StartsWith("@"))
                    {
                        ProcessCopyFileDirective(pnpDriverInf, keyAndValues.Value[0].Substring(1));
                    }
                    else
                    {
                        foreach (string copyFilesSectionName in keyAndValues.Value)
                        {
                            ProcessCopyFilesSection(pnpDriverInf, copyFilesSectionName);
                        }
                    }
                    break;

                default:
                    break;
                }
            }
        }
示例#2
0
        /// <param name="relativeRoot">
        /// The location where HKR entried will be stored, relative to 'SYSTEM\CurrentControlSet\' (or ControlSet001 for that matter)
        /// </param>
        private void ProcessAddRegSection(PNPDriverINFFile pnpDriverInf, string sectionName, string relativeRoot)
        {
            List <string> section = pnpDriverInf.GetSection(sectionName);

            foreach (string line in section)
            {
                List <string> values            = INIFile.GetCommaSeparatedValues(line);
                string        hiveName          = values[0];
                string        subKeyName        = INIFile.Unquote(values[1]);
                string        valueName         = INIFile.TryGetValue(values, 2);
                string        valueType         = INIFile.TryGetValue(values, 3);;
                string        valueDataUnparsed = String.Empty;
                if (values.Count > 3)
                {
                    valueDataUnparsed = StringUtils.Join(values.GetRange(4, values.Count - 4), ","); // byte-list is separated using commmas
                }

                valueName = INIFile.Unquote(valueName);
                valueType = pnpDriverInf.ExpandToken(valueType);
                int    valueTypeFlags = PNPDriverINFFile.ConvertFromIntStringOrHexString(valueType);
                string valueTypeHexString;
                if (!valueType.StartsWith("0x"))
                {
                    valueTypeHexString = "0x" + valueTypeFlags.ToString("X8"); // we want value type in 8 digit hex string.
                }
                else
                {
                    valueTypeHexString = valueType;
                }
                RegistryValueKind valueKind = PNPDriverINFFile.GetRegistryValueKind(valueTypeFlags);
                if (valueKind == RegistryValueKind.String)
                {
                    valueDataUnparsed = pnpDriverInf.ExpandToken(valueDataUnparsed);
                }
                object valueData = HiveINIFile.ParseValueDataString(valueDataUnparsed, valueKind);

                if (hiveName == "HKR")
                {
                    string cssKeyName = relativeRoot;
                    if (subKeyName != String.Empty)
                    {
                        cssKeyName = cssKeyName + @"\" + subKeyName;
                    }
                    // Note that software key will stick from text-mode:
                    SetCurrentControlSetRegistryKey(cssKeyName, valueName, valueKind, valueData);
                }
                else if (hiveName == "HKLM" && subKeyName.StartsWith(@"SYSTEM\CurrentControlSet\", StringComparison.InvariantCultureIgnoreCase))
                {
                    string cssKeyName = subKeyName.Substring(@"SYSTEM\CurrentControlSet\".Length);

                    SetCurrentControlSetRegistryKey(cssKeyName, valueName, valueKind, valueData);
                }
                else
                {
                    //Console.WriteLine("Warning: unsupported registry path: " + hiveName + @"\" + subKeyName);
                }
            }
        }
示例#3
0
        private void ProcessCopyFilesSection(PNPDriverINFFile pnpDriverInf, string sectionName)
        {
            List <string> section = pnpDriverInf.GetSection(sectionName);

            foreach (string line in section)
            {
                List <string> values = INIFile.GetCommaSeparatedValues(line);
                string        destinationFileName = values[0];
                string        sourceFileName      = INIFile.TryGetValue(values, 1);
                if (sourceFileName == String.Empty)
                {
                    sourceFileName = destinationFileName;
                }
                ProcessCopyFileDirective(pnpDriverInf, sourceFileName, destinationFileName);
            }
        }
示例#4
0
        private void ProcessEventLogInstallSection(PNPDriverINFFile pnpDriverInf, string sectionName, string eventLogType, string eventName)
        {
            List <string> installSection = pnpDriverInf.GetSection(sectionName);

            string relativeRoot = @"Services\EventLog\" + eventLogType + @"\" + eventName;

            foreach (string line in installSection)
            {
                KeyValuePair <string, List <string> > keyAndValues = INIFile.GetKeyAndValues(line);
                switch (keyAndValues.Key)
                {
                case "AddReg":
                    foreach (string registrySectionName in keyAndValues.Value)
                    {
                        ProcessAddRegSection(pnpDriverInf, registrySectionName, relativeRoot);
                    }
                    break;

                default:
                    break;
                }
            }
        }
示例#5
0
        private void ProcessServiceInstallSection(PNPDriverINFFile pnpDriverInf, string sectionName, string serviceName)
        {
            Console.WriteLine("Registering service '" + serviceName + "'");
            List <string> serviceInstallSection = pnpDriverInf.GetSection(sectionName);

            string displayName        = String.Empty;
            string serviceBinary      = String.Empty;
            string serviceTypeString  = String.Empty;
            string errorControlString = String.Empty;
            string loadOrderGroup     = String.Empty;

            //string guiModeRelativeRoot = @"Services\" + serviceName;
            foreach (string line in serviceInstallSection)
            {
                KeyValuePair <string, List <string> > keyAndValues = INIFile.GetKeyAndValues(line);
                switch (keyAndValues.Key)
                {
                case "AddReg":
                    // http://msdn.microsoft.com/en-us/library/ff546326%28v=vs.85%29.aspx
                    // AddReg will always come after ServiceBinaryServiceBinary

                    string relativeRoot = @"Services\" + serviceName;

                    foreach (string registrySectionName in keyAndValues.Value)
                    {
                        ProcessAddRegSection(pnpDriverInf, registrySectionName, relativeRoot);
                    }
                    break;

                case "DisplayName":
                    displayName = INIFile.TryGetValue(keyAndValues.Value, 0);
                    break;

                case "ServiceBinary":
                    serviceBinary = INIFile.TryGetValue(keyAndValues.Value, 0);
                    break;

                case "ServiceType":
                    serviceTypeString = INIFile.TryGetValue(keyAndValues.Value, 0);
                    break;

                case "ErrorControl":
                    errorControlString = INIFile.TryGetValue(keyAndValues.Value, 0);
                    break;

                case "LoadOrderGroup":
                    loadOrderGroup = INIFile.TryGetValue(keyAndValues.Value, 0);
                    break;

                default:
                    break;
                }
            }

            displayName = pnpDriverInf.ExpandToken(displayName);
            displayName = INIFile.Unquote(displayName);

            string fileName  = serviceBinary.Replace(@"%12%\", String.Empty);
            string imagePath = pnpDriverInf.ExpandDirID(serviceBinary);

            int serviceType  = PNPDriverINFFile.ConvertFromIntStringOrHexString(serviceTypeString);
            int errorControl = PNPDriverINFFile.ConvertFromIntStringOrHexString(errorControlString);

            string deviceDescription = pnpDriverInf.GetDeviceDescription(m_hardwareID, m_architectureIdentifier, m_minorOSVersion, m_productType);

            DeviceService deviceService;

            if (pnpDriverInf.IsNetworkAdapter)
            {
                // this is a nic, we are binding TCP/IP to it
                // we need a unique NetCfgInstanceID that will be used with Tcpip service and the nic's class
                string netCfgInstanceID = "{" + Guid.NewGuid().ToString().ToUpper() + "}";
                deviceService = new NetworkDeviceService(deviceDescription, serviceName, displayName, loadOrderGroup, serviceType, errorControl, fileName, imagePath, netCfgInstanceID);
                m_deviceServices.Add(deviceService);
            }
            else
            {
                deviceService = new DeviceService(deviceDescription, serviceName, displayName, loadOrderGroup, serviceType, errorControl, fileName, imagePath);
                m_deviceServices.Add(deviceService);
            }
        }