重构安装脚本:将安装文件移动到installer文件夹并修复路径问题

This commit is contained in:
2025-07-27 20:22:52 +08:00
parent 6d4de737c4
commit 1d8e2e25cf
4 changed files with 69 additions and 38 deletions
+55
View File
@@ -0,0 +1,55 @@
; NSIS Installation Script
!include "MUI2.nsh"
; Basic Information
Name "Gobang Game"
OutFile "..\\Gobang_Setup.exe"
InstallDir "$PROGRAMFILES\Gobang"
RequestExecutionLevel admin
; Interface Settings
!define MUI_ABORTWARNING
!define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\modern-install.ico"
; Installation Pages
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
; Language Settings
!insertmacro MUI_LANGUAGE "SimpChinese"
; Installation Section
Section "Main"
SetOutPath "$INSTDIR"
; Copy configuration and documentation files
File "..\\gobang_config.ini"
File "..\\README.md"
; Copy executable file if exists
IfFileExists "..\\gobang.exe" 0 +2
File "..\\gobang.exe"
; Create program group directory
CreateDirectory "$SMPROGRAMS\Gobang"
; Create shortcuts (only if executable exists)
IfFileExists "$INSTDIR\gobang.exe" 0 +3
CreateShortCut "$DESKTOP\Gobang.lnk" "$INSTDIR\gobang.exe"
CreateShortCut "$SMPROGRAMS\Gobang\Gobang.lnk" "$INSTDIR\gobang.exe"
; Write uninstall information
WriteUninstaller "$INSTDIR\Uninstall.exe"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Gobang" \
"DisplayName" "Gobang Game"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Gobang" \
"UninstallString" "$\"$INSTDIR\Uninstall.exe$\""
SectionEnd
; Uninstall Section
Section "Uninstall"
RMDir /r "$INSTDIR"
Delete "$DESKTOP\Gobang.lnk"
RMDir /r "$SMPROGRAMS\Gobang"
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Gobang"
SectionEnd
+57
View File
@@ -0,0 +1,57 @@
; Inno Setup Script for Gobang Game
; Generated by Inno Setup Script Wizard
[Setup]
; NOTE: The value of AppId uniquely identifies this application.
; Do not use the same AppId value in installers for other applications.
AppId={{A92AAE42-5C7E-4C8E-9F2B-8D4E5F6A7B8C}
AppName=Gobang Game
AppVersion=1.0
AppPublisher=Gobang Game Developer
DefaultDirName={autopf}\Gobang
DefaultGroupName=Gobang Game
AllowNoIcons=yes
OutputDir=..
OutputBaseFilename=Gobang_Setup
SetupIconFile=compiler:SetupClassicIcon.ico
Compression=lzma
SolidCompression=yes
WizardStyle=modern
[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"
Name: "chinesesimplified"; MessagesFile: "compiler:Languages\ChineseSimplified.isl"
[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
[Files]
; 可执行文件
Source: "..\\gobang.exe"; DestDir: "{app}"; Flags: ignoreversion
; 配置文件
Source: "..\\gobang_config.ini"; DestDir: "{app}"; Flags: ignoreversion
; 指定的TXT文件
Source: "..\\TXT\\*"; DestDir: "{app}\TXT"; Flags: ignoreversion
; 文档文件
Source: "..\\README.md"; DestDir: "{app}"; Flags: ignoreversion
[Dirs]
; 创建空的records目录(不包含存档文件)
Name: "{app}\records"
[Icons]
Name: "{group}\Gobang Game"; Filename: "{app}\gobang.exe"; Check: FileExists(ExpandConstant('{app}\gobang.exe'))
Name: "{group}\{cm:UninstallProgram,Gobang Game}"; Filename: "{uninstallexe}"
Name: "{autodesktop}\Gobang Game"; Filename: "{app}\gobang.exe"; Tasks: desktopicon; Check: FileExists(ExpandConstant('{app}\gobang.exe'))
[Run]
Filename: "{app}\gobang.exe"; Description: "{cm:LaunchProgram,Gobang Game}"; Flags: nowait postinstall skipifsilent; Check: FileExists(ExpandConstant('{app}\gobang.exe'))
[Code]
function FileExists(const FileName: string): Boolean;
begin
Result := FileExists(FileName);
end;