|
1 | 1 | import {HIVES, shortenHive, extendHive} from './constants.mjs' |
2 | | -import {sanitizePath} from './util.mjs' |
| 2 | +import {sanitizePath, spawn} from './util.mjs' |
3 | 3 |
|
4 | 4 |
|
5 | 5 | // Collection of static methods for interacting with any key in windows registry. |
@@ -33,11 +33,39 @@ export class Registry { |
33 | 33 | return args |
34 | 34 | } |
35 | 35 |
|
| 36 | + static async setCodePage(encoding) { |
| 37 | + try { |
| 38 | + await spawn('cmd.exe', ['/c', 'chcp', encoding]) |
| 39 | + } catch (e) { |
| 40 | + throw new Error(`Invalid code page: ${encoding}`) |
| 41 | + } |
| 42 | + } |
| 43 | + |
| 44 | + static async enableUnicode() { |
| 45 | + if (this.unicode) return |
| 46 | + var {stdout} = await spawn('cmd.exe', ['/c', 'chcp']) |
| 47 | + var cp = Number(stdout.split(':')[1]) |
| 48 | + if (Number.isNaN(cp)) throw new Error(`Can't get current code page`) |
| 49 | + this.lastCodePage = cp |
| 50 | + this.unicode = true |
| 51 | + } |
| 52 | + |
| 53 | + static async disableUnicode() { |
| 54 | + if (!this.unicode) return |
| 55 | + await this.setCodePage(this.lastCodePage) |
| 56 | + this.lastCodePage = undefined |
| 57 | + this.unicode = false |
| 58 | + } |
| 59 | + |
36 | 60 | } |
37 | 61 |
|
38 | 62 | Registry.VALUES = '$values' |
39 | 63 | Registry.DEFAULT = '' |
40 | 64 |
|
| 65 | + |
| 66 | +Registry.unicode = false |
| 67 | +Registry.lastCodePage |
| 68 | + |
41 | 69 | // Only names and paths are affected, not the data |
42 | 70 | Registry.lowercase = true |
43 | 71 | // Calls return simplified output format by default. |
|
0 commit comments