From ceaffe4569984e892361e0c07bc48d0552668bc2 Mon Sep 17 00:00:00 2001 From: Victorious Children Studios Date: Mon, 18 Dec 2023 20:12:00 +0200 Subject: [PATCH] Seems like it almost works. --- network/http_client.py | 122 ++++++++++++++++++--- settings/languages/English.data | 3 +- settings/themes/Default/icons/download.png | Bin 0 -> 750 bytes studio/studio_gtk.py | 2 + 4 files changed, 111 insertions(+), 16 deletions(-) create mode 100644 settings/themes/Default/icons/download.png diff --git a/network/http_client.py b/network/http_client.py index 0380b09..0867463 100644 --- a/network/http_client.py +++ b/network/http_client.py @@ -5,6 +5,7 @@ import os import json import time import fnmatch +import threading import hashlib import urllib.request import urllib.parse @@ -88,6 +89,9 @@ def down(win, website, filename, fsize=100000): response = urllib.request.urlopen(url) savef = open(win.project+filename, "wb") + + + sofar = 0 chunk = response.read(8192) while chunk: @@ -99,7 +103,27 @@ def down(win, website, filename, fsize=100000): savef.close() +def download_missing_changed(win, cur): + # This function downloads files from remote server using the + # remote-folder-data data. + + website = win.analytics["remote-server-url"] + + for t in ["missing", "changed"]: + while win.current["remote-folder-data"][cur][t]: # IDK WHAT I'M DOING!!! + try: + for f in win.current["remote-folder-data"][cur][t]: + fdata = win.current["remote-folder-data"][cur][t][f] + if fdata.get("to_download", True): + print("Downloading", f) + down(win, website, f, fdata.get("filesize", 10000)) + del win.current["remote-folder-data"][cur][t][f] + except: + pass + + win.current["remote-folder-data"][cur]["downloading"] = False + def get_folder_info(win, folders, cur): # This function gets an information of what files should be changed. And outputs @@ -120,6 +144,7 @@ def get_folder_info(win, folders, cur): def sort_file(filename, files, f): filedata = files.get(f, {}) + filedata["finished"] = False try: hashis = hashlib.md5(open(win.project+filename,'rb').read()).hexdigest() except: @@ -510,21 +535,79 @@ def prompt_layer(win, call): win.current["h"]-200, 10) - # Exit button - def do(): - win.current["calls"][call]["var"] = False - - - UI_elements.roundrect(layer, win, - win.current["w"]/2+310, - win.current["h"]-140, - 40, - 40, - 10, - button=do, - icon="cancel", - tip=talk.text("cancel")) + + cur = win.current["remote-folder-data"]["prompt"] + + + if "downloading" not in win.current["remote-folder-data"][cur]: + win.current["remote-folder-data"][cur]["downloading"] = False + + if not win.current["remote-folder-data"][cur]["downloading"]: + + + # Exit button + def do(): + win.current["calls"][call]["var"] = False + + + UI_elements.roundrect(layer, win, + win.current["w"]/2+310, + win.current["h"]-140, + 40, + 40, + 10, + button=do, + icon="cancel", + tip=talk.text("cancel")) + + # Download button + def do(): + win.current["remote-folder-data"][cur]["downloading"] = True + + start_downaloding = threading.Thread(target=download_missing_changed, + args=(win, cur, )) + start_downaloding.setDaemon(True) + start_downaloding.start() + + + UI_elements.roundrect(layer, win, + win.current["w"]/2+270, + win.current["h"]-140, + 40, + 40, + 10, + button=do, + icon="download", + tip=talk.text("DownloadRemoteServer")) + + else: + + # Progress bar + + UI_color.set(layer, win, "progress_background") + UI_elements.roundrect(layer, win, + win.current["w"]/2-200, + win.current["h"]-140, + 400, + 20, + 10, + tip="Hello") + + UI_color.set(layer, win, "progress_active") + UI_elements.roundrect(layer, win, + win.current["w"]/2-200, + win.current["h"]-140, + 400*max(0, min(1, win.current["http-server"]["fileprog"])), + 20, + 10,) + + UI_color.set(layer, win, "text_normal") + layer.set_font_size(15) + layer.move_to(win.current["w"]/2-180, + win.current["h"]-145) + layer.show_text(win.current["http-server"]["message"]) + # Clipping everything UI_elements.roundrect(layer, win, win.current["w"]/2-350, @@ -545,7 +628,7 @@ def prompt_layer(win, call): if "http-prompt" not in win.scroll: win.scroll["http-prompt"] = 0 - cur = win.current["remote-folder-data"]["prompt"] + current_Y = 0 @@ -584,6 +667,12 @@ def prompt_layer(win, call): if win.current["remote-folder-data"][cur]["missing_active"]: for f in win.current["remote-folder-data"][cur]["missing"]: + + fdata = win.current["remote-folder-data"][cur]["missing"][f] + + if fdata.get("finished"): + continue + UI_color.set(layer, win, "text_normal") layer.set_font_size(20) layer.move_to(win.current["w"]/2-270, @@ -631,6 +720,9 @@ def prompt_layer(win, call): fdata = win.current["remote-folder-data"][cur]["changed"][f] + if fdata.get("finished"): + continue + icon = "unchecked" if fdata["to_download"]: icon = "checked" diff --git a/settings/languages/English.data b/settings/languages/English.data index 8e532f1..85fa116 100644 --- a/settings/languages/English.data +++ b/settings/languages/English.data @@ -287,4 +287,5 @@ the downloaded files.] remote-server-url = [The hostname of the remote server.] MissingFiles = [Missing Files] ChangedFiles = [Changed Files] -RemoteAssetUpdates = [Remote Asset Updates] \ No newline at end of file +RemoteAssetUpdates = [Remote Asset Updates] +DownloadRemoteServer = [Download Files] \ No newline at end of file diff --git a/settings/themes/Default/icons/download.png b/settings/themes/Default/icons/download.png new file mode 100644 index 0000000000000000000000000000000000000000..965773825c0bbe3cc6fa690ca03c9fcade1f8ed3 GIT binary patch literal 750 zcmVEX>4Tx04R}tkv&MmKpe$iTcsiuQ9DR+2vVIah>AFB6^c+H)C#RSm|Xe=O&XFE z7e~Rh;NZt%)xpJCR|i)?5c~jfb#YR3krMxx6k5c1aNLh~_a1le0DryARI_6oP&La) zCE`LRyD9`<5kf!u5W%p-Onpuilkgm0_we!cF2=LG&;2=il$^-`pFljzbi*RvAfDc| zbk6(4VOEqB;&b9LgDyz?$aUG}H_ioz{X8>lq*L?6VPc`s#&R38qM;H`5l0nOqkMnH zWrgz=XSG~q&3p0}hH~1 zax9<%6_Voz|AXJ%n)%5IHz^bcI$v!2V+0890*#t&e;?a+;{*si16NwhU#SB#pQP7X zTJ#9$-3BhMTbjHFTnGy0}1FmMZWuerT7_i_3Fq^Yaq4RCM> zj20++-Q(R|?Y;ebrrF;QeK&HencH!|00006VoOIv04M+~05^dc#W4T?010qNS#tmY z4c7nw4c7reD4Tcy000McNliru=L`}N926Nmv*-W-0P9IaK~z}7?bbUA!axwl@ma|Q zBqG65tUZO`i9*ieRV zRX|`0obAvRSakhjDMaRhz2mBoE^shh8In(i#W~0T$Q&fO?+gfrenq>Lbkoa)2!XHx zvK9`AfT(PaSFy*c&OwYZPhcY=dl5lIw#Jx8jit+~30_;(wxG54Vg>#fujXyujkSXJ g9t=0pXf%JE7x2bxPFRBRGXMYp07*qoM6N<$f^lI$9smFU literal 0 HcmV?d00001 diff --git a/studio/studio_gtk.py b/studio/studio_gtk.py index bb54c92..6aa6043 100644 --- a/studio/studio_gtk.py +++ b/studio/studio_gtk.py @@ -198,6 +198,8 @@ def run(project, win): win.current["camera_arrived"] = False # Remote server stuff + win.current["http-server"] = {"message":"", + "fileprog": 0} win.current["in-asset-remote-server"] = True