# make_version.py
import datetime
import os

def create_version_file():
    # 1. 生成版本号 (示例：使用 年.月.日.0)
    today = datetime.date.today()
    # 格式：(2026, 1, 5, 0)
    ver_tuple = (today.year, today.month, today.day, 0)
    ver_str = f"{today.year}.{today.month}.{today.day}.0"
    
    # 2. 定义版本信息结构 (PyInstaller 格式)
    # 语言代码 2052 = 简体中文, 字符集 1200 = Unicode
    content = f"""# UTF-8
VSVersionInfo(
  ffi=FixedFileInfo(
    filevers={ver_tuple},
    prodvers={ver_tuple},
    mask=0x3f,
    flags=0x0,
    OS=0x40004,
    fileType=0x1,
    subtype=0x0,
    date=(0, 0)
  ),
  kids=[
    StringFileInfo(
      [
      StringTable(
        u'080404b0',
        [StringStruct(u'CompanyName', u'中能建西北院海上能源业务开发部'),
        StringStruct(u'FileDescription', u'海上风电场集电线路设计优化系统'),
        StringStruct(u'FileVersion', u'{ver_str}'),
        StringStruct(u'InternalName', u'WindFarmOptimizer'),
        StringStruct(u'LegalCopyright', u'Copyright (c) {today.year}'),
        StringStruct(u'OriginalFilename', u'海上风电场集电线路设计优化系统.exe'),
        StringStruct(u'ProductName', u'海上风电场集电线路设计优化系统'),
        StringStruct(u'ProductVersion', u'{ver_str}')])
      ]), 
    VarFileInfo([VarStruct(u'Translation', [2052, 1200])])
  ]
)
"""
    
    with open("version_info.txt", "w", encoding="utf-8") as f:
        f.write(content)
    
    # 3. 同时生成一个 python 文件供 gui.py 调用
    with open("version.py", "w", encoding="utf-8") as f:
        f.write(f'VERSION = "v{ver_str}"\n')
        
    print(f"已生成版本信息文件: version_info.txt 和 version.py (版本: v{ver_str})")

if __name__ == "__main__":
    create_version_file()
