From 90075755b13729835731a547e5faec9e8b7671ad Mon Sep 17 00:00:00 2001 From: superp00t Date: Sat, 19 Aug 2023 05:16:48 -0400 Subject: [PATCH] feat(os): implement OsSetCurrentDirectory and OsGetCurrentDirectory --- bc/file/File.cpp | 12 ++++++++++++ bc/file/File.hpp | 2 ++ bc/os/File.cpp | 12 ++++++++++++ bc/os/File.hpp | 4 ++++ 4 files changed, 30 insertions(+) diff --git a/bc/file/File.cpp b/bc/file/File.cpp index 2bbc793..72709be 100644 --- a/bc/file/File.cpp +++ b/bc/file/File.cpp @@ -150,6 +150,18 @@ bool GetWorkingDirectory(char* path, size_t capacity) { return manager->Do(Filesystem::Call::GetWorkingDirectory, &parms); } +bool SetWorkingDirectory(const char* path) { + auto manager = System_File::Stacked::Manager(); + if (!manager) { + return false; + } + + System_File::Stacked::FileParms parms = {}; + parms.filename = path; + + return manager->Do(Filesystem::Call::SetWorkingDirectory, &parms); +} + // Get file information from a stream record, returning a file info pointer owned by StreamRecord // The FileInfo ptr returned is invalidated after a call to File::Close(stream) FileInfo* GetFileInfo(StreamRecord* stream) { diff --git a/bc/file/File.hpp b/bc/file/File.hpp index becffbc..ea22d6a 100644 --- a/bc/file/File.hpp +++ b/bc/file/File.hpp @@ -34,6 +34,8 @@ FileInfo* GetFileInfo(StreamRecord* stream); bool GetWorkingDirectory(char* path, size_t capacity); +bool SetWorkingDirectory(const char* path); + bool MakeAbsolutePath(const char* rel, char* result, int32_t capacity, bool unkflag); bool Open(const char* filename, uint32_t flags, StreamRecord*& stream); diff --git a/bc/os/File.cpp b/bc/os/File.cpp index cf558a9..341929b 100644 --- a/bc/os/File.cpp +++ b/bc/os/File.cpp @@ -146,3 +146,15 @@ int64_t OsSetFilePointer(HOSFILE fileHandle, int64_t distanceToMove, uint32_t mo void OsCloseFile(HOSFILE fileHandle) { Blizzard::File::Close(static_cast(fileHandle)); } + +int32_t OsSetCurrentDirectory(const char* pathName) { + BLIZZARD_ASSERT(pathName); + + return Blizzard::File::SetWorkingDirectory(pathName); +} + +int32_t OsGetCurrentDirectory(size_t pathLen, char* pathName) { + BLIZZARD_ASSERT(pathName); + + return Blizzard::File::GetWorkingDirectory(pathName, pathLen); +} diff --git a/bc/os/File.hpp b/bc/os/File.hpp index c5e359e..48fd8b3 100644 --- a/bc/os/File.hpp +++ b/bc/os/File.hpp @@ -64,4 +64,8 @@ void OsCloseFile(HOSFILE fileHandle); int64_t OsSetFilePointer(HOSFILE fileHandle, int64_t distanceToMove, uint32_t moveMethod); +int32_t OsSetCurrentDirectory(const char* pathName); + +int32_t OsGetCurrentDirectory(size_t pathLen, char* pathName); + #endif