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.

185 lines
4.3 KiB

  1. //-----------------------------------------------------------------------//
  2. //
  3. // File: export.cpp
  4. // Created: April 1997
  5. // By: Zeyong Xu
  6. // Purpose: Support EXPORT and IMPORT .reg file
  7. //
  8. //------------------------------------------------------------------------//
  9. #include "stdafx.h"
  10. #include <regeditp.h>
  11. #include "reg.h"
  12. extern UINT g_FileErrorStringID;
  13. //-----------------------------------------------------------------------
  14. //
  15. // ExportRegFile()
  16. //
  17. //-----------------------------------------------------------------------
  18. LONG ExportRegFile(PAPPVARS pAppVars, UINT argc, TCHAR *argv[])
  19. {
  20. LONG nResult;
  21. HKEY hKey;
  22. //
  23. // Parse the cmd-line
  24. //
  25. nResult = ParseExportCmdLine(pAppVars, argc, argv);
  26. if(nResult != ERROR_SUCCESS)
  27. return nResult;
  28. //
  29. // check if the key existed
  30. //
  31. nResult = RegOpenKeyEx(pAppVars->hRootKey,
  32. pAppVars->szSubKey,
  33. 0,
  34. KEY_READ,
  35. &hKey);
  36. if(nResult == ERROR_SUCCESS)
  37. {
  38. RegCloseKey(hKey);
  39. nResult = RegExportRegFile(NULL,
  40. TRUE,
  41. pAppVars->bNT4RegFile,
  42. pAppVars->szValueName,
  43. pAppVars->szFullKey);
  44. }
  45. return nResult;
  46. }
  47. //------------------------------------------------------------------------
  48. //
  49. // ParseCmdLine()
  50. //
  51. //------------------------------------------------------------------------
  52. REG_STATUS ParseExportCmdLine(PAPPVARS pAppVars, UINT argc, TCHAR *argv[])
  53. {
  54. REG_STATUS nResult = ERROR_SUCCESS;
  55. //
  56. // Do we have a *valid* number of cmd-line params
  57. //
  58. if (argc < 4)
  59. {
  60. return REG_STATUS_TOFEWPARAMS;
  61. }
  62. else if (argc > 5)
  63. {
  64. return REG_STATUS_TOMANYPARAMS;
  65. }
  66. // Machine Name and Registry key
  67. //
  68. nResult = BreakDownKeyString(argv[2], pAppVars);
  69. if(nResult != ERROR_SUCCESS)
  70. return nResult;
  71. // current, not remotable
  72. if(pAppVars->bUseRemoteMachine)
  73. return REG_STATUS_NONREMOTABLE;
  74. //
  75. // Get the FileName - using the szValueName string field to hold it
  76. //
  77. pAppVars->szValueName = (TCHAR*) calloc(_tcslen(argv[3]) + 1,
  78. sizeof(TCHAR));
  79. _tcscpy(pAppVars->szValueName, argv[3]);
  80. #ifdef REG_FOR_WIN2000
  81. //
  82. // option params
  83. //
  84. if(argc == 4)
  85. return nResult;
  86. if( argc == 5 &&
  87. !_tcsicmp(argv[4], _T("/nt4")))
  88. {
  89. pAppVars->bNT4RegFile = TRUE;
  90. }
  91. else
  92. nResult = REG_STATUS_INVALIDPARAMS;
  93. #else
  94. pAppVars->bNT4RegFile = TRUE;
  95. if(argc > 4)
  96. nResult = REG_STATUS_TOMANYPARAMS;
  97. #endif
  98. return nResult;
  99. }
  100. //-----------------------------------------------------------------------
  101. //
  102. // ImportRegFile()
  103. //
  104. //-----------------------------------------------------------------------
  105. LONG ImportRegFile(PAPPVARS pAppVars, UINT argc, TCHAR *argv[])
  106. {
  107. LONG nResult;
  108. //
  109. // Parse the cmd-line
  110. //
  111. nResult = ParseImportCmdLine(pAppVars, argc, argv);
  112. if(nResult == ERROR_SUCCESS)
  113. {
  114. nResult = RegImportRegFile(NULL,
  115. TRUE,
  116. pAppVars->szValueName);
  117. }
  118. if(nResult != ERROR_SUCCESS)
  119. {
  120. if ( g_FileErrorStringID == IDS_IMPFILEERRSUCCESS || nResult == ERROR_FILE_NOT_FOUND)
  121. nResult = REG_STATUS_BADFILEFORMAT;
  122. }
  123. return nResult;
  124. }
  125. //------------------------------------------------------------------------
  126. //
  127. // ParseCmdLine()
  128. //
  129. //------------------------------------------------------------------------
  130. REG_STATUS ParseImportCmdLine(PAPPVARS pAppVars, UINT argc, TCHAR *argv[])
  131. {
  132. REG_STATUS nResult = ERROR_SUCCESS;
  133. //
  134. // Do we have a valid number of cmd-line params
  135. //
  136. if (argc < 3)
  137. {
  138. return REG_STATUS_TOFEWPARAMS;
  139. }
  140. else if (argc > 3)
  141. {
  142. return REG_STATUS_TOMANYPARAMS;
  143. }
  144. //
  145. // Get the FileName - using the szValueName string field to hold it
  146. //
  147. pAppVars->szValueName = (TCHAR*) calloc(_tcslen(argv[2]) + 1, sizeof(TCHAR));
  148. if( pAppVars->szValueName ) {
  149. _tcscpy(pAppVars->szValueName, argv[2]);
  150. } else {
  151. nResult = ERROR_INSUFFICIENT_BUFFER;
  152. }
  153. return nResult;
  154. }