diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2020-11-19 04:14:48 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-11-19 01:14:48 -0800 |
| commit | b59451020eee59cd52e4d8231360ebed4fc59adb (patch) | |
| tree | a5a77794097ee99bbef91b8f28be8788284e7736 /source/core/slang-io.cpp | |
| parent | ac41b9956681d54f4487ff06922017f2753d0c45 (diff) | |
File system refactor (#1611)
* #include an absolute path didn't work - because paths were taken to always be relative.
* WIP FileSystem refactor.
* Made loadFile load the file in binary mode.
* Fixed some comments.
Fixed typo in RelativePath - not used 'fixedPath'.
Diffstat (limited to 'source/core/slang-io.cpp')
| -rw-r--r-- | source/core/slang-io.cpp | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/source/core/slang-io.cpp b/source/core/slang-io.cpp index 5cbe021a2..8e7266dc5 100644 --- a/source/core/slang-io.cpp +++ b/source/core/slang-io.cpp @@ -557,6 +557,49 @@ namespace Slang #endif } + SlangResult Path::remove(const String& path) + { +#ifdef _WIN32 + // Need to determine if its a file or directory + + SlangPathType pathType; + SLANG_RETURN_ON_FAIL(getPathType(path, &pathType)); + + + switch (pathType) + { + case SLANG_PATH_TYPE_FILE: + { + // https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-deletefilea + if (DeleteFileA(path.getBuffer())) + { + return SLANG_OK; + } + break; + } + case SLANG_PATH_TYPE_DIRECTORY: + { + // https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-removedirectorya + if (RemoveDirectoryA(path.getBuffer())) + { + return SLANG_OK; + } + break; + } + default: break; + } + + return SLANG_FAIL; +#else + // https://linux.die.net/man/3/remove + if (::remove(path.getBuffer()) == 0) + { + return SLANG_OK; + } + return SLANG_FAIL; +#endif + } + #if defined(_WIN32) /* static */SlangResult Path::find(const String& directoryPath, const char* pattern, Visitor* visitor) { |
