Skip to content

Commit 8687bd0

Browse files
committed
Trying to move to config file based Generals.exe search
1 parent 8eed1c2 commit 8687bd0

File tree

6 files changed

+250
-108
lines changed

6 files changed

+250
-108
lines changed

src/common.pas

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
unit Common;
2+
3+
{$mode objfpc}{$H+}
4+
5+
interface
6+
7+
uses
8+
Classes, SysUtils, Forms, Dialogs, LCLType;
9+
10+
// Warning dialog box (helper func)
11+
procedure Warning( t:string );
12+
function path_join( a: string; b:string ): string;
13+
14+
implementation
15+
16+
// show warning message
17+
procedure Warning( t:string );
18+
begin
19+
Application.MessageBox( PChar(t), '경고', MB_ICONWARNING );
20+
end;
21+
22+
function path_join( a:string; b:string ): string;
23+
begin
24+
result := IncludeTrailingPathDelimiter( a );
25+
result += b;
26+
end;
27+
28+
end.
29+

src/mainform.lfm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
object FormMain: TFormMain
2-
Left = 315
2+
Left = 365
33
Height = 192
4-
Top = 172
4+
Top = 201
55
Width = 216
66
BorderIcons = [biSystemMenu, biMinimize]
77
BorderStyle = bsSingle
@@ -11,7 +11,7 @@ object FormMain: TFormMain
1111
OnClose = FormClose
1212
OnCreate = FormCreate
1313
Position = poDefaultPosOnly
14-
LCLVersion = '1.4.4.0'
14+
LCLVersion = '1.6.0.4'
1515
object ImgLogo: TImage
1616
Left = 8
1717
Height = 90

src/mainform.lrs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{ This is an automatically generated lazarus resource file }
22

33
LazarusResources.Add('TFormMain','FORMDATA',[
4-
'TPF0'#9'TFormMain'#8'FormMain'#4'Left'#3';'#1#6'Height'#3#192#0#3'Top'#3#172
4+
'TPF0'#9'TFormMain'#8'FormMain'#4'Left'#3'm'#1#6'Height'#3#192#0#3'Top'#3#201
55
+#0#5'Width'#3#216#0#11'BorderIcons'#11#12'biSystemMenu'#10'biMinimize'#0#11
66
+'BorderStyle'#7#8'bsSingle'#7'Caption'#6#13#235#170#168#235#147#156' '#235
77
+#159#176#236#178#152#12'ClientHeight'#3#192#0#11'ClientWidth'#3#216#0#7'OnCl'
88
+'ose'#7#9'FormClose'#8'OnCreate'#7#10'FormCreate'#8'Position'#7#16'poDefault'
9-
+'PosOnly'#10'LCLVersion'#6#7'1.4.4.0'#0#6'TImage'#7'ImgLogo'#4'Left'#2#8#6'H'
9+
+'PosOnly'#10'LCLVersion'#6#7'1.6.0.4'#0#6'TImage'#7'ImgLogo'#4'Left'#2#8#6'H'
1010
+'eight'#2'Z'#3'Top'#2'`'#5'Width'#3#200#0#6'Center'#9#7'OnClick'#7#12'ImgLog'
1111
+'oClick'#12'Picture.Data'#10#4#7#0#0#23'TPortableNetworkGraphic'#232#6#0#0
1212
+#137'PNG'#13#10#26#10#0#0#0#13'IHDR'#0#0#0#195#0#0#0'['#8#3#0#0#0#249#148#193

src/mainform.pas

Lines changed: 15 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ interface
66

77
uses
88
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
9-
StdCtrls, ExtCtrls,
9+
StdCtrls, ExtCtrls, Process, Windows,
1010
// my additions
11-
Windows, Registry, Process;
11+
Common, Settings;
1212

1313
type
1414

@@ -30,24 +30,12 @@ TFormMain = class(TForm)
3030
procedure ImgLogoClick(Sender: TObject);
3131
private
3232
{ 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
4133
zbigs: TStringList; // remembers what files are moved to game dir.
34+
settings: TSettings; // game location + UI settings
4235
active_mod: string; // remembers what mod is active now.
4336

44-
// jdj's own procedures
4537
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
5139
procedure LaunchGame( mod_name:string; params: string );
5240

5341
procedure ActivateMod( mod_name: string );
@@ -68,12 +56,12 @@ implementation
6856
// set button states correctly.
6957
procedure TFormMain.ScanScripts();
7058
begin
71-
if( DirectoryExists( script ) ) then begin
59+
if( DirectoryExists( settings.script ) ) then begin
7260
BtnMod.Enabled := true;
7361
BtnRestore.Enabled:= false;
7462
end;
7563

76-
if( DirectoryExists( dscript ) ) then begin
64+
if( DirectoryExists( settings.dscript ) ) then begin
7765
BtnMod.Enabled := false;
7866
BtnRestore.Enabled:= true;
7967
end;
@@ -85,20 +73,14 @@ procedure TFormMain.ImgLogoClick(Sender: TObject);
8573
ShellExecute( 0, 'open', 'http://red2.net', nil, nil, SW_SHOWNORMAL );
8674
end;
8775

88-
// show warning message
89-
procedure TFormMain.Warning( t:string );
90-
begin
91-
Application.MessageBox( PChar(t), '경고', MB_ICONWARNING );
92-
end;
93-
9476
// Scan mod directory.
9577
procedure TFormMain.ScanMods();
9678
var
9779
info : TSearchRec;
9880
mod_dir : string;
9981
begin
10082
// scan the dirs in gamedir/Mods
101-
mod_dir := IncludeTrailingPathDelimiter(game_dir)+'Mods';
83+
mod_dir := IncludeTrailingPathDelimiter(settings.game_dir)+'Mods';
10284
If FindFirst( mod_dir + '\*', faAnyFile and faDirectory, info ) = 0 then
10385
begin
10486
Repeat
@@ -116,81 +98,12 @@ procedure TFormMain.ScanMods();
11698
ModList.ItemIndex:= 0; // select 1st item.
11799
end;
118100

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-
188101
// Initialization of the program (?),
189102
// at least this form.
190103
procedure TFormMain.FormCreate(Sender: TObject);
191104
begin
192105
zbigs := TStringList.create;
193-
GetDirs();
106+
settings := TSettings.create;
194107
ScanMods();
195108
ScanScripts();
196109
end;
@@ -206,7 +119,7 @@ procedure TFormMain.LaunchGame( mod_name: string; params: string );
206119
// Run the mod
207120
//ShellExecute( 0, 'open', PChar(game_exe), PChar(params), nil, SW_NORMAL );
208121
output := '';
209-
RunCommand( game_exe, params, output );
122+
RunCommand( settings.game_exe, params, output );
210123

211124
// Wait for it to finish
212125
DeactivateMod( mod_name );
@@ -222,7 +135,7 @@ procedure TFormMain.ActivateMod( mod_name: string );
222135
active_mod := ModList.Text;
223136

224137
// 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) +
226139
'Mods\' + mod_name + '\';
227140

228141
If FindFirst( mod_path + '*.zbig', faAnyFile, info ) = 0 then
@@ -239,7 +152,7 @@ procedure TFormMain.ActivateMod( mod_name: string );
239152
begin
240153
fname := zbigs[ i ];
241154
src := mod_path + fname;
242-
dest := game_dir + fname;
155+
dest := settings.game_dir + fname;
243156
dest := StringReplace( dest, '.zbig', '.big', [rfReplaceAll] );
244157
MoveFile( PChar(src), PChar(dest) );
245158
end;
@@ -254,15 +167,15 @@ procedure TFormMain.DeactivateMod( mod_name: string );
254167
active_mod := '';
255168

256169
// 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) +
258171
'Mods\' + mod_name + '\';
259172

260173
// For each items in zbigs, move the file to the game dir.
261174
for i := 0 to zbigs.Count-1 do
262175
begin
263176
fname := zbigs[ i ];
264177
dest := mod_path + fname;
265-
src := game_dir + fname;
178+
src := settings.game_dir + fname;
266179
src := StringReplace( src, '.zbig', '.big', [rfReplaceAll] );
267180
//Warning( src + ' --> ' + dest );
268181
MoveFile( PChar(src), PChar(dest) );
@@ -288,13 +201,13 @@ procedure TFormMain.FormClose(Sender: TObject; var CloseAction: TCloseAction);
288201

289202
procedure TFormMain.BtnModClick(Sender: TObject);
290203
begin
291-
MoveFile( PChar(script), PChar(dscript) );
204+
MoveFile( PChar(settings.script), PChar(settings.dscript) );
292205
ScanScripts();
293206
end;
294207

295208
procedure TFormMain.BtnRestoreClick(Sender: TObject);
296209
begin
297-
MoveFile( PChar(dscript), PChar(script) );
210+
MoveFile( PChar(settings.dscript), PChar(settings.script) );
298211
ScanScripts();
299212
end;
300213

src/mod4.lpi

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
<PackageName Value="LCL"/>
3535
</Item1>
3636
</RequiredPackages>
37-
<Units Count="2">
37+
<Units Count="4">
3838
<Unit0>
3939
<Filename Value="mod4.lpr"/>
4040
<IsPartOfProject Value="True"/>
@@ -47,6 +47,16 @@
4747
<ResourceBaseClass Value="Form"/>
4848
<UnitName Value="MainForm"/>
4949
</Unit1>
50+
<Unit2>
51+
<Filename Value="settings.pas"/>
52+
<IsPartOfProject Value="True"/>
53+
<UnitName Value="Settings"/>
54+
</Unit2>
55+
<Unit3>
56+
<Filename Value="common.pas"/>
57+
<IsPartOfProject Value="True"/>
58+
<UnitName Value="Common"/>
59+
</Unit3>
5060
</Units>
5161
</ProjectOptions>
5262
<CompilerOptions>

0 commit comments

Comments
 (0)