AutoPercenty3/generate_iss.py.bak

134 lines
5.0 KiB
Python

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
updateManager/__version__.py 파일에서 정보를 읽어 Inno Setup 스크립트 파일을 생성합니다.
"""
import os
import sys
import datetime
import importlib.util
from pathlib import Path
def load_version_module(version_file_path):
"""버전 정보 모듈을 동적으로 로드합니다."""
spec = importlib.util.spec_from_file_location("version_module", version_file_path)
version_module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(version_module)
return version_module
def generate_iss_file():
"""버전 정보를 읽어 .iss 파일을 생성합니다."""
# 현재 디렉토리 확인
current_dir = os.path.dirname(os.path.abspath(__file__))
# 버전 파일 경로
version_file = os.path.join(current_dir, 'updateManager', '__version__.py')
if not os.path.exists(version_file):
print(f"오류: 버전 파일을 찾을 수 없습니다: {version_file}")
sys.exit(1)
try:
# 버전 모듈 로드
version_module = load_version_module(version_file)
# 현재 날짜와 시간
now = datetime.datetime.now()
date_str = now.strftime("%Y%m%d_%H%M%S")
# 생성할 .iss 파일 이름
iss_filename = f"AutoPercenty_{date_str}.iss"
# 템플릿 작성
iss_template = f"""; AutoPercenty3 Inno Setup Script
; 이 스크립트는 cx_Freeze로 빌드된 결과물이 있는 "build\exe.win-amd64-3.11" 폴더를 기반으로 인스톨러를 제작합니다.
; {date_str}에 생성됨
#define MyAppName "{version_module.__title__}"
#define MyAppVersion "{version_module.__version__}"
#define MyAppPublisher "{version_module.__company_name__}"
#define MyAppProgramName "{version_module.__program_name__}"
#define MyAppDescription "{version_module.__description__}"
#define MyAppCopyright "{version_module.__copyright__}"
#define MyAppExeName "{version_module.__exe_name__}"
#define MySetupName "{version_module.__setup_name__}"
#define MySetupIcon "{version_module.__icon_file__}"
#define MySetupOutputDir "{version_module.__setup_output_dir__}"
[Setup]
AppName={{#MyAppProgramName}}
AppVersion={{#MyAppVersion}}
AppPublisher={{#MyAppPublisher}}
AppPublisherURL=
; 기본 설치 경로: AppData\Local\AutoPercenty3
DefaultDirName={{localappdata}}\\{{#MyAppName}}
DefaultGroupName={{#MyAppProgramName}}
OutputDir={{#MySetupOutputDir}}
OutputBaseFilename={{#MySetupName}}
SetupIconFile={{#MySetupIcon}}
Compression=lzma
SolidCompression=yes
VersionInfoVersion={{#MyAppVersion}}
VersionInfoCompany={{#MyAppPublisher}}
VersionInfoDescription={{#MyAppDescription}}
VersionInfoCopyright={{#MyAppCopyright}}
VersionInfoProductName={{#MyAppProgramName}}
VersionInfoProductVersion={{#MyAppVersion}}
[Languages]
Name: "korean"; MessagesFile: "compiler:Languages\\Korean.isl"
[Tasks]
Name: "desktopicon"; Description: "{{cm:CreateDesktopIcon}}"; GroupDescription: "{{cm:AdditionalIcons}}"
[Dirs]
; 설치 시 {{app}}\\logs 폴더를 생성하고,
; Users 그룹에 'modify' 권한(=쓰기 가능)을 부여
Name: "{{app}}\\logs"; Permissions: users-modify
[Files]
; cx_Freeze로 빌드된 결과물 모두를 설치 폴더로 복사
Source: "build\\exe.win-amd64-3.11\\*"; DestDir: "{{app}}"; Flags: ignoreversion recursesubdirs createallsubdirs
; VC++ 재배포 패키지 파일을 임시 폴더({{tmp}})에 복사
Source: "VC_redist.x64.exe"; DestDir: "{{tmp}}"; Flags: deleteafterinstall
[Icons]
; 시작 메뉴 바로가기
Name: "{{group}}\\{{#MyAppProgramName}}"; Filename: "{{app}}\\{{#MyAppExeName}}.exe"
; 바탕화면 바로가기
Name: "{{autodesktop}}\\{{#MyAppProgramName}}"; Filename: "{{app}}\\{{#MyAppExeName}}.exe"; Tasks: desktopicon
[Run]
; VC++ 재배포 패키지 설치 (필요할 경우)
Filename: "{{tmp}}\\VC_redist.x64.exe"; Parameters: "/install /passive /norestart"; StatusMsg: "VC++ 재배포 패키지 설치 중..."; Check: NeedsVCredist
; 설치 후 프로그램 실행 (원할 경우 주석 해제)
Filename: "{{app}}\\{{#MyAppExeName}}.exe"; Description: "{{cm:LaunchProgram,{{#MyAppProgramName}}}}"; Flags: nowait postinstall skipifsilent
[Code]
function NeedsVCredist: Boolean;
begin
// 예: 레지스트리 키 확인으로 VC++ 2015~2022 x64 런타임이 깔려있는지 판단
// (VC++ 버전에 따라 키/값이 달라질 수 있으므로, 실제 환경에 맞게 수정 필요)
if RegKeyExists(HKEY_LOCAL_MACHINE, 'SOFTWARE\\Microsoft\\VisualStudio\\14.0\\VC\\Runtimes\\x64') then
Result := False // 이미 설치됨
else
Result := True; // 미설치 -> 설치 필요
end;
"""
# .iss 파일 저장
with open(iss_filename, 'w', encoding='utf-8') as f:
f.write(iss_template)
print(f".iss 파일이 성공적으로 생성되었습니다: {iss_filename}")
return iss_filename
except Exception as e:
print(f"오류 발생: {e}")
sys.exit(1)
if __name__ == "__main__":
generate_iss_file()