-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGlobals.pas
218 lines (198 loc) · 4.4 KB
/
Globals.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
unit Globals;
(*
Copyright 1999,2009 Csabo.
This program 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 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 Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*)
interface
Const
VersionMajor = '1';
VersionMinor = '16.beta';
Type
TAssociations = ( assoc_None, assoc_WAD, assoc_Common, assoc_All );
var
gOpenLast : Boolean;
gCutCopyEmpty : Boolean;
sTempFolder : String;
gOnlyOneBack : Boolean;
gAutoCleanUp : Boolean;
gAutoBackup : Boolean;
gPreviewMaps : Boolean;
gAutoPlaySounds : Boolean;
gDisableUndo : Boolean;
gRawPNG : Boolean;
gAutoApplyOffsets : Boolean;
//
gCacheTextures : Boolean;
//
gShowFullPath : Boolean;
gShowSize : Boolean;
gShowPosition : Boolean;
gDontAutoCapitalize : Boolean;
//
gAssociations : TAssociations;
//
sCredits : String;
sExePath : String;
//
gFileReadOnly : Boolean; // if true, file is read-only
Type
// ---
TPal = Record
Name : String;
Pal : Array [ 0 .. 255, 0 .. 2 ] Of Byte;
End;
Type
TPicData = Array [ 0 .. 1000000 ] Of Byte;
Var
PicData : ^TPicData;
Var
//
// ---
//
nPals : Integer;
iPreferredPal : Integer;
Pals : Array [ 0 .. 99 ] Of TPal;
procedure UpdateIniFile ( sSection, sMatch, sTool : String );
Function RemoveFolder ( s : String ) : String;
function GetEnvVarValue(const VarName: string): string;
implementation
Uses
Windows, SysUtils, Stringz;
Function RemoveFolder ( s : String ) : String;
Var
s0 : String;
Begin
s0 := Copy ( s, Length ( s ), 1 );
If ( s0 <> '/' ) And ( s0 <> '\' ) Then
Begin
s0 := '';
End
Else
Begin
s := Copy ( s, 1, Length ( s ) - 1 );
End;
//
If PosR ( '/', s ) > 0 Then
Begin
s := RemoveFromLeft ( s, PosR ( '/', s ) );
End;
If PosR ( '\', s ) > 0 Then
Begin
s := RemoveFromLeft ( s, PosR ( '\', s ) );
End;
//
s := s + s0;
//
RemoveFolder := s;
End;
procedure UpdateIniFile ( sSection, sMatch, sTool : String );
Var
tf, tn : TextFile;
s, sOrig : String;
bSection, bDone : Boolean;
Begin
AssignFile ( tf, sExePath + 'xwe.ini' );
Reset ( tf );
//
AssignFile ( tn, sExePath + 'xwe.~ini' );
Rewrite ( tn );
//
bSection := False;
bDone := False;
//
While Not Eof ( tf ) Do
Begin
ReadLn ( tf, sOrig );
s := Trim ( sOrig );
//
if Not bDone Then
Begin
if Length ( s ) > 0 Then
begin
If ( s [ 1 ] <> ';' ) Then
Begin
If ( s [ 1 ] = '<' )
Or ( s [ 1 ] = '(' )
Or ( s [ 1 ] = '[' ) Then
Begin
//
// --- Section start.
//
If bSection Then
Begin
// our section is just now over, but line was not found
// add it 'manually'
WriteLn ( tn, sTool );
bDone := True;
End
Else
Begin
If UpperCase ( s ) = UpperCase ( sSection ) Then
Begin
// this is our section.
bSection := True;
End;
End;
End
Else
Begin
If bSection Then
Begin
If UpperCase ( Copy ( s, 1, Length ( sMatch ) ) ) = UpperCase ( sMatch ) Then
Begin
sOrig := ';' + sOrig;
WriteLn ( tn, sTool );
bDone := True;
End;
End;
End;
End;
End;
end;
//
WriteLn ( tn, sOrig );
End;
//
If Not bDone Then
Begin
If Not bSection Then
Begin
WriteLn ( tn, sSection );
End;
WriteLn ( tn, sTool );
End;
//
CloseFile ( tf );
CloseFile ( tn );
//
AssignFile ( tf, sExePath + 'xwe.ini' );
Erase ( tf );
AssignFile ( tf, sExePath + 'xwe.~ini' );
Rename ( tf, sExePath + 'xwe.ini' );
End;
function GetEnvVarValue(const VarName: string): string;
var
BufSize: Integer; // buffer size required for value
begin
// Get required buffer size (inc. terminal #0)
BufSize := GetEnvironmentVariable ( PChar ( VarName ), nil, 0 );
if BufSize > 0 then
begin
// Read env var value into result string
SetLength ( Result, BufSize - 1 );
GetEnvironmentVariable ( PChar ( VarName ), PChar ( Result ), BufSize );
end
else
// No such environment variable
Result := '';
end;
end.