-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathPathMgr.pp
More file actions
85 lines (71 loc) · 2.26 KB
/
PathMgr.pp
File metadata and controls
85 lines (71 loc) · 2.26 KB
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
{ Copyright (C) 2021-2024 by Bill Stewart (bstewart at iname.com)
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your option) any
later version.
This program 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 Lesser Public License for more
details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see https://www.gnu.org/licenses/.
}
{$MODE OBJFPC}
{$MODESWITCH UNICODESTRINGS}
{$R *.res}
library PathMgr;
uses
Windows,
WindowsPath;
procedure CopyString(const Source: string; Dest: PChar);
var
NumChars: DWORD;
begin
NumChars := Length(Source);
Move(Source[1], Dest^, NumChars * SizeOf(Char));
Dest[NumChars] := #0;
end;
function GetPath(PathType, Expand: DWORD; Buffer: PChar; NumChars: DWORD): DWORD; stdcall;
var
Path: string;
begin
if PathType > 1 then
PathType := 1;
if WindowsPath.GetPath(TPathType(PathType), Expand <> 0, Path) = ERROR_SUCCESS then
begin
result := Length(Path);
if (result > 0) and (result <= NumChars) and Assigned(Buffer) then
CopyString(Path, Buffer);
end
else
result := 0;
end;
function IsDirInPath(DirName: PChar; PathType: DWORD; FindType: PDWORD): DWORD; stdcall;
var
PathFindType: TPathFindType;
begin
if PathType > 1 then
PathType := 1;
result := WindowsPath.IsDirInPath(string(DirName), TPathType(PathType), PathFindType);
FindType^ := DWORD(PathFindType);
end;
function AddDirToPath(DirName: PChar; PathType, AddType: DWORD): DWORD; stdcall;
begin
if PathType > 1 then
PathType := 1;
if AddType > 1 then
AddType := 1;
result := WindowsPath.AddDirToPath(string(DirName), TPathType(PathType), TPathAddType(AddType));
end;
function RemoveDirFromPath(DirName: PChar; PathType: DWORD): DWORD; stdcall;
begin
if PathType > 1 then
PathType := 1;
result := WindowsPath.RemoveDirFromPath(string(DirName), TPathType(PathType));
end;
exports
AddDirToPath,
GetPath,
IsDirInPath,
RemoveDirFromPath;
end.