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 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"

View file

@ -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]
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
# Remote server stuff
win.current["http-server"] = {"message":"",
"fileprog": 0}
win.current["in-asset-remote-server"] = True