@@ -6,9 +6,9 @@ interface
6
6
7
7
uses
8
8
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
9
- StdCtrls, ExtCtrls,
9
+ StdCtrls, ExtCtrls, Process, Windows,
10
10
// my additions
11
- Windows, Registry, Process ;
11
+ Common, Settings ;
12
12
13
13
type
14
14
@@ -30,24 +30,12 @@ TFormMain = class(TForm)
30
30
procedure ImgLogoClick (Sender: TObject);
31
31
private
32
32
{ private declarations }
33
- // private variable for convenience
34
- script: string;
35
- dscript: string;
36
- game_dir: string;
37
- game_exe: string;
38
- // moddir: string;
39
-
40
- // Moved files for running mod
41
33
zbigs: TStringList; // remembers what files are moved to game dir.
34
+ settings: TSettings; // game location + UI settings
42
35
active_mod: string; // remembers what mod is active now.
43
36
44
- // jdj's own procedures
45
37
procedure ScanMods ();
46
- procedure GetDirs ();
47
- // function GetMyDoc(): string;
48
- function GenReg ( t: string ): string;
49
- procedure Warning ( t: string );
50
- procedure ScanScripts ();
38
+ procedure ScanScripts (); // scan scripts folder in the game & update UI
51
39
procedure LaunchGame ( mod_name:string; params: string );
52
40
53
41
procedure ActivateMod ( mod_name: string );
@@ -68,12 +56,12 @@ implementation
68
56
// set button states correctly.
69
57
procedure TFormMain.ScanScripts ();
70
58
begin
71
- if ( DirectoryExists( script ) ) then begin
59
+ if ( DirectoryExists( settings. script ) ) then begin
72
60
BtnMod.Enabled := true;
73
61
BtnRestore.Enabled:= false;
74
62
end ;
75
63
76
- if ( DirectoryExists( dscript ) ) then begin
64
+ if ( DirectoryExists( settings. dscript ) ) then begin
77
65
BtnMod.Enabled := false;
78
66
BtnRestore.Enabled:= true;
79
67
end ;
@@ -85,20 +73,14 @@ procedure TFormMain.ImgLogoClick(Sender: TObject);
85
73
ShellExecute( 0 , ' open' , ' http://red2.net' , nil , nil , SW_SHOWNORMAL );
86
74
end ;
87
75
88
- // show warning message
89
- procedure TFormMain.Warning ( t:string );
90
- begin
91
- Application.MessageBox( PChar(t), ' 경고' , MB_ICONWARNING );
92
- end ;
93
-
94
76
// Scan mod directory.
95
77
procedure TFormMain.ScanMods ();
96
78
var
97
79
info : TSearchRec;
98
80
mod_dir : string;
99
81
begin
100
82
// scan the dirs in gamedir/Mods
101
- mod_dir := IncludeTrailingPathDelimiter(game_dir)+' Mods' ;
83
+ mod_dir := IncludeTrailingPathDelimiter(settings. game_dir)+' Mods' ;
102
84
If FindFirst( mod_dir + ' \*' , faAnyFile and faDirectory, info ) = 0 then
103
85
begin
104
86
Repeat
@@ -116,81 +98,12 @@ procedure TFormMain.ScanMods();
116
98
ModList.ItemIndex:= 0 ; // select 1st item.
117
99
end ;
118
100
119
- // read values from
120
- // SOFTWARE\Electronic Arts\EA Games\Command and Conquer Generals Zero Hour
121
- function TFormMain.GenReg ( t: string ): string;
122
- var
123
- reg: TRegistry;
124
- begin
125
- reg := TRegistry.Create(KEY_READ);
126
- try
127
- reg.RootKey := HKEY_LOCAL_MACHINE;
128
- reg.OpenKey(' SOFTWARE\Electronic Arts\EA Games\Command and Conquer Generals Zero Hour' , False);
129
- if reg.ValueExists( t ) then
130
- Result := reg.ReadString( t )
131
- else begin
132
- Result := ' ' ;
133
- Warning( ' 제로아워 레지스트리값 ' + t + ' 읽기 실패' );
134
- end ;
135
- finally
136
- reg.Free;
137
- end ;
138
- end ;
139
-
140
- // get directories we need for the launcher.
141
- procedure TFormMain.GetDirs ();
142
- var
143
- // mydoc: string;
144
- // dataleaf: string;
145
- installdir: string;
146
- begin
147
- // mydoc := GetMyDoc();
148
- // dataleaf := GenReg( 'UserDataLeafName' );
149
- installdir := GenReg( ' InstallPath' );
150
- if ( FileExists( installdir ) ) then
151
- begin
152
- // installdir might contain Generals.exe!
153
- // If file, FileExists returns true.
154
- // If dir, returns False.
155
- installdir := ExtractFilePath( installdir );
156
- end ;
157
-
158
- // we are ready to calculate now.
159
- // mydoc := IncludeTrailingPathDelimiter( mydoc );
160
- // moddir := mydoc + dataleaf;
161
-
162
- installdir := IncludeTrailingPathDelimiter( installdir );
163
- game_dir := installdir;
164
- game_exe := installdir + ' generals.exe' ;
165
- script := installdir + ' Data\Scripts' ;
166
- dscript := installdir + ' Data\_Scripts' ;
167
-
168
- // game_exe is the only parameter that is not checked by other routines.
169
- // checking it here...
170
- if ( not FileExists( game_exe ) ) then
171
- Warning( game_exe + ' 가 존재하지 않음!' );
172
- end ;
173
-
174
- // get mydocuments
175
- // function TFormMain.GetMyDoc(): string;
176
- // var
177
- // PIDL : PItemIDList;
178
- // Folder : array[0..MAX_PATH] of Char;
179
- // const
180
- // // CSIDL_APPDATA = $001A;
181
- // CSIDL_PERSONAL = $0005;
182
- // begin
183
- // SHGetSpecialFolderLocation(0, CSIDL_PERSONAL, PIDL);
184
- // SHGetPathFromIDList(PIDL, Folder);
185
- // result:=Folder;
186
- // end;
187
-
188
101
// Initialization of the program (?),
189
102
// at least this form.
190
103
procedure TFormMain.FormCreate (Sender: TObject);
191
104
begin
192
105
zbigs := TStringList.create;
193
- GetDirs() ;
106
+ settings := TSettings.create ;
194
107
ScanMods();
195
108
ScanScripts();
196
109
end ;
@@ -206,7 +119,7 @@ procedure TFormMain.LaunchGame( mod_name: string; params: string );
206
119
// Run the mod
207
120
// ShellExecute( 0, 'open', PChar(game_exe), PChar(params), nil, SW_NORMAL );
208
121
output := ' ' ;
209
- RunCommand( game_exe, params, output );
122
+ RunCommand( settings. game_exe, params, output );
210
123
211
124
// Wait for it to finish
212
125
DeactivateMod( mod_name );
@@ -222,7 +135,7 @@ procedure TFormMain.ActivateMod( mod_name: string );
222
135
active_mod := ModList.Text;
223
136
224
137
// Find zbigs in the game/Mods/mod_name then move it to game dir.
225
- mod_path := IncludeTrailingPathDelimiter(game_dir) +
138
+ mod_path := IncludeTrailingPathDelimiter(settings. game_dir) +
226
139
' Mods\' + mod_name + ' \' ;
227
140
228
141
If FindFirst( mod_path + ' *.zbig' , faAnyFile, info ) = 0 then
@@ -239,7 +152,7 @@ procedure TFormMain.ActivateMod( mod_name: string );
239
152
begin
240
153
fname := zbigs[ i ];
241
154
src := mod_path + fname;
242
- dest := game_dir + fname;
155
+ dest := settings. game_dir + fname;
243
156
dest := StringReplace( dest, ' .zbig' , ' .big' , [rfReplaceAll] );
244
157
MoveFile( PChar(src), PChar(dest) );
245
158
end ;
@@ -254,15 +167,15 @@ procedure TFormMain.DeactivateMod( mod_name: string );
254
167
active_mod := ' ' ;
255
168
256
169
// Find zbigs in the game/Mods/mod_name then move it to game dir.
257
- mod_path := IncludeTrailingPathDelimiter(game_dir) +
170
+ mod_path := IncludeTrailingPathDelimiter(settings. game_dir) +
258
171
' Mods\' + mod_name + ' \' ;
259
172
260
173
// For each items in zbigs, move the file to the game dir.
261
174
for i := 0 to zbigs.Count-1 do
262
175
begin
263
176
fname := zbigs[ i ];
264
177
dest := mod_path + fname;
265
- src := game_dir + fname;
178
+ src := settings. game_dir + fname;
266
179
src := StringReplace( src, ' .zbig' , ' .big' , [rfReplaceAll] );
267
180
// Warning( src + ' --> ' + dest );
268
181
MoveFile( PChar(src), PChar(dest) );
@@ -288,13 +201,13 @@ procedure TFormMain.FormClose(Sender: TObject; var CloseAction: TCloseAction);
288
201
289
202
procedure TFormMain.BtnModClick (Sender: TObject);
290
203
begin
291
- MoveFile( PChar(script), PChar(dscript) );
204
+ MoveFile( PChar(settings. script), PChar(settings. dscript) );
292
205
ScanScripts();
293
206
end ;
294
207
295
208
procedure TFormMain.BtnRestoreClick (Sender: TObject);
296
209
begin
297
- MoveFile( PChar(dscript), PChar(script) );
210
+ MoveFile( PChar(settings. dscript), PChar(settings. script) );
298
211
ScanScripts();
299
212
end ;
300
213
0 commit comments