Skip to content

Commit 0f4bd1d

Browse files
Merge pull request #9 from famous1622/v0.2.1
v0.2.1
2 parents 7e27751 + 13ee224 commit 0f4bd1d

File tree

2 files changed

+37
-13
lines changed

2 files changed

+37
-13
lines changed

app.py

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
VERSION_URL="https://raw.githubusercontent.com/famous1622/fDDMEPlayer/master/version"
2828
PATTERNS = ("options.rpyc","*.rpa","options.rpy")
2929

30+
31+
class InvalidModError(Exception):
32+
pass
33+
3034
def saveConfig():
3135
with open("config.ini", 'w') as configfile:
3236
config.write(configfile)
@@ -129,24 +133,44 @@ def addmod():
129133
addmodgui.go()
130134
return "<meta http-equiv=\"refresh\" content=\"1; url=http://localhost:5000/\">Please wait..."
131135

136+
def installZipMod(file,slug):
137+
with ZipFile(file) as modzip:
138+
with tempfile.TemporaryDirectory() as tmpdirname:
139+
modzip.extractall(tmpdirname)
140+
modGameDir=findParent(PATTERNS,tmpdirname)
141+
if modGameDir is None:
142+
print("That isn't a mod")
143+
logging.error("Not a mod :shrugika:")
144+
raise InvalidModError
145+
else:
146+
moveTree(modGameDir,str(modspath/slug/'game'))
147+
148+
def installRpaMod(file,slug):
149+
with tempfile.TemporaryDirectory() as tmpdirname:
150+
shutil.copy(file,tmpdirname)
151+
moveTree(tmpdirname,str(modspath/slug/'game'))
152+
153+
154+
132155
def addmodPress(button):
133156
global addmodgui
134157
modname = addmodgui.getEntry("Mod Name")
135158
modfile = addmodgui.getEntry("f1")
136159
if button == "Add":
137160
shutil.copytree(str(modspath/"vanilla"),str(modspath/slugify(modname)))
138-
with ZipFile(modfile) as modzip:
139-
with tempfile.TemporaryDirectory() as tmpdirname:
140-
modzip.extractall(tmpdirname)
141-
modGameDir=findParent(PATTERNS,tmpdirname)
142-
if modGameDir is None:
143-
print("That isn't a mod")
144-
logging.error("Not a mod :shrugika:")
145-
shutil.rmtree(str(modspath/slugify(modname)))
146-
return;
147-
else:
148-
moveTree(modGameDir,str(modspath/slugify(modname)/'game'))
149-
161+
ext = Path(modfile).suffix
162+
if ext == ".zip":
163+
try:
164+
installZipMod(modfile,slugify(modname))
165+
except InvalidModError:
166+
shutil.rmtree(str(modspath/slugify(modname)))
167+
return
168+
elif ext == ".rpa":
169+
installRpaMod(modfile,slugify(modname))
170+
else:
171+
print("{} files are not a supported mod type. If they should be, please create an issue on GitHub.".format(ext))
172+
shutil.rmtree(str(modspath/slugify(modname)))
173+
return
150174
with shelve.open('mods.db',writeback=True) as mods:
151175
mods[slugify(modname)]=modname
152176
addmodgui.stop()

version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v0.2
1+
v0.2.1

0 commit comments

Comments
 (0)