Skip to content

Commit ce5eafa

Browse files
Fixed config dumping
1 parent 2a74a18 commit ce5eafa

File tree

5 files changed

+63
-50
lines changed

5 files changed

+63
-50
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@ Many thanks to <a href="https://github.com/spiky-s">spiky_Spike</a> for the prov
1616
On Windows:
1717
- Download Python 3.7 or newer version from <a href="https://www.python.org/downloads/">official page</a>.
1818
- Install Python. While Installing, enable such parameters as "Add Python to PATH", "Install pip", "Install py launcher", "Associate files with Python" and "Add Python to environment variables".
19-
- Download XCoder from <a href="https://github.com/MasterDevX/XCoder/releases">releases page</a> and extract it.
19+
- Download XCoder from <a href="https://github.com/Vorono4ka/XCoder/releases">releases page</a> and extract it.
2020
- Execute "main.py" file</br>
2121

2222
On Linux:
2323
- Open Terminal and install Python by executing following command:</br>
2424
```sudo apt-get update && sudo apt-get install python3 python3-pip```
25-
- Download XCoder from <a href="https://github.com/MasterDevX/XCoder/releases">releases page</a> and extract it.
25+
- Download XCoder from <a href="https://github.com/Vorono4ka/XCoder/releases">releases page</a> and extract it.
2626
- Execute "main.py" file
2727

2828
On Android:
2929
- Download and install PyDroid app from <a href="https://play.google.com/store/apps/details?id=ru.iiec.pydroid3">Google Play</a>.
3030
- Open PyDroid and wait until Python installs.
31-
- Download XCoder from <a href="https://github.com/MasterDevX/XCoder/releases">releases page</a> and extract it.
31+
- Download XCoder from <a href="https://github.com/Vorono4ka/XCoder/releases">releases page</a> and extract it.
3232
- In PyDroid open and execute "main.py" file</br>
3333

3434
### TODO:

lib.py

Lines changed: 42 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,14 @@ def make_dirs(directory):
8989
os.makedirs(directory)
9090

9191

92-
def print_feature_with_description(name: str, description: str = None, console_width: int = -1):
92+
def print_feature(name: str, description: str = None, console_width: int = -1):
9393
print(name, end='')
9494
if description:
9595
print(' ' * (console_width // 2 - len(name)) + ': ' + description, end='')
9696
print()
9797

9898

99-
def colored_print(text, color=None):
99+
def print_category(text, color=None):
100100
if color is None:
101101
color = colorama.Back.GREEN
102102
return print(color + colorama.Fore.BLACK + text + ' ' * (10 - len(text)) + colorama.Style.RESET_ALL)
@@ -106,41 +106,39 @@ def welcome_text():
106106
locale.load_from(config.lang)
107107

108108
console_width = shutil.get_terminal_size().columns
109-
print(
110-
(
111-
colorama.Back.BLACK + colorama.Fore.GREEN +
112-
locale.xcoder_header % config.version +
113-
colorama.Style.RESET_ALL
114-
).center(console_width + 14)
115-
)
109+
print((
110+
colorama.Back.BLACK + colorama.Fore.GREEN +
111+
locale.xcoder_header % config.version +
112+
colorama.Style.RESET_ALL
113+
).center(console_width + 14))
116114
print('github.com/Vorono4ka/XCoder'.center(console_width))
117115
print(console_width * '-')
118116

119-
colored_print(locale.sc_label)
120-
print_feature_with_description(' 1 ' + locale.decode_sc, locale.decode_sc_description, console_width)
121-
print_feature_with_description(' 2 ' + locale.encode_sc, locale.encode_sc_description, console_width)
122-
print_feature_with_description(' 3 ' + locale.decode_by_parts, locale.decode_by_parts_description, console_width)
123-
print_feature_with_description(' 4 ' + locale.encode_by_parts, locale.encode_by_parts_description, console_width)
124-
print_feature_with_description(' 5 ' + locale.overwrite_by_parts, locale.overwrite_by_parts_description, console_width)
117+
print_category(locale.sc_label)
118+
print_feature(' 1 ' + locale.decode_sc, locale.decode_sc_description, console_width)
119+
print_feature(' 2 ' + locale.encode_sc, locale.encode_sc_description, console_width)
120+
print_feature(' 3 ' + locale.decode_by_parts, locale.decode_by_parts_description, console_width)
121+
print_feature(' 4 ' + locale.encode_by_parts, locale.encode_by_parts_description, console_width)
122+
print_feature(' 5 ' + locale.overwrite_by_parts, locale.overwrite_by_parts_description, console_width)
125123
print(console_width * '-')
126124

127-
colored_print(locale.csv_label)
128-
print_feature_with_description(' 11 ' + locale.decompress_csv, locale.decompress_csv_description, console_width)
129-
print_feature_with_description(' 12 ' + locale.compress_csv, locale.compress_csv_description, console_width)
125+
print_category(locale.csv_label)
126+
print_feature(' 11 ' + locale.decompress_csv, locale.decompress_csv_description, console_width)
127+
print_feature(' 12 ' + locale.compress_csv, locale.compress_csv_description, console_width)
130128
print(console_width * '-')
131129

132-
colored_print(locale.other_features_label)
133-
print_feature_with_description(' 101 ' + locale.check_update, locale.version % config.version, console_width)
134-
print_feature_with_description(' 102 ' + locale.check_for_outdated)
135-
print_feature_with_description(' 103 ' + locale.reinit, locale.reinit_description, console_width)
136-
print_feature_with_description(' 104 ' + locale.change_lang, locale.change_lang_description % config.lang, console_width)
137-
print_feature_with_description(' 105 ' + locale.clear_dirs, locale.clean_dirs_description, console_width)
138-
print_feature_with_description(
130+
print_category(locale.other_features_label)
131+
print_feature(' 101 ' + locale.check_update, locale.version % config.version, console_width)
132+
print_feature(' 102 ' + locale.check_for_outdated)
133+
print_feature(' 103 ' + locale.reinit, locale.reinit_description, console_width)
134+
print_feature(' 104 ' + locale.change_lang, locale.change_lang_description % config.lang, console_width)
135+
print_feature(' 105 ' + locale.clear_dirs, locale.clean_dirs_description, console_width)
136+
print_feature(
139137
' 106 ' + locale.toggle_update_auto_checking,
140138
locale.enabled if config.auto_update else locale.disabled,
141139
console_width
142140
)
143-
print_feature_with_description(' 107 ' + locale.exit)
141+
print_feature(' 107 ' + locale.exit)
144142
print(console_width * '-')
145143

146144
choice = input(locale.choice)
@@ -354,12 +352,14 @@ def sc1_decode():
354352
base_name = os.path.basename(file).rsplit('.', 1)[0]
355353

356354
with open(f'{folder_export}/{current_sub_path}/{base_name}.xcod', 'wb') as xcod_file:
357-
xcod_file.write(b'XCOD' + bool.to_bytes(use_lzham, 1, 'big') + int.to_bytes(len(swf.textures), 1, 'big'))
355+
xcod_file.write(b'XCOD' + bool.to_bytes(use_lzham, 1, 'big') +
356+
int.to_bytes(len(swf.textures), 1, 'big'))
358357

359358
for img_index in range(len(swf.textures)):
360359
filename = base_name + '_' * img_index
361-
swf.textures[img_index].image.save(f'{folder_export}/{current_sub_path}/textures/{filename}.png')
362-
360+
swf.textures[img_index].image.save(
361+
f'{folder_export}/{current_sub_path}/textures/{filename}.png'
362+
)
363363

364364
Console.info(locale.dec_sc)
365365

@@ -436,7 +436,7 @@ def open_sc(input_filename: str):
436436
#
437437
if signature == Signatures.SCLZ:
438438
use_lzham = True
439-
except Exception:
439+
except TypeError:
440440
Console.info(locale.decompression_error)
441441
exit(1)
442442

@@ -471,7 +471,7 @@ def compile_sc(_dir, from_memory=None, img_data=None, folder_export=None):
471471
use_lzham, = struct.unpack('?', sc_data.read(1))
472472
sc_data.read(1)
473473
has_xcod = True
474-
except Exception:
474+
except OSError:
475475
Console.info(locale.not_xcod)
476476
Console.info(locale.default_types)
477477

@@ -609,7 +609,13 @@ def load_tags(self):
609609
texture.load(self, tag, has_texture)
610610

611611
if has_texture:
612-
Console.info(locale.about_sc % (self.filename, texture_id, texture.pixel_type, texture.width, texture.height))
612+
Console.info(locale.about_sc % (
613+
self.filename,
614+
texture_id,
615+
texture.pixel_type,
616+
texture.width,
617+
texture.height
618+
))
613619
print()
614620

615621
self.xcod_writer.write_ubyte(tag)
@@ -690,7 +696,10 @@ def place_sprites(xcod, folder, overwrite=False):
690696
sheet_image = []
691697
sheet_image_data = {'use_lzham': use_lzham, 'data': []}
692698
for i in range(pictures_count):
693-
file_type, sub_type, width, height = xcod.read_ubyte(), xcod.read_ubyte(), xcod.read_uint16(), xcod.read_uint16()
699+
file_type, sub_type, width, height = xcod.read_ubyte(), \
700+
xcod.read_ubyte(), \
701+
xcod.read_uint16(), \
702+
xcod.read_uint16()
694703
sheet_image.append(
695704
Image.open(f'{folder}/textures/{tex[i]}')
696705
if overwrite else

main.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ def select_lang():
2525
config.dump()
2626

2727

28-
def init(ret=True):
29-
if ret:
28+
def init(first_init=False):
29+
if first_init:
3030
clear()
3131

3232
Console.info(locale.detected_os % platform.system())
@@ -51,7 +51,7 @@ def init(ret=True):
5151
config.version = get_tags('vorono4ka', 'xcoder')[0]['name'][1:]
5252
config.dump()
5353

54-
if ret:
54+
if first_init:
5555
input(locale.to_continue)
5656

5757

@@ -82,11 +82,7 @@ def clear_dirs():
8282
locale.load_from(config.lang)
8383

8484
if not config.inited:
85-
init()
86-
try:
87-
run('python%s "%s"' % ('' if is_windows else '3', __file__))
88-
except Exception as e:
89-
logger.write(e)
85+
init(True)
9086
exit()
9187

9288
if is_windows:
@@ -125,11 +121,13 @@ def clear_dirs():
125121
'3': sc1_decode,
126122
'4': sc1_encode,
127123
'5': lambda: sc1_encode(True),
124+
128125
'11': decompress_csv,
129126
'12': compress_csv,
127+
130128
'101': check_update,
131129
'102': check_for_outdated,
132-
'103': lambda: init(ret=False),
130+
'103': init,
133131
'104': lambda: (select_lang(), locale.load_from(config.lang)),
134132
'105': lambda: clear_dirs() if Console.question(locale.clear_qu) else -1,
135133
'106': toggle_auto_update,

system/languages/ru-RU.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"reinit": "Повторная инициализация",
3939
"change_lang": "Выбрать другой язык",
4040
"clear_dirs": "Очистить рабочие папки",
41-
"toggle_update_auto_checking": "Включить/Выключить проверку обновлений",
41+
"toggle_update_auto_checking": "Переключить проверку обновлений",
4242
"exit": "Выход",
4343
"version": "Версия: %s",
4444
"reinit_description": "Если что-то пошло не так",

system/lib/config.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,16 @@ class Config:
77
inited: bool
88

99
def __init__(self):
10-
self.config_items = []
11-
12-
self.inited: bool = False
10+
self.config_items = (
11+
'initialized',
12+
'version',
13+
'lang',
14+
'has_update',
15+
'last_update',
16+
'auto_update',
17+
)
18+
19+
self.initialized: bool = False
1320
self.version = None
1421
self.lang: str = 'en-EU'
1522
self.has_update: bool = False
@@ -22,7 +29,6 @@ def load(self):
2229
if os.path.isfile(self.config_path):
2330
for key, value in json.load(open(self.config_path)).items():
2431
setattr(self, key, value)
25-
self.config_items.append(key)
2632

2733
def dump(self):
2834
json.dump({

0 commit comments

Comments
 (0)