Exemple #1
0
    def proxify_mod_files_in_folder_list(self, folder_list, is_revert):

        files_to_be_proxified = []

        for folder_path in folder_list:
            files_to_be_proxified += self.proxify_mod_files_in_folder(
                folder_path, is_revert)

        file_count = len(files_to_be_proxified)
        cur_file = 0
        if is_revert:
            print_localized("reverting_old_version_proxies")
        else:
            print_localized("changing_url")

        for file in files_to_be_proxified:
            original_modify_time = os.path.getmtime(
                file)  # capture modify time

            self.proxify_file(file, is_revert)

            os.utime(file, (original_modify_time,
                            original_modify_time))  # restore modify time

            cur_file += 1
            done = int(50 * cur_file / file_count)
            sys.stdout.write("\r[%s%s]" % ('=' * done, ' ' * (50 - done)))
            sys.stdout.flush()
        print()

        return
Exemple #2
0
    def load_proxy_history(self, file_path):
        print(get_localized_string("loading_proxy_history") + file_path)
        if not os.path.isfile(file_path):
            print_localized("history_not_found")
            return

        s = None
        with open(file_path, 'r', encoding='utf8', errors='ignore') as f:
            s = f.read()
        j = json.loads(s)
        self.proxy_history = j["proxy_history"]
        self.non_special_proxy_history = j["non_special_proxy_history"]
        return
def get_mods_root_path():
    path = os.path.expanduser("~/Documents/My Games/Tabletop Simulator/")
    while True:
        if os.path.isdir(os.path.join(path, "Mods")) and os.path.isdir(os.path.join(path, "Mods", "Workshop")):
            break
        elif path == "":
            print_localized("no_folder")
            exit(0)
        else:
            print_localized("show_file")

        root = Tk()
        root.withdraw()
        path = filedialog.askdirectory(
            initialdir=path,
            title=get_localized_string("choose_root")
        )
    return path
Exemple #4
0
def get_latest_release():
    global latest_release

    # get latest release from cache
    if latest_release:
        return latest_release

    # get latest version from github api
    try:
        r = requests.get(settings.update_repository_url)
    except requests.exceptions.RequestException as e:  # This is the correct syntax
        print_localized("problem_checking_new_version")
        raise Exception("problem checking new version")

    if r.ok:
        # parse json api data
        latest_release = json.loads(r.text or r.content)
        return latest_release
    raise Exception("problem checking new version")
Exemple #5
0
def get_latest_release():
    global latest_release

    # get latest release from cache
    if latest_release:
        return latest_release

    # get latest version from github api
    try:
        r = requests.get(
            'https://api.github.com/repos/seyahdoo/TabletopTurkeyifier/releases/latest'
        )
    except requests.exceptions.RequestException as e:  # This is the correct syntax
        print_localized("problem_checking_new_version")
        raise Exception("problem checking new version")

    if r.ok:
        # parse json api data
        latest_release = json.loads(r.text or r.content)
        return latest_release
    raise Exception("problem checking new version")
Exemple #6
0
def update_app():

    # delete old updater if there is any
    for filename in os.listdir(get_application_path()):
        props = get_file_properties(
            os.path.join(get_application_path(), filename))
        app_name = None
        try:
            app_name = props["StringFileInfo"]["ProductName"]
        except:
            pass

        if app_name == settings.app_name:
            if filename == settings.updater_executable_name:
                print_localized("deleting_updater")
                # wait for updater to close
                with open(os.path.join(get_application_path(), filename), 'w'):
                    pass
                os.remove(os.path.join(get_application_path(), filename))
                return True

    release = get_latest_release()

    # if there is a newer version or we are in production
    if release["tag_name"] != version and version != "development":
        print_localized("updating")

        # download updater,
        exec_name = None
        # download all it's assets
        for asset in release["assets"]:
            if asset["name"] == settings.updater_executable_name:
                download_with_progress(
                    asset["browser_download_url"],
                    os.path.join(get_application_path(), asset["name"]))
                exec_name = asset["name"]

        # start new version and exit program
        if exec_name is not None:
            print_localized("starting_updater")
            os.startfile(os.path.join(get_application_path(), exec_name))
            exit(0)
        else:
            print_localized("problem_downloading_new_ver")
    return False
Exemple #7
0
        app_name = None
        try:
            app_name = props["StringFileInfo"]["ProductName"]
        except:
            pass

        prod_ver = None
        try:
            prod_ver = props["StringFileInfo"]["ProductVersion"]
        except:
            pass

        if app_name == settings.app_name:
            if prod_ver is not None:
                if prod_ver < version:
                    print_localized("deleting_old_ver")
                    # wait for old version to close
                    with open(os.path.join(get_application_path(), filename),
                              'w'):
                        pass
                    os.remove(os.path.join(get_application_path(), filename))

    # download new version
    release = get_latest_release()

    exec_name = None
    # download executable
    for asset in release["assets"]:
        if asset["name"] == settings.app_executable_name:
            download_with_progress(
                asset["browser_download_url"],
Exemple #8
0
    print("##########################################")
    print("####                                  ####")
    print("####    TABLETOP TURKEYIFIER          ####")
    print("####                                  ####")
    print("####           created by seyahdoo    ####")
    print("####                                  ####")
    print("##########################################")
    print("##########################################")
    print()
    print("version = " + version)

    # Try to update self
    just_updated = update_app()

    # Getting root mods path
    print_localized("find_root")
    mods_list, asset_folder_list = get_paths()

    # Backing up intial data
    print_localized("backup")
    for mod_path in mods_list:
        do_backup_folder(mod_path)

    p = Proxify()

    history_location = os.path.join(get_documents_root(),
                                    "TurkeyifierHistory.json")

    # Proxying json mod files
    p.load_proxy_history(history_location)