Skip to content

Commit

Permalink
IO: use core::Path for sysAbsolutePath and sysFindBinary
Browse files Browse the repository at this point in the history
  • Loading branch information
mgerhardy committed Sep 26, 2024
1 parent d3108a4 commit fcb7d7f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
23 changes: 14 additions & 9 deletions src/modules/io/Filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ bool Filesystem::init(const core::String &organisation, const core::String &appn
return true;
}

core::String Filesystem::sysFindBinary(const core::String &binaryName) const {
core::Path Filesystem::sysFindBinary(const core::String &binaryName) const {
#ifdef _WIN32
core::String binaryWithExtension = binaryName;
binaryWithExtension += ".exe";
Expand All @@ -109,13 +109,13 @@ core::String Filesystem::sysFindBinary(const core::String &binaryName) const {
#endif
// Check current working directory
if (fs_exists(binaryPath)) {
return sysAbsolutePath(binaryPath.str());
return sysAbsolutePath(binaryPath);
}

// Check the directory of the current binary
core::Path fullBinaryPath = _basePath.append(binaryName);
if (fs_exists(fullBinaryPath)) {
return sysAbsolutePath(fullBinaryPath.str());
return sysAbsolutePath(fullBinaryPath);
}

// Check PATH environment variable
Expand All @@ -132,11 +132,11 @@ core::String Filesystem::sysFindBinary(const core::String &binaryName) const {
core::Path binPath(p);
binPath.append(binaryPath);
if (fs_exists(binPath)) {
return binPath.str();
return binPath;
}
}
}
return "";
return core::Path();
}

const core::DynamicArray<ThisPCEntry> Filesystem::sysOtherPaths() const {
Expand Down Expand Up @@ -280,20 +280,25 @@ void Filesystem::shutdown() {
#endif
}

core::String Filesystem::sysAbsolutePath(const core::String &path) const {
core::Path Filesystem::sysAbsolutePath(const core::Path& path) const {
core::Path abspath = fs_realpath(core::Path(path));
if (abspath.empty()) {
for (const core::Path &p : registeredPaths()) {
const core::Path &fullPath = p.append(path);
abspath = fs_realpath(fullPath);
if (!abspath.empty()) {
return abspath.str();
return abspath;
}
}
Log::error("Failed to get absolute path for '%s'", path.c_str());
return "";
return core::Path();
}
return abspath.str();
return abspath;
}

core::String Filesystem::sysAbsolutePath(const core::String &path) const {
core::Path p = sysAbsolutePath(core::Path(path));
return p.str();
}

bool Filesystem::sysIsHidden(const core::Path &name) {
Expand Down
3 changes: 2 additions & 1 deletion src/modules/io/Filesystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class Filesystem {
core::String sysSpecialDir(FilesystemDirectories dir) const;
const core::DynamicArray<ThisPCEntry> sysOtherPaths() const;

core::String sysFindBinary(const core::String &binaryName) const;
core::Path sysFindBinary(const core::String &binaryName) const;

/**
* @brief The current working directory without a tailing /
Expand All @@ -150,6 +150,7 @@ class Filesystem {
static bool sysIsReadableDir(const core::String& name);
static bool sysIsHidden(const core::Path &name);
core::String sysAbsolutePath(const core::String& path) const;
core::Path sysAbsolutePath(const core::Path& path) const;

/**
* @brief Changes the current working directory
Expand Down
2 changes: 1 addition & 1 deletion src/tools/voxconvert/VoxConvertUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ void VoxConvertUI::onRenderUI() {
if (_overwriteTargetFile) {
arguments.push_back("-f");
}
const int exitCode = core::Process::exec(_voxconvertBinary, arguments, nullptr, &stream);
const int exitCode = core::Process::exec(_voxconvertBinary.str(), arguments, nullptr, &stream);
stream.seek(0);
stream.readString(stream.size(), _output);
_output = core::string::removeAnsiColors(_output.c_str());
Expand Down
2 changes: 1 addition & 1 deletion src/tools/voxconvert/VoxConvertUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class VoxConvertUI : public ui::IMGUIApp {
using Super = ui::IMGUIApp;
core::String _output;
core::String _source;
core::String _voxconvertBinary = "vengi-voxconvert";
core::Path _voxconvertBinary {"vengi-voxconvert"};
core::String _targetFile;
bool _targetFileExists = false;
bool _overwriteTargetFile = false;
Expand Down

0 comments on commit fcb7d7f

Please sign in to comment.