-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathVfsExport.pas
171 lines (141 loc) · 4.97 KB
/
VfsExport.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
unit VfsExport;
(*
*)
(***) interface (***)
uses
Windows,
Utils,
VfsDebug, VfsBase, VfsControl, VfsWatching, VfsUtils;
exports
VfsDebug.SetLoggingProc,
VfsDebug.WriteLog_ name 'WriteLog',
VfsControl.RunVfs,
VfsBase.PauseVfs,
VfsBase.ResetVfs,
VfsBase.RefreshVfs,
VfsBase.CallWithoutVfs;
(***) implementation (***)
function Externalize (const Str: AnsiString): {O} pointer; overload;
begin
GetMem(result, Length(Str) + 1);
Utils.CopyMem(Length(Str) + 1, pchar(Str), result);
end;
function Externalize (const Str: WideString): {O} pointer; overload;
begin
GetMem(result, (Length(Str) + 1) * sizeof(WideChar));
Utils.CopyMem((Length(Str) + 1) * sizeof(WideChar), PWideChar(Str), result);
end;
function MapDir (const VirtPath, RealPath: PWideChar; OverwriteExisting: boolean; Flags: integer = 0): LONGBOOL; stdcall;
begin
result := VfsBase.MapDir(WideString(VirtPath), WideString(RealPath), OverwriteExisting, Flags);
end;
function MapDirA (const VirtPath, RealPath: PAnsiChar; OverwriteExisting: boolean; Flags: integer = 0): LONGBOOL; stdcall;
begin
result := VfsBase.MapDir(WideString(VirtPath), WideString(RealPath), OverwriteExisting, Flags);
end;
function MapModsFromList (const RootDir, ModsDir, ModListFile: PWideChar; Flags: integer = 0): LONGBOOL; stdcall;
begin
result := VfsControl.MapModsFromList(WideString(RootDir), WideString(ModsDir), WideString(ModListFile), Flags);
end;
function MapModsFromListA (const RootDir, ModsDir, ModListFile: PAnsiChar; Flags: integer = 0): LONGBOOL; stdcall;
begin
result := VfsControl.MapModsFromList(WideString(RootDir), WideString(ModsDir), WideString(ModListFile), Flags);
end;
function GetSerializedModList: {O} pointer; stdcall;
begin
result := VfsControl.GetSerializedModList;
end;
function GetSerializedModListA: {O} pointer; stdcall;
begin
result := VfsControl.GetSerializedModListA;
end;
function RunWatcher (const WatchDir: PWideChar; DebounceInterval: integer): LONGBOOL; stdcall;
begin
result := VfsWatching.RunWatcher(WatchDir, DebounceInterval);
end;
function RunWatcherA (const WatchDir: pchar; DebounceInterval: integer): LONGBOOL; stdcall;
begin
result := VfsWatching.RunWatcher(WatchDir, DebounceInterval);
end;
(* Frees buffer, that was transfered to client earlier using other VFS API *)
procedure MemFree ({O} Buf: pointer); stdcall;
begin
FreeMem(Buf);
end;
(* Returns text with all applied mappings, separated via #13#10. If ShortenPaths is true, common part
of real and virtual paths is stripped. Call MemFree to release result buffer *)
function GetMappingsReport: {O} PWideChar; stdcall;
begin
result := Externalize(VfsBase.GetMappingsReport);
end;
function GetMappingsReportA: {O} PAnsiChar; stdcall;
begin
result := Externalize(AnsiString(VfsBase.GetMappingsReport));
end;
(* Returns text with all applied mappings on per-file level, separated via #13#10. If ShortenPaths is true, common part
of real and virtual paths is stripped *)
function GetDetailedMappingsReport: {O} PWideChar; stdcall;
begin
result := Externalize(VfsBase.GetDetailedMappingsReport);
end;
function GetDetailedMappingsReportA: {O} PAnsiChar; stdcall;
begin
result := Externalize(AnsiString(VfsBase.GetDetailedMappingsReport));
end;
procedure ConsoleLoggingProc (Operation, Message: pchar); stdcall;
begin
WriteLn('>> ', string(Operation), ': ', string(Message), #13#10);
end;
(* Allocates console and install logger, writing messages to console *)
procedure InstallConsoleLogger; stdcall;
var
Rect: TSmallRect;
BufSize: TCoord;
hIn: THandle;
hOut: THandle;
begin
AllocConsole;
SetConsoleCP(GetACP);
SetConsoleOutputCP(GetACP);
hIn := GetStdHandle(STD_INPUT_HANDLE);
hOut := GetStdHandle(STD_OUTPUT_HANDLE);
pinteger(@System.Input)^ := hIn;
pinteger(@System.Output)^ := hOut;
BufSize.x := 120;
BufSize.y := 1000;
SetConsoleScreenBufferSize(hOut, BufSize);
Rect.Left := 0;
Rect.Top := 0;
Rect.Right := 120 - 1;
Rect.Bottom := 50 - 1;
SetConsoleWindowInfo(hOut, true, Rect);
SetConsoleTextAttribute(hOut, (0 shl 4) or $0F);
VfsDebug.SetLoggingProc(@ConsoleLoggingProc);
end; // .procedure InitConsole;
(* Returns real path for vfs item by its virtual path or empty string on error *)
function GetRealPath (const VirtPath: WideString): {O} PWideChar; stdcall;
begin
result := Externalize(VfsBase.GetVfsItemRealPath(VfsUtils.NormalizePath(VirtPath)));
end;
function GetRealPathA (const VirtPath: AnsiString): {O} PAnsiChar; stdcall;
begin
result := Externalize(AnsiString(VfsBase.GetVfsItemRealPath(VfsUtils.NormalizePath(VirtPath))));
end;
exports
GetDetailedMappingsReport,
GetDetailedMappingsReportA,
GetMappingsReport,
GetMappingsReportA,
GetRealPath,
GetRealPathA,
GetSerializedModList,
GetSerializedModListA,
InstallConsoleLogger,
MapDir,
MapDirA,
MapModsFromList,
MapModsFromListA,
MemFree,
RunWatcher,
RunWatcherA;
end.