From 6d4de737c4203d80168998571ac07bdcd56a83be Mon Sep 17 00:00:00 2001 From: LHY20 <3364451258@qq.com> Date: Sun, 27 Jul 2025 10:34:49 +0800 Subject: [PATCH] Add NSIS installer script and update main.c --- installer.nsi | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++ main.c | 4 ++- 2 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 installer.nsi diff --git a/installer.nsi b/installer.nsi new file mode 100644 index 0000000..d723b92 --- /dev/null +++ b/installer.nsi @@ -0,0 +1,83 @@ +; 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 all C source files + File "ai.c" + File "config.c" + File "game_mode.c" + File "globals.c" + File "gobang.c" + File "init_board.c" + File "main.c" + File "network.c" + File "record.c" + File "ui.c" + + ; Copy all header files + File "ai.h" + File "config.h" + File "game_mode.h" + File "globals.h" + File "gobang.h" + File "init_board.h" + File "network.h" + File "record.h" + File "type.h" + File "ui.h" + + ; Copy configuration and documentation files + File "gobang_config.ini" + File "README.md" + + ; Copy directories + File /r "MD" + File /r "TXT" + + ; 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 \ No newline at end of file diff --git a/main.c b/main.c index f1b406a..03604ae 100644 --- a/main.c +++ b/main.c @@ -4,10 +4,12 @@ * @note 本文件包含了游戏的主循环、模式选择和游戏初始化等功能 * @brief 将以下指令复制到powershell * gcc -std=c17 -o gobang.exe *.c -lws2_32 - .\gobang.exe + .\gobang.exe * @detail gcc 为编译器,添加了-lws2_32链接Windows网络库 * @detail 编译指令:gcc -std=c17 -o gobang.exe *.c -lws2_32 * @detail 运行指令:.\gobang.exe + * @brief & "D:\Program Files (x86)\NSIS\makensis.exe" "d:\Code\doing_exercises\gobang\installer.nsi" + * @detail 安装指令:makensis installer.nsi */ #include "game_mode.h"