|
1 | 1 | import sys |
2 | | -import time |
3 | 2 |
|
4 | 3 | from loguru import logger |
5 | 4 |
|
6 | | -from system import clear |
7 | | -from system.lib.config import config |
8 | | -from system.lib.console import Console |
9 | | -from system.lib.features.directories import clear_directories |
10 | | -from system.lib.features.initialization import initialize |
11 | | -from system.lib.features.update.check import check_for_outdated, check_update, get_tags |
12 | | -from system.lib.menu import Menu, menu |
13 | | -from system.localization import locale |
14 | | - |
15 | 5 | logger.remove() |
16 | 6 | logger.add( |
17 | 7 | "./logs/info/{time:YYYY-MM-DD}.log", |
|
28 | 18 | level="ERROR", |
29 | 19 | ) |
30 | 20 | logger.add(sys.stdout, format="<lvl>[{level}] {message}</lvl>", level="INFO") |
31 | | - |
32 | | - |
33 | | -locale.load(config.language) |
34 | | - |
35 | | - |
36 | | -def check_auto_update(): |
37 | | - if config.auto_update and time.time() - config.last_update > 60 * 60 * 24 * 7: |
38 | | - check_update() |
39 | | - config.last_update = int(time.time()) |
40 | | - config.dump() |
41 | | - |
42 | | - |
43 | | -def check_files_updated(): |
44 | | - if config.has_update: |
45 | | - logger.opt(colors=True).info(f'<green>{locale.update_done % ""}</green>') |
46 | | - if Console.question(locale.done_qu): |
47 | | - latest_tag = get_tags("vorono4ka", "xcoder")[0] |
48 | | - latest_tag_name = latest_tag["name"][1:] |
49 | | - |
50 | | - config.has_update = False |
51 | | - config.version = latest_tag_name |
52 | | - config.last_update = int(time.time()) |
53 | | - config.dump() |
54 | | - else: |
55 | | - exit() |
56 | | - |
57 | | - |
58 | | -# noinspection PyUnresolvedReferences |
59 | | -@logger.catch() |
60 | | -def refill_menu(): |
61 | | - menu.categories.clear() |
62 | | - |
63 | | - sc_category = Menu.Category(0, locale.sc_label) |
64 | | - ktx_category = Menu.Category(1, locale.ktx_label) |
65 | | - csv_category = Menu.Category(2, locale.csv_label) |
66 | | - other = Menu.Category(10, locale.other_features_label) |
67 | | - |
68 | | - menu.add_category(sc_category) |
69 | | - menu.add_category(ktx_category) |
70 | | - menu.add_category(csv_category) |
71 | | - menu.add_category(other) |
72 | | - |
73 | | - try: |
74 | | - import sc_compression |
75 | | - |
76 | | - del sc_compression |
77 | | - except ImportError: |
78 | | - logger.warning(locale.install_to_unlock % "sc-compression") |
79 | | - else: |
80 | | - from system.lib.features.csv.compress import compress_csv |
81 | | - from system.lib.features.csv.decompress import decompress_csv |
82 | | - |
83 | | - try: |
84 | | - import PIL |
85 | | - |
86 | | - del PIL |
87 | | - except ImportError: |
88 | | - logger.warning(locale.install_to_unlock % "PILLOW") |
89 | | - else: |
90 | | - from system.lib.features.sc.decode import ( |
91 | | - decode_and_render_objects, |
92 | | - decode_textures_only, |
93 | | - ) |
94 | | - from system.lib.features.sc.encode import ( |
95 | | - collect_objects_and_encode, |
96 | | - encode_textures_only, |
97 | | - ) |
98 | | - |
99 | | - sc_category.add( |
100 | | - Menu.Item( |
101 | | - name=locale.decode_sc, |
102 | | - description=locale.decode_sc_description, |
103 | | - handler=decode_textures_only, |
104 | | - ) |
105 | | - ) |
106 | | - sc_category.add( |
107 | | - Menu.Item( |
108 | | - name=locale.encode_sc, |
109 | | - description=locale.encode_sc_description, |
110 | | - handler=encode_textures_only, |
111 | | - ) |
112 | | - ) |
113 | | - sc_category.add( |
114 | | - Menu.Item( |
115 | | - name=locale.decode_by_parts, |
116 | | - description=locale.decode_by_parts_description, |
117 | | - handler=decode_and_render_objects, |
118 | | - ) |
119 | | - ) |
120 | | - sc_category.add( |
121 | | - Menu.Item( |
122 | | - name=locale.encode_by_parts, |
123 | | - description=locale.encode_by_parts_description, |
124 | | - handler=collect_objects_and_encode, |
125 | | - ) |
126 | | - ) |
127 | | - sc_category.add( |
128 | | - Menu.Item( |
129 | | - name=locale.overwrite_by_parts, |
130 | | - description=locale.overwrite_by_parts_description, |
131 | | - handler=lambda: collect_objects_and_encode(True), |
132 | | - ) |
133 | | - ) |
134 | | - |
135 | | - from system.lib.features.ktx import ( |
136 | | - convert_ktx_textures_to_png, |
137 | | - convert_png_textures_to_ktx, |
138 | | - ) |
139 | | - from system.lib.pvr_tex_tool import can_use_pvr_tex_tool |
140 | | - |
141 | | - if can_use_pvr_tex_tool(): |
142 | | - ktx_category.add( |
143 | | - Menu.Item( |
144 | | - name=locale.ktx_from_png_label, |
145 | | - description=locale.ktx_from_png_description, |
146 | | - handler=convert_png_textures_to_ktx, |
147 | | - ) |
148 | | - ) |
149 | | - ktx_category.add( |
150 | | - Menu.Item( |
151 | | - name=locale.png_from_ktx_label, |
152 | | - description=locale.png_from_ktx_description, |
153 | | - handler=convert_ktx_textures_to_png, |
154 | | - ) |
155 | | - ) |
156 | | - |
157 | | - csv_category.add( |
158 | | - Menu.Item( |
159 | | - name=locale.decompress_csv, |
160 | | - description=locale.decompress_csv_description, |
161 | | - handler=decompress_csv, |
162 | | - ) |
163 | | - ) |
164 | | - csv_category.add( |
165 | | - Menu.Item( |
166 | | - name=locale.compress_csv, |
167 | | - description=locale.compress_csv_description, |
168 | | - handler=compress_csv, |
169 | | - ) |
170 | | - ) |
171 | | - |
172 | | - other.add( |
173 | | - Menu.Item( |
174 | | - name=locale.check_update, |
175 | | - description=locale.version % config.version, |
176 | | - handler=check_update, |
177 | | - ) |
178 | | - ) |
179 | | - other.add(Menu.Item(name=locale.check_for_outdated, handler=check_for_outdated)) |
180 | | - other.add( |
181 | | - Menu.Item( |
182 | | - name=locale.reinit, |
183 | | - description=locale.reinit_description, |
184 | | - handler=lambda: (initialize(), refill_menu()), |
185 | | - ) |
186 | | - ) |
187 | | - other.add( |
188 | | - Menu.Item( |
189 | | - name=locale.change_language, |
190 | | - description=locale.change_lang_description % config.language, |
191 | | - handler=lambda: (config.change_language(locale.change()), refill_menu()), |
192 | | - ) |
193 | | - ) |
194 | | - other.add( |
195 | | - Menu.Item( |
196 | | - name=locale.clear_directories, |
197 | | - description=locale.clean_dirs_description, |
198 | | - handler=lambda: clear_directories() |
199 | | - if Console.question(locale.clear_qu) |
200 | | - else -1, |
201 | | - ) |
202 | | - ) |
203 | | - other.add( |
204 | | - Menu.Item( |
205 | | - name=locale.toggle_update_auto_checking, |
206 | | - description=locale.enabled if config.auto_update else locale.disabled, |
207 | | - handler=lambda: (config.toggle_auto_update(), refill_menu()), |
208 | | - ) |
209 | | - ) |
210 | | - other.add(Menu.Item(name=locale.exit, handler=lambda: (clear(), exit()))) |
0 commit comments