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.

218 lines
4.0 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. hugecopy.c
  5. Abstract:
  6. <TODO: fill in abstract>
  7. Author:
  8. TODO: <full name> (<alias>) <date>
  9. Revision History:
  10. <full name> (<alias>) <date> <comments>
  11. --*/
  12. #include "pch.h"
  13. HANDLE g_hHeap;
  14. HINSTANCE g_hInst;
  15. BOOL WINAPI MigUtil_Entry (HINSTANCE, DWORD, PVOID);
  16. BOOL
  17. pCallEntryPoints (
  18. DWORD Reason
  19. )
  20. {
  21. HINSTANCE Instance;
  22. //
  23. // Simulate DllMain
  24. //
  25. Instance = g_hInst;
  26. //
  27. // Initialize the common libs
  28. //
  29. if (!MigUtil_Entry (Instance, Reason, NULL)) {
  30. return FALSE;
  31. }
  32. //
  33. // TODO: Add others here if needed (don't forget to prototype above)
  34. //
  35. return TRUE;
  36. }
  37. BOOL
  38. Init (
  39. VOID
  40. )
  41. {
  42. g_hHeap = GetProcessHeap();
  43. g_hInst = GetModuleHandle (NULL);
  44. return pCallEntryPoints (DLL_PROCESS_ATTACH);
  45. }
  46. VOID
  47. Terminate (
  48. VOID
  49. )
  50. {
  51. pCallEntryPoints (DLL_PROCESS_DETACH);
  52. }
  53. VOID
  54. HelpAndExit (
  55. VOID
  56. )
  57. {
  58. //
  59. // This routine is called whenever command line args are wrong
  60. //
  61. _ftprintf (
  62. stderr,
  63. TEXT("Command Line Syntax:\n\n")
  64. //
  65. // TODO: Describe command line syntax(es), indent 2 spaces
  66. //
  67. TEXT(" hugecopy <source> <destination>\n")
  68. TEXT("\nDescription:\n\n")
  69. //
  70. // TODO: Describe tool, indent 2 spaces
  71. //
  72. TEXT(" hugecopy copies a file that has a path longer than MAX_PATH\n")
  73. TEXT("\nArguments:\n\n")
  74. //
  75. // TODO: Describe args, indent 2 spaces, say optional if necessary
  76. //
  77. TEXT(" source - Specifies the file to copy\n")
  78. TEXT(" destination - Specifies the name and path of the new copy\n")
  79. TEXT("\n")
  80. TEXT("NOTE: both source and destination must contain a file name, and\n")
  81. TEXT(" they cannot contain wildcard characters\n")
  82. );
  83. exit (1);
  84. }
  85. INT
  86. __cdecl
  87. _tmain (
  88. INT argc,
  89. PCTSTR argv[]
  90. )
  91. {
  92. INT i;
  93. PCTSTR src = NULL;
  94. PCTSTR dest = NULL;
  95. PCWSTR decoratedSrc;
  96. PCWSTR decoratedDest;
  97. WCHAR bigSrc[MAX_PATH * 8];
  98. WCHAR bigDest[MAX_PATH * 8];
  99. BOOL b;
  100. PCWSTR unicodeSrc;
  101. PCWSTR unicodeDest;
  102. //
  103. // TODO: Parse command line here
  104. //
  105. for (i = 1 ; i < argc ; i++) {
  106. if (argv[i][0] == TEXT('/') || argv[i][0] == TEXT('-')) {
  107. switch (_totlower (_tcsnextc (&argv[i][1]))) {
  108. default:
  109. HelpAndExit();
  110. }
  111. } else {
  112. //
  113. // Parse other args that don't require / or -
  114. //
  115. if (!src) {
  116. src = argv[i];
  117. } else if (!dest) {
  118. dest = argv[i];
  119. } else {
  120. HelpAndExit();
  121. }
  122. }
  123. }
  124. if (!dest) {
  125. HelpAndExit();
  126. }
  127. //
  128. // Begin processing
  129. //
  130. if (!Init()) {
  131. return 0;
  132. }
  133. unicodeSrc = CreateUnicode (src);
  134. unicodeDest = CreateUnicode (dest);
  135. if (!GetFullPathNameW (unicodeSrc, ARRAYSIZE(bigSrc), bigSrc, NULL)) {
  136. StackStringCopyW (bigSrc, unicodeSrc);
  137. }
  138. if (!GetFullPathNameW (unicodeDest, ARRAYSIZE(bigDest), bigDest, NULL)) {
  139. StackStringCopyW (bigDest, unicodeDest);
  140. }
  141. decoratedSrc = JoinPathsW (L"\\\\?", bigSrc);
  142. decoratedDest = JoinPathsW (L"\\\\?", bigDest);
  143. b = CopyFileW (decoratedSrc, decoratedDest, FALSE);
  144. if (b) {
  145. printf ("%s -> %s\n", src, dest);
  146. } else {
  147. wprintf (L"%s -> %s\n", decoratedSrc, decoratedDest);
  148. printf ("Copy failed, error=%u\n", GetLastError());
  149. }
  150. DestroyUnicode (unicodeSrc);
  151. DestroyUnicode (unicodeDest);
  152. FreePathStringW (decoratedSrc);
  153. FreePathStringW (decoratedDest);
  154. //
  155. // End of processing
  156. //
  157. Terminate();
  158. return 0;
  159. }