Source code of Windows XP (NT5)
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.

3198 lines
75 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: C W I N F . C P P
  7. //
  8. // Contents: Definition of class CWInfFile and other related classes
  9. //
  10. // Notes:
  11. //
  12. // Author: kumarp 12 April 97
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "pch.h"
  16. #pragma hdrstop
  17. #include "kkcwinf.h"
  18. #include "kkutils.h"
  19. #include <stdio.h>
  20. #define TC_COMMENT_CHAR L';'
  21. const WCHAR c_szCommentPrefix[] = L"; ";
  22. extern const WCHAR c_szYes[];
  23. extern const WCHAR c_szNo[];
  24. void EraseAndDeleteAll(IN WifLinePtrList* ppl)
  25. {
  26. WifLinePtrListIter i=ppl->begin();
  27. while (i != ppl->end())
  28. {
  29. delete *i++;
  30. }
  31. ppl->erase(ppl->begin(), ppl->end());
  32. }
  33. inline void EraseAll(IN WifLinePtrList* ppl)
  34. {
  35. ppl->erase(ppl->begin(), ppl->end());
  36. }
  37. inline WifLinePtrListIter GetIterAtBack(IN const WifLinePtrList* ppl)
  38. {
  39. WifLinePtrListIter pliRet = ppl->end();
  40. pliRet--;
  41. return pliRet;
  42. }
  43. inline WifLinePtrListIter AddAtEndOfPtrList(IN WifLinePtrList& pl, IN PCWInfLine pwifLine)
  44. {
  45. return pl.insert(pl.end(), pwifLine);
  46. }
  47. // ======================================================================
  48. // Class CWInfFile
  49. // ======================================================================
  50. // ----------------------------------------------------------------------
  51. // CWInfFile public functions
  52. // ----------------------------------------------------------------------
  53. //+---------------------------------------------------------------------------
  54. //
  55. // Member: CWInfFile::CWInfFile
  56. //
  57. // Purpose: constructor
  58. //
  59. // Arguments: none
  60. //
  61. // Author: kumarp 12 April 97 (05:53:03 pm)
  62. //
  63. // Notes:
  64. // We keep the read-context and write-context separate. This allows us
  65. // to simultaneously read and write from the file
  66. CWInfFile::CWInfFile()
  67. {
  68. m_fp = NULL;
  69. }
  70. //+---------------------------------------------------------------------------
  71. //
  72. // Member: CWInfFile::~CWInfFile
  73. //
  74. // Purpose: destructor
  75. //
  76. // Arguments: none
  77. //
  78. // Author: kumarp 12 April 97 (05:53:03 pm)
  79. //
  80. //
  81. CWInfFile::~CWInfFile()
  82. {
  83. EraseAndDeleteAll(m_plLines);
  84. EraseAll(m_plSections);
  85. CWInfKey::UnInit();
  86. delete m_plLines;
  87. delete m_plSections;
  88. }
  89. //+---------------------------------------------------------------------------
  90. //
  91. // Member: CWInfFile::Init
  92. //
  93. // Purpose: initialization of alloc'd member variables
  94. //
  95. // Arguments: none
  96. //
  97. // Author: davea 17 Feb 2000
  98. //
  99. //
  100. BOOL CWInfFile::Init()
  101. {
  102. m_plLines = new WifLinePtrList(); // lines in this file
  103. m_plSections = new WifLinePtrList(); // lines that represent sections
  104. // this allows us to quickly locate a section
  105. if ((m_plLines != NULL) &&
  106. (m_plSections != NULL))
  107. {
  108. m_ReadContext.posSection = m_plSections->end();
  109. m_ReadContext.posLine = m_plLines->end();
  110. m_WriteContext.posSection = m_plSections->end();
  111. m_WriteContext.posLine = m_plLines->end();
  112. }
  113. else
  114. {
  115. return(FALSE);
  116. }
  117. CWInfKey::Init();
  118. return(TRUE);
  119. }
  120. //+---------------------------------------------------------------------------
  121. //
  122. // Member: CWInfFile::Open
  123. //
  124. // Purpose: Opens an INF file
  125. //
  126. // Arguments:
  127. // pszFileName [in] name of the file to open
  128. //
  129. // Returns: TRUE if suceeded, FALSE otherwise.
  130. //
  131. // Author: kumarp 12 April 97 (05:53:03 pm)
  132. //
  133. // Notes:
  134. // This does not keep the physical file handle open. We just open the file
  135. // read the contents and close it. After this, one can freely read from or
  136. // write to the file. This is done to the memory image of the file. To write
  137. // this file back, one must call Close() or SaveAs() member functions
  138. BOOL CWInfFile::Open(IN PCWSTR pszFileName)
  139. {
  140. DefineFunctionName("CWInfFile::Open");
  141. BOOL status = FALSE;
  142. m_strFileName = pszFileName;
  143. FILE *fp = _wfopen(pszFileName, L"r");
  144. if (fp)
  145. {
  146. status = Open(fp);
  147. fclose(fp);
  148. }
  149. else
  150. {
  151. TraceTag(ttidError, "%s: could not open file: %S",
  152. __FUNCNAME__, pszFileName);
  153. }
  154. return status;
  155. }
  156. //+---------------------------------------------------------------------------
  157. //
  158. // Member: CWInfFile::Open
  159. //
  160. // Purpose: Opens an INF file
  161. //
  162. // Arguments:
  163. // fp [in] FILE* of the file to read from
  164. //
  165. // Returns: TRUE if suceeded, FALSE otherwise.
  166. //
  167. // Author: kumarp 12 April 97 (05:53:03 pm)
  168. //
  169. // Notes:
  170. // This does not physically close the file handle
  171. BOOL CWInfFile::Open(IN FILE *fp)
  172. {
  173. PWSTR pszLineRoot = (PWSTR) MemAlloc ((MAX_INF_STRING_LENGTH + 1) *
  174. sizeof (WCHAR));
  175. if (!pszLineRoot)
  176. {
  177. return FALSE;
  178. }
  179. PWSTR pszNewLinePos;
  180. while (!feof(fp))
  181. {
  182. PWSTR pszLine = pszLineRoot;
  183. *pszLine = 0;
  184. if (fgetws(pszLine, MAX_INF_STRING_LENGTH, fp))
  185. {
  186. // Trim leading spaces
  187. //
  188. while (iswspace(*pszLine))
  189. {
  190. pszLine++;
  191. }
  192. if (pszNewLinePos = wcschr(pszLine, L'\n'))
  193. {
  194. *pszNewLinePos = 0;
  195. }
  196. if (!wcslen(pszLine))
  197. {
  198. continue;
  199. }
  200. ParseLine(pszLine);
  201. }
  202. }
  203. MemFree (pszLineRoot);
  204. return TRUE;
  205. }
  206. //+---------------------------------------------------------------------------
  207. //
  208. // Member: CWInfFile::ParseLine
  209. //
  210. // Purpose: Parse the given line and update internal structures
  211. //
  212. // Arguments:
  213. // pszLine [in] line text to parse
  214. //
  215. // Returns: TRUE if suceeded, FALSE otherwise.
  216. //
  217. // Author: kumarp 12 April 97 (05:53:03 pm)
  218. //
  219. // Notes:
  220. // Parse the line and add a CWInfKey / CWInfSection / CWInfComment
  221. // as appropriate in the current write context
  222. // The logic:
  223. // add CWInfComment if line begins with ';'
  224. // add CWInfKey if line is of the form key=value
  225. // add CWInfSection if line begins with '[' and has ']' at the end
  226. // ignore anything else i.e. dont add anything
  227. void CWInfFile::ParseLine(IN PCWSTR pszLine)
  228. {
  229. tstring strTemp;
  230. PWSTR pszTemp, pszTemp2;
  231. if (!CurrentWriteSection() && (pszLine[0] != L'['))
  232. {
  233. return;
  234. }
  235. if (pszLine[0] == TC_COMMENT_CHAR)
  236. {
  237. //it is a comment
  238. AddComment(pszLine + 1);
  239. }
  240. else if (pszLine[0] == L'[')
  241. {
  242. //it is a section
  243. pszTemp = wcschr(pszLine, L']');
  244. if (!pszTemp)
  245. {
  246. return;
  247. }
  248. tstring strSectionName(pszLine+1, pszTemp-pszLine-1);
  249. AddSection(strSectionName.c_str());
  250. }
  251. else if ((pszTemp = wcschr(pszLine, L'=')) != NULL)
  252. {
  253. if (pszLine == pszTemp)
  254. {
  255. return;
  256. }
  257. //it is a key
  258. pszTemp2 = pszTemp; // pszTemp2 points at '='
  259. pszTemp2--;
  260. while (iswspace(*pszTemp2) && (pszTemp2 != pszLine))
  261. {
  262. pszTemp2--;
  263. }
  264. pszTemp++; // skip '='
  265. while (*pszTemp && iswspace(*pszTemp))
  266. {
  267. pszTemp++;
  268. }
  269. if ((*pszTemp == L'"') && !wcschr(pszTemp, L','))
  270. {
  271. pszTemp++;
  272. DWORD dwLen = wcslen(pszTemp);
  273. if (pszTemp[dwLen-1] == L'"')
  274. {
  275. pszTemp[dwLen-1] = 0;
  276. }
  277. }
  278. tstring strKeyName(pszLine, pszTemp2-pszLine+1);
  279. tstring strKeyValue(pszTemp);
  280. AddKey(strKeyName.c_str(), strKeyValue.c_str());
  281. }
  282. else
  283. {
  284. // we cannot interpret the line, just add it
  285. AddRawLine(pszLine);
  286. }
  287. }
  288. //+---------------------------------------------------------------------------
  289. //
  290. // Member: CWInfFile::Create
  291. //
  292. // Purpose: Create a blank INF file in memory
  293. //
  294. // Arguments:
  295. // pszFileName [in] name of the file to create
  296. //
  297. // Returns: TRUE if suceeded, FALSE otherwise.
  298. //
  299. // Author: kumarp 12 April 97 (05:53:03 pm)
  300. //
  301. // Notes:
  302. // This does not write anything to disk
  303. BOOL CWInfFile::Create(IN PCWSTR pszFileName)
  304. {
  305. m_strFileName = pszFileName;
  306. return TRUE;
  307. }
  308. //+---------------------------------------------------------------------------
  309. //
  310. // Member: CWInfFile::Create
  311. //
  312. // Purpose: Create a blank INF file in memory
  313. //
  314. // Arguments:
  315. // fp [in] FILE* of the file to create
  316. //
  317. // Returns: TRUE if suceeded, FALSE otherwise.
  318. //
  319. // Author: kumarp 12 April 97 (05:53:03 pm)
  320. //
  321. // Notes:
  322. // This does not write anything to disk
  323. BOOL CWInfFile::Create(IN FILE *fp)
  324. {
  325. m_fp = fp;
  326. return fp != NULL;
  327. }
  328. //+---------------------------------------------------------------------------
  329. //
  330. // Member: CWInfFile::Close
  331. //
  332. // Purpose: Close the file, flushing data to disk.
  333. //
  334. // Arguments: none
  335. //
  336. // Returns: TRUE if suceeded, FALSE otherwise.
  337. //
  338. // Author: kumarp 12 April 97 (05:53:03 pm)
  339. //
  340. // Notes:
  341. // This just calls CWInfFile::flush() which will actually write the file back
  342. BOOL CWInfFile::Close()
  343. {
  344. return Flush();
  345. }
  346. //+---------------------------------------------------------------------------
  347. //
  348. // Member: CWInfFile::Flush
  349. //
  350. // Purpose: Close the file, flushing data to disk.
  351. //
  352. // Arguments: none
  353. //
  354. // Returns: TRUE if suceeded, FALSE otherwise.
  355. //
  356. // Author: kumarp 12 April 97 (05:53:03 pm)
  357. //
  358. // Notes:
  359. // This just calls CWInfFile::flush() which will actually write the file back
  360. BOOL CWInfFile::Flush()
  361. {
  362. WifLinePtrListIter pos;
  363. CWInfLine *line;
  364. tstring line_text;
  365. BOOL fStatus = TRUE;
  366. //if a filename was specified then open it for writing
  367. //
  368. if (!m_strFileName.empty())
  369. {
  370. m_fp = _wfopen(m_strFileName.c_str(), L"w");
  371. }
  372. if (!m_fp)
  373. return FALSE;
  374. // get text of each line and dump it to the file
  375. for( pos = m_plLines->begin(); pos != m_plLines->end(); )
  376. {
  377. line = (CWInfLine *) *pos++;
  378. line->GetText(line_text);
  379. if (line->Type() == INF_SECTION)
  380. fwprintf(m_fp, L"\n");
  381. fwprintf(m_fp, L"%s", line_text.c_str());
  382. fwprintf(m_fp, L"\n");
  383. }
  384. if (!m_strFileName.empty())
  385. {
  386. fStatus = fclose(m_fp) == 0;
  387. m_fp = NULL;
  388. }
  389. return fStatus;
  390. }
  391. //+---------------------------------------------------------------------------
  392. //
  393. // Member: CWInfFile::FlushEx
  394. //
  395. // Purpose: Close the file, flushing data to disk.
  396. //
  397. // Arguments: none
  398. //
  399. // Returns: TRUE if suceeded, FALSE otherwise.
  400. //
  401. // Author: frankli 4 May 2000
  402. //
  403. // Notes:
  404. // This is used by SysPrep to enclose value of a key with quotes except
  405. // for multi-sz value.
  406. BOOL CWInfFile::FlushEx()
  407. {
  408. WifLinePtrListIter pos;
  409. CWInfLine *line;
  410. tstring line_text;
  411. BOOL fStatus = TRUE;
  412. //if a filename was specified then open it for writing
  413. //
  414. if (!m_strFileName.empty())
  415. {
  416. m_fp = _wfopen(m_strFileName.c_str(), L"w");
  417. }
  418. if (!m_fp)
  419. return FALSE;
  420. // get text of each line and dump it to the file
  421. for( pos = m_plLines->begin(); pos != m_plLines->end(); )
  422. {
  423. line = (CWInfLine *) *pos++;
  424. line->GetTextEx(line_text);
  425. if (line->Type() == INF_SECTION)
  426. fwprintf(m_fp, L"\n");
  427. fwprintf(m_fp, L"%s", line_text.c_str());
  428. fwprintf(m_fp, L"\n");
  429. }
  430. if (!m_strFileName.empty())
  431. {
  432. fStatus = fclose(m_fp) == 0;
  433. m_fp = NULL;
  434. }
  435. return fStatus;
  436. }
  437. //+---------------------------------------------------------------------------
  438. //
  439. // Member: CWInfFile::SaveAs
  440. //
  441. // Purpose: Save current image to the given file
  442. //
  443. // Arguments:
  444. // pszFileName [in] name of the file to save as
  445. //
  446. // Returns: TRUE if suceeded, FALSE otherwise.
  447. //
  448. // Author: kumarp 12 April 97 (05:53:03 pm)
  449. //
  450. // Notes:
  451. // This is not same as Close()!, Close() will still write to
  452. // the original file.
  453. BOOL CWInfFile::SaveAs(IN PCWSTR pszFileName)
  454. {
  455. BOOL fStatus;
  456. tstring strTemp = m_strFileName;
  457. m_strFileName = pszFileName;
  458. fStatus = Flush();
  459. m_strFileName = strTemp;
  460. return fStatus;
  461. }
  462. //+---------------------------------------------------------------------------
  463. //
  464. // Member: CWInfFile::SaveAsEx
  465. //
  466. // Purpose: Save current image to the given file
  467. //
  468. // Arguments:
  469. // pszFileName [in] name of the file to save as
  470. //
  471. // Returns: TRUE if suceeded, FALSE otherwise.
  472. //
  473. // Author: frankli 4 May 2000
  474. //
  475. // Notes:
  476. // This is not same as Close()!, Close() will still write to
  477. // the original file. Save SysPrep prepared data,
  478. // value of a key will be enclosed with quotes except for multi-sz
  479. // value.
  480. BOOL CWInfFile::SaveAsEx(IN PCWSTR pszFileName)
  481. {
  482. BOOL fStatus;
  483. tstring strTemp = m_strFileName;
  484. m_strFileName = pszFileName;
  485. fStatus = FlushEx();
  486. m_strFileName = strTemp;
  487. return fStatus;
  488. }
  489. // ---------------------------------------------------------------------------
  490. // Functions for reading
  491. // ---------------------------------------------------------------------------
  492. //+---------------------------------------------------------------------------
  493. //
  494. // Member: CWInfFile::SetCurrentReadSection
  495. //
  496. // Purpose: Set read-context so that subsequent reads
  497. // will be from this section
  498. //
  499. // Arguments:
  500. // pwisSection [in] Section to set context to
  501. //
  502. // Returns: none
  503. //
  504. // Author: kumarp 12 April 97 (05:53:03 pm)
  505. //
  506. // Notes:
  507. //
  508. void CWInfFile::SetCurrentReadSection(IN PCWInfSection pwisSection)
  509. {
  510. if ((CurrentReadSection() != pwisSection) && pwisSection)
  511. {
  512. m_ReadContext.posSection = pwisSection->m_posSection;
  513. m_ReadContext.posLine = pwisSection->m_posLine;
  514. }
  515. }
  516. //+---------------------------------------------------------------------------
  517. //
  518. // Member: CWInfFile::FindSection
  519. //
  520. // Purpose: Find the given section in current file
  521. //
  522. //
  523. // Arguments:
  524. // pszSectionName [in] Section to find
  525. // wsmMode [in] Search mode
  526. // (search from beginning-of-file / current-position)
  527. // Returns: Pointer to section if found, NULL otherwise
  528. //
  529. // Author: kumarp 12 April 97 (05:53:03 pm)
  530. //
  531. // Notes:
  532. // Sets the current read-context to the section found
  533. //
  534. PCWInfSection CWInfFile::FindSection(IN PCWSTR pszSectionName,
  535. IN WInfSearchMode wsmMode)
  536. {
  537. PCWInfSection pwisRet=NULL, pwisTemp;
  538. WifLinePtrListIter pos, old_pos;
  539. if (wsmMode == ISM_FromBeginning)
  540. {
  541. pos = m_plSections->begin();
  542. }
  543. else
  544. {
  545. pos = m_ReadContext.posSection;
  546. if (pos == m_plSections->end())
  547. pos = m_plSections->begin();
  548. }
  549. while (pos != m_plSections->end())
  550. {
  551. old_pos = pos;
  552. pwisTemp = (PCWInfSection) *pos++;
  553. if (!lstrcmpiW(pwisTemp->m_Name.c_str(), pszSectionName))
  554. {
  555. pwisRet = pwisTemp;
  556. SetCurrentReadSection(pwisRet);
  557. /*
  558. // m_ReadContext.posSection = old_pos;
  559. m_ReadContext.posSection = pwisRet->m_posSection;
  560. m_ReadContext.posLine = pwisRet->m_posLine;
  561. */
  562. break;
  563. }
  564. }
  565. return pwisRet;
  566. }
  567. //+---------------------------------------------------------------------------
  568. //
  569. // Member: CWInfFile::FindKey
  570. //
  571. // Purpose: Find a key in the current section
  572. //
  573. //
  574. // Arguments:
  575. // pszKeyName [in] Key to find
  576. // wsmMode [in] Search mode
  577. // (search from beginning-of-section / current-position)
  578. // Returns: Pointer to the key if found, NULL otherwise
  579. //
  580. // Author: kumarp 12 April 97 (05:53:03 pm)
  581. //
  582. // Notes:
  583. //
  584. PCWInfKey CWInfFile::FindKey(IN PCWSTR pszKeyName, IN WInfSearchMode wsmMode)
  585. {
  586. WifLinePtrListIter pos, old_pos;
  587. PCWInfKey pwikRet=NULL;
  588. PCWInfLine pwilTemp;
  589. PCWInfSection pwisCurrentReadSection = CurrentReadSection();
  590. ReturnNULLIf(!pwisCurrentReadSection);
  591. if (wsmMode == ISM_FromCurrentPosition)
  592. {
  593. pos = m_ReadContext.posLine;
  594. }
  595. else
  596. {
  597. pos = pwisCurrentReadSection->m_posLine;
  598. }
  599. pos++; // start from next line
  600. while(pos != m_plLines->end())
  601. {
  602. old_pos = pos;
  603. pwilTemp = (PCWInfLine) *pos++;
  604. if (pwilTemp->Type() != INF_KEY)
  605. {
  606. if (pwilTemp->Type() == INF_SECTION)
  607. {
  608. break;
  609. }
  610. else
  611. {
  612. continue;
  613. }
  614. }
  615. if (!lstrcmpiW(((PCWInfKey) pwilTemp)->m_Name.c_str(), pszKeyName))
  616. {
  617. pwikRet = (PCWInfKey) pwilTemp;
  618. m_ReadContext.posLine = old_pos;
  619. break;
  620. }
  621. }
  622. ReturnNULLIf(!pwikRet);
  623. return pwikRet;
  624. }
  625. //+---------------------------------------------------------------------------
  626. //
  627. // Member: CWInfFile::FirstKey
  628. //
  629. // Purpose: Return the first key in the current section
  630. //
  631. //
  632. // Arguments: none
  633. //
  634. // Returns: Pointer to the key if found, NULL otherwise
  635. //
  636. // Author: kumarp 12 April 97 (05:53:03 pm)
  637. //
  638. // Notes:
  639. // Sets read-context to this key
  640. //
  641. PCWInfKey CWInfFile::FirstKey()
  642. {
  643. WifLinePtrListIter pos, old_pos;
  644. PCWInfKey pwikRet=NULL;
  645. PCWInfLine pwilTemp;
  646. PCWInfSection pwisCurrentReadSection = CurrentReadSection();
  647. if (!pwisCurrentReadSection)
  648. {
  649. return NULL;
  650. }
  651. pos = pwisCurrentReadSection->m_posLine;
  652. pos++; // start from next line
  653. while(pos != m_plLines->end())
  654. {
  655. old_pos = pos;
  656. pwilTemp = (PCWInfLine) *pos++;
  657. if (pwilTemp->Type() != INF_KEY)
  658. {
  659. if (pwilTemp->Type() == INF_SECTION)
  660. {
  661. break;
  662. }
  663. else
  664. {
  665. continue;
  666. }
  667. }
  668. pwikRet = (PCWInfKey) pwilTemp;
  669. m_ReadContext.posLine = old_pos;
  670. break;
  671. }
  672. return pwikRet;
  673. }
  674. //+---------------------------------------------------------------------------
  675. //
  676. // Member: CWInfFile::NextKey
  677. //
  678. // Purpose: Return the next key in the current section
  679. //
  680. //
  681. // Arguments: none
  682. //
  683. // Returns: Pointer to the key if found, NULL otherwise
  684. //
  685. // Author: kumarp 12 April 97 (05:53:03 pm)
  686. //
  687. // Notes:
  688. // Sets read-context to this key
  689. //
  690. PCWInfKey CWInfFile::NextKey()
  691. {
  692. WifLinePtrListIter pos, old_pos;
  693. PCWInfKey pwikRet=NULL;
  694. PCWInfLine pwilTemp;
  695. PCWInfSection pwisCurrentReadSection = CurrentReadSection();
  696. if (!pwisCurrentReadSection)
  697. {
  698. return NULL;
  699. }
  700. pos = m_ReadContext.posLine;
  701. pos++; // start from next line
  702. while(pos != m_plLines->end())
  703. {
  704. old_pos = pos;
  705. pwilTemp = (PCWInfLine) *pos++;
  706. if (pwilTemp->Type() != INF_KEY)
  707. {
  708. if (pwilTemp->Type() == INF_SECTION)
  709. {
  710. break;
  711. }
  712. else
  713. {
  714. continue;
  715. }
  716. }
  717. pwikRet = (PCWInfKey) pwilTemp;
  718. m_ReadContext.posLine = old_pos;
  719. break;
  720. }
  721. return pwikRet;
  722. }
  723. //+---------------------------------------------------------------------------
  724. //
  725. // Member: CWInfFile::GetStringListValue
  726. //
  727. // Purpose: Return the value of the given key as a string-list
  728. //
  729. //
  730. // Arguments:
  731. // pszKeyName [in] Key to find
  732. // pslList [out] List value to return
  733. //
  734. // Returns: TRUE if key found and value in correct format, FALSE otherwise
  735. //
  736. // Author: kumarp 12 April 97 (05:53:03 pm)
  737. //
  738. // Notes:
  739. // If the value is a comma-delimited list, converts it to a TStringList
  740. // otherwise returns a TStringList with a single element
  741. //
  742. BOOL CWInfFile::GetStringListValue(IN PCWSTR pszKeyName, OUT TStringList &pslList)
  743. {
  744. CWInfKey* key;
  745. key = FindKey(pszKeyName);
  746. if (!key)
  747. return FALSE;
  748. return key->GetStringListValue(pslList);
  749. }
  750. //+---------------------------------------------------------------------------
  751. //
  752. // Member: CWInfFile::GetStringArrayValue
  753. //
  754. // Purpose: Return the value of the given key as a string-Array
  755. //
  756. //
  757. // Arguments:
  758. // pszKeyName [in] Key to find
  759. // saStrings [out] Array value to return
  760. //
  761. // Returns: TRUE if key found and value in correct format, FALSE otherwise
  762. //
  763. // Author: kumarp 12-November-97
  764. //
  765. // Notes:
  766. // If the value is a comma-delimited list, converts it to a TStringArray
  767. // otherwise returns a TStringArray with a single element
  768. //
  769. BOOL CWInfFile::GetStringArrayValue(IN PCWSTR pszKeyName, OUT TStringArray &saStrings)
  770. {
  771. CWInfKey* key;
  772. key = FindKey(pszKeyName);
  773. if (key)
  774. {
  775. return key->GetStringArrayValue(saStrings);
  776. }
  777. else
  778. {
  779. return FALSE;
  780. }
  781. }
  782. //+---------------------------------------------------------------------------
  783. //
  784. // Member: CWInfFile::GetStringValue
  785. //
  786. // Purpose: Return the value of the given key as a string
  787. //
  788. //
  789. // Arguments:
  790. // pszKeyName [in] Key to find
  791. // strValue [out] string value to return
  792. //
  793. // Returns: TRUE if key found and value in correct format, FALSE otherwise
  794. //
  795. // Author: kumarp 12 April 97 (05:53:03 pm)
  796. //
  797. // Notes:
  798. //
  799. BOOL CWInfFile::GetStringValue(IN PCWSTR pszKeyName, OUT tstring &strValue)
  800. {
  801. CWInfKey* key;
  802. key = FindKey(pszKeyName);
  803. if (!key)
  804. return FALSE;
  805. return key->GetStringValue(strValue);
  806. }
  807. //+---------------------------------------------------------------------------
  808. //
  809. // Member: CWInfFile::GetIntValue
  810. //
  811. // Purpose: Return the value of the given key as an int
  812. //
  813. //
  814. // Arguments:
  815. // pszKeyName [in] Key to find
  816. // pdwValue [out] int value to return
  817. //
  818. // Returns: TRUE if key found and value in correct format, FALSE otherwise
  819. //
  820. // Author: kumarp 12 April 97 (05:53:03 pm)
  821. //
  822. // Notes:
  823. //
  824. BOOL CWInfFile::GetIntValue(IN PCWSTR pszKeyName, OUT DWORD *pdwValue)
  825. {
  826. CWInfKey* key;
  827. key = FindKey(pszKeyName);
  828. if (!key)
  829. return FALSE;
  830. return key->GetIntValue(pdwValue);
  831. }
  832. //+---------------------------------------------------------------------------
  833. //
  834. // Member: CWInfFile::GetQwordValue
  835. //
  836. // Purpose: Return the value of the given key as a QWORD
  837. //
  838. //
  839. // Arguments:
  840. // pszKeyName [in] Key to find
  841. // pqwValue [out] int value to return
  842. //
  843. // Returns: TRUE if key found and value in correct format, FALSE otherwise
  844. //
  845. // Author: kumarp 12 April 97 (05:53:03 pm)
  846. //
  847. // Notes:
  848. //
  849. BOOL CWInfFile::GetQwordValue(IN PCWSTR pszKeyName, OUT QWORD *pqwValue)
  850. {
  851. CWInfKey* key;
  852. key = FindKey(pszKeyName);
  853. if (!key)
  854. return FALSE;
  855. return key->GetQwordValue(pqwValue);
  856. }
  857. //+---------------------------------------------------------------------------
  858. //
  859. // Member: CWInfFile::GetBoolValue
  860. //
  861. // Purpose: Return the value of the given key as a BOOL
  862. //
  863. //
  864. // Arguments:
  865. // pszKeyName [in] Key to find
  866. // pfValue [out] BOOL value to return
  867. //
  868. // Returns: TRUE if key found and value in correct format, FALSE otherwise
  869. //
  870. // Author: kumarp 12 April 97 (05:53:03 pm)
  871. //
  872. // Notes:
  873. // converts:
  874. // "True" / "Yes" / 1 to TRUE
  875. // "False" / "No" / 0 to FALSE
  876. //
  877. BOOL CWInfFile::GetBoolValue(IN PCWSTR pszKeyName, OUT BOOL *pfValue)
  878. {
  879. CWInfKey* key;
  880. key = FindKey(pszKeyName);
  881. if (!key)
  882. return FALSE;
  883. return key->GetBoolValue(pfValue);
  884. }
  885. //+---------------------------------------------------------------------------
  886. //
  887. // Member: CWInfFile::GetStringValue
  888. //
  889. // Purpose: Return the value of the given key as a string
  890. //
  891. //
  892. // Arguments:
  893. // pszKeyName [in] Key to find
  894. // pszDefault [in] default value
  895. //
  896. // Returns: value if key found and value in correct format,
  897. // otherwise returns the default-value
  898. //
  899. // Author: kumarp 12 April 97 (05:53:03 pm)
  900. //
  901. // Notes:
  902. //
  903. PCWSTR CWInfFile::GetStringValue(IN PCWSTR pszKeyName, IN PCWSTR pszDefault)
  904. {
  905. CWInfKey* key;
  906. key = FindKey(pszKeyName);
  907. if (!key)
  908. {
  909. return pszDefault;
  910. }
  911. return key->GetStringValue(pszDefault);
  912. }
  913. //+---------------------------------------------------------------------------
  914. //
  915. // Member: CWInfFile::GetIntValue
  916. //
  917. // Purpose: Return the value of the given key as an int
  918. //
  919. //
  920. // Arguments:
  921. // pszKeyName [in] Key to find
  922. // dwDefault [in] default value
  923. //
  924. // Returns: value if key found and value in correct format,
  925. // otherwise returns the default-value
  926. //
  927. // Author: kumarp 12 April 97 (05:53:03 pm)
  928. //
  929. // Notes:
  930. //
  931. DWORD CWInfFile::GetIntValue(IN PCWSTR pszKeyName, IN DWORD dwDefault)
  932. {
  933. CWInfKey* key;
  934. key = FindKey(pszKeyName);
  935. if (!key)
  936. {
  937. return dwDefault;
  938. }
  939. return key->GetIntValue(dwDefault);
  940. }
  941. //+---------------------------------------------------------------------------
  942. //
  943. // Member: CWInfFile::GetQwordValue
  944. //
  945. // Purpose: Return the value of the given key as a QWORD
  946. //
  947. //
  948. // Arguments:
  949. // pszKeyName [in] Key to find
  950. // qwDefault [in] default value
  951. //
  952. // Returns: value if key found and value in correct format,
  953. // otherwise returns the default-value
  954. //
  955. // Author: kumarp 12 April 97 (05:53:03 pm)
  956. //
  957. // Notes:
  958. //
  959. QWORD CWInfFile::GetQwordValue(IN PCWSTR pszKeyName, IN QWORD qwDefault)
  960. {
  961. CWInfKey* key;
  962. key = FindKey(pszKeyName);
  963. if (!key)
  964. {
  965. return qwDefault;
  966. }
  967. return key->GetQwordValue(qwDefault);
  968. }
  969. //+---------------------------------------------------------------------------
  970. //
  971. // Member: CWInfFile::GetBoolValue
  972. //
  973. // Purpose: Return the value of the given key as a BOOL
  974. //
  975. //
  976. // Arguments:
  977. // pszKeyName [in] Key to find
  978. // fDefault [in] default value
  979. //
  980. // Returns: value if key found and value in correct format,
  981. // otherwise returns the default-value
  982. //
  983. // Author: kumarp 12 April 97 (05:53:03 pm)
  984. //
  985. // Notes:
  986. //
  987. BOOL CWInfFile::GetBoolValue(IN PCWSTR pszKeyName, IN BOOL fDefault)
  988. {
  989. CWInfKey* key;
  990. key = FindKey(pszKeyName);
  991. if (!key)
  992. {
  993. return fDefault;
  994. }
  995. return key->GetBoolValue(fDefault);
  996. }
  997. // ---------------------------------------------------------------------------
  998. // Functions for writing
  999. // ---------------------------------------------------------------------------
  1000. //+---------------------------------------------------------------------------
  1001. //
  1002. // Member: CWInfFile::AddSection
  1003. //
  1004. // Purpose: Adds the given section to the current file
  1005. //
  1006. //
  1007. // Arguments:
  1008. // pszSectionName [in] Section to add
  1009. //
  1010. // Returns: Pointer to section added, NULL in case of error
  1011. //
  1012. // Author: kumarp 12 April 97 (05:53:03 pm)
  1013. //
  1014. // Notes:
  1015. // Sets the current write-context to the section added
  1016. //
  1017. PCWInfSection CWInfFile::AddSection(IN PCWSTR pszSectionName)
  1018. {
  1019. WifLinePtrListIter tpos, section_pos, line_pos;
  1020. CWInfSection *current_section;
  1021. if ((current_section = CurrentWriteSection()) != NULL)
  1022. GotoEndOfSection(current_section);
  1023. CWInfSection *section = new CWInfSection(pszSectionName, this);
  1024. if (m_plSections->empty())
  1025. {
  1026. m_plSections->push_back(section);
  1027. section_pos = GetIterAtBack(m_plSections);
  1028. line_pos = m_plLines->end();
  1029. }
  1030. else
  1031. {
  1032. section_pos = m_WriteContext.posSection;
  1033. section_pos++;
  1034. section_pos = m_plSections->insert(section_pos, section);
  1035. }
  1036. if (line_pos == m_plLines->end())
  1037. {
  1038. line_pos = AddAtEndOfPtrList(*m_plLines, section);
  1039. }
  1040. else
  1041. {
  1042. line_pos = m_WriteContext.posLine;
  1043. line_pos++;
  1044. line_pos = m_plLines->insert(line_pos, section);
  1045. // line_pos = AddAtEndOfPtrList(*m_plLines, section);
  1046. }
  1047. m_WriteContext.posSection = section_pos;
  1048. m_WriteContext.posLine = line_pos;
  1049. section->m_posLine = line_pos;
  1050. section->m_posSection = section_pos;
  1051. return section;
  1052. }
  1053. //+---------------------------------------------------------------------------
  1054. //
  1055. // Member: CWInfFile::AddSectionIfNotPresent
  1056. //
  1057. // Purpose: Adds the given section to the current file if it is not
  1058. // present. if present, returns pointer to the section
  1059. //
  1060. //
  1061. // Arguments:
  1062. // pszSectionName [in] Section to add/find
  1063. //
  1064. // Returns: Pointer to section added/found, NULL in case of error
  1065. //
  1066. // Author: kumarp kumarp 11-September-97 (06:09:06 pm)
  1067. //
  1068. // Notes:
  1069. // Sets the current write-context to the section added
  1070. //
  1071. PCWInfSection CWInfFile::AddSectionIfNotPresent(IN PCWSTR szSectionName)
  1072. {
  1073. CWInfSection* pwis;
  1074. pwis = FindSection(szSectionName);
  1075. if (!pwis)
  1076. {
  1077. pwis = AddSection(szSectionName);
  1078. }
  1079. return pwis;
  1080. }
  1081. //+---------------------------------------------------------------------------
  1082. //
  1083. // Member: CWInfFile::GotoEndOfSection
  1084. //
  1085. // Purpose: Sets write context to the end of a given section
  1086. // (so that more keys can be added to the end)
  1087. //
  1088. //
  1089. // Arguments:
  1090. // pwisSection [in] the given Section
  1091. //
  1092. // Returns: none
  1093. //
  1094. // Author: kumarp 12 April 97 (05:53:03 pm)
  1095. //
  1096. // Notes:
  1097. // Sets the current write-context to the end of pwisSection
  1098. //
  1099. void CWInfFile::GotoEndOfSection(PCWInfSection pwisSection)
  1100. {
  1101. // line corresponding to the end of current section is the line
  1102. // prior to the next section
  1103. WifLinePtrListIter posEndOfSection, posNextSection;
  1104. posNextSection = pwisSection->m_posSection;
  1105. posNextSection++;
  1106. if (posNextSection == m_plSections->end())
  1107. {
  1108. posEndOfSection = GetIterAtBack(m_plLines);
  1109. }
  1110. else
  1111. {
  1112. PCWInfSection pwisNextSection;
  1113. pwisNextSection = (PCWInfSection) *posNextSection;
  1114. posEndOfSection = pwisNextSection->m_posLine;
  1115. --posEndOfSection;
  1116. }
  1117. m_WriteContext.posSection = pwisSection->m_posSection;
  1118. m_WriteContext.posLine = posEndOfSection;
  1119. }
  1120. //+---------------------------------------------------------------------------
  1121. //
  1122. // Member: CWInfFile::GotoEnd
  1123. //
  1124. // Purpose: Sets write context to the end of the file
  1125. //
  1126. //
  1127. // Arguments:
  1128. // pwisSection [in] the given Section
  1129. //
  1130. // Returns: none
  1131. //
  1132. // Author: kumarp 12 April 97 (05:53:03 pm)
  1133. //
  1134. // Notes:
  1135. //
  1136. void CWInfFile::GotoEnd()
  1137. {
  1138. m_WriteContext.posSection = GetIterAtBack(m_plSections);
  1139. m_WriteContext.posLine = GetIterAtBack(m_plLines);
  1140. }
  1141. //+---------------------------------------------------------------------------
  1142. //
  1143. // Member: CWInfFile::AddKey
  1144. //
  1145. // Purpose: Adds a key in the current section
  1146. //
  1147. //
  1148. // Arguments:
  1149. // pszKeyName [in] Key to add
  1150. // pszValue [in] value to assign
  1151. //
  1152. // Returns: none
  1153. //
  1154. // Author: kumarp 12 April 97 (05:53:03 pm)
  1155. //
  1156. // Notes:
  1157. //
  1158. void CWInfFile::AddKey(IN PCWSTR pszKeyName, IN PCWSTR pszValue)
  1159. {
  1160. AddKey(pszKeyName)->SetValue(pszValue);
  1161. }
  1162. //+---------------------------------------------------------------------------
  1163. //
  1164. // Member: CWInfFile::AddKey
  1165. //
  1166. // Purpose: Adds a key in the current section
  1167. //
  1168. //
  1169. // Arguments:
  1170. // pszKeyName [in] Key to add
  1171. //
  1172. // Returns: pointer to the key just added, NULL in case of error
  1173. //
  1174. // Author: kumarp 12 April 97 (05:53:03 pm)
  1175. //
  1176. // Notes:
  1177. // No value is assigned
  1178. //
  1179. PCWInfKey CWInfFile::AddKey(IN PCWSTR pszKeyName)
  1180. {
  1181. CWInfKey *key;
  1182. key = new CWInfKey(pszKeyName);
  1183. AddLine(key);
  1184. return key;
  1185. }
  1186. //+---------------------------------------------------------------------------
  1187. //
  1188. // Member: CWInfFile::AddKey
  1189. //
  1190. // Purpose: Adds a key in the current section
  1191. //
  1192. //
  1193. // Arguments:
  1194. // pszKeyName [in] Key to add
  1195. // dwValue [in] value
  1196. //
  1197. // Returns: none
  1198. //
  1199. // Author: kumarp 12 April 97 (05:53:03 pm)
  1200. //
  1201. // Notes:
  1202. //
  1203. void CWInfFile::AddKey(IN PCWSTR pszKeyName, IN DWORD dwValue)
  1204. {
  1205. AddKey(pszKeyName)->SetValue(dwValue);
  1206. }
  1207. //+---------------------------------------------------------------------------
  1208. //
  1209. // Member: CWInfFile::AddQwordKey
  1210. //
  1211. // Purpose: Adds a key in the current section
  1212. //
  1213. //
  1214. // Arguments:
  1215. // pszKeyName [in] Key to add
  1216. // qwValue [in] value
  1217. //
  1218. // Returns: none
  1219. //
  1220. // Author: kumarp 12 April 97 (05:53:03 pm)
  1221. //
  1222. // Notes:
  1223. //
  1224. void CWInfFile::AddQwordKey(IN PCWSTR pszKeyName, IN QWORD qwValue)
  1225. {
  1226. AddKey(pszKeyName)->SetValue(qwValue);
  1227. }
  1228. //+---------------------------------------------------------------------------
  1229. //
  1230. // Member: CWInfFile::AddHexKey
  1231. //
  1232. // Purpose: Adds a key in the current section, stores value in hex.
  1233. //
  1234. //
  1235. // Arguments:
  1236. // pszKeyName [in] Key to add
  1237. // dwValue [in] value
  1238. //
  1239. // Returns: none
  1240. //
  1241. // Author: kumarp 12 April 97 (05:53:03 pm)
  1242. //
  1243. // Notes:
  1244. //
  1245. void CWInfFile::AddHexKey(IN PCWSTR pszKeyName, IN DWORD dwValue)
  1246. {
  1247. AddKey(pszKeyName)->SetHexValue(dwValue);
  1248. }
  1249. //+---------------------------------------------------------------------------
  1250. //
  1251. // Member: CWInfFile::AddBoolKey
  1252. //
  1253. // Purpose: Adds a key in the current section
  1254. //
  1255. //
  1256. // Arguments:
  1257. // pszKeyName [in] Key to add
  1258. // fValue [in] value
  1259. //
  1260. // Returns: none
  1261. //
  1262. // Author: kumarp 12 April 97 (05:53:03 pm)
  1263. //
  1264. // Notes:
  1265. // TRUE is stored as "Yes"
  1266. // FALSE is stored as "No"
  1267. //
  1268. void CWInfFile::AddBoolKey(IN PCWSTR pszKeyName, IN BOOL Value)
  1269. {
  1270. AddKey(pszKeyName)->SetBoolValue(Value);
  1271. }
  1272. //+---------------------------------------------------------------------------
  1273. //
  1274. // Member: CWInfFile::AddKeyV
  1275. //
  1276. // Purpose: Adds a key in the current section
  1277. //
  1278. //
  1279. // Arguments:
  1280. // pszKeyName [in] Key to add
  1281. // pszFormat [in] format string (printf style)
  1282. //
  1283. // Returns: none
  1284. //
  1285. // Author: kumarp 12 April 97 (05:53:03 pm)
  1286. //
  1287. // Notes:
  1288. //
  1289. void CWInfFile::AddKeyV(IN PCWSTR pszKeyName, IN PCWSTR Format, IN ...)
  1290. {
  1291. va_list arglist;
  1292. va_start (arglist, Format);
  1293. AddKey(pszKeyName)->SetValues(Format, arglist);
  1294. va_end(arglist);
  1295. }
  1296. //+---------------------------------------------------------------------------
  1297. //
  1298. // Member: CWInfFile::AddKey
  1299. //
  1300. // Purpose: Adds a key in the current section
  1301. //
  1302. //
  1303. // Arguments:
  1304. // pszKeyName [in] Key to add
  1305. // pszFormat [in] format string (printf style)
  1306. // arglist [in] argument list
  1307. //
  1308. // Returns: none
  1309. //
  1310. // Author: kumarp 12 April 97 (05:53:03 pm)
  1311. //
  1312. // Notes:
  1313. //
  1314. void CWInfFile::AddKey(IN PCWSTR pszKeyName, IN PCWSTR Format, IN va_list arglist)
  1315. {
  1316. AddKey(pszKeyName)->SetValues(Format, arglist);
  1317. }
  1318. //+---------------------------------------------------------------------------
  1319. //
  1320. // Member: CWInfFile::AddKey
  1321. //
  1322. // Purpose: Adds a key in the current section
  1323. //
  1324. //
  1325. // Arguments:
  1326. // pszKeyName [in] Key to add
  1327. // slValues [in] values in the form of a string list
  1328. //
  1329. // Returns: none
  1330. //
  1331. // Author: kumarp 12 April 97 (05:53:03 pm)
  1332. //
  1333. // Notes:
  1334. // The string-list is converted to a comma-delimited list before
  1335. // the value is assigned to the key
  1336. //
  1337. void CWInfFile::AddKey(IN PCWSTR pszKeyName, IN const TStringList &slValues)
  1338. {
  1339. AddKey(pszKeyName)->SetValue(slValues);
  1340. }
  1341. //+---------------------------------------------------------------------------
  1342. //
  1343. // Member: CWInfFile::AddComment
  1344. //
  1345. // Purpose: Adds a comment in the current section
  1346. //
  1347. //
  1348. // Arguments:
  1349. // pszComment [in] text of the comment
  1350. //
  1351. // Returns: none
  1352. //
  1353. // Author: kumarp 12 April 97 (05:53:03 pm)
  1354. //
  1355. // Notes:
  1356. // A "; " is prefixed to pszComment before it is inserted into the section.
  1357. //
  1358. void CWInfFile::AddComment(IN PCWSTR pszComment)
  1359. {
  1360. CWInfComment *Comment;
  1361. Comment = new CWInfComment(pszComment);
  1362. AddLine(Comment);
  1363. }
  1364. //+---------------------------------------------------------------------------
  1365. //
  1366. // Member: CWInfFile::AddRawLine
  1367. //
  1368. // Purpose: Adds a raw line in the current section
  1369. //
  1370. //
  1371. // Arguments:
  1372. // szText [in] text to add
  1373. //
  1374. // Returns: none
  1375. //
  1376. // Author: danielwe 11 Jun 1997
  1377. //
  1378. void CWInfFile::AddRawLine(IN PCWSTR szText)
  1379. {
  1380. CWInfRaw *pwir;
  1381. pwir = new CWInfRaw(szText);
  1382. AddLine(pwir);
  1383. }
  1384. //+---------------------------------------------------------------------------
  1385. //
  1386. // Member: CWInfFile::AddRawLines
  1387. //
  1388. // Purpose: Adds a raw line in the current section
  1389. //
  1390. //
  1391. // Arguments:
  1392. // szText [in] text to add
  1393. //
  1394. // Returns: none
  1395. //
  1396. // Author: danielwe 11 Jun 1997
  1397. //
  1398. void CWInfFile::AddRawLines(IN PCWSTR* pszLines, IN DWORD cLines)
  1399. {
  1400. AssertValidReadPtr(pszLines);
  1401. AssertSz(cLines, "CWInfFile::AddRawLines: dont add 0 lines");
  1402. CWInfRaw *pwir;
  1403. for (DWORD i=0; i<cLines; i++)
  1404. {
  1405. AssertSz(pszLines[i], "CWInfRaw::AddRawLines: One of the lines is bad");
  1406. pwir = new CWInfRaw(pszLines[i]);
  1407. AddLine(pwir);
  1408. }
  1409. }
  1410. // ----------------------------------------------------------------------
  1411. // CWInfFile protected functions
  1412. // ----------------------------------------------------------------------
  1413. //+---------------------------------------------------------------------------
  1414. //
  1415. // Member: CWInfFile::CurrentWriteSection
  1416. //
  1417. // Purpose: Get a pointer to the section selected for writing
  1418. //
  1419. //
  1420. // Arguments: none
  1421. //
  1422. // Returns: pointer to the section if exists, NULL if file has no sections
  1423. //
  1424. // Author: kumarp 12 April 97 (05:53:03 pm)
  1425. //
  1426. // Notes:
  1427. //
  1428. PCWInfSection CWInfFile::CurrentWriteSection() const
  1429. {
  1430. WifLinePtrListIter pos = m_WriteContext.posSection;
  1431. if (pos == m_plSections->end())
  1432. {
  1433. return NULL;
  1434. }
  1435. else
  1436. {
  1437. return (PCWInfSection) *pos;
  1438. }
  1439. }
  1440. //+---------------------------------------------------------------------------
  1441. //
  1442. // Member: CWInfFile::CurrentReadSection
  1443. //
  1444. // Purpose: Get a pointer to the section selected for reading
  1445. //
  1446. //
  1447. // Arguments: none
  1448. //
  1449. // Returns: pointer to the section if exists, NULL if file has no sections
  1450. //
  1451. // Author: kumarp 12 April 97 (05:53:03 pm)
  1452. //
  1453. // Notes:
  1454. //
  1455. PCWInfSection CWInfFile::CurrentReadSection() const
  1456. {
  1457. PCWInfSection pwisCurrent;
  1458. WifLinePtrListIter pos = m_ReadContext.posSection;
  1459. if (pos == m_plSections->end())
  1460. {
  1461. return NULL;
  1462. }
  1463. else
  1464. {
  1465. pwisCurrent = (PCWInfSection) *pos;
  1466. return pwisCurrent;
  1467. }
  1468. }
  1469. //+---------------------------------------------------------------------------
  1470. //
  1471. // Function: CWInfFile::RemoveSection
  1472. //
  1473. // Purpose: Remove a section and its contents
  1474. //
  1475. // Arguments:
  1476. // szSectionName [in] name of Section to remove
  1477. //
  1478. // Returns: None
  1479. //
  1480. // Author: kumarp 09-December-98
  1481. //
  1482. // Notes:
  1483. //
  1484. void CWInfFile::RemoveSection(IN PCWSTR szSectionName)
  1485. {
  1486. CWInfSection* pwis;
  1487. if (pwis = FindSection(szSectionName))
  1488. {
  1489. m_plSections->erase(pwis->m_posSection);
  1490. WifLinePtrListIter pos = pwis->m_posLine;
  1491. WifLinePtrListIter posTemp;
  1492. do
  1493. {
  1494. posTemp = pos;
  1495. pos++;
  1496. m_plLines->erase(posTemp);
  1497. }
  1498. while (pos != m_plLines->end() &&
  1499. ((CWInfLine*) *pos)->Type() != INF_SECTION);
  1500. }
  1501. }
  1502. //+---------------------------------------------------------------------------
  1503. //
  1504. // Function: CWInfFile::RemoveSections
  1505. //
  1506. // Purpose: Remove the specified sections
  1507. //
  1508. // Arguments:
  1509. // slSections [in] list of sections to remove
  1510. //
  1511. // Returns: None
  1512. //
  1513. // Author: kumarp 09-December-98
  1514. //
  1515. // Notes:
  1516. //
  1517. void CWInfFile::RemoveSections(IN TStringList& slSections)
  1518. {
  1519. PCWSTR szSectionName;
  1520. TStringListIter pos;
  1521. pos = slSections.begin();
  1522. while (pos != slSections.end())
  1523. {
  1524. szSectionName = (*pos)->c_str();
  1525. pos++;
  1526. RemoveSection(szSectionName);
  1527. }
  1528. }
  1529. //+---------------------------------------------------------------------------
  1530. //
  1531. // Member: CWInfFile::AddLine
  1532. //
  1533. // Purpose: Add a CWInfLine in the current section, adjust write context.
  1534. //
  1535. // Arguments:
  1536. // ilLine [in] pointer to a CWInfLine
  1537. //
  1538. // Returns: TRUE on success, FALSE otherwise
  1539. //
  1540. // Author: kumarp 12 April 97 (05:53:03 pm)
  1541. //
  1542. // Notes:
  1543. //
  1544. BOOL CWInfFile::AddLine(IN const PCWInfLine ilLine)
  1545. {
  1546. CWInfSection *section = CurrentWriteSection();
  1547. if (!section)
  1548. return FALSE;
  1549. WifLinePtrListIter pos;
  1550. pos = m_WriteContext.posLine;
  1551. pos++;
  1552. pos = m_plLines->insert(pos, ilLine);
  1553. m_WriteContext.posLine = pos;
  1554. return TRUE;
  1555. }
  1556. // ======================================================================
  1557. // Class CWInfSection
  1558. // ======================================================================
  1559. // ----------------------------------------------------------------------
  1560. // CWInfSection public functions
  1561. // ----------------------------------------------------------------------
  1562. //+---------------------------------------------------------------------------
  1563. //
  1564. // Member: CWInfSection::GetText
  1565. //
  1566. // Purpose: Get text representation of this section.
  1567. //
  1568. // Arguments:
  1569. // text [in] string that receives the text
  1570. //
  1571. // Returns: none
  1572. //
  1573. // Author: kumarp 12 April 97 (05:53:03 pm)
  1574. //
  1575. // Notes:
  1576. //
  1577. void CWInfSection::GetText(OUT tstring &text) const
  1578. {
  1579. text = L"[" + m_Name + L"]";
  1580. }
  1581. // used by SysPrep
  1582. void CWInfSection::GetTextEx(OUT tstring &text) const
  1583. {
  1584. text = L"[" + m_Name + L"]";
  1585. }
  1586. //+---------------------------------------------------------------------------
  1587. //
  1588. // Member: CWInfSection::FindKey
  1589. //
  1590. // Purpose: Find a key in this section
  1591. //
  1592. //
  1593. // Arguments:
  1594. // pszKeyName [in] Key to find
  1595. // wsmMode [in] Search mode
  1596. // (search from beginning-of-section / current-position)
  1597. // Returns: Pointer to the key if found, NULL otherwise
  1598. //
  1599. // Author: kumarp 12 April 97 (05:53:03 pm)
  1600. //
  1601. // Notes:
  1602. //
  1603. PCWInfKey CWInfSection::FindKey(IN PCWSTR pszKeyName,
  1604. IN WInfSearchMode wsmMode)
  1605. {
  1606. m_Parent->SetCurrentReadSection(this);
  1607. return m_Parent->FindKey(pszKeyName, wsmMode);
  1608. }
  1609. //+---------------------------------------------------------------------------
  1610. //
  1611. // Member: CWInfSection::FirstKey
  1612. //
  1613. // Purpose: Return the first key in this section
  1614. //
  1615. //
  1616. // Arguments: none
  1617. //
  1618. // Returns: Pointer to the key if found, NULL otherwise
  1619. //
  1620. // Author: kumarp 12 April 97 (05:53:03 pm)
  1621. //
  1622. // Notes:
  1623. // Sets read-context to this key
  1624. //
  1625. PCWInfKey CWInfSection::FirstKey()
  1626. {
  1627. m_Parent->SetCurrentReadSection(this);
  1628. return m_Parent->FirstKey();
  1629. }
  1630. //+---------------------------------------------------------------------------
  1631. //
  1632. // Member: CWInfSection::NextKey
  1633. //
  1634. // Purpose: Return the next key in this section
  1635. //
  1636. //
  1637. // Arguments: none
  1638. //
  1639. // Returns: Pointer to the key if found, NULL otherwise
  1640. //
  1641. // Author: kumarp 12 April 97 (05:53:03 pm)
  1642. //
  1643. // Notes:
  1644. // Sets read-context to this key
  1645. //
  1646. PCWInfKey CWInfSection::NextKey()
  1647. {
  1648. m_Parent->SetCurrentReadSection(this);
  1649. return m_Parent->NextKey();
  1650. }
  1651. //+---------------------------------------------------------------------------
  1652. //
  1653. // Member: CWInfSection::GetStringArrayValue
  1654. //
  1655. // Purpose: Return the value of the given key as a string-Array
  1656. //
  1657. //
  1658. // Arguments:
  1659. // pszKeyName [in] Key to find
  1660. // saStrings [out] Array value to return
  1661. //
  1662. // Returns: TRUE if key found and value in correct format, FALSE otherwise
  1663. //
  1664. // Author: kumarp 12-November-97
  1665. //
  1666. // Notes:
  1667. // If the value is a comma-delimited list, converts it to a TStringArray
  1668. // otherwise returns a TStringArray with a single element
  1669. //
  1670. BOOL CWInfSection::GetStringArrayValue(IN PCWSTR pszKeyName, OUT TStringArray &saStrings)
  1671. {
  1672. CWInfKey* key;
  1673. key = FindKey(pszKeyName);
  1674. if (key)
  1675. {
  1676. return key->GetStringArrayValue(saStrings);
  1677. }
  1678. else
  1679. {
  1680. return FALSE;
  1681. }
  1682. }
  1683. //+---------------------------------------------------------------------------
  1684. //
  1685. // Member: CWInfSection::GetStringListValue
  1686. //
  1687. // Purpose: Return the value of the given key as a string-list
  1688. //
  1689. //
  1690. // Arguments:
  1691. // pszKeyName [in] Key to find
  1692. // pslList [out] List value to return
  1693. //
  1694. // Returns: TRUE if key found and value in correct format, FALSE otherwise
  1695. //
  1696. // Author: kumarp 12 April 97 (05:53:03 pm)
  1697. //
  1698. // Notes:
  1699. // If the value is a comma-delimited list, converts it to a TStringList
  1700. // otherwise returns a TStringList with a single element
  1701. //
  1702. BOOL CWInfSection::GetStringListValue(IN PCWSTR pszKeyName, OUT TStringList &pslList)
  1703. {
  1704. CWInfKey* key;
  1705. key = FindKey(pszKeyName, ISM_FromBeginning);
  1706. if (!key)
  1707. return FALSE;
  1708. return key->GetStringListValue(pslList);
  1709. }
  1710. //+---------------------------------------------------------------------------
  1711. //
  1712. // Member: CWInfSection::GetStringValue
  1713. //
  1714. // Purpose: Return the value of the given key as a string
  1715. //
  1716. //
  1717. // Arguments:
  1718. // pszKeyName [in] Key to find
  1719. // strValue [out] string value to return
  1720. //
  1721. // Returns: TRUE if key found and value in correct format, FALSE otherwise
  1722. //
  1723. // Author: kumarp 12 April 97 (05:53:03 pm)
  1724. //
  1725. // Notes:
  1726. //
  1727. BOOL CWInfSection::GetStringValue(IN PCWSTR pszKeyName, OUT tstring &strValue)
  1728. {
  1729. CWInfKey* key;
  1730. key = FindKey(pszKeyName, ISM_FromBeginning);
  1731. if (!key)
  1732. return FALSE;
  1733. return key->GetStringValue(strValue);
  1734. }
  1735. //+---------------------------------------------------------------------------
  1736. //
  1737. // Member: CWInfSection::GetIntValue
  1738. //
  1739. // Purpose: Return the value of the given key as an integer
  1740. //
  1741. //
  1742. // Arguments:
  1743. // pszKeyName [in] Key to find
  1744. // pdwValue [out] int value to return
  1745. //
  1746. // Returns: TRUE if key found and value in correct format, FALSE otherwise
  1747. //
  1748. // Author: kumarp 12 April 97 (05:53:03 pm)
  1749. //
  1750. // Notes:
  1751. //
  1752. BOOL CWInfSection::GetIntValue(IN PCWSTR pszKeyName, OUT DWORD *pdwValue)
  1753. {
  1754. CWInfKey* key;
  1755. key = FindKey(pszKeyName, ISM_FromBeginning);
  1756. if (!key)
  1757. return FALSE;
  1758. return key->GetIntValue(pdwValue);
  1759. }
  1760. //+---------------------------------------------------------------------------
  1761. //
  1762. // Member: CWInfSection::GetQwordValue
  1763. //
  1764. // Purpose: Return the value of the given key as a QWORD
  1765. //
  1766. //
  1767. // Arguments:
  1768. // pszKeyName [in] Key to find
  1769. // pqwValue [out] int value to return
  1770. //
  1771. // Returns: TRUE if key found and value in correct format, FALSE otherwise
  1772. //
  1773. // Author: kumarp 12 April 97 (05:53:03 pm)
  1774. //
  1775. // Notes:
  1776. //
  1777. BOOL CWInfSection::GetQwordValue(IN PCWSTR pszKeyName, OUT QWORD *pqwValue)
  1778. {
  1779. CWInfKey* key;
  1780. key = FindKey(pszKeyName, ISM_FromBeginning);
  1781. if (!key)
  1782. return FALSE;
  1783. return key->GetQwordValue(pqwValue);
  1784. }
  1785. //+---------------------------------------------------------------------------
  1786. //
  1787. // Member: CWInfSection::GetBoolValue
  1788. //
  1789. // Purpose: Return the value of the given key as a BOOL
  1790. //
  1791. //
  1792. // Arguments:
  1793. // pszKeyName [in] Key to find
  1794. // pfValue [out] BOOL value to return
  1795. //
  1796. // Returns: TRUE if key found and value in correct format, FALSE otherwise
  1797. //
  1798. // Author: kumarp 12 April 97 (05:53:03 pm)
  1799. //
  1800. // Notes:
  1801. // converts:
  1802. // "True" / "Yes" / 1 to TRUE
  1803. // "False" / "No" / 0 to FALSE
  1804. //
  1805. BOOL CWInfSection::GetBoolValue(IN PCWSTR pszKeyName, OUT BOOL *pfValue)
  1806. {
  1807. CWInfKey* key;
  1808. key = FindKey(pszKeyName, ISM_FromBeginning);
  1809. if (!key)
  1810. return FALSE;
  1811. return key->GetBoolValue(pfValue);
  1812. }
  1813. //+---------------------------------------------------------------------------
  1814. //
  1815. // Member: CWInfSection::GetStringValue
  1816. //
  1817. // Purpose: Return the value of the given key as a string
  1818. //
  1819. //
  1820. // Arguments:
  1821. // pszKeyName [in] Key to find
  1822. // pszDefault [in] default value
  1823. //
  1824. // Returns: value if key found and value in correct format,
  1825. // otherwise returns the default-value
  1826. //
  1827. // Author: kumarp 12 April 97 (05:53:03 pm)
  1828. //
  1829. // Notes:
  1830. //
  1831. PCWSTR CWInfSection::GetStringValue(IN PCWSTR pszKeyName, IN PCWSTR pszDefault)
  1832. {
  1833. CWInfKey* key;
  1834. key = FindKey(pszKeyName, ISM_FromBeginning);
  1835. if (!key)
  1836. {
  1837. return pszDefault;
  1838. }
  1839. return key->GetStringValue(pszDefault);
  1840. }
  1841. //+---------------------------------------------------------------------------
  1842. //
  1843. // Member: CWInfSection::GetIntValue
  1844. //
  1845. // Purpose: Return the value of the given key as an int
  1846. //
  1847. //
  1848. // Arguments:
  1849. // pszKeyName [in] Key to find
  1850. // dwDefault [in] default value
  1851. //
  1852. // Returns: value if key found and value in correct format,
  1853. // otherwise returns the default-value
  1854. //
  1855. // Author: kumarp 12 April 97 (05:53:03 pm)
  1856. //
  1857. // Notes:
  1858. //
  1859. DWORD CWInfSection::GetIntValue(IN PCWSTR pszKeyName, IN DWORD dwDefault)
  1860. {
  1861. CWInfKey* key;
  1862. key = FindKey(pszKeyName, ISM_FromBeginning);
  1863. if (!key)
  1864. {
  1865. return dwDefault;
  1866. }
  1867. return key->GetIntValue(dwDefault);
  1868. }
  1869. //+---------------------------------------------------------------------------
  1870. //
  1871. // Member: CWInfSection::GetQwordValue
  1872. //
  1873. // Purpose: Return the value of the given key as a QWORD
  1874. //
  1875. //
  1876. // Arguments:
  1877. // pszKeyName [in] Key to find
  1878. // qwDefault [in] default value
  1879. //
  1880. // Returns: value if key found and value in correct format,
  1881. // otherwise returns the default-value
  1882. //
  1883. // Author: kumarp 12 April 97 (05:53:03 pm)
  1884. //
  1885. // Notes:
  1886. //
  1887. QWORD CWInfSection::GetQwordValue(IN PCWSTR pszKeyName, IN QWORD qwDefault)
  1888. {
  1889. CWInfKey* key;
  1890. key = FindKey(pszKeyName);
  1891. if (!key)
  1892. {
  1893. return qwDefault;
  1894. }
  1895. return key->GetQwordValue(qwDefault);
  1896. }
  1897. //+---------------------------------------------------------------------------
  1898. //
  1899. // Member: CWInfSection::GetBoolValue
  1900. //
  1901. // Purpose: Return the value of the given key as a BOOL
  1902. //
  1903. //
  1904. // Arguments:
  1905. // pszKeyName [in] Key to find
  1906. // fDefault [in] default value
  1907. //
  1908. // Returns: value if key found and value in correct format,
  1909. // otherwise returns the default-value
  1910. //
  1911. // Author: kumarp 12 April 97 (05:53:03 pm)
  1912. //
  1913. // Notes:
  1914. //
  1915. BOOL CWInfSection::GetBoolValue(IN PCWSTR pszKeyName, IN BOOL fDefault)
  1916. {
  1917. CWInfKey* key;
  1918. key = FindKey(pszKeyName, ISM_FromBeginning);
  1919. if (!key)
  1920. {
  1921. return fDefault;
  1922. }
  1923. return key->GetBoolValue(fDefault);
  1924. }
  1925. //+---------------------------------------------------------------------------
  1926. //
  1927. // Member: CWInfSection::GotoEnd
  1928. //
  1929. // Purpose: Sets write context to the end of this section
  1930. // (so that more keys can be added to the end)
  1931. //
  1932. // Arguments: none
  1933. //
  1934. // Returns: none
  1935. //
  1936. // Author: kumarp 12 April 97 (05:53:03 pm)
  1937. //
  1938. // Notes:
  1939. // Sets this write-context to the end of pwisSection
  1940. //
  1941. void CWInfSection::GotoEnd()
  1942. {
  1943. m_Parent->GotoEndOfSection(this);
  1944. }
  1945. //+---------------------------------------------------------------------------
  1946. //
  1947. // Member: CWInfSection::AddKey
  1948. //
  1949. // Purpose: Adds a key in this section
  1950. //
  1951. //
  1952. // Arguments:
  1953. // pszKeyName [in] Key to add
  1954. //
  1955. // Returns: pointer to the key just added, NULL in case of error
  1956. //
  1957. // Author: kumarp 12 April 97 (05:53:03 pm)
  1958. //
  1959. // Notes:
  1960. // No value is assigned
  1961. //
  1962. PCWInfKey CWInfSection::AddKey(IN PCWSTR pszKeyName)
  1963. {
  1964. GotoEnd();
  1965. return m_Parent->AddKey(pszKeyName);
  1966. }
  1967. //+---------------------------------------------------------------------------
  1968. //
  1969. // Member: CWInfSection::AddKey
  1970. //
  1971. // Purpose: Adds a key in this section
  1972. //
  1973. //
  1974. // Arguments:
  1975. // pszKeyName [in] Key to add
  1976. // pszValue [in] value to assign
  1977. //
  1978. // Returns: none
  1979. //
  1980. // Author: kumarp 12 April 97 (05:53:03 pm)
  1981. //
  1982. // Notes:
  1983. //
  1984. void CWInfSection::AddKey(IN PCWSTR pszKeyName, IN PCWSTR pszValue)
  1985. {
  1986. GotoEnd();
  1987. m_Parent->AddKey(pszKeyName, pszValue);
  1988. }
  1989. //+---------------------------------------------------------------------------
  1990. //
  1991. // Member: CWInfSection::AddKey
  1992. //
  1993. // Purpose: Adds a key in this section
  1994. //
  1995. //
  1996. // Arguments:
  1997. // pszKeyName [in] Key to add
  1998. // dwValue [in] value
  1999. //
  2000. // Returns: none
  2001. //
  2002. // Author: kumarp 12 April 97 (05:53:03 pm)
  2003. //
  2004. // Notes:
  2005. //
  2006. void CWInfSection::AddKey(IN PCWSTR pszKeyName, IN DWORD Value)
  2007. {
  2008. GotoEnd();
  2009. m_Parent->AddKey(pszKeyName, Value);
  2010. }
  2011. //+---------------------------------------------------------------------------
  2012. //
  2013. // Member: CWInfSection::AddQwordKey
  2014. //
  2015. // Purpose: Adds a key in the current section
  2016. //
  2017. //
  2018. // Arguments:
  2019. // pszKeyName [in] Key to add
  2020. // qwValue [in] value
  2021. //
  2022. // Returns: none
  2023. //
  2024. // Author: kumarp 12 April 97 (05:53:03 pm)
  2025. //
  2026. // Notes:
  2027. //
  2028. void CWInfSection::AddQwordKey(IN PCWSTR pszKeyName, IN QWORD qwValue)
  2029. {
  2030. AddKey(pszKeyName)->SetQwordValue(qwValue);
  2031. }
  2032. //+---------------------------------------------------------------------------
  2033. //
  2034. // Member: CWInfSection::AddHexKey
  2035. //
  2036. // Purpose: Adds a key in this section, stores value in hex.
  2037. //
  2038. //
  2039. // Arguments:
  2040. // pszKeyName [in] Key to add
  2041. // dwValue [in] value
  2042. //
  2043. // Returns: none
  2044. //
  2045. // Author: kumarp 12 April 97 (05:53:03 pm)
  2046. //
  2047. // Notes:
  2048. //
  2049. void CWInfSection::AddHexKey(IN PCWSTR pszKeyName, IN DWORD Value)
  2050. {
  2051. GotoEnd();
  2052. m_Parent->AddHexKey(pszKeyName, Value);
  2053. }
  2054. //+---------------------------------------------------------------------------
  2055. //
  2056. // Member: CWInfSection::AddKey
  2057. //
  2058. // Purpose: Adds a key in this section
  2059. //
  2060. //
  2061. // Arguments:
  2062. // pszKeyName [in] Key to add
  2063. // slValues [in] values in the form of a string list
  2064. //
  2065. // Returns: none
  2066. //
  2067. // Author: kumarp 12 April 97 (05:53:03 pm)
  2068. //
  2069. // Notes:
  2070. // The string-list is converted to a comma-delimited list before
  2071. // the value is assigned to the key
  2072. //
  2073. void CWInfSection::AddKey(IN PCWSTR pszKeyName, IN const TStringList &slValues)
  2074. {
  2075. GotoEnd();
  2076. m_Parent->AddKey(pszKeyName, slValues);
  2077. }
  2078. //+---------------------------------------------------------------------------
  2079. //
  2080. // Member: CWInfSection::AddBoolKey
  2081. //
  2082. // Purpose: Adds a key in this section
  2083. //
  2084. //
  2085. // Arguments:
  2086. // pszKeyName [in] Key to add
  2087. // fValue [in] value
  2088. //
  2089. // Returns: none
  2090. //
  2091. // Author: kumarp 12 April 97 (05:53:03 pm)
  2092. //
  2093. // Notes:
  2094. // TRUE is stored as "Yes"
  2095. // FALSE is stored as "No"
  2096. //
  2097. void CWInfSection::AddBoolKey(IN PCWSTR pszKeyName, IN BOOL Value)
  2098. {
  2099. GotoEnd();
  2100. m_Parent->AddBoolKey(pszKeyName, Value);
  2101. }
  2102. //+---------------------------------------------------------------------------
  2103. //
  2104. // Member: CWInfSection::AddKeyV
  2105. //
  2106. // Purpose: Adds a key in this section
  2107. //
  2108. //
  2109. // Arguments:
  2110. // pszKeyName [in] Key to add
  2111. // pszFormat [in] format string (printf style)
  2112. //
  2113. // Returns: none
  2114. //
  2115. // Author: kumarp 12 April 97 (05:53:03 pm)
  2116. //
  2117. // Notes:
  2118. //
  2119. void CWInfSection::AddKeyV(IN PCWSTR pszKeyName, IN PCWSTR Format, IN ...)
  2120. {
  2121. GotoEnd();
  2122. va_list arglist;
  2123. va_start (arglist, Format);
  2124. m_Parent->AddKey(pszKeyName, Format, arglist);
  2125. va_end(arglist);
  2126. }
  2127. //+---------------------------------------------------------------------------
  2128. //
  2129. // Member: CWInfSection::AddComment
  2130. //
  2131. // Purpose: Adds a comment in this section
  2132. //
  2133. //
  2134. // Arguments:
  2135. // pszComment [in] text of the comment
  2136. //
  2137. // Returns: none
  2138. //
  2139. // Author: kumarp 12 April 97 (05:53:03 pm)
  2140. //
  2141. // Notes:
  2142. // A "; " is prefixed to pszComment before it is inserted into the section.
  2143. //
  2144. void CWInfSection::AddComment(IN PCWSTR pszComment)
  2145. {
  2146. GotoEnd();
  2147. m_Parent->AddComment(pszComment);
  2148. }
  2149. //+---------------------------------------------------------------------------
  2150. //
  2151. // Member: CWInfSection::AddComment
  2152. //
  2153. // Purpose: Adds a comment in this section
  2154. //
  2155. //
  2156. // Arguments:
  2157. // szLine [in] raw line to be inserted
  2158. //
  2159. // Returns: none
  2160. //
  2161. // Author: danielwe 11 Jun 1997
  2162. //
  2163. void CWInfSection::AddRawLine(IN PCWSTR szLine)
  2164. {
  2165. GotoEnd();
  2166. m_Parent->AddRawLine(szLine);
  2167. }
  2168. // ----------------------------------------------------------------------
  2169. // CWInfSection protected functions
  2170. // ----------------------------------------------------------------------
  2171. //+---------------------------------------------------------------------------
  2172. //
  2173. // Member: CWInfSection::CWInfSection
  2174. //
  2175. // Purpose: constructor
  2176. //
  2177. // Arguments: none
  2178. //
  2179. // Author: kumarp 12 April 97 (05:53:03 pm)
  2180. //
  2181. // Notes:
  2182. //
  2183. CWInfSection::CWInfSection(IN PCWSTR SectionName, IN PCWInfFile parent)
  2184. : CWInfLine(INF_SECTION)
  2185. {
  2186. m_Name = SectionName;
  2187. m_posLine = 0;
  2188. m_Parent = parent;
  2189. }
  2190. //+---------------------------------------------------------------------------
  2191. //
  2192. // Member: CWInfSection::~CWInfSection
  2193. //
  2194. // Purpose: destructor
  2195. //
  2196. // Arguments: none
  2197. //
  2198. // Author: kumarp 12 April 97 (05:53:03 pm)
  2199. //
  2200. //
  2201. CWInfSection::~CWInfSection()
  2202. {
  2203. }
  2204. // ======================================================================
  2205. // Class CWInfKey
  2206. // ======================================================================
  2207. // ----------------------------------------------------------------------
  2208. // CWInfKey public functions
  2209. // ----------------------------------------------------------------------
  2210. WCHAR *CWInfKey::m_Buffer;
  2211. //+---------------------------------------------------------------------------
  2212. //
  2213. // Member: CWInfKey::CWInfFile
  2214. //
  2215. // Purpose: constructor
  2216. //
  2217. // Arguments: none
  2218. //
  2219. // Author: kumarp 12 April 97 (05:53:03 pm)
  2220. //
  2221. // Notes:
  2222. //
  2223. CWInfKey::CWInfKey(IN PCWSTR pszKeyName)
  2224. : CWInfLine(INF_KEY)
  2225. {
  2226. m_Value = c_szEmpty;
  2227. m_Name = pszKeyName;
  2228. m_fIsAListAndAlreadyProcessed = FALSE;
  2229. }
  2230. //+---------------------------------------------------------------------------
  2231. //
  2232. // Member: CWInfKey::~CWInfFile
  2233. //
  2234. // Purpose: destructor
  2235. //
  2236. // Arguments: none
  2237. //
  2238. // Author: kumarp 12 April 97 (05:53:03 pm)
  2239. //
  2240. //
  2241. CWInfKey::~CWInfKey()
  2242. {
  2243. }
  2244. //+---------------------------------------------------------------------------
  2245. //
  2246. // Member: CWInfKey::Init
  2247. //
  2248. // Purpose: allocate internal shared buffer
  2249. //
  2250. // Arguments: none
  2251. //
  2252. // Author: kumarp 12 April 97 (05:53:03 pm)
  2253. //
  2254. //
  2255. void CWInfKey::Init()
  2256. {
  2257. if (NULL == m_Buffer)
  2258. {
  2259. m_Buffer = new WCHAR[MAX_INF_STRING_LENGTH];
  2260. }
  2261. }
  2262. //+---------------------------------------------------------------------------
  2263. //
  2264. // Member: CWInfKey::UnInit
  2265. //
  2266. // Purpose: deallocate internal shared buffer
  2267. //
  2268. // Arguments: none
  2269. //
  2270. // Author: kumarp 12 April 97 (05:53:03 pm)
  2271. //
  2272. //
  2273. void CWInfKey::UnInit()
  2274. {
  2275. if (NULL != m_Buffer)
  2276. {
  2277. delete [] m_Buffer;
  2278. m_Buffer = NULL;
  2279. }
  2280. }
  2281. //+---------------------------------------------------------------------------
  2282. //
  2283. // Member: CWInfKey::GetText
  2284. //
  2285. // Purpose: Get text representation in the format key=value.
  2286. //
  2287. // Arguments:
  2288. // text [in] string that receives the text
  2289. //
  2290. // Returns: none
  2291. //
  2292. // Author: kumarp 12 April 97 (05:53:03 pm)
  2293. //
  2294. // Notes:
  2295. //
  2296. void CWInfKey::GetText(tstring &text) const
  2297. {
  2298. // Text mode setup does not like certain special characters in the
  2299. // value of a key. if the value has one of these characters then
  2300. // we need to enclose the entire value in quotes
  2301. //
  2302. static const WCHAR szSpecialChars[] = L" %=][";
  2303. tstring strTemp = m_Value;
  2304. tstring strTempName = m_Name;
  2305. if (!m_fIsAListAndAlreadyProcessed)
  2306. {
  2307. if (m_Value.empty() ||
  2308. (L'\"' != *(m_Value.c_str()) &&
  2309. wcscspn(m_Value.c_str(), szSpecialChars) < m_Value.size()))
  2310. {
  2311. strTemp = L"\"" + m_Value + L"\"";
  2312. }
  2313. }
  2314. if (m_Name.empty() ||
  2315. (L'\"' != *(m_Name.c_str()) &&
  2316. wcscspn(m_Name.c_str(), szSpecialChars) < m_Name.size()))
  2317. {
  2318. strTempName = L"\"" + m_Name + L"\"";
  2319. }
  2320. text = strTempName + L"=" + strTemp;
  2321. }
  2322. //+---------------------------------------------------------------------------
  2323. //
  2324. // Member: CWInfKey::GetTextEx
  2325. //
  2326. // Purpose: Get text representation in the format key=value for multi-sz value
  2327. // Otherwiese, get text representation in the format key="value"
  2328. //
  2329. // Arguments:
  2330. // text [in] string that receives the text
  2331. //
  2332. // Returns: none
  2333. //
  2334. // Author: frankli 4 May 2000
  2335. //
  2336. // Notes: value will be enclosed in quotes except for multi-sz value
  2337. //
  2338. void CWInfKey::GetTextEx(tstring &text) const
  2339. {
  2340. // we need to enclose the entire value in quotes except for multi-sz value.
  2341. // For example,
  2342. // tcpip adapter specific
  2343. // NameServer registry value is of type REG_SZ and it is a string of
  2344. // comma-delimited dns server name. We need to enclosed it in quotes,
  2345. // otherwise, it will be interpreted as multi-sz value
  2346. // Text mode setup does not like certain special characters in the
  2347. // value of a key. if the value has one of these characters then
  2348. // we need to enclose the entire value in quotes
  2349. //
  2350. static const WCHAR szSpecialChars[] = L" %=][";
  2351. tstring strTemp = m_Value;
  2352. tstring strTempName = m_Name;
  2353. if (!m_fIsAListAndAlreadyProcessed)
  2354. { // we don't do this for multi-sz value
  2355. strTemp = L"\"" + m_Value + L"\"";
  2356. }
  2357. // leave the processing of the key as in CWInfKey::GetText
  2358. if (m_Name.empty() ||
  2359. (L'\"' != *(m_Name.c_str()) &&
  2360. wcscspn(m_Name.c_str(), szSpecialChars) < m_Name.size()))
  2361. {
  2362. strTempName = L"\"" + m_Name + L"\"";
  2363. }
  2364. text = strTempName + L"=" + strTemp;
  2365. }
  2366. // --------- Read values --------------------------------------------------
  2367. //+---------------------------------------------------------------------------
  2368. //
  2369. // Member: CWInfKey::GetStringArrayValue
  2370. //
  2371. // Purpose: Return the value of the given key as a string-Array
  2372. //
  2373. //
  2374. // Arguments:
  2375. // saStrings [out] Array value to return
  2376. //
  2377. // Returns: TRUE if key found and value in correct format, FALSE otherwise
  2378. //
  2379. // Author: kumarp 12 April 97 (05:53:03 pm)
  2380. //
  2381. // Notes:
  2382. // If the value is a comma-delimited list, converts it to a TStringArray
  2383. // otherwise returns a TStringArray with a single element
  2384. //
  2385. BOOL CWInfKey::GetStringArrayValue(TStringArray &saStrings) const
  2386. {
  2387. ConvertCommaDelimitedListToStringArray(m_Value, saStrings);
  2388. return TRUE;
  2389. }
  2390. //+---------------------------------------------------------------------------
  2391. //
  2392. // Member: CWInfKey::GetStringListValue
  2393. //
  2394. // Purpose: Return the value of the given key as a string-list
  2395. //
  2396. //
  2397. // Arguments:
  2398. // pslList [out] List value to return
  2399. //
  2400. // Returns: TRUE if key found and value in correct format, FALSE otherwise
  2401. //
  2402. // Author: kumarp 12 April 97 (05:53:03 pm)
  2403. //
  2404. // Notes:
  2405. // If the value is a comma-delimited list, converts it to a TStringList
  2406. // otherwise returns a TStringList with a single element
  2407. //
  2408. BOOL CWInfKey::GetStringListValue(TStringList &pslList) const
  2409. {
  2410. ConvertCommaDelimitedListToStringList(m_Value, pslList);
  2411. return TRUE;
  2412. }
  2413. //+---------------------------------------------------------------------------
  2414. //
  2415. // Member: CWInfKey::GetStringValue
  2416. //
  2417. // Purpose: Return the value of the given key as a string
  2418. //
  2419. //
  2420. // Arguments:
  2421. // strValue [out] string value to return
  2422. //
  2423. // Returns: TRUE if key found and value in correct format, FALSE otherwise
  2424. //
  2425. // Author: kumarp 12 April 97 (05:53:03 pm)
  2426. //
  2427. // Notes:
  2428. //
  2429. BOOL CWInfKey::GetStringValue(OUT tstring& strValue) const
  2430. {
  2431. strValue = m_Value;
  2432. return TRUE;
  2433. }
  2434. //+---------------------------------------------------------------------------
  2435. //
  2436. // Member: CWInfKey::GetIntValue
  2437. //
  2438. // Purpose: Return the value of the given key as an in
  2439. //
  2440. //
  2441. // Arguments:
  2442. // pdwValue [out] int value to return
  2443. //
  2444. // Returns: TRUE if key found and value in correct format, FALSE otherwise
  2445. //
  2446. // Author: kumarp 12 April 97 (05:53:03 pm)
  2447. //
  2448. // Notes:
  2449. //
  2450. BOOL CWInfKey::GetIntValue(OUT DWORD *pdwValue) const
  2451. {
  2452. if ((swscanf(m_Value.c_str(), L"0x%x", pdwValue) == 1) ||
  2453. (swscanf(m_Value.c_str(), L"%d", pdwValue) == 1))
  2454. {
  2455. return TRUE;
  2456. }
  2457. return FALSE;
  2458. }
  2459. //+---------------------------------------------------------------------------
  2460. //
  2461. // Member: CWInfKey::GetQwordValue
  2462. //
  2463. // Purpose: Return the value of the given key as a QWORD
  2464. //
  2465. //
  2466. // Arguments:
  2467. // pqwValue [out] int value to return
  2468. //
  2469. // Returns: TRUE if key found and value in correct format, FALSE otherwise
  2470. //
  2471. // Author: kumarp 12 April 97 (05:53:03 pm)
  2472. //
  2473. // Notes:
  2474. //
  2475. BOOL CWInfKey::GetQwordValue(OUT QWORD *pqwValue) const
  2476. {
  2477. if ((swscanf(m_Value.c_str(), L"0x%I64x", pqwValue) == 1) ||
  2478. (swscanf(m_Value.c_str(), L"%I64d", pqwValue) == 1))
  2479. {
  2480. return TRUE;
  2481. }
  2482. return FALSE;
  2483. }
  2484. //+---------------------------------------------------------------------------
  2485. //
  2486. // Member: CWInfKey::GetBoolValue
  2487. //
  2488. // Purpose: Return the value of the given key as a BOOL
  2489. //
  2490. //
  2491. // Arguments:
  2492. // pfValue [out] BOOL value to return
  2493. //
  2494. // Returns: TRUE if key found and value in correct format, FALSE otherwise
  2495. //
  2496. // Author: kumarp 12 April 97 (05:53:03 pm)
  2497. //
  2498. // Notes:
  2499. // converts:
  2500. // "True" / "Yes" / 1 to TRUE
  2501. // "False" / "No" / 0 to FALSE
  2502. //
  2503. BOOL CWInfKey::GetBoolValue(OUT BOOL *pfValue) const
  2504. {
  2505. return IsBoolString(m_Value.c_str(), pfValue);
  2506. }
  2507. //+---------------------------------------------------------------------------
  2508. //these functions return the default value if value not found
  2509. //or if it is in a wrong format
  2510. //+---------------------------------------------------------------------------
  2511. //+---------------------------------------------------------------------------
  2512. //
  2513. // Member: CWInfKey::GetStringValue
  2514. //
  2515. // Purpose: Return the value of the given key as a string
  2516. //
  2517. //
  2518. // Arguments:
  2519. // pszDefault [in] default value
  2520. //
  2521. // Returns: value if key found and value in correct format,
  2522. // otherwise returns the default-value
  2523. //
  2524. // Author: kumarp 12 April 97 (05:53:03 pm)
  2525. //
  2526. // Notes:
  2527. //
  2528. PCWSTR CWInfKey::GetStringValue(IN PCWSTR pszDefault) const
  2529. {
  2530. if (m_Value.empty())
  2531. {
  2532. return pszDefault;
  2533. }
  2534. else
  2535. {
  2536. return m_Value.c_str();
  2537. }
  2538. }
  2539. //+---------------------------------------------------------------------------
  2540. //
  2541. // Member: CWInfKey::GetIntValue
  2542. //
  2543. // Purpose: Return the value of the given key as an int
  2544. //
  2545. //
  2546. // Arguments:
  2547. // dwDefault [in] default value
  2548. //
  2549. // Returns: value if key found and value in correct format,
  2550. // otherwise returns the default-value
  2551. //
  2552. // Author: kumarp 12 April 97 (05:53:03 pm)
  2553. //
  2554. // Notes:
  2555. //
  2556. DWORD CWInfKey::GetIntValue(IN DWORD dwDefault) const
  2557. {
  2558. DWORD dwValue;
  2559. if ((swscanf(m_Value.c_str(), L"0x%lx", &dwValue) == 1) ||
  2560. (swscanf(m_Value.c_str(), L"%ld", &dwValue) == 1))
  2561. {
  2562. return dwValue;
  2563. }
  2564. else
  2565. {
  2566. return dwDefault;
  2567. }
  2568. }
  2569. //+---------------------------------------------------------------------------
  2570. //
  2571. // Member: CWInfKey::GetQwordValue
  2572. //
  2573. // Purpose: Return the value of the given key as an int
  2574. //
  2575. //
  2576. // Arguments:
  2577. // qwDefault [in] default value
  2578. //
  2579. // Returns: value if key found and value in correct format,
  2580. // otherwise returns the default-value
  2581. //
  2582. // Author: kumarp 12 April 97 (05:53:03 pm)
  2583. //
  2584. // Notes:
  2585. //
  2586. QWORD CWInfKey::GetQwordValue(IN QWORD qwDefault) const
  2587. {
  2588. QWORD qwValue;
  2589. if ((swscanf(m_Value.c_str(), L"0x%I64x", &qwValue) == 1) ||
  2590. (swscanf(m_Value.c_str(), L"%I64x", &qwValue) == 1) ||
  2591. (swscanf(m_Value.c_str(), L"%I64d", &qwValue) == 1))
  2592. {
  2593. return qwValue;
  2594. }
  2595. else
  2596. {
  2597. return qwDefault;
  2598. }
  2599. }
  2600. //+---------------------------------------------------------------------------
  2601. //
  2602. // Member: CWInfKey::GetBoolValue
  2603. //
  2604. // Purpose: Return the value of the given key as a BOOL
  2605. //
  2606. //
  2607. // Arguments:
  2608. // fDefault [in] default value
  2609. //
  2610. // Returns: value if key found and value in correct format,
  2611. // otherwise returns the default-value
  2612. //
  2613. // Author: kumarp 12 April 97 (05:53:03 pm)
  2614. //
  2615. // Notes:
  2616. //
  2617. BOOL CWInfKey::GetBoolValue(IN BOOL bDefault) const
  2618. {
  2619. BOOL bValue;
  2620. if (IsBoolString(m_Value.c_str(), &bValue))
  2621. {
  2622. return bValue;
  2623. }
  2624. else
  2625. {
  2626. return bDefault;
  2627. }
  2628. }
  2629. // --------- Write values --------------------------------------------------
  2630. //+---------------------------------------------------------------------------
  2631. //
  2632. // Member: CWInfKey::SetValues
  2633. //
  2634. // Purpose: Sets the value of this key to the value passed
  2635. //
  2636. //
  2637. // Arguments:
  2638. // pszFormat [in] format string (printf style)
  2639. //
  2640. // Returns: none
  2641. //
  2642. // Author: kumarp 12 April 97 (05:53:03 pm)
  2643. //
  2644. // Notes:
  2645. //
  2646. void CWInfKey::SetValues(IN PCWSTR Format, IN ...)
  2647. {
  2648. va_list arglist;
  2649. va_start (arglist, Format);
  2650. SetValues(Format, arglist);
  2651. va_end(arglist);
  2652. }
  2653. //+---------------------------------------------------------------------------
  2654. //
  2655. // Member: CWInfKey::SetValue
  2656. //
  2657. // Purpose: Sets the value of this key to the value passed
  2658. //
  2659. //
  2660. // Arguments:
  2661. // pszFormat [in] format string (printf style)
  2662. // arglist [in] argument list
  2663. //
  2664. // Returns: none
  2665. //
  2666. // Author: kumarp 12 April 97 (05:53:03 pm)
  2667. //
  2668. // Notes:
  2669. //
  2670. void CWInfKey::SetValues(IN PCWSTR Format, va_list arglist)
  2671. {
  2672. // we need m_Buffer because tstring does not provide
  2673. // tstring::Format( PCWSTR lpszFormat, va_list );
  2674. vswprintf(m_Buffer, Format, arglist);
  2675. m_Value = m_Buffer;
  2676. }
  2677. //+---------------------------------------------------------------------------
  2678. //
  2679. // Member: CWInfKey::SetValue
  2680. //
  2681. // Purpose: Sets the value of this key to the value passed
  2682. //
  2683. //
  2684. // Arguments:
  2685. // pszValue [in] value to assign
  2686. //
  2687. // Returns: none
  2688. //
  2689. // Author: kumarp 12 April 97 (05:53:03 pm)
  2690. //
  2691. // Notes:
  2692. //
  2693. void CWInfKey::SetValue(IN PCWSTR Value)
  2694. {
  2695. m_Value = Value;
  2696. }
  2697. //+---------------------------------------------------------------------------
  2698. //
  2699. // Member: CWInfKey::SetValue
  2700. //
  2701. // Purpose: Sets the value of this key to the value passed
  2702. //
  2703. //
  2704. // Arguments:
  2705. // dwValue [in] value
  2706. //
  2707. // Returns: none
  2708. //
  2709. // Author: kumarp 12 April 97 (05:53:03 pm)
  2710. //
  2711. // Notes:
  2712. //
  2713. void CWInfKey::SetValue(IN DWORD Value)
  2714. {
  2715. FormatTString(m_Value, L"%d", Value);
  2716. }
  2717. //+---------------------------------------------------------------------------
  2718. //
  2719. // Member: CWInfKey::SetQwordValue
  2720. //
  2721. // Purpose: Sets the value of this key to the value passed
  2722. //
  2723. //
  2724. // Arguments:
  2725. // qwValue [in] value
  2726. //
  2727. // Returns: none
  2728. //
  2729. // Author: kumarp 12 April 97 (05:53:03 pm)
  2730. //
  2731. // Notes:
  2732. //
  2733. void CWInfKey::SetQwordValue(IN QWORD Value)
  2734. {
  2735. FormatTString(m_Value, L"0x%I64x", Value);
  2736. }
  2737. //+---------------------------------------------------------------------------
  2738. //
  2739. // Member: CWInfKey::SetHexValue
  2740. //
  2741. // Purpose: Sets the value of this key to the value passed, stores value in hex.
  2742. //
  2743. //
  2744. // Arguments:
  2745. // dwValue [in] value
  2746. //
  2747. // Returns: none
  2748. //
  2749. // Author: kumarp 12 April 97 (05:53:03 pm)
  2750. //
  2751. // Notes:
  2752. //
  2753. void CWInfKey::SetHexValue(IN DWORD Value)
  2754. {
  2755. FormatTString(m_Value, L"0x%0lx", Value);
  2756. }
  2757. //+---------------------------------------------------------------------------
  2758. //
  2759. // Member: CWInfKey::SetValue
  2760. //
  2761. // Purpose: Sets the value of this key to the value passed
  2762. //
  2763. //
  2764. // Arguments:
  2765. // slValues [in] values in the form of a string list
  2766. //
  2767. // Returns: none
  2768. //
  2769. // Author: kumarp 12 April 97 (05:53:03 pm)
  2770. //
  2771. // Notes:
  2772. // The string-list is converted to a comma-delimited list before
  2773. // the value is assigned to the key
  2774. //
  2775. void CWInfKey::SetValue(IN const TStringList &slValues)
  2776. {
  2777. tstring strFlatList;
  2778. ConvertStringListToCommaList(slValues, strFlatList);
  2779. SetValue(strFlatList.c_str());
  2780. m_fIsAListAndAlreadyProcessed = TRUE;
  2781. }
  2782. //+---------------------------------------------------------------------------
  2783. //
  2784. // Member: CWInfKey::SetBoolValue
  2785. //
  2786. // Purpose: Sets the value of this key to the value passed
  2787. //
  2788. //
  2789. // Arguments:
  2790. // fValue [in] value
  2791. //
  2792. // Returns: none
  2793. //
  2794. // Author: kumarp 12 April 97 (05:53:03 pm)
  2795. //
  2796. // Notes:
  2797. // TRUE is stored as "Yes"
  2798. // FALSE is stored as "No"
  2799. //
  2800. void CWInfKey::SetBoolValue(IN BOOL Value)
  2801. {
  2802. m_Value = Value ? c_szYes : c_szNo;
  2803. }
  2804. // ======================================================================
  2805. // Class CWInfComment
  2806. // ======================================================================
  2807. // ----------------------------------------------------------------------
  2808. // CWInfComment public functions
  2809. // ----------------------------------------------------------------------
  2810. //+---------------------------------------------------------------------------
  2811. //
  2812. // Member: CWInfComment::CWInfComment
  2813. //
  2814. // Purpose: constructor
  2815. //
  2816. // Arguments: none
  2817. //
  2818. // Author: kumarp 12 April 97 (05:53:03 pm)
  2819. //
  2820. // Notes:
  2821. //
  2822. CWInfComment::CWInfComment(IN PCWSTR pszComment)
  2823. : CWInfLine(INF_COMMENT)
  2824. {
  2825. m_strCommentText = tstring(c_szCommentPrefix) + pszComment;
  2826. }
  2827. //+---------------------------------------------------------------------------
  2828. //
  2829. // Member: CWInfComment::~CWInfComment
  2830. //
  2831. // Purpose: destructor
  2832. //
  2833. // Arguments: none
  2834. //
  2835. // Author: kumarp 12 April 97 (05:53:03 pm)
  2836. //
  2837. //
  2838. CWInfComment::~CWInfComment()
  2839. {
  2840. }
  2841. //+---------------------------------------------------------------------------
  2842. //
  2843. // Member: CWInfComment::GetText
  2844. //
  2845. // Purpose: Get text representation of this comment
  2846. //
  2847. // Arguments:
  2848. // text [in] string that receives the text
  2849. //
  2850. // Returns: none
  2851. //
  2852. // Author: kumarp 12 April 97 (05:53:03 pm)
  2853. //
  2854. // Notes:
  2855. //
  2856. void CWInfComment::GetText(tstring &text) const
  2857. {
  2858. text = m_strCommentText;
  2859. }
  2860. // used by SysPrep
  2861. void CWInfComment::GetTextEx(tstring &text) const
  2862. {
  2863. text = m_strCommentText;
  2864. }
  2865. // ======================================================================
  2866. // Class CWInfRaw
  2867. // ======================================================================
  2868. // ----------------------------------------------------------------------
  2869. // CWInfRaw public functions
  2870. // ----------------------------------------------------------------------
  2871. //+---------------------------------------------------------------------------
  2872. //
  2873. // Member: CWInfRaw::CWInfRaw
  2874. //
  2875. // Purpose: constructor
  2876. //
  2877. // Arguments: none
  2878. //
  2879. // Author: danielwe 11 Jun 1997
  2880. //
  2881. // Notes:
  2882. //
  2883. CWInfRaw::CWInfRaw(IN PCWSTR szText)
  2884. : CWInfLine(INF_RAW)
  2885. {
  2886. m_strText = szText;
  2887. }
  2888. //+---------------------------------------------------------------------------
  2889. //
  2890. // Member: CWInfRaw::~CWInfRaw
  2891. //
  2892. // Purpose: destructor
  2893. //
  2894. // Arguments: none
  2895. //
  2896. // Author: danielwe 11 Jun 1997
  2897. //
  2898. //
  2899. CWInfRaw::~CWInfRaw()
  2900. {
  2901. }
  2902. //+---------------------------------------------------------------------------
  2903. //
  2904. // Member: CWInfRaw::GetText
  2905. //
  2906. // Purpose: Get text representation of this raw string
  2907. //
  2908. // Arguments:
  2909. // text [in] string that receives the text
  2910. //
  2911. // Returns: none
  2912. //
  2913. // Author: danielwe 11 Jun 1997
  2914. //
  2915. // Notes:
  2916. //
  2917. void CWInfRaw::GetText(tstring &text) const
  2918. {
  2919. text = m_strText;
  2920. }
  2921. // used by SysPrep
  2922. void CWInfRaw::GetTextEx(tstring &text) const
  2923. {
  2924. text = m_strText;
  2925. }