|
1 | 1 | <script lang="ts" context="module"> |
2 | 2 | import { Valuable } from '../util/stores' |
3 | 3 | import { translate } from '../util/translation' |
4 | | - import { resolveEnvVariables } from '../util/misc' |
5 | 4 | import { MINECRAFT_REGISTRY } from '../systems/minecraft/registryManager' |
6 | 5 |
|
7 | 6 | import Checkbox from './dialogItems/checkbox.svelte' |
|
19 | 18 | import KoFiImage from '../assets/kofi_s_tag_white.webp' |
20 | 19 |
|
21 | 20 | import fontUrl from '../assets/MinecraftFull.ttf' |
| 21 | + import { resolvePath } from '../util/fileUtil' |
22 | 22 | if (![...document.fonts.keys()].some(v => v.family === 'MinecraftFull')) { |
23 | 23 | void new FontFace('MinecraftFull', fontUrl, {}).load().then(font => { |
24 | 24 | document.fonts.add(font) |
|
163 | 163 | } |
164 | 164 |
|
165 | 165 | function dataPackFolderChecker(value: string): { type: string; message: string } { |
166 | | - value = resolveEnvVariables(value) |
| 166 | + let path: string |
| 167 | + try { |
| 168 | + path = resolvePath(value) |
| 169 | + } catch (e) { |
| 170 | + console.error(e) |
| 171 | + return { |
| 172 | + type: 'error', |
| 173 | + message: translate( |
| 174 | + 'dialog.blueprint_settings.data_pack.error.folder_does_not_exist', |
| 175 | + ), |
| 176 | + } |
| 177 | + } |
| 178 | + console.log(path) |
167 | 179 | switch (true) { |
168 | 180 | case value === '': |
169 | 181 | return { |
|
172 | 184 | 'dialog.blueprint_settings.data_pack.error.no_folder_selected', |
173 | 185 | ), |
174 | 186 | } |
175 | | - case !fs.existsSync(value): |
| 187 | + case !fs.existsSync(path): |
176 | 188 | return { |
177 | 189 | type: 'error', |
178 | 190 | message: translate( |
179 | 191 | 'dialog.blueprint_settings.data_pack.error.folder_does_not_exist', |
180 | 192 | ), |
181 | 193 | } |
182 | | - case !fs.statSync(value).isDirectory(): |
| 194 | + case !fs.statSync(path).isDirectory(): |
183 | 195 | return { |
184 | 196 | type: 'error', |
185 | 197 | message: translate('dialog.blueprint_settings.data_pack.error.not_a_folder'), |
186 | 198 | } |
187 | | - case !fs.existsSync(PathModule.join(value, 'pack.mcmeta')): |
| 199 | + case !fs.existsSync(PathModule.join(path, 'pack.mcmeta')): |
188 | 200 | return { |
189 | 201 | type: 'error', |
190 | 202 | message: translate( |
191 | 203 | 'dialog.blueprint_settings.data_pack.error.missing_pack_mcmeta', |
192 | 204 | ), |
193 | 205 | } |
194 | | - case !fs.existsSync(PathModule.join(value, 'data')): |
| 206 | + case !fs.existsSync(PathModule.join(path, 'data')): |
195 | 207 | return { |
196 | 208 | type: 'error', |
197 | 209 | message: translate( |
|
204 | 216 | } |
205 | 217 |
|
206 | 218 | function resourcePackFolderChecker(value: string): { type: string; message: string } { |
| 219 | + let path: string |
| 220 | + try { |
| 221 | + path = resolvePath(value) |
| 222 | + } catch (e) { |
| 223 | + console.error(e) |
| 224 | + return { |
| 225 | + type: 'error', |
| 226 | + message: translate( |
| 227 | + 'dialog.blueprint_settings.resource_pack.error.folder_does_not_exist', |
| 228 | + ), |
| 229 | + } |
| 230 | + } |
| 231 | + console.log(path) |
207 | 232 | switch (true) { |
208 | 233 | case value === '': |
209 | 234 | return { |
|
212 | 237 | 'dialog.blueprint_settings.resource_pack.error.no_folder_selected', |
213 | 238 | ), |
214 | 239 | } |
215 | | - case !fs.existsSync(value): |
| 240 | + case !fs.existsSync(path): |
216 | 241 | return { |
217 | 242 | type: 'error', |
218 | 243 | message: translate( |
219 | 244 | 'dialog.blueprint_settings.resource_pack.error.folder_does_not_exist', |
220 | 245 | ), |
221 | 246 | } |
222 | | - case !fs.statSync(value).isDirectory(): |
| 247 | + case !fs.statSync(path).isDirectory(): |
223 | 248 | return { |
224 | 249 | type: 'error', |
225 | 250 | message: translate( |
226 | 251 | 'dialog.blueprint_settings.resource_pack.error.not_a_folder', |
227 | 252 | ), |
228 | 253 | } |
229 | | - case !fs.existsSync(PathModule.join(value, 'pack.mcmeta')): |
| 254 | + case !fs.existsSync(PathModule.join(path, 'pack.mcmeta')): |
230 | 255 | return { |
231 | 256 | type: 'error', |
232 | 257 | message: translate( |
233 | 258 | 'dialog.blueprint_settings.resource_pack.error.missing_pack_mcmeta', |
234 | 259 | ), |
235 | 260 | } |
236 | | - case !fs.existsSync(PathModule.join(value, 'assets')): |
| 261 | + case !fs.existsSync(PathModule.join(path, 'assets')): |
237 | 262 | return { |
238 | 263 | type: 'error', |
239 | 264 | message: translate( |
|
246 | 271 | } |
247 | 272 |
|
248 | 273 | function advancedResourcePackFileChecker(value: string): { type: string; message: string } { |
| 274 | + let path: string |
| 275 | + try { |
| 276 | + path = resolvePath(value) |
| 277 | + } catch (e) { |
| 278 | + console.error(e) |
| 279 | + return { |
| 280 | + type: 'error', |
| 281 | + message: translate( |
| 282 | + 'dialog.blueprint_settings.advanced_resource_pack_file.error.file_does_not_exist', |
| 283 | + ), |
| 284 | + } |
| 285 | + } |
| 286 | + console.log(path) |
249 | 287 | switch (true) { |
250 | 288 | case value === '': |
251 | 289 | return { |
|
254 | 292 | 'dialog.blueprint_settings.advanced_resource_pack_file.error.no_file_selected', |
255 | 293 | ), |
256 | 294 | } |
257 | | - case !fs.existsSync(value): |
| 295 | + case !fs.existsSync(path): |
258 | 296 | return { |
259 | 297 | type: 'error', |
260 | 298 | message: translate( |
261 | 299 | 'dialog.blueprint_settings.advanced_resource_pack_file.error.file_does_not_exist', |
262 | 300 | ), |
263 | 301 | } |
264 | | - case !fs.statSync(value).isFile(): |
| 302 | + case !fs.statSync(path).isFile(): |
265 | 303 | return { |
266 | 304 | type: 'error', |
267 | 305 | message: translate( |
|
274 | 312 | } |
275 | 313 |
|
276 | 314 | function jsonFileChecker(value: string): { type: string; message: string } { |
| 315 | + let path: string |
| 316 | + try { |
| 317 | + path = resolvePath(value) |
| 318 | + } catch (e) { |
| 319 | + console.error(e) |
| 320 | + return { |
| 321 | + type: 'error', |
| 322 | + message: translate('dialog.blueprint_settings.json_file.error.file_does_not_exist'), |
| 323 | + } |
| 324 | + } |
| 325 | + console.log(path) |
277 | 326 | switch (true) { |
278 | 327 | case value === '': |
279 | 328 | return { |
|
282 | 331 | 'dialog.blueprint_settings.json_file.error.no_file_selected', |
283 | 332 | ), |
284 | 333 | } |
285 | | - case fs.existsSync(value) && !fs.statSync(value).isFile(): |
| 334 | + case fs.existsSync(path) && !fs.statSync(path).isFile(): |
286 | 335 | return { |
287 | 336 | type: 'error', |
288 | 337 | message: translate('dialog.blueprint_settings.json_file.error.not_a_file'), |
|
293 | 342 | } |
294 | 343 |
|
295 | 344 | function advancedResourcePackFolderChecker(value: string): { type: string; message: string } { |
| 345 | + let path: string |
| 346 | + try { |
| 347 | + path = resolvePath(value) |
| 348 | + } catch (e) { |
| 349 | + console.error(e) |
| 350 | + return { |
| 351 | + type: 'error', |
| 352 | + message: translate( |
| 353 | + 'dialog.blueprint_settings.advanced_resource_pack_folder.error.folder_does_not_exist', |
| 354 | + ), |
| 355 | + } |
| 356 | + } |
| 357 | + console.log(path) |
296 | 358 | switch (true) { |
297 | 359 | case value === '': |
298 | 360 | return { |
|
301 | 363 | 'dialog.blueprint_settings.advanced_resource_pack_folder.error.no_folder_selected', |
302 | 364 | ), |
303 | 365 | } |
304 | | - case !fs.existsSync(value): |
| 366 | + case !fs.existsSync(path): |
305 | 367 | return { |
306 | 368 | type: 'error', |
307 | 369 | message: translate( |
308 | 370 | 'dialog.blueprint_settings.advanced_resource_pack_folder.error.folder_does_not_exist', |
309 | 371 | ), |
310 | 372 | } |
311 | | - case !fs.statSync(value).isDirectory(): |
| 373 | + case !fs.statSync(path).isDirectory(): |
312 | 374 | return { |
313 | 375 | type: 'error', |
314 | 376 | message: translate( |
|
321 | 383 | } |
322 | 384 |
|
323 | 385 | function zipChecker(value: string): { type: string; message: string } { |
| 386 | + let path: string |
| 387 | + try { |
| 388 | + path = resolvePath(value) |
| 389 | + } catch (e) { |
| 390 | + console.error(e) |
| 391 | + return { |
| 392 | + type: 'error', |
| 393 | + message: translate( |
| 394 | + 'dialog.blueprint_settings.data_pack_zip.error.file_does_not_exist', |
| 395 | + ), |
| 396 | + } |
| 397 | + } |
| 398 | + console.log(path) |
324 | 399 | switch (true) { |
325 | 400 | case value === '': |
326 | 401 | return { |
|
329 | 404 | 'dialog.blueprint_settings.resource_pack_zip.error.no_file_selected', |
330 | 405 | ), |
331 | 406 | } |
332 | | - case fs.existsSync(value) && !fs.statSync(value).isFile(): |
| 407 | + case fs.existsSync(path) && !fs.statSync(path).isFile(): |
333 | 408 | return { |
334 | 409 | type: 'error', |
335 | 410 | message: translate( |
|
0 commit comments