remove invalid zip from interrupted previous download

This commit is contained in:
seuyh
2025-03-26 14:15:40 +07:00
parent e3f8b6a5db
commit 9b0d3042d4
+13 -13
View File
@@ -1,7 +1,7 @@
import os
from shutil import rmtree, copytree
from sys import argv
from zipfile import ZipFile
from zipfile import ZipFile, BadZipFile
import requests
from PyQt5.QtGui import QDesktopServices, QColor, QBrush, QIcon
@@ -392,7 +392,7 @@ class MainWindow(QMainWindow, ui_main.Ui_MainWindow):
file_url = f"{'https://stlunlocker.pro/unlocker/'}{dlc_folder}.zip"
save_path = os.path.join(self.game_path, 'dlc', f'{dlc_folder}.zip')
dlc_path = os.path.join(self.game_path, 'dlc', dlc_folder)
if not os.path.exists(dlc_path) and self.is_invalid_zip(save_path):
if os.path.exists(save_path):
os.remove(save_path)
@@ -413,17 +413,17 @@ class MainWindow(QMainWindow, ui_main.Ui_MainWindow):
@staticmethod
def is_invalid_zip(path):
if not os.path.exists(path):
return True
if os.path.getsize(path) == 0:
return True
try:
with zipfile.ZipFile(path, 'r') as zf:
if zf.testzip() is not None:
return True # Corrupted file found
except zipfile.BadZipFile:
return True # Not even a zip
return False
if not os.path.exists(path):
return True
if os.path.getsize(path) == 0:
return True
try:
with ZipFile(path, 'r') as zf:
if zf.testzip() is not None:
return True # Corrupted file found
except BadZipFile:
return True # Not even a zip
return False
def update_progress(self, value, by_download=False):
self.dlc_download_progress_bar.setValue(value)