55interface
66
77uses
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;
8181begin
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;
129129begin
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' , ' ' ) );
155155end ;
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;
160208var
161209 reg: TRegistry;
162210begin
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