Seems like it almost works.

This commit is contained in:
Victorious Children Studios 2023-12-18 20:12:00 +02:00
parent 5e7052b3ab
commit ceaffe4569
4 changed files with 111 additions and 16 deletions

View file

@ -5,6 +5,7 @@ import os
import json import json
import time import time
import fnmatch import fnmatch
import threading
import hashlib import hashlib
import urllib.request import urllib.request
import urllib.parse import urllib.parse
@ -88,6 +89,9 @@ def down(win, website, filename, fsize=100000):
response = urllib.request.urlopen(url) response = urllib.request.urlopen(url)
savef = open(win.project+filename, "wb") savef = open(win.project+filename, "wb")
sofar = 0 sofar = 0
chunk = response.read(8192) chunk = response.read(8192)
while chunk: while chunk:
@ -99,6 +103,26 @@ def down(win, website, filename, fsize=100000):
savef.close() 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): def get_folder_info(win, folders, cur):
@ -120,6 +144,7 @@ def get_folder_info(win, folders, cur):
def sort_file(filename, files, f): def sort_file(filename, files, f):
filedata = files.get(f, {}) filedata = files.get(f, {})
filedata["finished"] = False
try: try:
hashis = hashlib.md5(open(win.project+filename,'rb').read()).hexdigest() hashis = hashlib.md5(open(win.project+filename,'rb').read()).hexdigest()
except: except:
@ -510,6 +535,17 @@ def prompt_layer(win, call):
win.current["h"]-200, win.current["h"]-200,
10) 10)
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 # Exit button
def do(): def do():
win.current["calls"][call]["var"] = False win.current["calls"][call]["var"] = False
@ -525,6 +561,53 @@ def prompt_layer(win, call):
icon="cancel", icon="cancel",
tip=talk.text("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 # Clipping everything
UI_elements.roundrect(layer, win, UI_elements.roundrect(layer, win,
win.current["w"]/2-350, win.current["w"]/2-350,
@ -545,7 +628,7 @@ def prompt_layer(win, call):
if "http-prompt" not in win.scroll: if "http-prompt" not in win.scroll:
win.scroll["http-prompt"] = 0 win.scroll["http-prompt"] = 0
cur = win.current["remote-folder-data"]["prompt"]
current_Y = 0 current_Y = 0
@ -584,6 +667,12 @@ def prompt_layer(win, call):
if win.current["remote-folder-data"][cur]["missing_active"]: if win.current["remote-folder-data"][cur]["missing_active"]:
for f in win.current["remote-folder-data"][cur]["missing"]: 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") UI_color.set(layer, win, "text_normal")
layer.set_font_size(20) layer.set_font_size(20)
layer.move_to(win.current["w"]/2-270, 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] fdata = win.current["remote-folder-data"][cur]["changed"][f]
if fdata.get("finished"):
continue
icon = "unchecked" icon = "unchecked"
if fdata["to_download"]: if fdata["to_download"]:
icon = "checked" icon = "checked"

View file

@ -288,3 +288,4 @@ remote-server-url = [The hostname of the remote server.]
MissingFiles = [Missing Files] MissingFiles = [Missing Files]
ChangedFiles = [Changed Files] ChangedFiles = [Changed Files]
RemoteAssetUpdates = [Remote Asset Updates] RemoteAssetUpdates = [Remote Asset Updates]
DownloadRemoteServer = [Download Files]

Binary file not shown.

After

Width:  |  Height:  |  Size: 750 B

View file

@ -198,6 +198,8 @@ def run(project, win):
win.current["camera_arrived"] = False win.current["camera_arrived"] = False
# Remote server stuff # Remote server stuff
win.current["http-server"] = {"message":"",
"fileprog": 0}
win.current["in-asset-remote-server"] = True win.current["in-asset-remote-server"] = True