Last active
October 13, 2023 14:54
-
-
Save juancarlospaco/a8cde1d7f798129c10a61f5f0f59ac48 to your computer and use it in GitHub Desktop.
Unreal Engine 5 project folder Minify/Anonymizer/Cleaner in Nim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import std/[os, strutils, json, sequtils] | |
proc main(cwd: string) = | |
if dirExists(cwd / "Content"): | |
# Minify uproject to valid minimal. | |
for f in walkPattern(cwd / "*.uproject"): | |
let uproject = parseFile(f) | |
if uproject.contains"Category": uproject.delete"Category" | |
if uproject.contains"Description": uproject.delete"Description" | |
if uproject.contains"EngineAssociation": uproject.delete"EngineAssociation" | |
writeFile(f, $uproject) | |
echo "Minified\t", f | |
break | |
# Delete all caches. | |
for folder in walkDirRec(cwd, yieldFilter = {pcDir}, relative=off, checkDir=off, skipSpecial=off): | |
for f in ["DerivedDataCache", "Intermediate", "Binaries", "Build", "Saved", "Content" / "Collections", "Content" / "Developers"]: | |
if folder == cwd / f: | |
echo "Deleted\t", folder | |
removeDir(folder) | |
if dirExists(cwd / "Config"): | |
for f in walkPattern(cwd / "Config" / "*.ini"): | |
# Delete editor-specific local-only settings. | |
if extractFilename(f) in ["DefaultEditorPerProjectUserSettings.ini", "DefaultGamePerProjectUserSettings.ini"]: | |
if tryRemoveFile(f): echo "Deleted\t", f | |
else: | |
# Minify INI to valid minimal. | |
writeFile(f, readFile(f).strip.splitLines.filterIt(it.strip.len > 0).join("\n")) | |
echo "Minified\t", f | |
else: quit "IO Error: Unreal Engine project folder not found or not writable." | |
when isMainModule: | |
doAssert paramCount() == 1, "Full path to Unreal Engine project folder must be the only argument" | |
main(paramStr(1)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment