|
27 | 27 | VERSION_URL="https://raw.githubusercontent.com/famous1622/fDDMEPlayer/master/version" |
28 | 28 | PATTERNS = ("options.rpyc","*.rpa","options.rpy") |
29 | 29 |
|
| 30 | + |
| 31 | +class InvalidModError(Exception): |
| 32 | + pass |
| 33 | + |
30 | 34 | def saveConfig(): |
31 | 35 | with open("config.ini", 'w') as configfile: |
32 | 36 | config.write(configfile) |
@@ -129,24 +133,44 @@ def addmod(): |
129 | 133 | addmodgui.go() |
130 | 134 | return "<meta http-equiv=\"refresh\" content=\"1; url=http://localhost:5000/\">Please wait..." |
131 | 135 |
|
| 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 | + |
132 | 155 | def addmodPress(button): |
133 | 156 | global addmodgui |
134 | 157 | modname = addmodgui.getEntry("Mod Name") |
135 | 158 | modfile = addmodgui.getEntry("f1") |
136 | 159 | if button == "Add": |
137 | 160 | 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 |
150 | 174 | with shelve.open('mods.db',writeback=True) as mods: |
151 | 175 | mods[slugify(modname)]=modname |
152 | 176 | addmodgui.stop() |
|
0 commit comments