-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSyatiManager.py
656 lines (631 loc) · 29.6 KB
/
SyatiManager.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
import os
import sys
import subprocess
from urllib import request
from urllib.parse import urlparse
import json
import tarfile
import zipfile
import shutil
from pathlib import Path
class ModuleInfo:
def __init__(self, items: dict[str] = {}):
self.Name = str()
self.Author = str()
self.Description = str()
self.InstallDependencies = list[str]()
self.BuildTasks = list[str]()
self.ObjectDatabaseEntries = list()
self.ModuleType = ""
self.FolderPath = ""
class InstallableModule:
def __init__(self, items: dict[str] = {}):
self.FolderName = str()
self.Name = str()
self.Author = str()
self.Description = str()
self.InstallType = str()
self.InstallUrl = str()
self.GitRepo = str()
self.GitPath = str()
self.ModuleType = ""
moduleData = list[ModuleInfo]()
installableModules = list[InstallableModule]()
useLocalData = False
def wingetInstall (packageName :str, displayName :str):
if sys.platform == "win32":
print(f"{displayName} was not found. Would you like to download it now?")
prompt = input("[Y/N] ")
if (prompt.lower() == "y" & subprocess.run(["winget", "install", f"{packageName}.{packageName}"]).returncode != 1):
print(f"Error while installing {displayName}.")
exit(1)
else:
exit(1)
else:
print(f"{displayName} was not found. Please download it using your standard package manager.")
exit(1)
def copyFilesRecursive (srcPath :str, destPath :str):
for member in os.listdir(srcPath):
if (os.path.isdir(f"{srcPath}{member}")):
if not os.path.isdir(f"{destPath}{member}/"):
os.makedirs(f"{destPath}{member}/")
copyFilesRecursive(f"{srcPath}{member}/", f"{destPath}{member}/")
else:
shutil.copy(f"{srcPath}{member}", f"{destPath}{member}")
def addFilesToArc (arc, dirName :str, pathInArc :str):
for file in os.listdir(dirName):
print(file)
if (os.path.isdir(f"{dirName}/{file}")):
print("Is dir")
arc.create_folder(f"{pathInArc}/{file}")
addFilesToArc(arc, f"{dirName}/{file}", f"{pathInArc}/{file}")
else:
with open(f"{dirName}/{file}", "rb") as f:
arc.create_file(f"{pathInArc}/" + os.path.basename(file), bytearray(f.read()))
def runBuildTask (buildTask :dict, srcPath :str):
if (buildTask["Task"] == "Copy"):
if not os.path.isdir(f"{srcPath}/{buildTask['To']}"):
os.makedirs(f"{srcPath}/{buildTask['To']}")
copyFilesRecursive(f"{srcPath}/{buildTask['From']}", f"{srcPath}/{buildTask['To']}")
elif (buildTask["Task"] == "Command"):
if (sys.platform == "win32" and subprocess.run(buildTask["win32"]).returncode):
print("Error while running build task.")
return False
elif (subprocess.run(buildTask["linux"]).returncode):
print("Error while running build task.")
return False
elif (buildTask["Task"] == "BuildLoader"):
if (not buildLoaderScript(buildTask["Regions"], buildTask["FullLoader"], f"{srcPath}/{buildTask['OutputPath']}")):
return False
elif ("Arc" in buildTask["Task"] or "Bcsv" in buildTask["Task"]):
try:
import pyjkernel # RARC
import pyjmap # BCSV
except Exception as e:
print(e)
print("Fatal: Please install the missing package using pip.")
return False
if (buildTask["Task"] == "Arc_Append"):
arcPath = input(f"Please provide '{buildTask['RequestArc']}' from your game dump: ")
arc = pyjkernel.from_archive_file(arcPath)
addFilesToArc(arc, buildTask["AppendFilePath"], arc._root_._name_)
pyjkernel.write_archive_file(arc, arcPath, big_endian=True)
else:
arcPath = input(f"Please provide '{buildTask['RequestArc']}' from your game dump: ")
arc = pyjkernel.from_archive_file(arcPath)
hashtable = pyjmap.SuperMarioGalaxyHashTable()
bcsvBuffer = arc.get_file(buildTask["FromBcsv"]).data
if (not bcsvBuffer):
info = pyjmap.JMapInfo(hashtable) # Not sure if this works
info = pyjmap.from_buffer(hashtable, bcsvBuffer, offset=0, big_endian=True)
if (buildTask["Task"] == "Bcsv_Write"):
info.clear_entries()
for row in buildTask["AppendRows"]:
info.create_entry()
for key in row:
info[-1][key] = row[key]
arc._lookup_files_[buildTask["FromBcsv"].lower()].data = info.makebin(True, "shift_jisx0213")
pyjkernel.write_archive_file(arc, arcPath, big_endian=True)
else:
print(f"Unknown task type {buildTask['Task']}.")
return False
return True
def buildScript (regionList :list = list(), buildTasks :list = list(), outputPath :str = "Syati/Output", unibuild :bool = False):
global moduleData
if (not os.path.isdir(outputPath)):
os.makedirs(outputPath)
if (not regionList):
print("Which region? Press Enter to build all regions.")
match (input("[J] = JPN, [U] = USA, [P] = PAL, [K] = KOR, [T] = TWN: ").lower()):
case "j":
regionList = ["JPN"]
case "u":
regionList = ["USA"]
case "p":
regionList = ["PAL"]
case "k":
regionList = ["KOR"]
case "t":
regionList = ["TWN"]
case _:
regionList = ["JPN", "USA", "PAL", "KOR", "TWN"]
for region in regionList:
print(f"Building target {region}...")
if (subprocess.run(["./Syati/SyatiModuleBuildTool", region, "Syati/Syati/", "Syati/Modules/", outputPath, "-u" if unibuild else ""]).returncode):
print(f"Failed building target {region}. Abort.")
return False
objectdbPath = ""
for module in moduleData:
if (module.ModuleType != "enabled"):
break
print(f"Running build tasks for {module.Name}...")
for buildTask in module.BuildTasks + buildTasks:
if (not runBuildTask(buildTask, module.FolderPath)):
return False
for objectdbEntry in module.ObjectDatabaseEntries:
if (not objectdbPath):
objectdbPath = input("Please specify the path to Whitehole's objectdb.json: ")
with open(objectdbPath, "r") as f:
objectdbData = json.load(f)
objectdbData.append(objectdbEntry)
with open(objectdbPath, "w") as f:
json.dump(objectdbData, f)
print("\nBuilt successfully!")
if os.path.isdir(f"{outputPath}/disc"):
print("Note: Make sure to copy the disc/ folder into your game dump, otherwise the built modules may not work correctly.")
return True
def buildLoaderScript (regionList :list = list(), makeFullXML :bool = None, outputPath :str = "../Output"):
os.chdir("Syati/Syati")
if (not os.path.isdir(outputPath)):
os.makedirs(outputPath)
if (makeFullXML == None):
print("Full [F] or Partial [P] XML?")
if (input("If you do not use a Riivolution XML yet, choose Full. ").lower() == "f"):
makeFullXML = True
if (not regionList):
print("Which region? Press Enter to build all regions.")
match (input("[J] = JPN, [U] = USA, [P] = PAL, [K] = KOR, [T] = TWN: ").lower()):
case "j":
regionList = ["JPN"]
case "u":
regionList = ["USA"]
case "p":
regionList = ["PAL"]
case "k":
regionList = ["KOR"]
case "t":
regionList = ["TWN"]
case _:
regionList = ["JPN", "USA", "PAL", "KOR", "TWN"]
for region in regionList:
if (subprocess.run(f"python buildloader.py {region} -o {outputPath} {'--full-xml' if makeFullXML else ''}").returncode):
print("\nError while building the loader. Abort.")
os.chdir("../..")
return False
os.chdir("../..")
print("\nBuilt the loader successfully!")
return True
def installModule (module :InstallableModule, installAllDeps :bool = False):
global moduleData
match (module.InstallType):
case "git" | "git_recursive":
if (subprocess.run(["git"], stdout=open(os.devnull, "wb")).returncode != 1):
if (not wingetInstall("git", "Git")):
return False
print(f"Cloning module {module.Name}...")
if (subprocess.run(["git", "-C", "Syati/Modules", "clone", module.InstallUrl + (" --recursive" if module.InstallType == "git_recursive" else "")], stderr=open(os.devnull, "wb")).returncode):
print(f"Cloning module {module.Name} failed. Abort.")
return False
case "lginc_module":
print(f"Downloading module {module.Name}...")
with request.urlopen(f"https://mariogalaxy.org/syati-modules?module={module.InstallUrl}") as req:
moduleTar = req.read()
with open("Syati/Modules/" + module.InstallUrl + ".tar.gz", "wb") as f:
f.write(moduleTar)
os.chdir("Syati/Modules/")
with tarfile.open(module.InstallUrl + ".tar.gz") as f:
f.extractall(".")
os.chdir("../..")
os.remove("Syati/Modules/" + module.InstallUrl + ".tar.gz")
case "url_tar":
print(f"Downloading module {module.Name}...")
pathToModuleTar = "Syati/Modules/" + os.path.basename(module.InstallUrl)
with request.urlopen(module.InstallUrl) as req:
moduleTar = req.read()
with open(pathToModuleTar, "wb") as f:
f.write(moduleTar)
with tarfile.open(pathToModuleTar) as f:
f.extractall(".")
os.remove(pathToModuleTar)
case "url_zip":
print(f"Downloading module {module.Name}...")
pathToModuleZip = "Syati/Modules/" + os.path.basename(module.InstallUrl)
with request.urlopen(module.InstallUrl) as req:
moduleTar = req.read()
with open(pathToModuleZip, "wb") as f:
f.write(moduleTar)
with zipfile.ZipFile(pathToModuleZip) as f:
f.extractall(".")
os.remove(pathToModuleZip)
with open(f"Syati/Modules/{module.FolderName}/ModuleInfo.json", "r") as f:
infoJson = json.load(f)
moduleInfo = createModuleInfoFromJson(infoJson)
moduleInfo.ModuleType = "enabled"
moduleInfo.FolderPath = "Syati/Modules/" + module.FolderName
moduleData.append(moduleInfo)
if (not checkDependencies(moduleInfo, installAllDeps)):
shutil.move(moduleInfo.FolderPath, "Syati/DisabledModules/")
moduleInfo.FolderPath.replace("/Modules/", "/DisabledModules/")
moduleInfo.ModuleType = "disabled"
print("Abort.")
return "disabled"
print("Done.")
return True
def getModuleFromFolderPath (moduleFolderPath :str):
global moduleData
for module in moduleData:
if (module.ModuleType == "available"):
continue
if (module.FolderPath == moduleFolderPath):
return module
return False
def getInstallableModuleFromFolderName (moduleFolderName :str):
global moduleData
for module in moduleData:
if (module.ModuleType != "available"):
continue
if (module.FolderName == moduleFolderName):
return module
return False
def checkDependencies (module :ModuleInfo, installAll :bool = False):
for dependency in module.InstallDependencies:
dependencyData = getModuleFromFolderPath("Syati/DisabledModules/" + dependency)
if (dependencyData and not os.path.isdir("Syati/Modules/" + dependency)):
if (not installAll):
print(f"This module requires the disabled module {dependencyData.Name}. Enable it now?")
if (input("[Y/N] ").lower() == "y"):
if (not checkDependencies(dependencyData)):
print("Abort.")
return False
else:
print("Abort.")
return False
shutil.move(dependencyData.FolderPath, "Syati/Modules/")
dependencyData.FolderPath.replace("/DisabledModules/", "/Modules/")
dependencyData.ModuleType = "enabled"
elif (not os.path.isdir("Syati/Modules/" + dependency)):
dependencyData = getModuleFromFolderPath("Syati/Modules/" + dependency)
if (not dependencyData):
dependencyData = getInstallableModuleFromFolderName(dependency)
if (not dependencyData):
print(f"Fatal error: Module {dependency} is required but was not found.")
return False
if (not installAll):
print(f"This module requires the installable module {dependency}. Download it now?")
if (input("[Y/N] ").lower() == "n"):
return False
installModule(dependencyData)
return True
def newModule ():
os.system("cls" if sys.platform == "win32" else "clear")
print("--- New Module ---")
print("This will use the SyatiModuleTemplate to create a new blank module for you to use.\nPlease fill out the form and press Enter after every question.\n")
newModuleData = dict()
newModuleData["Name"] = input("Name: ")
newModuleData["Author"] = input("Author(s): ")
newModuleData["Description"] = input("Description: ")
print("\nAre these details ok?")
if (input("[Y/N] ").lower() == "n"):
return False
else:
newFolderName = newModuleData["Name"].replace(" ", "")
shutil.copytree("Syati/SyatiModuleTemplate", "Syati/Modules/" + newFolderName)
subprocess.run(["rm", "-rf", f"Syati/Modules/{newFolderName}/.git"])
os.remove(f"Syati/Modules/{newFolderName}/.gitattributes")
os.remove(f"Syati/Modules/{newFolderName}/.gitignore")
os.remove(f"Syati/Modules/{newFolderName}/include/.gitkeep")
os.remove(f"Syati/Modules/{newFolderName}/source/.gitkeep")
with open(f"Syati/Modules/{newFolderName}/ModuleInfo.json", "w") as f:
json.dump(newModuleData, f)
os.system("cls" if sys.platform == "win32" else "clear")
def showModuleDetails (moduleId :int):
global moduleData
os.system("cls" if sys.platform == "win32" else "clear")
if (moduleData[moduleId].ModuleType == "enabled"):
print("\033[32mEnabled\033[0m")
print(f"Name: {moduleData[moduleId].Name}")
print(f"Author: {moduleData[moduleId].Author}")
print(f"Description: {moduleData[moduleId].Description}")
match (input("[0] = Disable, [X] = Remove, [C] = Cancel: ").lower()):
case "0":
os.system("cls" if sys.platform == "win32" else "clear")
print(f"Disabling module {moduleData[moduleId].Name}...")
shutil.move(moduleData[moduleId].FolderPath, "Syati/DisabledModules/")
moduleData[moduleId].FolderPath.replace("/Modules/", "/DisabledModules/")
moduleData[moduleId].ModuleType = "disabled"
print("Done.")
case "x":
print("Are you sure you want to remove this module?")
if (input("[Y/N] ").lower() == "y"):
os.system("cls" if sys.platform == "win32" else "clear")
print(f"Deleting module {moduleData[moduleId].Name}...")
subprocess.call(f"rm -rf \"{moduleData[moduleId].FolderPath}\"")
del moduleData[moduleId]
print("Done.")
elif (moduleData[moduleId].ModuleType == "disabled"):
print("\033[91mDisabled\033[0m")
print(f"Name: {moduleData[moduleId].Name}")
print(f"Author: {moduleData[moduleId].Author}")
print(f"Description: {moduleData[moduleId].Description}")
match (input("[1] = Enable, [X] = Remove, [C] = Cancel: ").lower()):
case "1":
os.system("cls" if sys.platform == "win32" else "clear")
print(f"Enabling module {moduleData[moduleId].Name}...")
if (not checkDependencies(moduleData[moduleId])):
print("Abort.")
return
shutil.move(moduleData[moduleId].FolderPath, "Syati/Modules/")
moduleData[moduleId].FolderPath.replace("/DisabledModules/", "/Modules/")
moduleData[moduleId].ModuleType = "enabled"
print("Done.")
case "x":
print("Are you sure you want to remove this module?")
if (input("[Y/N] ").lower() == "y"):
os.system("cls" if sys.platform == "win32" else "clear")
print(f"Deleting module {moduleData[moduleId].Name}...")
subprocess.call(f"rm -rf \"{moduleData[moduleId].FolderPath}\"")
del moduleData[moduleId]
print("Done.")
else:
print("\033[94mNot installed\033[0m")
print(f"Name: {moduleData[moduleId].Name}")
print(f"Author: {moduleData[moduleId].Author}")
print(f"Description: {moduleData[moduleId].Description}")
print(f"InstallType: {moduleData[moduleId].InstallType}")
match (input("[I] = Install, [C] = Cancel: ").lower()):
case "i":
os.system("cls" if sys.platform == "win32" else "clear")
installModule(moduleData[moduleId])
def createModuleInfoFromJson (moduleJson :object):
moduleInfo = ModuleInfo()
moduleInfo.Name = moduleJson.get("Name")
moduleInfo.Author = moduleJson.get("Author")
moduleInfo.Description = moduleJson.get("Description")
moduleInfo.InstallDependencies = moduleJson.get("InstallDependencies", list())
moduleInfo.BuildTasks = moduleJson.get("BuildTasks", list())
moduleInfo.ObjectDatabaseEntries = moduleJson.get("ObjectDatabaseEntries", list())
return moduleInfo
def createInstallableModuleFromJson (moduleJson :object):
moduleInfo = InstallableModule()
moduleInfo.Name = moduleJson.get("Name")
moduleInfo.Author = moduleJson.get("Author")
moduleInfo.Description = moduleJson.get("Description")
moduleInfo.InstallType = moduleJson.get("InstallType")
moduleInfo.InstallUrl = moduleJson.get("InstallUrl")
moduleInfo.GitRepo = moduleJson.get("GitRepo")
moduleInfo.GitPath = moduleJson.get("GitPath")
moduleInfo.FolderName = moduleJson.get("FolderName")
return moduleInfo
def checkIfModuleIsInstalled (moduleName :str):
global moduleData
for module in moduleData:
if module.ModuleType == "available":
return False
if module.Name == moduleName:
return True
return False
def initModules (printOutInfo :bool = True, includeDuplicates :bool = False):
global moduleData
global installableModules
moduleData = list()
totalModuleAmount = 0
if (printOutInfo):
print("--- Enabled Modules: ---")
enabledModuleAmount = 0
for module in os.listdir("Syati/Modules"):
if module[0] == ".": # ignore modules with a . in front of them
continue
with open("Syati/Modules/" + module + "/ModuleInfo.json", "r") as infoJson:
moduleJson = json.load(infoJson)
moduleInfo = createModuleInfoFromJson(moduleJson)
moduleInfo.ModuleType = "enabled"
moduleInfo.FolderPath = "Syati/Modules/" + module
moduleData.append(moduleInfo)
if (printOutInfo):
print(f"#{totalModuleAmount}: {moduleInfo.Name}")
totalModuleAmount += 1
enabledModuleAmount += 1
if (not enabledModuleAmount and printOutInfo):
print("No enabled modules.")
if (printOutInfo):
print("\n--- Disabled Modules: ---")
disabledModuleAmount = 0
for module in os.listdir("Syati/DisabledModules"):
if "." in module:
continue
with open("Syati/DisabledModules/" + module + "/ModuleInfo.json", "r") as infoJson:
moduleJson = json.load(infoJson)
moduleInfo = createModuleInfoFromJson(moduleJson)
moduleInfo.ModuleType = "disabled"
moduleInfo.FolderPath = "Syati/DisabledModules/" + module
moduleData.append(moduleInfo)
if (printOutInfo):
print(f"#{totalModuleAmount}: {moduleInfo.Name}")
totalModuleAmount += 1
disabledModuleAmount += 1
if (not disabledModuleAmount and printOutInfo):
print("No disabled modules.")
if (printOutInfo):
print("\n--- Available Modules: ---")
installableModuleAmount = 0
for module in installableModules:
if (not includeDuplicates and checkIfModuleIsInstalled(module.get("Name"))):
continue
moduleInfo = InstallableModule()
moduleInfo.Name = module.get("Name")
moduleInfo.Author = module.get("Author")
moduleInfo.Description = module.get("Description")
moduleInfo.InstallType = module.get("InstallType")
moduleInfo.InstallUrl = module.get("InstallUrl")
moduleInfo.GitRepo = module.get("GitRepo")
moduleInfo.GitPath = module.get("GitPath")
moduleInfo.FolderName = module.get("FolderName")
moduleInfo.ModuleType = "available"
moduleData.append(moduleInfo)
if (printOutInfo):
print(f"#{totalModuleAmount}: {moduleInfo.Name}")
totalModuleAmount += 1
installableModuleAmount += 1
if (not installableModuleAmount and printOutInfo):
print("No available modules.")
def moduleManager ():
while True:
initModules()
print("\n[0] - View Details for Module #0")
print("[0,1,2] - Enable Modules #0, #1, #2")
print("[N] - Create New Module")
print("[C] - Cancel")
actionStr = input().lower()
if (actionStr == "c"):
return
elif (actionStr == "n"):
newModule()
elif (not actionStr.count(",")):
showModuleDetails(int(actionStr))
else:
for currentModule in actionStr.split(","):
currentModule = int(currentModule)
if (moduleData[currentModule].ModuleType == "available"):
installModule(moduleData[currentModule])
continue
elif (moduleData[currentModule].ModuleType == "enabled"):
continue
if (not checkDependencies(moduleData[currentModule])):
print("Abort.")
return
shutil.move(moduleData[currentModule].FolderPath, "Syati/Modules/")
moduleData[currentModule].FolderPath.replace("/DisabledModules/", "/Modules/")
moduleData[currentModule].ModuleType = "enabled"
def getInstallableModuleFromModuleName (moduleName :str):
global installableModules
for installableModule in installableModules:
if (installableModule["Name"] == moduleName):
return installableModule
return False
def updateModules ():
global moduleData
os.system("cls" if sys.platform == "win32" else "clear")
print("Updating all modules...")
for module in moduleData:
if module.ModuleType == "available":
print("\nDone.")
return
print(f"{module.Name}: ", end="\n\t")
if not os.path.isdir(f"{module.FolderPath}/.git"):
installableModule = getInstallableModuleFromModuleName(module.Name)
if (not installableModule):
print("Warning: Could not find an install method for module. Skipping update...")
continue
if (installableModule["InstallType"] == "url_tar"):
print("Redownloading module...")
pathToModuleTar = f"{module.FolderPath}/../{os.path.basename(module.InstallUrl)}"
with request.urlopen(module.InstallUrl) as req:
moduleTar = req.read()
with open(pathToModuleTar, "wb") as f:
f.write(moduleTar)
subprocess.run(["rm", "-rf", module.FolderPath])
with tarfile.open(pathToModuleTar) as f:
f.extractall(".")
os.remove(pathToModuleTar)
print("\tSuccess.")
elif (installableModule["InstallType"] == "url_zip"):
print("Redownloading module...")
pathToModuleTar = f"{module.FolderPath}/../{os.path.basename(module.InstallUrl)}"
with request.urlopen(module.InstallUrl) as req:
moduleTar = req.read()
with open(pathToModuleTar, "wb") as f:
f.write(moduleTar)
subprocess.run(["rm", "-rf", module.FolderPath])
with zipfile.ZipFile.open(pathToModuleTar) as f:
f.extractall(".")
os.remove(pathToModuleTar)
print("\tSuccess.")
elif (installableModule["InstallType"] == "lginc_module"):
print("Redownloading module...")
with request.urlopen(f"https://mariogalaxy.org/syati-modules?module={installableModule['InstallUrl']}") as req:
moduleTar = req.read()
pathToModuleTar = f"{module.FolderPath}/../{installableModule['InstallUrl']}"
with open(pathToModuleTar + ".tar.gz", "wb") as f:
f.write(moduleTar)
subprocess.run(["rm", "-rf", module.FolderPath])
with tarfile.open(pathToModuleTar + ".tar.gz") as f:
f.extractall(module.FolderPath + "/../")
os.remove(pathToModuleTar + ".tar.gz")
print("\tSuccess.")
else:
print("\tWarning: Could not find an install method for module. Skipping update...")
else:
if (subprocess.run(["git", "-C", module.FolderPath, "pull"]).returncode):
print(f"Error while updating {module.Name}. Skipping update...")
print("Syati Manager v2.0\nby Bavario\n-----------------")
if not os.path.isdir("Syati/"):
print("No instance of Syati was found. Please run SyatiSetup.py.")
exit(1)
print("Getting newest database...")
try:
argc = 0
for argument in sys.argv:
if argument == "--use-local":
del sys.argv[argc]
raise Exception
argc += 1
with request.urlopen("https://github.com/SMGCommunity/SyatiManager/raw/main/installable_modules.json") as req:
installableJson = req.read()
installableModules = json.loads(installableJson)
except:
print("Using local module list. New modules may not be available.")
installableModules = json.load(open("installable_modules.json", "r"))
if (len(sys.argv) > 1):
outputPath = f"Syati/Output/{os.path.splitext(os.path.basename(sys.argv[1]))[0]}"
for module in os.listdir("Syati/Modules"):
if (os.path.isdir(f"Syati/DisabledModules/{module}")):
subprocess.run(["rm", "-rf", f"Syati/DisabledModules/{module}"])
shutil.move(f"Syati/Modules/{module}", f"Syati/DisabledModules/{module}")
print(f"Building solution {os.path.basename(outputPath)}...")
initModules(False, True)
with open(sys.argv[1], "r") as f:
solutionData = json.load(f)
installAll = (True if "InstallAll" in solutionData and solutionData["InstallAll"] else False)
for module in solutionData["Modules"]:
if (installAll or not os.path.isdir(f"Syati/DisabledModules/{module}")):
installableModule = getInstallableModuleFromFolderName(module)
if (not installableModule):
print(f"Fatal: No way to install module {module} was found.")
exit(1)
if (installModule(installableModule, True) == "disabled"):
print(f"Solution {os.path.basename(outputPath)} cannot be built.")
elif (os.path.isdir(f"Syati/DisabledModules/{module}")):
print(f"Enabling module {module}...")
shutil.move(f"Syati/DisabledModules/{module}", f"Syati/Modules/{module}")
initModules(False)
if ("LocalModules" not in solutionData):
solutionData["LocalModules"] = []
for localModule in solutionData["LocalModules"]:
print(f"Copying local module {os.path.basename(localModule)}...")
shutil.copytree(f"{os.path.dirname(sys.argv[1])}/{localModule}", f"Syati/Modules/{os.path.basename(localModule)}")
print("\nAll required modules enabled. Building...")
if ("OutputPath" not in solutionData):
solutionData["OutputPath"] = "Syati/Output"
else:
path = Path(sys.argv[1])
solutionData["OutputPath"] = (str(path.parent) if path.is_file() else str(path)) + "/" + solutionData["OutputPath"]
if ("BuildTasks" not in solutionData):
solutionData["BuildTasks"] = list()
if ("Unibuild" not in solutionData):
solutionData["Unibuild"] = False
else:
print("Using unibuild.")
if (not buildScript(solutionData["Regions"], solutionData["BuildTasks"], solutionData["OutputPath"], solutionData["Unibuild"])):
print(f"Solution {os.path.basename(outputPath)} cannot be built.")
exit(1)
print(f"Solution {os.path.basename(outputPath)} built successfully!")
exit(0)
while True:
print("Would you like to build [B], compile the loader [L], manage modules [M], update modules [U] or quit [Q]?")
match (input().lower()):
case "b":
initModules(False)
buildScript()
continue
case "l":
buildLoaderScript()
continue
case "m":
os.system("cls" if sys.platform == "win32" else "clear")
moduleManager()
continue
case "u":
initModules(False)
updateModules()
case "q":
exit(0)