Skip to content

Commit

Permalink
Add option to delete a file/folder before extracting an option
Browse files Browse the repository at this point in the history
 - Needed for implementing 07th-mod/higurashi-rei#14 as an option, while not overwriting every existing OG sprite
  • Loading branch information
drojf committed Jul 30, 2023
1 parent 48a81de commit 161a8b8
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 2 deletions.
2 changes: 2 additions & 0 deletions JSONValidator/Sources/JSONValidator/JSONValidator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,6 @@ public struct ModOptionFileDefinition: Codable {
public var relativeExtractionPath: String?
/// The priority of this file (same system as above priorities)
public var priority: Int
/// A file or folder path relative to the *top-level game directory*, to be deleted before extraction
public var deletePath: String?
}
19 changes: 19 additions & 0 deletions common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1551,3 +1551,22 @@ def crc32_of_file(file_path):
fb = f.read(BLOCK_SIZE)

return "{:08x}".format(hash & 0xffffffff)

def applyDeletions(installPath, optionParser):
#type: (str, installConfiguration.ModOptionParser) -> None
for opt in optionParser.downloadAndExtractOptionsByPriority:
if opt.deletePath is not None:
# Do not allow paths with '..' to avoid deleting stuff outside the install path
if '..' in opt.deletePath.replace('\\', '/').split('/'):
raise Exception("Developer Error: You are not allowed to use '..' for deletePath")

fullDeletePath = os.path.join(installPath, opt.deletePath)

try:
print("applyDeletions(): Attempting to delete path {} due to option {}...".format(fullDeletePath, opt.name))
if os.path.isdir(fullDeletePath):
shutil.rmtree(fullDeletePath)
else:
os.remove(fullDeletePath)
except Exception as e:
print("applyDeletions(): Failed to delete path: {}".format(e))
4 changes: 4 additions & 0 deletions higurashiInstaller.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,8 @@ def main(fullInstallConfiguration):
if not isVoiceOnly:
installer.backupFiles()
installer.cleanOld()
# If any mod options request deletion of a folder, do it before the extraction
common.applyDeletions(fullInstallConfiguration.installPath, modOptionParser)
print("Extracting...")
installer.extractFiles()
commandLineParser.printSeventhModStatusUpdate(97, "Cleaning up...")
Expand All @@ -544,6 +546,8 @@ def main(fullInstallConfiguration):
if not isVoiceOnly:
installer.backupFiles()
installer.cleanOld()
# If any mod options request deletion of a folder, do it before the extraction
common.applyDeletions(fullInstallConfiguration.installPath, modOptionParser)
installer.moveFilesIntoPlace()
commandLineParser.printSeventhModStatusUpdate(97, "Cleaning up...")
installer.removeResourcesAssetsBackup()
Expand Down
6 changes: 4 additions & 2 deletions installConfiguration.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,13 +255,14 @@ def __repr__(self):


class DownloadAndExtractOption:
def __init__(self, name, description, url, relativeExtractionPath, priority, group):
def __init__(self, name, description, url, relativeExtractionPath, priority, group, deletePath):
self.name = name # type: str
self.description = description # type: str
self.url = url # type: str
self.relativeExtractionPath = relativeExtractionPath # type: str
self.priority = priority # type: int
self.group = group # type: str
self.deletePath = deletePath # type: str


class ModOptionParser:
Expand All @@ -286,7 +287,8 @@ def __init__(self, fullInstallConfiguration):
modOption.data['url'],
modOption.data['relativeExtractionPath'],
modOption.data['priority'],
modOption.group
modOption.group,
modOption.data.get('deletePath')
)
)
elif modOption.type == 'keepDownloads':
Expand Down
3 changes: 3 additions & 0 deletions uminekoInstaller.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ def remapPaths(originalFolder, originalFilename):
else:
return originalFolder, originalFilename

# If any mod options request deletion of a folder, do it before the extraction
common.applyDeletions(conf.installPath, optionParser)

downloaderAndExtractor.extract(remapPaths)

############################################# FIX .ARC FILE NAMING #################################################
Expand Down
3 changes: 3 additions & 0 deletions uminekoNScripterInstaller.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ def main(conf):

downloaderAndExtractor.download()

# If any mod options request deletion of a folder, do it before the extraction
common.applyDeletions(conf.installPath, parser)

# Extract files
fileVersionManager.saveVersionInstallStarted()
downloaderAndExtractor.extract()
Expand Down

0 comments on commit 161a8b8

Please sign in to comment.