()
| 71 | } |
| 72 | |
| 73 | private load(): void { |
| 74 | this.state.clear(); |
| 75 | |
| 76 | if (existsSync(this.file)) { |
| 77 | try { |
| 78 | const stateObj = JSON.parse(readFileSync(this.file, "utf8")) as KeyValue; |
| 79 | |
| 80 | for (const key in stateObj) { |
| 81 | this.state.set(key.startsWith("0x") ? key : Number.parseInt(key, 10), stateObj[key]); |
| 82 | } |
| 83 | |
| 84 | logger.debug(`Loaded state from file ${this.file}`); |
| 85 | } catch (error) { |
| 86 | logger.debug(`Failed to load state from file ${this.file} (corrupt file?) (${(error as Error).message})`); |
| 87 | } |
| 88 | } else { |
| 89 | logger.debug(`Can't load state from file ${this.file} (doesn't exist)`); |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | private save(): void { |
| 94 | if (settings.get().advanced.cache_state_persistent) { |
no test coverage detected