@@ -12,12 +12,13 @@ import * as vscode from "vscode";
12
12
import * as constants from "../common/constants" ;
13
13
import * as util from "../common/util" ;
14
14
import * as Logger from "../logger/logger" ;
15
- import * as settings from "./settings" ;
16
15
17
16
import { DeviceContext , IDeviceContext } from "../deviceContext" ;
17
+ import { IArduinoSettings } from "./arduinoSettings" ;
18
18
import { BoardManager } from "./boardManager" ;
19
19
import { ExampleManager } from "./exampleManager" ;
20
20
import { LibraryManager } from "./libraryManager" ;
21
+ import { VscodeSettings } from "./vscodeSettings" ;
21
22
22
23
import { arduinoChannel } from "../common/outputChannel" ;
23
24
import { SerialMonitor } from "../serialmonitor/serialMonitor" ;
@@ -27,8 +28,6 @@ import { SerialMonitor } from "../serialmonitor/serialMonitor";
27
28
*/
28
29
export class ArduinoApp {
29
30
30
- private _preferences : Map < string , string > ;
31
-
32
31
private _boardManager : BoardManager ;
33
32
34
33
private _libraryManager : LibraryManager ;
@@ -38,18 +37,19 @@ export class ArduinoApp {
38
37
/**
39
38
* @param {IArduinoSettings } ArduinoSetting object.
40
39
*/
41
- constructor ( private _settings : settings . IArduinoSettings ) {
40
+ constructor ( private _settings : IArduinoSettings ) {
42
41
}
43
42
44
43
/**
45
44
* Need refresh Arduino IDE's setting when starting up.
46
45
* @param {boolean } force - Whether force initialzie the arduino
47
46
*/
48
47
public async initialize ( force : boolean = false ) {
49
- if ( ! util . fileExistsSync ( path . join ( this . _settings . packagePath , "preferences.txt" ) ) ) {
48
+ if ( ! util . fileExistsSync ( this . _settings . preferencePath ) ) {
50
49
try {
51
50
// Use empty pref value to initialize preference.txt file
52
51
await this . setPref ( "boardsmanager.additional.urls" , "" ) ;
52
+ this . _settings . loadPreferences ( ) ; // reload preferences.
53
53
} catch ( ex ) {
54
54
}
55
55
}
@@ -114,7 +114,7 @@ export class ArduinoApp {
114
114
115
115
const appPath = path . join ( vscode . workspace . rootPath , dc . sketch ) ;
116
116
const args = [ "--upload" , "--board" , boardDescriptor , "--port" , dc . port , appPath ] ;
117
- if ( this . _settings . logLevel === "verbose" ) {
117
+ if ( VscodeSettings . getIntance ( ) . logLevel === "verbose" ) {
118
118
args . push ( "--verbose" ) ;
119
119
}
120
120
await util . spawn ( this . _settings . commandPath , arduinoChannel . channel , args ) . then ( async ( result ) => {
@@ -143,7 +143,7 @@ export class ArduinoApp {
143
143
arduinoChannel . start ( `Verify sketch - ${ dc . sketch } ` ) ;
144
144
const appPath = path . join ( vscode . workspace . rootPath , dc . sketch ) ;
145
145
const args = [ "--verify" , "--board" , boardDescriptor , appPath ] ;
146
- if ( this . _settings . logLevel === "verbose" ) {
146
+ if ( VscodeSettings . getIntance ( ) . logLevel === "verbose" ) {
147
147
args . push ( "--verbose" ) ;
148
148
}
149
149
arduinoChannel . show ( ) ;
@@ -350,7 +350,7 @@ export class ArduinoApp {
350
350
}
351
351
352
352
// Step 1: Copy the example project to a temporary directory.
353
- const sketchPath = this . preferences . get ( "sketchbook. path" ) || path . dirname ( this . _settings . libPath ) ;
353
+ const sketchPath = path . join ( this . _settings . sketchbookPath , "generated_examples" ) ;
354
354
if ( ! util . directoryExistsSync ( sketchPath ) ) {
355
355
util . mkdirRecursivelySync ( sketchPath ) ;
356
356
}
@@ -404,13 +404,6 @@ export class ArduinoApp {
404
404
return destExample ;
405
405
}
406
406
407
- public get preferences ( ) {
408
- if ( ! this . _preferences ) {
409
- this . loadPreferences ( ) ;
410
- }
411
- return this . _preferences ;
412
- }
413
-
414
407
public get settings ( ) {
415
408
return this . _settings ;
416
409
}
@@ -439,22 +432,6 @@ export class ArduinoApp {
439
432
this . _exampleManager = value ;
440
433
}
441
434
442
- private loadPreferences ( ) {
443
- this . _preferences = new Map < string , string > ( ) ;
444
- const lineRegex = / ( \S + ) = ( \S + ) / ;
445
-
446
- const rawText = fs . readFileSync ( path . join ( this . _settings . packagePath , "preferences.txt" ) , "utf8" ) ;
447
- const lines = rawText . split ( "\n" ) ;
448
- lines . forEach ( ( line ) => {
449
- if ( line ) {
450
- const match = lineRegex . exec ( line ) ;
451
- if ( match && match . length > 2 ) {
452
- this . _preferences . set ( match [ 1 ] , match [ 2 ] ) ;
453
- }
454
- }
455
- } ) ;
456
- }
457
-
458
435
private getBoardBuildString ( deviceContext : IDeviceContext ) : string {
459
436
const selectedBoard = this . boardManager . currentBoard ;
460
437
if ( ! selectedBoard ) {
0 commit comments