Author: fireball Date: Thu Nov 12 13:35:01 2009 New Revision: 44116
URL: http://svn.reactos.org/svn/reactos?rev=44116&view=rev Log: [Unused ReactOS setup] - Move duplicate code from LoadSetupData to a separate function - Fix a bug on line 1054 of the original file: SetupData.LangCount should be SetupData.KbLayoutCount (copy-paste mistake). This would have probably gone unnoticed if SetupData.LangCount > SetupData.KbLayoutCount due to other end of section checking. - Based on a patch from bug 4933.
Modified: trunk/reactos/base/setup/reactos/reactos.c
Modified: trunk/reactos/base/setup/reactos/reactos.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/setup/reactos/reactos.... ============================================================================== --- trunk/reactos/base/setup/reactos/reactos.c [iso-8859-1] (original) +++ trunk/reactos/base/setup/reactos/reactos.c [iso-8859-1] Thu Nov 12 13:35:01 2009 @@ -103,6 +103,8 @@ HINSTANCE hInstance; BOOL isUnattend;
+LONG LoadGenentry(HINF hinf,PCTSTR name,PGENENTRY gen,PINFCONTEXT context); + /* FUNCTIONS ****************************************************************/
static VOID @@ -995,13 +997,12 @@ if (hTxtsetupSif != INVALID_HANDLE_VALUE) { // get language list - Count = SetupGetLineCount(hTxtsetupSif, _T("Language")); - if (Count > 0) - { - SetupData.pLanguages = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(LANG) * Count); + SetupData.LangCount = SetupGetLineCount(hTxtsetupSif, _T("Language")); + if (SetupData.LangCount > 0) + { + SetupData.pLanguages = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(LANG) * SetupData.LangCount); if (SetupData.pLanguages != NULL) { - SetupData.LangCount = Count; Count = 0; if (SetupFindFirstLine(hTxtsetupSif, _T("Language"), NULL, &InfContext)) { @@ -1020,19 +1021,18 @@ &LineLength); ++Count; } - while (SetupFindNextLine(&InfContext, &InfContext) && Count < SetupData.LangCount); + while (SetupFindNextLine(&InfContext, &InfContext) && Count < SetupData.LangCount); } } }
// get keyboard layout list - Count = SetupGetLineCount(hTxtsetupSif, _T("KeyboardLayout")); - if (Count > 0) - { - SetupData.pKbLayouts = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(KBLAYOUT) * Count); + SetupData.KbLayoutCount = SetupGetLineCount(hTxtsetupSif, _T("KeyboardLayout")); + if (SetupData.KbLayoutCount > 0) + { + SetupData.pKbLayouts = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(KBLAYOUT) * SetupData.KbLayoutCount); if (SetupData.pKbLayouts != NULL) { - SetupData.KbLayoutCount = Count; Count = 0; if (SetupFindFirstLine(hTxtsetupSif, _T("KeyboardLayout"), NULL, &InfContext)) { @@ -1051,7 +1051,7 @@ &LineLength); ++Count; } - while (SetupFindNextLine(&InfContext, &InfContext) && Count < SetupData.LangCount); + while (SetupFindNextLine(&InfContext, &InfContext) && Count < SetupData.KbLayoutCount); } } } @@ -1084,99 +1084,13 @@ }
// get computers list - Count = SetupGetLineCount(hTxtsetupSif, _T("Computer")); - if (Count > 0) - { - SetupData.pComputers = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(GENENTRY) * Count); - if (SetupData.pComputers != NULL) - { - SetupData.CompCount = Count; - Count = 0; - if (SetupFindFirstLine(hTxtsetupSif, _T("Computer"), NULL, &InfContext)) - { - do - { - SetupGetStringField(&InfContext, - 0, - SetupData.pComputers[Count].Id, - sizeof(SetupData.pComputers[Count].Id) / sizeof(TCHAR), - &LineLength); - - SetupGetStringField(&InfContext, - 1, - SetupData.pComputers[Count].Value, - sizeof(SetupData.pComputers[Count].Value) / sizeof(TCHAR), - &LineLength); - ++Count; - } - while (SetupFindNextLine(&InfContext, &InfContext) && Count < SetupData.CompCount); - } - } - } + SetupData.CompCount = LoadGenentry(hTxtsetupSif,_T("Computer"),SetupData.pComputers,&InfContext);
// get display list - Count = SetupGetLineCount(hTxtsetupSif, _T("Display")); - if (Count > 0) - { - SetupData.pDisplays = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(GENENTRY) * Count); - if (SetupData.pDisplays != NULL) - { - SetupData.DispCount = Count; - Count = 0; - - if (SetupFindFirstLine(hTxtsetupSif, _T("Display"), NULL, &InfContext)) - { - do - { - SetupGetStringField(&InfContext, - 0, - SetupData.pDisplays[Count].Id, - sizeof(SetupData.pDisplays[Count].Id) / sizeof(TCHAR), - &LineLength); - - SetupGetStringField(&InfContext, - 1, - SetupData.pDisplays[Count].Value, - sizeof(SetupData.pDisplays[Count].Value) / sizeof(TCHAR), - &LineLength); - ++Count; - } - while (SetupFindNextLine(&InfContext, &InfContext) && Count < SetupData.DispCount); - } - } - } + SetupData.DispCount = LoadGenentry(hTxtsetupSif,_T("Display"),SetupData.pDisplays,&InfContext);
// get keyboard list - Count = SetupGetLineCount(hTxtsetupSif, _T("Keyboard")); - if (Count > 0) - { - SetupData.pKeyboards = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(GENENTRY) * Count); - if (SetupData.pKeyboards != NULL) - { - SetupData.KeybCount = Count; - Count = 0; - - if (SetupFindFirstLine(hTxtsetupSif, _T("Keyboard"), NULL, &InfContext)) - { - do - { - SetupGetStringField(&InfContext, - 0, - SetupData.pKeyboards[Count].Id, - sizeof(SetupData.pKeyboards[Count].Id) / sizeof(TCHAR), - &LineLength); - - SetupGetStringField(&InfContext, - 1, - SetupData.pKeyboards[Count].Value, - sizeof(SetupData.pKeyboards[Count].Value) / sizeof(TCHAR), - &LineLength); - ++Count; - } - while (SetupFindNextLine(&InfContext, &InfContext) && Count < SetupData.KeybCount); - } - } - } + SetupData.KeybCount = LoadGenentry(hTxtsetupSif, _T("Keyboard"),SetupData.pKeyboards,&InfContext);
// get install directory if (SetupFindFirstLine(hTxtsetupSif, _T("SetupData"), _T("DefaultPath"), &InfContext)) @@ -1189,6 +1103,42 @@ } SetupCloseInfFile(hTxtsetupSif); } +} + +LONG LoadGenentry(HINF hinf,PCTSTR name,PGENENTRY gen,PINFCONTEXT context) +{ + LONG TotalCount; + + TotalCount = SetupGetLineCount(hinf, name); + if (TotalCount > 0) + { + gen = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(GENENTRY) * TotalCount); + if (gen != NULL) + { + if (SetupFindFirstLine(hinf, name, NULL, context)) + { + LONG Count = 0; + do + { + SetupGetStringField(context, + 0, + gen[Count].Id, + sizeof(gen[Count].Id) / sizeof(TCHAR), + NULL); + + SetupGetStringField(context, + 1, + gen[Count].Value, + sizeof(gen[Count].Value) / sizeof(TCHAR), + NULL); + Count++; + } + while (SetupFindNextLine(context, context) && Count < TotalCount); + } + } + } + + return TotalCount; }
BOOL isUnattendSetup()