Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Helmssyss authored Dec 4, 2023
1 parent 7d866bf commit 16418ed
Show file tree
Hide file tree
Showing 8 changed files with 83,455 additions and 37 deletions.
12 changes: 6 additions & 6 deletions GUI/src/funcs/sync_dll_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@

class SyncMagnetDllService():
currentfileIsSending = None
_dllPath:str = r".\src\service\DLL\sync_service.dll"
__magnetDll:ctypes.CDLL = None
_clientName:str = ""
def __init__(self) -> None:
self._dllPath:str = r".\sync_service.dll" # /src/service/DLL
self.__magnetDll:ctypes.CDLL = None

def LoadMagnetDll(self) -> bool:
""" Dll dosyasının varlığını kontrol et """
Expand All @@ -25,7 +26,6 @@ def ManageDllStarted(self):
except FileNotFoundError:
self.__magnetDll = ctypes.CDLL(name=self._dllPath,winmode=0)
finally:
self.__magnetDll.GetChangeLog()
self.__magnetDll.SetupServer(gethostbyname(gethostname()).encode())
self.__magnetDll.StartServer()

Expand Down Expand Up @@ -83,9 +83,9 @@ def CanGetDeviceState(self) -> None:
def GetDeviceBatteryStatus(self):
return self.__magnetDll.GetDeviceBatteryStatusPerSecond()

def SetCanDeviceState(self):
return self.__magnetDll.SetCanDeviceState()
def SetCanDeviceState(self,state: bool):
return self.__magnetDll.SetCanDeviceState(state)

def formatSize(self,byte) -> str:
""" Dosya boyutu birim dönüşümü """

Expand Down
17 changes: 9 additions & 8 deletions GUI/src/funcs/sync_workers.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class SyncConnectWorker(QObject):

def start(self) -> None:
__DLL_SERVICE__.ManageDllStarted()
self.connectStart.emit({"isConnect": True, "this":__DLL_SERVICE__})
self.connectStart.emit({"isConnect": True, "service":__DLL_SERVICE__})
# ##### ===> SyncConnectWorker

# ##### ===> SyncClientInfoWorker
Expand All @@ -47,7 +47,7 @@ def start(self) -> None:
__DLL_SERVICE__.GetDeviceBatteryStatus()

except Exception as E:
# print("SyncClientInfoWorker ERROR: ",E)
print("SyncClientInfoWorker ERROR: ",E)
pass

finally:
Expand Down Expand Up @@ -83,7 +83,7 @@ def start(self):
__DLL_SERVICE__.HandleFileTransfer()
self.onConnectDownload.emit({"state":__DLL_SERVICE__.GetIsDownloadCompletedFile(),"dFiles":CACHE_DOWNLOAD_FILE})
# print("__DLL_SERVICE__.HandleFileTransfer()")
sleep(0.6)
sleep(0.1)
# ##### ===> SyncFileDownloadWorker

# ##### ===> SyncDownloadFileListener
Expand Down Expand Up @@ -124,12 +124,12 @@ def start(self):
self.isBackground.emit(False)
else:
self.isBackground.emit(True)
sleep(0.6)
sleep(0.1)
# ##### ===> SyncProcessRunWorker

# ##### ===> SyncLoadPageCDWorker
class SyncLoadPageCDWorker(QObject):
connectCurrentLoadSize = pyqtSignal(int)
connectCurrentLoadSize = pyqtSignal(dict)
connectCurrentLoadFileName = pyqtSignal(str)
def __init__(self,) -> None:
super().__init__()
Expand All @@ -142,7 +142,8 @@ def start(self):
while self.__runWorker:
try:
fSize = __DLL_SERVICE__.GetCurrentDownloadFileSize()
self.connectCurrentLoadSize.emit(fSize)
ftSize = __DLL_SERVICE__.GetCurrentTotalDownloadFileSize()
self.connectCurrentLoadSize.emit({"fileSize":fSize,"fileTotalSize":ftSize})
root = ET.parse(r".\MagnetManifest.xml")
getDownloadFile = root.findall('.//GetFile')
getUploadFile = root.findall('.//SendFile')
Expand All @@ -163,7 +164,7 @@ def start(self):
print("ERR: -> ",E)
continue
finally:
sleep(0.6)
sleep(0.1)
# ##### ===> SyncLoadPageCDWorker


Expand All @@ -180,7 +181,7 @@ def setRunState(self, newRunState: bool):
def checkStart(self):
while self.__run:
try:
response = requestGet("https://www.google.com")
response = requestGet("https://www.google.com",timeout=50)
response.raise_for_status()
self.checkNet.emit(True)
except RequestException:
Expand Down
2 changes: 1 addition & 1 deletion GUI/src/pages/sync_check_net_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def eventFilter(self, source, event) -> bool:

@pyqtSlot(bool)
def progressBarState(self,check: bool):
if check and self.waitcount == 10:
if check and self.waitcount == 3:
self.checkWorker.setRunState(False)
self.checkThread.quit()
self.checkThread.wait()
Expand Down
7 changes: 6 additions & 1 deletion GUI/src/pages/sync_connect_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from socket import gethostbyname
from socket import gethostname
from webbrowser import open as openWeb
from requests import Session

class ConnectWindow(QMainWindow):
def __init__(self,application: QApplication) -> None:
Expand Down Expand Up @@ -182,11 +183,15 @@ def connectStart(self):
self.connectThread.started.connect(self.connectWorker.start)
self.connectThread.start()
self.connectWorker.connectStart.connect(self.onConnected)
with Session() as session:
r = session.get("https://raw.githubusercontent.com/Helmssyss/SyncMagnet/main/CHANGELOG.md")
with open(r".\CHANGELOG.md","w") as mdFile:
mdFile.write(r.text)

@pyqtSlot(dict)
def onConnected(self, param: dict[str,object]):
if param['isConnect']:
serverPage = ServerWindow(__APPLICATION__=self.application,dllService= param["this"])
serverPage = ServerWindow(__APPLICATION__=self.application,dllService=param["service"])
serverPage.show()
self.close()

Expand Down
16 changes: 7 additions & 9 deletions GUI/src/pages/sync_load_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,17 @@ def setupUi(self, Form):
self.currentDownloadSizeWorker.connectCurrentLoadSize.connect(self.manage)
self.currentDownloadSizeWorker.connectCurrentLoadFileName.connect(self.appendListWidget)

@pyqtSlot(int)
def manage(self, size: int):
@pyqtSlot(dict)
def manage(self, param: dict):
self.totalDownloadLabel.setGeometry(QRect(120, 30, 181, 31))
self.progressBar.setMaximum(self.dll.GetCurrentTotalDownloadFileSize())
self.progressBar.setValue(size)
fSize = self.dll.GetCurrentDownloadFileSize()
tFSize = self.dll.GetCurrentTotalDownloadFileSize()
if fSize != 1 and tFSize != 1:
self.totalDownloadLabel.setText(f"""<html><head/><body><p><span style="font-size:16pt;">{self.dll.formatSize(size)} </span><span style="font-size:16pt; vertical-align:super;">{self.dll.formatSize(self.dll.GetCurrentTotalDownloadFileSize())}</span></p></body></html>""")
if size == 1:
self.progressBar.setValue(param['fileSize'])
if param['fileTotalSize'] != 1 and param['fileSize'] != 1:
self.totalDownloadLabel.setText(f"""<html><head/><body><p><span style="font-size:16pt;">{self.dll.formatSize(param['fileSize'])} </span><span style="font-size:16pt; vertical-align:super;">{self.dll.formatSize(param['fileTotalSize'])}</span></p></body></html>""")
if param['fileSize'] == 1:
self.totalDownloadLabel.setGeometry(QRect(100, 30, 161, 31))
self.totalDownloadLabel.setText("""<html><span style="font-size:16pt;">Done</span></html>""")
if fSize == 1 and tFSize == 1:
if param['fileSize'] == 1 and param['fileTotalSize'] == 1:
self.currentDownloadSizeWorker.setRunState(False)
self.currentDownloadSizeThread.quit()
self.currentDownloadSizeThread.wait()
Expand Down
39 changes: 28 additions & 11 deletions GUI/src/pages/sync_server_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
from src.widgets import SyncTableWidget
from webbrowser import open as openSourcePage

CACHE_DOWNLOAD_FILE_NAME = set()

class ServerWindow(QMainWindow):
def __init__(self,__APPLICATION__: QApplication,dllService: SyncMagnetDllService) -> None:
super(ServerWindow,self).__init__()
Expand All @@ -28,6 +30,7 @@ def __init__(self,__APPLICATION__: QApplication,dllService: SyncMagnetDllService
self.SAVE_FILE_THREAD = None
self.isBack = False
self.run = True
self.isloadPageOpen = False
self.syncMagnetDllService = dllService
QThread.sleep(1)
self.setWindowFlags(Qt.FramelessWindowHint)
Expand Down Expand Up @@ -940,7 +943,12 @@ def connectedButtons(self):
@pyqtSlot(bool)
def onAppIsBackground(self, isBackground: bool):
if isBackground:
pass
if self.isloadPageOpen:
if self.isMinimized():
self.showNormal()
self.activateWindow()
self.raise_()
# pass
# print("Background")
else:
pass
Expand All @@ -950,14 +958,16 @@ def closeApplication(self):
self.run = False
self.isBack = True
self.appRunWorker.setRunState(False)
self.getInfoWorker.setRunState(False)
self.downloadFileWorker.setRunState(False)
self.appRunThread.quit()
self.appRunThread.wait()
self.syncMagnetDllService.SetCanDeviceState(False)
self.getInfoWorker.setRunState(False)
self.getInfoThread.quit()
self.getInfoThread.wait()
self.downloadFileThread.quit()
self.downloadFileThread.wait()
if getattr(self,"downloadFileWorker",None):
self.downloadFileWorker.setRunState(False)
self.downloadFileThread.quit()
self.downloadFileThread.wait()
self.close()
self.syncMagnetDllService.ManageDllFinished()

Expand Down Expand Up @@ -997,7 +1007,7 @@ def goHomePage(self):
self.downloadFileWorker.setRunState(False)
self.downloadFileThread.quit()
self.downloadFileThread.wait()
self.syncMagnetDllService.SetCanDeviceState()
self.syncMagnetDllService.SetCanDeviceState(True)

def goUploadPage(self):
self.stackedWidget.setCurrentIndex(2)
Expand All @@ -1013,9 +1023,10 @@ def goUploadPage(self):
self.downloadFileWorker.setRunState(False)
self.downloadFileThread.quit()
self.downloadFileThread.wait()
self.syncMagnetDllService.SetCanDeviceState()
self.syncMagnetDllService.SetCanDeviceState(True)

def goDownloadPage(self):
self.syncMagnetDllService.SetCanDeviceState(False)
self.stackedWidget.setCurrentIndex(1)
self.label_top_info_2.setText("| DOWNLOAD")
root = ET.parse(r".\MagnetManifest.xml")
Expand Down Expand Up @@ -1056,7 +1067,13 @@ def loadPage(self, isShow: bool):
QTimer.singleShot(5000,lambda: self.loadWindowClosed())

def loadWindowOpened(self):
self.isloadPageOpen = True
self.loadWindow = LoadWindow(self,self.syncMagnetDllService,self.isDownload)
load_window_size = self.loadWindow.size()
main_window_size = self.size()
x = (main_window_size.width() - load_window_size.width()) / 2
y = (main_window_size.height() - load_window_size.height()) / 2
self.loadWindow.setGeometry(x, y, load_window_size.width(), load_window_size.height())
self.loadWindow.show()
self.homeMenuButton.setEnabled(False)
self.uploadButton.setEnabled(False)
Expand All @@ -1065,14 +1082,14 @@ def loadWindowOpened(self):
self.downloadButton.setEnabled(False)
self.selectAllButton.setEnabled(False)
self.sendButton.setEnabled(False)
self.btn_close.setEnabled(False)
self.btn_maximize_restore.setEnabled(False)
self.btn_minimize.setEnabled(False)
self.btn_toggle_menu.setEnabled(False)
self.openDownloadFolderButton.setEnabled(False)

def loadWindowClosed(self):
try:
self.isloadPageOpen = False
self.loadWindow.close()
self.loadWindow = None
self.homeMenuButton.setEnabled(True)
Expand All @@ -1082,7 +1099,6 @@ def loadWindowClosed(self):
self.downloadButton.setEnabled(True)
self.selectAllButton.setEnabled(True)
self.sendButton.setEnabled(True)
self.btn_close.setEnabled(True)
self.btn_maximize_restore.setEnabled(True)
self.btn_minimize.setEnabled(True)
self.btn_toggle_menu.setEnabled(True)
Expand Down Expand Up @@ -1180,14 +1196,15 @@ def onDownloadWorkerCompleted(self, param: dict):
getFiles = [file.attrib['file'] for file in root.findall(".//GetFile")]
for row, file_info in enumerate(getFiles):
print(row,"<---->" ,file_info)
if file_info not in param['dFiles']:
if file_info not in CACHE_DOWNLOAD_FILE_NAME:
CACHE_DOWNLOAD_FILE_NAME.add(file_info)
self.downloadedFilesTable.insertRow(row)
size_item = QTableWidgetItem(self.syncMagnetDllService.formatSize(os.path.getsize(os.path.join(self.label_top_info_1.text(),file_info))))
size_item.setIcon(QIcon(":/16x16/assets/16x16/cil-check-alt.png"))
name_item = QTableWidgetItem(file_info)
self.downloadedFilesTable.setItem(row, 0, size_item)
self.downloadedFilesTable.setItem(row, 1, name_item)
print("YÜKLEME İŞLEMİ BİTTİ TABLE WIDGET'A EKLENDİ")
print("YÜKLEME İŞLEMİ BİTTİ")

def toggleMenu(self, maxWidth, enable):
isHidden = False
Expand Down
Loading

0 comments on commit 16418ed

Please sign in to comment.