Skip to content

Commit 0091d5d

Browse files
committed
Fix: Log as Text feature, delete old setting files
1 parent dc14caf commit 0091d5d

3 files changed

Lines changed: 43 additions & 23 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ Use OpenBCIHub v2.0.9 please.
33

44
## Beta 1
55

6+
### Bug fixes
7+
* Fix 'Open Log as Text' feature in ConsoleLog
8+
* Delete old/broken user and default settings when attempting to load
9+
610
### Improvements
711

812
#### SSVEP

OpenBCI_GUI/ConsoleLog.pde

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,25 +131,27 @@ static class ConsoleWindow extends PApplet {
131131

132132
void openLogFileAsText() {
133133
try {
134-
println("Opening console log as text file!");
134+
println("ConsoleLog: Opening console log as text file!");
135135
File file = new File (outputStream.getFilePath());
136136
Desktop desktop = Desktop.getDesktop();
137-
if(file.exists()) {
137+
if (file.exists()) {
138138
desktop.open(file);
139+
} else {
140+
println("ConsoleLog: ERROR - Unable to open console log as text file...");
139141
}
140142
} catch (IOException e) {}
141143
}
142144

143145
void copyFullTextToClipboard() {
144-
println("Copying console log to clipboard!");
146+
println("ConsoleLog: Copying console log to clipboard!");
145147
String stringToCopy = outputStream.getFullLog();
146148
String formattedCodeBlock = "```\n" + stringToCopy + "\n```";
147149
clipboardCopy.copyString(formattedCodeBlock);
148150
}
149151

150152
void copyLastLineToClipboard() {
151153
clipboardCopy.copyString(outputStream.getLastLine());
152-
println("Previous line copied to clipboard.");
154+
println("ConsoleLog: Previous line copied to clipboard.");
153155
}
154156

155157
void updateButtonPositions() {
@@ -167,7 +169,7 @@ static class ConsoleWindow extends PApplet {
167169
}
168170

169171
void exit() {
170-
println("ConsoleWindow: Console closed!");
172+
println("ConsoleLog: Console closed!");
171173
instance = null;
172174
dispose();
173175
}
@@ -215,7 +217,7 @@ static class ConsoleWindow extends PApplet {
215217
data = (String)pasteObject(DataFlavor.stringFlavor);
216218
}
217219
catch (Exception e) {
218-
println("Error getting String from clipboard: " + e);
220+
println("ConsoleLog: Error getting String from clipboard: " + e);
219221
}
220222
return data;
221223
}
@@ -300,7 +302,7 @@ class CustomOutputStream extends PrintStream {
300302
}
301303

302304
public String getFilePath() {
303-
return sketchPath() + System.getProperty("file.separator") + filePath;
305+
return filePath;
304306
}
305307

306308
public String getLastLine() {

OpenBCI_GUI/SoftwareSettings.pde

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -379,12 +379,12 @@ class SoftwareSettings {
379379
this.load(settingsFileToLoad);
380380
errorUserSettingsNotFound = false;
381381
} catch (Exception e) {
382-
e.printStackTrace();
382+
//e.printStackTrace();
383383
println("InitSettings: " + settingsFileToLoad + " not found or other error.");
384384
errorUserSettingsNotFound = true;
385-
File f = new File(sketchPath()+System.getProperty("file.separator")+settingsFileToLoad);
385+
File f = new File(settingsFileToLoad);
386386
if (f.exists()) {
387-
if (f.delete()) println("SoftwareSettings: Removed old settings file.");
387+
if (f.delete()) println("SoftwareSettings: Removed old/broken settings file.");
388388
}
389389
}
390390
}
@@ -1532,7 +1532,7 @@ class SoftwareSettings {
15321532
output("The new data source is " + dataModeVersionToPrint + " and NCHAN = [" + nchan + "]. Data source error: Default Settings Loaded."); //Show a normal message for loading Default Settings
15331533
} else if (errorUserSettingsNotFound) {
15341534
verbosePrint("OpenBCI_GUI: initSystem: -- Init 5 -- " + "Load settings error: File not found. " + millis()); //Print the error to console
1535-
output("The new data source is " + dataModeVersionToPrint + " and NCHAN = [" + nchan + "]. User settings error: Default Settings Loaded."); //Show a normal message for loading Default Settings
1535+
output("The new data source is " + dataModeVersionToPrint + " and NCHAN = [" + nchan + "]. User Settings Error: Default Settings Loaded."); //Show a normal message for loading Default Settings
15361536
} else {
15371537
verbosePrint("OpenBCI_GUI: initSystem: -- Init 5 -- " + "Load settings error: Connection Error: Failed to apply channel settings to Cyton" + millis()); //Print the error to console
15381538
outputError(dataModeVersionToPrint + " and NCHAN = [" + nchan + "]. Connection Error: Channel settings failed to apply to Cyton."); //Show a normal message for loading Default Settings
@@ -1553,14 +1553,27 @@ class SoftwareSettings {
15531553
errorUserSettingsNotFound = true;
15541554
}
15551555
//Output message when Loading settings is complete
1556+
String err = null;
15561557
if (chanNumError == false && dataSourceError == false && errorUserSettingsNotFound == false && loadErrorCytonEvent == false) {
15571558
outputSuccess("Settings Loaded!");
15581559
} else if (chanNumError) {
1559-
outputError("Load Settings Error: Invalid number of channels");
1560+
err = "Invalid number of channels";
15601561
} else if (dataSourceError) {
1561-
outputError("Load Settings Error: Invalid data source");
1562-
} else {
1563-
outputError("Load settings error: " + settingsFileToLoad + " not found. ");
1562+
err = "Invalid data source";
1563+
} else if (errorUserSettingsNotFound) {
1564+
err = settingsFileToLoad + " not found.";
1565+
}
1566+
1567+
if (err != null) {
1568+
println("Load Settings Error: " + err);
1569+
File f = new File(settingsFileToLoad);
1570+
if (f.exists()) {
1571+
if (f.delete()) {
1572+
outputError("Found old/broken GUI settings. Please reconfigure the GUI and save new settings.");
1573+
} else {
1574+
outputError("SoftwareSettings: Error deleting old/broken settings file...");
1575+
}
1576+
}
15641577
}
15651578
}
15661579

@@ -1595,14 +1608,15 @@ class SoftwareSettings {
15951608
this.load(defaultSettingsFileToLoad);
15961609
outputSuccess("Default Settings Loaded!");
15971610
} catch (Exception e) {
1598-
outputError("Default Settings Error: New settings will be made next system start.");
1599-
File f = new File(sketchPath()+System.getProperty("file.separator")+defaultSettingsFileToLoad);
1600-
if (f.delete()) {
1601-
println("Old settings file succesfully deleted.");
1602-
} else {
1603-
println("Error deleting file...");
1611+
outputError("Default Settings Error: Valid Default Settings will be saved next system start.");
1612+
File f = new File(defaultSettingsFileToLoad);
1613+
if (f.exists()) {
1614+
if (f.delete()) {
1615+
println("SoftwareSettings: Old/Broken Default Settings file succesfully deleted.");
1616+
} else {
1617+
println("SoftwareSettings: Error deleting Default Settings file...");
1618+
}
16041619
}
1605-
16061620
}
16071621
}
16081622

@@ -1659,8 +1673,8 @@ void loadConfigFile(File selection) {
16591673
outputError("Settings Error: Data Source Mismatch Detected");
16601674
} else {
16611675
outputError("Error trying to load settings file, possibly from previous GUI. Removing old settings.");
1676+
if (selection.exists()) selection.delete();
16621677
}
1663-
if (selection.exists()) selection.delete();
16641678
}
16651679
settings.loadDialogName = null; //reset this variable for future use
16661680
}

0 commit comments

Comments
 (0)