Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1776 lines
71 KiB

  1. #include <w95wraps.h>
  2. #include <windows.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include "shlwapi.h"
  6. #include "parse.h"
  7. #include "..\ieakutil\ieakutil.h"
  8. #define NCATEGORY 0
  9. #define NPOLICY 1
  10. #define NPART 2
  11. #define NACTIONLIST 3
  12. TCHAR *pKeyNames[29] = { TEXT("CLASS"), TEXT("CATEGORY"), TEXT("KEYNAME"), TEXT("POLICY"), TEXT("VALUENAME"),
  13. TEXT("ACTIONLISTON"), TEXT("ACTIONLISTOFF"), TEXT("PART"), TEXT("END"), TEXT("ITEMLIST"), TEXT("NAME"),
  14. TEXT("MAXLEN"), TEXT("DEFAULT"), TEXT("ACTIONLIST"), TEXT("SUGGESTIONS"), TEXT("MIN"), TEXT("MAX"), TEXT("VALUEON"),
  15. TEXT("VALUEOFF"), TEXT("VALUE"), TEXT("DEFCHECKED"), TEXT("SPIN"), TEXT("#if"), TEXT("#endif"), TEXT("VERSION"),
  16. TEXT("<"), TEXT("<="), TEXT(">"), TEXT(">=") };
  17. TCHAR *pPartTypes[8] = { TEXT("EDITTEXT"), TEXT("DROPDOWNLIST"), TEXT("NUMERIC"), TEXT("CHECKBOX"),
  18. TEXT("LISTBOX"), TEXT("TEXT"), TEXT("COMBOBOX"), TEXT("POLICY") };
  19. BOOL ReadAdmFile(LPADMFILE, LPCTSTR);
  20. void FreeAdmMemory(LPADMFILE);
  21. int g_nLine = 1;
  22. #define MAX_NUMERIC 32767
  23. #define MAX_EDITTEXTLEN 512
  24. #define ALLOCATE 100
  25. #define REALLOCATE 101
  26. //-------------------------------------------------------------------------
  27. // F I L E E X I S T S
  28. //
  29. // Checks to see if a file exists and returns true if it does
  30. //-------------------------------------------------------------------------
  31. BOOL FileExists( LPCTSTR pcszFile )
  32. {
  33. return (GetFileAttributes( pcszFile ) != -1 );
  34. }
  35. void FreeActionList(LPACTIONLIST pActionList, int nActions)
  36. {
  37. if (pActionList == NULL)
  38. return;
  39. for(int nActionListIndex = 0; nActionListIndex < nActions; nActionListIndex++)
  40. {
  41. if(pActionList[nActionListIndex].szName != NULL)
  42. LocalFree(pActionList[nActionListIndex].szName);
  43. if(pActionList[nActionListIndex].szValue != NULL)
  44. LocalFree(pActionList[nActionListIndex].szValue);
  45. for(int nValueIndex = 0; nValueIndex < pActionList[nActionListIndex].nValues; nValueIndex++)
  46. {
  47. if(pActionList[nActionListIndex].value[nValueIndex].szKeyname != NULL)
  48. LocalFree(pActionList[nActionListIndex].value[nValueIndex].szKeyname);
  49. if(pActionList[nActionListIndex].value[nValueIndex].szValueName != NULL)
  50. LocalFree(pActionList[nActionListIndex].value[nValueIndex].szValueName);
  51. if(pActionList[nActionListIndex].value[nValueIndex].szValue != NULL)
  52. LocalFree(pActionList[nActionListIndex].value[nValueIndex].szValue);
  53. if(pActionList[nActionListIndex].value[nValueIndex].szValueOn != NULL)
  54. LocalFree(pActionList[nActionListIndex].value[nValueIndex].szValueOn);
  55. if(pActionList[nActionListIndex].value[nValueIndex].szValueOff != NULL)
  56. LocalFree(pActionList[nActionListIndex].value[nValueIndex].szValueOff);
  57. }
  58. if (pActionList[nActionListIndex].value != NULL)
  59. HeapFree(GetProcessHeap(), 0, pActionList[nActionListIndex].value);
  60. }
  61. }
  62. //--------------------------------------------------------------------------
  63. // F R E E A D M M E M O R Y Exported Function
  64. //
  65. // Releases memory allocated by ReadAdmFile
  66. //--------------------------------------------------------------------------
  67. void FreeAdmMemory( LPADMFILE pAdmFile )
  68. {
  69. if (pAdmFile == NULL)
  70. return;
  71. for(int nPartIndex = 0; nPartIndex < pAdmFile->nParts; nPartIndex++ )
  72. {
  73. if(pAdmFile->pParts[nPartIndex].szName != NULL)
  74. LocalFree(pAdmFile->pParts[nPartIndex].szName);
  75. if(pAdmFile->pParts[nPartIndex].szCategory != NULL)
  76. LocalFree(pAdmFile->pParts[nPartIndex].szCategory);
  77. if(pAdmFile->pParts[nPartIndex].szDefaultValue != NULL)
  78. LocalFree(pAdmFile->pParts[nPartIndex].szDefaultValue);
  79. if(pAdmFile->pParts[nPartIndex].value.szKeyname != NULL)
  80. LocalFree(pAdmFile->pParts[nPartIndex].value.szKeyname);
  81. if(pAdmFile->pParts[nPartIndex].value.szValueName != NULL)
  82. LocalFree(pAdmFile->pParts[nPartIndex].value.szValueName);
  83. if(pAdmFile->pParts[nPartIndex].value.szValue != NULL)
  84. LocalFree(pAdmFile->pParts[nPartIndex].value.szValue);
  85. if(pAdmFile->pParts[nPartIndex].value.szValueOn != NULL)
  86. LocalFree(pAdmFile->pParts[nPartIndex].value.szValueOn);
  87. if(pAdmFile->pParts[nPartIndex].value.szValueOff != NULL)
  88. LocalFree(pAdmFile->pParts[nPartIndex].value.szValueOff);
  89. FreeActionList(pAdmFile->pParts[nPartIndex].actionlist, pAdmFile->pParts[nPartIndex].nActions);
  90. if (pAdmFile->pParts[nPartIndex].actionlist != NULL)
  91. HeapFree(GetProcessHeap(), 0, pAdmFile->pParts[nPartIndex].actionlist);
  92. for(int nSuggestionIndex = 0; nSuggestionIndex < pAdmFile->pParts[nPartIndex].nSuggestions; nSuggestionIndex++)
  93. {
  94. if(pAdmFile->pParts[nPartIndex].suggestions[nSuggestionIndex].szText != NULL)
  95. LocalFree(pAdmFile->pParts[nPartIndex].suggestions[nSuggestionIndex].szText);
  96. }
  97. if (pAdmFile->pParts[nPartIndex].suggestions != NULL)
  98. HeapFree(GetProcessHeap(), 0, pAdmFile->pParts[nPartIndex].suggestions);
  99. }
  100. if(pAdmFile->pParts != NULL)
  101. {
  102. HeapFree(GetProcessHeap(), 0, pAdmFile->pParts);
  103. pAdmFile->pParts = NULL;
  104. }
  105. pAdmFile->nParts = 0;
  106. *pAdmFile->szFilename = TEXT('\0');
  107. }
  108. void FreePartData( LPVOID* pPartData, int nParts )
  109. {
  110. LPPARTDATA pData = NULL;
  111. if (pData == NULL)
  112. return;
  113. pData = (LPPARTDATA)*pPartData;
  114. for(int nPartIndex = 0; nPartIndex < nParts; nPartIndex++ )
  115. {
  116. if(pData != NULL && pData[nPartIndex].value.szValue != NULL)
  117. LocalFree(pData[nPartIndex].value.szValue);
  118. FreeActionList(pData[nPartIndex].actionlist, pData[nPartIndex].nActions);
  119. if (pData[nPartIndex].actionlist != NULL)
  120. HeapFree(GetProcessHeap(), 0, pData[nPartIndex].actionlist);
  121. }
  122. HeapFree(GetProcessHeap(), 0, pData);
  123. pData = NULL;
  124. }
  125. //--------------------------------------------------------------------------
  126. // R E A D K E Y W O R D
  127. //
  128. // Reads the next word in the string pData and copyies it into szKeyWord
  129. // Returns a pointer to the next character after the word
  130. //--------------------------------------------------------------------------
  131. TCHAR *ReadKeyword( TCHAR *pData, TCHAR *szKeyWord, int cchLength )
  132. {
  133. int i;
  134. int nIndex;
  135. memset( szKeyWord, 0, cchLength*sizeof(TCHAR) );
  136. // remove whitespace
  137. i = StrSpn( pData, TEXT(" \n\t\x0d\x0a") );
  138. if(i)
  139. {
  140. for(nIndex = 0; nIndex < i; nIndex++)
  141. {
  142. if(*(pData + nIndex) == TEXT('\x0a'))
  143. g_nLine++;
  144. }
  145. }
  146. pData += i;
  147. i = StrCSpn( pData, TEXT(" \n\t\x0d\x0a") );
  148. if( i > cchLength ) // make sure we dont overrun our buffer
  149. i = cchLength - 1;
  150. StrCpyN( szKeyWord, pData, i+1 );
  151. pData += i;
  152. return pData;
  153. }
  154. //--------------------------------------------------------------------------
  155. // G E T E O F
  156. //
  157. // Returns the number of bytes in pFile
  158. //--------------------------------------------------------------------------
  159. //int GetEof( FILE *pFile )
  160. //{
  161. // int i = 0;
  162. // char cByte;
  163. //
  164. // while( !feof( pFile ))
  165. // {
  166. // fread( &cByte, 1, 1, pFile );
  167. // i++;
  168. // }
  169. // rewind( pFile );
  170. // return i;
  171. //}
  172. //--------------------------------------------------------------------------
  173. // G E T K E Y N A M E
  174. //
  175. // Compares szKeyName to an array of available keynames and returns an
  176. // index into that array
  177. //--------------------------------------------------------------------------
  178. int GetKeyName( TCHAR *szKeyName )
  179. {
  180. int i;
  181. for( i = 0; i < ARRAYSIZE( pKeyNames ); i++ )
  182. {
  183. if( StrCmpI( szKeyName, pKeyNames[i] ) == 0 )
  184. return i;
  185. }
  186. return KEY_ERROR;
  187. }
  188. //--------------------------------------------------------------------------
  189. // G E T P A R T N A M E
  190. //
  191. // compares szParyType to an array of available part types and return an
  192. // index into that array
  193. //--------------------------------------------------------------------------
  194. int GetPartName( TCHAR *szPartType )
  195. {
  196. int i;
  197. for( i = 0; i < ARRAYSIZE( pPartTypes ); i++ )
  198. {
  199. if( StrCmp( szPartType, pPartTypes[i] ) == 0 )
  200. return i;
  201. }
  202. return PART_ERROR;
  203. }
  204. //--------------------------------------------------------------------------
  205. // C H E C K S T R I N G S
  206. //
  207. // Checks to see if szString is localizable and replaces it if it is
  208. //--------------------------------------------------------------------------
  209. void CheckStrings( TCHAR *szString, LPCTSTR pcszFileName )
  210. {
  211. TCHAR szTemp[1024];
  212. if( StrCmpN( szString, TEXT("!!"), 2 ) == 0 )
  213. {
  214. szString += 2; //incrememt pointer
  215. GetPrivateProfileString( TEXT("strings"), szString, TEXT(""), szTemp,
  216. ARRAYSIZE( szTemp ), pcszFileName );
  217. szString -= 2; //decrement pointer
  218. if( *szTemp )
  219. {
  220. StrCpy( szString, szTemp );
  221. }
  222. }
  223. }
  224. //--------------------------------------------------------------------------
  225. // G E T Q U O T E D T E X T
  226. //
  227. // Checks to see if the current word is quoted and copies the entire
  228. // series of quoted words into szKeyWord
  229. //--------------------------------------------------------------------------
  230. TCHAR *GetQuotedText( TCHAR *pData, TCHAR *szKeyWord, int nLength )
  231. {
  232. int i;
  233. pData -= lstrlen( szKeyWord );
  234. // if we are not quoted, return the current pointer
  235. if( pData[0] != TEXT('\"') )
  236. {
  237. pData += lstrlen( szKeyWord );
  238. return pData;
  239. }
  240. // skip over first quote
  241. pData++;
  242. // search for another quote or a newline character
  243. i = StrCSpn( pData, TEXT("\"\n") );
  244. memset( szKeyWord, 0, nLength );
  245. StrCpyN( szKeyWord, pData, i+1 );
  246. pData += i;
  247. return ++pData;
  248. }
  249. //--------------------------------------------------------------------------
  250. // R E A D V A L U E
  251. //
  252. //
  253. //--------------------------------------------------------------------------
  254. TCHAR *ReadValue( TCHAR *pCurrent, LPVALUE value, int nValue, LPCTSTR pcszFileName )
  255. {
  256. TCHAR szKeyWord[1024];
  257. pCurrent = ReadKeyword( pCurrent, szKeyWord, ARRAYSIZE( szKeyWord ));
  258. if( StrCmp( szKeyWord, TEXT("VALUE") ) == 0 )
  259. {
  260. pCurrent = ReadKeyword( pCurrent, szKeyWord, ARRAYSIZE( szKeyWord ));
  261. if(value[nValue].szValue != NULL)
  262. LocalFree(value[nValue].szValue);
  263. value[nValue].szValue = NULL;
  264. if( StrCmp( szKeyWord, TEXT("NUMERIC") ) == 0 )
  265. {
  266. pCurrent = ReadKeyword( pCurrent, szKeyWord, ARRAYSIZE( szKeyWord ));
  267. value[nValue].dwValue = StrToInt( szKeyWord );
  268. value[nValue].fNumeric = TRUE;
  269. }
  270. else
  271. {
  272. if( StrCmp( szKeyWord, TEXT("TEXT") ) == 0 )
  273. pCurrent = ReadKeyword( pCurrent, szKeyWord, ARRAYSIZE( szKeyWord ));
  274. if (pCurrent && (*pCurrent != TEXT('\0')))
  275. pCurrent = GetQuotedText( pCurrent, szKeyWord, sizeof( szKeyWord ));
  276. CheckStrings( szKeyWord, pcszFileName );
  277. value[nValue].szValue = StrDup(szKeyWord);
  278. }
  279. }
  280. return pCurrent;
  281. }
  282. BOOL AllocateActions(LPACTIONLIST* actionlist, int nAllocate, int nAllocType)
  283. {
  284. LPVOID lpTemp = NULL;
  285. if(nAllocType == ALLOCATE)
  286. {
  287. *actionlist = (LPACTIONLIST) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(ACTIONLIST) * nAllocate);
  288. if(*actionlist == NULL)
  289. return FALSE;
  290. }
  291. else
  292. {
  293. lpTemp = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, *actionlist, sizeof(ACTIONLIST) * nAllocate);
  294. if(lpTemp == NULL)
  295. return FALSE;
  296. *actionlist = (LPACTIONLIST) lpTemp;
  297. }
  298. return TRUE;
  299. }
  300. BOOL AllocateValues(LPVALUE* values, int nAllocate, int nAllocType)
  301. {
  302. LPVOID lpTemp = NULL;
  303. if(nAllocType == ALLOCATE)
  304. {
  305. *values = (LPVALUE) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(VALUE) * nAllocate);
  306. if(*values == NULL)
  307. return FALSE;
  308. }
  309. else
  310. {
  311. lpTemp = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, *values, sizeof(VALUE) * nAllocate);
  312. if(lpTemp == NULL)
  313. return FALSE;
  314. *values = (LPVALUE) lpTemp;
  315. }
  316. return TRUE;
  317. }
  318. BOOL AllocateSuggestions(LPSUGGESTIONS* suggestions, int nAllocate, int nAllocType)
  319. {
  320. LPVOID lpTemp = NULL;
  321. if(nAllocType == ALLOCATE)
  322. {
  323. *suggestions = (LPSUGGESTIONS) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(SUGGESTIONS) * nAllocate);
  324. if(*suggestions == NULL)
  325. return FALSE;
  326. }
  327. else
  328. {
  329. lpTemp = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, *suggestions, sizeof(SUGGESTIONS) * nAllocate);
  330. if(lpTemp == NULL)
  331. return FALSE;
  332. *suggestions = (LPSUGGESTIONS) lpTemp;
  333. }
  334. return TRUE;
  335. }
  336. //--------------------------------------------------------------------------
  337. // R E A D A D M F I L E Exported Function
  338. //
  339. // Parses a global policy template into an array of PARTs.
  340. //--------------------------------------------------------------------------
  341. BOOL ReadAdmFile( LPADMFILE admfile, LPCTSTR pcszFileName)
  342. {
  343. HANDLE hFile;
  344. TCHAR *pData;
  345. TCHAR *pCurrent;
  346. TCHAR szKeyWord[1024];
  347. int nFileSize;
  348. int nParts = 0;
  349. int nValues = 0;
  350. int nSuggestions = 0;
  351. LPPART part = NULL;
  352. LPVALUE value = NULL;
  353. LPSUGGESTIONS suggestions = NULL;
  354. HGLOBAL hFileMem;
  355. int nPartsAlloc = 100;
  356. int nValuesAlloc = 0;
  357. int nSuggestionsAlloc = 0;
  358. HKEY hkCurrentClass = HKEY_CURRENT_USER;
  359. TCHAR szCurrentCategory[1024];
  360. BOOL fInPart = FALSE, fInPolicy = FALSE, fInCategory = FALSE;
  361. BOOL fInActionList = FALSE;
  362. TCHAR szRegKey[4][1024];
  363. TCHAR szValueName[1024];
  364. BOOL bContinue = TRUE;
  365. int nActionsAlloc = 0;
  366. int nActions = 0;
  367. LPACTIONLIST actionlist = NULL;
  368. LPVOID lpTemp = NULL;
  369. int nPolicyPart = -1;
  370. int nKeyValue = 0;
  371. TCHAR szValueOn[1024];
  372. TCHAR szValueOff[1024];
  373. int nValueOn = 1;
  374. int nValueOff = 0;
  375. BOOL fInItemList = FALSE;
  376. int nActionListType = -1;
  377. BOOL fSkip = FALSE;
  378. if( !FileExists( pcszFileName ))
  379. {
  380. SetLastError( ERROR_FILE_NOT_FOUND );
  381. return FALSE;
  382. }
  383. // allocate memory
  384. part = (LPPART) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(PART) * nPartsAlloc);
  385. // set up pointers and structures
  386. admfile->pParts = part;
  387. admfile->nParts = 0;
  388. if(part == NULL)
  389. {
  390. FreeAdmMemory( admfile );
  391. SetLastError( ERROR_NOT_ENOUGH_MEMORY );
  392. return FALSE;
  393. }
  394. memset( szRegKey, 0, sizeof( szRegKey ));
  395. hFile = CreateFile( pcszFileName, GENERIC_READ, FILE_SHARE_READ,
  396. NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL );
  397. if( hFile == INVALID_HANDLE_VALUE )
  398. {
  399. FreeAdmMemory( admfile );
  400. return FALSE;
  401. }
  402. nFileSize = GetFileSize( hFile, NULL );
  403. hFileMem = LocalAlloc( LPTR, (nFileSize + 1)*sizeof(TCHAR));
  404. if( hFileMem == NULL )
  405. {
  406. CloseHandle( hFile );
  407. FreeAdmMemory( admfile );
  408. SetLastError( ERROR_NOT_ENOUGH_MEMORY );
  409. return FALSE;
  410. }
  411. pData = (LPTSTR) hFileMem;
  412. // read all of the data available
  413. ReadStringFromFile( hFile, pData, (DWORD) nFileSize);
  414. CloseHandle( hFile );
  415. // set the current pointer to the beginning of the data
  416. pCurrent = pData;
  417. g_nLine = 1;
  418. // main loop
  419. do
  420. {
  421. pCurrent = ReadKeyword( pCurrent, szKeyWord, ARRAYSIZE( szKeyWord ));
  422. if( pCurrent >= pData + nFileSize )
  423. break;
  424. nKeyValue = GetKeyName(szKeyWord);
  425. if (nKeyValue != KEY_ENDIF && fSkip == TRUE)
  426. continue;
  427. switch((nKeyValue))
  428. {
  429. case KEY_CLASS:
  430. pCurrent = ReadKeyword( pCurrent, szKeyWord, ARRAYSIZE( szKeyWord ));
  431. if( StrCmp( szKeyWord, TEXT("MACHINE") ) == 0 )
  432. hkCurrentClass = HKEY_LOCAL_MACHINE;
  433. if( StrCmp( szKeyWord, TEXT("USER") ) == 0 )
  434. hkCurrentClass = HKEY_CURRENT_USER;
  435. break;
  436. case KEY_CATEGORY:
  437. fInCategory = TRUE;
  438. pCurrent = ReadKeyword( pCurrent, szKeyWord, ARRAYSIZE( szKeyWord ));
  439. pCurrent = GetQuotedText( pCurrent, szKeyWord, sizeof( szKeyWord ));
  440. CheckStrings( szKeyWord, pcszFileName );
  441. StrCpy( szCurrentCategory, szKeyWord );
  442. // patch for displaying the icon
  443. part[nParts].hkClass = hkCurrentClass;
  444. if(part[nParts].szCategory != NULL)
  445. LocalFree(part[nParts].szCategory);
  446. part[nParts].szCategory = NULL;
  447. part[nParts].szCategory = StrDup(szCurrentCategory);
  448. part[nParts].nType = PART_ERROR;
  449. break;
  450. case KEY_END:
  451. pCurrent = ReadKeyword( pCurrent, szKeyWord, ARRAYSIZE( szKeyWord ));
  452. switch( GetKeyName( szKeyWord ))
  453. {
  454. case KEY_PART:
  455. if(fInPart)
  456. {
  457. if(part[nParts].nType != PART_TEXT && part[nParts].nType != PART_ERROR)
  458. {
  459. if(part[nParts].value.szKeyname != NULL)
  460. LocalFree(part[nParts].value.szKeyname);
  461. part[nParts].value.szKeyname = NULL;
  462. if( ISNONNULL( szRegKey[NPART] ))
  463. {
  464. part[nParts].value.szKeyname = StrDup(szRegKey[NPART]);
  465. memset( szRegKey[NPART], 0, sizeof( szRegKey[NPART] ));
  466. }
  467. else if( ISNONNULL( szRegKey[NPOLICY] ))
  468. part[nParts].value.szKeyname = StrDup(szRegKey[NPOLICY]);
  469. else if( ISNONNULL( szRegKey[NCATEGORY] ))
  470. part[nParts].value.szKeyname = StrDup(szRegKey[NCATEGORY]);
  471. if(part[nParts].value.szValueName != NULL)
  472. LocalFree(part[nParts].value.szValueName);
  473. part[nParts].value.szValueName = NULL;
  474. part[nParts].value.szValueName = StrDup(szValueName);
  475. // using szDefaultValue variable as the storage for holding the policy key for
  476. // part as a listbox only
  477. if((lstrlen(szRegKey[NPOLICY]) || lstrlen(szRegKey[NCATEGORY])) && part[nParts].nType == PART_LISTBOX)
  478. {
  479. if(part[nParts].szDefaultValue != NULL)
  480. LocalFree(part[nParts].szDefaultValue);
  481. part[nParts].szDefaultValue = NULL;
  482. if(ISNONNULL(szRegKey[NPOLICY]))
  483. part[nParts].szDefaultValue = StrDup(szRegKey[NPOLICY]);
  484. else
  485. part[nParts].szDefaultValue = StrDup(szRegKey[NCATEGORY]);
  486. }
  487. }
  488. if(nActions)
  489. {
  490. if(!AllocateActions(&actionlist, nActions, REALLOCATE))
  491. bContinue = FALSE;
  492. else
  493. part[nParts].actionlist = &actionlist[0];
  494. }
  495. if(nSuggestions)
  496. {
  497. if(!AllocateSuggestions(&suggestions, nSuggestions, REALLOCATE))
  498. bContinue = FALSE;
  499. else
  500. part[nParts].suggestions = &suggestions[0];
  501. }
  502. nParts++;
  503. if(nParts >= nPartsAlloc)
  504. {
  505. nPartsAlloc += 50;
  506. lpTemp = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, part, sizeof(PART) * nPartsAlloc);
  507. if(lpTemp == NULL)
  508. bContinue = FALSE;
  509. else
  510. part = (LPPART) lpTemp;
  511. }
  512. memset(szRegKey[NACTIONLIST], 0, sizeof( szRegKey[NACTIONLIST]));
  513. fInPart = FALSE;
  514. }
  515. break;
  516. case KEY_POLICY:
  517. if(fInPolicy)
  518. {
  519. if(part[nPolicyPart].fRequired == TRUE)
  520. {
  521. if(part[nPolicyPart].value.szKeyname != NULL)
  522. LocalFree(part[nPolicyPart].value.szKeyname);
  523. part[nPolicyPart].value.szKeyname = NULL;
  524. if( ISNONNULL( szRegKey[NPOLICY] ))
  525. part[nPolicyPart].value.szKeyname = StrDup(szRegKey[NPOLICY]);
  526. else if( ISNONNULL( szRegKey[NCATEGORY] ))
  527. part[nPolicyPart].value.szKeyname = StrDup(szRegKey[NCATEGORY]);
  528. if(part[nPolicyPart].value.szValueName != NULL)
  529. LocalFree(part[nPolicyPart].value.szValueName);
  530. part[nPolicyPart].value.szValueName = NULL;
  531. part[nPolicyPart].value.szValueName = StrDup(szValueName);
  532. part[nPolicyPart].value.nValueOn = nValueOn;
  533. part[nPolicyPart].value.nValueOff = nValueOff;
  534. if(*szValueOn != TEXT('\0'))
  535. {
  536. if(part[nPolicyPart].value.szValueOn != NULL)
  537. LocalFree(part[nPolicyPart].value.szValueOn);
  538. part[nPolicyPart].value.szValueOn = NULL;
  539. part[nPolicyPart].value.szValueOn = StrDup(szValueOn);
  540. }
  541. if(*szValueOff != TEXT('\0'))
  542. {
  543. if(part[nPolicyPart].value.szValueOff != NULL)
  544. LocalFree(part[nPolicyPart].value.szValueOff);
  545. part[nPolicyPart].value.szValueOff = NULL;
  546. part[nPolicyPart].value.szValueOff = StrDup(szValueOff);
  547. }
  548. }
  549. memset(szRegKey[NACTIONLIST], 0, sizeof(szRegKey[NACTIONLIST]));
  550. memset( szRegKey[NPART], 0, sizeof( szRegKey[NPART] ));
  551. memset( szRegKey[NPOLICY], 0, sizeof( szRegKey[NPOLICY] ));
  552. nPolicyPart = -1;
  553. fInPolicy = FALSE;
  554. }
  555. break;
  556. case KEY_CATEGORY:
  557. if(fInCategory)
  558. {
  559. memset(szRegKey[NACTIONLIST], 0, sizeof(szRegKey[NACTIONLIST]));
  560. memset( szRegKey[NPART], 0, sizeof( szRegKey[NPART] ));
  561. memset( szRegKey[NPOLICY], 0, sizeof( szRegKey[NPOLICY] ));
  562. memset( szRegKey[NCATEGORY], 0, sizeof( szRegKey[NCATEGORY] ));
  563. fInCategory = FALSE;
  564. }
  565. break;
  566. case KEY_ACTIONLIST:
  567. case KEY_ACTIONLISTOFF:
  568. case KEY_ACTIONLISTON:
  569. if(fInActionList)
  570. {
  571. if(nValues)
  572. {
  573. if(!AllocateValues(&value, nValues, REALLOCATE))
  574. bContinue = FALSE;
  575. else
  576. {
  577. part[nParts].actionlist[part[nParts].nActions - 1].value = &value[0];
  578. nValuesAlloc = nValues;
  579. }
  580. }
  581. memset(szRegKey[NACTIONLIST], 0, sizeof(szRegKey[NACTIONLIST]));
  582. fInActionList = FALSE;
  583. }
  584. break;
  585. case KEY_ITEMLIST:
  586. fInItemList = FALSE;
  587. }
  588. break;
  589. case KEY_ACTIONLISTON:
  590. case KEY_ACTIONLISTOFF:
  591. if (part[nParts].nType == PART_CHECKBOX)
  592. {
  593. fInActionList = TRUE;
  594. nActionListType = (nKeyValue == KEY_ACTIONLISTOFF) ? 0 : 1;
  595. if(part[nParts].nActions == 0)
  596. {
  597. nActionsAlloc = 1;
  598. if(!AllocateActions(&actionlist, nActionsAlloc, ALLOCATE))
  599. bContinue = FALSE;
  600. else
  601. part[nParts].actionlist = &actionlist[0];
  602. part[nParts].nActions++;
  603. nActions++;
  604. nValues = 0;
  605. nValuesAlloc = 0;
  606. value = NULL;
  607. }
  608. }
  609. break;
  610. case KEY_ACTIONLIST:
  611. if (fInItemList)
  612. fInActionList = TRUE;
  613. break;
  614. case KEY_ITEMLIST:
  615. if (fInPart)
  616. fInItemList = TRUE;
  617. break;
  618. case KEY_MAXLEN:
  619. if(part[nParts].nType == PART_EDITTEXT)
  620. {
  621. pCurrent = ReadKeyword( pCurrent, szKeyWord, ARRAYSIZE( szKeyWord ));
  622. part[nParts].nMax = StrToInt( szKeyWord );
  623. if (part[nParts].nMax > MAX_EDITTEXTLEN)
  624. part[nParts].nMax = MAX_EDITTEXTLEN;
  625. }
  626. break;
  627. case KEY_MIN:
  628. if(part[nParts].nType == PART_NUMERIC)
  629. {
  630. pCurrent = ReadKeyword( pCurrent, szKeyWord, ARRAYSIZE( szKeyWord ));
  631. part[nParts].nMin = StrToInt( szKeyWord );
  632. }
  633. break;
  634. case KEY_MAX:
  635. if(part[nParts].nType == PART_NUMERIC)
  636. {
  637. pCurrent = ReadKeyword( pCurrent, szKeyWord, ARRAYSIZE( szKeyWord ));
  638. part[nParts].nMax = StrToInt( szKeyWord );
  639. }
  640. break;
  641. case KEY_SPIN:
  642. if(part[nParts].nType == PART_NUMERIC)
  643. {
  644. pCurrent = ReadKeyword( pCurrent, szKeyWord, ARRAYSIZE( szKeyWord ));
  645. part[nParts].nSpin = StrToInt( szKeyWord );
  646. }
  647. break;
  648. case KEY_DEFCHECKED:
  649. if(part[nParts].nType == PART_CHECKBOX)
  650. part[nParts].nDefault = 1;
  651. else if(!fInPart && fInPolicy)
  652. part[nParts - 1].nDefault = 1;
  653. break;
  654. case KEY_DEFAULT:
  655. if( part[nParts].nType == PART_NUMERIC)
  656. {
  657. pCurrent = ReadKeyword( pCurrent, szKeyWord, ARRAYSIZE( szKeyWord ));
  658. part[nParts].nDefault = StrToInt( szKeyWord );
  659. }
  660. else if( part[nParts].nType == PART_EDITTEXT || part[nParts].nType == PART_COMBOBOX)
  661. {
  662. pCurrent = ReadKeyword( pCurrent, szKeyWord, ARRAYSIZE( szKeyWord ));
  663. pCurrent = GetQuotedText( pCurrent, szKeyWord, sizeof( szKeyWord ));
  664. CheckStrings( szKeyWord, pcszFileName );
  665. if(part[nParts].szDefaultValue != NULL)
  666. LocalFree(part[nParts].szDefaultValue);
  667. part[nParts].szDefaultValue = NULL;
  668. part[nParts].szDefaultValue = StrDup(szKeyWord);
  669. }
  670. else if(part[nParts].nType == PART_DROPDOWNLIST)
  671. {
  672. if(part[nParts].szDefaultValue != NULL)
  673. LocalFree(part[nParts].szDefaultValue);
  674. part[nParts].szDefaultValue = NULL;
  675. if(part[nParts].nActions != 0 && part[nParts].actionlist[part[nParts].nActions - 1].szName != NULL)
  676. part[nParts].szDefaultValue = StrDup(part[nParts].actionlist[part[nParts].nActions - 1].szName);
  677. }
  678. break;
  679. case KEY_PART:
  680. if(fInPolicy)
  681. {
  682. fInPart = TRUE;
  683. // read the name of the part
  684. pCurrent = ReadKeyword( pCurrent, szKeyWord, ARRAYSIZE( szKeyWord ));
  685. pCurrent = GetQuotedText( pCurrent, szKeyWord, sizeof( szKeyWord ));
  686. CheckStrings( szKeyWord, pcszFileName );
  687. if(part[nParts].szName != NULL)
  688. LocalFree(part[nParts].szName);
  689. part[nParts].szName = NULL;
  690. part[nParts].szName = StrDup(szKeyWord);
  691. // read the type of the part
  692. pCurrent = ReadKeyword( pCurrent, szKeyWord, ARRAYSIZE( szKeyWord ));
  693. part[nParts].nType = GetPartName( szKeyWord );
  694. if(part[nParts].nType != PART_TEXT && part[nParts].nType != PART_ERROR && nPolicyPart != -1)
  695. part[nPolicyPart].fRequired = FALSE;
  696. part[nParts].hkClass = hkCurrentClass;
  697. if(part[nParts].szCategory != NULL)
  698. LocalFree(part[nParts].szCategory);
  699. part[nParts].szCategory = NULL;
  700. part[nParts].szCategory = StrDup(szCurrentCategory);
  701. part[nParts].nLine = g_nLine;
  702. part[nParts].nMax = MAX_NUMERIC;
  703. if (part[nParts].nType == PART_EDITTEXT)
  704. part[nParts].nMax = MAX_PATH;
  705. if(part[nParts].nType == PART_CHECKBOX)
  706. {
  707. part[nParts].value.nValueOn = nValueOn;
  708. part[nParts].value.nValueOff = nValueOff;
  709. if(*szValueOn != 0)
  710. {
  711. if(part[nParts].value.szValueOn != NULL)
  712. LocalFree(part[nParts].value.szValueOn);
  713. part[nParts].value.szValueOn = NULL;
  714. part[nParts].value.szValueOn = StrDup(szValueOn);
  715. }
  716. if(*szValueOff != 0)
  717. {
  718. if(part[nParts].value.szValueOff != NULL)
  719. LocalFree(part[nParts].value.szValueOff);
  720. part[nParts].value.szValueOff = NULL;
  721. part[nParts].value.szValueOff = StrDup(szValueOff);
  722. }
  723. }
  724. nActionsAlloc = 0;
  725. nActions = 0;
  726. actionlist = NULL;
  727. nSuggestions = 0;
  728. nSuggestionsAlloc = 0;
  729. suggestions = NULL;
  730. }
  731. break;
  732. case KEY_POLICY:
  733. if(fInCategory)
  734. {
  735. fInPolicy = TRUE;
  736. nPolicyPart = nParts;
  737. part[nParts].fRequired = TRUE;
  738. memset(szValueOn, 0, sizeof(szValueOn));
  739. memset(szValueOff, 0, sizeof(szValueOff));
  740. nValueOn = 1;
  741. nValueOff = 0;
  742. pCurrent = ReadKeyword( pCurrent, szKeyWord, ARRAYSIZE( szKeyWord ));
  743. pCurrent = GetQuotedText( pCurrent, szKeyWord, sizeof( szKeyWord ));
  744. CheckStrings( szKeyWord, pcszFileName );
  745. // to display policy name, add as a text
  746. if(part[nParts].szName != NULL)
  747. LocalFree(part[nParts].szName);
  748. part[nParts].szName = NULL;
  749. part[nParts].szName = StrDup(szKeyWord);
  750. part[nParts].nType = GetPartName( TEXT("POLICY") );
  751. part[nParts].hkClass = hkCurrentClass;
  752. if(part[nParts].szCategory != NULL)
  753. LocalFree(part[nParts].szCategory);
  754. part[nParts].szCategory = NULL;
  755. part[nParts].szCategory = StrDup(szCurrentCategory);
  756. part[nParts].nLine = g_nLine;
  757. nParts++;
  758. if(nParts >= nPartsAlloc)
  759. {
  760. nPartsAlloc += 50;
  761. lpTemp = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, part, sizeof(PART) * nPartsAlloc);
  762. if(lpTemp == NULL)
  763. bContinue = FALSE;
  764. else
  765. part = (LPPART) lpTemp;
  766. }
  767. }
  768. break;
  769. case KEY_NAME:
  770. if(fInItemList)
  771. {
  772. pCurrent = ReadKeyword( pCurrent, szKeyWord, ARRAYSIZE( szKeyWord ));
  773. pCurrent = GetQuotedText( pCurrent, szKeyWord, sizeof( szKeyWord ));
  774. CheckStrings( szKeyWord, pcszFileName );
  775. if(part[nParts].nActions == 0)
  776. {
  777. nActionsAlloc = 10;
  778. if(!AllocateActions(&actionlist, nActionsAlloc, ALLOCATE))
  779. bContinue = FALSE;
  780. else
  781. part[nParts].actionlist = &actionlist[0];
  782. }
  783. if(part[nParts].actionlist[part[nParts].nActions].szName != NULL)
  784. LocalFree(part[nParts].actionlist[part[nParts].nActions].szName);
  785. part[nParts].actionlist[part[nParts].nActions].szName = NULL;
  786. part[nParts].actionlist[part[nParts].nActions].szName = StrDup(szKeyWord);
  787. part[nParts].nActions++;
  788. nActions++;
  789. if(nActions >= nActionsAlloc)
  790. {
  791. nActionsAlloc += 10;
  792. if(!AllocateActions(&actionlist, nActionsAlloc, REALLOCATE))
  793. bContinue = FALSE;
  794. else
  795. part[nParts].actionlist = &actionlist[0];
  796. }
  797. nValues = 0;
  798. nValuesAlloc = 0;
  799. value = NULL;
  800. }
  801. break;
  802. case KEY_KEYNAME:
  803. pCurrent = ReadKeyword( pCurrent, szKeyWord, ARRAYSIZE( szKeyWord ));
  804. pCurrent = GetQuotedText( pCurrent, szKeyWord, sizeof( szKeyWord ));
  805. if( fInActionList )
  806. {
  807. StrCpy( szRegKey[NACTIONLIST], szKeyWord );
  808. break;
  809. }
  810. if( fInPart )
  811. {
  812. StrCpy( szRegKey[NPART], szKeyWord );
  813. break;
  814. }
  815. if( fInPolicy )
  816. {
  817. StrCpy( szRegKey[NPOLICY], szKeyWord );
  818. break;
  819. }
  820. if( fInCategory )
  821. {
  822. StrCpy( szRegKey[NCATEGORY], szKeyWord );
  823. break;
  824. }
  825. break;
  826. case KEY_VALUENAME:
  827. if( fInActionList )
  828. {
  829. if(part[nParts].nActions == 0)
  830. break;
  831. pCurrent = ReadKeyword( pCurrent, szKeyWord, ARRAYSIZE( szKeyWord ));
  832. pCurrent = GetQuotedText( pCurrent, szKeyWord, sizeof( szKeyWord ));
  833. // put the pointer to the current value into the actionlist
  834. if( part[nParts].actionlist[part[nParts].nActions - 1].nValues == 0)
  835. {
  836. nValuesAlloc = 10;
  837. if(!AllocateValues(&value, nValuesAlloc, ALLOCATE))
  838. bContinue = FALSE;
  839. else
  840. part[nParts].actionlist[part[nParts].nActions - 1].value = &value[0];
  841. }
  842. else if (nValues >= nValuesAlloc)
  843. {
  844. nValuesAlloc += 10;
  845. if(!AllocateValues(&value, nValuesAlloc, REALLOCATE))
  846. bContinue = FALSE;
  847. else
  848. part[nParts].actionlist[part[nParts].nActions - 1].value = &value[0];
  849. }
  850. if(value[nValues].szValueName != NULL)
  851. LocalFree(value[nValues].szValueName);
  852. value[nValues].szValueName = NULL;
  853. value[nValues].szValueName = StrDup(szKeyWord);
  854. if(value[nValues].szKeyname != NULL)
  855. LocalFree(value[nValues].szKeyname);
  856. value[nValues].szKeyname = NULL;
  857. if( ISNONNULL( szRegKey[NACTIONLIST] ))
  858. value[nValues].szKeyname = StrDup(szRegKey[NACTIONLIST]);
  859. else if( ISNONNULL( szRegKey[NPART] ))
  860. value[nValues].szKeyname = StrDup(szRegKey[NPART]);
  861. else if( ISNONNULL( szRegKey[NPOLICY] ))
  862. value[nValues].szKeyname = StrDup(szRegKey[NPOLICY]);
  863. else if( ISNONNULL( szRegKey[NCATEGORY] ))
  864. value[nValues].szKeyname = StrDup(szRegKey[NCATEGORY]);
  865. part[nParts].actionlist[part[nParts].nActions - 1].nValues++;
  866. pCurrent = ReadValue( pCurrent, &value[0], nValues, pcszFileName );
  867. if (part[nParts].nType == PART_CHECKBOX)
  868. value[nValues].nValueOn = nActionListType; // nValueOn is used as a buffer to hold the ACTIONLISTOFF/ON type.
  869. nValues++;
  870. break;
  871. }
  872. if( fInPolicy || fInPart )
  873. {
  874. pCurrent = ReadKeyword( pCurrent, szKeyWord, ARRAYSIZE( szKeyWord ));
  875. pCurrent = GetQuotedText( pCurrent, szKeyWord, sizeof( szKeyWord ));
  876. StrCpy( szValueName, szKeyWord );
  877. break;
  878. }
  879. break;
  880. case KEY_SUGGESTIONS:
  881. if(fInPart)
  882. {
  883. while( StrCmp( szKeyWord, TEXT("END") ) != 0 && bContinue == TRUE)
  884. {
  885. pCurrent = ReadKeyword( pCurrent, szKeyWord, ARRAYSIZE( szKeyWord ));
  886. pCurrent = GetQuotedText( pCurrent, szKeyWord, sizeof( szKeyWord ));
  887. CheckStrings( szKeyWord, pcszFileName );
  888. if( StrCmp( szKeyWord, TEXT("END") ) != 0 )
  889. {
  890. if(part[nParts].nSuggestions == 0)
  891. {
  892. nSuggestionsAlloc = 10;
  893. if(!AllocateSuggestions(&suggestions, nSuggestionsAlloc, ALLOCATE))
  894. bContinue = FALSE;
  895. else
  896. part[nParts].suggestions = &suggestions[0];
  897. }
  898. if(suggestions[nSuggestions].szText != NULL)
  899. LocalFree(suggestions[nSuggestions].szText);
  900. suggestions[nSuggestions].szText = NULL;
  901. suggestions[nSuggestions].szText = StrDup(szKeyWord);
  902. part[nParts].nSuggestions++;
  903. nSuggestions++;
  904. if(nSuggestions >= nSuggestionsAlloc)
  905. {
  906. nSuggestionsAlloc += 10;
  907. if(!AllocateSuggestions(&suggestions, nSuggestionsAlloc, REALLOCATE))
  908. bContinue = FALSE;
  909. else
  910. part[nParts].suggestions = &suggestions[0];
  911. }
  912. }
  913. }
  914. // throw out the word "suggestions"
  915. pCurrent = ReadKeyword( pCurrent, szKeyWord, ARRAYSIZE( szKeyWord ));
  916. }
  917. break;
  918. case KEY_VALUEON:
  919. case KEY_VALUEOFF:
  920. if(fInPolicy || fInPart)
  921. {
  922. pCurrent = ReadKeyword( pCurrent, szKeyWord, ARRAYSIZE( szKeyWord ));
  923. //pCurrent = GetQuotedText( pCurrent, szKeyWord, sizeof( szKeyWord ));
  924. //CheckStrings( szKeyWord, pcszFileName );
  925. if( StrCmp( szKeyWord, TEXT("NUMERIC") ) == 0 )
  926. {
  927. pCurrent = ReadKeyword( pCurrent, szKeyWord, ARRAYSIZE( szKeyWord ));
  928. if(nKeyValue == KEY_VALUEON)
  929. {
  930. if(!fInPart)
  931. nValueOn = StrToInt( szKeyWord );
  932. else if(fInPart && part[nParts].nType == PART_CHECKBOX)
  933. {
  934. part[nParts].value.nValueOn = StrToInt( szKeyWord );
  935. if(part[nParts].value.szValueOn != NULL)
  936. LocalFree(part[nParts].value.szValueOn);
  937. part[nParts].value.szValueOn = NULL;
  938. }
  939. }
  940. else
  941. {
  942. if(!fInPart)
  943. nValueOff = StrToInt( szKeyWord );
  944. else if(fInPart && part[nParts].nType == PART_CHECKBOX)
  945. {
  946. part[nParts].value.nValueOff = StrToInt( szKeyWord );
  947. if(part[nParts].value.szValueOff != NULL)
  948. LocalFree(part[nParts].value.szValueOff);
  949. part[nParts].value.szValueOff = NULL;
  950. }
  951. }
  952. }
  953. else
  954. {
  955. if( StrCmp( szKeyWord, TEXT("TEXT") ) == 0 )
  956. pCurrent = ReadKeyword( pCurrent, szKeyWord, ARRAYSIZE( szKeyWord ));
  957. pCurrent = GetQuotedText( pCurrent, szKeyWord, sizeof( szKeyWord ));
  958. CheckStrings( szKeyWord, pcszFileName );
  959. if(nKeyValue == KEY_VALUEON)
  960. {
  961. if(!fInPart)
  962. StrCpy(szValueOn, szKeyWord);
  963. else if(fInPart && part[nParts].nType == PART_CHECKBOX)
  964. {
  965. if(part[nParts].value.szValueOn != NULL)
  966. LocalFree(part[nParts].value.szValueOn);
  967. part[nParts].value.szValueOn = NULL;
  968. part[nParts].value.szValueOn = StrDup(szKeyWord);
  969. }
  970. }
  971. else
  972. {
  973. if (!fInPart)
  974. StrCpy(szValueOff, szKeyWord);
  975. else if (fInPart && part[nParts].nType == PART_CHECKBOX)
  976. {
  977. if(part[nParts].value.szValueOff != NULL)
  978. LocalFree(part[nParts].value.szValueOff);
  979. part[nParts].value.szValueOff = NULL;
  980. part[nParts].value.szValueOff = StrDup(szKeyWord);
  981. }
  982. }
  983. }
  984. }
  985. break;
  986. case KEY_VALUE:
  987. if(fInItemList)
  988. {
  989. pCurrent = ReadKeyword( pCurrent, szKeyWord, ARRAYSIZE( szKeyWord ));
  990. //pCurrent = GetQuotedText( pCurrent, szKeyWord, sizeof( szKeyWord ));
  991. //CheckStrings( szKeyWord, pcszFileName );
  992. part[nParts].actionlist[(part[nParts].nActions) - 1].dwValue = 0;
  993. if(part[nParts].actionlist[(part[nParts].nActions) - 1].szValue != NULL)
  994. LocalFree(part[nParts].actionlist[(part[nParts].nActions) - 1].szValue);
  995. part[nParts].actionlist[(part[nParts].nActions) - 1].szValue = NULL;
  996. if( StrCmp( szKeyWord, TEXT("NUMERIC") ) == 0 )
  997. {
  998. pCurrent = ReadKeyword( pCurrent, szKeyWord, ARRAYSIZE( szKeyWord ));
  999. part[nParts].actionlist[(part[nParts].nActions) - 1].dwValue = StrToInt( szKeyWord );
  1000. }
  1001. else
  1002. {
  1003. if( StrCmp( szKeyWord, TEXT("TEXT") ) == 0 )
  1004. pCurrent = ReadKeyword( pCurrent, szKeyWord, ARRAYSIZE( szKeyWord ));
  1005. pCurrent = GetQuotedText( pCurrent, szKeyWord, sizeof( szKeyWord ));
  1006. CheckStrings( szKeyWord, pcszFileName );
  1007. part[nParts].actionlist[(part[nParts].nActions) - 1].szValue = StrDup( szKeyWord );
  1008. }
  1009. }
  1010. break;
  1011. case KEY_IF:
  1012. pCurrent = ReadKeyword(pCurrent, szKeyWord, ARRAYSIZE(szKeyWord));
  1013. if (KEY_VERSION == GetKeyName(szKeyWord))
  1014. {
  1015. int nVersion = 0;
  1016. fSkip = FALSE;
  1017. // get the operator keyword
  1018. pCurrent = ReadKeyword(pCurrent, szKeyWord, ARRAYSIZE(szKeyWord));
  1019. nKeyValue = GetKeyName(szKeyWord);
  1020. // get the version number
  1021. pCurrent = ReadKeyword(pCurrent, szKeyWord, ARRAYSIZE(szKeyWord));
  1022. nVersion = StrToInt(szKeyWord);
  1023. switch (nKeyValue)
  1024. {
  1025. case KEY_LT:
  1026. case KEY_LTE:
  1027. break;
  1028. case KEY_GT:
  1029. if (ADM_VERSION <= nVersion)
  1030. fSkip = TRUE;
  1031. break;
  1032. case KEY_GTE:
  1033. if (ADM_VERSION < nVersion)
  1034. fSkip = TRUE;
  1035. break;
  1036. }
  1037. }
  1038. break;
  1039. case KEY_ENDIF:
  1040. fSkip = FALSE;
  1041. break;
  1042. }
  1043. }
  1044. while( lstrlen( pCurrent ) && bContinue);
  1045. if (bContinue == FALSE)
  1046. {
  1047. FreeAdmMemory( admfile );
  1048. SetLastError( ERROR_NOT_ENOUGH_MEMORY );
  1049. }
  1050. else
  1051. {
  1052. admfile->pParts = part;
  1053. admfile->nParts = nParts;
  1054. StrCpy(admfile->szFilename, pcszFileName);
  1055. }
  1056. // clean up
  1057. LocalFree( hFileMem );
  1058. return bContinue;
  1059. }
  1060. #define MAX_REGLINE 1024
  1061. BOOL CopyData(LPTSTR pData, int* pnData, int* pnCopyIndex, LPTSTR szTmpData)
  1062. {
  1063. LPVOID lpTemp = NULL;
  1064. if ((*pnCopyIndex + lstrlen(szTmpData) + 1) > ((*pnData) - 1))
  1065. {
  1066. (*pnData) += MAX_REGLINE;
  1067. lpTemp = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, pData, StrCbFromCch(*pnData));
  1068. if (lpTemp == NULL)
  1069. return FALSE;
  1070. else
  1071. pData = (LPTSTR) lpTemp;
  1072. }
  1073. CopyMemory(pData + *pnCopyIndex, szTmpData, StrCbFromSz(szTmpData));
  1074. (*pnCopyIndex) += lstrlen(szTmpData);
  1075. // skip over one byte so our list is 0 separated
  1076. (*pnCopyIndex)++;
  1077. return TRUE;
  1078. }
  1079. //--------------------------------------------------------------------------
  1080. // W R I T E I N F F I L E Exported Function
  1081. //
  1082. // Creates an .inf file from a PART array.
  1083. //--------------------------------------------------------------------------
  1084. void WriteInfFile( LPADMFILE admfile, LPCTSTR pcszFileName, LPPARTDATA pData )
  1085. {
  1086. LPPART part;
  1087. int nParts;
  1088. TCHAR szClassString[5];
  1089. TCHAR szTmpData[MAX_REGLINE];
  1090. int i, j;
  1091. BOOL bContinue = TRUE;
  1092. TCHAR szValueText[1024];
  1093. DWORD dwValue;
  1094. TCHAR szKeyName[MAX_PATH];
  1095. BOOL fWrite = FALSE;
  1096. LPTSTR pHKLMData, pHKCUData;
  1097. int nHKLMCopyIndex = 0,
  1098. nHKCUCopyIndex = 0,
  1099. nHKLMData = ((admfile->nParts + 1) * MAX_REGLINE),
  1100. nHKCUData = ((admfile->nParts + 1) * MAX_REGLINE);
  1101. // allocate memory for the .inf section
  1102. pHKLMData = (LPTSTR) HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, StrCbFromCch(nHKLMData));
  1103. pHKCUData = (LPTSTR) HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, StrCbFromCch(nHKCUData));
  1104. if (pHKLMData == NULL || pHKCUData == NULL)
  1105. return;
  1106. part = (LPPART) admfile->pParts;
  1107. nParts = admfile->nParts;
  1108. // loop through parts, adding each one to the inf section
  1109. for( i = 0; (i < nParts) && bContinue; i++ )
  1110. {
  1111. if (!pData[i].fSave)
  1112. continue;
  1113. fWrite = TRUE;
  1114. if( (pData[i].value.szValue != NULL && lstrlen( pData[i].value.szValue ) > 0) ||
  1115. (pData[i].value.fNumeric == TRUE) )
  1116. {
  1117. // get the class
  1118. if( part[i].hkClass == HKEY_LOCAL_MACHINE )
  1119. StrCpy( szClassString, TEXT("HKLM") );
  1120. else
  1121. StrCpy( szClassString, TEXT("HKCU") );
  1122. ZeroMemory(szTmpData, sizeof(szTmpData));
  1123. if( !pData[i].value.fNumeric ) // value is a string
  1124. {
  1125. ZeroMemory(szValueText, sizeof(szValueText));
  1126. if(part[i].nType == PART_DROPDOWNLIST)
  1127. {
  1128. if(pData[i].nSelectedAction != NO_ACTION && part[i].nActions > 0)
  1129. {
  1130. LPACTIONLIST action = &part[i].actionlist[pData[i].nSelectedAction];
  1131. if(action->szValue != NULL)
  1132. StrCpy(szValueText, action->szValue);
  1133. else
  1134. {
  1135. if(part[i].value.szKeyname != NULL && part[i].value.szValueName != NULL)
  1136. {
  1137. if ((lstrlen(szClassString) + lstrlen(part[i].value.szKeyname) +
  1138. lstrlen(part[i].value.szValueName) + 27) < MAX_REGLINE)
  1139. wnsprintf(szTmpData, ARRAYSIZE(szTmpData), TEXT("%s,\"%s\",\"%s\",0x10001,%x,%x,%x,%x"), szClassString,
  1140. part[i].value.szKeyname, part[i].value.szValueName,
  1141. LOBYTE(LOWORD(action->dwValue)),
  1142. HIBYTE(LOWORD(action->dwValue)),
  1143. LOBYTE(HIWORD(action->dwValue)),
  1144. HIBYTE(HIWORD(action->dwValue)));
  1145. }
  1146. }
  1147. }
  1148. }
  1149. else
  1150. StrCpy(szValueText, pData[i].value.szValue);
  1151. if(part[i].value.szKeyname != NULL && part[i].value.szValueName != NULL && ISNONNULL(szValueText))
  1152. {
  1153. if ((lstrlen(szClassString) + lstrlen(part[i].value.szKeyname) + lstrlen(part[i].value.szValueName) +
  1154. lstrlen(szValueText) + 12) < MAX_REGLINE)
  1155. wnsprintf(szTmpData, ARRAYSIZE(szTmpData), TEXT("%s,\"%s\",\"%s\",0,\"%s\""), szClassString,
  1156. part[i].value.szKeyname, part[i].value.szValueName,
  1157. szValueText);
  1158. }
  1159. }
  1160. else // value is a dword
  1161. {
  1162. if(((part[i].nType == PART_POLICY && part->fRequired) || part[i].nType == PART_CHECKBOX) &&
  1163. (part[i].value.szValueOn != NULL))
  1164. {
  1165. if(pData[i].value.dwValue != 0)
  1166. StrCpy(szValueText, part[i].value.szValueOn);
  1167. else
  1168. StrCpy(szValueText, part[i].value.szValueOff);
  1169. if(part[i].value.szKeyname != NULL && part[i].value.szValueName != NULL)
  1170. {
  1171. if ((lstrlen(szClassString) + lstrlen(part[i].value.szKeyname) + lstrlen(part[i].value.szValueName) +
  1172. lstrlen(szValueText) + 12) < MAX_REGLINE)
  1173. wnsprintf(szTmpData, ARRAYSIZE(szTmpData), TEXT("%s,\"%s\",\"%s\",0,\"%s\""), szClassString,
  1174. part[i].value.szKeyname, part[i].value.szValueName,
  1175. szValueText);
  1176. }
  1177. }
  1178. else
  1179. {
  1180. if((part[i].nType == PART_POLICY && part->fRequired) || part[i].nType == PART_CHECKBOX)
  1181. {
  1182. if(pData[i].value.dwValue != 0)
  1183. dwValue = part[i].value.nValueOn;
  1184. else
  1185. dwValue = part[i].value.nValueOff;
  1186. }
  1187. else
  1188. dwValue = pData[i].value.dwValue;
  1189. memset(szKeyName, 0, sizeof(szKeyName));
  1190. if(part[i].nType == PART_LISTBOX)
  1191. StrCpy(szKeyName, part[i].szDefaultValue);
  1192. else
  1193. StrCpy(szKeyName, part[i].value.szKeyname);
  1194. if(ISNONNULL(szKeyName) && part[i].value.szValueName != NULL)
  1195. {
  1196. if ((lstrlen(szClassString) + lstrlen(szKeyName) +
  1197. lstrlen(part[i].value.szValueName) + 27) < MAX_REGLINE)
  1198. wnsprintf(szTmpData, ARRAYSIZE(szTmpData), TEXT("%s,\"%s\",\"%s\",0x10001,%x,%x,%x,%x"), szClassString,
  1199. szKeyName, part[i].value.szValueName,
  1200. LOBYTE(LOWORD(dwValue)),
  1201. HIBYTE(LOWORD(dwValue)),
  1202. LOBYTE(HIWORD(dwValue)),
  1203. HIBYTE(HIWORD(dwValue)));
  1204. }
  1205. }
  1206. }
  1207. if(ISNONNULL(szTmpData))
  1208. {
  1209. if (part[i].hkClass == HKEY_LOCAL_MACHINE)
  1210. bContinue = CopyData(pHKLMData, &nHKLMData, &nHKLMCopyIndex, szTmpData);
  1211. else
  1212. bContinue = CopyData(pHKCUData, &nHKCUData, &nHKCUCopyIndex, szTmpData);
  1213. }
  1214. }
  1215. // check to see if there is an item in an actionlist selected
  1216. if( pData[i].nSelectedAction != NO_ACTION && (part[i].nActions > 0 || pData[i].nActions > 0))
  1217. {
  1218. LPACTIONLIST action = NULL;
  1219. if(part[i].nType == PART_LISTBOX)
  1220. action = &pData[i].actionlist[pData[i].nSelectedAction];
  1221. else
  1222. action = &part[i].actionlist[pData[i].nSelectedAction];
  1223. // get the class
  1224. if( part[i].hkClass == HKEY_LOCAL_MACHINE )
  1225. {
  1226. StrCpy( szClassString, TEXT("HKLM") );
  1227. }
  1228. else
  1229. {
  1230. StrCpy( szClassString, TEXT("HKCU") );
  1231. }
  1232. for( j = 0; j < action->nValues; j++ )
  1233. {
  1234. if (part[i].nType == PART_CHECKBOX && ((int)pData[i].value.dwValue) != action->value[j].nValueOn)
  1235. continue;
  1236. ZeroMemory(szTmpData, sizeof(szTmpData));
  1237. if( !action->value[j].fNumeric )
  1238. {
  1239. if(action->value[j].szKeyname != NULL && action->value[j].szValueName != NULL && action->value[j].szValue != NULL)
  1240. {
  1241. if ((lstrlen(szClassString) + lstrlen(action->value[j].szKeyname) + lstrlen(action->value[j].szValueName) +
  1242. lstrlen(action->value[j].szValue) + 12) < MAX_REGLINE)
  1243. wnsprintf(szTmpData, ARRAYSIZE(szTmpData), TEXT("%s,\"%s\",\"%s\",0,\"%s\""), szClassString,
  1244. action->value[j].szKeyname, action->value[j].szValueName,
  1245. action->value[j].szValue);
  1246. }
  1247. }
  1248. else // value is a dword
  1249. {
  1250. if(action->value[j].szKeyname != NULL && action->value[j].szValueName != NULL)
  1251. {
  1252. if ((lstrlen(szClassString) + lstrlen(action->value[j].szKeyname) +
  1253. lstrlen(action->value[j].szValueName) + 27) < MAX_REGLINE)
  1254. wnsprintf(szTmpData, ARRAYSIZE(szTmpData), TEXT("%s,\"%s\",\"%s\",0x10001,%x,%x,%x,%x"), szClassString,
  1255. action->value[j].szKeyname, action->value[j].szValueName,
  1256. LOBYTE(LOWORD(action->value[j].dwValue)),
  1257. HIBYTE(LOWORD(action->value[j].dwValue)),
  1258. LOBYTE(HIWORD(action->value[j].dwValue)),
  1259. HIBYTE(HIWORD(action->value[j].dwValue)));
  1260. }
  1261. }
  1262. if(ISNONNULL(szTmpData))
  1263. {
  1264. if (part[i].hkClass == HKEY_LOCAL_MACHINE)
  1265. bContinue = CopyData(pHKLMData, &nHKLMData, &nHKLMCopyIndex, szTmpData);
  1266. else
  1267. bContinue = CopyData(pHKCUData, &nHKCUData, &nHKCUCopyIndex, szTmpData);
  1268. }
  1269. }
  1270. }
  1271. }
  1272. if (fWrite)
  1273. {
  1274. // write default headers into the .inf file
  1275. InsWriteString( TEXT("Version"), TEXT("Signature"), TEXT("$CHICAGO$"), pcszFileName );
  1276. InsWriteString( TEXT("Version"), TEXT("SetupClass"), TEXT("Base"), pcszFileName );
  1277. InsWriteString( TEXT("DefaultInstall"), TEXT("AddReg"), TEXT("AddRegSection.HKLM,AddRegSection.HKCU"), pcszFileName );
  1278. InsWriteString( TEXT("DefaultInstall"), TEXT("RequiredEngine"), TEXT("Setupapi,\"missing setupapi.dll\""), pcszFileName );
  1279. InsWriteString( TEXT("DefaultInstall.HKLM"), TEXT("AddReg"), TEXT("AddRegSection.HKLM"), pcszFileName );
  1280. InsWriteString( TEXT("DefaultInstall.HKLM"), TEXT("RequiredEngine"), TEXT("Setupapi,\"missing setupapi.dll\""), pcszFileName );
  1281. InsWriteString( TEXT("IEAKInstall.HKLM"), TEXT("AddReg"), TEXT("AddRegSection.HKLM"), pcszFileName );
  1282. InsWriteString( TEXT("IEAKInstall.HKLM"), TEXT("RequiredEngine"), TEXT("Setupapi,\"missing setupapi.dll\""), pcszFileName );
  1283. InsWriteString( TEXT("DefaultInstall.HKCU"), TEXT("AddReg"), TEXT("AddRegSection.HKCU"), pcszFileName );
  1284. InsWriteString( TEXT("DefaultInstall.HKCU"), TEXT("RequiredEngine"), TEXT("Setupapi,\"missing setupapi.dll\""), pcszFileName );
  1285. InsWriteString( TEXT("IEAKInstall.HKCU"), TEXT("AddReg"), TEXT("AddRegSection.HKCU"), pcszFileName );
  1286. InsWriteString( TEXT("IEAKInstall.HKCU"), TEXT("RequiredEngine"), TEXT("Setupapi,\"missing setupapi.dll\""), pcszFileName );
  1287. InsDeleteSection( TEXT("AddRegSection"), pcszFileName );
  1288. InsDeleteSection( TEXT("AddRegSection.HKLM"), pcszFileName );
  1289. InsDeleteSection( TEXT("AddRegSection.HKCU"), pcszFileName );
  1290. WritePrivateProfileSection( TEXT("AddRegSection.HKLM"), pHKLMData, pcszFileName );
  1291. WritePrivateProfileSection( TEXT("AddRegSection.HKCU"), pHKCUData, pcszFileName );
  1292. InsFlushChanges(pcszFileName);
  1293. }
  1294. HeapFree(GetProcessHeap(), 0, pHKLMData);
  1295. HeapFree(GetProcessHeap(), 0, pHKCUData);
  1296. }
  1297. //--------------------------------------------------------------------------
  1298. // R E M O V E Q U O T E S
  1299. //
  1300. // Removes and quotes surrounding a string
  1301. //--------------------------------------------------------------------------
  1302. void RemoveQuotes( LPTSTR pText )
  1303. {
  1304. if( pText[0] == TEXT('\"') && pText[lstrlen(pText)-1] == TEXT('\"') )
  1305. {
  1306. memcpy( pText, &pText[1], (lstrlen( pText ) - 2) * sizeof(TCHAR) );
  1307. pText[lstrlen( pText ) - 2] = TEXT('\0');
  1308. }
  1309. }
  1310. //--------------------------------------------------------------------------
  1311. // R E A D H E X S T R
  1312. //
  1313. // Reads in a hex number from a string and converts it to an int
  1314. //--------------------------------------------------------------------------
  1315. int ReadHexStr( LPTSTR szStr )
  1316. {
  1317. int i,j; // counter
  1318. int n = 1; // multiplier
  1319. int num = 0; // return value
  1320. int tmp = 0; // temporary value
  1321. int nLen = lstrlen( szStr );
  1322. for( i = 0; i < nLen; i++ )
  1323. {
  1324. n = 1;
  1325. for( j = 0; j < (nLen - i - 1); j++ )
  1326. n *= 0x10;
  1327. if( szStr[i] >= TEXT('0') && szStr[i] <= TEXT('9') )
  1328. tmp = szStr[i] - TEXT('0');
  1329. if( szStr[i] >= TEXT('a') && szStr[i] <= TEXT('f') )
  1330. tmp = szStr[i] - TEXT('a') + 10;
  1331. if( szStr[i] >= TEXT('A') && szStr[i] <= TEXT('F') )
  1332. tmp = szStr[i] - TEXT('A') + 10;
  1333. tmp *= n;
  1334. num += tmp;
  1335. }
  1336. return num;
  1337. }
  1338. //--------------------------------------------------------------------------
  1339. // R E A D I N F F I L E Exported Function
  1340. //
  1341. // Reads an .inf file into a PART array
  1342. //--------------------------------------------------------------------------
  1343. void ReadInfFile( LPADMFILE admfile, LPCTSTR pcszFileName, LPPARTDATA pPartData )
  1344. {
  1345. LPPART part;
  1346. LPTSTR pData;
  1347. LPTSTR pCurrent;
  1348. VALUE value;
  1349. HKEY hkClass;
  1350. TCHAR szClass[10];
  1351. TCHAR szType[10];
  1352. TCHAR szValue[MAX_PATH + 1];
  1353. int i;
  1354. int nSize;
  1355. int nIndex;
  1356. if( !FileExists( pcszFileName ))
  1357. return; // bug bug
  1358. part = admfile->pParts;
  1359. // allocate 32KB for GetPrivateProfileSection
  1360. pData = (LPTSTR) LocalAlloc( LPTR, (MAX_NUMERIC + 1) * sizeof(TCHAR) );
  1361. if (pData == NULL)
  1362. return;
  1363. nSize = GetPrivateProfileSection( TEXT("AddRegSection"), pData, MAX_NUMERIC, pcszFileName );
  1364. if( nSize == 0 )
  1365. {
  1366. nSize = GetPrivateProfileSection( TEXT("AddRegSection.HKLM"), pData, MAX_NUMERIC, pcszFileName );
  1367. nSize += GetPrivateProfileSection( TEXT("AddRegSection.HKCU"), pData + nSize, MAX_NUMERIC - nSize, pcszFileName );
  1368. if (nSize == 0)
  1369. {
  1370. LocalFree((HGLOBAL)pData);
  1371. return; // bug bug
  1372. }
  1373. }
  1374. // convert all zeros to newlines
  1375. for( i = 0; i < nSize; i++ )
  1376. {
  1377. if( pData[i] == TEXT('\0') )
  1378. {
  1379. pData[i] = TEXT('\n');
  1380. }
  1381. }
  1382. pCurrent = pData;
  1383. while( pCurrent < pData + nSize - 2 )
  1384. {
  1385. memset( &value, 0, sizeof( value ));
  1386. // read one line from the section
  1387. i = StrCSpn( pCurrent, TEXT(",\n") );
  1388. StrCpyN( szClass, pCurrent, i+1 );
  1389. pCurrent += i+1;
  1390. i = StrCSpn( pCurrent, TEXT(",\n") );
  1391. value.szKeyname = (TCHAR *)LocalAlloc(LPTR, sizeof(TCHAR) * (i+2));
  1392. StrCpyN( value.szKeyname, pCurrent, i+1 );
  1393. pCurrent += i+1;
  1394. i = StrCSpn( pCurrent, TEXT(",\n") );
  1395. value.szValueName = (TCHAR *)LocalAlloc(LPTR, sizeof(TCHAR) * (i+2));
  1396. StrCpyN( value.szValueName, pCurrent, i+1 );
  1397. pCurrent += i+1;
  1398. i = StrCSpn( pCurrent, TEXT(",\n") );
  1399. StrCpyN( szType, pCurrent, i+1 );
  1400. pCurrent += i+1;
  1401. i = StrCSpn( pCurrent, TEXT("\n") );
  1402. StrCpyN( szValue, pCurrent, i+1 );
  1403. pCurrent += i+1;
  1404. RemoveQuotes( value.szKeyname );
  1405. RemoveQuotes( value.szValueName );
  1406. RemoveQuotes( szValue );
  1407. if( StrCmpI( szClass, TEXT("HKLM") ) == 0 )
  1408. hkClass = HKEY_LOCAL_MACHINE;
  1409. else
  1410. hkClass = HKEY_CURRENT_USER;
  1411. if( StrCmp(szType, TEXT("0") ) == 0 )
  1412. value.fNumeric = FALSE;
  1413. else
  1414. value.fNumeric = TRUE;
  1415. if( value.fNumeric )
  1416. {
  1417. int a[4]={0,0,0,0},j=0;
  1418. TCHAR *p1, *p2;
  1419. p1 = p2 = szValue;
  1420. while( *p1 )
  1421. {
  1422. if( *p1 == TEXT(',') )
  1423. {
  1424. *p1 = TEXT('\0');
  1425. a[j] = ReadHexStr( p2 );
  1426. j++;
  1427. p2 = p1 + 1;
  1428. }
  1429. p1++;
  1430. }
  1431. a[j] = ReadHexStr( p2 );
  1432. value.dwValue = MAKELONG(MAKEWORD(a[0],a[1]),MAKEWORD(a[2],a[3]));
  1433. }
  1434. else
  1435. value.szValue = StrDup(szValue);
  1436. for( i = 0; i < admfile->nParts; i++ )
  1437. {
  1438. if( hkClass == part[i].hkClass )
  1439. {
  1440. if( part[i].value.szKeyname != NULL && StrCmpI( value.szKeyname, part[i].value.szKeyname ) == 0 )
  1441. {
  1442. // special case out LISTBOX because there is no valuenames specified for
  1443. // individual list items.
  1444. if( part[i].nType == PART_LISTBOX || part[i].value.szValueName != NULL && StrCmpI( value.szValueName, part[i].value.szValueName) == 0 )
  1445. {
  1446. if(pPartData[i].value.szValue != NULL)
  1447. LocalFree(pPartData[i].value.szValue);
  1448. pPartData[i].value.szValue = NULL;
  1449. if((part[i].nType == PART_POLICY && part->fRequired) || part[i].nType == PART_CHECKBOX)
  1450. {
  1451. if(value.fNumeric)
  1452. {
  1453. if(value.dwValue == (DWORD) part[i].value.nValueOn)
  1454. pPartData[i].value.dwValue = 1;
  1455. else
  1456. pPartData[i].value.dwValue = 0;
  1457. if (value.szValue != NULL)
  1458. pPartData[i].value.szValue = StrDup(value.szValue);
  1459. pPartData[i].value.fNumeric = value.fNumeric;
  1460. }
  1461. else
  1462. {
  1463. if(part[i].value.szValueOn != NULL && value.szValue != NULL && StrCmp(part[i].value.szValueOn, value.szValue) == 0)
  1464. pPartData[i].value.dwValue = 1;
  1465. else
  1466. pPartData[i].value.dwValue = 0;
  1467. if (value.szValue != NULL)
  1468. pPartData[i].value.szValue = StrDup(value.szValue);
  1469. pPartData[i].value.fNumeric = TRUE;
  1470. }
  1471. pPartData[i].fSave = TRUE;
  1472. }
  1473. else if(part[i].nType == PART_DROPDOWNLIST)
  1474. {
  1475. if(part[i].nSelectedAction != NO_ACTION && part[i].nActions > 0)
  1476. {
  1477. for(nIndex = 0; nIndex < part[i].nActions; nIndex++)
  1478. {
  1479. if(value.fNumeric)
  1480. {
  1481. if(part[i].actionlist[nIndex].dwValue == value.dwValue && part[i].actionlist[nIndex].szName)
  1482. {
  1483. pPartData[i].value.szValue = StrDup(part[i].actionlist[nIndex].szName);
  1484. pPartData[i].nSelectedAction = nIndex;
  1485. }
  1486. }
  1487. else
  1488. {
  1489. if(part[i].actionlist[nIndex].szValue != NULL && value.szValue != NULL &&
  1490. StrCmp(part[i].actionlist[nIndex].szValue, value.szValue) == 0 &&
  1491. part[i].actionlist[nIndex].szName != NULL)
  1492. {
  1493. pPartData[i].value.szValue = StrDup(part[i].actionlist[nIndex].szName);
  1494. pPartData[i].nSelectedAction = nIndex;
  1495. }
  1496. }
  1497. }
  1498. pPartData[i].fSave = TRUE;
  1499. }
  1500. pPartData[i].value.fNumeric = FALSE;
  1501. }
  1502. else if(part[i].nType == PART_LISTBOX && !value.fNumeric)
  1503. {
  1504. // Allocate memory
  1505. if(pPartData[i].nActions == 0)
  1506. pPartData[i].actionlist = (LPACTIONLIST) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(ACTIONLIST));
  1507. if(pPartData[i].actionlist != NULL)
  1508. {
  1509. if(pPartData[i].nActions == 0)
  1510. {
  1511. pPartData[i].nActions = 1;
  1512. pPartData[i].actionlist[0].value = (LPVALUE) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(VALUE));
  1513. }
  1514. if(pPartData[i].actionlist[0].value != NULL)
  1515. {
  1516. TCHAR szValueName[10];
  1517. int nItems = pPartData[i].actionlist[0].nValues;
  1518. if(nItems != 0)
  1519. {
  1520. LPVOID lpTemp;
  1521. lpTemp = (LPVALUE) HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, pPartData[i].actionlist[0].value, sizeof(VALUE) * (nItems + 1));
  1522. if (lpTemp != NULL)
  1523. pPartData[i].actionlist[0].value = (LPVALUE)lpTemp;
  1524. else
  1525. continue;
  1526. }
  1527. if (part[i].value.szKeyname != NULL)
  1528. pPartData[i].actionlist[0].value[nItems].szKeyname = StrDup(part[i].value.szKeyname);
  1529. wnsprintf(szValueName, ARRAYSIZE(szValueName), TEXT("%d"), nItems + 1);
  1530. pPartData[i].actionlist[0].value[nItems].szValueName = StrDup(szValueName);
  1531. if (value.szValue != NULL)
  1532. pPartData[i].actionlist[0].value[nItems].szValue = StrDup(value.szValue);
  1533. pPartData[i].actionlist[0].nValues++;
  1534. pPartData[i].value.fNumeric = TRUE;
  1535. pPartData[i].value.dwValue = 1;
  1536. pPartData[i].fSave = TRUE;
  1537. }
  1538. }
  1539. }
  1540. else
  1541. {
  1542. if (value.szValue != NULL)
  1543. pPartData[i].value.szValue = StrDup(value.szValue);
  1544. pPartData[i].value.dwValue = value.dwValue;
  1545. pPartData[i].value.fNumeric = value.fNumeric;
  1546. pPartData[i].fSave = TRUE;
  1547. }
  1548. }
  1549. }
  1550. }
  1551. }
  1552. if(value.szKeyname != NULL)
  1553. LocalFree(value.szKeyname);
  1554. value.szKeyname = NULL;
  1555. if(value.szValueName != NULL)
  1556. LocalFree(value.szValueName);
  1557. value.szValueName = NULL;
  1558. if(value.szValue != NULL)
  1559. LocalFree(value.szValue);
  1560. value.szValue = NULL;
  1561. }
  1562. LocalFree( (HGLOBAL) pData );
  1563. }
  1564. //--------------------------------------------------------------------------
  1565. // B A S E F I L E N A M E
  1566. //
  1567. // Returns a pointer to the filename stripping directory path if any
  1568. //--------------------------------------------------------------------------
  1569. LPCTSTR BaseFileName(LPCTSTR pcszFileName)
  1570. {
  1571. TCHAR* ptr = StrRChr(pcszFileName, NULL, TEXT('\\'));
  1572. if(ptr == NULL)
  1573. return pcszFileName;
  1574. else
  1575. return (LPCTSTR) ++ptr;
  1576. }