diff --git a/app/downloader.py b/app/downloader.py index 49e032e..6fca726 100644 --- a/app/downloader.py +++ b/app/downloader.py @@ -3,6 +3,7 @@ import time from math import inf from pathlib import Path +import os import requests @@ -47,7 +48,13 @@ def worker(self): else: # gets the size of the file self.curr = path.stat().st_size - start = self.getval('start') + self.curr + # add the old start size and the current size to get the new start size + start = self.getval("start") + self.curr + # corruption check to make sure parts are not corrupted + if start > end: + os.remove(path) + self.error.set() + print("corrupted file!") url = self.getval('url') if self.curr != self.getval('size'): @@ -147,7 +154,7 @@ def download(self, url, filepath, num_connections, display, multithread): # load the progress from the progress file # the object_hook converts the key strings whose value is int to type int progress = json.loads(json_file.read_text(), object_hook=lambda d: { - int(k) if k.isdigit() else k: v for k, v in d.items()}) + int(k) if k.isdigit() else k: v for k, v in d.items()}) segment = total / num_connections self._dic['total'] = total self._dic['connections'] = num_connections diff --git a/app/maingui.py b/app/maingui.py index 22f6952..4496ddf 100644 --- a/app/maingui.py +++ b/app/maingui.py @@ -8,7 +8,7 @@ import clr from PyQt6.QtCore import (QObject, QRunnable, Qt, QThreadPool, pyqtSignal, - pyqtSlot) + pyqtSlot) from PyQt6.QtGui import QIcon from PyQt6.QtWidgets import QFileDialog, QMainWindow @@ -18,7 +18,8 @@ from url_gen import url_generator from utls import open_browser -dll_path = os.path.abspath(r"data\System.Management.Automation.dll") +script_dir = os.path.dirname(os.path.abspath(__file__)) +dll_path = os.path.join(script_dir,"data\System.Management.Automation.dll") clr.AddReference(dll_path) try: @@ -62,7 +63,7 @@ class Worker(QRunnable): Inherits from QRunnable to handler worker thread setup, signals and wrap-up. :param callback: The function callback to run on this worker thread. Supplied args and - kwargs will be passed through to the runner. + kwargs will be passed through to the runner. :type callback: function :param args: Arguments to pass to the callback function :param kwargs: Keywords to pass to the callback function