* Sync up to trunk head (r64829).
[reactos.git] / dll / win32 / mspatcha / mspatcha_main.c
1 /*
2 * PatchAPI
3 *
4 * Copyright 2011 David Hedberg for CodeWeavers
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21 #include <wine/config.h>
22
23 #include <stdarg.h>
24
25 #include <windef.h>
26 #include <winbase.h>
27 #include <winnls.h>
28 #include <patchapi.h>
29
30 #include <wine/debug.h>
31
32 WINE_DEFAULT_DEBUG_CHANNEL(mspatcha);
33
34 /*****************************************************
35 * DllMain (MSPATCHA.@)
36 */
37 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
38 {
39 TRACE("(0x%p, %d, %p)\n", hinstDLL, fdwReason, lpvReserved);
40
41 switch (fdwReason)
42 {
43 case DLL_WINE_PREATTACH:
44 return FALSE; /* prefer native version */
45 case DLL_PROCESS_ATTACH:
46 DisableThreadLibraryCalls(hinstDLL);
47 break;
48 }
49
50 return TRUE;
51 }
52
53 static inline WCHAR *strdupAW( const char *src )
54 {
55 WCHAR *dst = NULL;
56 if (src)
57 {
58 int len = MultiByteToWideChar( CP_ACP, 0, src, -1, NULL, 0 );
59 if ((dst = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
60 MultiByteToWideChar( CP_ACP, 0, src, -1, dst, len );
61 }
62 return dst;
63 }
64
65 /*****************************************************
66 * ApplyPatchToFileA (MSPATCHA.1)
67 */
68 BOOL WINAPI ApplyPatchToFileA(LPCSTR patch_file, LPCSTR old_file, LPCSTR new_file, ULONG apply_flags)
69 {
70 BOOL ret;
71 WCHAR *patch_fileW, *new_fileW, *old_fileW = NULL;
72
73 if (!(patch_fileW = strdupAW( patch_file ))) return FALSE;
74 if (old_file && !(old_fileW = strdupAW( old_file )))
75 {
76 HeapFree( GetProcessHeap(), 0, patch_fileW );
77 return FALSE;
78 }
79 if (!(new_fileW = strdupAW( new_file )))
80 {
81 HeapFree( GetProcessHeap(), 0, patch_fileW );
82 HeapFree( GetProcessHeap(), 0, old_fileW );
83 return FALSE;
84 }
85 ret = ApplyPatchToFileW( patch_fileW, old_fileW, new_fileW, apply_flags );
86 HeapFree( GetProcessHeap(), 0, patch_fileW );
87 HeapFree( GetProcessHeap(), 0, old_fileW );
88 HeapFree( GetProcessHeap(), 0, new_fileW );
89 return ret;
90 }
91
92 /*****************************************************
93 * ApplyPatchToFileW (MSPATCHA.6)
94 */
95 BOOL WINAPI ApplyPatchToFileW(LPCWSTR patch_file, LPCWSTR old_file, LPCWSTR new_file, ULONG apply_flags)
96 {
97 FIXME("stub - %s, %s, %s, %08x\n", debugstr_w(patch_file), debugstr_w(old_file),
98 debugstr_w(new_file), apply_flags);
99
100 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
101 return FALSE;
102 }
103
104 /*****************************************************
105 * GetFilePatchSignatureA (MSPATCHA.7)
106 */
107 BOOL WINAPI GetFilePatchSignatureA(LPCSTR filename, ULONG flags, PVOID data, ULONG ignore_range_count,
108 PPATCH_IGNORE_RANGE ignore_range, ULONG retain_range_count,
109 PPATCH_RETAIN_RANGE retain_range, ULONG bufsize, LPSTR buffer)
110 {
111 FIXME("stub - %s, %x, %p, %u, %p, %u, %p, %u, %p\n", debugstr_a(filename), flags, data,
112 ignore_range_count, ignore_range, retain_range_count, retain_range, bufsize, buffer);
113 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
114 return FALSE;
115 }
116
117 /*****************************************************
118 * GetFilePatchSignatureW (MSPATCHA.9)
119 */
120 BOOL WINAPI GetFilePatchSignatureW(LPCWSTR filename, ULONG flags, PVOID data, ULONG ignore_range_count,
121 PPATCH_IGNORE_RANGE ignore_range, ULONG retain_range_count,
122 PPATCH_RETAIN_RANGE retain_range, ULONG bufsize, LPWSTR buffer)
123 {
124 FIXME("stub - %s, %x, %p, %u, %p, %u, %p, %u, %p\n", debugstr_w(filename), flags, data,
125 ignore_range_count, ignore_range, retain_range_count, retain_range, bufsize, buffer);
126 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
127 return FALSE;
128 }