Sono riuscito a realizzare ls ricerca del path della JRE ed eventualmente bloccare il setup in caso di assenza.
Posto il codice da inserire nel tag code dell'Inno Setup Script:
codice:
var
javawExePath: String;
javaMinVersion: String;
(* cerca JRE, in Registry *)
function getJREVersion(): String;
var
javaVersion: String;
begin
javaVersion := '';
(* Cerco chiave su registro SOFTWARE\JavaSoft\Java Runtime Environment *)
RegQueryStringValue(HKLM, 'SOFTWARE\JavaSoft\Java Runtime Environment', 'CurrentVersion', javaVersion);
(* Catturo versione *)
GetVersionNumbersString(javaVersion, javaVersion);
(* Ritorno versione *)
Result := javaVersion;
end;
(* cerca JRE, in Registry *)
function getJDKVersion(): String;
var
jdkVersion: String;
begin
jdkVersion := '';
(* Cerco chiave su registro SOFTWARE\JavaSoft\Java Development Kit *)
RegQueryStringValue(HKLM, 'SOFTWARE\JavaSoft\Java Development Kit', 'CurrentVersion', jdkVersion);
(* Catturo versione *)
GetVersionNumbersString(jdkVersion, jdkVersion);
(* Ritorno versione *)
Result := jdkVersion;
end;
(* Carco path "javaw.exe" in JDK or JRE directory *)
(* in registry. Verifico esisteza del Java. *)
(* Se non trovo niente, ritorno "". *)
function GetJavaPath(Default: String): String;
var
javaVersion: String;
javaHome: String;
path: String;
begin
path := '';
(* Se ho già trovato path java *)
if Length(javawExePath) > 0 then
begin
(* Ritorno path java *)
Result := javawExePath;
path := javawExePath;
end;
(* cerco JDK *)
javaVersion := getJDKVersion();
(* Se non ho ancora trovato il Java AND javaVersion è valido && la versione >= di javaMinVersion *)
if (Length(path) = 0) and (Length(javaVersion) > 0) and ((javaVersion) >= javaMinVersion) then
begin
(* Catturo path del JDK *)
RegQueryStringValue(HKLM, 'SOFTWARE\JavaSoft\Java Development Kit\' + javaVersion, 'JavaHome', javaHome);
(* Costruisco path per JRE *)
path := javaHome + '\bin\' + 'javaw.exe';
(* Se path costruito esiste *)
if FileExists(path) then
begin
(* Trovato JAVA -> ritorno percorso *)
Log('(JDK) found javaw.exe: ' + path);
Result := javaHome;
end;
end;
(* Se non ho ancora trovato il Java *)
if Length(path) = 0 then
begin
Log('(JRE) JDK not found, looking for JRE');
(* cerco JRE *)
javaVersion := getJREVersion();
(* Se javaVersion è valido && la versione >= di javaMinVersion *)
if (Length(javaVersion) > 0) and ((javaVersion) >= javaMinVersion) then
begin
(* Catturo path del JRE *)
RegQueryStringValue(HKLM, 'SOFTWARE\JavaSoft\Java Runtime Environment\' + javaVersion, 'JavaHome', javaHome);
(* Costruisco path per JRE *)
path := javaHome + '\bin\' + 'javaw.exe';
(* Se path costruito esiste *)
if FileExists(path) then
begin
(* Trovato JAVA -> ritorno percorso *)
Log('(JRE) found javaw.exe: ' + path);
Result := javaHome;
end
end;
end;
(* Memorizzo risultato del path in variabile globale *)
javawExePath := Result;
end;
(* Funzione richiamata all'avvio del setup *)
function InitializeSetup(): Boolean;
var
javaPath: String;
begin
(* JRE version richiesta *)
javaMinVersion := '1.4.2';
(* Catturo JAVAHOME *)
javaPath := GetJavaPath('');
(* Se trovato JAVAHOME *)
if Length(javaPath) > 0 then
begin
(* Ritorno true *)
Result := true;
end
else
begin
MsgBox('Impossibile trovare Java Development Kit o Java Runtime ' + javaMinVersion + ', or superiore, installato.' + #13 +
'JDK o JRE, ' + javaMinVersion + ' o superiore richisto per proseguire l''installazione.' + #13 +
'Puoi scaricare JRE direttamente da http://java.sun.com. Intalla la JRE e riavvia il setup.', mbInformation, MB_OK);
(* Ritorno false *)
Result := false;
end;
end;
Adesso avrei un'altra necesità: creare un database MySql e costruirne la struttura iniziale.
Non ho molta dimestichezza, ma per quel che ho visto Inno Setup è scritto in Delphi.
E' molto probabile che il codice in Delphi per la costruzione di un db in MySql funzioni anche come script di Inno Setup.
A questo punto chiedo a chi ne sa più di me (alka?) un esempio di codice Delphi per lavorare con MySql.
Ho visitato anche www.torry.net, ma ho ancora qualche dificcoltà
Grazie a tutti.