From e8c39e344a64befa8fd28eb5c67e7345e6125c06 Mon Sep 17 00:00:00 2001 From: ThaaoBlues <40574784+ThaaoBlues@users.noreply.github.com> Date: Tue, 20 Jul 2021 18:21:12 +0200 Subject: [PATCH] fixed temp directory bug with build --- copypasta.py | 7 +++++-- launcher.py | 17 ++++++++++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/copypasta.py b/copypasta.py index 24bb582..3906df0 100644 --- a/copypasta.py +++ b/copypasta.py @@ -16,6 +16,7 @@ from pyautogui import write as send_keystrokes from flask_cors import CORS, cross_origin from re import findall +import sys #init flask app and secret key app = Flask(__name__) @@ -25,8 +26,10 @@ app.secret_key = "CF3gNqD#%#MpSs=7J!VmM2KxWCWhGwjSP%pc*4G?XuUU4s6CC=2KcUba4WPA#EhhZ52gyU57_nF6cDM*_B9X7FpPH%^-c+c8naZSx2$atBwS?V" -APP_PATH = path.abspath(__file__).replace("main.py","").replace("main.exe","").replace("copypasta.exe","").replace("copypasta.py","") - +if getattr(sys, 'frozen', False): + APP_PATH = path.dirname(sys.executable) +elif __file__: + APP_PATH = path.dirname(__file__) diff --git a/launcher.py b/launcher.py index 2f23126..8898c70 100644 --- a/launcher.py +++ b/launcher.py @@ -4,15 +4,19 @@ from shutil import rmtree from zipfile import ZipFile from os import path, chdir, remove +import sys -APP_PATH = path.abspath(__file__).replace("main.py","").replace("main.exe","").replace("copypasta.exe","").replace("copypasta.py","").replace("launcher.exe","").replace("launcher.py","") +if getattr(sys, 'frozen', False): + APP_PATH = path.dirname(sys.executable) +elif __file__: + APP_PATH = path.dirname(__file__) def update_main_executable(version: str) -> None: if not literal_eval(get("https://api.github.com/repos/CopyPastaOfficial/CopyPasta/tags").text)[0]['name'] == version: - + print("NOT UP TO DATE") #remove copypasta folder berfore downloading new version try: rmtree("copypasta") @@ -43,8 +47,10 @@ def get_current_version_and_check_update() -> None: with open("copypasta/version","r") as f: version = f.read() + print(version) f.close() - update_main_executable(version) + + update_main_executable(version) except: update_main_executable("0") @@ -53,12 +59,13 @@ def get_current_version_and_check_update() -> None: #make sure we work in the right directory chdir(APP_PATH) + print(APP_PATH) #install copypasta like if it is not installed by the same process as updating if not is_installed(): #is still the lastest version ? get_current_version_and_check_update() - + + print("starting copypasta...") #now that we have the lastest, we can start the app :D Popen("copypasta/copypasta.exe") - \ No newline at end of file