31
31
32
32
const Uint8 Loopidity::N_SCENES = NUM_SCENES ;
33
33
const Uint8 Loopidity::N_LOOPS = NUM_LOOPS ;
34
- const std::string Loopidity::ASSETS_DIR = GetAssetsPath () ;
34
+ const std::string Loopidity::ASSETS_DIR = GetAssetsDir () ;
35
35
36
36
37
37
/* Loopidity class side private varables */
@@ -162,14 +162,14 @@ DEBUG_TRACE_LOOPIDITY_MAIN_OUT
162
162
163
163
// getters/setters
164
164
165
- std::string Loopidity::GetAssetsPath (std::string filename )
165
+ std::string Loopidity::GetAssetsDir ( )
166
166
{
167
167
// determine proper path to assets on the current system
168
- std::string this_path ;
169
- std::string assets_path ;
168
+ std::string this_bin ;
169
+ std::string this_dir ;
170
170
171
171
#ifdef _WIN32
172
- this_path =" ./" ; // FIXME
172
+ this_dir =" ./" ; // FIXME
173
173
/* TODO:
174
174
std::vector<wchar_t> path_buffer ;
175
175
DWORD n_wchars = 0 ;
@@ -180,20 +180,26 @@ this_path="./" ; // FIXME
180
180
}
181
181
pathBuf.resize(n_wchars) ;
182
182
wstring path(path_buffer.begin() , path_buffer.end()) ;
183
- this_path = std::wstring_convert<std::codecvt_utf8<wchar_t> , wchar_t> converterX.to_bytes(path) ;
183
+ this_dir = std::wstring_convert<std::codecvt_utf8<wchar_t> , wchar_t> converterX.to_bytes(path) ;
184
184
*/
185
185
#else // _WIN32
186
186
#define SCRATCH_BUFFER_SIZE 2048
187
187
char path_buffer[SCRATCH_BUFFER_SIZE] ;
188
188
if (::readlink (" /proc/self/exe" , path_buffer , SCRATCH_BUFFER_SIZE) > 0 )
189
- this_path = std::string (path_buffer) ;
190
- #endif // _WIN32
191
- this_path = this_path.substr (0 , this_path.find_last_of (" /\\ " )) ;
192
- assets_path = this_path + " /../share/loopidity/" + filename ;
189
+ this_bin = std::string (path_buffer) ;
190
+ this_dir = this_bin.substr (0 , this_bin.find_last_of (" /\\ " )) ;
191
+ #endif // _WIN32
193
192
194
- printf (" Loopidity::GetAssetsPath() loading asset=%s\n\n " , assets_path.c_str ());
193
+ std::string assets_dir = this_dir + " /assets" ;
194
+ std::string data_dir = LOOPIDITY_DATADIR ;
195
+ struct stat stats ;
195
196
196
- return assets_path ;
197
+ bool does_assets_dir_exist = stat (assets_dir.c_str () , &stats) == 0 && stats.st_mode & S_IFDIR ;
198
+ bool does_data_dir_exist = stat (data_dir.c_str () , &stats) == 0 && stats.st_mode & S_IFDIR ;
199
+ bool is_uninstalled = does_assets_dir_exist && this_dir.compare (LOOPIDITY_BINDIR) != 0 ;
200
+
201
+ return (does_data_dir_exist) ? data_dir + " /" :
202
+ (is_uninstalled ) ? assets_dir + " /" : " " ;
197
203
}
198
204
199
205
Uint8 Loopidity::GetCurrentSceneN () { return CurrentSceneN ; }
0 commit comments