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.

137 lines
2.7 KiB

  1. #ifndef _WIN32_WINNT
  2. #define _WIN32_WINNT 0x0400
  3. #endif
  4. #ifndef WIN32
  5. #define WIN32 0x0400
  6. #endif
  7. #pragma warning( disable: 4001 4035 4115 4200 4201 4204 4209 4214 4514 4699 )
  8. #include <windows.h>
  9. #pragma warning( disable: 4001 4035 4115 4200 4201 4204 4209 4214 4514 4699 )
  10. #include <stdlib.h>
  11. #include <stdio.h>
  12. #include "patchapi.h"
  13. #include "patchprv.h"
  14. #include <ntverp.h>
  15. #include <common.ver>
  16. void CopyRight( void ) {
  17. printf(
  18. "\n"
  19. "APATCH " VER_PRODUCTVERSION_STR " Patch Application Utility\n"
  20. VER_LEGALCOPYRIGHT_STR
  21. "\n\n"
  22. );
  23. }
  24. void Usage( void ) {
  25. printf(
  26. "Usage: APATCH PatchFile OldFile TargetNewFile\n\n"
  27. );
  28. exit( 1 );
  29. }
  30. BOOL
  31. CALLBACK
  32. MyProgressCallback(
  33. PVOID CallbackContext,
  34. ULONG CurrentPosition,
  35. ULONG MaximumPosition
  36. )
  37. {
  38. UNREFERENCED_PARAMETER( CallbackContext );
  39. if ( CurrentPosition & 0xFF000000 ) {
  40. CurrentPosition >>= 8;
  41. MaximumPosition >>= 8;
  42. }
  43. if ( MaximumPosition != 0 ) {
  44. fprintf( stderr, "\r%3.1f%% complete", ( CurrentPosition * 100.0 ) / MaximumPosition );
  45. }
  46. return TRUE;
  47. }
  48. void __cdecl main( int argc, char *argv[] ) {
  49. LPSTR OldFileName = NULL;
  50. LPSTR PatchFileName = NULL;
  51. LPSTR NewFileName = NULL;
  52. BOOL Success;
  53. LPSTR arg;
  54. int i;
  55. SetErrorMode( SEM_FAILCRITICALERRORS );
  56. #ifndef DEBUG
  57. SetErrorMode( SEM_NOALIGNMENTFAULTEXCEPT | SEM_FAILCRITICALERRORS );
  58. #endif
  59. CopyRight();
  60. for ( i = 1; i < argc; i++ ) {
  61. arg = argv[ i ];
  62. if ( strchr( arg, '?' )) {
  63. Usage();
  64. }
  65. if ( PatchFileName == NULL ) {
  66. PatchFileName = arg;
  67. }
  68. else if ( OldFileName == NULL ) {
  69. OldFileName = arg;
  70. }
  71. else if ( NewFileName == NULL ) {
  72. NewFileName = arg;
  73. }
  74. else {
  75. Usage();
  76. }
  77. }
  78. if (( OldFileName == NULL ) || ( NewFileName == NULL ) || ( PatchFileName == NULL )) {
  79. Usage();
  80. }
  81. DeleteFile( NewFileName );
  82. Success = ApplyPatchToFileEx(
  83. PatchFileName,
  84. OldFileName,
  85. NewFileName,
  86. 0,
  87. MyProgressCallback,
  88. NULL
  89. );
  90. printf( "\n\n" );
  91. if ( ! Success ) {
  92. CHAR ErrorText[ 16 ];
  93. ULONG ErrorCode = GetLastError();
  94. sprintf( ErrorText, ( ErrorCode < 0x10000000 ) ? "%d" : "%X", ErrorCode );
  95. printf( "Failed to create file from patch (%s)\n", ErrorText );
  96. exit( 1 );
  97. }
  98. printf( "OK\n" );
  99. exit( 0 );
  100. }