Files
OpenVulkano/openVulkanoCpp/IO/FileDescription.hpp
2025-05-22 21:49:56 +02:00

84 lines
2.1 KiB
C++

/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#pragma once
#include <filesystem>
namespace OpenVulkano
{
struct FileDescription
{
constexpr static std::filesystem::perms ALL_READ = std::filesystem::perms::owner_read | std::filesystem::perms::group_read | std::filesystem::perms::others_read;
constexpr static size_t UNKNOWN_SIZE = SIZE_MAX;
std::filesystem::file_type type;
std::string path;
size_t size;
std::filesystem::perms permissions;
time_t createTime = {}, modTime = {};
[[deprecated("Use MkFile instead")]]
static FileDescription MakeDescriptionForFile(const char* path, const size_t size) { return MkFile(path, size); }
void Reset()
{
type = std::filesystem::file_type::unknown;
path = "";
size = 0;
permissions = {};
createTime = modTime = {};
}
static FileDescription MkFile(const char* path, const size_t size)
{
return {
std::filesystem::file_type::regular,
path,
size,
std::filesystem::perms::owner_write | ALL_READ,
std::time(nullptr), std::time(nullptr)
};
}
static FileDescription MkFile(const std::string& path, const size_t size)
{
return {
std::filesystem::file_type::regular,
path,
size,
std::filesystem::perms::owner_write | ALL_READ,
std::time(nullptr), std::time(nullptr)
};
}
static FileDescription MkFile(const std::filesystem::path& path, const size_t size)
{
return {
std::filesystem::file_type::regular,
path.string(),
size,
std::filesystem::perms::owner_write | ALL_READ,
std::time(nullptr), std::time(nullptr)
};
}
static FileDescription MkDir(const char* path)
{
FileDescription desc = MkFile(path, 0);
desc.type = std::filesystem::file_type::directory;
return desc;
}
static FileDescription MkDir(const std::string& path)
{
FileDescription desc = MkFile(path, 0);
desc.type = std::filesystem::file_type::directory;
return desc;
}
};
}