-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathuMIExplorer_Funcs.pas
150 lines (131 loc) · 3.69 KB
/
uMIExplorer_Funcs.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
{
******************************************************
Monkey Island Explorer
Copyright (c) 2010 - 2018 Bennyboy
Http://quickandeasysoftware.net
******************************************************
}
unit uMIExplorer_Funcs;
interface
uses
Sysutils, Windows, Classes, StrUtils, JCLStrings, JCLRegistry;
function GetMI1SEPath: string;
function GetMI2SEPath: string;
function SanitiseFileName(FileName: string): string;
function ExtractPartialPath(FileName: string): string;
function SwapEndianDWord(Value: integer): integer; register;
procedure GetSteamLibraryPaths(LibraryPaths: TStringList);
implementation
procedure GetSteamLibraryPaths(LibraryPaths: TStringList);
var
SteamPath, VDFfile, CurrLine, NewPath: string;
Reader: TStreamReader;
begin
try
SteamPath := IncludeTrailingPathDelimiter(
RegReadString(HKEY_CURRENT_USER, 'SOFTWARE\Valve\Steam', 'SteamPath'));
SteamPath := StringReplace(SteamPath, '/', '\', [rfReplaceAll, rfIgnoreCase]);
except on EJCLRegistryError do
exit;
end;
LibraryPaths.Add(SteamPath);
VDFfile := SteamPath + 'config\libraryfolders.vdf';
if FileExists(VDFfile) = false then exit;
Reader := TStreamReader.Create(TFileStream.Create(VDFfile, fmOpenRead), TEncoding.UTF8);
try
while not Reader.EndOfStream do
begin
CurrLine := Reader.ReadLine;
if AnsiContainsStr(CurrLine, '"path"') then //BaseInstallFolder is the extra library
begin
NewPath := StrAfter('"path"', CurrLine);
NewPath := StrRemoveChars(NewPath, [#34]); //Remove the surrounding double quotes
NewPath := StrRemoveChars(NewPath, [#9]); //Remove any tab characters before the string
NewPath := IncludeTrailingPathDelimiter(NewPath); //Add the backslash to the path
StrReplace(NewPath, '\\', '\', [rfReplaceAll]); //Remove the \\ and replace with \
LibraryPaths.Add(NewPath);
//ShowMessage(NewPath);
end;
end;
finally
Reader.Close();
Reader.BaseStream.Free;
Reader.Free();
end;
end;
function GetMI1SEPath: string;
const
ExtraPath: string = 'steamapps\common\the secret of monkey island special edition\';
var
Paths: TStringList;
i: integer;
begin
Result := '';
Paths := TStringList.Create;
try
GetSteamLibraryPaths(Paths);
if Paths.Count > 0 then
for I := 0 to Paths.Count -1 do
begin
if DirectoryExists(Paths[i] + ExtraPath) then
begin
result:=Paths[i] + ExtraPath;
break;
end;
end;
finally
Paths.free;
end;
end;
function GetMI2SEPath: string;
const
ExtraPath: string = 'steamapps\common\monkey2\';
var
Paths: TStringList;
i: integer;
begin
Result := '';
Paths := TStringList.Create;
try
GetSteamLibraryPaths(Paths);
if Paths.Count > 0 then
for I := 0 to Paths.Count -1 do
begin
if DirectoryExists(Paths[i] + ExtraPath) then
begin
result:=Paths[i] + ExtraPath;
break;
end;
end;
finally
Paths.free;
end;
end;
function SanitiseFileName(FileName: string): string;
var
DelimiterPos: integer;
begin
DelimiterPos := LastDelimiter('/', FileName );
if DelimiterPos = 0 then
result := FileName
else
Result := Copy( FileName, DelimiterPos + 1, Length(FileName) - DelimiterPos + 1);
end;
function ExtractPartialPath(FileName: string): string;
var
DelimiterPos: integer;
begin
DelimiterPos := LastDelimiter('/', FileName );
if DelimiterPos = 0 then
result := ''
else
begin
Result := Copy( FileName, 1, DelimiterPos);
Result := StringReplace(Result, '/', '\', [rfReplaceAll, rfIgnoreCase ]);
end;
end;
function SwapEndianDWord(Value: integer): integer; register;
asm
bswap eax
end;
end.