Skip to content

Commit 642a606

Browse files
committed
On OS X, store lastConfig.xml and windowState.xml in ~/Library/Application Support/open-ephys
1 parent 839226a commit 642a606

1 file changed

Lines changed: 16 additions & 14 deletions

File tree

Source/MainWindow.cpp

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@
2525
#include <stdio.h>
2626
//-----------------------------------------------------------------------
2727

28+
static inline File getSavedStateDirectory() {
29+
#if defined(__APPLE__)
30+
File dir = File::getSpecialLocation(File::userApplicationDataDirectory).getChildFile("Application Support/open-ephys");
31+
if (!dir.isDirectory()) {
32+
dir.createDirectory();
33+
}
34+
return std::move(dir);
35+
#else
36+
return File::getSpecialLocation(File::currentExecutableFile).getParentDirectory();
37+
#endif
38+
}
39+
2840
MainWindow::MainWindow()
2941
: DocumentWindow(JUCEApplication::getInstance()->getApplicationName(),
3042
Colour(Colours::black),
@@ -71,10 +83,7 @@
7183

7284
if (shouldReloadOnStartup)
7385
{
74-
File executable = File::getSpecialLocation(File::currentExecutableFile);
75-
File executableDirectory = executable.getParentDirectory();
76-
File file = executableDirectory.getChildFile("lastConfig.xml");
77-
86+
File file = getSavedStateDirectory().getChildFile("lastConfig.xml");
7887
ui->getEditorViewport()->loadState(file);
7988
}
8089

@@ -97,10 +106,7 @@ MainWindow::~MainWindow()
97106
UIComponent* ui = (UIComponent*) getContentComponent();
98107
ui->disableDataViewport();
99108

100-
File executable = File::getSpecialLocation(File::currentExecutableFile);
101-
File executableDirectory = executable.getParentDirectory();
102-
File file = executableDirectory.getChildFile("lastConfig.xml");
103-
109+
File file = getSavedStateDirectory().getChildFile("lastConfig.xml");
104110
ui->getEditorViewport()->saveState(file);
105111

106112
setMenuBar(0);
@@ -130,9 +136,7 @@ void MainWindow::saveWindowBounds()
130136
std::cout << "Saving window bounds." << std::endl;
131137
std::cout << std::endl;
132138

133-
File executable = File::getSpecialLocation(File::currentExecutableFile);
134-
File executableDirectory = executable.getParentDirectory();
135-
File file = executableDirectory.getChildFile("windowState.xml");
139+
File file = getSavedStateDirectory().getChildFile("windowState.xml");
136140

137141
XmlElement* xml = new XmlElement("MAINWINDOW");
138142

@@ -180,9 +184,7 @@ void MainWindow::loadWindowBounds()
180184

181185
//File file = File::getCurrentWorkingDirectory().getChildFile("windowState.xml");
182186

183-
File executable = File::getSpecialLocation(File::currentExecutableFile);
184-
File executableDirectory = executable.getParentDirectory();
185-
File file = executableDirectory.getChildFile("windowState.xml");
187+
File file = getSavedStateDirectory().getChildFile("windowState.xml");
186188

187189
XmlDocument doc(file);
188190
XmlElement* xml = doc.getDocumentElement();

0 commit comments

Comments
 (0)