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.

164 lines
3.0 KiB

  1. #include <setupapi.hpp>
  2. #include <queue.hpp>
  3. struct InvalidArguments : BaseException<char>{
  4. void Dump(std::ostream &os) {
  5. os << "Invalid Arguments" << std::endl;
  6. }
  7. };
  8. template<class T>
  9. struct ProgramArguments {
  10. std::basic_string<T> FileName;
  11. ProgramArguments(int Argc, T *Argv[]) {
  12. if (Argc > 1) {
  13. FileName = Argv[1];
  14. } else {
  15. throw new InvalidArguments();
  16. }
  17. }
  18. ~ProgramArguments(){}
  19. };
  20. //
  21. // ANSI Arguments
  22. //
  23. typedef ProgramArguments<char> AnsiArgs;
  24. typedef ProgramArguments<wchar_t> UnicodeArgs;
  25. //
  26. // Prototypes
  27. //
  28. bool
  29. ReadTest(
  30. IN InfFileW &TestInfFile
  31. );
  32. bool
  33. WriteTest(
  34. IN InfFileW &TestInfFile
  35. );
  36. bool
  37. AppendTest(
  38. IN InfFileW &TestInfFile
  39. );
  40. //
  41. // main() entry point
  42. //
  43. int
  44. __cdecl
  45. wmain(int Argc, wchar_t *Argv[]) {
  46. int Result = 0;
  47. try{
  48. UnicodeArgs PrgArgs(Argc, Argv);
  49. InfFileW TestInf(PrgArgs.FileName);
  50. if (!WriteTest(TestInf)) {
  51. std::cout << "WriteTest failed" << std::endl;
  52. }
  53. if (!AppendTest(TestInf)) {
  54. std::cout << "AppendTest failed" << std::endl;
  55. }
  56. if (!ReadTest(TestInf)) {
  57. std::cout << "ReadTest failed" << std::endl;
  58. }
  59. }
  60. catch(BaseException<char> *Exp) {
  61. Exp->Dump(std::cout);
  62. delete Exp;
  63. }
  64. catch(exception *exp) {
  65. std::cout << exp->what() << std::endl;
  66. delete exp;
  67. }
  68. return Result;
  69. }
  70. bool
  71. ReadTest(
  72. IN InfFileW &TestInfFile
  73. )
  74. {
  75. bool Result = true;
  76. std::cout << TestInfFile.GetName() << " was opened correctly"
  77. << std::endl;
  78. std::cout << TestInfFile;
  79. return Result;
  80. }
  81. bool
  82. WriteTest(
  83. IN InfFileW &TestInfFile
  84. )
  85. {
  86. bool Result = false;
  87. Section<wchar_t> *NewSection = TestInfFile.AddSection(L"Testing", false);
  88. if (NewSection) {
  89. SectionValues<wchar_t> * NewValues = NewSection->AddLine(L"TestValueKey");
  90. if (NewValues) {
  91. NewValues->AppendValue(L"Value1");
  92. NewValues->AppendValue(L"Value2");
  93. Result = true;
  94. }
  95. }
  96. return Result;
  97. }
  98. bool
  99. AppendTest(
  100. IN InfFileW &TestInfFile
  101. )
  102. {
  103. bool Result = false;
  104. Section<wchar_t> *AppSection = TestInfFile.GetSection(L"appendtest");
  105. if (AppSection) {
  106. std::cout << *AppSection << std::endl;
  107. SectionValues<wchar_t> &OldValue = AppSection->GetValue(L"Key");
  108. std::wstring Value = OldValue.GetValue(0);
  109. OldValue.PutValue(0, L"\"This is new string\"");
  110. std::cout << *AppSection << std::endl;
  111. Result = true;
  112. }
  113. return Result;
  114. }
  115. /*
  116. bool
  117. QueueTest(
  118. VOID
  119. )
  120. {
  121. FileQueueW TestQueue();
  122. return false;
  123. }
  124. */