This repository was archived by the owner on Mar 26, 2023. It is now read-only.
forked from cdbbnnyCode/modpack-installer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclean.py
More file actions
43 lines (34 loc) · 1.18 KB
/
clean.py
File metadata and controls
43 lines (34 loc) · 1.18 KB
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
import os
import shutil
def make_global(dir, gdir):
if not os.path.exists(gdir):
os.mkdir(gdir)
if not os.path.islink(dir):
print("Converting %s to a global directory" % dir)
if os.path.isdir(dir):
shutil.rmtree(dir) # safe for downloaded things, but not for user created content
elif os.path.exists(dir):
os.remove(dir)
os.symlink(os.path.abspath(gdir), dir, True)
return True
return False
def main():
print("Modpack Maintenance v1.0.0")
mods = set()
moved = 0
deleted = 0
for packdirn in os.listdir('packs/'):
packdir = 'packs/' + packdirn
upd = make_global(packdir + '/.minecraft/assets', 'global/assets')
moved += upd
for mod in os.listdir(packdir + '/.minecraft/mods'):
mods.add(mod)
for mod in os.listdir('.modcache'):
if mod not in mods:
print("cleaning up %s" % mod)
deleted += os.stat('.modcache/' + mod).st_size
os.remove('.modcache/' + mod)
print("Done! Deleted %.3f MiB of mods and migrated %d data folders" % \
(deleted / 1048576, moved))
if __name__ == "__main__":
main()