Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
HIllya51 committed Nov 2, 2024
1 parent c53637a commit 619c5f8
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 293 deletions.
22 changes: 11 additions & 11 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- id: loadversion
run: python src/build.py loadversion | Out-File -FilePath $Env:GITHUB_OUTPUT -Encoding utf8 -Append

build_py:
pyrt:
runs-on: windows-latest
strategy:
matrix:
Expand All @@ -29,7 +29,7 @@ jobs:
python-version: '3.7.9'
architecture: ${{ matrix.architecture }}

- run: python src/build.py py ${{ matrix.architecture }} 3.7.9
- run: python src/build.py pyrt ${{ matrix.architecture }} 3.7.9
- uses: actions/upload-artifact@v4
with:
name: ${{ matrix.fname }}
Expand All @@ -53,7 +53,7 @@ jobs:

release:
runs-on: windows-latest
needs: [build_py,build_cpp,loadversion]
needs: [pyrt,build_cpp,loadversion]
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
Expand All @@ -64,11 +64,11 @@ jobs:
with:
name: cpp
path: src/plugins/builds
# - name: Release LunaTranslator
# uses: softprops/action-gh-release@v2
# with:
# tag_name: ${{ needs.loadversion.outputs.version }}
# files: |
# src/build/${{ matrix.fname }}.zip
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: softprops/action-gh-release@v2
with:
tag_name: ${{ needs.loadversion.outputs.version }}
files: |
src/build/LunaTranslator_x86.zip
src/build/LunaTranslator.zip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
37 changes: 20 additions & 17 deletions src/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,20 +267,9 @@ def downloadbass():
if sys.argv[1] == "cpp":
installVCLTL()
buildPlugins()
elif sys.argv[1] == "py":
elif sys.argv[1] == "pyrt":
arch = sys.argv[2]
version = sys.argv[3]
createPluginDirs()
downloadsomething()
downloadBrotli()
downloadLocaleEmulator()
downloadNtlea()
downloadCurl()
downloadOCRModel()
downloadcommon()
downloadbass()
downLunaHook()
os.chdir(rootDir)
if arch == "x86":
py37Path = (
f"C:\\hostedtoolcache\\windows\\Python\\{version}\\x86\\python.exe"
Expand All @@ -298,12 +287,26 @@ def downloadbass():
# 放弃,3.8需要安装KB2533623才能运行,3.7用不着。
subprocess.run(f"{py37Path} collectpyruntime.py")
elif sys.argv[1] == "merge":
1

def listdir():
createPluginDirs()
downloadsomething()
downloadBrotli()
downloadLocaleEmulator()
downloadNtlea()
downloadCurl()
downloadOCRModel()
downloadcommon()
downloadbass()
downLunaHook()
os.chdir(rootDir)
shutil.copytree(f'{rootDir}/../build/cpp', f'{rootDir}/plugins/builds',dirs_exist_ok=True)
os.chdir(rootDir + "\\plugins\\scripts")
subprocess.run(f"python copytarget.py 1")
subprocess.run(f"python copytarget.py 0")
shutil.copytree(f'{rootDir}/../build/LunaTranslator', f'{rootDir}/plugins/builds',dirs_exist_ok=True)
shutil.copytree(f'{rootDir}/../build/LunaTranslator_x86', f'{rootDir}/plugins/builds',dirs_exist_ok=True)
for f in os.walk("."):
_dir, _, _fs = f
for _f in _fs:
print(os.path.abspath(os.path.join(_dir, _f)))

listdir()
os.system('python collectall.py 32')
os.system('python collectall.py 64')
104 changes: 104 additions & 0 deletions src/collectall.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import shutil, os
import platform
import sys
from importanalysis import importanalysis

x86 = platform.architecture()[0] == "32bit"
if sys.argv[1] == "32":
targetdir = r"build\LunaTranslator_x86"
launch = r"plugins\builds\_x86"
baddll = "DLL64"
else:
baddll = "DLL32"
launch = r"plugins\builds\_x64"
targetdir = r"build\LunaTranslator"


def copycheck(src, tgt):
print(src, tgt, os.path.exists(src))
if not os.path.exists(src):
return
if src.lower().endswith("_ssl.pyd"):
return
if not os.path.exists(tgt):
os.makedirs(tgt, exist_ok=True)
if os.path.isdir(src):
tgt = os.path.join(tgt, os.path.basename(src))
if os.path.exists(tgt):
shutil.rmtree(tgt)
shutil.copytree(src, tgt)
return
shutil.copy(src, tgt)


copycheck(os.path.join(launch, "LunaTranslator.exe"), targetdir)
copycheck(os.path.join(launch, "LunaTranslator_admin.exe"), targetdir)
copycheck(os.path.join(launch, "LunaTranslator_debug.exe"), targetdir)
copycheck("./LunaTranslator", targetdir)
copycheck(r".\files", targetdir)
try:
shutil.rmtree(rf"{targetdir}\files\plugins\{baddll}")
except:
pass
shutil.copy(r"..\LICENSE", targetdir)

collect = []
for _dir, _, fs in os.walk(targetdir):
for f in fs:
collect.append(os.path.join(_dir, f))
for f in collect:
if f.endswith(".pyc") or f.endswith("Thumbs.db"):
os.remove(f)
elif f.endswith(".exe") or f.endswith(".pyd") or f.endswith(".dll"):
if f.endswith("Magpie.Core.exe"):
continue
print(f)
imports = importanalysis(f)
print(f, imports)
if len(imports) == 0:
continue
with open(f, "rb") as ff:
bs = bytearray(ff.read())
for _dll, offset in imports:
if _dll.lower().startswith("api-ms-win-core"):
# 其实对于api-ms-win-core-winrt-XXX实际上是到ComBase.dll之类的,不过此项目中不包含这些
_target = "kernel32.dll"
elif _dll.lower().startswith("api-ms-win-crt"):
_target = "ucrtbase.dll"
else:
continue
_dll = _dll.encode()
_target = _target.encode()
# print(len(bs))
bs[offset : offset + len(_dll)] = _target + b"\0" * (
len(_dll) - len(_target)
)
# print(len(bs))
with open(f, "wb") as ff:
ff.write(bs)

target = os.path.basename(targetdir)
os.chdir(os.path.dirname(targetdir))
if os.path.exists(rf"{target}.zip"):
os.remove(rf"{target}.zip")
if os.path.exists(rf"{target}.7z"):
os.remove(rf"{target}.7z")
os.system(rf'"C:\Program Files\7-Zip\7z.exe" a -m0=Deflate -mx9 {target}.zip {target}')
if 0:
os.system(rf'"C:\Program Files\7-Zip\7z.exe" a -m0=LZMA2 -mx9 {target}.7z {target}')
with open(r"C:\Program Files\7-Zip\7z.sfx", "rb") as ff:
sfx = ff.read()

config = """
;!@Install@!UTF-8!
;!@InstallEnd@!
"""
with open(rf"{target}.7z", "rb") as ff:
data = ff.read()

with open(rf"{target}.exe", "wb") as ff:
ff.write(sfx)
ff.write(config.encode("utf8"))
ff.write(data)
Loading

0 comments on commit 619c5f8

Please sign in to comment.