forked from alphaonex86/Supercopier
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SCWin32.pas
428 lines (373 loc) · 18.3 KB
/
SCWin32.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
{
This file is part of SuperCopier.
SuperCopier is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
SuperCopier is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
}
unit SCWin32;
{$MODE Delphi}
// Surcouche a l'api Win32 permettant de gйrer l'unicode, win9x et les int64
// (je maudis Microsoft sur 7 generations pour etre oblige de faire зa :)
interface
uses
Windows,Shellapi,ShlObj;
const
IOCTL_STORAGE_BASE=$2D;
METHOD_BUFFERED=0;
FILE_ANY_ACCESS=0;
IOCTL_STORAGE_GET_DEVICE_NUMBER = (IOCTL_STORAGE_BASE shl 16) or (FILE_ANY_ACCESS shl 14) or ($0420 shl 2) or (METHOD_BUFFERED);
type
TGetVolumePathNameW=function(lpszFileName,lpszVolumePathName:PWideChar;cchBufferLength:Cardinal):LongBool;stdcall;
TGetVolumeNameForVolumeMountPointW=function(lpszVolumeMountPoint,lpszVolumeName:PWideChar;cchBufferLength:Cardinal):LongBool;stdcall;
TGetSystemDefaultUILanguage=function:LANGID;stdcall;
TStorageDeviceNumber=record
DeviceType:DWORD;
DeviceNumber:cardinal;
PartitionNumber:cardinal;
end;
function GetFileSize(TheFile:THandle):Int64;
function SetFilePointer(TheFile:THandle;DistanceToMove:Int64;MoveMethod:Cardinal):Int64;
function GetFileAttributes(FileName:PWideChar):Integer;
function SetFileAttributes(FileName:PWideChar;Attr:Cardinal):Boolean;
function DeleteFile(FileName:PWideChar):Boolean;
function CreateDirectory(DirName:PWideChar;PSA:PSecurityAttributes):Boolean;
function RemoveDirectory(DirName:PWideChar):Boolean;
function GetDiskFreeSpaceEx(DirName:PWideChar;var FreeBytesAvailable: PLargeInteger;var TotalNumberOfBytes:PLargeInteger;TotalNumberOfFreeBytes:PLargeInteger):Boolean;
function MoveFile(Source,Dest:PWideChar):Boolean;
function DragQueryFile(hDrop:HDROP;iFile:Cardinal;lpszFile:PWideChar;cch:Cardinal):Cardinal;
function FindFirstFile(lpFileName: PWideChar; var lpFindFileData: TWIN32FindDataW): THandle;
function FindNextFile(hFindFile: THandle; var lpFindFileData: TWIN32FindDataW): Boolean;
function SHGetPathFromIDList(pidl:PItemIDList;pszPath:PWideChar):LongBool;
function SHBrowseForFolder(var lpbi:PBROWSEINFOW):PItemIDList;
function GetVolumeInformation(lpRootPathName: PWideChar;
lpVolumeNameBuffer: PWideChar; nVolumeNameSize: DWORD; lpVolumeSerialNumber: PDWORD;
var lpMaximumComponentLength, lpFileSystemFlags: DWORD;
lpFileSystemNameBuffer: PWideChar; nFileSystemNameSize: DWORD): BOOL;
function MessageBox(hWnd: HWND; lpText, lpCaption: WideString; uType: UINT): Integer;
function GetTempPath:WideString;
function CopyFile(lpExistingFileName, lpNewFileName: PWideChar; bFailIfExists: BOOL): BOOL;
function PathIsUNC(pszPath:PWideChar):LongBool;
function PathIsNetworkPath(pszPath:PWideChar):LongBool;
function GetUserName(lpBuffer: PWideChar; var nSize: DWORD): BOOL;
function CreateMutex(lpMutexAttributes: PSecurityAttributes; bInitialOwner: BOOL; lpName: PWideChar): THandle;
function CreateFileMapping(hFile: THandle; lpFileMappingAttributes: PSecurityAttributes;
flProtect, dwMaximumSizeHigh, dwMaximumSizeLow: DWORD; lpName: PWideChar): THandle;
function CreateEvent(lpEventAttributes: PSecurityAttributes;
bManualReset, bInitialState: BOOL; lpName: PWideChar): THandle;
function OpenMutex(dwDesiredAccess: DWORD; bInheritHandle: BOOL; lpName: PWideChar): THandle;
function OpenFileMapping(dwDesiredAccess: DWORD; bInheritHandle: BOOL; lpName: PWideChar): THandle;
function OpenEvent(dwDesiredAccess: DWORD; bInheritHandle: BOOL; lpName: PWideChar): THandle;
function CreateSemaphore(lpSemaphoreAttributes: PSecurityAttributes;
lInitialCount, lMaximumCount: Longint; lpName: PWideChar): THandle;
function GlobalAddAtom(lpString: PWideChar): TAtom;
function GlobalFindAtom(lpString: PWideChar): TAtom;
var
//HKernel32_dll:Cardinal;
// fonctions non dйclarйes sous tous les windows, appel dynamique obligatoire
GetVolumePathName:TGetVolumePathNameW;
GetVolumeNameForVolumeMountPoint:TGetVolumeNameForVolumeMountPointW;
GetSystemDefaultUILanguage:TGetSystemDefaultUILanguage;
implementation
uses Sysutils,lclproc;
function PathIsUNCA(pszPath:PChar):LongBool;stdcall;external 'shlwapi.dll' name 'PathIsUNCA';
function PathIsUNCW(pszPath:PWideChar):LongBool;stdcall;external 'shlwapi.dll' name 'PathIsUNCW';
function PathIsNetworkPathA(pszPath:PChar):LongBool;stdcall;external 'shlwapi.dll' name 'PathIsNetworkPathA';
function PathIsNetworkPathW(pszPath:PWideChar):LongBool;stdcall;external 'shlwapi.dll' name 'PathIsNetworkPathW';
//******************************************************************************
// GetFileSize
//******************************************************************************
function GetFileSize(TheFile:THandle):Int64;
var SizeHigh:cardinal;
ResRec:Int64Rec absolute Result;
begin
Result:=0;
ResRec.Lo:=Windows.GetFileSize(TheFile,@SizeHigh);
ResRec.Hi:=SizeHigh;
if ResRec.Lo=$ffffffff then Result:=0;
end;
//******************************************************************************
// SetFilePointer
//******************************************************************************
function SetFilePointer(TheFile:THandle;DistanceToMove:Int64;MoveMethod:Cardinal):Int64;
var HiPart,LoPart:Cardinal;
ResRec:Int64Rec absolute Result;
begin
LoPart:=Int64Rec(DistanceToMove).Lo;
HiPart:=Int64Rec(DistanceToMove).Hi;
ResRec.Lo:=Windows.SetFilePointer(TheFile,LoPart,@HiPart,MoveMethod);
ResRec.Hi:=HiPart;
end;
//******************************************************************************
// GetFileAttributes
//******************************************************************************
function GetFileAttributes(FileName:PWideChar):Integer;
begin
Result:=GetFileAttributesW(FileName);
end;
//******************************************************************************
// SetFileAttributes
//******************************************************************************
function SetFileAttributes(FileName:PWideChar;Attr:Cardinal):Boolean;
begin
Result:=SetFileAttributesW(FileName,Attr);
end;
//******************************************************************************
// DeleteFile
//******************************************************************************
function DeleteFile(FileName:PWideChar):Boolean;
begin
SetFileAttributesW(FileName,FILE_ATTRIBUTE_NORMAL);
Result:=DeleteFileW(FileName);
end;
//******************************************************************************
// CreateDirectory
//******************************************************************************
function CreateDirectory(DirName:PWideChar;PSA:PSecurityAttributes):Boolean;
begin
Result:=CreateDirectoryW(DirName,PSA);
end;
//******************************************************************************
// RemoveDirectory
//******************************************************************************
function RemoveDirectory(DirName:PWideChar):Boolean;
begin
Result:=RemoveDirectoryW(DirName);
end;
//******************************************************************************
// GetDiskFreeSpaceEx
//******************************************************************************
function GetDiskFreeSpaceEx(DirName:PWideChar;var FreeBytesAvailable: PLargeInteger;var TotalNumberOfBytes:PLargeInteger;TotalNumberOfFreeBytes:PLargeInteger):Boolean;
begin
Result:=Windows.GetDiskFreeSpaceExW(DirName,FreeBytesAvailable,TotalNumberOfBytes,TotalNumberOfFreeBytes)
end;
//******************************************************************************
// MoveFile
//******************************************************************************
function MoveFile(Source,Dest:PWideChar):Boolean;
begin
Result:=MoveFileW(Source,Dest);
end;
//******************************************************************************
// DragQueryFile
//******************************************************************************
function DragQueryFile(hDrop:HDROP;iFile:Cardinal;lpszFile:PWideChar;cch:Cardinal):Cardinal;
var Tmp:array of Char;
begin
if Win32Platform=VER_PLATFORM_WIN32_NT then
Result:=ShellApi.DragQueryFileW(hDrop,iFile,lpszFile,cch)
else
begin
SetLength(Tmp,cch);
Result:=ShellApi.DragQueryFile(hDrop,iFile,@Tmp[0],cch);
MultiByteToWideChar(CP_ACP,0,@Tmp[0],cch,lpszFile,cch*2);
SetLength(Tmp,0);
end;
end;
//******************************************************************************
// FindFirstFile
//******************************************************************************
function FindFirstFile(lpFileName: PWideChar; var lpFindFileData: TWIN32FindDataW): THandle;
begin
Result:=FindFirstFileW(lpFileName,lpFindFileData);
end;
//******************************************************************************
// FindNextFile
//******************************************************************************
function FindNextFile(hFindFile: THandle; var lpFindFileData: TWIN32FindDataW): Boolean;
begin
Result:=FindNextFileW(hFindFile,lpFindFileData);
end;
//******************************************************************************
// SHGetPathFromIDList
//******************************************************************************
function SHGetPathFromIDList(pidl:PItemIDList;pszPath:PWideChar):LongBool;
begin
Result:=SHGetPathFromIDListW(pidl,pszPath);
end;
//******************************************************************************
// SHBrowseForFolder
//******************************************************************************
function SHBrowseForFolder(var lpbi:PBROWSEINFOW):PItemIDList;
begin
Result:=SHBrowseForFolderW(lpbi);
end;
//******************************************************************************
// GetVolumeInformation
//******************************************************************************
function GetVolumeInformation(lpRootPathName: PWideChar;
lpVolumeNameBuffer: PWideChar; nVolumeNameSize: DWORD; lpVolumeSerialNumber: PDWORD;
var lpMaximumComponentLength, lpFileSystemFlags: DWORD;
lpFileSystemNameBuffer: PWideChar; nFileSystemNameSize: DWORD): BOOL;
var Tmp,Tmp2:array of Char;
begin
if Win32Platform=VER_PLATFORM_WIN32_NT then
begin
Result:=GetVolumeInformationW(lpRootPathName,lpVolumeNameBuffer,nVolumeNameSize,
lpVolumeSerialNumber,lpMaximumComponentLength,lpFileSystemFlags,
lpFileSystemNameBuffer,nFileSystemNameSize);
end
else
begin
SetLength(Tmp,nVolumeNameSize);
SetLength(Tmp2,nFileSystemNameSize);
Result:=GetVolumeInformationA(PChar(String(lpRootPathName)),@Tmp[0],nVolumeNameSize,
lpVolumeSerialNumber,lpMaximumComponentLength,lpFileSystemFlags,
@Tmp2[0],nFileSystemNameSize);
MultiByteToWideChar(CP_ACP,0,@Tmp[0],nVolumeNameSize,lpVolumeNameBuffer,nVolumeNameSize*2);
MultiByteToWideChar(CP_ACP,0,@Tmp2[0],nFileSystemNameSize,lpFileSystemNameBuffer,nFileSystemNameSize*2);
SetLength(Tmp,0);
SetLength(Tmp2,0);
end;
end;
//******************************************************************************
// MessageBox
//******************************************************************************
function MessageBox(hWnd: HWND; lpText, lpCaption: WideString; uType: UINT): Integer;
begin
Result:=MessageBoxW(hWnd,PWideChar(lpText),PWideChar(lpCaption),uType); // fonction implйmentйe sous Win9x
end;
//******************************************************************************
// GetTempPath
//******************************************************************************
function GetTempPath:WideString;
var Buf:array[0..MAX_PATH] of WideChar;
begin
if GetTempPathW(MAX_PATH,Buf)<>0 then Result:=Buf;
end;
//******************************************************************************
// CopyFile
//******************************************************************************
function CopyFile(lpExistingFileName, lpNewFileName: PWideChar; bFailIfExists: BOOL): BOOL;
begin
Result:=CopyFileW(lpExistingFileName,lpNewFileName,bFailIfExists);
end;
//******************************************************************************
// PathIsUNC
//******************************************************************************
function PathIsUNC(pszPath:PWideChar):LongBool;
begin
if Win32Platform=VER_PLATFORM_WIN32_NT then
Result:=PathIsUNCW(pszPath)
else
Result:=PathIsUNCA(PChar(String(pszPath)));
end;
//******************************************************************************
// PathIsNetworkPath
//******************************************************************************
function PathIsNetworkPath(pszPath:PWideChar):LongBool;
begin
if Win32Platform=VER_PLATFORM_WIN32_NT then
Result:=PathIsNetworkPathW(pszPath)
else
Result:=PathIsNetworkPathA(PChar(String(pszPath)));
end;
//******************************************************************************
// GetUserName
//******************************************************************************
function GetUserName(lpBuffer: PWideChar; var nSize: DWORD): BOOL;
begin
Result:=GetUserNameW(lpBuffer,nSize);
end;
//******************************************************************************
// CreateMutex
//******************************************************************************
function CreateMutex(lpMutexAttributes: PSecurityAttributes; bInitialOwner: BOOL; lpName: PWideChar): THandle;
begin
if Win32Platform=VER_PLATFORM_WIN32_NT then
Result:=CreateMutexW(lpMutexAttributes,bInitialOwner,lpName)
else
Result:=CreateMutexA(lpMutexAttributes,bInitialOwner,PChar(String(lpName)));
end;
//******************************************************************************
// CreateFileMapping
//******************************************************************************
function CreateFileMapping(hFile: THandle; lpFileMappingAttributes: PSecurityAttributes;
flProtect, dwMaximumSizeHigh, dwMaximumSizeLow: DWORD; lpName: PWideChar): THandle;
begin
if Win32Platform=VER_PLATFORM_WIN32_NT then
Result:=CreateFileMappingW(hFile,lpFileMappingAttributes,flProtect,dwMaximumSizeHigh,dwMaximumSizeLow,lpName)
else
Result:=CreateFileMappingA(hFile,lpFileMappingAttributes,flProtect,dwMaximumSizeHigh,dwMaximumSizeLow,PChar(String(lpName)));
end;
//******************************************************************************
// CreateEvent
//******************************************************************************
function CreateEvent(lpEventAttributes: PSecurityAttributes;
bManualReset, bInitialState: BOOL; lpName: PWideChar): THandle;
begin
if Win32Platform=VER_PLATFORM_WIN32_NT then
Result:=CreateEventW(lpEventAttributes,bManualReset,bInitialState,lpName)
else
Result:=CreateEventA(lpEventAttributes,bManualReset,bInitialState,PChar(String(lpName)));
end;
//******************************************************************************
// OpenMutex
//******************************************************************************
function OpenMutex(dwDesiredAccess: DWORD; bInheritHandle: BOOL; lpName: PWideChar): THandle;
begin
if Win32Platform=VER_PLATFORM_WIN32_NT then
Result:=OpenMutexW(dwDesiredAccess,bInheritHandle,lpName)
else
Result:=OpenMutexA(dwDesiredAccess,bInheritHandle,PChar(String(lpName)));
end;
//******************************************************************************
// OpenFileMapping
//******************************************************************************
function OpenFileMapping(dwDesiredAccess: DWORD; bInheritHandle: BOOL; lpName: PWideChar): THandle;
begin
if Win32Platform=VER_PLATFORM_WIN32_NT then
Result:=OpenFileMappingW(dwDesiredAccess,bInheritHandle,lpName)
else
Result:=OpenFileMappingA(dwDesiredAccess,bInheritHandle,PChar(String(lpName)));
end;
//******************************************************************************
// OpenEvent
//******************************************************************************
function OpenEvent(dwDesiredAccess: DWORD; bInheritHandle: BOOL; lpName: PWideChar): THandle;
begin
if Win32Platform=VER_PLATFORM_WIN32_NT then
Result:=OpenEventW(dwDesiredAccess,bInheritHandle,lpName)
else
Result:=OpenEventA(dwDesiredAccess,bInheritHandle,PChar(String(lpName)));
end;
//******************************************************************************
// CreateSemaphore
//******************************************************************************
function CreateSemaphore(lpSemaphoreAttributes: PSecurityAttributes;
lInitialCount, lMaximumCount: Longint; lpName: PWideChar): THandle;
begin
if Win32Platform=VER_PLATFORM_WIN32_NT then
Result:=CreateSemaphoreW(lpSemaphoreAttributes,lInitialCount,lMaximumCount,lpName)
else
Result:=CreateSemaphoreA(lpSemaphoreAttributes,lInitialCount,lMaximumCount,PChar(String(lpName)));
end;
//******************************************************************************
// GlobalAddAtom
//******************************************************************************
function GlobalAddAtom(lpString: PWideChar): TAtom;
begin
if Win32Platform=VER_PLATFORM_WIN32_NT then
Result:=GlobalAddAtomW(lpString)
else
Result:=GlobalAddAtomA(PChar(String(lpString)));
end;
//******************************************************************************
// GlobalFindAtom
//******************************************************************************
function GlobalFindAtom(lpString: PWideChar): TAtom;
begin
if Win32Platform=VER_PLATFORM_WIN32_NT then
Result:=GlobalFindAtomW(lpString)
else
Result:=GlobalFindAtomA(PChar(String(lpString)));
end;
initialization
GetVolumePathName:=GetProcAddress(GetModuleHandle('kernel32.dll'),'GetVolumePathNameW');
GetVolumeNameForVolumeMountPoint:=GetProcAddress(GetModuleHandle('kernel32.dll'),'GetVolumeNameForVolumeMountPointW');
GetSystemDefaultUILanguage:=GetProcAddress(GetModuleHandle('kernel32.dll'),'GetSystemDefaultUILanguage');
end.