OpenRaider  0.1.4-dev
Open Source Tomb Raider Game Engine implementation
filesystem.cpp
Go to the documentation of this file.
1 
8 #include "global.h"
9 #include "utils/filesystem.h"
10 
11 #if defined(HAVE_UNISTD_H) && defined(HAVE_GETCWD)
12 #include <unistd.h>
13 #endif
14 
15 #if defined(HAVE_STDLIB_H) && defined(HAVE_GETENV)
16 #include <stdlib.h>
17 #endif
18 
19 #ifdef _WIN32
20 #include <windows.h>
21 #include <shlobj.h>
22 #endif
23 
25 #if defined(HAVE_UNISTD_H) && defined(HAVE_GETCWD)
26 
27  char path[1024];
28  assertEqual(getcwd(path, 1024), path);
29  return std::string(path);
30 
31 #else
32 
33  assert(false);
34  return "";
35 
36 #endif
37 }
38 
39 std::string getHomeDirectory() {
40 #if defined(HAVE_STDLIB_H) && defined(HAVE_GETENV)
41 
42  char* path = getenv("HOME");
43  assert(path != nullptr);
44  return path;
45 
46 #elif defined(_WIN32)
47 
48  char path[MAX_PATH];
49  assertEqual(SHGetFolderPath(nullptr, CSIDL_PROFILE, nullptr, 0, path), S_OK);
50  size_t lenPath = strlen(path);
51  for (unsigned int i = 0; i < lenPath; i++)
52  if (path[i] == '\\')
53  path[i] = '/';
54  return std::string(path);
55 
56 #else
57 
58  assert(false);
59  return "";
60 
61 #endif
62 }
63 
std::string getCurrentWorkingDirectory()
Definition: filesystem.cpp:24
Included everywhere.
#define assert(x)
Definition: global.h:124
std::string getHomeDirectory()
Definition: filesystem.cpp:39
file-system utilities
#define assertEqual(x, y)
Definition: global.h:130