forked from CLF78/HideNSeek
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildrelease.py
92 lines (74 loc) · 2.21 KB
/
buildrelease.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# Global imports
import os
import shutil
from subprocess import run
# Local imports
from files.UIPatches.buildui import main as buildui
from src.make import main as buildsrc
"""
HOW TO USE
- Make sure wszst and 7z are installed
- Read the notes for every other script (if present)
- Run this script
"""
root = os.path.join('..', '..')
riivoroot = os.path.join('build', 'Riivo', 'hns')
isoroot = os.path.join('build', 'ISO', 'hns')
# Ignore any file except those with the given extension
def fileFilter(d, ext):
return [os.path.join(d, entry.name) for entry in os.scandir(d) if entry.is_file() and entry.name.endswith('.' + ext)]
# Build caller
def callBuildScript(fileSrc, destRiivo, destIso, buildFunc, fileExt, isSrc=False):
# Cwd to the script's folder and call function
os.chdir(fileSrc)
if buildFunc:
buildFunc()
# A bunch of hardcodes
if isSrc:
os.chdir('..')
filelist = fileFilter(os.path.join(fileSrc, 'bin'), fileExt)
else:
os.chdir(root)
filelist = fileFilter(fileSrc, fileExt)
# Make destination folders if necessary
os.makedirs(destRiivo, exist_ok=True)
os.makedirs(destIso, exist_ok=True)
# Copy files to Riivo folder and move them to ISO folder
for file in filelist:
shutil.copy(file, destRiivo)
shutil.move(file, destIso)
def main():
# Clean build folders
if os.path.isdir(isoroot):
shutil.rmtree(isoroot)
if os.path.isdir(riivoroot):
shutil.rmtree(riivoroot)
# Build ui patches
callBuildScript(os.path.join('files', 'UIPatches'),
os.path.join(riivoroot, 'UI'),
isoroot,
buildui,
'szs')
# Build code
callBuildScript('src',
os.path.join(riivoroot, 'hns'),
os.path.join(isoroot, 'code'),
buildsrc,
'bin',
True)
# Move the loader back
shutil.move(os.path.join(riivoroot, 'hns', 'Loader.bin'), riivoroot)
shutil.move(os.path.join(isoroot, 'code', 'Loader.bin'), isoroot)
# Add My Stuff folder to Riivo
os.mkdir(os.path.join(riivoroot, 'My Stuff'))
# Create zips
arcname = 'HNS'
isoname = f'{arcname} ISO Patcher.zip'
isoname2 = isoname.replace(' ', '_')
run(['7z', 'a', '-mx=9', f'{arcname}.zip', './build/Riivo/*'])
run(['7z', 'a', '-mx=9', isoname2, './build/ISO/*'])
os.rename(isoname2, isoname)
# All done!
print('Built all!')
if __name__ == '__main__':
main()