Skip to content
This repository has been archived by the owner on Oct 1, 2024. It is now read-only.

fix example issue for protable mode #509

Merged
merged 1 commit into from
Mar 29, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 39 additions & 4 deletions src/arduino/arduinoSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,17 @@ export class ArduinoSettings implements IArduinoSettings {
} else {
this._packagePath = path.join(process.env.HOME, ".arduino15");
}
this._sketchbookPath = this.preferences.get("sketchbook.path") || path.join(process.env.HOME, "Arduino");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

combine them to a function ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The second part, here is path.join(process.env.HOME, "Arduino"), is related with platform, so I do not think we can get any benefit from combining them to a function


if (this.preferences.get("sketchbook.path")) {
if (util.directoryExistsSync(path.join(this._arduinoPath, "portable"))) {
this._sketchbookPath = path.join(this._arduinoPath, "portable", this.preferences.get("sketchbook.path"));
} else {
this._sketchbookPath = this.preferences.get("sketchbook.path");
}
} else {
this._sketchbookPath = path.join(process.env.HOME, "Arduino");
}

if (this._commandPath === "") {
this._commandPath = "arduino";
}
Expand All @@ -63,7 +73,17 @@ export class ArduinoSettings implements IArduinoSettings {
} else {
this._packagePath = path.join(process.env.HOME, "Library/Arduino15");
}
this._sketchbookPath = this.preferences.get("sketchbook.path") || path.join(process.env.HOME, "Documents/Arduino");

if (this.preferences.get("sketchbook.path")) {
if (util.directoryExistsSync(path.join(this._arduinoPath, "portable"))) {
this._sketchbookPath = path.join(this._arduinoPath, "portable", this.preferences.get("sketchbook.path"));
} else {
this._sketchbookPath = this.preferences.get("sketchbook.path");
}
} else {
this._sketchbookPath = path.join(process.env.HOME, "Documents/Arduino");
}

if (this._commandPath === "") {
this._commandPath = "/Contents/MacOS/Arduino";
}
Expand Down Expand Up @@ -128,7 +148,13 @@ export class ArduinoSettings implements IArduinoSettings {

public reloadPreferences() {
this._preferences = util.parseConfigFile(this.preferencePath);
this._sketchbookPath = this._preferences.get("sketchbook.path") || this._sketchbookPath;
if (this.preferences.get("sketchbook.path")) {
if (util.directoryExistsSync(path.join(this._arduinoPath, "portable"))) {
this._sketchbookPath = path.join(this._arduinoPath, "portable", this.preferences.get("sketchbook.path"));
} else {
this._sketchbookPath = this.preferences.get("sketchbook.path");
}
}
}

/**
Expand Down Expand Up @@ -159,7 +185,16 @@ export class ArduinoSettings implements IArduinoSettings {
} else {
this._packagePath = path.join(process.env.LOCALAPPDATA, "Arduino15");
}
this._sketchbookPath = this.preferences.get("sketchbook.path") || path.join(folder, "Arduino");

if (this.preferences.get("sketchbook.path")) {
if (util.directoryExistsSync(path.join(this._arduinoPath, "portable"))) {
this._sketchbookPath = path.join(this._arduinoPath, "portable", this.preferences.get("sketchbook.path"));
} else {
this._sketchbookPath = this.preferences.get("sketchbook.path");
}
} else {
this._sketchbookPath = path.join(folder, "Arduino");
}
}

private async tryResolveArduinoPath(): Promise<void> {
Expand Down