From 0623bde34e7aaa21c99ffbce9058a7bfb717dcb2 Mon Sep 17 00:00:00 2001 From: sam-teng <70181350+sam-teng@users.noreply.github.com> Date: Sun, 21 Aug 2022 16:40:58 +0800 Subject: [PATCH] update-dataV0.0.1-beta.1 v0.0.1-beta1 Add files via upload Fix the bugs Add new function --- pythonController-autoUpdate/__main__V0_10.py | 149 +++++++ pythonController-autoUpdate/__main__V0_11.py | 160 +++++++ pythonController-autoUpdate/__main__V0_8.py | 125 ++++++ pythonController-autoUpdate/__main__V0_9.py | 149 +++++++ .../cheakUpdateV0_4.py | 378 +++++++++++++++++ pythonController-autoUpdate/config | 4 +- pythonController-autoUpdate/configV0.0.0.txt | 4 + pythonController-autoUpdate/info | 2 +- pythonController-autoUpdate/version | 2 +- pythonController-autoUpdate/versionV0.0.0.txt | 1 + .../webDownloader-beta2.11.2.py | 2 +- .../webDownloader-beta2.11.7.py | 390 ++++++++++++++++++ 12 files changed, 1362 insertions(+), 4 deletions(-) create mode 100644 pythonController-autoUpdate/__main__V0_10.py create mode 100644 pythonController-autoUpdate/__main__V0_11.py create mode 100644 pythonController-autoUpdate/__main__V0_8.py create mode 100644 pythonController-autoUpdate/__main__V0_9.py create mode 100644 pythonController-autoUpdate/cheakUpdateV0_4.py create mode 100644 pythonController-autoUpdate/configV0.0.0.txt create mode 100644 pythonController-autoUpdate/versionV0.0.0.txt create mode 100644 pythonController-autoUpdate/webDownloader-beta2.11.7.py diff --git a/pythonController-autoUpdate/__main__V0_10.py b/pythonController-autoUpdate/__main__V0_10.py new file mode 100644 index 0000000..0ce04cb --- /dev/null +++ b/pythonController-autoUpdate/__main__V0_10.py @@ -0,0 +1,149 @@ +# -*- coding: UTF-8 -*- +from tkinter import * +from tkinter import messagebox + +import os +import threading + +import run +from run import main#,setting + +root = Tk() +root.title("Mune")#ch16_8 +root.geometry("300x180") +root.iconbitmap('unicorn') # 更改左上角的icon圖示 + +try: + basePath = "./" +except: + basePath = os.getcwd().replace("\\", "/")+"/" + +E_count = 0 + +def _cheakUpdate(): + + from cheakUpdateV0_4 import __init__ + global E_count + fileName = "webDownloader-beta2.11.7" + file_name = "webDoenloader-" + #file_name.split(".").pop() + + #i = 0 + with open(os.path.join(basePath,"config"),"r") as config: + config = config.read() + print("config:",config) + for c in config.split(",\n"): + #print(file_name,c) + #i += 1 + if file_name in c: + #i -= 1 + fileName = c + + break + #print("i:",i) + + #if not i == 1: + #return + if not os.path.isfile(os.path.join(basePath,fileName+".exe")): + try: + exec(open(fileName+".py","rb").read()) + return False + except: + """ + try: + + t[1] = threading.Thread(target = r'from fileName import *') + + rlock1 = t[1].RLock() + semaphore1 = t[1].Semaphore(1) + rlock1.acquire() + semaphore1.acquire() + # 執行該子執行緒 + t[1].start() + t[1].join() + rlock1.release() + semaphore1.release() + except: + return + finally: + pass + """ + E_count += 1 + print("Can not find the Downloader!") + tkinter.messagebox.showinfo("ERROR", "更新錯誤") + return True + elif not os.path.isfile(os.path.join(basePath,fileName+".py")): + try: + os.system(fileName+".exe") + return False + except: + E_count += 1 + print("Can not find the Downloader!") + tkinter.messagebox.showinfo("ERROR", "更新錯誤") + return True + else: + print("Can not find the Downloader!") + tkinter.messagebox.showinfo("ERROR", "更新錯誤") + cheakUpdate() + if E_count >= 5: + print("Can not find the Downloader!") + tkinter.messagebox.showinfo("ERROR", "更新錯誤") + return False + +#檢查更新 +#while cheakUpdate(): +#_cheakUpdate() + +""" +fr = "" +with open("webDownloader-beta2.6.py","rb") as fr: + fr = fr.read() + #print(fr) +""" +def __init__(): + t = [] + t.append(threading.Thread(target = __main__())) + t.append(threading.Thread(target = _cheakUpdate())) + + for th in range(len(t)): + t[th].start() + if th == 0: + continue + #while _cheakUpdate(): + t[th].join() + if th <= len(t): + th += 1 + +def _exit(): + run._exit() + root.destroy() + exit() + +def __main__(): + menubar = Menu(root) # 建立最上層功能表 + # 建立功能表類別物件,和將此功能表類別命名File + filemenu = Menu(menubar,tearoff=False) + menubar.add_cascade(label="File",menu=filemenu,underline=0) + # 在File功能表內建立功能表清單 + updatamenu = Menu(filemenu,tearoff=False) # 取消分隔線 + filemenu.add_cascade(label="Help",menu=updatamenu,underline=0) + # 首先在File功能表內建立updata子功能表物件 + updatamenu.add_command(label="cheakUpdata",command=_cheakUpdate,underline=0) + # 首先在File功能表內建立find子功能表物件 + #findmenu.add_command(label="game_socket-client_2P-GUIv2.1.py",command=game_s_cli_2) + #findmenu.add_command(label="game_socket-server_2P-GUIv2.1.py",command=game_s_ser_2) + + gamemenu = Menu(menubar,tearoff=False) # 取消分隔線 + menubar.add_cascade(label="Game",menu=gamemenu) + gamemenu.add_command(label="game_socket-client_2P-GUIv2.2",command=main("client")) + gamemenu.add_command(label="game_socket-server_2P-GUIv2.2",command=main("server")) + + # 下列是增加分隔線和建立Exit!指令 + filemenu.add_separator() + filemenu.add_command(label="Exit!",command=_exit,underline=0) + + root.config(menu=menubar) # 顯示功能表物件 + root.mainloop() + +if __name__ == '__main__': + __init__() diff --git a/pythonController-autoUpdate/__main__V0_11.py b/pythonController-autoUpdate/__main__V0_11.py new file mode 100644 index 0000000..768e73f --- /dev/null +++ b/pythonController-autoUpdate/__main__V0_11.py @@ -0,0 +1,160 @@ +# -*- coding: UTF-8 -*- +from tkinter import * +from tkinter import messagebox + +import os +import threading + +import run +from run import main,setting + +root = Tk() +root.title("Mune")#ch16_8 +root.geometry("300x180") +root.iconbitmap('unicorn.ico') # 更改左上角的icon圖示 + +try: + basePath = "./" +except: + basePath = os.getcwd().replace("\\", "/")+"/" + +E_count = 0 + +def _cheakUpdate(): + + from cheakUpdateV0_4 import __init__ + global E_count + fileName = "webDownloader-beta2.11.7" + file_name = "webDoenloader-" + #file_name.split(".").pop() + + #i = 0 + with open(os.path.join(basePath,"config"),"r") as config: + config = config.read() + print("config:",config) + for c in config.split(",\n"): + #print(file_name,c) + #i += 1 + if file_name in c: + #i -= 1 + fileName = c + + break + #print("i:",i) + + #if not i == 1: + #return + if not os.path.isfile(os.path.join(basePath,fileName+".exe")): + try: + exec(open(fileName+".py","rb").read()) + return False + except: + """ + try: + + t[1] = threading.Thread(target = r'from fileName import *') + + rlock1 = t[1].RLock() + semaphore1 = t[1].Semaphore(1) + rlock1.acquire() + semaphore1.acquire() + # 執行該子執行緒 + t[1].start() + t[1].join() + rlock1.release() + semaphore1.release() + except: + return + finally: + pass + """ + E_count += 1 + print("Can not find the Downloader!") + tkinter.messagebox.showinfo("ERROR", "更新錯誤") + return True + elif not os.path.isfile(os.path.join(basePath,fileName+".py")): + try: + os.system(fileName+".exe") + return False + except: + E_count += 1 + print("Can not find the Downloader!") + tkinter.messagebox.showinfo("ERROR", "更新錯誤") + return True + else: + print("Can not find the Downloader!") + tkinter.messagebox.showinfo("ERROR", "更新錯誤") + cheakUpdate() + if E_count >= 5: + print("Can not find the Downloader!") + tkinter.messagebox.showinfo("ERROR", "更新錯誤") + return False + +#檢查更新 +#while cheakUpdate(): +#_cheakUpdate() + +""" +fr = "" +with open("webDownloader-beta2.6.py","rb") as fr: + fr = fr.read() + #print(fr) +""" +def __init__(): + t = [] + t.append(threading.Thread(target = __main__())) + t.append(threading.Thread(target = _cheakUpdate())) + + for th in range(len(t)): + try: + t[th].start() + except: + t[th].join() + for th in range(len(t)): + if th == 0: + continue + #while _cheakUpdate(): + t[th].join() + """ + if th <= len(t): + th += 1 + """ + +def _exit(): + root.destroy() + run._exit() + exit() + +def __main__(): + menubar = Menu(root) # 建立最上層功能表 + # 建立功能表類別物件,和將此功能表類別命名File + filemenu = Menu(menubar,tearoff=False) + menubar.add_cascade(label="File",menu=filemenu,underline=0) + # 在File功能表內建立功能表清單 + updatamenu = Menu(filemenu,tearoff=False) # 取消分隔線 + filemenu.add_cascade(label="Help",menu=updatamenu,underline=0) + # 首先在File功能表內建立updata子功能表物件 + updatamenu.add_command(label="cheakUpdata",command=_cheakUpdate,underline=0) + # 首先在File功能表內建立find子功能表物件 + #findmenu.add_command(label="game_socket-client_2P-GUIv2.1.py",command=game_s_cli_2) + #findmenu.add_command(label="game_socket-server_2P-GUIv2.1.py",command=game_s_ser_2) + + gamemenu = Menu(menubar,tearoff=False) # 取消分隔線 + menubar.add_cascade(label="Game",menu=gamemenu) + gamemenu.add_command(label="(selet) game_socket-2P-GUIv2.2",command=main) + #gamemenu.add_command(label="game_socket-client_2P-GUIv2.2",command=main) + #gamemenu.add_command(label="game_socket-server_2P-GUIv2.2",command=main) + + settingmenu = Menu(menubar,tearoff=False) # 取消分隔線 + menubar.add_cascade(label="Game Setting",menu=settingmenu) + settingmenu.add_command(label="Setting",command=setting,underline=0) + + # 下列是增加分隔線和建立Exit!指令 + filemenu.add_separator() + filemenu.add_command(label="Exit!",command=_exit,underline=0) + + root.config(menu=menubar) # 顯示功能表物件 + root.mainloop() + +if __name__ == '__main__': + __init__() diff --git a/pythonController-autoUpdate/__main__V0_8.py b/pythonController-autoUpdate/__main__V0_8.py new file mode 100644 index 0000000..b7b2861 --- /dev/null +++ b/pythonController-autoUpdate/__main__V0_8.py @@ -0,0 +1,125 @@ +# -*- coding: UTF-8 -*- +from tkinter import * +from tkinter import messagebox + +import os +import threading + +from cheakUpdateV0_3 import * +from run import main,setting + +root = Tk() +root.title("Mune")#ch16_8 +root.geometry("300x180") +root.iconbitmap('unicorn') # 更改左上角的icon圖示 + +menubar = Menu(root) # 建立最上層功能表 +# 建立功能表類別物件,和將此功能表類別命名File +filemenu = Menu(menubar,tearoff=False) +menubar.add_cascade(label="File",menu=filemenu,underline=0) +# 在File功能表內建立功能表清單 +updatamenu = Menu(filemenu,tearoff=False) # 取消分隔線 +filemenu.add_cascade(label="Help",menu=updatamenu,underline=0) +# 首先在File功能表內建立updata子功能表物件 +updatamenu.add_command(label="cheakUpdata",command=cheakUpdate,underline=0) +# 首先在File功能表內建立find子功能表物件 +#findmenu.add_command(label="game_socket-client_2P-GUIv2.1.py",command=game_s_cli_2) +#findmenu.add_command(label="game_socket-server_2P-GUIv2.1.py",command=game_s_ser_2) + +gamemenu = Menu(menubar,tearoff=False) # 取消分隔線 +menubar.add_cascade(label="Game",menu=gamemenu) +gamemenu.add_command(label="game_socket-client_2P-GUIv2.2",command=main("client")) +gamemenu.add_command(label="game_socket-server_2P-GUIv2.2",command=main("server")) + +# 下列是增加分隔線和建立Exit!指令 +filemenu.add_separator() +filemenu.add_command(label="Exit!",command=root.destroy,underline=0) + +root.config(menu=menubar) # 顯示功能表物件 + +E_count = 0 + +def _cheakUpdate(): + fileName = "webDownloader-beta2.6" + file_name = "webDoenloader-" + #file_name.split(".").pop() + + #i = 0 + with open(self.file_source+"config","r") as config: + config = config.read() + print("config:",config) + for c in config.split(",\n"): + #print(file_name,c) + #i += 1 + if file_name in c: + #i -= 1 + fileName = c + + break + #print("i:",i) + + #if not i == 1: + #return + if not os.path.isfile(os.path.join(basePath,fileName+".exe")): + try: + exec(open(fileName+".py","rb").read()) + except: + """ + try: + + t[1] = threading.Thread(target = r'from fileName import *') + + rlock1 = t[1].RLock() + semaphore1 = t[1].Semaphore(1) + rlock1.acquire() + semaphore1.acquire() + # 執行該子執行緒 + t[1].start() + t[1].join() + rlock1.release() + semaphore1.release() + except: + return + finally: + pass + """ + E_count += 1 + print("Can not find the Downloader!") + tkinter.messagebox.showinfo("ERROR", "更新錯誤") + return + elif not os.path.isfile(os.path.join(basePath,fileName+".py")): + try: + os.system(fileName+".exe") + except: + E_count += 1 + print("Can not find the Downloader!") + tkinter.messagebox.showinfo("ERROR", "更新錯誤") + return + else: + print("Can not find the Downloader!") + tkinter.messagebox.showinfo("ERROR", "更新錯誤") + cheakUpdate() + if E_count >= 5: + print("Can not find the Downloader!") + tkinter.messagebox.showinfo("ERROR", "更新錯誤") + +#檢查更新 +#while cheakUpdate(): +#_cheakUpdate() + +""" +fr = "" +with open("webDownloader-beta2.6.py","rb") as fr: + fr = fr.read() + #print(fr) +""" +def init(): + t = [] + t.append(threading.Thread(target = root.mainloop())) + t.append(threading.Thread(target = _cheakUpdate())) + + for th in range(len(t)): + t[th].start() + if th == 0: + continue + t[th].join() diff --git a/pythonController-autoUpdate/__main__V0_9.py b/pythonController-autoUpdate/__main__V0_9.py new file mode 100644 index 0000000..d250cc0 --- /dev/null +++ b/pythonController-autoUpdate/__main__V0_9.py @@ -0,0 +1,149 @@ +# -*- coding: UTF-8 -*- +from tkinter import * +from tkinter import messagebox + +import os +import threading + +import run +from run import main,setting + +root = Tk() +root.title("Mune")#ch16_8 +root.geometry("300x180") +root.iconbitmap('unicorn') # 更改左上角的icon圖示 + +try: + basePath = "./" +except: + basePath = os.getcwd().replace("\\", "/")+"/" + +E_count = 0 + +def _cheakUpdate(): + + from cheakUpdateV0_4 import __init__ + global E_count + fileName = "webDownloader-beta2.11.6" + file_name = "webDoenloader-" + #file_name.split(".").pop() + + #i = 0 + with open(os.path.join(basePath,"config"),"r") as config: + config = config.read() + print("config:",config) + for c in config.split(",\n"): + #print(file_name,c) + #i += 1 + if file_name in c: + #i -= 1 + fileName = c + + break + #print("i:",i) + + #if not i == 1: + #return + if not os.path.isfile(os.path.join(basePath,fileName+".exe")): + try: + exec(open(fileName+".py","rb").read()) + return False + except: + """ + try: + + t[1] = threading.Thread(target = r'from fileName import *') + + rlock1 = t[1].RLock() + semaphore1 = t[1].Semaphore(1) + rlock1.acquire() + semaphore1.acquire() + # 執行該子執行緒 + t[1].start() + t[1].join() + rlock1.release() + semaphore1.release() + except: + return + finally: + pass + """ + E_count += 1 + print("Can not find the Downloader!") + tkinter.messagebox.showinfo("ERROR", "更新錯誤") + return True + elif not os.path.isfile(os.path.join(basePath,fileName+".py")): + try: + os.system(fileName+".exe") + return False + except: + E_count += 1 + print("Can not find the Downloader!") + tkinter.messagebox.showinfo("ERROR", "更新錯誤") + return True + else: + print("Can not find the Downloader!") + tkinter.messagebox.showinfo("ERROR", "更新錯誤") + cheakUpdate() + if E_count >= 5: + print("Can not find the Downloader!") + tkinter.messagebox.showinfo("ERROR", "更新錯誤") + return False + +#檢查更新 +#while cheakUpdate(): +#_cheakUpdate() + +""" +fr = "" +with open("webDownloader-beta2.6.py","rb") as fr: + fr = fr.read() + #print(fr) +""" +def __init__(): + t = [] + t.append(threading.Thread(target = __main__())) + t.append(threading.Thread(target = _cheakUpdate())) + + for th in range(len(t)): + t[th].start() + if th == 0: + continue + #while _cheakUpdate(): + t[th].join() + if th <= len(t): + th += 1 + +def _exit(): + run._exit() + root.destroy() + exit() + +def __main__(): + menubar = Menu(root) # 建立最上層功能表 + # 建立功能表類別物件,和將此功能表類別命名File + filemenu = Menu(menubar,tearoff=False) + menubar.add_cascade(label="File",menu=filemenu,underline=0) + # 在File功能表內建立功能表清單 + updatamenu = Menu(filemenu,tearoff=False) # 取消分隔線 + filemenu.add_cascade(label="Help",menu=updatamenu,underline=0) + # 首先在File功能表內建立updata子功能表物件 + updatamenu.add_command(label="cheakUpdata",command=_cheakUpdate,underline=0) + # 首先在File功能表內建立find子功能表物件 + #findmenu.add_command(label="game_socket-client_2P-GUIv2.1.py",command=game_s_cli_2) + #findmenu.add_command(label="game_socket-server_2P-GUIv2.1.py",command=game_s_ser_2) + + gamemenu = Menu(menubar,tearoff=False) # 取消分隔線 + menubar.add_cascade(label="Game",menu=gamemenu) + gamemenu.add_command(label="game_socket-client_2P-GUIv2.2",command=main("client")) + gamemenu.add_command(label="game_socket-server_2P-GUIv2.2",command=main("server")) + + # 下列是增加分隔線和建立Exit!指令 + filemenu.add_separator() + filemenu.add_command(label="Exit!",command=_exit,underline=0) + + root.config(menu=menubar) # 顯示功能表物件 + root.mainloop() + +if __name__ == '__main__': + __init__() diff --git a/pythonController-autoUpdate/cheakUpdateV0_4.py b/pythonController-autoUpdate/cheakUpdateV0_4.py new file mode 100644 index 0000000..4c7fe61 --- /dev/null +++ b/pythonController-autoUpdate/cheakUpdateV0_4.py @@ -0,0 +1,378 @@ +import os,site +import time +import sys +#import urllib #urllib2.urlopen + +if sys.version_info >= (3, 0): + import urllib +else: + # Import urllib2 to catch errors + import urllib2 + +import requests + +import threading + +from tkinter import * +from tkinter.ttk import * +import tkinter.messagebox + +from cheakfileV1_5_3 import * #cheakFile,replaceFile + +root = Tk() +root.title("cheakUpdate") +with open("unicorn", "rb") as ico: + with open("unicorn.ico", "wb") as icof: + icof.write(ico.read()) +try: + root.iconbitmap('unicorn.ico') # 更改左上角的icon圖示 +except IOError as e: + try: + root.iconbitmap('unicorn') # 更改左上角的icon圖示 + except FileError as e: + print("Can not find the icon") + +_bytes = 0 # 設定初值 +maxbytes = 10000 # 假設下載檔案大小 +state = 0 +count = 0 +i = 0 +lenght = 0 + +th = [] +t = [] + +fn = None +data = """\ +https://github.com/sam-teng/update-data/archive/refs/heads/main.zip, +""" + +""", +https://github.com/sam-teng/update-data/blob/main/pythonGame-autoUpdate/game_socket-client_2P-GUIv2.py, +https://github.com/sam-teng/update-data/blob/main/pythonGame-autoUpdate/game_socket-server_2P-GUIv2.py, +https://github.com/sam-teng/update-data/blob/main/pythonGame-autoUpdate/view.py + +""" + +def _exec(): + with open("updatefile.py","rb") as fr: + fr = fr.read() + print(fr) + exec(fr) +def main(): + """ + rl = threading.RLock() + sem = threading.Semaphore(2) + rl.acquire() + sem.acquire() + """ + root.mainloop() + """ + rl.release() + sem.release() + """ + +pb = Progressbar(root,length=200,mode="determinate",orient=HORIZONTAL)#mode="indeterminate" +pb.pack(padx=10,pady=10) +#pb["value"] = 0 # Prograssbar初始值 +#pb["maximum"] = maxbytes # Prograddbar最大值 + +def load(): # 啟動Prograssbar + """ + pb = Progressbar(root,length=200,mode="determinate",orient=HORIZONTAL)#mode="indeterminate" + pb.pack(padx=10,pady=10) + """ + pb["value"] = 0 # Prograssbar初始值 + pb["maximum"] = maxbytes # Prograddbar最大值 + + t.append(threading.Thread(target = pb.after(50,loading))) + # 經過0.05秒繼續執行loading + + #loading() + +def loading(): # 模擬下載資料 + + if state == 0: + + """ + pb = Progressbar(root,length=200,mode="determinate",orient=HORIZONTAL)#mode="indeterminate" + pb.pack(padx=10,pady=10) + """ + pb["value"] = 0 # Prograssbar初始值 + pb["maximum"] = maxbytes # Prograddbar最大值 + + t.append(threading.Thread(target = pb.after(50,loading))) + # 經過0.05秒繼續執行loading + + + global _bytes + + if maxbytes == 0 or lenght == 0: + _bytes += maxbytes # 模擬每次下載500bytes + pb["value"] = _bytes # 設定指針 + """ + if state == 0: + t.append(threading.Thread(target = pb.after(50,loading))) + # 經過0.05秒繼續執行loading + """ + return False + elif _bytes < maxbytes: + _bytes += maxbytes//lenght # 模擬每次下載500bytes + pb["value"] = _bytes # 設定指針 + """ + if state == 0: + t.append(threading.Thread(target = pb.after(50,loading))) + # 經過0.05秒繼續執行loading + """ + return False + else: + packageFile(mode="path").main() + #cleanFile() + tkinter.messagebox.showinfo("showinfo", "更新完成") + #root.destroy() + return True + exit() + +def preview(): + global lenght + i = 0 + if fn == None: + if len(list(data)) == 0: + yt_urls = input("enter your file's full url") + else: + yt_urls = data + yt_urls = yt_urls.split(",") + for yt_url in yt_urls: + i += 1 + if yt_url == "": + yt_url = "https://github.com/sam-teng/update-data/blob/main/pythonGame-autoUpdate/game_socket-client_2P-GUIv2.py" + if not "http" in yt_url: + lenght += 1 + continue + lenght = i - lenght + maxbytes = lenght + +def downloads(): + global i + global lenght + # ------ + #import zipfile #zipfile.ZipFile + if fn == None: + if len(list(data)) == 0: + yt_urls = input("enter your file's full url") + else: + yt_urls = data + yt_urls = yt_urls.split(",") + #i = 0 + yt_title = [] + #print("wget is on path %s" % (wget.__file__)) + for yt_url in yt_urls: + + if yt_url == "": + #yt_url = "https://github.com/sam-teng/update-data/blob/main/pythonGame-autoUpdate/game_socket-client_2P-GUIv2.py" + continue + if not "http" in yt_url: + continue + try: + url = yt_url + r = requests.get(url, auth=('user', 'pass'))#https://api.github.com + print(r.status_code) + print(r.headers['content-type']) + + response = requests.get(f'{url}') + print(response) + + + ''' + file_size = os.path.getsize(response.content) + print('File Size:', file_size, 'bytes') + + #time.sleep(0.5) + + """ + filesize = 0 + with open(file_r_path, "rb")as f: + my_bytes = f.read() + my_bytes_array.append(my_bytes) + filesize = 1 + print(my_bytes[0:file_size]) + print(filesize) + """ + file_start_size = (file_size//100)*100 + file_end_size = file_size-file_start_size + """ + with open(""+file_r_path, "rb") as f: + my_bytes = f.read() + """ + my_bytes = response.content + """ + if bool(input("continue bin bytes?")): + #試試看:跟剛才的版本,看到的my_bytes前一百項,有什麼不同? + """ + for i in range(0,file_start_size,100): + print(my_bytes[i+0:i+100]) + print("\n") + time.sleep(0.03) + ii = i + time.sleep(2) + for i in range(ii,file_end_size): + print(my_bytes[i+0:i+100]) + print("\n") + time.sleep(0.03) + print("-==-"*30) + print("file_size",file_size,"\n") + """ + """ + ''' + + test_file_name = str(i)#+".zip" + + pw = "" + with open(test_file_name, 'wb') as file: + #th4.start() + pw = id(file) + file.write(response.content) + file.close() + + import random + pw = bytes((str(pw) + str(pw+random.randint(-pw,pw))).encode("UTF-8")) + + """ + req = urllib.request(url) + downloadurl = urllib.urlopen(req) + zipcontent = downloadurl.read() + with open("%d.py"%(i), 'wb') as f:#with open("%d."+input("請輸入副檔名")%(i), 'wb') as f: + f.write(zipcontent) + """ + """ + w = wget.download(url,out="\\"+str(i)+".zip") + """ + + from zipfile import ZipFile + + try: + import pyminizip + src = None # "..." + compression_level = 5 # 1‑9 + pyminizip.compress(test_file_name, src, test_file_name, pw, compression_level) + except: + with ZipFile(test_file_name, 'a') as Zip: + Zip.setpassword(pw) + Zip.printdir() + + with ZipFile(test_file_name, 'r') as Zip: + Zip.printdir() + Zip.extractall("temp",pwd = pw) + """ + yt = YouTube(yt_url)#YouTube('https://www.youtube.com/channel/UC-9-kyTW8ZkZNDHQJ6FgpwQ') + print('strart downloads: ',yt.title) + path = ""#yt.title + #yt_title = yt_title.join(yt.title) + yt_title.append(yt.title) + """ + """ + if not os.path.exists(path): + os.makedirs(path) + """ + #print(type(yt)) + """ + yt.streams.filter(subtype='mp4').first().download(path)# + print('finish',yt.title,'downloads!') + """ + + #exec(open("cheakfile.py").read()) + + except Exception as e: + print(e,"can't from " + yt_url + "\t download file") + tkinter.messagebox.showinfo("showinfo", "第"+str(i+1)+"項"+"更新失敗") + if i+1 == lenght: + root.destroy() + exit() + #yt_title.remove(yt.title) + finally: + i = i + 1 + time.sleep(3) + + else: + pass + if not loading(): + downloads() + else: + root.destroy() + exit() + pass + +def state(): + global count + if _bytes >= maxbytes: + count += 1 + +def cheakstate(): + if count == 0: + pass#count += 1 + elif count == 1: + tkinter.messagebox.showinfo("showinfo", "更新完成") + + time.sleep(1) + + elif count == 2: + + time.sleep(1.5) + """ + #th.join() + #th0.join() + th1.join() + th3.join() + th4.join() + #th5.join() + th2.join() + """ + + for ths in range(len(th)): + th[ths].join() + exit() + +def __init__(): + #t = [main(),state(),preview(),load(),downloads(),cheakstate()] + """ + th = threading.Thread(target = preview()) + #th0 = threading.Thread(target = _exec()) + th1 = threading.Thread(target = downloads()) + #load() + th2 = threading.Thread(target = main()) + #root.mainloop() + th3 = threading.Thread(target = state()) + #count += 1 + th4 = threading.Thread(target = load()) + #cheakstate() + + th5 = threading.Thread(target = cheakstate()) + """ + ths = 0 + + for ts in t: + th.append(threading.Thread(target = ts)) + th[ths].start() + ths += 1 + """ +#load() +#downloads() +#cheakstate() + th2.start() + + th3.start() + th.start() + th.join() + th4.start()#->move into downloads. + th1.start() + #th0.start() + th5.start() + """ + +tkinter.messagebox.showinfo("showinfo", "更新中請耐心等候") + +t = [state(),preview(),load(),downloads(),cheakstate()]#,main()] + +if __name__ == "__main__": + __init__() + main() diff --git a/pythonController-autoUpdate/config b/pythonController-autoUpdate/config index 2e2a29e..6c2ca3d 100644 --- a/pythonController-autoUpdate/config +++ b/pythonController-autoUpdate/config @@ -1 +1,3 @@ -webDownloader-beta2.11.4.py +runV3.py, +__main__V0_11.py +webDownloader-beta2.11.7.py diff --git a/pythonController-autoUpdate/configV0.0.0.txt b/pythonController-autoUpdate/configV0.0.0.txt new file mode 100644 index 0000000..b3dedd2 --- /dev/null +++ b/pythonController-autoUpdate/configV0.0.0.txt @@ -0,0 +1,4 @@ +game_socket-client_2P-GUIv2.2.py, +game_socket-server_2P-GUIv2.2.py, +viewV3.py, +webDownloader-beta2.11.2.py diff --git a/pythonController-autoUpdate/info b/pythonController-autoUpdate/info index eb6e775..248b2b6 100644 --- a/pythonController-autoUpdate/info +++ b/pythonController-autoUpdate/info @@ -1 +1 @@ -pythonController-autoUpdate \ No newline at end of file +PythonContral \ No newline at end of file diff --git a/pythonController-autoUpdate/version b/pythonController-autoUpdate/version index bd52db8..5b40a7a 100644 --- a/pythonController-autoUpdate/version +++ b/pythonController-autoUpdate/version @@ -1 +1 @@ -0.0.0 \ No newline at end of file +0.0.1-beta0 \ No newline at end of file diff --git a/pythonController-autoUpdate/versionV0.0.0.txt b/pythonController-autoUpdate/versionV0.0.0.txt new file mode 100644 index 0000000..bd52db8 --- /dev/null +++ b/pythonController-autoUpdate/versionV0.0.0.txt @@ -0,0 +1 @@ +0.0.0 \ No newline at end of file diff --git a/pythonController-autoUpdate/webDownloader-beta2.11.2.py b/pythonController-autoUpdate/webDownloader-beta2.11.2.py index 235ce16..3283dbd 100644 --- a/pythonController-autoUpdate/webDownloader-beta2.11.2.py +++ b/pythonController-autoUpdate/webDownloader-beta2.11.2.py @@ -17,7 +17,7 @@ from tkinter.ttk import * import tkinter.messagebox -from cheakfileV1_5_2 import * #cheakFile,replaceFile +from cheakfileV1_5_1 import * #cheakFile,replaceFile root = Tk() root.title("cheakUpdate") diff --git a/pythonController-autoUpdate/webDownloader-beta2.11.7.py b/pythonController-autoUpdate/webDownloader-beta2.11.7.py new file mode 100644 index 0000000..78754c8 --- /dev/null +++ b/pythonController-autoUpdate/webDownloader-beta2.11.7.py @@ -0,0 +1,390 @@ +import os,site +import time +import sys +#import urllib #urllib2.urlopen + +if sys.version_info >= (3, 0): + import urllib +else: + # Import urllib2 to catch errors + import urllib2 + +import requests + +import threading + +from tkinter import * +from tkinter.ttk import * +import tkinter.messagebox + +from cheakfileV1_5_3 import * #cheakFile,replaceFile + +root = Tk() +root.title("cheakUpdate") +with open("unicorn", "rb") as ico: + with open("unicorn.ico", "wb") as icof: + icof.write(ico.read()) +try: + root.iconbitmap('unicorn.ico') # 更改左上角的icon圖示 +except IOError as e: + try: + root.iconbitmap('unicorn') # 更改左上角的icon圖示 + except FileError as e: + print("Can not find the icon") + +_bytes = 0 # 設定初值 +maxbytes = 10000 # 假設下載檔案大小 +state = 0 +count = 0 +i = 0 +lenght = 0 + +th = [] +t = [] + +main_state = None +fn = None +data = """\ +https://github.com/sam-teng/update-data/archive/refs/heads/main.zip, +""" + +""", +https://github.com/sam-teng/update-data/blob/main/pythonGame-autoUpdate/game_socket-client_2P-GUIv2.py, +https://github.com/sam-teng/update-data/blob/main/pythonGame-autoUpdate/game_socket-server_2P-GUIv2.py, +https://github.com/sam-teng/update-data/blob/main/pythonGame-autoUpdate/view.py + +""" + +if __name__ == '__main__': + main_state = True +else: + main_state = False + +def _exec(): + with open("updatefile.py","rb") as fr: + fr = fr.read() + print(fr) + exec(fr) + +def __main__(): + """ + rl = threading.RLock() + sem = threading.Semaphore(2) + rl.acquire() + sem.acquire() + """ + root.mainloop() + """ + rl.release() + sem.release() + """ + +pb = Progressbar(root,length=200,mode="determinate",orient=HORIZONTAL)#mode="indeterminate" +pb.pack(padx=10,pady=10) +#pb["value"] = 0 # Prograssbar初始值 +#pb["maximum"] = maxbytes # Prograddbar最大值 + +def load(): # 啟動Prograssbar + """ + pb = Progressbar(root,length=200,mode="determinate",orient=HORIZONTAL)#mode="indeterminate" + pb.pack(padx=10,pady=10) + """ + pb["value"] = 0 # Prograssbar初始值 + pb["maximum"] = maxbytes # Prograddbar最大值 + + t.append(threading.Thread(target = pb.after(50,loading))) + # 經過0.05秒繼續執行loading + + #loading() + +def loading(): # 模擬下載資料 + + if state == 0: + + """ + pb = Progressbar(root,length=200,mode="determinate",orient=HORIZONTAL)#mode="indeterminate" + pb.pack(padx=10,pady=10) + """ + pb["value"] = 0 # Prograssbar初始值 + pb["maximum"] = maxbytes # Prograddbar最大值 + + t.append(threading.Thread(target = pb.after(50,loading))) + # 經過0.05秒繼續執行loading + + + global _bytes + + if maxbytes == 0 or lenght == 0: + _bytes += maxbytes # 模擬每次下載500bytes + pb["value"] = _bytes # 設定指針 + """ + if state == 0: + t.append(threading.Thread(target = pb.after(50,loading))) + # 經過0.05秒繼續執行loading + """ + return False + elif _bytes < maxbytes: + _bytes += maxbytes//lenght # 模擬每次下載500bytes + pb["value"] = _bytes # 設定指針 + """ + if state == 0: + t.append(threading.Thread(target = pb.after(50,loading))) + # 經過0.05秒繼續執行loading + """ + return False + else: + packageFile(mode="path").main() + #cleanFile() + tkinter.messagebox.showinfo("showinfo", "更新完成") + root.destroy() + return True + if main_state: + exit() + +def preview(): + global lenght + i = 0 + if fn == None: + if len(list(data)) == 0: + yt_urls = input("enter your file's full url") + else: + yt_urls = data + yt_urls = yt_urls.split(",") + for yt_url in yt_urls: + i += 1 + if yt_url == "": + yt_url = "https://github.com/sam-teng/update-data/blob/main/pythonGame-autoUpdate/game_socket-client_2P-GUIv2.py" + if not "http" in yt_url: + lenght += 1 + continue + lenght = i - lenght + maxbytes = lenght + +def downloads(): + global i + global lenght + # ------ + #import zipfile #zipfile.ZipFile + if fn == None: + if len(list(data)) == 0: + yt_urls = input("enter your file's full url") + else: + yt_urls = data + yt_urls = yt_urls.split(",") + #i = 0 + yt_title = [] + #print("wget is on path %s" % (wget.__file__)) + for yt_url in yt_urls: + + if yt_url == "": + #yt_url = "https://github.com/sam-teng/update-data/blob/main/pythonGame-autoUpdate/game_socket-client_2P-GUIv2.py" + continue + if not "http" in yt_url: + continue + try: + url = yt_url + r = requests.get(url, auth=('user', 'pass'))#https://api.github.com + print(r.status_code) + print(r.headers['content-type']) + + response = requests.get(f'{url}') + print(response) + + + ''' + file_size = os.path.getsize(response.content) + print('File Size:', file_size, 'bytes') + + #time.sleep(0.5) + + """ + filesize = 0 + with open(file_r_path, "rb")as f: + my_bytes = f.read() + my_bytes_array.append(my_bytes) + filesize = 1 + print(my_bytes[0:file_size]) + print(filesize) + """ + file_start_size = (file_size//100)*100 + file_end_size = file_size-file_start_size + """ + with open(""+file_r_path, "rb") as f: + my_bytes = f.read() + """ + my_bytes = response.content + """ + if bool(input("continue bin bytes?")): + #試試看:跟剛才的版本,看到的my_bytes前一百項,有什麼不同? + """ + for i in range(0,file_start_size,100): + print(my_bytes[i+0:i+100]) + print("\n") + time.sleep(0.03) + ii = i + time.sleep(2) + for i in range(ii,file_end_size): + print(my_bytes[i+0:i+100]) + print("\n") + time.sleep(0.03) + print("-==-"*30) + print("file_size",file_size,"\n") + """ + """ + ''' + + test_file_name = str(i)#+".zip" + + pw = "" + with open(test_file_name, 'wb') as file: + #th4.start() + pw = id(file) + file.write(response.content) + file.close() + + import random + pw = bytes((str(pw) + str(pw+random.randint(-pw,pw))).encode("UTF-8")) + + """ + req = urllib.request(url) + downloadurl = urllib.urlopen(req) + zipcontent = downloadurl.read() + with open("%d.py"%(i), 'wb') as f:#with open("%d."+input("請輸入副檔名")%(i), 'wb') as f: + f.write(zipcontent) + """ + """ + w = wget.download(url,out="\\"+str(i)+".zip") + """ + + from zipfile import ZipFile + + try: + import pyminizip + src = None # "..." + compression_level = 5 # 1‑9 + pyminizip.compress(test_file_name, src, test_file_name, pw, compression_level) + except: + with ZipFile(test_file_name, 'a') as Zip: + Zip.setpassword(pw) + Zip.printdir() + + with ZipFile(test_file_name, 'r') as Zip: + Zip.printdir() + Zip.extractall("temp",pwd = pw) + """ + yt = YouTube(yt_url)#YouTube('https://www.youtube.com/channel/UC-9-kyTW8ZkZNDHQJ6FgpwQ') + print('strart downloads: ',yt.title) + path = ""#yt.title + #yt_title = yt_title.join(yt.title) + yt_title.append(yt.title) + """ + """ + if not os.path.exists(path): + os.makedirs(path) + """ + #print(type(yt)) + """ + yt.streams.filter(subtype='mp4').first().download(path)# + print('finish',yt.title,'downloads!') + """ + + #exec(open("cheakfile.py").read()) + + except Exception as e: + print(e,"can't from " + yt_url + "\t download file") + tkinter.messagebox.showinfo("showinfo", "第"+str(i+1)+"項"+"更新失敗") + if i+1 == lenght: + root.destroy() + if main_state: + exit() + #yt_title.remove(yt.title) + finally: + i = i + 1 + time.sleep(3) + + else: + pass + if not loading(): + downloads() + else: + root.destroy() + if main_state: + exit() + pass + +def state(): + global count + if _bytes >= maxbytes: + count += 1 + +def cheakstate(): + if count == 0: + pass#count += 1 + elif count == 1: + tkinter.messagebox.showinfo("showinfo", "更新完成") + + time.sleep(1) + + elif count == 2: + + time.sleep(1.5) + """ + #th.join() + #th0.join() + th1.join() + th3.join() + th4.join() + #th5.join() + th2.join() + """ + + for ths in range(len(th)): + th[ths].join() + if main_state: + exit() + +def __init__(): + #t = [main(),state(),preview(),load(),downloads(),cheakstate()] + """ + th = threading.Thread(target = preview()) + #th0 = threading.Thread(target = _exec()) + th1 = threading.Thread(target = downloads()) + #load() + th2 = threading.Thread(target = main()) + #root.mainloop() + th3 = threading.Thread(target = state()) + #count += 1 + th4 = threading.Thread(target = load()) + #cheakstate() + + th5 = threading.Thread(target = cheakstate()) + """ + ths = 0 + + for ts in t: + th.append(threading.Thread(target = ts)) + th[ths].start() + ths += 1 + """ +#load() +#downloads() +#cheakstate() + th2.start() + + th3.start() + th.start() + th.join() + th4.start()#->move into downloads. + th1.start() + #th0.start() + th5.start() + """ + +tkinter.messagebox.showinfo("showinfo", "更新中請耐心等候") + +t = [state(),preview(),load(),downloads(),cheakstate()]#,main()] +""" +if __name__ == '__main__': + __init__() + __main__() +""" \ No newline at end of file