This repository was archived by the owner on Oct 1, 2024. It is now read-only.
File tree 1 file changed +20
-7
lines changed
1 file changed +20
-7
lines changed Original file line number Diff line number Diff line change @@ -207,13 +207,16 @@ export function spawn(
207
207
208
208
let codepage = "65001" ;
209
209
if ( os . platform ( ) === "win32" ) {
210
- try {
211
- const chcp = child_process . execSync ( "chcp.com" ) ;
212
- codepage = chcp . toString ( ) . split ( ":" ) . pop ( ) . trim ( ) ;
213
- } catch ( error ) {
214
- arduinoChannel . warning ( `Defaulting to code page 850 because chcp.com failed.\
215
- \rEnsure your path includes %SystemRoot%\\system32\r${ error . message } ` ) ;
216
- codepage = "850" ;
210
+ codepage = getArduinoL4jCodepage ( command . replace ( / .e x e $ / i, ".l4j.ini" ) ) ;
211
+ if ( ! codepage ) {
212
+ try {
213
+ const chcp = child_process . execSync ( "chcp.com" ) ;
214
+ codepage = chcp . toString ( ) . split ( ":" ) . pop ( ) . trim ( ) ;
215
+ } catch ( error ) {
216
+ arduinoChannel . warning ( `Defaulting to code page 850 because chcp.com failed.\
217
+ \rEnsure your path includes %SystemRoot%\\system32\r${ error . message } ` ) ;
218
+ codepage = "850" ;
219
+ }
217
220
}
218
221
}
219
222
@@ -253,6 +256,16 @@ export function spawn(
253
256
} ) ;
254
257
}
255
258
259
+ export function getArduinoL4jCodepage ( filePath : string ) : string | undefined {
260
+ const encoding = parseConfigFile ( filePath ) . get ( "-Dfile.encoding" ) ;
261
+ if ( encoding === "UTF8" ) {
262
+ return "65001" ;
263
+ }
264
+ return Object . keys ( encodingMapping ) . reduce ( ( r , key ) => {
265
+ return encodingMapping [ key ] === encoding ? key : r ;
266
+ } , undefined ) ;
267
+ }
268
+
256
269
export function decodeData ( data : Buffer , codepage : string ) : string {
257
270
if ( Object . prototype . hasOwnProperty . call ( encodingMapping , codepage ) ) {
258
271
return iconv . decode ( data , encodingMapping [ codepage ] ) ;
You can’t perform that action at this time.
0 commit comments