Skip to content

Commit d064f9f

Browse files
authored
Update proton_manager.py
1 parent 5762ea8 commit d064f9f

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

proton_manager.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ def install_proton(self, version, proton_type, progress_callback=None):
145145
print(f"No tar.gz asset found for {version}")
146146
return False, f"No tar.gz asset found for {version}"
147147
dl_url = tar_asset['browser_download_url']
148-
progress_callback("Downloading", 0, 100)
148+
if progress_callback:
149+
progress_callback("Downloading", 0, 100)
149150
with tempfile.NamedTemporaryFile(suffix='.tar.gz', delete=False) as temp_tar:
150151
response = requests.get(dl_url, stream=True, timeout=30)
151152
response.raise_for_status()
@@ -160,7 +161,8 @@ def install_proton(self, version, proton_type, progress_callback=None):
160161
if progress_callback and total_size:
161162
progress_callback("Downloading", downloaded, total_size)
162163
temp_tar_path = temp_tar.name
163-
progress_callback("Extracting", 0, 100)
164+
if progress_callback:
165+
progress_callback("Extracting", 0, 100)
164166
extract_dir = os.path.join(self.protons_dir, version)
165167
os.makedirs(extract_dir, exist_ok=True)
166168
with tarfile.open(temp_tar_path) as tar:
@@ -191,13 +193,18 @@ def install_proton(self, version, proton_type, progress_callback=None):
191193
except Exception as e:
192194
logging.error(f"Error installing {proton_type} proton {version}: {e}")
193195
print(f"Error installing {proton_type} proton {version}: {e}")
196+
if 'extract_dir' in locals():
197+
shutil.rmtree(extract_dir, ignore_errors=True)
198+
if 'temp_tar_path' in locals() and os.path.exists(temp_tar_path):
199+
os.remove(temp_tar_path)
194200
return False, str(e)
195201

196202
def install_custom_tar(self, tar_path, version, progress_callback=None):
197203
try:
198204
extract_dir = os.path.join(self.protons_dir, version)
199205
os.makedirs(extract_dir, exist_ok=True)
200-
progress_callback("Extracting", 0, 100)
206+
if progress_callback:
207+
progress_callback("Extracting", 0, 100)
201208
with tarfile.open(tar_path) as tar:
202209
for member in tar.getmembers():
203210
member_path = os.path.join(extract_dir, member.name)
@@ -225,6 +232,8 @@ def install_custom_tar(self, tar_path, version, progress_callback=None):
225232
except Exception as e:
226233
logging.error(f"Error installing custom tar: {e}")
227234
print(f"Error installing custom tar: {e}")
235+
if 'extract_dir' in locals():
236+
shutil.rmtree(extract_dir, ignore_errors=True)
228237
return False, str(e)
229238

230239
def install_custom_folder(self, src_folder, version):
@@ -239,6 +248,8 @@ def install_custom_folder(self, src_folder, version):
239248
except Exception as e:
240249
logging.error(f"Error installing custom folder: {e}")
241250
print(f"Error installing custom folder: {e}")
251+
if 'dest' in locals():
252+
shutil.rmtree(dest, ignore_errors=True)
242253
return False, str(e)
243254

244255
def remove_proton(self, version):

0 commit comments

Comments
 (0)