| 447 | * @param removeCRCharacters If true, will remove \r characters usually added by Windows when editing files |
| 448 | */ |
| 449 | export const loadVariableFromJSONFile = function ( |
| 450 | variable: gdjs.Variable, |
| 451 | loadPath: string, |
| 452 | resultVar: gdjs.Variable, |
| 453 | removeCRCharacters: boolean |
| 454 | ) { |
| 455 | let result = 'error'; |
| 456 | if (fs) { |
| 457 | try { |
| 458 | const data = fs.readFileSync(loadPath, 'utf8'); |
| 459 | if (data) { |
| 460 | variable.fromJSON( |
| 461 | removeCRCharacters ? data.replace(/\r/g, '') : data |
| 462 | ); |
| 463 | result = 'ok'; |
| 464 | } |
| 465 | } catch (err) { |
| 466 | logger.error( |
| 467 | "Unable to load variable from the file at path: '" + |
| 468 | loadPath + |
| 469 | "': ", |
| 470 | err |
| 471 | ); |
| 472 | } |
| 473 | } |
| 474 | resultVar.setString(result); |
| 475 | }; |
| 476 | |
| 477 | /** |
| 478 | * Load a JSON file and convert it into a variable, asynchronously. |