|
1 | 1 | import os |
2 | | -import shutil |
3 | | -import sys |
| 2 | +import requests |
| 3 | +import zipfile |
4 | 4 | from pathlib import Path |
5 | 5 |
|
6 | 6 |
|
7 | | -# From https://stackoverflow.com/questions/26577574/python-pyinstaller-onefile-executable |
8 | | -def resource(relative_path): |
9 | | - if getattr(sys, 'frozen', False): |
10 | | - return os.path.join(sys._MEIPASS, relative_path) |
| 7 | +chromedir = Path.home() / ".pogify" / "GoogleChromePortable" |
11 | 8 |
|
12 | | - return os.path.join(os.path.abspath('.'), relative_path) |
13 | 9 |
|
14 | | -chrome = resource("GoogleChromePortable") # "GoogleChromePortable.exe")) |
15 | | -newpath = Path.home() / ".pogify" / "GoogleChromePortable" |
16 | | - |
17 | | -print("Relocating chrome executable") |
| 10 | +def unzip(filepath: str, resultpath: str) -> None: |
| 11 | + with zipfile.ZipFile(filepath, "r") as zip_ref: |
| 12 | + zip_ref.extractall(resultpath) |
18 | 13 |
|
19 | 14 | try: |
20 | 15 | os.mkdir(Path.home() / ".pogify") |
21 | | -except FileExistsError: |
22 | | - pass |
| 16 | + zippath = Path.home() / ".pogify" / "chrome.zip" |
| 17 | + |
| 18 | + with open(zippath, 'wb+') as fout: |
| 19 | + fout.write( |
| 20 | + requests.get( |
| 21 | + "https://github.com/Pogify/pogify-client" |
| 22 | + "/releases/latest/download/GoogleChromePortable.zip" |
| 23 | + ).content) |
| 24 | + |
| 25 | + unzip(str(zippath), Path.home() / ".pogify") |
| 26 | + os.remove(str(zippath)) |
23 | 27 |
|
24 | | -try: |
25 | | - shutil.copytree(chrome, newpath) |
26 | 28 | except FileExistsError: |
27 | 29 | pass |
28 | 30 |
|
| 31 | + |
29 | 32 | os.system( |
30 | | - f"start {newpath / 'GoogleChromePortable.exe'} --app=http://pogify.net/" |
| 33 | + f"start {chromedir / 'GoogleChromePortable.exe'} --app=http://pogify.net/" |
31 | 34 | ) |
0 commit comments