From bf05309af734431c3b3cf869a63ed477439a6739 Mon Sep 17 00:00:00 2001 From: Hein-Pieter van Braam Date: Fri, 8 Dec 2017 15:05:47 +0100 Subject: Import thekla_atlas As requested by reduz, an import of thekla_atlas into thirdparty/ --- thirdparty/thekla_atlas/nvcore/FileSystem.cpp | 75 +++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 thirdparty/thekla_atlas/nvcore/FileSystem.cpp (limited to 'thirdparty/thekla_atlas/nvcore/FileSystem.cpp') diff --git a/thirdparty/thekla_atlas/nvcore/FileSystem.cpp b/thirdparty/thekla_atlas/nvcore/FileSystem.cpp new file mode 100644 index 0000000000..5ed0ca074f --- /dev/null +++ b/thirdparty/thekla_atlas/nvcore/FileSystem.cpp @@ -0,0 +1,75 @@ +// This code is in the public domain -- castano@gmail.com + +#include "FileSystem.h" + +#if NV_OS_WIN32 +#define _CRT_NONSTDC_NO_WARNINGS // _chdir is defined deprecated, but that's a bug, chdir is deprecated, _chdir is *not*. +//#include // PathFileExists +#include // GetFileAttributes +#include // _mkdir +#elif NV_OS_XBOX +#include +#elif NV_OS_DURANGO +#include +#else +#include +#include +#include +#endif +#include // remove, unlink + +using namespace nv; + + +bool FileSystem::exists(const char * path) +{ +#if NV_OS_UNIX + return access(path, F_OK|R_OK) == 0; + //struct stat buf; + //return stat(path, &buf) == 0; +#elif NV_OS_WIN32 || NV_OS_XBOX || NV_OS_DURANGO + // PathFileExists requires linking to shlwapi.lib + //return PathFileExists(path) != 0; + return GetFileAttributesA(path) != INVALID_FILE_ATTRIBUTES; +#else + if (FILE * fp = fopen(path, "r")) + { + fclose(fp); + return true; + } + return false; +#endif +} + +bool FileSystem::createDirectory(const char * path) +{ +#if NV_OS_WIN32 || NV_OS_XBOX || NV_OS_DURANGO + return CreateDirectoryA(path, NULL) != 0; +#elif NV_OS_ORBIS + // not implemented + return false; +#else + return mkdir(path, 0777) != -1; +#endif +} + +bool FileSystem::changeDirectory(const char * path) +{ +#if NV_OS_WIN32 + return _chdir(path) != -1; +#elif NV_OS_XBOX || NV_OS_DURANGO + // Xbox doesn't support Current Working Directory! + return false; +#elif NV_OS_ORBIS + // Orbis doesn't support Current Working Directory! + return false; +#else + return chdir(path) != -1; +#endif +} + +bool FileSystem::removeFile(const char * path) +{ + // @@ Use unlink or remove? + return remove(path) == 0; +} -- cgit v1.2.3