Skip to content

Commit f66455b

Browse files
fix auto-update
fix: auto-update thinking everything is an update #2 fix: temporarily disabled luscious due to it being broken fix: auto_update.py is now also uploaded
1 parent cb7fccb commit f66455b

File tree

3 files changed

+89
-3
lines changed

3 files changed

+89
-3
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,5 @@ testing_accounts.txt.bak
1313
db/
1414
outdated
1515
modules/updateManager.old
16-
modules/auto_update.py
1716
runtime.log
1817
delete-exe.bat

main.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from sys import exit
88
import inquirer
99

10-
version = "1.4.0"
10+
version = "1.4.1"
1111
windll.kernel32.SetConsoleTitleW(f"NN-Downloader | v{version}")
1212
proxy_list = []
1313
header = {"User-Agent":f"nn-downloader/{version} (by Official Husko on GitHub)"}
@@ -76,7 +76,7 @@ def main_startup():
7676
print(colored("What site do you want to download from?", "green"))
7777
questions = [
7878
inquirer.List('selection',
79-
choices=['E621', 'E926', 'Furbooru', 'Luscious', 'Multporn', 'Rule34', 'Yiffer']),
79+
choices=['E621', 'E926', 'Furbooru', 'Multporn', 'Rule34', 'Yiffer']), #choices=['E621', 'E926', 'Furbooru', 'Luscious', 'Multporn', 'Rule34', 'Yiffer']),
8080
]
8181
answers = inquirer.prompt(questions)
8282
print("")

modules/auto_update.py

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import requests
2+
import random
3+
import base64
4+
from termcolor import colored
5+
import inquirer
6+
import webbrowser
7+
import os
8+
from time import sleep
9+
from alive_progress import alive_bar
10+
11+
from main import version
12+
from .logger import Logger
13+
from .pretty_print import error, ok
14+
15+
class AutoUpdate:
16+
17+
def Checker():
18+
try:
19+
url = "https://api.github.com/repos/Official-Husko/NN-Downloader/releases/latest"
20+
21+
headers = {
22+
"User-Agent":f"nn-downloader/{version} (by Official Husko on GitHub)",
23+
"Accept": "application/vnd.github+json",
24+
"X-GitHub-Api-Version": "2022-11-28"
25+
}
26+
27+
req = requests.get(url, headers=headers).json()
28+
repo_version = req.get("tag_name")
29+
download_link = req["assets"][0]["browser_download_url"]
30+
31+
if str(version) < repo_version:
32+
print(colored("UPDATE AVAILABLE! ", "red", attrs=["blink"]))
33+
34+
body = req.get("body")
35+
name = req.get("name")
36+
date = req.get("published_at").replace("T", " ").replace("Z", "")
37+
38+
print("")
39+
print(f"Latest release is {colored(name, 'light_blue')} released on {colored(date, 'yellow')}")
40+
print("")
41+
print(body)
42+
print("")
43+
amount_question = [
44+
inquirer.List('selection',
45+
message=colored("Do you want to download the update?", "green"),
46+
choices=["Yes", "No"],
47+
),
48+
]
49+
amount_answers = inquirer.prompt(amount_question)
50+
print("")
51+
decision = amount_answers.get("selection")
52+
if decision == "Yes":
53+
r = requests.get(download_link, headers={"User-Agent":f"nn-downloader/{version} (by Official Husko on GitHub)"}, timeout=5, stream=True)
54+
with alive_bar(int(int(r.headers.get('content-length')) / 1024 + 1)) as bar:
55+
bar.text = f'-> Downloading Update {repo_version}, please wait...'
56+
file = open(f"nn-downloader-{repo_version}.exe", 'wb')
57+
for chunk in r.iter_content(chunk_size=1024):
58+
if chunk:
59+
file.write(chunk)
60+
file.flush()
61+
bar()
62+
print(f"{ok} Update successfully downloaded! The program will now close and delete the old exe.")
63+
if os.path.exists("delete-exe.bat"):
64+
os.remove("delete-exe.bat")
65+
with open("delete-exe.bat", "a") as bat_creator:
66+
bat_content = f'TASKKILL -F /IM NN-Downloader.exe\ntimeout 3\nDEL .\\NN-Downloader.exe\nren .\\nn-downloader-{repo_version}.exe NN-Downloader.exe\nDEL .\\delete-exe.bat'
67+
bat_creator.write(bat_content)
68+
bat_creator.close()
69+
os.startfile(r".\\delete-exe.bat")
70+
sleep(5)
71+
exit(0)
72+
elif decision == "No":
73+
if not os.path.exists("outdated"):
74+
with open("outdated", "a") as mark_outdated:
75+
mark_outdated.close()
76+
elif str(version) >= repo_version:
77+
try:
78+
os.remove("outdated")
79+
except Exception:
80+
pass
81+
82+
except Exception as e:
83+
# Construct and print the error
84+
error_str = f"An error occured while checking for updates! Please report this. Exception: {e}"
85+
print(f"{error} {error_str}")
86+
Logger.log_event(error_str, req)
87+
sleep(7)

0 commit comments

Comments
 (0)