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),
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
@@ -178,11 +182,7 @@ void MainWindow::loadWindowBounds()
178182 std::cout << " Loading window bounds." << std::endl;
179183 std::cout << std::endl;
180184
181- // File file = File::getCurrentWorkingDirectory().getChildFile("windowState.xml");
182-
183- File executable = File::getSpecialLocation (File::currentExecutableFile);
184- File executableDirectory = executable.getParentDirectory ();
185- File file = executableDirectory.getChildFile (" windowState.xml" );
185+ File file = getSavedStateDirectory ().getChildFile (" windowState.xml" );
186186
187187 XmlDocument doc (file);
188188 XmlElement* xml = doc.getDocumentElement ();
0 commit comments