Skip to content

Commit ca29434

Browse files
committed
determine absolute filesystem path for assets
* renamed Loopidity::GetAssetsPath() to Loopidity::GetAssetsDir()
1 parent 02949bb commit ca29434

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

src/loopidity.cpp

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
const Uint8 Loopidity::N_SCENES = NUM_SCENES ;
3333
const Uint8 Loopidity::N_LOOPS = NUM_LOOPS ;
34-
const std::string Loopidity::ASSETS_DIR = GetAssetsPath() ;
34+
const std::string Loopidity::ASSETS_DIR = GetAssetsDir() ;
3535

3636

3737
/* Loopidity class side private varables */
@@ -162,14 +162,14 @@ DEBUG_TRACE_LOOPIDITY_MAIN_OUT
162162

163163
// getters/setters
164164

165-
std::string Loopidity::GetAssetsPath(std::string filename)
165+
std::string Loopidity::GetAssetsDir()
166166
{
167167
// 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 ;
170170

171171
#ifdef _WIN32
172-
this_path="./" ; // FIXME
172+
this_dir="./" ; // FIXME
173173
/* TODO:
174174
std::vector<wchar_t> path_buffer ;
175175
DWORD n_wchars = 0 ;
@@ -180,20 +180,26 @@ this_path="./" ; // FIXME
180180
}
181181
pathBuf.resize(n_wchars) ;
182182
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) ;
184184
*/
185185
#else // _WIN32
186186
#define SCRATCH_BUFFER_SIZE 2048
187187
char path_buffer[SCRATCH_BUFFER_SIZE] ;
188188
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
193192

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 ;
195196

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 + "/" : "" ;
197203
}
198204

199205
Uint8 Loopidity::GetCurrentSceneN() { return CurrentSceneN ; }

src/loopidity.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,9 @@ class Loopidity
9999
static int Main(int argc , char** argv) ;
100100

101101
// getters/setters
102-
static std::string GetAssetsPath(std::string filename) ;
103102
// static void SetNFramesPerPeriod( Uint32 nFrames) ;
104-
static Uint8 GetCurrentSceneN(void) ;
105-
static Uint8 GetNextSceneN( void) ;
103+
static Uint8 GetCurrentSceneN(void) ;
104+
static Uint8 GetNextSceneN( void) ;
106105
// static Uint32 GetLoopPos( void) ;
107106
static bool GetIsRolling( void) ;
108107
// static bool GetShouldSaveLoop( void) ;
@@ -119,6 +118,7 @@ class Loopidity
119118
/* Loopidity class side private functions */
120119

121120
// setup
121+
static std::string GetAssetsDir() ;
122122
#if ! INIT_JACK_BEFORE_SCENES
123123
static bool IsInitialized() ;
124124
#endif // INIT_JACK_BEFORE_SCENES

0 commit comments

Comments
 (0)