mirror of
https://github.com/JDM170/SaveWizard
synced 2025-04-20 22:30:42 +07:00
Typo fixes
Signed-off-by: JDM170 <30170278+JDM170@users.noreply.github.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<ui version="4.0">
|
<ui version="4.0">
|
||||||
|
<author>JDM170</author>
|
||||||
<class>Choice</class>
|
<class>Choice</class>
|
||||||
<widget class="QDialog" name="Choice">
|
<widget class="QDialog" name="Choice">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ class ChoiceWindow(QDialog, Ui_Choice):
|
|||||||
answer = remember_data.get("answer_updates")
|
answer = remember_data.get("answer_updates")
|
||||||
if answer:
|
if answer:
|
||||||
box = QMessageBox(QMessageBox.Information, "Info",
|
box = QMessageBox(QMessageBox.Information, "Info",
|
||||||
"Some configs get updated, do you want update your local configs?")
|
"Some configs have been updated. Do you want to update the local configs?")
|
||||||
box.addButton("Yes", QMessageBox.YesRole) # 0
|
box.addButton("Yes", QMessageBox.YesRole) # 0
|
||||||
box.addButton("Yes, remember that", QMessageBox.YesRole) # 1
|
box.addButton("Yes, remember that", QMessageBox.YesRole) # 1
|
||||||
box.addButton("No", QMessageBox.NoRole) # 2
|
box.addButton("No", QMessageBox.NoRole) # 2
|
||||||
|
|||||||
15
dataIO.py
15
dataIO.py
@@ -7,10 +7,6 @@ from os.path import splitext
|
|||||||
from random import randint
|
from random import randint
|
||||||
|
|
||||||
|
|
||||||
class InvalidFileIO(Exception):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class DataIO:
|
class DataIO:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _read_json(filename):
|
def _read_json(filename):
|
||||||
@@ -18,12 +14,6 @@ class DataIO:
|
|||||||
data = load(f)
|
data = load(f)
|
||||||
return data
|
return data
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def _save_json(filename, data):
|
|
||||||
with open(filename, encoding="utf-8", mode="w") as f:
|
|
||||||
dump(data, f, indent=4, sort_keys=True, separators=(",", " : "))
|
|
||||||
return data
|
|
||||||
|
|
||||||
def is_valid_json(self, filename):
|
def is_valid_json(self, filename):
|
||||||
"""Verifies if json file exists / is readable"""
|
"""Verifies if json file exists / is readable"""
|
||||||
try:
|
try:
|
||||||
@@ -43,7 +33,10 @@ class DataIO:
|
|||||||
rnd = randint(1000, 9999)
|
rnd = randint(1000, 9999)
|
||||||
path, ext = splitext(filename)
|
path, ext = splitext(filename)
|
||||||
tmp_file = "{}-{}.tmp".format(path, rnd)
|
tmp_file = "{}-{}.tmp".format(path, rnd)
|
||||||
self._save_json(tmp_file, data)
|
# self._save_json(filename, data)
|
||||||
|
with open(filename, encoding="utf-8", mode="w") as f:
|
||||||
|
dump(data, f, indent=4, sort_keys=True, separators=(",", " : "))
|
||||||
|
# return data (?)
|
||||||
try:
|
try:
|
||||||
self._read_json(tmp_file)
|
self._read_json(tmp_file)
|
||||||
except decoder.JSONDecodeError:
|
except decoder.JSONDecodeError:
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<ui version="4.0">
|
<ui version="4.0">
|
||||||
|
<author>JDM170</author>
|
||||||
<class>MainWindow</class>
|
<class>MainWindow</class>
|
||||||
<widget class="QDialog" name="MainWindow">
|
<widget class="QDialog" name="MainWindow">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
|
|||||||
@@ -99,8 +99,8 @@ class MainWindow(QDialog, Ui_MainWindow):
|
|||||||
cfg_path = "configs/{}/dlc.json".format(self.selected_game)
|
cfg_path = "configs/{}/dlc.json".format(self.selected_game)
|
||||||
if dataIO.is_valid_json(cfg_path) is False:
|
if dataIO.is_valid_json(cfg_path) is False:
|
||||||
self.owns = False
|
self.owns = False
|
||||||
show_message(QMessageBox.Warning, "Warning", "'dlc.json' from '{}' not found, functionality "
|
show_message(QMessageBox.Warning, "Warning", "'dlc.json' from '{}' have errors or not found, "
|
||||||
"has been limited".format(self.selected_game))
|
"functionality has been limited".format(self.selected_game))
|
||||||
else:
|
else:
|
||||||
self.owns = {}
|
self.owns = {}
|
||||||
self.dlc = dataIO.load_json(cfg_path)
|
self.dlc = dataIO.load_json(cfg_path)
|
||||||
@@ -138,7 +138,10 @@ class MainWindow(QDialog, Ui_MainWindow):
|
|||||||
self.old_file = f.read()
|
self.old_file = f.read()
|
||||||
show_message(QMessageBox.Information, "Success", "File successfully decrypted.")
|
show_message(QMessageBox.Information, "Success", "File successfully decrypted.")
|
||||||
except UnicodeDecodeError:
|
except UnicodeDecodeError:
|
||||||
show_message(QMessageBox.Critical, "Error", "Error to decrypt and open file. Try again.")
|
show_message(QMessageBox.Critical, "Error", "Error to decrypt and open file. "
|
||||||
|
"Try again.\nIf you still get error on this step,"
|
||||||
|
"try to change \"uset g_save_format\" to 2, resave game "
|
||||||
|
"and try again.")
|
||||||
return
|
return
|
||||||
set_lines(self.old_file.split("\n"))
|
set_lines(self.old_file.split("\n"))
|
||||||
|
|
||||||
@@ -177,8 +180,8 @@ class MainWindow(QDialog, Ui_MainWindow):
|
|||||||
return
|
return
|
||||||
|
|
||||||
def change_configs(self):
|
def change_configs(self):
|
||||||
box = QMessageBox(QMessageBox.Warning, "Warning", "Do you really change configs? "
|
box = QMessageBox(QMessageBox.Warning, "Warning", "Do you really want to load other configs?\n"
|
||||||
"Your changes has been lost!")
|
"Your current changes won't be saved.")
|
||||||
box.addButton("Yes", QMessageBox.YesRole)
|
box.addButton("Yes", QMessageBox.YesRole)
|
||||||
box.addButton("No", QMessageBox.NoRole)
|
box.addButton("No", QMessageBox.NoRole)
|
||||||
if box.exec() == 0:
|
if box.exec() == 0:
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<ui version="4.0">
|
<ui version="4.0">
|
||||||
|
<author>JDM170</author>
|
||||||
<class>SecondWindow</class>
|
<class>SecondWindow</class>
|
||||||
<widget class="QDialog" name="SecondWindow">
|
<widget class="QDialog" name="SecondWindow">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ class SecondWindow(QDialog, Ui_SecondWindow):
|
|||||||
self.ui.dealer_edit.setEnabled(False)
|
self.ui.dealer_edit.setEnabled(False)
|
||||||
self.ui.dealer_add.setEnabled(False)
|
self.ui.dealer_add.setEnabled(False)
|
||||||
self.ui.dealer_add_all.setEnabled(False)
|
self.ui.dealer_add_all.setEnabled(False)
|
||||||
show_message(QMessageBox.Warning, "Warning", "'dealers.json' from '{}' not found, dealers "
|
show_message(QMessageBox.Warning, "Warning", "'dealers.json' from '{}' have errors or not found, dealers "
|
||||||
"editing has been disabled".format(selected_game))
|
"editing has been disabled".format(selected_game))
|
||||||
else:
|
else:
|
||||||
self.dealers = []
|
self.dealers = []
|
||||||
@@ -44,7 +44,7 @@ class SecondWindow(QDialog, Ui_SecondWindow):
|
|||||||
self.ui.agency_edit.setEnabled(False)
|
self.ui.agency_edit.setEnabled(False)
|
||||||
self.ui.agency_add.setEnabled(False)
|
self.ui.agency_add.setEnabled(False)
|
||||||
self.ui.agency_add_all.setEnabled(False)
|
self.ui.agency_add_all.setEnabled(False)
|
||||||
show_message(QMessageBox.Warning, "Warning", "'agencies.json' from '{}' not found, agencies "
|
show_message(QMessageBox.Warning, "Warning", "'agencies.json' from '{}' have errors or not found, agencies "
|
||||||
"editing has been disabled".format(selected_game))
|
"editing has been disabled".format(selected_game))
|
||||||
else:
|
else:
|
||||||
self.agencies = []
|
self.agencies = []
|
||||||
@@ -121,7 +121,7 @@ class SecondWindow(QDialog, Ui_SecondWindow):
|
|||||||
def add_garage(self):
|
def add_garage(self):
|
||||||
garage = self.ui.garage_edit.text().lower()
|
garage = self.ui.garage_edit.text().lower()
|
||||||
if garage is "":
|
if garage is "":
|
||||||
show_message(QMessageBox.Critical, "Error", "Enter a name for the city.")
|
show_message(QMessageBox.Critical, "Error", "Enter city name!")
|
||||||
return
|
return
|
||||||
self.ui.garage_edit.setText("")
|
self.ui.garage_edit.setText("")
|
||||||
reg_garage = "garage." + garage
|
reg_garage = "garage." + garage
|
||||||
@@ -156,12 +156,12 @@ class SecondWindow(QDialog, Ui_SecondWindow):
|
|||||||
def change_headquarter(self):
|
def change_headquarter(self):
|
||||||
hq = self.ui.headquarter_edit.text().lower()
|
hq = self.ui.headquarter_edit.text().lower()
|
||||||
if hq is "":
|
if hq is "":
|
||||||
show_message(QMessageBox.Critical, "Error", "Enter a name for the city.")
|
show_message(QMessageBox.Critical, "Error", "Enter city name!")
|
||||||
return
|
return
|
||||||
if get_value(search_line("hq_city:")) == hq:
|
if get_value(search_line("hq_city:")) == hq:
|
||||||
show_message(QMessageBox.Information, "Info", "Your headquarter is already in this city")
|
show_message(QMessageBox.Information, "Info", "Your headquarter is already in this city.")
|
||||||
elif hq not in self.purchased_garages():
|
elif hq not in self.purchased_garages():
|
||||||
show_message(QMessageBox.Critical, "Error", "You need to own the garage in this city.")
|
show_message(QMessageBox.Critical, "Error", "You need a garage in \"{}\" to set headquarter.".format(hq))
|
||||||
else:
|
else:
|
||||||
set_value(search_line("hq_city:"), hq)
|
set_value(search_line("hq_city:"), hq)
|
||||||
show_message(QMessageBox.Information, "Success", "Headquarter successfully set to \"{}\".".format(hq))
|
show_message(QMessageBox.Information, "Success", "Headquarter successfully set to \"{}\".".format(hq))
|
||||||
@@ -179,7 +179,7 @@ class SecondWindow(QDialog, Ui_SecondWindow):
|
|||||||
def add_city(self):
|
def add_city(self):
|
||||||
city = self.ui.city_edit.text().lower()
|
city = self.ui.city_edit.text().lower()
|
||||||
if city is "":
|
if city is "":
|
||||||
show_message(QMessageBox.Critical, "Error", "Enter a name for the city.")
|
show_message(QMessageBox.Critical, "Error", "Enter city name!")
|
||||||
return
|
return
|
||||||
self.ui.city_edit.setText("")
|
self.ui.city_edit.setText("")
|
||||||
if city not in get_array_items(search_line("visited_cities:")):
|
if city not in get_array_items(search_line("visited_cities:")):
|
||||||
@@ -188,7 +188,7 @@ class SecondWindow(QDialog, Ui_SecondWindow):
|
|||||||
show_message(QMessageBox.Information, "Success", "City \"{}\" successfully visited.".format(city))
|
show_message(QMessageBox.Information, "Success", "City \"{}\" successfully visited.".format(city))
|
||||||
self.check_cities()
|
self.check_cities()
|
||||||
else:
|
else:
|
||||||
show_message(QMessageBox.Critical, "Error", "You already visited \"{}\".".format(city))
|
show_message(QMessageBox.Critical, "Error", "You've already visited \"{}\".".format(city))
|
||||||
|
|
||||||
def add_all_cities(self):
|
def add_all_cities(self):
|
||||||
visited_cities = get_array_items(search_line("visited_cities:"))
|
visited_cities = get_array_items(search_line("visited_cities:"))
|
||||||
@@ -242,15 +242,16 @@ class SecondWindow(QDialog, Ui_SecondWindow):
|
|||||||
edit, file_var, message_var = da_arr[0], da_arr[1], da_arr[2]
|
edit, file_var, message_var = da_arr[0], da_arr[1], da_arr[2]
|
||||||
city_element = edit.text().lower()
|
city_element = edit.text().lower()
|
||||||
if not city_element:
|
if not city_element:
|
||||||
show_message(QMessageBox.Critical, "Error", "Enter a name for the city.")
|
show_message(QMessageBox.Critical, "Error", "Enter city name!")
|
||||||
return
|
return
|
||||||
edit.setText("")
|
edit.setText("")
|
||||||
if city_element not in da_arr[3]:
|
if city_element not in da_arr[3]:
|
||||||
show_message(QMessageBox.Critical, "Error", "There is no {} in that city.".format(message_var.lower()))
|
show_message(QMessageBox.Critical, "Error", "There is no {} in that city.".format(message_var.lower()))
|
||||||
elif city_element in get_array_items(search_line(file_var)):
|
elif city_element in get_array_items(search_line(file_var)):
|
||||||
show_message(QMessageBox.Information, "Info", "{} is already unlocked.".format(message_var))
|
show_message(QMessageBox.Information, "Info",
|
||||||
|
"{} in \"{}\" is already unlocked.".format(message_var, city_element))
|
||||||
else:
|
else:
|
||||||
add_array_value(search_line(file_var), city_element)
|
add_array_value(search_line(file_var), city_element)
|
||||||
show_message(QMessageBox.Information, "Success", "{} in \"{}\" successfully unlocked."
|
show_message(QMessageBox.Information, "Success",
|
||||||
"".format(message_var, city_element))
|
"{} in \"{}\" successfully unlocked.".format(message_var, city_element))
|
||||||
da_arr[4]()
|
da_arr[4]()
|
||||||
|
|||||||
63
util.py
63
util.py
@@ -1,7 +1,8 @@
|
|||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
from re import search, match, sub
|
# from re import search, match, sub
|
||||||
|
from re import search, match
|
||||||
from PyQt5.QtWidgets import QMessageBox
|
from PyQt5.QtWidgets import QMessageBox
|
||||||
|
|
||||||
github_link = "https://raw.githubusercontent.com/JDM170/SaveWizard/master/"
|
github_link = "https://raw.githubusercontent.com/JDM170/SaveWizard/master/"
|
||||||
@@ -71,9 +72,9 @@ def set_value(line, value):
|
|||||||
lines[line] = name + ": " + value
|
lines[line] = name + ": " + value
|
||||||
|
|
||||||
|
|
||||||
def get_unit_name(line):
|
# def get_unit_name(line):
|
||||||
global lines
|
# global lines
|
||||||
return search(r" : (.+) {$", lines[line]).group(1)
|
# return search(r" : (.+) {$", lines[line]).group(1)
|
||||||
|
|
||||||
|
|
||||||
def get_array_length(line):
|
def get_array_length(line):
|
||||||
@@ -81,19 +82,19 @@ def get_array_length(line):
|
|||||||
return int(search(r": ([0-9]+)$", lines[line]).group(1))
|
return int(search(r": ([0-9]+)$", lines[line]).group(1))
|
||||||
|
|
||||||
|
|
||||||
def get_array_value_by_index(line, index):
|
# def get_array_value_by_index(line, index):
|
||||||
global lines
|
# global lines
|
||||||
return search(r": (.+)$", lines[line + index + 1]).group(1)
|
# return search(r": (.+)$", lines[line + index + 1]).group(1)
|
||||||
|
#
|
||||||
|
#
|
||||||
def get_array_index_by_value(line, value):
|
# def get_array_index_by_value(line, value):
|
||||||
global lines
|
# global lines
|
||||||
count = 0
|
# count = 0
|
||||||
for i in range(get_array_length(line)):
|
# for i in range(get_array_length(line)):
|
||||||
if get_value(line + count + 1) == value:
|
# if get_value(line + count + 1) == value:
|
||||||
return count
|
# return count
|
||||||
count += 1
|
# count += 1
|
||||||
return None
|
# return None
|
||||||
|
|
||||||
|
|
||||||
def get_array_items(line):
|
def get_array_items(line):
|
||||||
@@ -114,17 +115,17 @@ def add_array_value(line, value):
|
|||||||
lines.insert(line + count + 1, name + "[" + str(count) + "]: " + value)
|
lines.insert(line + count + 1, name + "[" + str(count) + "]: " + value)
|
||||||
|
|
||||||
|
|
||||||
def remove_array_value(line, value):
|
# def remove_array_value(line, value):
|
||||||
global lines
|
# global lines
|
||||||
name = match(r"(.+):", lines[line]).group(1)
|
# name = match(r"(.+):", lines[line]).group(1)
|
||||||
del lines[line + 1 + get_array_index_by_value(line, value)]
|
# del lines[line + 1 + get_array_index_by_value(line, value)]
|
||||||
count = get_array_length(line)
|
# count = get_array_length(line)
|
||||||
lines[line] = name + ": " + str(count - 1)
|
# lines[line] = name + ": " + str(count - 1)
|
||||||
for i in range(count):
|
# for i in range(count):
|
||||||
lines[line + i + 1] = sub(r"\[[0-9]+\]", "[" + str(i) + "]", lines[line + i + 1])
|
# lines[line + i + 1] = sub(r"\[[0-9]+]", "[" + str(i) + "]", lines[line + i + 1])
|
||||||
|
#
|
||||||
|
#
|
||||||
def change_array_value(line, index, value):
|
# def change_array_value(line, index, value):
|
||||||
global lines
|
# global lines
|
||||||
line += index + 1
|
# line += index + 1
|
||||||
set_value(line, value)
|
# set_value(line, value)
|
||||||
|
|||||||
Reference in New Issue
Block a user