Example #1
0
        public static bool GetInfSection(string infFile, string section, out Dictionary <string, List <string> > OemInfEntities)
        {
            uint ErrorLine = 0;

            OemInfEntities = new Dictionary <string, List <string> >();
            IntPtr infHandle = SetupOpenInfFile(infFile, null, INF_STYLE_OLDNT | INF_STYLE_WIN4, out ErrorLine);
            int    iCode     = Marshal.GetLastWin32Error();

            if (infHandle.ToInt64() != INVALID_HANDLE_VALUE)
            {
                INFCONTEXT Context = new INFCONTEXT();
                if (SetupFindFirstLine(infHandle, section, null, ref Context) == true)
                {
                    do
                    {
                        StringBuilder sb         = new StringBuilder(1024);
                        string        valueName  = String.Empty;
                        List <string> valueText  = new List <string>();
                        int           fieldIndex = 0;
                        int           requiredSize;

                        while (SetupGetStringField(ref Context, fieldIndex++, sb, sb.Capacity, out requiredSize))
                        {
                            if (fieldIndex == 1)
                            {
                                valueName = sb.ToString(0, requiredSize - 1);
                            }
                            else
                            {
                                valueText.Add(sb.ToString(0, requiredSize - 1));
                            }
                        }
                        try
                        {
                            OemInfEntities.Add(valueName, valueText);
                        }
                        catch
                        {
                            Console.WriteLine("Skipping duplicate {0}", valueName);
                        }
                    } while (SetupFindNextLine(ref Context, out Context));
                }
                else
                {
                    Console.WriteLine("Can't find {0} section.", section);
                }
                SetupCloseInfFile(infHandle);
            }
            else
            {
                Console.WriteLine("Failed to open INF file. Error code - {0}.", iCode);
                if (ErrorLine != 0)
                {
                    Console.WriteLine("Failure line - {0}.", ErrorLine);
                }
            }
            return(false);
        }
Example #2
0
        public static bool GetInfSection(string InfFile, string Section,
                                         out Dictionary <string, List <string> > OemInfEntities)
        {
            OemInfEntities = new Dictionary <string, List <string> >(StringComparer.InvariantCultureIgnoreCase);
            var infHandle = SetupOpenInfFile(InfFile, null, INF_STYLE_OLDNT | INF_STYLE_WIN4, out var errorLine);
            var iCode     = Marshal.GetLastWin32Error();

            if (infHandle.ToInt64() != INVALID_HANDLE_VALUE)
            {
                var context = new INFCONTEXT();
                if (SetupFindFirstLine(infHandle, Section, null, ref context))
                {
                    do
                    {
                        var sb         = new StringBuilder(1024);
                        var valueName  = string.Empty;
                        var valueText  = new List <string>();
                        var fieldIndex = 0;

                        while (SetupGetStringField(ref context, fieldIndex++, sb, sb.Capacity, out var requiredSize))
                        {
                            if (fieldIndex == 1)
                            {
                                valueName = sb.ToString(0, requiredSize - 1);
                            }
                            else
                            {
                                valueText.Add(sb.ToString(0, requiredSize - 1));
                            }
                        }
                        try
                        {
                            OemInfEntities.Add(valueName, valueText);
                        }
                        catch
                        {
                            Console.WriteLine("Skipping duplicate {0}", valueName);
                        }
                    } while (SetupFindNextLine(ref context, out context));
                }
                else
                {
                    Console.WriteLine("Can't find {0} section.", Section);
                }

                SetupCloseInfFile(infHandle);
            }
            else
            {
                Console.WriteLine("Failed to open INF file. Error code - {0}.", iCode);
                if (errorLine != 0)
                {
                    Console.WriteLine("Failure line - {0}.", errorLine);
                }
            }

            return(false);
        }
Example #3
0
        public static bool GetInfSection(string infFile, string section, out Dictionary<string, List<string>> OemInfEntities)
        {
            uint ErrorLine = 0;
            OemInfEntities=new Dictionary<string, List<string>>();
            IntPtr infHandle = SetupOpenInfFile(infFile, null, INF_STYLE_OLDNT | INF_STYLE_WIN4, out ErrorLine);
            int iCode = Marshal.GetLastWin32Error();
            if (infHandle.ToInt64() != INVALID_HANDLE_VALUE)
            {
                INFCONTEXT Context = new INFCONTEXT();
                if (SetupFindFirstLine(infHandle, section, null, ref Context) == true)
                {

                    do
                    {
                        StringBuilder sb = new StringBuilder(1024);
                        string valueName = String.Empty;
                        List<string> valueText=new List<string>();
                        int fieldIndex = 0;
                        int requiredSize;

                        while (SetupGetStringField(ref Context, fieldIndex++, sb, sb.Capacity, out requiredSize))
                        {
                            if (fieldIndex==1)
                                valueName = sb.ToString(0, requiredSize-1);
                            else
                                valueText.Add(sb.ToString(0, requiredSize-1));
                        }
                        try
                        {
                            OemInfEntities.Add(valueName, valueText);
                        }
                        catch
                        {
                            Console.WriteLine("Skipping duplicate {0}", valueName);
                        }

                    } while (SetupFindNextLine(ref Context, out Context));
                }
                else
                {
                    Console.WriteLine("Can't find {0} section.",section);
                }
                SetupCloseInfFile(infHandle);
            }
            else
            {
                Console.WriteLine("Failed to open INF file. Error code - {0}.", iCode);
                if (ErrorLine != 0)
                {
                    Console.WriteLine("Failure line - {0}.", ErrorLine);
                }
            }
            return false;
        }
Example #4
0
 public static extern bool SetupGetStringField(ref INFCONTEXT Context, Int32 FieldIndex, [MarshalAs(UnmanagedType.LPTStr)] StringBuilder ReturnBuffer,
                                               Int32 ReturnBufferSize, out Int32 RequiredSize);
Example #5
0
 public static extern bool SetupFindNextLine(ref INFCONTEXT ContextIn, out INFCONTEXT ContextOut);
Example #6
0
 public static extern bool SetupFindFirstLine(IntPtr InfHandle, [MarshalAs(UnmanagedType.LPTStr)] string Section,
                                              [MarshalAs(UnmanagedType.LPTStr)] string Key, ref INFCONTEXT Context);
Example #7
0
 public static extern bool SetupGetStringField(ref INFCONTEXT Context, Int32 FieldIndex, [MarshalAs(UnmanagedType.LPTStr)] StringBuilder ReturnBuffer,
     Int32 ReturnBufferSize, out Int32 RequiredSize);
Example #8
0
 public static extern bool SetupFindNextLine(ref INFCONTEXT ContextIn, out INFCONTEXT ContextOut);
Example #9
0
 public static extern bool SetupFindFirstLine(IntPtr InfHandle, [MarshalAs(UnmanagedType.LPTStr)] string Section,
     [MarshalAs(UnmanagedType.LPTStr)] string Key, ref INFCONTEXT Context);
Example #10
0
 public static extern bool SetupGetStringField(ref INFCONTEXT Context, int FieldIndex,
                                               [MarshalAs(UnmanagedType.LPTStr)] string ReturnBuffer,
                                               int ReturnBufferSize, out int RequiredSize);