+ LPTSTR CustomPath = NULL;
+ DWORD CustomPathLength;
+ LPTSTR Buffer = NULL;
+ LPTSTR pBuffer; /* Pointer into Buffer */
+ int ItemsCount, Length;
+ DWORD i;
+ DWORD TotalLength = 0;
+ BOOL UseCustomPath = TRUE;
+ HKEY hKey = NULL;
+ LONG rc;
+
+ /* Get custom path */
+ Length = ComboBox_GetTextLength(hwndCombo) + 1;
+ CustomPath = HeapAlloc(GetProcessHeap(), 0, Length * sizeof(TCHAR));
+ if (!CustomPath)
+ {
+ TRACE("HeapAlloc() failed\n");
+ goto cleanup;
+ }
+ CustomPathLength = ComboBox_GetText(hwndCombo, CustomPath, Length) + 1;
+
+ /* Calculate length of the buffer */
+ ItemsCount = ComboBox_GetCount(hwndCombo);
+ if (ItemsCount == CB_ERR)
+ {
+ TRACE("ComboBox_GetCount() failed\n");
+ goto cleanup;
+ }
+ for (i = 0; i < ItemsCount; i++)
+ {
+ Length = ComboBox_GetLBTextLen(hwndCombo, i);
+ if (Length == CB_ERR)
+ {
+ TRACE("ComboBox_GetLBTextLen() failed\n");
+ goto cleanup;
+ }
+ TotalLength += Length + 1;
+ }
+ TotalLength++; /* Final NULL char */
+
+ /* Allocate buffer */
+ Buffer = HeapAlloc(GetProcessHeap(), 0, (CustomPathLength + TotalLength + 1) * sizeof(TCHAR));
+ if (!Buffer)
+ {
+ TRACE("HeapAlloc() failed\n");
+ goto cleanup;
+ }
+
+ /* Fill the buffer */
+ pBuffer = &Buffer[CustomPathLength];
+ for (i = 0; i < ItemsCount; i++)
+ {
+ Length = ComboBox_GetLBText(hwndCombo, i, pBuffer);
+ if (Length == CB_ERR)
+ {
+ TRACE("ComboBox_GetLBText() failed\n");
+ goto cleanup;
+ }
+ else if (UseCustomPath && _tcsicmp(CustomPath, pBuffer) == 0)
+ UseCustomPath = FALSE;
+ pBuffer += 1 + Length;
+ }
+ *pBuffer = '\0'; /* Add final NULL char */
+
+ if (!UseCustomPath)
+ {
+ /* Nothing to save to registry */
+ goto cleanup;
+ }
+
+ TotalLength += CustomPathLength;
+ _tcscpy(Buffer, CustomPath);
+
+ /* Save the buffer */
+ /* RegSetKeyValue would have been better... */
+ rc = RegOpenKeyEx(
+ HKEY_LOCAL_MACHINE,
+ REGSTR_PATH_SETUP REGSTR_KEY_SETUP,
+ 0,
+ KEY_SET_VALUE,
+ &hKey);
+ if (rc != ERROR_SUCCESS)
+ {
+ TRACE("RegOpenKeyEx() failed with error 0x%lx\n", rc);
+ goto cleanup;
+ }
+ rc = RegSetValueEx(
+ hKey,
+ _T("Installation Sources"),
+ 0,
+ REG_MULTI_SZ,
+ (const BYTE*)Buffer,
+ TotalLength * sizeof(TCHAR));
+ if (rc != ERROR_SUCCESS)
+ {
+ TRACE("RegSetValueEx() failed with error 0x%lx\n", rc);
+ goto cleanup;
+ }
+
+cleanup:
+ if (hKey != NULL)
+ RegCloseKey(hKey);
+ HeapFree(GetProcessHeap(), 0, CustomPath);
+ HeapFree(GetProcessHeap(), 0, Buffer);