install_all.iss

This commit is contained in:
yuejiajun 2025-08-26 16:15:34 +08:00
parent 18b1103c90
commit d8b12f9c6d

View File

@ -1,7 +1,7 @@
;iss ;iss
#define MyAppName "基础环境" #define MyAppName "基础环境"
#define MyAppVersion "1.0.12" #define MyAppVersion "1.0.14"
#define MyAppPublisher "X" #define MyAppPublisher "X"
#define MyAppURL "~" #define MyAppURL "~"
#define MyAppExeName "command" #define MyAppExeName "command"
@ -506,6 +506,141 @@ end;
// 删除过程文件
procedure RemoveTempFile;
begin
// DeleteFile
// DelTree
// 删除模版文件
if FileExists(ExpandConstant('{app}\mysql\template.ini')) then
DeleteFile(ExpandConstant('{app}\mysql\template.ini'));
if FileExists(ExpandConstant('{app}\mysql\template-initialize-and-start-mysql.bat')) then
DelTree(ExpandConstant('{app}\mysql\template-initialize-and-start-mysql.bat'), False, True, False);
if FileExists(ExpandConstant('{app}\mysql\template-register-mysql-with-data.bat')) then
DelTree(ExpandConstant('{app}\mysql\template-register-mysql-with-data.bat'), False, True, False);
if FileExists(ExpandConstant('{app}\mysql\import-data-into-mysql-v2.bat')) then
DelTree(ExpandConstant('{app}\mysql\import-data-into-mysql-v2.bat'), False, True, False);
// 删除默认 Readme.md
if FileExists(ExpandConstant('{app}\io\Readme.md')) then
DeleteFile(ExpandConstant('{app}\io\Readme.md'));
if FileExists(ExpandConstant('{app}\jdk\Readme.md')) then
DeleteFile(ExpandConstant('{app}\jdk\Readme.md'));
if FileExists(ExpandConstant('{app}\mysql\Readme.md')) then
DeleteFile(ExpandConstant('{app}\mysql\Readme.md'));
if FileExists(ExpandConstant('{app}\nginx\Readme.md')) then
DeleteFile(ExpandConstant('{app}\nginx\Readme.md'));
end;
// 初始化并启动MySQL
procedure InitializeAndStartMySQL;
var
ResultCode: Integer;
Cmd: string;
begin
// 通过 mysql 初始化生成的唯一 uuid 判断 mysql 是否已经完成初始化
if not FileExists(ExpandConstant('{app}\mysql\data\auto.cnf')) then
begin
// 如果没有完成初始化,则判断是否存在 readme.md 文件 即完全没有初始化
if FileExists(ExpandConstant('{app}\mysql\data\Readme.md')) then
begin
// 如果没有初始化,则删除 readme
DelTree(ExpandConstant('{app}\mysql\data\Readme.md'), False, True, False);
DelayMS(200);
end;
// 存在默认库SQL压缩包
if FileExists(ExpandConstant('{app}\mysql\database.rar')) then
begin
// 解压
if not Exec('cmd.exe', '/C " cd ' + ExpandConstant('{app}') + '\mysql && %cd%\..\usr\unrar.exe x database.rar script\demo\"', '', SW_HIDE, ewNoWait, ResultCode) then
begin
MsgBox('解压 MySQL 默认库失败', mbError, MB_OK);
end;
// 删除 database.rar 默认库SQL压缩包
DelayMS(1000);
DelTree(ExpandConstant('{app}\mysql\database.rar'), False, True, False);
end;
DelayMS(1000);
// 初始化
// 同步 ewWaitUntilTerminated
// 异步 ewNoWait
// 初始化并启动 MySQL
// Cmd := '/C "' + ExpandConstant('{app}') + '\mysql\initialize-and-start-mysql.bat"';
Cmd := '/C " cd ' + ExpandConstant('{app}') + '\mysql && initialize.bat"';
if not Exec('cmd.exe', Cmd, '', SW_HIDE, ewNoWait, ResultCode) then
begin
MsgBox('初始化 MySQL 脚本失败', mbError, MB_OK);
end else begin
DelayMS(3000);
// DeleteFile(ExpandConstant('{app}\mysql\initialize-and-start-mysql.bat'));
DeleteFile(ExpandConstant('{app}\mysql\register-mysql-with-data.bat'));
// DeleteFile(ExpandConstant('{app}\mysql\initialize.bat'));
end;
DelayMS(1000);
end; // mysql auto.conf 初始化判定
end;
// 导入默认数据库到 MySQL
// procedure ImportDefaultDatabase2MySQL;
// var
// ResultCode: Integer;
// Cmd: string;
// MySQLPath: string;
// UsrPath: string;
// begin
//
// // 判断是否安装了 usr 基础环境
// if FileExists(ExpandConstant('{app}\usr\rar.exe')) then
// begin
//
// // 等待 MySQL 服务启动完成
// DelayMS(3000);
// // 这个时候 `环境变量` 还没开始注册,所以 bat 导入脚本不生效因此需要指定临时Path环境变量
// // 导出默认库和用户
// if FileExists(ExpandConstant('{app}\mysql\import-data-into-mysql.bat')) then
// begin
//
// // 临时设置 PATH 并执行脚本
// MySQLPath := ExpandConstant('{app}') + '\mysql\bin';
// UsrPath := ExpandConstant('{app}') + '\usr';
// Cmd := '/C "set PATH=' + MySQLPath + '; ' + UsrPath + ';%PATH%' +
// ' && cd ' + ExpandConstant('{app}') + '\mysql' +
// ' && import-data-into-mysql.bat"' +
// ' && exit"';
//
// if not Exec('cmd.exe', Cmd, '', SW_HIDE, ewNoWait, ResultCode) then
// begin
// MsgBox('初始化默认库脚本失败', mbError, MB_OK);
// end;
// DelayMS(1000);
// end;
// end; // 是否安装了 usr 环境
//
// end;
@ -529,117 +664,22 @@ end;
// 在安装完成后执行 // 在安装完成后执行
procedure CurStepChanged(CurStep: TSetupStep); procedure CurStepChanged(CurStep: TSetupStep);
var
ResultCode: Integer;
Cmd: string;
MySQLPath: string;
UsrPath: string;
begin begin
// 仅在安装完成后执行 // 仅在安装完成后执行
if CurStep = ssPostInstall then if CurStep = ssPostInstall then
begin begin
// 创建配置文件
CreateConfigFromTemplate;
// 删除过程文件
RemoveTempFile;
// 创建配置文件 // 初始化并启动 MySQL
CreateConfigFromTemplate; InitializeAndStartMySQL;
// DeleteFile
// DelTree
// 删除模版文件
if FileExists(ExpandConstant('{app}\mysql\template.ini')) then
DeleteFile(ExpandConstant('{app}\mysql\template.ini'));
if FileExists(ExpandConstant('{app}\mysql\template-initialize-and-start-mysql.bat')) then
DelTree(ExpandConstant('{app}\mysql\template-initialize-and-start-mysql.bat'), False, True, False);
if FileExists(ExpandConstant('{app}\mysql\template-register-mysql-with-data.bat')) then
DelTree(ExpandConstant('{app}\mysql\template-register-mysql-with-data.bat'), False, True, False);
if FileExists(ExpandConstant('{app}\mysql\import-data-into-mysql-v2.bat')) then
DelTree(ExpandConstant('{app}\mysql\import-data-into-mysql-v2.bat'), False, True, False);
// 删除默认 Readme.md
if FileExists(ExpandConstant('{app}\io\Readme.md')) then
DeleteFile(ExpandConstant('{app}\io\Readme.md'));
if FileExists(ExpandConstant('{app}\jdk\Readme.md')) then
DeleteFile(ExpandConstant('{app}\jdk\Readme.md'));
if FileExists(ExpandConstant('{app}\mysql\Readme.md')) then
DeleteFile(ExpandConstant('{app}\mysql\Readme.md'));
if FileExists(ExpandConstant('{app}\nginx\Readme.md')) then
DeleteFile(ExpandConstant('{app}\nginx\Readme.md'));
// 通过 mysql 初始化生成的唯一 uuid 判断 mysql 是否已经完成初始化
if not FileExists(ExpandConstant('{app}\mysql\data\auto.cnf')) then
begin
// 如果没有完成初始化,则判断是否存在 readme.md 文件 即完全没有初始化
if FileExists(ExpandConstant('{app}\mysql\data\Readme.md')) then
begin
// 如果没有初始化,则删除 readme
DelTree(ExpandConstant('{app}\mysql\data\Readme.md'), False, True, False);
// 初始化
// 同步 ewWaitUntilTerminated
// 异步 ewNoWait
Cmd := '/C "' + ExpandConstant('{app}') + '\mysql\initialize-and-start-mysql.bat"';
if not Exec('cmd.exe', Cmd, '', SW_HIDE, ewNoWait, ResultCode) then
begin
MsgBox('初始化 MySQL 脚本失败', mbError, MB_OK);
end else begin
DelayMS(3000);
DeleteFile(ExpandConstant('{app}\mysql\initialize-and-start-mysql.bat'));
DeleteFile(ExpandConstant('{app}\mysql\register-mysql-with-data.bat'));
end;
// 存在默认库SQL压缩包
if FileExists(ExpandConstant('{app}\mysql\database.rar')) then
begin
// 解压
if not Exec('cmd.exe', '/C " cd ' + ExpandConstant('{app}') + '\mysql && %cd%\..\usr\unrar.exe x database.rar script\demo\"', '', SW_HIDE, ewNoWait, ResultCode) then
begin
MsgBox('初始化 MySQL 脚本失败', mbError, MB_OK);
end;
// 删除 database.rar 默认库SQL压缩包
DelayMS(1000);
DelTree(ExpandConstant('{app}\mysql\database.rar'), False, True, False);
// 判断是否安装了 usr 基础环境
if FileExists(ExpandConstant('{app}\usr\rar.exe')) then
begin
// 这个时候 `环境变量` 还没开始注册,所以 bat 导入脚本不生效因此需要指定临时Path环境变量
// 导出默认库和用户
if FileExists(ExpandConstant('{app}\mysql\import-data-into-mysql.bat')) then
begin
// 临时设置 PATH 并执行脚本
MySQLPath := ExpandConstant('{app}') + '\mysql\bin';
UsrPath := ExpandConstant('{app}') + '\usr';
Cmd := '/C "set PATH=' + MySQLPath + '; ' + UsrPath + ';%PATH%' +
' && cd ' + ExpandConstant('{app}') + '\mysql' +
' && import-data-into-mysql.bat"' +
' && exit"';
if not Exec('cmd.exe', Cmd, '', SW_HIDE, ewNoWait, ResultCode) then
begin
MsgBox('初始化 MySQL 脚本失败', mbError, MB_OK);
end;
DelayMS(1000);
end;
end;
end;
end;
end;
// 导入默认数据库到 MySQL
// ImportDefaultDatabase2MySQL;
end; // 安装完成后的执行 end; // 安装完成后的执行