mirror of
https://github.com/KeksPirates/SoftwareManager.git
synced 2026-08-04 01:49:42 +02:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c3efa39b09 | |||
| d3d7a9d2ac |
@@ -139,7 +139,7 @@ def settings_dialog(self):
|
|||||||
image_path_layout = QHBoxLayout()
|
image_path_layout = QHBoxLayout()
|
||||||
|
|
||||||
image_path = QLineEdit()
|
image_path = QLineEdit()
|
||||||
image_path_layout.addWidget(QLabel("Image Path (requires restart):"))
|
image_path_layout.addWidget(QLabel("Image Path (requires restart, experimental):"))
|
||||||
image_path_layout.addWidget(image_path)
|
image_path_layout.addWidget(image_path)
|
||||||
image_path_container.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed)
|
image_path_container.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed)
|
||||||
image_path_container.setLayout(image_path_layout)
|
image_path_container.setLayout(image_path_layout)
|
||||||
|
|||||||
@@ -680,7 +680,7 @@ class MainWindow(QtWidgets.QMainWindow, QWidget):
|
|||||||
self.context_menu = QtWidgets.QMenu(self)
|
self.context_menu = QtWidgets.QMenu(self)
|
||||||
self.context_menu.addAction("Open Containing Folder", self.openFolderAction)
|
self.context_menu.addAction("Open Containing Folder", self.openFolderAction)
|
||||||
self.context_menu.addAction("Copy Magnet URI", self.copyMagnetURIAction)
|
self.context_menu.addAction("Copy Magnet URI", self.copyMagnetURIAction)
|
||||||
self.context_menu.addAction("Cancel Download", self.cancelDownloadAction)
|
self.context_menu.addAction("Remove from list", self.cancelDownloadAction)
|
||||||
self.context_menu.addAction("Delete File", self.deleteFileAction)
|
self.context_menu.addAction("Delete File", self.deleteFileAction)
|
||||||
|
|
||||||
def _create_tracker_table(self):
|
def _create_tracker_table(self):
|
||||||
@@ -1038,9 +1038,9 @@ class MainWindow(QtWidgets.QMainWindow, QWidget):
|
|||||||
consoleLog(f"Deleted files for: {magnetdl.status().name}", True)
|
consoleLog(f"Deleted files for: {magnetdl.status().name}", True)
|
||||||
else:
|
else:
|
||||||
import shutil
|
import shutil
|
||||||
del state.active_downloads[magnet_link]
|
|
||||||
remove_download_log(magnet_link)
|
remove_download_log(magnet_link)
|
||||||
shutil.rmtree(download_path)
|
shutil.rmtree(download_path)
|
||||||
|
del state.active_downloads[magnet_link]
|
||||||
consoleLog(f"Deleted files for: {magnetdl.status().name}", True)
|
consoleLog(f"Deleted files for: {magnetdl.status().name}", True)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
consoleLog(f"Error deleting files: {e}", True)
|
consoleLog(f"Error deleting files: {e}", True)
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import time
|
import time
|
||||||
import os
|
import os
|
||||||
|
import platform
|
||||||
|
import ctypes
|
||||||
from core.utils.general.wrappers import run_thread
|
from core.utils.general.wrappers import run_thread
|
||||||
from core.network.interface import get_interface_ip
|
from core.network.interface import get_interface_ip
|
||||||
import threading
|
import threading
|
||||||
@@ -11,6 +13,15 @@ from core.utils.logging.logs import consoleLog
|
|||||||
global loop_running
|
global loop_running
|
||||||
loop_running = False
|
loop_running = False
|
||||||
|
|
||||||
|
def get_free_space_mb(dirname):
|
||||||
|
if platform.system() == 'Windows':
|
||||||
|
free_bytes = ctypes.c_ulonglong(0)
|
||||||
|
ctypes.windll.kernel32.GetDiskFreeSpaceExW(ctypes.c_wchar_p(dirname), None, None, ctypes.pointer(free_bytes))
|
||||||
|
return free_bytes.value
|
||||||
|
else:
|
||||||
|
st = os.statvfs(dirname)
|
||||||
|
return st.f_bavail * st.f_frsize
|
||||||
|
|
||||||
def init_session():
|
def init_session():
|
||||||
if state.dl_session is not None:
|
if state.dl_session is not None:
|
||||||
return
|
return
|
||||||
@@ -51,6 +62,8 @@ def add_download(magnet_uri, dl_path=state.download_path):
|
|||||||
|
|
||||||
init_session()
|
init_session()
|
||||||
|
|
||||||
|
free_space = get_free_space_mb(state.download_path)
|
||||||
|
|
||||||
if magnet_uri in state.active_downloads:
|
if magnet_uri in state.active_downloads:
|
||||||
try:
|
try:
|
||||||
handle = state.active_downloads[magnet_uri]
|
handle = state.active_downloads[magnet_uri]
|
||||||
@@ -75,13 +88,31 @@ def add_download(magnet_uri, dl_path=state.download_path):
|
|||||||
del state.active_downloads[magnet_uri]
|
del state.active_downloads[magnet_uri]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
magnetdl = lt.parse_magnet_uri(magnet_uri)
|
params = lt.parse_magnet_uri(magnet_uri)
|
||||||
magnetdl.save_path = dl_path
|
params.save_path = "."
|
||||||
download = state.dl_session.add_torrent(magnetdl)
|
|
||||||
|
handle = state.dl_session.add_torrent(params)
|
||||||
|
|
||||||
|
while not handle.has_metadata():
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
|
total_size = handle.get_torrent_info().total_size()
|
||||||
|
|
||||||
|
if free_space > total_size:
|
||||||
|
magnetdl = lt.parse_magnet_uri(magnet_uri)
|
||||||
|
magnetdl.save_path = dl_path
|
||||||
|
download = state.dl_session.add_torrent(magnetdl)
|
||||||
|
else:
|
||||||
|
download = None
|
||||||
|
state.dl_session.remove_torrent(handle)
|
||||||
|
consoleLog("Not enough free space to download this item.")
|
||||||
|
return False
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
consoleLog(f"Failed to add torrent: {e}")
|
consoleLog(f"Failed to add torrent or fetch info: {e}")
|
||||||
return False
|
return False
|
||||||
state.active_downloads[magnet_uri] = download
|
if download:
|
||||||
|
state.active_downloads[magnet_uri] = download
|
||||||
consoleLog(f"Added {magnet_uri} to downloads")
|
consoleLog(f"Added {magnet_uri} to downloads")
|
||||||
|
|
||||||
run_thread(threading.Thread(target=dl_status_loop))
|
run_thread(threading.Thread(target=dl_status_loop))
|
||||||
@@ -171,4 +202,3 @@ def update_bound_interface():
|
|||||||
settings = { "outgoing_interfaces": state.bound_interface }
|
settings = { "outgoing_interfaces": state.bound_interface }
|
||||||
|
|
||||||
state.dl_session.apply_settings(settings)
|
state.dl_session.apply_settings(settings)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user