Skip to content

Commit 30f10c4

Browse files
committed
Fix Generals.exe resolution bug
1 parent ba6d43b commit 30f10c4

3 files changed

Lines changed: 60 additions & 18 deletions

File tree

src/mainform.pas

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ interface
66

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

@@ -55,7 +55,7 @@ TFormMain = class(TForm)
5555

5656
public
5757
{ public declarations }
58-
end;
58+
end;
5959

6060
var
6161
FormMain: TFormMain;
@@ -236,7 +236,7 @@ procedure TFormMain.ActivateMod( mod_name: string );
236236
zbigs.Add( info.name );
237237
Until FindNext(info) <> 0;
238238
SysUtils.FindClose( info );
239-
239+
240240
// Remember these settings so that it may be deactivated later,
241241
// even after the mod launhcher is terminated.
242242
settings.conf.SetValue( '/current_mod/name', mod_name );
@@ -358,4 +358,3 @@ initialization
358358
{$I mainform.lrs}
359359

360360
end.
361-

src/mod4.lpr

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,3 @@
1818
Application.CreateForm(TFormMain, FormMain);
1919
Application.Run;
2020
end.
21-

src/settings.pas

Lines changed: 57 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
interface
66

77
uses
8-
Classes, SysUtils, Registry, jsonConf, Dialogs, Controls,
8+
Classes, Forms, SysUtils, Registry, jsonConf, Dialogs, Controls,
99
Common;
1010

1111
// Class to hold user settings and reading registry.
@@ -21,7 +21,7 @@ TSettings = class
2121
procedure LoadConf();
2222

2323
//function GetMyDoc(): string;
24-
function GenReg( t: string ): string;
24+
function FindGeneralsExe( t: string ): string;
2525
function GetInstallDir: string;
2626

2727
// Property getter setters
@@ -80,15 +80,15 @@ function TSettings.GetInstallDir: string;
8080
diag: TOpenDialog;
8181
begin
8282
// Number 1, try registry.
83-
result := GenReg( 'InstallPath' );
83+
result := FindGeneralsExe( 'InstallPath' );
8484

8585
// installdir might point to Generals.exe!
8686
// If file, FileExists returns true.
8787
// If dir, returns False.
8888
if( FileExists( result ) ) then
8989
begin
9090
// Ask user confirmation
91-
if MessageDlg( '확인', '다음 제로아워 경로가를 사용하겠습니까?:' + sLineBreak + result,
91+
if MessageDlg( '확인', '다음 제로아워 경로를 사용하겠습니까?:' + sLineBreak + result,
9292
mtConfirmation, [mbYes, mbNo],0) = mrYes
9393
then
9494
begin
@@ -128,7 +128,7 @@ procedure TSettings.GetDirs();
128128
installdir: string;
129129
begin
130130
//mydoc := GetMyDoc();
131-
//dataleaf := GenReg( 'UserDataLeafName' );
131+
//dataleaf := FindGeneralsExe( 'UserDataLeafName' );
132132
//moddir := mydoc + dataleaf;
133133

134134
// Well, config load failed. Attempt to read reg or read user input...
@@ -139,7 +139,7 @@ procedure TSettings.GetDirs();
139139

140140
// we are ready to calculate now.
141141
installdir := IncludeTrailingPathDelimiter( game_dir );
142-
game_exe := installdir + 'generals.exe';
142+
game_exe := installdir + 'Generals.exe';
143143
script := installdir + 'Data\Scripts';
144144
dscript := installdir + 'Data\_Scripts';
145145

@@ -154,22 +154,66 @@ function TSettings.GetGameDir(): string;
154154
result := Utf8Encode( conf.GetValue( 'game_dir', '' ) );
155155
end;
156156

157+
function TryReadRegKey(
158+
reg: TRegistry;
159+
key: string;
160+
t: string
161+
): string;
162+
var
163+
tmp: string;
164+
begin
165+
Result := '';
166+
if reg.KeyExists(key) then
167+
begin
168+
reg.OpenKeyReadOnly(key);
169+
if reg.ValueExists(t) then
170+
tmp := reg.ReadString( t );
171+
reg.CloseKey();
172+
173+
tmp := path_join(tmp, 'Generals.exe');
174+
if FileExists(tmp) then
175+
Result := tmp;
176+
end;
177+
end;
178+
179+
function ResolveZH(
180+
reg: TRegistry;
181+
t: string
182+
): string;
183+
var
184+
key: string;
185+
tmp: string;
186+
begin
187+
Result := TryReadRegKey(reg, 'SOFTWARE\Electronic Arts\EA Games\Command and Conquer Generals Zero Hour', t);
188+
if Result <> '' then Exit(Result);
189+
190+
Result := TryReadRegKey(reg, 'SOFTWARE\WOW6432Node\Electronic Arts\EA Games\Command and Conquer Generals Zero Hour', t);
191+
if Result <> '' then Exit(Result);
192+
193+
Result := TryReadRegKey(reg, 'SOFTWARE\Electronic Arts\EA Games\Generals', t);
194+
if Result <> '' then Exit(Result);
195+
196+
Result := TryReadRegKey(reg, 'SOFTWARE\WOW6432Node\Electronic Arts\EA Games\Generals', t);
197+
if Result <> '' then Exit(Result);
198+
199+
// Try where mod4.exe is
200+
tmp := path_join(ExtractFileDir(Application.ExeName), 'Generals.exe');
201+
if FileExists(tmp) then
202+
Result := tmp;
203+
end;
204+
157205
// read values from
158206
// SOFTWARE\Electronic Arts\EA Games\Command and Conquer Generals Zero Hour
159-
function TSettings.GenReg( t: string ): string;
207+
function TSettings.FindGeneralsExe( t: string ): string;
160208
var
161209
reg: TRegistry;
162210
begin
163211
reg := TRegistry.Create(KEY_READ);
164212
try
165213
reg.RootKey := HKEY_LOCAL_MACHINE;
166-
reg.OpenKey('SOFTWARE\Electronic Arts\EA Games\Command and Conquer Generals Zero Hour', False);
167-
if reg.ValueExists( t ) then
168-
Result := reg.ReadString( t )
169-
else begin
170-
Result := '';
214+
Result := ResolveZH(reg, t);
215+
if Result = '' then
171216
Warning( '제로아워 레지스트리값 ' + t + ' 읽기 실패, Generals.exe를 직접 골라주세요.' );
172-
end;
173217
finally
174218
reg.Free;
175219
end;

0 commit comments

Comments
 (0)