Skip to content

Commit 240f4aa

Browse files
authored
Use Helper Methods for ctmod Extraction (#250)
* Use helper functions to extract ctmod archives * Proton-tkg: Use new extraction logic * Luxtorpeda: Use new extraction logic + refactor * DXVK: use new extraction logic * Boxtron: use new extraction * Northstar Proton: use new extraction * Roberta: Use new extraction * DXVK Async: Use new extraction * GE-Proton: use new extraction * Wine-GE: Use new extraction * Kron4ek: Use new extraction * Lutris-Wine: Use new extraction * ctmod: Remove unused imports * DXVK Nightly: Use new extraction Also fix silly mistake with Lutris Wine * Util: Remove extract_zst Not used during development
1 parent 65337e4 commit 240f4aa

17 files changed

+282
-279
lines changed

pupgui2/resources/ctmods/ctmod_00protonge.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@
33
# Copyright (C) 2021 DavidoTek, partially based on AUNaseef's protonup
44

55
import os
6-
import shutil
7-
import tarfile
86
import requests
97
import hashlib
108

119
from PySide6.QtCore import QObject, QCoreApplication, Signal, Property
1210

13-
from pupgui2.util import ghapi_rlcheck
11+
from pupgui2.util import ghapi_rlcheck, extract_tar
1412

1513

1614
CT_NAME = 'GE-Proton'
@@ -149,20 +147,17 @@ def get_tool(self, version, install_dir, temp_dir):
149147
else:
150148
return False
151149

152-
destination = temp_dir
153-
destination += data['download'].split('/')[-1]
154-
destination = destination
155-
156-
if not self.__download(url=data['download'], destination=destination):
150+
proton_tar = os.path.join(temp_dir, data['download'].split('/')[-1])
151+
if not self.__download(url=data['download'], destination=proton_tar):
157152
return False
158153

159-
download_checksum = self.__sha512sum(destination)
154+
download_checksum = self.__sha512sum(proton_tar)
160155
if source_checksum and (download_checksum not in source_checksum):
161156
return False
162157

163-
if os.path.exists(protondir):
164-
shutil.rmtree(protondir)
165-
tarfile.open(destination, "r:gz").extractall(install_dir)
158+
if not extract_tar(proton_tar, install_dir, mode='gz'):
159+
return False
160+
166161
if os.path.exists(checksum_dir):
167162
open(checksum_dir, 'w').write(download_checksum)
168163

pupgui2/resources/ctmods/ctmod_00winege.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@
33
# Copyright (C) 2021 DavidoTek, partially based on AUNaseef's protonup
44

55
import os
6-
import shutil
7-
import tarfile
86
import requests
97
import hashlib
108

119
from PySide6.QtCore import QObject, QCoreApplication, Signal, Property
1210

13-
from pupgui2.util import ghapi_rlcheck
11+
from pupgui2.util import ghapi_rlcheck, extract_tar
1412

1513

1614
CT_NAME = 'Wine-GE'
@@ -147,20 +145,17 @@ def get_tool(self, version, install_dir, temp_dir):
147145
else:
148146
return False
149147

150-
destination = temp_dir
151-
destination += data['download'].split('/')[-1]
152-
destination = destination
153-
154-
if not self.__download(url=data['download'], destination=destination):
148+
proton_tar = os.path.join(temp_dir, data['download'].split('/')[-1])
149+
if not self.__download(url=data['download'], destination=proton_tar):
155150
return False
156151

157-
download_checksum = self.__sha512sum(destination)
152+
download_checksum = self.__sha512sum(proton_tar)
158153
if source_checksum and (download_checksum not in source_checksum):
159154
return False
160155

161-
if os.path.exists(protondir):
162-
shutil.rmtree(protondir)
163-
tarfile.open(destination, "r:xz").extractall(install_dir)
156+
if not extract_tar(proton_tar, install_dir, mode='xz'):
157+
return False
158+
164159
if os.path.exists(checksum_dir):
165160
open(checksum_dir, 'w').write(download_checksum)
166161

pupgui2/resources/ctmods/ctmod_boxtron.py

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,12 @@
33
# Copyright (C) 2021 DavidoTek, partially based on AUNaseef's protonup
44

55
import os
6-
import shutil
7-
import tarfile
86
import requests
97

108
from PySide6.QtCore import QObject, QCoreApplication, Signal, Property
119
from PySide6.QtWidgets import QMessageBox
1210

13-
from pupgui2.util import ghapi_rlcheck
14-
from pupgui2.util import host_which
11+
from pupgui2.util import ghapi_rlcheck, host_which, extract_tar, write_tool_version
1512

1613

1714
CT_NAME = 'Boxtron'
@@ -135,23 +132,15 @@ def get_tool(self, version, install_dir, temp_dir):
135132
if not data or 'download' not in data:
136133
return False
137134

138-
protondir = f'{install_dir}boxtron'
139135

140-
destination = temp_dir
141-
destination += data['download'].split('/')[-1]
142-
destination = destination
143-
144-
if not self.__download(url=data['download'], destination=destination):
136+
boxtron_tar = os.path.join(temp_dir, data['download'].split('/')[-1])
137+
if not self.__download(url=data['download'], destination=boxtron_tar):
145138
return False
146139

147-
if os.path.exists(protondir):
148-
shutil.rmtree(protondir)
149-
tarfile.open(destination, "r:xz").extractall(install_dir)
150-
151-
if os.path.exists(protondir):
152-
with open(os.path.join(protondir, 'VERSION.txt'), 'w') as f:
153-
f.write(version)
154-
f.write('\n')
140+
boxtron_dir = os.path.join(install_dir, 'boxtron')
141+
if not extract_tar(boxtron_tar, install_dir, mode='xz'):
142+
return False
143+
write_tool_version(boxtron_dir, version)
155144

156145
self.__set_download_progress_percent(100)
157146

pupgui2/resources/ctmods/ctmod_d8vk.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@
33
# Copyright (C) 2022 DavidoTek, partially based on AUNaseef's protonup
44

55
import os
6-
import shutil
76
import requests
8-
import zipfile
97

108
from PySide6.QtCore import QObject, QCoreApplication, Signal, Property
119

12-
from pupgui2.util import ghapi_rlcheck
10+
from pupgui2.util import ghapi_rlcheck, extract_zip
1311

1412

1513
CT_NAME = 'D8VK (nightly)'
@@ -135,19 +133,13 @@ def get_tool(self, version, install_dir, temp_dir):
135133
if not data or 'download' not in data:
136134
return False
137135

138-
dxvk_dir = self.get_extract_dir(install_dir)
139-
dxvk_install_dir = os.path.join(dxvk_dir, 'd8vk-git-' + data['version'])
140-
destination = temp_dir
141-
destination += data['download'].split('/')[-1]
142-
destination = destination
143-
144-
if not self.__download(url=data['download'], destination=destination, f_size=data['size']):
136+
d8vk_zip = os.path.join(temp_dir, data['download'].split('/')[-1])
137+
if not self.__download(url=data['download'], destination=d8vk_zip, f_size=data['size']):
145138
return False
146139

147-
if os.path.exists(dxvk_dir + 'd8vk-git-' + data['version']):
148-
shutil.rmtree(dxvk_dir + 'd8vk-git-' + data['version'])
149-
with zipfile.ZipFile(destination) as zip:
150-
zip.extractall(dxvk_install_dir)
140+
d8vk_dir = os.path.join(self.get_extract_dir(install_dir), 'd8vk-git-' + data['version'])
141+
if not extract_zip(d8vk_zip, d8vk_dir):
142+
return False
151143

152144
self.__set_download_progress_percent(100)
153145

pupgui2/resources/ctmods/ctmod_kron4ekvanilla.py

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@
44

55
import os
66
import subprocess
7-
import shutil
8-
import tarfile
97
import requests
108

119
from PySide6.QtCore import QObject, QCoreApplication, Signal, Property
1210

13-
from pupgui2.util import ghapi_rlcheck
11+
from pupgui2.util import ghapi_rlcheck, extract_tar
1412

1513

1614
CT_NAME = 'Kron4ek Wine-Builds Vanilla'
@@ -122,22 +120,15 @@ def get_tool(self, version, install_dir, temp_dir):
122120
"""
123121

124122
data = self.__fetch_github_data(version)
125-
126123
if not data or 'download' not in data:
127124
return False
128125

129-
protondir = f'{install_dir}wine-{data["version"].lower()}-amd64'
130-
131-
destination = temp_dir
132-
destination += data['download'].split('/')[-1]
133-
destination = destination
134-
135-
if not self.__download(url=data['download'], destination=destination):
126+
kron4ek_tar = os.path.join(temp_dir, data['download'].split('/')[-1])
127+
if not self.__download(url=data['download'], destination=kron4ek_tar):
136128
return False
137129

138-
if os.path.exists(protondir):
139-
shutil.rmtree(protondir)
140-
tarfile.open(destination, "r:xz").extractall(install_dir)
130+
if not extract_tar(kron4ek_tar, install_dir, mode='xz'):
131+
return False
141132

142133
self.__set_download_progress_percent(100)
143134

pupgui2/resources/ctmods/ctmod_lutriswine.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@
33
# Copyright (C) 2021 DavidoTek, partially based on AUNaseef's protonup
44

55
import os
6-
import shutil
7-
import tarfile
86
import requests
97
import hashlib
108

119
from PySide6.QtCore import QObject, QCoreApplication, Signal, Property
1210

13-
from pupgui2.util import ghapi_rlcheck
11+
from pupgui2.util import ghapi_rlcheck, extract_tar
1412

1513

1614
CT_NAME = 'Lutris-Wine'
@@ -164,20 +162,17 @@ def get_tool(self, version, install_dir, temp_dir):
164162
else:
165163
return False
166164

167-
destination = temp_dir
168-
destination += data['download'].split('/')[-1]
169-
destination = destination
170-
171-
if not self.__download(url=data['download'], destination=destination):
165+
proton_tar = os.path.join(temp_dir, data['download'].split('/')[-1])
166+
if not self.__download(url=data['download'], destination=proton_tar):
172167
return False
173168

174-
download_checksum = self.__sha512sum(destination)
169+
download_checksum = self.__sha512sum(proton_tar)
175170
if source_checksum and (download_checksum not in source_checksum):
176171
return False
177172

178-
if os.path.exists(protondir):
179-
shutil.rmtree(protondir)
180-
tarfile.open(destination, "r:xz").extractall(install_dir)
173+
if not extract_tar(proton_tar, install_dir, mode='xz'):
174+
return False
175+
181176
if os.path.exists(checksum_dir):
182177
open(checksum_dir, 'w').write(download_checksum)
183178

pupgui2/resources/ctmods/ctmod_luxtorpeda.py

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@
33
# Copyright (C) 2021 DavidoTek, partially based on AUNaseef's protonup
44

55
import os
6-
import shutil
7-
import tarfile
86
import requests
97

108
from PySide6.QtCore import QObject, QCoreApplication, Signal, Property
119

12-
from pupgui2.util import ghapi_rlcheck
10+
from pupgui2.util import ghapi_rlcheck, extract_tar, write_tool_version
1311

1412

1513
CT_NAME = 'Luxtorpeda'
@@ -118,23 +116,14 @@ def get_tool(self, version, install_dir, temp_dir):
118116
if not data or 'download' not in data:
119117
return False
120118

121-
protondir = f'{install_dir}luxtorpeda'
122-
123-
destination = temp_dir
124-
destination += data['download'].split('/')[-1]
125-
destination = destination
126-
127-
if not self.__download(url=data['download'], destination=destination):
119+
luxtorpeda_tar = os.path.join(temp_dir, data['download'].split('/')[-1])
120+
if not self.__download(url=data['download'], destination=luxtorpeda_tar):
128121
return False
129122

130-
if os.path.exists(protondir):
131-
shutil.rmtree(protondir)
132-
tarfile.open(destination, "r:xz").extractall(install_dir)
133-
134-
if os.path.exists(protondir):
135-
with open(os.path.join(protondir, 'VERSION.txt'), 'w') as f:
136-
f.write(version)
137-
f.write('\n')
123+
luxtorpeda_dir = os.path.join(install_dir, 'luxtorpeda')
124+
if not extract_tar(luxtorpeda_tar, install_dir, mode='xz'):
125+
return False
126+
write_tool_version(luxtorpeda_dir, version)
138127

139128
self.__set_download_progress_percent(100)
140129

pupgui2/resources/ctmods/ctmod_northstarproton.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@
33
# Copyright (C) 2022 DavidoTek, partially based on AUNaseef's protonup
44

55
import os
6-
import shutil
7-
import tarfile
86
import requests
97

108
from PySide6.QtCore import QObject, Signal, Property, QCoreApplication
119

12-
from pupgui2.util import ghapi_rlcheck
10+
from pupgui2.util import ghapi_rlcheck, extract_tar
1311

1412

1513
CT_NAME = 'NorthStar Proton (TitanFall 2)'
@@ -118,18 +116,12 @@ def get_tool(self, version, install_dir, temp_dir):
118116
if not data or 'download' not in data:
119117
return False
120118

121-
protondir = os.path.join(install_dir, data['version'])
122-
123-
destination = temp_dir
124-
destination += data['download'].split('/')[-1]
125-
destination = destination
126-
127-
if not self.__download(url=data['download'], destination=destination):
119+
northstar_tar = os.path.join(temp_dir, data['download'].split('/')[-1])
120+
if not self.__download(url=data['download'], destination=northstar_tar):
128121
return False
129122

130-
if os.path.exists(protondir):
131-
shutil.rmtree(protondir)
132-
tarfile.open(destination, "r:gz").extractall(install_dir)
123+
if not extract_tar(northstar_tar, install_dir, mode='gz'):
124+
return False
133125

134126
self.__set_download_progress_percent(100)
135127

0 commit comments

Comments
 (0)