Compare commits
No commits in common. "6cc31f660c923ac3928f8bd91a63a0c1a523b632" and "38e1c3f8b760d3e22cc2e8f8fdfb5a8816308740" have entirely different histories.
6cc31f660c
...
38e1c3f8b7
@ -1,22 +1,11 @@
|
|||||||
#include <Miscellaneous/FileSystem.h>
|
#include <Miscellaneous/FileSystem.h>
|
||||||
|
|
||||||
#include "Numerics/Bit.h"
|
#include "Numerics/Bit.h"
|
||||||
#include "Numerics/Math.h"
|
|
||||||
#include "Templates/ScopeHelper.h"
|
#include "Templates/ScopeHelper.h"
|
||||||
#include "Containers/StaticArray.h"
|
#include "Containers/StaticArray.h"
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
|
||||||
#if PLATFORM_WINDOWS
|
|
||||||
# undef TEXT
|
|
||||||
# include <windows.h>
|
|
||||||
# undef CreateDirectory
|
|
||||||
#elif PLATFORM_LINUX
|
|
||||||
# include <unistd.h>
|
|
||||||
# include <dirent.h>
|
|
||||||
# include <sys/stat.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#pragma warning(push)
|
#pragma warning(push)
|
||||||
#pragma warning(disable: 4996)
|
#pragma warning(disable: 4996)
|
||||||
|
|
||||||
@ -28,8 +17,6 @@ NAMESPACE_BEGIN(FileSystem)
|
|||||||
|
|
||||||
bool LoadFileToArray(TArray<uint8>& Result, FStringView Path)
|
bool LoadFileToArray(TArray<uint8>& Result, FStringView Path)
|
||||||
{
|
{
|
||||||
if (!FileSystem::Exists(Path)) return false;
|
|
||||||
|
|
||||||
FILE* File = std::fopen(*Path, "rb");
|
FILE* File = std::fopen(*Path, "rb");
|
||||||
|
|
||||||
if (File == nullptr) return false;
|
if (File == nullptr) return false;
|
||||||
@ -40,7 +27,7 @@ bool LoadFileToArray(TArray<uint8>& Result, FStringView Path)
|
|||||||
|
|
||||||
const long Length = std::ftell(File);
|
const long Length = std::ftell(File);
|
||||||
|
|
||||||
if (!Math::IsWithin(Length, 0, TNumericLimits<long>::Max())) return false;
|
if (Length == -1) return false;
|
||||||
|
|
||||||
if (std::fseek(File, 0, SEEK_SET) != 0) return false;
|
if (std::fseek(File, 0, SEEK_SET) != 0) return false;
|
||||||
|
|
||||||
@ -75,8 +62,6 @@ bool SaveArrayToFile(TArrayView<const uint8> Data, FStringView Path)
|
|||||||
template <CCharType T>
|
template <CCharType T>
|
||||||
bool LoadFileToString(TString<T>& Result, FStringView Path, FileSystem::EEncoding Encoding /* = FileSystem::EEncoding::Default */, bool bVerify /* = false */)
|
bool LoadFileToString(TString<T>& Result, FStringView Path, FileSystem::EEncoding Encoding /* = FileSystem::EEncoding::Default */, bool bVerify /* = false */)
|
||||||
{
|
{
|
||||||
if (!FileSystem::Exists(Path)) return false;
|
|
||||||
|
|
||||||
FILE* File = std::fopen(*Path, "rb");
|
FILE* File = std::fopen(*Path, "rb");
|
||||||
|
|
||||||
if (File == nullptr) return false;
|
if (File == nullptr) return false;
|
||||||
@ -87,7 +72,7 @@ bool LoadFileToString(TString<T>& Result, FStringView Path, FileSystem::EEncodin
|
|||||||
|
|
||||||
long Length = std::ftell(File);
|
long Length = std::ftell(File);
|
||||||
|
|
||||||
if (!Math::IsWithin(Length, 0, TNumericLimits<long>::Max())) return false;
|
if (Length == -1) return false;
|
||||||
|
|
||||||
if (std::fseek(File, 0, SEEK_SET) != 0) return false;
|
if (std::fseek(File, 0, SEEK_SET) != 0) return false;
|
||||||
|
|
||||||
@ -151,7 +136,7 @@ bool LoadFileToString(TString<T>& Result, FStringView Path, FileSystem::EEncodin
|
|||||||
|
|
||||||
if (ReadNum != sizeof(U)) return false;
|
if (ReadNum != sizeof(U)) return false;
|
||||||
|
|
||||||
if (bByteSwap) Char = Math::ByteSwap(static_cast<TMakeUnsigned<U>>(Char));
|
if constexpr (sizeof(U) > 1) if (bByteSwap) Char = Math::ByteSwap(Char);
|
||||||
|
|
||||||
# if PLATFORM_WINDOWS
|
# if PLATFORM_WINDOWS
|
||||||
{
|
{
|
||||||
@ -202,12 +187,6 @@ bool LoadFileToString(TString<T>& Result, FStringView Path, FileSystem::EEncodin
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template REDCRAFTUTILITY_API bool LoadFileToString<char> (FString&, FStringView, FileSystem::EEncoding, bool);
|
|
||||||
template REDCRAFTUTILITY_API bool LoadFileToString<wchar> (FWString&, FStringView, FileSystem::EEncoding, bool);
|
|
||||||
template REDCRAFTUTILITY_API bool LoadFileToString<u8char> (FU8String&, FStringView, FileSystem::EEncoding, bool);
|
|
||||||
template REDCRAFTUTILITY_API bool LoadFileToString<u16char>(FU16String&, FStringView, FileSystem::EEncoding, bool);
|
|
||||||
template REDCRAFTUTILITY_API bool LoadFileToString<u32char>(FU32String&, FStringView, FileSystem::EEncoding, bool);
|
|
||||||
|
|
||||||
template <CCharType T>
|
template <CCharType T>
|
||||||
bool SaveStringToFile(TStringView<T> String, FStringView Path, FileSystem::EEncoding Encoding /* = FileSystem::EEncoding::Default */, bool bWithBOM /* = true */)
|
bool SaveStringToFile(TStringView<T> String, FStringView Path, FileSystem::EEncoding Encoding /* = FileSystem::EEncoding::Default */, bool bWithBOM /* = true */)
|
||||||
{
|
{
|
||||||
@ -273,14 +252,14 @@ bool SaveStringToFile(TStringView<T> String, FStringView Path, FileSystem::EEnco
|
|||||||
{
|
{
|
||||||
T Return = LITERAL(T, '\r');
|
T Return = LITERAL(T, '\r');
|
||||||
|
|
||||||
if (bByteSwap) Return = Math::ByteSwap(static_cast<TMakeUnsigned<T>>(Return));
|
if constexpr (sizeof(T) > 1) if (bByteSwap) Return = Math::ByteSwap(Return);
|
||||||
|
|
||||||
if (std::fwrite(&Return, 1, sizeof(T), File) != sizeof(T)) return false;
|
if (std::fwrite(&Return, 1, sizeof(T), File) != sizeof(T)) return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
if (bByteSwap) Char = Math::ByteSwap(static_cast<TMakeUnsigned<T>>(Char));
|
if constexpr (sizeof(T) > 1) if (bByteSwap) Char = Math::ByteSwap(Char);
|
||||||
|
|
||||||
if (std::fwrite(&Char, 1, sizeof(T), File) != sizeof(T)) return false;
|
if (std::fwrite(&Char, 1, sizeof(T), File) != sizeof(T)) return false;
|
||||||
}
|
}
|
||||||
@ -292,301 +271,21 @@ bool SaveStringToFile(TStringView<T> String, FStringView Path, FileSystem::EEnco
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
FString PathWithNull;
|
|
||||||
|
|
||||||
PathWithNull.Reserve(Path.Num() + 1);
|
|
||||||
|
|
||||||
PathWithNull += Path;
|
|
||||||
PathWithNull += '\0';
|
|
||||||
|
|
||||||
switch (Encoding)
|
switch (Encoding)
|
||||||
{
|
{
|
||||||
case FileSystem::EEncoding::Narrow: { FString Temp; if (!Temp.DecodeFrom(String)) return false; if (!FileSystem::SaveStringToFile(Temp, PathWithNull, FileSystem::EEncoding::Narrow, bWithBOM)) return false; break; }
|
case FileSystem::EEncoding::Narrow: { FString Temp; if (!Temp.DecodeFrom(String)) return false; if (!FileSystem::SaveStringToFile(Temp, Path, FileSystem::EEncoding::Narrow, bWithBOM)) return false; break; }
|
||||||
case FileSystem::EEncoding::Wide: { FWString Temp; if (!Temp.DecodeFrom(String)) return false; if (!FileSystem::SaveStringToFile(Temp, PathWithNull, FileSystem::EEncoding::Wide, bWithBOM)) return false; break; }
|
case FileSystem::EEncoding::Wide: { FWString Temp; if (!Temp.DecodeFrom(String)) return false; if (!FileSystem::SaveStringToFile(Temp, Path, FileSystem::EEncoding::Wide, bWithBOM)) return false; break; }
|
||||||
case FileSystem::EEncoding::UTF8: { FU8String Temp; if (!Temp.DecodeFrom(String)) return false; if (!FileSystem::SaveStringToFile(Temp, PathWithNull, FileSystem::EEncoding::UTF8, bWithBOM)) return false; break; }
|
case FileSystem::EEncoding::UTF8: { FU8String Temp; if (!Temp.DecodeFrom(String)) return false; if (!FileSystem::SaveStringToFile(Temp, Path, FileSystem::EEncoding::UTF8, bWithBOM)) return false; break; }
|
||||||
case FileSystem::EEncoding::UTF16BE: { FU16String Temp; if (!Temp.DecodeFrom(String)) return false; if (!FileSystem::SaveStringToFile(Temp, PathWithNull, FileSystem::EEncoding::UTF16BE, bWithBOM)) return false; break; }
|
case FileSystem::EEncoding::UTF16BE: { FU16String Temp; if (!Temp.DecodeFrom(String)) return false; if (!FileSystem::SaveStringToFile(Temp, Path, FileSystem::EEncoding::UTF16BE, bWithBOM)) return false; break; }
|
||||||
case FileSystem::EEncoding::UTF16LE: { FU16String Temp; if (!Temp.DecodeFrom(String)) return false; if (!FileSystem::SaveStringToFile(Temp, PathWithNull, FileSystem::EEncoding::UTF16LE, bWithBOM)) return false; break; }
|
case FileSystem::EEncoding::UTF16LE: { FU16String Temp; if (!Temp.DecodeFrom(String)) return false; if (!FileSystem::SaveStringToFile(Temp, Path, FileSystem::EEncoding::UTF16LE, bWithBOM)) return false; break; }
|
||||||
case FileSystem::EEncoding::UTF32BE: { FU32String Temp; if (!Temp.DecodeFrom(String)) return false; if (!FileSystem::SaveStringToFile(Temp, PathWithNull, FileSystem::EEncoding::UTF32BE, bWithBOM)) return false; break; }
|
case FileSystem::EEncoding::UTF32BE: { FU32String Temp; if (!Temp.DecodeFrom(String)) return false; if (!FileSystem::SaveStringToFile(Temp, Path, FileSystem::EEncoding::UTF32BE, bWithBOM)) return false; break; }
|
||||||
case FileSystem::EEncoding::UTF32LE: { FU32String Temp; if (!Temp.DecodeFrom(String)) return false; if (!FileSystem::SaveStringToFile(Temp, PathWithNull, FileSystem::EEncoding::UTF32LE, bWithBOM)) return false; break; }
|
case FileSystem::EEncoding::UTF32LE: { FU32String Temp; if (!Temp.DecodeFrom(String)) return false; if (!FileSystem::SaveStringToFile(Temp, Path, FileSystem::EEncoding::UTF32LE, bWithBOM)) return false; break; }
|
||||||
default: check_no_entry(); return false;
|
default: check_no_entry(); return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template REDCRAFTUTILITY_API bool SaveStringToFile<char> (FStringView, FStringView, FileSystem::EEncoding, bool);
|
|
||||||
template REDCRAFTUTILITY_API bool SaveStringToFile<wchar> (FWStringView, FStringView, FileSystem::EEncoding, bool);
|
|
||||||
template REDCRAFTUTILITY_API bool SaveStringToFile<u8char> (FU8StringView, FStringView, FileSystem::EEncoding, bool);
|
|
||||||
template REDCRAFTUTILITY_API bool SaveStringToFile<u16char>(FU16StringView, FStringView, FileSystem::EEncoding, bool);
|
|
||||||
template REDCRAFTUTILITY_API bool SaveStringToFile<u32char>(FU32StringView, FStringView, FileSystem::EEncoding, bool);
|
|
||||||
|
|
||||||
size_t FileSize(FStringView Path)
|
|
||||||
{
|
|
||||||
if (!FileSystem::Exists(Path)) return static_cast<size_t>(-1);
|
|
||||||
|
|
||||||
FILE* File = std::fopen(*Path, "rb");
|
|
||||||
|
|
||||||
if (File == nullptr) return static_cast<size_t>(-1);
|
|
||||||
|
|
||||||
auto FileGuard = TScopeCallback([=] { Ignore = std::fclose(File); });
|
|
||||||
|
|
||||||
if (std::fseek(File, 0, SEEK_END) != 0) return static_cast<size_t>(-1);
|
|
||||||
|
|
||||||
const long Length = std::ftell(File);
|
|
||||||
|
|
||||||
if (!Math::IsWithin(Length, 0, TNumericLimits<long>::Max())) return static_cast<size_t>(-1);
|
|
||||||
|
|
||||||
FileGuard.Release();
|
|
||||||
|
|
||||||
if (std::fclose(File) != 0) return static_cast<size_t>(-1);
|
|
||||||
|
|
||||||
return Length;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Delete(FStringView Path)
|
|
||||||
{
|
|
||||||
return std::remove(*Path) == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Exists(FStringView Path)
|
|
||||||
{
|
|
||||||
# if PLATFORM_WINDOWS
|
|
||||||
{
|
|
||||||
DWORD Attributes = GetFileAttributesA(*Path);
|
|
||||||
|
|
||||||
if (Attributes == INVALID_FILE_ATTRIBUTES) return false;
|
|
||||||
|
|
||||||
return !(Attributes & FILE_ATTRIBUTE_DIRECTORY);
|
|
||||||
}
|
|
||||||
# elif PLATFORM_LINUX
|
|
||||||
{
|
|
||||||
struct stat FileInfo;
|
|
||||||
|
|
||||||
FileInfo.st_size = -1;
|
|
||||||
|
|
||||||
if (stat(*Path, &FileInfo) != 0) return false;
|
|
||||||
|
|
||||||
if (!S_ISREG(FileInfo.st_mode)) return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
# endif
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Copy(FStringView Destination, FStringView Source)
|
|
||||||
{
|
|
||||||
if (!FileSystem::Exists(Source)) return false;
|
|
||||||
|
|
||||||
FILE* FileA = std::fopen(*Source, "rb");
|
|
||||||
|
|
||||||
if (FileA == nullptr) return false;
|
|
||||||
|
|
||||||
auto FileGuardA = TScopeCallback([=] { Ignore = std::fclose(FileA); });
|
|
||||||
|
|
||||||
FILE* FileB = std::fopen(*Destination, "wb");
|
|
||||||
|
|
||||||
if (FileB == nullptr) return false;
|
|
||||||
|
|
||||||
auto FileGuardB = TScopeCallback([=] { Ignore = std::fclose(FileB); });
|
|
||||||
|
|
||||||
size_t ReadSize;
|
|
||||||
|
|
||||||
constexpr size_t BufferSize = 4096;
|
|
||||||
|
|
||||||
TStaticArray<uint8, BufferSize> Buffer;
|
|
||||||
|
|
||||||
do
|
|
||||||
{
|
|
||||||
ReadSize = std::fread(Buffer.GetData(), 1, BufferSize, FileA);
|
|
||||||
|
|
||||||
if (std::fwrite(Buffer.GetData(), 1, ReadSize, FileB) != ReadSize) return false;
|
|
||||||
}
|
|
||||||
while (ReadSize == BufferSize);
|
|
||||||
|
|
||||||
FileGuardA.Release();
|
|
||||||
|
|
||||||
if (std::fclose(FileA) != 0) return false;
|
|
||||||
|
|
||||||
FileGuardB.Release();
|
|
||||||
|
|
||||||
if (std::fclose(FileB) != 0) return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Rename(FStringView Destination, FStringView Source)
|
|
||||||
{
|
|
||||||
return std::rename(*Source, *Destination) == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CreateDirectory(FStringView Path, bool bRecursive /* = false */)
|
|
||||||
{
|
|
||||||
if (Path.Num() == 0) return false;
|
|
||||||
|
|
||||||
if (bRecursive)
|
|
||||||
{
|
|
||||||
if (Path.Back() == '/' || Path.Back() == '\\') Path = Path.First(Path.Num() - 1);
|
|
||||||
|
|
||||||
FStringView Parent = Path.First(Path.FindLastOf("/\\"));
|
|
||||||
|
|
||||||
if (!FileSystem::ExistsDirectory(Parent) && !FileSystem::CreateDirectory(Parent, true)) return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
# if PLATFORM_WINDOWS
|
|
||||||
{
|
|
||||||
return CreateDirectoryA(*Path, nullptr) != 0;
|
|
||||||
}
|
|
||||||
# elif PLATFORM_LINUX
|
|
||||||
{
|
|
||||||
return mkdir(*Path, 0755) == 0;
|
|
||||||
}
|
|
||||||
# endif
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DeleteDirectory(FStringView Path, bool bRecursive /* = false */)
|
|
||||||
{
|
|
||||||
if (bRecursive)
|
|
||||||
{
|
|
||||||
FString Temp;
|
|
||||||
|
|
||||||
bool bSuccessfully = FileSystem::IterateDirectory(Path, [&](FStringView File, bool bIsDirectory) -> bool
|
|
||||||
{
|
|
||||||
Temp.Reset(false);
|
|
||||||
|
|
||||||
Temp += Path;
|
|
||||||
Temp += '/';
|
|
||||||
Temp += File;
|
|
||||||
Temp += '\0';
|
|
||||||
|
|
||||||
if (bIsDirectory)
|
|
||||||
{
|
|
||||||
if (!FileSystem::DeleteDirectory(Temp, true)) return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (!FileSystem::Delete(Temp)) return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!bSuccessfully) return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
# if PLATFORM_WINDOWS
|
|
||||||
{
|
|
||||||
return RemoveDirectoryA(*Path) != 0;
|
|
||||||
}
|
|
||||||
# elif PLATFORM_LINUX
|
|
||||||
{
|
|
||||||
return rmdir(*Path) == 0;
|
|
||||||
}
|
|
||||||
# endif
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ExistsDirectory(FStringView Path)
|
|
||||||
{
|
|
||||||
# if PLATFORM_WINDOWS
|
|
||||||
{
|
|
||||||
DWORD Attributes = GetFileAttributesA(*Path);
|
|
||||||
|
|
||||||
if (Attributes == INVALID_FILE_ATTRIBUTES) return false;
|
|
||||||
|
|
||||||
return Attributes & FILE_ATTRIBUTE_DIRECTORY;
|
|
||||||
}
|
|
||||||
# elif PLATFORM_LINUX
|
|
||||||
{
|
|
||||||
DIR* Directory = opendir(*Path);
|
|
||||||
|
|
||||||
if (Directory == nullptr) return false;
|
|
||||||
|
|
||||||
Ignore = closedir(Directory);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
# endif
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool IterateDirectory(FStringView Path, TFunctionRef<bool(FStringView /* Path */, bool /* bIsDirectory */)> Visitor)
|
|
||||||
{
|
|
||||||
# if PLATFORM_WINDOWS
|
|
||||||
{
|
|
||||||
FString FindPath;
|
|
||||||
|
|
||||||
FindPath.Reserve(Path.Num() + 3);
|
|
||||||
|
|
||||||
FindPath += Path;
|
|
||||||
FindPath += '\\';
|
|
||||||
FindPath += '*';
|
|
||||||
FindPath += '\0';
|
|
||||||
|
|
||||||
WIN32_FIND_DATA FindData;
|
|
||||||
|
|
||||||
HANDLE FindHandle = FindFirstFileA(*FindPath, &FindData);
|
|
||||||
|
|
||||||
auto FindGuard = TScopeCallback([=] { Ignore = FindClose(FindHandle); });
|
|
||||||
|
|
||||||
if (FindHandle == INVALID_HANDLE_VALUE) return false;
|
|
||||||
|
|
||||||
do
|
|
||||||
{
|
|
||||||
const FStringView FilePath = FindData.cFileName;
|
|
||||||
|
|
||||||
if (FilePath == "." || FilePath == "..") continue;
|
|
||||||
|
|
||||||
const bool bIsDirectory = (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
|
|
||||||
|
|
||||||
if (!Visitor(FilePath, bIsDirectory)) return false;
|
|
||||||
}
|
|
||||||
while (FindNextFileA(FindHandle, &FindData) != 0);
|
|
||||||
|
|
||||||
FindGuard.Release();
|
|
||||||
|
|
||||||
if (!FindClose(FindHandle)) return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
# elif PLATFORM_LINUX
|
|
||||||
{
|
|
||||||
DIR* Directory = opendir(*Path);
|
|
||||||
|
|
||||||
if (Directory == nullptr) return false;
|
|
||||||
|
|
||||||
auto DirectoryGuard = TScopeCallback([=] { Ignore = closedir(Directory); });
|
|
||||||
|
|
||||||
dirent* Entry;
|
|
||||||
|
|
||||||
while ((Entry = readdir(Directory)) != nullptr)
|
|
||||||
{
|
|
||||||
const FStringView FilePath = Entry->d_name;
|
|
||||||
|
|
||||||
if (FilePath == "." || FilePath == "..") continue;
|
|
||||||
|
|
||||||
const bool bIsDirectory = Entry->d_type == DT_DIR;
|
|
||||||
|
|
||||||
if (!Visitor(FilePath, bIsDirectory)) return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
DirectoryGuard.Release();
|
|
||||||
|
|
||||||
if (closedir(Directory) != 0) return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
# endif
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
NAMESPACE_END(FileSystem)
|
NAMESPACE_END(FileSystem)
|
||||||
|
|
||||||
NAMESPACE_MODULE_END(Utility)
|
NAMESPACE_MODULE_END(Utility)
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
#include "CoreTypes.h"
|
#include "CoreTypes.h"
|
||||||
#include "TypeTraits/TypeTraits.h"
|
#include "TypeTraits/TypeTraits.h"
|
||||||
#include "Templates/Utility.h"
|
|
||||||
#include "Templates/Function.h"
|
|
||||||
#include "Containers/Array.h"
|
#include "Containers/Array.h"
|
||||||
#include "Strings/StringView.h"
|
#include "Strings/StringView.h"
|
||||||
#include "Strings/String.h"
|
#include "Strings/String.h"
|
||||||
@ -44,7 +42,13 @@ REDCRAFTUTILITY_API bool SaveArrayToFile(TArrayView<const uint8> Data, FStringVi
|
|||||||
* @return true if the file was successfully loaded, false otherwise.
|
* @return true if the file was successfully loaded, false otherwise.
|
||||||
*/
|
*/
|
||||||
template <CCharType T>
|
template <CCharType T>
|
||||||
REDCRAFTUTILITY_API bool LoadFileToString(TString<T>& Result, FStringView Path, FileSystem::EEncoding Encoding = FileSystem::EEncoding::Default, bool bVerify = false);
|
bool LoadFileToString(TString<T>& Result, FStringView Path, FileSystem::EEncoding Encoding = FileSystem::EEncoding::Default, bool bVerify = false);
|
||||||
|
|
||||||
|
template REDCRAFTUTILITY_API bool LoadFileToString<char> (FString&, FStringView, FileSystem::EEncoding, bool);
|
||||||
|
template REDCRAFTUTILITY_API bool LoadFileToString<wchar> (FWString&, FStringView, FileSystem::EEncoding, bool);
|
||||||
|
template REDCRAFTUTILITY_API bool LoadFileToString<u8char> (FU8String&, FStringView, FileSystem::EEncoding, bool);
|
||||||
|
template REDCRAFTUTILITY_API bool LoadFileToString<u16char>(FU16String&, FStringView, FileSystem::EEncoding, bool);
|
||||||
|
template REDCRAFTUTILITY_API bool LoadFileToString<u32char>(FU32String&, FStringView, FileSystem::EEncoding, bool);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Saves the string to the file at the specified path.
|
* Saves the string to the file at the specified path.
|
||||||
@ -57,7 +61,13 @@ REDCRAFTUTILITY_API bool LoadFileToString(TString<T>& Result, FStringView Path,
|
|||||||
* @return true if the file was successfully saved, false otherwise.
|
* @return true if the file was successfully saved, false otherwise.
|
||||||
*/
|
*/
|
||||||
template <CCharType T>
|
template <CCharType T>
|
||||||
REDCRAFTUTILITY_API bool SaveStringToFile(TStringView<T> String, FStringView Path, FileSystem::EEncoding Encoding = FileSystem::EEncoding::Default, bool bWithBOM = true);
|
bool SaveStringToFile(TStringView<T> String, FStringView Path, FileSystem::EEncoding Encoding = FileSystem::EEncoding::Default, bool bWithBOM = true);
|
||||||
|
|
||||||
|
template REDCRAFTUTILITY_API bool SaveStringToFile<char> (FStringView, FStringView, FileSystem::EEncoding, bool);
|
||||||
|
template REDCRAFTUTILITY_API bool SaveStringToFile<wchar> (FWStringView, FStringView, FileSystem::EEncoding, bool);
|
||||||
|
template REDCRAFTUTILITY_API bool SaveStringToFile<u8char> (FU8StringView, FStringView, FileSystem::EEncoding, bool);
|
||||||
|
template REDCRAFTUTILITY_API bool SaveStringToFile<u16char>(FU16StringView, FStringView, FileSystem::EEncoding, bool);
|
||||||
|
template REDCRAFTUTILITY_API bool SaveStringToFile<u32char>(FU32StringView, FStringView, FileSystem::EEncoding, bool);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Saves the string to the file at the specified path.
|
* Saves the string to the file at the specified path.
|
||||||
@ -82,33 +92,6 @@ bool SaveStringToFile(T&& String, FStringView Path, FileSystem::EEncoding Encodi
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return The size of the file at the specified path. */
|
|
||||||
REDCRAFTUTILITY_API size_t FileSize(FStringView Path);
|
|
||||||
|
|
||||||
/** Deletes the file at the specified path. */
|
|
||||||
REDCRAFTUTILITY_API bool Delete(FStringView Path);
|
|
||||||
|
|
||||||
/** @return true if the regular file at the specified path exists, false otherwise. */
|
|
||||||
REDCRAFTUTILITY_API bool Exists(FStringView Path);
|
|
||||||
|
|
||||||
/** Copies the file from the source path to the destination path. */
|
|
||||||
REDCRAFTUTILITY_API bool Copy(FStringView Destination, FStringView Source);
|
|
||||||
|
|
||||||
/** Renames the file from the source path to the destination path. */
|
|
||||||
REDCRAFTUTILITY_API bool Rename(FStringView Destination, FStringView Source);
|
|
||||||
|
|
||||||
/** Creates the directory at the specified path. If recursive, it will not delete the created items on failure. */
|
|
||||||
REDCRAFTUTILITY_API bool CreateDirectory(FStringView Path, bool bRecursive = false);
|
|
||||||
|
|
||||||
/** Deletes the directory at the specified path. If recursive, it will not recreate the deleted items on failure. */
|
|
||||||
REDCRAFTUTILITY_API bool DeleteDirectory(FStringView Path, bool bRecursive = false);
|
|
||||||
|
|
||||||
/** @return true if the directory at the specified path exists, false otherwise. */
|
|
||||||
REDCRAFTUTILITY_API bool ExistsDirectory(FStringView Path);
|
|
||||||
|
|
||||||
/** Iterates items in the directory at the specified path. */
|
|
||||||
REDCRAFTUTILITY_API bool IterateDirectory(FStringView Path, TFunctionRef<bool(FStringView /* Path */, bool /* bIsDirectory */)> Visitor);
|
|
||||||
|
|
||||||
NAMESPACE_END(FileSystem)
|
NAMESPACE_END(FileSystem)
|
||||||
|
|
||||||
NAMESPACE_MODULE_END(Utility)
|
NAMESPACE_MODULE_END(Utility)
|
||||||
|
@ -1124,7 +1124,10 @@ public:
|
|||||||
/** @return The non-modifiable standard C character string version of the string. */
|
/** @return The non-modifiable standard C character string version of the string. */
|
||||||
NODISCARD FORCEINLINE auto operator*() &&
|
NODISCARD FORCEINLINE auto operator*() &&
|
||||||
{
|
{
|
||||||
if (!EndsWith(LITERAL(T, '\0'))) this->PushBack(LITERAL(T, '\0'));
|
if (this->Back() != LITERAL(T, '\0'))
|
||||||
|
{
|
||||||
|
this->PushBack(LITERAL(T, '\0'));
|
||||||
|
}
|
||||||
|
|
||||||
return AsConst(*this).GetData();
|
return AsConst(*this).GetData();
|
||||||
}
|
}
|
||||||
|
@ -493,7 +493,7 @@ public:
|
|||||||
/** @return The non-modifiable standard C character string version of the string view. */
|
/** @return The non-modifiable standard C character string version of the string view. */
|
||||||
NODISCARD FORCEINLINE auto operator*() const
|
NODISCARD FORCEINLINE auto operator*() const
|
||||||
{
|
{
|
||||||
if (EndsWith(LITERAL(FElementType, '\0')) || Contains(LITERAL(FElementType, '\0')))
|
if (this->Back() == LITERAL(FElementType, '\0') || Contains(LITERAL(FElementType, '\0')))
|
||||||
{
|
{
|
||||||
return NAMESPACE_PRIVATE::TCStringFromTStringView<FElementType>(this->GetData(), false);
|
return NAMESPACE_PRIVATE::TCStringFromTStringView<FElementType>(this->GetData(), false);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user