Skip to content

Commit 293fd4b

Browse files
authored
Update source folder
1 parent 450b059 commit 293fd4b

File tree

7 files changed

+93
-12
lines changed

7 files changed

+93
-12
lines changed

source/r_notes/notes.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"version": "2.0.3 (Beta)",
66
"release_notes":
77
{
8-
"title": "Atualização 2.0.3",
9-
"date": "25/04/2025",
8+
"title": "Atualização 2.0.2",
9+
"date": "14/04/2025",
1010
"content":
1111
[
1212
[
@@ -32,4 +32,4 @@
3232
"new": true
3333
}
3434
]
35-
}
35+
}

source/r_notes/releaseNotes.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,16 @@ def __init__(self):
107107
for i in range(len(self.notes["update"])):
108108
self.all_versions.append(VersionButton(i, self.notes["update"][i]["version"]))
109109
self.released_notes.append(self.notes["update"][i]["release_notes"])
110-
if self.current_notes_index == None:
111-
if self.notes["update"][i]["new"] == True: self.current_notes_index = i
112110

113111
if self.current_notes_index != None:
114112
self.notes["update"][self.current_notes_index]["active"] = True
115113
else:
116114
self.current_notes_index = len(self.all_versions) - 1
117115
self.notes["update"][self.current_notes_index]["active"] = True
118116

117+
if self.notes["update"][self.current_notes_index]["new"] == True:
118+
self.render = True
119+
119120
self.all_versions[self.current_notes_index].active = True
120121

121122
def lastUpdatesAside(self):
@@ -149,6 +150,9 @@ def exit(self):
149150
cfg.releasenotes_btn.updating = True
150151
self.current_notes_index = None
151152
self.all_versions[-1].active = True
153+
self.notes["update"][-1]["new"] = False
154+
# rewrite the json file with the new information
155+
with open("source/r_notes/notes.json", mode="w", encoding="utf-8") as file: json.dump(self.notes, file, indent=4, ensure_ascii=False)
152156
self.content.reset() # resets the starting position
153157

154158
class ContentDisplayment:

source/scripts/config.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@
3030
pygame.image.load('./assets/img/timer-box.png'),
3131
pygame.image.load('./assets/img/block.png'),
3232
pygame.image.load('./assets/img/btn-texture.png'),
33-
pygame.image.load('./assets/img/logo-menu.png'),
34-
pygame.image.load('./assets/img/logo.png')
33+
pygame.image.load('./assets/img/logo-menu.png')
3534
]
3635
SOUNDS = None
3736

source/scripts/updates/bridge.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# This bridge.py file serves as a "bridge" between the update process and the game running.
2+
import os, sys
3+
import subprocess
4+
5+
def launch():
6+
try:
7+
exe_path = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(__file__)))), "Sudoku.exe")
8+
subprocess.Popen([exe_path], cwd=os.path.dirname(exe_path))
9+
except Exception as e:
10+
with open("source/scripts/updates/launcher_log.txt", mode="w", encoding="utf-8") as log:
11+
log.write(f"ERROR: {str(e)}\nFailed game start or Corrupted path in {exe_path}")
12+
13+
if __name__ == "__main__":
14+
launch()
15+
sys.exit()
8.08 MB
Binary file not shown.

source/scripts/updates/updater.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# This file is responsible for the game's automatic update system through github
2+
import os
3+
import ctypes
4+
import subprocess
5+
import requests
6+
import zipfile
7+
import json
8+
9+
def msgbox(text: str, title: str, style: int, icon: int): return ctypes.windll.user32.MessageBoxW(0, text, title, style|icon)
10+
11+
def checkForUpdates():
12+
try:
13+
version_url = requests.get("https://raw.githubusercontent.com/RaiMonteiro/sudoku-python/refs/heads/main/source/r_notes/notes.json")
14+
online = True
15+
except requests.exceptions.RequestException:
16+
online = False
17+
18+
if online:
19+
if version_url.status_code == 200: # the file was found
20+
# loads the remote and local json data
21+
remote_data = version_url.json()
22+
with open("source/r_notes/notes.json", mode="r", encoding="utf-8") as file: local_data = json.load(file)
23+
24+
if remote_data["update"][-1]["version"] != local_data["update"][-1]["version"]: # compare versions
25+
if msgbox(f"Existe uma nova versão!\nPretende atualizar o jogo para a versão {remote_data["update"][-1]["version"]}?", "Sudoku Updater", 4, 0x20) == 6: # ok = 6
26+
if updateFiles(remote_data["update"][-1]["version"]):
27+
try:
28+
exe_path = os.path.join(os.path.dirname(__file__), "launcher.exe")
29+
subprocess.Popen([exe_path], cwd=os.path.dirname(exe_path)) # launch the executable
30+
return "UPDATE_SUCESS"
31+
32+
except FileNotFoundError:
33+
msgbox(f"Arquivo não encontrado em {exe_path}.", f"Sudoku Updater - Erro: FileNotFoundError", 0, 0x30)
34+
return "UPDATE_FAILED"
35+
except PermissionError:
36+
msgbox(f"Sem permissão para executar.", f"Sudoku Updater - Erro: PermissionError", 0, 0x30)
37+
return "UPDATE_FAILED"
38+
except Exception as e:
39+
msgbox(f"Ocorreu um erro ao executar o programa.", f"Sudoku Updater - Erro: {str(e)}", 0, 0x30)
40+
return "UPDATE_FAILED"
41+
42+
else: return "UPDATE_FAILED"
43+
else: return "UPDATE_DECLINED"
44+
else: return "NO_UPDATE"
45+
else:
46+
msgbox(f"Ocorreu um erro ao verficar novas atualizações.\nPor favor tente mais tarde.", f"Sudoku Updater - Erro: {version_url.status_code}", 0, 0x30)
47+
return "OFFLINE"
48+
49+
def updateFiles(version: str):
50+
zip_url = f"https://github.com/RaiMonteiro/sudoku-python/releases/download/v{version}/sudoku-update-v{version}.zip"
51+
response = requests.get(zip_url)
52+
53+
if response.status_code != 200:
54+
msgbox(f"Ocorreu um erro durante a atualização.\nPor favor tente mais tarde.", f"Sudoku Updater - Erro: {response.status_code}", 0, 0x30)
55+
return False
56+
57+
try:
58+
# Open a local file in binary mode for writing, 'wb' = write binary (required for ZIP files)
59+
with open("update.zip", "wb") as f: f.write(response.content)
60+
61+
# Open the ZIP file to extract its contents
62+
with zipfile.ZipFile("update.zip", 'r') as zip_ref: zip_ref.extractall(".")
63+
64+
os.remove("update.zip") # Clean up downloaded zip
65+
return True
66+
except Exception as e:
67+
msgbox(f"Ocorreu um erro durante a atualização dos ficheiros locais.\nPor favor tente mais tarde.", f"Sudoku Updater - Erro: {str(e)}", 0, 0x30)
68+
return False

source/scripts/utils.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,6 @@ def inputHandler(shutdown = True, buttons = None, blocks = None): # manages the
133133
cfg.releasenotes.content.scroll.eventHandler(event)
134134
for b in cfg.releasenotes.all_versions: b.eventHandler(event)
135135

136-
137-
# Sujeito a ser retirado
138-
if pygame.key.get_pressed()[pygame.K_ESCAPE]:
139-
close()
140-
141136
def shuffle(list):
142137
for i in range(8, 0, -1):
143138
r = random.randint(0, i)

0 commit comments

Comments
 (0)