static BOOL InstallSysSetupInfDevices(VOID) { INFCONTEXT InfContext; WCHAR szLineBuffer[256]; DWORD dwLineLength; if (!SetupFindFirstLineW(hSysSetupInf, L"DeviceInfsToInstall", NULL, &InfContext)) { return FALSE; } do { if (!SetupGetStringFieldW(&InfContext, 0, szLineBuffer, sizeof(szLineBuffer)/sizeof(szLineBuffer[0]), &dwLineLength)) { return FALSE; } if (!SetupDiInstallClassW(NULL, szLineBuffer, DI_QUIETINSTALL, NULL)) { return FALSE; } } while (SetupFindNextLine(&InfContext, &InfContext)); return TRUE; }
static VOID InitFontSizeList(HWND hWnd) { HINF hInf; HKEY hKey; HWND hFontSize; INFCONTEXT Context; int i, ci = 0; DWORD dwSize, dwValue, dwType; hFontSize = GetDlgItem(hWnd, IDC_FONTSIZE_COMBO); hInf = SetupOpenInfFile(_T("font.inf"), NULL, INF_STYLE_WIN4, NULL); if (hInf != INVALID_HANDLE_VALUE) { if (SetupFindFirstLine(hInf, _T("Font Sizes"), NULL, &Context)) { if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\FontDPI"), 0, KEY_READ, &hKey) == ERROR_SUCCESS) for (;;) { TCHAR Buffer[LINE_LEN]; TCHAR Desc[LINE_LEN]; if (SetupGetStringField(&Context, 0, Buffer, sizeof(Buffer) / sizeof(TCHAR), NULL) && SetupGetIntField(&Context, 1, &ci)) { _stprintf(Desc, _T("%s (%d DPI)"), Buffer, ci); i = SendMessage(hFontSize, CB_ADDSTRING, 0, (LPARAM)Desc); if (i != CB_ERR) SendMessage(hFontSize, CB_SETITEMDATA, (WPARAM)i, (LPARAM)ci); dwSize = MAX_PATH; dwType = REG_DWORD; if (RegQueryValueEx(hKey, _T("LogPixels"), NULL, &dwType, (LPBYTE)&dwValue, &dwSize) == ERROR_SUCCESS) { if ((int)dwValue == ci) { SendMessage(hFontSize, CB_SETCURSEL, (WPARAM)i, 0); SetWindowText(GetDlgItem(hWnd, IDC_FONTSIZE_CUSTOM), Desc); } } } if (!SetupFindNextLine(&Context, &Context)) { RegCloseKey(hKey); break; } } } } SetupCloseInfFile(hInf); }
BOOL RegisterTypeLibraries (HINF hinf, LPCWSTR szSection) { INFCONTEXT InfContext; BOOL res; WCHAR szName[MAX_PATH]; WCHAR szPath[MAX_PATH]; INT csidl; LPWSTR p; HMODULE hmod; HRESULT hret; /* Begin iterating the entries in the inf section */ res = SetupFindFirstLine(hinf, szSection, NULL, &InfContext); if (!res) return FALSE; do { /* Get the name of the current type library */ if (!SetupGetStringFieldW(&InfContext, 1, szName, MAX_PATH, NULL)) { FatalError("SetupGetStringFieldW failed\n"); continue; } if (!SetupGetIntField(&InfContext, 2, &csidl)) csidl = CSIDL_SYSTEM; hret = SHGetFolderPathW(NULL, csidl, NULL, 0, szPath); if (FAILED(hret)) { FatalError("SHGetFolderPathW failed hret=0x%d\n", hret); continue; } p = PathAddBackslash(szPath); _tcscpy(p, szName); hmod = LoadLibraryW(szName); if (hmod == NULL) { FatalError("LoadLibraryW failed\n"); continue; } __wine_register_resources(hmod); }while (SetupFindNextLine(&InfContext, &InfContext)); return TRUE; }
PGENERIC_LIST CreateKeyboardDriverList( HINF InfFile) { CHAR Buffer[128]; PGENERIC_LIST List; INFCONTEXT Context; PWCHAR KeyName; PWCHAR KeyValue; PWCHAR UserData; List = CreateGenericList(); if (List == NULL) return NULL; if (!SetupFindFirstLineW (InfFile, L"Keyboard", NULL, &Context)) { DestroyGenericList(List, FALSE); return NULL; } do { if (!INF_GetData (&Context, &KeyName, &KeyValue)) { /* FIXME: Handle error! */ DPRINT("INF_GetData() failed\n"); break; } UserData = (WCHAR*)RtlAllocateHeap(ProcessHeap, 0, (wcslen(KeyName) + 1) * sizeof(WCHAR)); if (UserData == NULL) { /* FIXME: Handle error! */ } wcscpy(UserData, KeyName); sprintf(Buffer, "%S", KeyValue); AppendGenericListEntry(List, Buffer, UserData, FALSE); } while (SetupFindNextLine(&Context, &Context)); return List; }
/* Advanced INF callbacks */ static HRESULT del_dirs_callback(HINF hinf, PCWSTR field, const void *arg) { INFCONTEXT context; HRESULT hr = S_OK; DWORD size; BOOL ok = SetupFindFirstLineW(hinf, field, NULL, &context); for (; ok; ok = SetupFindNextLine(&context, &context)) { WCHAR directory[MAX_INF_STRING_LENGTH]; if (!SetupGetLineTextW(&context, NULL, NULL, NULL, directory, MAX_INF_STRING_LENGTH, &size)) continue; if (DelNodeW(directory, ADN_DEL_IF_EMPTY) != S_OK) hr = E_FAIL; } return hr; }
static BOOL CreateShortcuts(HINF hinf, LPCWSTR szSection) { INFCONTEXT Context; WCHAR szPath[MAX_PATH]; WCHAR szFolder[MAX_PATH]; WCHAR szFolderSection[MAX_PATH]; INT csidl; CoInitialize(NULL); if (!SetupFindFirstLine(hinf, szSection, NULL, &Context)) return FALSE; do { if (SetupGetFieldCount(&Context) < 2) continue; if (!SetupGetStringFieldW(&Context, 0, szFolderSection, MAX_PATH, NULL)) continue; if (!SetupGetIntField(&Context, 1, &csidl)) continue; if (!SetupGetStringFieldW(&Context, 2, szFolder, MAX_PATH, NULL)) continue; if (FAILED(SHGetFolderPathAndSubDirW(NULL, csidl|CSIDL_FLAG_CREATE, (HANDLE)-1, SHGFP_TYPE_DEFAULT, szFolder, szPath))) continue; CreateShortcutsFromSection(hinf, szFolderSection, szPath); }while (SetupFindNextLine(&Context, &Context)); CoUninitialize(); return TRUE; }
static HRESULT run_setup_commands_callback(HINF hinf, PCWSTR field, const void *arg) { const ADVInfo *info = (const ADVInfo *)arg; INFCONTEXT context; HRESULT hr = S_OK; DWORD size; BOOL ok = SetupFindFirstLineW(hinf, field, NULL, &context); for (; ok; ok = SetupFindNextLine(&context, &context)) { WCHAR buffer[MAX_INF_STRING_LENGTH]; if (!SetupGetLineTextW(&context, NULL, NULL, NULL, buffer, MAX_INF_STRING_LENGTH, &size)) continue; if (launch_exe(buffer, info->working_dir, NULL) != S_OK) hr = E_FAIL; } return hr; }
static HRESULT register_ocxs_callback(HINF hinf, PCWSTR field, const void *arg) { HMODULE hm; INFCONTEXT context; HRESULT hr = S_OK; BOOL ok = SetupFindFirstLineW(hinf, field, NULL, &context); for (; ok; ok = SetupFindNextLine(&context, &context)) { WCHAR buffer[MAX_INF_STRING_LENGTH]; /* get OCX filename */ if (!SetupGetStringFieldW(&context, 1, buffer, sizeof(buffer) / sizeof(WCHAR), NULL)) continue; hm = LoadLibraryExW(buffer, NULL, LOAD_WITH_ALTERED_SEARCH_PATH); if (hm) { if (do_ocx_reg(hm, TRUE, NULL, NULL) != S_OK) hr = E_FAIL; FreeLibrary(hm); } else hr = E_FAIL; if (FAILED(hr)) { /* FIXME: display a message box */ break; } } return hr; }
static BOOL CreateShortcutsFromSection(HINF hinf, LPWSTR pszSection, LPCWSTR pszFolder) { INFCONTEXT Context; WCHAR szCommand[MAX_PATH]; WCHAR szName[MAX_PATH]; WCHAR szDescription[MAX_PATH]; INT iIconNr; if (!SetupFindFirstLine(hinf, pszSection, NULL, &Context)) return FALSE; do { if (SetupGetFieldCount(&Context) < 4) continue; if (!SetupGetStringFieldW(&Context, 1, szCommand, MAX_PATH, NULL)) continue; if (!SetupGetStringFieldW(&Context, 2, szName, MAX_PATH, NULL)) continue; if (!SetupGetStringFieldW(&Context, 3, szDescription, MAX_PATH, NULL)) continue; if (!SetupGetIntField(&Context, 4, &iIconNr)) continue; _tcscat(szName, L".lnk"); CreateShortcut(pszFolder, szName, szCommand, szDescription, iIconNr); }while (SetupFindNextLine(&Context, &Context)); return TRUE; }
static VOID InstallPrivileges(VOID) { HINF hSecurityInf = INVALID_HANDLE_VALUE; LSA_OBJECT_ATTRIBUTES ObjectAttributes; WCHAR szPrivilegeString[256]; WCHAR szSidString[256]; INFCONTEXT InfContext; DWORD i; PRIVILEGE_SET PrivilegeSet; PSID AccountSid; NTSTATUS Status; LSA_HANDLE PolicyHandle = NULL; LSA_HANDLE AccountHandle; DPRINT("InstallPrivileges()\n"); hSecurityInf = SetupOpenInfFileW(L"defltws.inf", //szNameBuffer, NULL, INF_STYLE_WIN4, NULL); if (hSecurityInf == INVALID_HANDLE_VALUE) { DPRINT1("SetupOpenInfFileW failed\n"); return; } memset(&ObjectAttributes, 0, sizeof(LSA_OBJECT_ATTRIBUTES)); Status = LsaOpenPolicy(NULL, &ObjectAttributes, POLICY_CREATE_ACCOUNT, &PolicyHandle); if (!NT_SUCCESS(Status)) { DPRINT1("LsaOpenPolicy failed (Status %08lx)\n", Status); goto done; } if (!SetupFindFirstLineW(hSecurityInf, L"Privilege Rights", NULL, &InfContext)) { DPRINT1("SetupFindfirstLineW failed\n"); goto done; } PrivilegeSet.PrivilegeCount = 1; PrivilegeSet.Control = 0; do { /* Retrieve the privilege name */ if (!SetupGetStringFieldW(&InfContext, 0, szPrivilegeString, 256, NULL)) { DPRINT1("SetupGetStringFieldW() failed\n"); goto done; } DPRINT("Privilege: %S\n", szPrivilegeString); if (!LookupPrivilegeValueW(NULL, szPrivilegeString, &(PrivilegeSet.Privilege[0].Luid))) { DPRINT1("LookupPrivilegeNameW() failed\n"); goto done; } PrivilegeSet.Privilege[0].Attributes = 0; for (i = 0; i < SetupGetFieldCount(&InfContext); i++) { if (!SetupGetStringFieldW(&InfContext, i + 1, szSidString, 256, NULL)) { DPRINT1("SetupGetStringFieldW() failed\n"); goto done; } DPRINT("SID: %S\n", szSidString); ConvertStringSidToSid(szSidString, &AccountSid); Status = LsaOpenAccount(PolicyHandle, AccountSid, ACCOUNT_VIEW | ACCOUNT_ADJUST_PRIVILEGES, &AccountHandle); if (NT_SUCCESS(Status)) { Status = LsaAddPrivilegesToAccount(AccountHandle, &PrivilegeSet); if (!NT_SUCCESS(Status)) { DPRINT1("LsaAddPrivilegesToAccount() failed (Status %08lx)\n", Status); } LsaClose(AccountHandle); } LocalFree(AccountSid); } } while (SetupFindNextLine(&InfContext, &InfContext)); done: if (PolicyHandle != NULL) LsaClose(PolicyHandle); if (hSecurityInf != INVALID_HANDLE_VALUE) SetupCloseInfFile(hSecurityInf); }
static PBOOTRECORD ReadFreeldrSection(HINF hInf, WCHAR *szSectionName) { PBOOTRECORD pRecord; INFCONTEXT InfContext; WCHAR szName[MAX_PATH]; WCHAR szValue[MAX_PATH]; DWORD LineLength; if (!SetupFindFirstLineW(hInf, szSectionName, NULL, &InfContext)) { /* Failed to find section */ return NULL; } pRecord = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BOOTRECORD)); if (pRecord == NULL) { return NULL; } wcscpy(pRecord->szSectionName, szSectionName); do { if (!SetupGetStringFieldW(&InfContext, 0, szName, sizeof(szName) / sizeof(WCHAR), &LineLength)) { break; } if (!SetupGetStringFieldW(&InfContext, 1, szValue, sizeof(szValue) / sizeof(WCHAR), &LineLength)) { break; } if (!_wcsnicmp(szName, L"BootType", 8)) { if (!_wcsnicmp(szValue, L"ReactOS", 7)) { // FIXME: Store as enum pRecord->BootType = 1; } else { pRecord->BootType = 0; } } else if (!_wcsnicmp(szName, L"SystemPath", 10)) { wcscpy(pRecord->szBootPath, szValue); } else if (!_wcsnicmp(szName, L"Options", 7)) { // FIXME: Store flags as values wcscpy(pRecord->szOptions, szValue); } } while (SetupFindNextLine(&InfContext, &InfContext)); return pRecord; }
/* loads the LDIDs specified in the install section of an INF */ void set_ldids(HINF hInf, LPCWSTR pszInstallSection, LPCWSTR pszWorkingDir) { WCHAR field[MAX_FIELD_LENGTH]; WCHAR line[MAX_FIELD_LENGTH]; WCHAR dest[MAX_PATH]; INFCONTEXT context; DWORD size; int ldid; static const WCHAR source_dir[] = {'S','o','u','r','c','e','D','i','r',0}; static const WCHAR custDestW[] = { 'C','u','s','t','o','m','D','e','s','t','i','n','a','t','i','o','n',0 }; if (!SetupGetLineTextW(NULL, hInf, pszInstallSection, custDestW, field, MAX_FIELD_LENGTH, &size)) return; if (!SetupFindFirstLineW(hInf, field, NULL, &context)) return; do { LPWSTR value, ptr, key, key_copy = NULL; DWORD flags = 0; SetupGetLineTextW(&context, NULL, NULL, NULL, line, MAX_FIELD_LENGTH, &size); /* SetupGetLineTextW returns the value if there is only one key, but * returns the whole line if there is more than one key */ if (!(value = strchrW(line, '='))) { SetupGetStringFieldW(&context, 0, NULL, 0, &size); key = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR)); key_copy = key; SetupGetStringFieldW(&context, 0, key, size, &size); value = line; } else { key = line; *(value++) = '\0'; } /* remove leading whitespace from the value */ while (*value == ' ') value++; /* Extract the flags */ ptr = strchrW(value, ','); if (ptr) { *ptr = '\0'; flags = atolW(ptr+1); } /* set dest to pszWorkingDir if key is SourceDir */ if (pszWorkingDir && !lstrcmpiW(value, source_dir)) lstrcpynW(dest, pszWorkingDir, MAX_PATH); else get_dest_dir(hInf, value, dest, MAX_PATH); /* If prompting required, provide dialog to request path */ if (flags & 0x04) FIXME("Need to support changing paths - default will be used\n"); /* set all ldids to dest */ while ((ptr = get_parameter(&key, ',', FALSE))) { ldid = atolW(ptr); SetupSetDirectoryIdW(hInf, ldid, dest); } HeapFree(GetProcessHeap(), 0, key_copy); } while (SetupFindNextLine(&context, &context)); }
static INT LoadFreeldrSettings(HINF hInf, HWND hwndDlg) { INFCONTEXT InfContext; PBOOTRECORD pRecord; WCHAR szDefaultOs[MAX_PATH]; WCHAR szName[MAX_PATH]; WCHAR szValue[MAX_PATH]; DWORD LineLength; DWORD TimeOut; LRESULT lResult; if (!SetupFindFirstLineW(hInf, L"FREELOADER", L"DefaultOS", &InfContext)) { /* Failed to find default os */ return FALSE; } if (!SetupGetStringFieldW(&InfContext, 1, szDefaultOs, sizeof(szDefaultOs) / sizeof(WCHAR), &LineLength)) { /* No key */ return FALSE; } if (!SetupFindFirstLineW(hInf, L"FREELOADER", L"TimeOut", &InfContext)) { /* Expected to find timeout value */ return FALSE; } if (!SetupGetIntField(&InfContext, 1, (PINT)&TimeOut)) { /* Failed to retrieve timeout */ return FALSE; } if (!SetupFindFirstLineW(hInf, L"Operating Systems", NULL, &InfContext)) { /* Expected list of operating systems */ return FALSE; } do { if (!SetupGetStringFieldW(&InfContext, 0, szName, sizeof(szName) / sizeof(WCHAR), &LineLength)) { /* The ini file is messed up */ return FALSE; } if (!SetupGetStringFieldW(&InfContext, 1, szValue, sizeof(szValue) / sizeof(WCHAR), &LineLength)) { /* The ini file is messed up */ return FALSE; } pRecord = ReadFreeldrSection(hInf, szName); if (pRecord) { lResult = SendDlgItemMessageW(hwndDlg, IDC_STRECOSCOMBO, CB_ADDSTRING, (WPARAM)0, (LPARAM)szValue); if (lResult != CB_ERR) { SendDlgItemMessageW(hwndDlg, IDC_STRECOSCOMBO, CB_SETITEMDATA, (WPARAM)lResult, (LPARAM)pRecord); if (!wcscmp(szDefaultOs, szName)) { /* We store the friendly name as key */ wcscpy(szDefaultOs, szValue); } } else { HeapFree(GetProcessHeap(), 0, pRecord); } } } while (SetupFindNextLine(&InfContext, &InfContext)); /* Find default os in list */ lResult = SendDlgItemMessageW(hwndDlg, IDC_STRECOSCOMBO, CB_FINDSTRING, (WPARAM)-1, (LPARAM)szDefaultOs); if (lResult != CB_ERR) { /* Set cur sel */ SendDlgItemMessageW(hwndDlg, IDC_STRECOSCOMBO, CB_SETCURSEL, (WPARAM)lResult, (LPARAM)0); } if(TimeOut) { SendDlgItemMessageW(hwndDlg, IDC_STRECLIST, BM_SETCHECK, (WPARAM)BST_CHECKED, (LPARAM)0); } SetTimeout(hwndDlg, TimeOut); return TRUE; }
/*********************************************************************** * registry_callback * * Called once for each AddReg and DelReg entry in a given section. */ static BOOLEAN registry_callback (HINF hInf, PCWSTR Section, BOOLEAN Delete) { OBJECT_ATTRIBUTES ObjectAttributes; WCHAR Buffer[MAX_INF_STRING_LENGTH]; UNICODE_STRING Name; UNICODE_STRING Value; PUNICODE_STRING ValuePtr; NTSTATUS Status; UINT Flags; ULONG Length; INFCONTEXT Context; HANDLE KeyHandle; BOOLEAN Ok; Ok = SetupFindFirstLineW (hInf, Section, NULL, &Context); if (Ok) { for (;Ok; Ok = SetupFindNextLine (&Context, &Context)) { /* get root */ if (!SetupGetStringFieldW (&Context, 1, Buffer, MAX_INF_STRING_LENGTH, NULL)) continue; if (!GetRootKey (Buffer)) continue; /* get key */ Length = wcslen (Buffer); if (!SetupGetStringFieldW (&Context, 2, Buffer + Length, MAX_INF_STRING_LENGTH - Length, NULL)) *Buffer = 0; DPRINT("KeyName: <%S>\n", Buffer); /* get flags */ if (!SetupGetIntField (&Context, 4, (PINT)&Flags)) Flags = 0; DPRINT("Flags: %lx\n", Flags); #ifdef __ODYSSEY__ RtlInitUnicodeString (&Name, Buffer); InitializeObjectAttributes (&ObjectAttributes, &Name, OBJ_CASE_INSENSITIVE, NULL, NULL); if (Delete || (Flags & FLG_ADDREG_OVERWRITEONLY)) { Status = NtOpenKey (&KeyHandle, KEY_ALL_ACCESS, &ObjectAttributes); if (!NT_SUCCESS(Status)) { DPRINT("NtOpenKey(%wZ) failed (Status %lx)\n", &Name, Status); continue; /* ignore if it doesn't exist */ } } else { Status = CreateNestedKey (&KeyHandle, KEY_ALL_ACCESS, &ObjectAttributes); if (!NT_SUCCESS(Status)) { DPRINT("CreateNestedKey(%wZ) failed (Status %lx)\n", &Name, Status); continue; } } #else if (Delete || (Flags & FLG_ADDREG_OVERWRITEONLY)) { LONG rc = RegOpenKeyW(NULL, Buffer, &KeyHandle); if (rc != ERROR_SUCCESS) { DPRINT("RegOpenKeyW(%S) failed (error %lu)\n", Buffer, rc); continue; /* ignore if it doesn't exist */ } } else { LONG rc = RegCreateKeyW(NULL, Buffer, &KeyHandle); if (rc != ERROR_SUCCESS) { DPRINT("RegCreateKeyW(%S) failed (error %lu)\n", Buffer, rc); continue; } } #endif /* get value name */ if (SetupGetStringFieldW (&Context, 3, Buffer, MAX_INF_STRING_LENGTH, NULL)) { RtlInitUnicodeString (&Value, Buffer); ValuePtr = &Value; } else { ValuePtr = NULL; } /* and now do it */ if (!do_reg_operation (KeyHandle, ValuePtr, &Context, Flags)) { NtClose (KeyHandle); return FALSE; } #ifdef __ODYSSEY__ NtClose (KeyHandle); #endif } } return TRUE; }
PGENERIC_LIST CreateKeyboardLayoutList(HINF InfFile, WCHAR * DefaultKBLayout) { CHAR Buffer[128]; PGENERIC_LIST List; INFCONTEXT Context; PWCHAR KeyName; PWCHAR KeyValue; PWCHAR UserData; const MUI_LAYOUTS * LayoutsList; ULONG uIndex = 0; BOOL KeyboardLayoutsFound = FALSE; /* Get default layout id */ if (!SetupFindFirstLineW (InfFile, L"NLS", L"DefaultLayout", &Context)) return NULL; if (!INF_GetData (&Context, NULL, &KeyValue)) return NULL; wcscpy(DefaultKBLayout, KeyValue); List = CreateGenericList(); if (List == NULL) return NULL; LayoutsList = MUIGetLayoutsList(); do { if (!SetupFindFirstLineW(InfFile, L"KeyboardLayout", NULL, &Context)) { DestroyGenericList(List, FALSE); return NULL; } do { if (!INF_GetData (&Context, &KeyName, &KeyValue)) { /* FIXME: Handle error! */ DPRINT("INF_GetData() failed\n"); DestroyGenericList(List, FALSE); return NULL; } if (_wcsicmp(LayoutsList[uIndex].LayoutID, KeyName) == 0) { UserData = (WCHAR*) RtlAllocateHeap(ProcessHeap, 0, (wcslen(KeyName) + 1) * sizeof(WCHAR)); if (UserData == NULL) { /* FIXME: Handle error! */ DPRINT("RtlAllocateHeap() failed\n"); DestroyGenericList(List, FALSE); return NULL; } wcscpy(UserData, KeyName); sprintf(Buffer, "%S", KeyValue); AppendGenericListEntry(List, Buffer, UserData, _wcsicmp(KeyName, DefaultKBLayout) ? FALSE : TRUE); KeyboardLayoutsFound = TRUE; } } while (SetupFindNextLine(&Context, &Context)); uIndex++; } while (LayoutsList[uIndex].LangID != NULL); /* FIXME: Handle this case */ if (!KeyboardLayoutsFound) { DPRINT1("No keyboard layouts have been found\n"); DestroyGenericList(List, FALSE); return NULL; } return List; }
PGENERIC_LIST CreateDisplayDriverList(HINF InfFile) { CHAR Buffer[128]; PGENERIC_LIST List; INFCONTEXT Context; PWCHAR KeyName; PWCHAR KeyValue; PWCHAR UserData; WCHAR DisplayIdentifier[128]; WCHAR DisplayKey[32]; /* Get the display identification */ if (!GetDisplayIdentifier(DisplayIdentifier, 128)) { DisplayIdentifier[0] = 0; } DPRINT("Display identifier: '%S'\n", DisplayIdentifier); /* Search for matching device identifier */ if (!SetupFindFirstLineW(InfFile, L"Map.Display", NULL, &Context)) { /* FIXME: error message */ return NULL; } do { if (!INF_GetDataField(&Context, 1, &KeyValue)) { /* FIXME: Handle error! */ DPRINT("INF_GetDataField() failed\n"); return NULL; } DPRINT("KeyValue: %S\n", KeyValue); if (wcsstr(DisplayIdentifier, KeyValue)) { if (!INF_GetDataField(&Context, 0, &KeyName)) { /* FIXME: Handle error! */ DPRINT("INF_GetDataField() failed\n"); return NULL; } DPRINT("Display key: %S\n", KeyName); wcscpy(DisplayKey, KeyName); } } while (SetupFindNextLine(&Context, &Context)); List = CreateGenericList(); if (List == NULL) return NULL; if (!SetupFindFirstLineW (InfFile, L"Display", NULL, &Context)) { DestroyGenericList(List, FALSE); return NULL; } do { if (!INF_GetDataField(&Context, 0, &KeyName)) { DPRINT1("INF_GetDataField() failed\n"); break; } if (!INF_GetDataField(&Context, 1, &KeyValue)) { DPRINT1("INF_GetDataField() failed\n"); break; } UserData = (WCHAR*) RtlAllocateHeap(ProcessHeap, 0, (wcslen(KeyName) + 1) * sizeof(WCHAR)); if (UserData == NULL) { DPRINT1("RtlAllocateHeap() failed\n"); DestroyGenericList(List, TRUE); return NULL; } wcscpy(UserData, KeyName); sprintf(Buffer, "%S", KeyValue); AppendGenericListEntry(List, Buffer, UserData, _wcsicmp(KeyName, DisplayKey) ? FALSE : TRUE); } while (SetupFindNextLine(&Context, &Context)); #if 0 AppendGenericListEntry(List, "Other display driver", NULL, TRUE); #endif return List; }
static INT LoadBootSettings(HINF hInf, HWND hwndDlg) { INFCONTEXT InfContext; WCHAR szName[MAX_PATH]; WCHAR szValue[MAX_PATH]; DWORD LineLength; DWORD TimeOut = 0; WCHAR szDefaultOS[MAX_PATH]; WCHAR szOptions[MAX_PATH]; PBOOTRECORD pRecord; LRESULT lResult; if(!SetupFindFirstLineW(hInf, L"boot loader", NULL, &InfContext)) { return FALSE; } do { if (!SetupGetStringFieldW(&InfContext, 0, szName, sizeof(szName) / sizeof(WCHAR), &LineLength)) { return FALSE; } if (!SetupGetStringFieldW(&InfContext, 1, szValue, sizeof(szValue) / sizeof(WCHAR), &LineLength)) { return FALSE; } if (!_wcsnicmp(szName, L"timeout", 7)) { TimeOut = _wtoi(szValue); } if (!_wcsnicmp(szName, L"default", 7)) { wcscpy(szDefaultOS, szValue); } } while (SetupFindNextLine(&InfContext, &InfContext)); if (!SetupFindFirstLineW(hInf, L"operating systems", NULL, &InfContext)) { /* Failed to find operating systems section */ return FALSE; } do { if (!SetupGetStringFieldW(&InfContext, 0, szName, sizeof(szName) / sizeof(WCHAR), &LineLength)) { return FALSE; } if (!SetupGetStringFieldW(&InfContext, 1, szValue, sizeof(szValue) / sizeof(WCHAR), &LineLength)) { return FALSE; } SetupGetStringFieldW(&InfContext, 2, szOptions, sizeof(szOptions) / sizeof(WCHAR), &LineLength); pRecord = (PBOOTRECORD) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BOOTRECORD)); if (pRecord) { pRecord->BootType = 0; wcscpy(pRecord->szBootPath, szName); wcscpy(pRecord->szSectionName, szValue); wcscpy(pRecord->szOptions, szOptions); if (!wcscmp(szName, szDefaultOS)) { /* ms boot ini stores the path not the friendly name */ wcscpy(szDefaultOS, szValue); } lResult = SendDlgItemMessageW(hwndDlg, IDC_STRECOSCOMBO, CB_ADDSTRING, (WPARAM)0, (LPARAM)szValue); if (lResult != CB_ERR) { SendDlgItemMessageW(hwndDlg, IDC_STRECOSCOMBO, CB_SETITEMDATA, (WPARAM)lResult, (LPARAM)pRecord); } else { HeapFree(GetProcessHeap(), 0, pRecord); } } } while (SetupFindNextLine(&InfContext, &InfContext)); /* Find default os in list */ lResult = SendDlgItemMessageW(hwndDlg, IDC_STRECOSCOMBO, CB_FINDSTRING, (WPARAM)0, (LPARAM)szDefaultOS); if (lResult != CB_ERR) { /* Set cur sel */ SendDlgItemMessageW(hwndDlg, IDC_STRECOSCOMBO, CB_SETCURSEL, (WPARAM)lResult, (LPARAM)0); } if(TimeOut) { SendDlgItemMessageW(hwndDlg, IDC_STRECLIST, BM_SETCHECK, (WPARAM)BST_CHECKED, (LPARAM)0); } SetTimeout(hwndDlg, TimeOut); return TRUE; }
PGENERIC_LIST CreateLanguageList(HINF InfFile, WCHAR * DefaultLanguage) { CHAR Buffer[128]; PGENERIC_LIST List; INFCONTEXT Context; PWCHAR KeyName; PWCHAR KeyValue; PWCHAR UserData = NULL; ULONG uIndex = 0; /* Get default language id */ if (!SetupFindFirstLineW (InfFile, L"NLS", L"DefaultLanguage", &Context)) return NULL; if (!INF_GetData (&Context, NULL, &KeyValue)) return NULL; wcscpy(DefaultLanguage, KeyValue); SelectedLanguageId = KeyValue; List = CreateGenericList(); if (List == NULL) return NULL; if (!SetupFindFirstLineW (InfFile, L"Language", NULL, &Context)) { DestroyGenericList(List, FALSE); return NULL; } do { if (!INF_GetData (&Context, &KeyName, &KeyValue)) { /* FIXME: Handle error! */ DPRINT("INF_GetData() failed\n"); break; } if (IsLanguageAvailable(KeyName)) { UserData = (WCHAR*) RtlAllocateHeap(ProcessHeap, 0, (wcslen(KeyName) + 1) * sizeof(WCHAR)); if (UserData == NULL) { /* FIXME: Handle error! */ } wcscpy(UserData, KeyName); if (!_wcsicmp(KeyName, DefaultLanguage)) DefaultLanguageIndex = uIndex; sprintf(Buffer, "%S", KeyValue); AppendGenericListEntry(List, Buffer, UserData, FALSE); uIndex++; } } while (SetupFindNextLine(&Context, &Context)); /* Only one language available, make it the default one */ if(uIndex == 1 && UserData != NULL) { DefaultLanguageIndex = 0; wcscpy(DefaultLanguage, UserData); } return List; }
static BOOL InstallSysSetupInfComponents(VOID) { INFCONTEXT InfContext; WCHAR szNameBuffer[256]; WCHAR szSectionBuffer[256]; HINF hComponentInf = INVALID_HANDLE_VALUE; if (!SetupFindFirstLineW(hSysSetupInf, L"Infs.Always", NULL, &InfContext)) { DPRINT("No Inf.Always section found\n"); } else { do { if (!SetupGetStringFieldW(&InfContext, 1, // Get the component name szNameBuffer, sizeof(szNameBuffer)/sizeof(szNameBuffer[0]), NULL)) { FatalError("Error while trying to get component name \n"); return FALSE; } if (!SetupGetStringFieldW(&InfContext, 2, // Get the component install section szSectionBuffer, sizeof(szSectionBuffer)/sizeof(szSectionBuffer[0]), NULL)) { FatalError("Error while trying to get component install section \n"); return FALSE; } DPRINT("Trying to execute install section '%S' from '%S' \n", szSectionBuffer, szNameBuffer); hComponentInf = SetupOpenInfFileW(szNameBuffer, NULL, INF_STYLE_WIN4, NULL); if (hComponentInf == INVALID_HANDLE_VALUE) { FatalError("SetupOpenInfFileW() failed to open '%S' (Error: %lu)\n", szNameBuffer, GetLastError()); return FALSE; } if (!SetupInstallFromInfSectionW(NULL, hComponentInf, szSectionBuffer, SPINST_ALL, NULL, NULL, SP_COPY_NEWER, SetupDefaultQueueCallbackW, NULL, NULL, NULL)) { FatalError("Error while trying to install : %S (Error: %lu)\n", szNameBuffer, GetLastError()); SetupCloseInfFile(hComponentInf); return FALSE; } SetupCloseInfFile(hComponentInf); } while (SetupFindNextLine(&InfContext, &InfContext)); } return TRUE; }
OSStatus CThirdPage::LoadPrintDriverDefsFromFile(Manufacturers & manufacturers, const CString & filename, bool checkForDuplicateModels ) { HINF handle = INVALID_HANDLE_VALUE; const TCHAR * section = TEXT( "Manufacturer" ); LONG sectionCount; TCHAR line[ 1000 ]; CString klass; INFCONTEXT manufacturerContext; BOOL ok; OSStatus err = 0; // Make sure we can open the file handle = SetupOpenInfFile( filename, NULL, INF_STYLE_WIN4, NULL ); translate_errno( handle != INVALID_HANDLE_VALUE, GetLastError(), kUnknownErr ); require_noerr( err, exit ); // Make sure it's a printer file ok = SetupGetLineText( NULL, handle, TEXT( "Version" ), TEXT( "Class" ), line, sizeof( line ), NULL ); translate_errno( ok, GetLastError(), kUnknownErr ); require_noerr( err, exit ); klass = line; require_action( klass == TEXT( "Printer" ), exit, err = kUnknownErr ); sectionCount = SetupGetLineCount( handle, section ); translate_errno( sectionCount != -1, GetLastError(), kUnknownErr ); require_noerr( err, exit ); memset( &manufacturerContext, 0, sizeof( manufacturerContext ) ); for ( LONG i = 0; i < sectionCount; i++ ) { Manufacturers::iterator iter; Manufacturer * manufacturer; CString manufacturerName; CString temp; CStringList modelSectionNameDecl; CString modelSectionName; CString baseModelName; CString model; INFCONTEXT modelContext; LONG modelCount; POSITION p; if ( i == 0 ) { ok = SetupFindFirstLine( handle, section, NULL, &manufacturerContext ); err = translate_errno( ok, GetLastError(), kUnknownErr ); require_noerr( err, exit ); } else { ok = SetupFindNextLine( &manufacturerContext, &manufacturerContext ); err = translate_errno( ok, GetLastError(), kUnknownErr ); require_noerr( err, exit ); } ok = SetupGetStringField( &manufacturerContext, 0, line, sizeof( line ), NULL ); err = translate_errno( ok, GetLastError(), kUnknownErr ); require_noerr( err, exit ); manufacturerName = line; ok = SetupGetLineText( &manufacturerContext, handle, NULL, NULL, line, sizeof( line ), NULL ); err = translate_errno( ok, GetLastError(), kUnknownErr ); require_noerr( err, exit ); // Try to find some model section name that has entries. Explanation of int file structure // can be found at: // // <http://msdn.microsoft.com/en-us/library/ms794359.aspx> Split( line, ',', modelSectionNameDecl ); p = modelSectionNameDecl.GetHeadPosition(); modelSectionName = modelSectionNameDecl.GetNext( p ); modelCount = SetupGetLineCount( handle, modelSectionName ); baseModelName = modelSectionName; while ( modelCount <= 0 && p ) { CString targetOSVersion; targetOSVersion = modelSectionNameDecl.GetNext( p ); modelSectionName = baseModelName + TEXT( "." ) + targetOSVersion; modelCount = SetupGetLineCount( handle, modelSectionName ); } if ( modelCount > 0 ) { manufacturerName = NormalizeManufacturerName( manufacturerName ); iter = manufacturers.find( manufacturerName ); if ( iter != manufacturers.end() ) { manufacturer = iter->second; require_action( manufacturer, exit, err = kUnknownErr ); } else { try { manufacturer = new Manufacturer; } catch (...) { manufacturer = NULL; } require_action( manufacturer, exit, err = kNoMemoryErr ); manufacturer->name = manufacturerName; manufacturers[ manufacturerName ] = manufacturer; } memset( &modelContext, 0, sizeof( modelContext ) ); for ( LONG j = 0; j < modelCount; j++ ) { CString modelName; Model * model; if ( j == 0 ) { ok = SetupFindFirstLine( handle, modelSectionName, NULL, &modelContext ); err = translate_errno( ok, GetLastError(), kUnknownErr ); require_noerr( err, exit ); } else { SetupFindNextLine( &modelContext, &modelContext ); err = translate_errno( ok, GetLastError(), kUnknownErr ); require_noerr( err, exit ); } ok = SetupGetStringField( &modelContext, 0, line, sizeof( line ), NULL ); err = translate_errno( ok, GetLastError(), kUnknownErr ); require_noerr( err, exit ); modelName = line; if (checkForDuplicateModels == true) { if ( MatchModel( manufacturer, ConvertToModelName( modelName ) ) != NULL ) { continue; } } // // Stock Vista printer inf files embed guids in the model // declarations for Epson printers. Let's ignore those. // if ( modelName.Find( TEXT( "{" ), 0 ) != -1 ) { continue; } try { model = new Model; } catch (...) { model = NULL; } require_action( model, exit, err = kNoMemoryErr ); model->infFileName = filename; model->displayName = modelName; model->name = modelName; model->driverInstalled = false; manufacturer->models.push_back(model); } } } exit: if ( handle != INVALID_HANDLE_VALUE ) { SetupCloseInfFile( handle ); handle = NULL; } return err; }
int usb_install_driver_np(const char *inf_file) { HDEVINFO dev_info; SP_DEVINFO_DATA dev_info_data; INFCONTEXT inf_context; HINF inf_handle; DWORD config_flags, problem, status; BOOL reboot; char inf_path[MAX_PATH]; char id[MAX_PATH]; char tmp_id[MAX_PATH]; char *p; int dev_index; HINSTANCE newdev_dll = NULL; HMODULE setupapi_dll = NULL; update_driver_for_plug_and_play_devices_t UpdateDriverForPlugAndPlayDevices; setup_copy_oem_inf_t SetupCopyOEMInf; newdev_dll = LoadLibrary("newdev.dll"); if(!newdev_dll) { usb_error("usb_install_driver(): loading newdev.dll failed\n"); return -1; } UpdateDriverForPlugAndPlayDevices = (update_driver_for_plug_and_play_devices_t) GetProcAddress(newdev_dll, "UpdateDriverForPlugAndPlayDevicesA"); if(!UpdateDriverForPlugAndPlayDevices) { usb_error("usb_install_driver(): loading newdev.dll failed\n"); return -1; } setupapi_dll = GetModuleHandle("setupapi.dll"); if(!setupapi_dll) { usb_error("usb_install_driver(): loading setupapi.dll failed\n"); return -1; } SetupCopyOEMInf = (setup_copy_oem_inf_t) GetProcAddress(setupapi_dll, "SetupCopyOEMInfA"); if(!SetupCopyOEMInf) { usb_error("usb_install_driver(): loading setupapi.dll failed\n"); return -1; } dev_info_data.cbSize = sizeof(SP_DEVINFO_DATA); /* retrieve the full .inf file path */ if(!GetFullPathName(inf_file, MAX_PATH, inf_path, NULL)) { usb_error("usb_install_driver(): .inf file %s not found\n", inf_file); return -1; } /* open the .inf file */ inf_handle = SetupOpenInfFile(inf_path, NULL, INF_STYLE_WIN4, NULL); if(inf_handle == INVALID_HANDLE_VALUE) { usb_error("usb_install_driver(): unable to open .inf file %s\n", inf_file); return -1; } /* find the .inf file's device description section marked "Devices" */ if(!SetupFindFirstLine(inf_handle, "Devices", NULL, &inf_context)) { usb_error("usb_install_driver(): .inf file %s does not contain " "any device descriptions\n", inf_file); SetupCloseInfFile(inf_handle); return -1; } do { /* get the device ID from the .inf file */ if(!SetupGetStringField(&inf_context, 2, id, sizeof(id), NULL)) { continue; } /* convert the string to lowercase */ strlwr(id); reboot = FALSE; /* copy the .inf file to the system directory so that is will be found */ /* when new devices are plugged in */ SetupCopyOEMInf(inf_path, NULL, SPOST_PATH, 0, NULL, 0, NULL, NULL); /* update all connected devices matching this ID, but only if this */ /* driver is better or newer */ UpdateDriverForPlugAndPlayDevices(NULL, id, inf_path, INSTALLFLAG_FORCE, &reboot); /* now search the registry for device nodes representing currently */ /* unattached devices */ /* get all USB device nodes from the registry, present and non-present */ /* devices */ dev_info = SetupDiGetClassDevs(NULL, "USB", NULL, DIGCF_ALLCLASSES); if(dev_info == INVALID_HANDLE_VALUE) { SetupCloseInfFile(inf_handle); break; } dev_index = 0; /* enumerate the device list to find all attached and unattached */ /* devices */ while(SetupDiEnumDeviceInfo(dev_info, dev_index, &dev_info_data)) { /* get the harware ID from the registry, this is a multi-zero string */ if(SetupDiGetDeviceRegistryProperty(dev_info, &dev_info_data, SPDRP_HARDWAREID, NULL, (BYTE *)tmp_id, sizeof(tmp_id), NULL)) { /* check all possible IDs contained in that multi-zero string */ for(p = tmp_id; *p; p += (strlen(p) + 1)) { /* convert the string to lowercase */ strlwr(p); /* found a match? */ if(strstr(p, id)) { /* is this device disconnected? */ if(CM_Get_DevNode_Status(&status, &problem, dev_info_data.DevInst, 0) == CR_NO_SUCH_DEVINST) { /* found a device node that represents an unattached */ /* device */ if(SetupDiGetDeviceRegistryProperty(dev_info, &dev_info_data, SPDRP_CONFIGFLAGS, NULL, (BYTE *)&config_flags, sizeof(config_flags), NULL)) { /* mark the device to be reinstalled the next time it is */ /* plugged in */ config_flags |= CONFIGFLAG_REINSTALL; /* write the property back to the registry */ SetupDiSetDeviceRegistryProperty(dev_info, &dev_info_data, SPDRP_CONFIGFLAGS, (BYTE *)&config_flags, sizeof(config_flags)); } } /* a match was found, skip the rest */ break; } } } /* check the next device node */ dev_index++; } SetupDiDestroyDeviceInfoList(dev_info); /* get the next device ID from the .inf file */ } while(SetupFindNextLine(&inf_context, &inf_context)); /* we are done, close the .inf file */ SetupCloseInfFile(inf_handle); usb_registry_stop_libusb_devices(); /* stop all libusb devices */ usb_registry_start_libusb_devices(); /* restart all libusb devices */ return 0; }