Jamie Reece Wilson
83f34b0c47
03:28:55:638 17>2 of 53388 functions (<0.1%) were compiled, the rest were copied from previous compilation. 03:28:55:638 17> 0 functions were new in current compilation 03:28:55:638 17> 65 functions had inline decision re-evaluated but remain unchanged 03:28:56:749 17>Finished generating code the header of const AuString & is the same as std::string_view therefore nothing changes. in fact, we still need to alloc strings a bunch of times for a zero terminated string. worse, <c++20 always allocs each time we want to access a hashmap with o(1) lookup, making small hashmaps kinda pointless when we always have to alloc+copy (thx std) perhaps this will help some language binders
122 lines
3.0 KiB
C++
122 lines
3.0 KiB
C++
/***
|
|
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
File: FS.hpp
|
|
Date: 2021-6-16
|
|
Author: Reece
|
|
***/
|
|
#pragma once
|
|
|
|
#if !defined(NO_FSTREAM) && (!defined(__has_include) || __has_include(<fstream>))
|
|
#include <fstream>
|
|
#if !defined(HAS_FSTREAM)
|
|
#define HAS_FSTREAM
|
|
#endif
|
|
#endif
|
|
|
|
#if !defined(NO_STD_FS) && (!defined(__has_include) || __has_include(<filesystem>))
|
|
#include <filesystem>
|
|
#define HAS_STD_FS
|
|
|
|
#if !defined(_HAS_CXX17) && defined(AURORA_COMPILER_MSVC)
|
|
// map experimental::filesystem to filesystem::
|
|
// as in newer compilers it is not experimental anymore
|
|
namespace std
|
|
{
|
|
namespace filesystem = experimental::filesystem;
|
|
}
|
|
#endif
|
|
|
|
#endif
|
|
|
|
namespace Aurora::IO::FS
|
|
{
|
|
#if defined(VENDOR_GENERIC_MICROSOFT) || defined(VENDOR_CONSOLE_MICROSOFT)
|
|
static const unsigned char kPathSplitter = '\\';
|
|
static const AuString kDoublePathSplitter = "\\\\";
|
|
#else
|
|
static const unsigned char kPathSplitter = '/';
|
|
static const AuString kDoublePathSplitter = "//";
|
|
#endif
|
|
|
|
void _NormalizePath(AuString &str);
|
|
|
|
static void NormalizePath(AuString &str)
|
|
{
|
|
try
|
|
{
|
|
_NormalizePath(str);
|
|
}
|
|
catch (...)
|
|
{
|
|
AuResetMember(str);
|
|
}
|
|
}
|
|
|
|
static auline AuString NormalizePathRet(AuROString str)
|
|
{
|
|
try
|
|
{
|
|
AuString ret = AuString(str);
|
|
_NormalizePath(ret);
|
|
return ret;
|
|
}
|
|
catch (...)
|
|
{
|
|
return {};
|
|
}
|
|
}
|
|
|
|
bool _MkDir(const AuROString &str);
|
|
|
|
static bool CreateDirectories(const AuROString &cpath, bool isFile)
|
|
{
|
|
try
|
|
{
|
|
// This gives us a significant performance boost
|
|
AuROString path;
|
|
if (isFile && GetDirectoryFromPath(path, cpath))
|
|
{
|
|
if (DirExists(path))
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
|
|
for (int i = 0; i < cpath.size(); i++)
|
|
{
|
|
bool end = i == cpath.size() - 1;
|
|
if ((cpath[i] == kPathSplitter) ||
|
|
((!isFile) && (end)))
|
|
{
|
|
auto subpath = end ? AuString(cpath) : AuString(cpath.begin(), cpath.begin() + i);
|
|
if (subpath.empty())
|
|
{
|
|
continue;
|
|
}
|
|
|
|
if (DirExists(subpath))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
if (!_MkDir(subpath))
|
|
{
|
|
if (!DirExists(subpath)) // copium. im worried :(
|
|
{
|
|
return false; // ...aw shit
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
catch (...)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
void InitResources();
|
|
} |