mirror of
https://github.com/open-goal/jak-project
synced 2026-07-07 22:22:21 -04:00
Update functions
This commit is contained in:
@@ -3,22 +3,31 @@
|
||||
#include <stdio.h> /* defines FILENAME_MAX */
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <direct.h>
|
||||
#define GetCurrentDir _getcwd
|
||||
#include <Windows.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#define GetCurrentDir getcwd
|
||||
#endif
|
||||
|
||||
std::string FileUtil::GetCurrentWorkingDir() {
|
||||
char buff[FILENAME_MAX];
|
||||
GetCurrentDir(buff, FILENAME_MAX);
|
||||
std::string current_working_dir(buff);
|
||||
return current_working_dir;
|
||||
std::string FileUtil::GetExecutablePath() {
|
||||
#ifdef _WIN32
|
||||
char buffer[FILENAME_MAX];
|
||||
GetModuleFileNameA(NULL, buffer, FILENAME_MAX);
|
||||
std::string::size_type pos =
|
||||
std::string(buffer).find_last_of("/\\"); // Strip executable from file path
|
||||
return std::string(buffer).substr(0, pos);
|
||||
#else // do Linux stuff
|
||||
char buffer[FILENAME_MAX];
|
||||
readlink("/proc/self/exe", buffer,
|
||||
FILENAME_MAX); // /proc/self acts like a "virtual folder" containing information about
|
||||
// the current process
|
||||
std::string::size_type pos =
|
||||
std::string(buffer).find_last_of("/\\"); // Strip executable from file path
|
||||
return std::string(buffer).substr(0, pos);
|
||||
#endif
|
||||
}
|
||||
|
||||
std::string FileUtil::get_file_path(const std::vector<std::string>& input) {
|
||||
std::string currentPath = FileUtil::GetCurrentWorkingDir(); // std::filesystem::current_path();
|
||||
std::string currentPath = FileUtil::GetExecutablePath();
|
||||
char dirSeparator;
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
#include <vector>
|
||||
|
||||
namespace FileUtil {
|
||||
std::string GetCurrentWorkingDir();
|
||||
std::string get_file_path(std::vector<std::string> input);
|
||||
std::string GetExecutablePath();
|
||||
std::string get_file_path(const std::vector<std::string>& input);
|
||||
} // namespace FileUtil
|
||||
|
||||
Reference in New Issue
Block a user