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.

150 lines
5.5 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1999, Microsoft Corp. All rights reserved.
  4. //
  5. // FILE
  6. //
  7. // command.cpp
  8. //
  9. // SYNOPSIS
  10. //
  11. // Process the command-line parameters of iasinfdb.exe
  12. //
  13. // MODIFICATION HISTORY
  14. //
  15. // 02/12/1999 Original version. Thierry Perraut
  16. //
  17. //////////////////////////////////////////////////////////////////////////////
  18. #include "precomp.hpp"
  19. #include "command.h"
  20. using namespace std;
  21. //////////////////////////////////////////////////////////////////////////////
  22. //
  23. // ProcessCommand
  24. //
  25. //
  26. //////////////////////////////////////////////////////////////////////////////
  27. HRESULT ProcessCommand(
  28. int argc,
  29. wchar_t * argv[],
  30. HINF *ppHINF,
  31. CDatabase& Database
  32. )
  33. {
  34. _ASSERTE(ppHINF != NULL);
  35. HRESULT hres;
  36. if (argc != NUMBER_ARGUMENTS)
  37. {
  38. /////////////////////////////////////
  39. // not the right number of arguments
  40. /////////////////////////////////////
  41. cerr << "inf2db Import an INF file into a Jet4 Database\n\ninf2db ";
  42. cerr << "[drive:][path]template.mdb [drive:][path]filename.inf";
  43. cerr << "[drive:][path]destination_database.mdb\n";
  44. hres = E_INVALIDARG;
  45. }
  46. else
  47. {
  48. /////////////////////////////////////
  49. // argv[1] = template database
  50. /////////////////////////////////////
  51. BOOL bCopyOk = CopyFileW(
  52. argv[1],
  53. TEMPORARY_FILENAME,
  54. // here false means success even if file already exists
  55. FALSE
  56. );
  57. if (!bCopyOk)
  58. {
  59. TracePrintf("Error: copy template %S -> new file %S failed ",
  60. argv[1],
  61. TEMPORARY_FILENAME
  62. );
  63. hres = E_FAIL;
  64. }
  65. else
  66. {
  67. ///////////////////////////////////////////////////////
  68. // suppress the read-only attribute from the new file
  69. ///////////////////////////////////////////////////////
  70. BOOL bChangedAttributeOK = SetFileAttributesW(
  71. TEMPORARY_FILENAME,
  72. FILE_ATTRIBUTE_NORMAL
  73. );
  74. if(!bChangedAttributeOK)
  75. {
  76. TracePrintf("Error: change attribute (RW) on %S failed",
  77. TEMPORARY_FILENAME
  78. );
  79. hres = E_FAIL;
  80. }
  81. else
  82. {
  83. ///////////////////////////////////////////////////////
  84. // three arg (argc = 4) Open the INF file for reading
  85. // Open for read (will fail if file does not exist)
  86. ///////////////////////////////////////////////////////
  87. UINT lErrorCode;
  88. if( (*ppHINF = (HINF) SetupOpenInfFileW(
  89. // name of the INF to open
  90. argv[2],
  91. // optional, the class of the INF file
  92. NULL,
  93. // specifies the style of the INF file
  94. INF_STYLE_WIN4,
  95. &lErrorCode
  96. ))
  97. == INVALID_HANDLE_VALUE
  98. )
  99. {
  100. //////////////////////////////////
  101. // Error situation
  102. //////////////////////////////////
  103. LPVOID lpMsgBuf;
  104. FormatMessageW(
  105. FORMAT_MESSAGE_ALLOCATE_BUFFER |
  106. FORMAT_MESSAGE_FROM_SYSTEM |
  107. FORMAT_MESSAGE_IGNORE_INSERTS,
  108. NULL,
  109. GetLastError(),
  110. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
  111. (LPWSTR) &lpMsgBuf,
  112. 0,
  113. NULL
  114. );
  115. TracePrintf("Error: %S",(LPCWSTR)lpMsgBuf);
  116. cerr << "Error: " << (LPCWSTR)lpMsgBuf << "\n";
  117. /////////////////////
  118. // Free the buffer.
  119. /////////////////////
  120. LocalFree(lpMsgBuf);
  121. cerr << "ERROR: Can't open the INF file " << argv[1] <<"\n";
  122. hres = E_INVALIDARG;
  123. }
  124. else
  125. {
  126. #ifdef DEBUG
  127. TraceString("Info: inf file open\n");
  128. #endif
  129. ////////////////////////////////////////////////
  130. // argv[3] = destination path to the database
  131. // call the initialize member function
  132. ////////////////////////////////////////////////
  133. Database.InitializeDB(argv[3]);
  134. hres = S_OK;
  135. }
  136. }
  137. }
  138. }
  139. return hres;
  140. }