FileSystem: Swap vector for DynamicHeapArray

No point zeroing it out.
This commit is contained in:
Stenzek 2024-08-25 22:13:18 +10:00
parent 1af36dcdfb
commit 7efacbad36
No known key found for this signature in database
50 changed files with 145 additions and 117 deletions

View file

@ -1401,9 +1401,9 @@ s64 FileSystem::GetPathFileSize(const char* Path)
return sd.Size; return sd.Size;
} }
std::optional<std::vector<u8>> FileSystem::ReadBinaryFile(const char* filename, Error* error) std::optional<DynamicHeapArray<u8>> FileSystem::ReadBinaryFile(const char* filename, Error* error)
{ {
std::optional<std::vector<u8>> ret; std::optional<DynamicHeapArray<u8>> ret;
ManagedCFilePtr fp = OpenManagedCFile(filename, "rb", error); ManagedCFilePtr fp = OpenManagedCFile(filename, "rb", error);
if (!fp) if (!fp)
@ -1413,9 +1413,9 @@ std::optional<std::vector<u8>> FileSystem::ReadBinaryFile(const char* filename,
return ret; return ret;
} }
std::optional<std::vector<u8>> FileSystem::ReadBinaryFile(std::FILE* fp, Error* error) std::optional<DynamicHeapArray<u8>> FileSystem::ReadBinaryFile(std::FILE* fp, Error* error)
{ {
std::optional<std::vector<u8>> ret; std::optional<DynamicHeapArray<u8>> ret;
if (FSeek64(fp, 0, SEEK_END) != 0) [[unlikely]] if (FSeek64(fp, 0, SEEK_END) != 0) [[unlikely]]
{ {
@ -1445,7 +1445,7 @@ std::optional<std::vector<u8>> FileSystem::ReadBinaryFile(std::FILE* fp, Error*
return ret; return ret;
} }
ret = std::vector<u8>(static_cast<size_t>(size)); ret = DynamicHeapArray<u8>(static_cast<size_t>(size));
if (size > 0 && std::fread(ret->data(), 1u, static_cast<size_t>(size), fp) != static_cast<size_t>(size)) [[unlikely]] if (size > 0 && std::fread(ret->data(), 1u, static_cast<size_t>(size), fp) != static_cast<size_t>(size)) [[unlikely]]
{ {
Error::SetErrno(error, "fread() failed: ", errno); Error::SetErrno(error, "fread() failed: ", errno);

View file

@ -1,8 +1,9 @@
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com> // SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) // SPDX-License-Identifier: (GPL-3.0 OR PolyForm-Strict-1.0.0)
#pragma once #pragma once
#include "heap_array.h"
#include "types.h" #include "types.h"
#include <cstdio> #include <cstdio>
@ -171,8 +172,8 @@ private:
}; };
#endif #endif
std::optional<std::vector<u8>> ReadBinaryFile(const char* filename, Error* error = nullptr); std::optional<DynamicHeapArray<u8>> ReadBinaryFile(const char* filename, Error* error = nullptr);
std::optional<std::vector<u8>> ReadBinaryFile(std::FILE* fp, Error* error = nullptr); std::optional<DynamicHeapArray<u8>> ReadBinaryFile(std::FILE* fp, Error* error = nullptr);
std::optional<std::string> ReadFileToString(const char* filename, Error* error = nullptr); std::optional<std::string> ReadFileToString(const char* filename, Error* error = nullptr);
std::optional<std::string> ReadFileToString(std::FILE* fp, Error* error = nullptr); std::optional<std::string> ReadFileToString(std::FILE* fp, Error* error = nullptr);
bool WriteBinaryFile(const char* filename, const void* data, size_t data_length, Error* error = nullptr); bool WriteBinaryFile(const char* filename, const void* data, size_t data_length, Error* error = nullptr);

View file

@ -1,10 +1,8 @@
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com> // SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) // SPDX-License-Identifier: (GPL-3.0 OR PolyForm-Strict-1.0.0)
#pragma once #pragma once
#include "common/assert.h"
#include <algorithm> #include <algorithm>
#include <cassert> #include <cassert>
#include <cstdlib> #include <cstdlib>
@ -117,18 +115,20 @@ private:
{ {
#ifdef _MSC_VER #ifdef _MSC_VER
m_data = static_cast<T*>(_aligned_malloc(SIZE * sizeof(T), ALIGNMENT)); m_data = static_cast<T*>(_aligned_malloc(SIZE * sizeof(T), ALIGNMENT));
if (!m_data) assert(m_data);
Panic("Memory allocation failed."); if (!m_data) [[unlikely]]
std::abort();
#else #else
if (posix_memalign(reinterpret_cast<void**>(&m_data), ALIGNMENT, SIZE * sizeof(T)) != 0) if (posix_memalign(reinterpret_cast<void**>(&m_data), ALIGNMENT, SIZE * sizeof(T)) != 0) [[unlikely]]
Panic("Memory allocation failed."); std::abort();
#endif #endif
} }
else else
{ {
m_data = static_cast<T*>(std::malloc(SIZE * sizeof(T))); m_data = static_cast<T*>(std::malloc(SIZE * sizeof(T)));
if (!m_data) assert(m_data);
Panic("Memory allocation failed."); if (!m_data) [[unlikely]]
std::abort();
} }
} }
void deallocate() void deallocate()
@ -377,11 +377,12 @@ private:
{ {
#ifdef _MSC_VER #ifdef _MSC_VER
m_data = static_cast<T*>(_aligned_realloc(prev_ptr, size * sizeof(T), alignment)); m_data = static_cast<T*>(_aligned_realloc(prev_ptr, size * sizeof(T), alignment));
assert(m_data);
if (!m_data) [[unlikely]] if (!m_data) [[unlikely]]
Panic("Memory allocation failed."); std::abort();
#else #else
if (posix_memalign(reinterpret_cast<void**>(&m_data), alignment, size * sizeof(T)) != 0) [[unlikely]] if (posix_memalign(reinterpret_cast<void**>(&m_data), alignment, size * sizeof(T)) != 0) [[unlikely]]
Panic("Memory allocation failed."); std::abort();
if (prev_ptr) if (prev_ptr)
{ {
@ -393,8 +394,9 @@ private:
else else
{ {
m_data = static_cast<T*>(std::realloc(prev_ptr, size * sizeof(T))); m_data = static_cast<T*>(std::realloc(prev_ptr, size * sizeof(T)));
assert(m_data);
if (!m_data) [[unlikely]] if (!m_data) [[unlikely]]
Panic("Memory allocation failed."); std::abort();
} }
m_size = size; m_size = size;

View file

@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com> and contributors. // SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com> and contributors.
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) // SPDX-License-Identifier: (GPL-3.0 OR PolyForm-Strict-1.0.0)
#include "bios.h" #include "bios.h"
#include "cpu_disasm.h" #include "cpu_disasm.h"
@ -190,7 +190,7 @@ std::optional<BIOS::Image> BIOS::LoadImageFromFile(const char* filename, Error*
} }
// We want to hash the whole file. That means reading the whole thing in, if it's a larger BIOS (PS2). // We want to hash the whole file. That means reading the whole thing in, if it's a larger BIOS (PS2).
std::optional<std::vector<u8>> data = FileSystem::ReadBinaryFile(fp.get(), error); std::optional<DynamicHeapArray<u8>> data = FileSystem::ReadBinaryFile(fp.get(), error);
if (!data.has_value() || data->size() < BIOS_SIZE) if (!data.has_value() || data->size() < BIOS_SIZE)
return ret; return ret;

View file

@ -1,10 +1,11 @@
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>. // SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>.
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) // SPDX-License-Identifier: (GPL-3.0 OR PolyForm-Strict-1.0.0)
#pragma once #pragma once
#include "types.h" #include "types.h"
#include "common/heap_array.h"
#include "common/small_string.h" #include "common/small_string.h"
#include <array> #include <array>
@ -52,7 +53,7 @@ struct Image
{ {
const ImageInfo* info; const ImageInfo* info;
ImageInfo::Hash hash; ImageInfo::Hash hash;
std::vector<u8> data; DynamicHeapArray<u8> data;
}; };
#pragma pack(push, 1) #pragma pack(push, 1)

View file

@ -1034,15 +1034,15 @@ bool Bus::SideloadEXE(const std::string& path, Error* error)
if (const std::string libps_path = Path::BuildRelativePath(path, "libps.exe"); if (const std::string libps_path = Path::BuildRelativePath(path, "libps.exe");
FileSystem::FileExists(libps_path.c_str())) FileSystem::FileExists(libps_path.c_str()))
{ {
const std::optional<std::vector<u8>> exe_data = FileSystem::ReadBinaryFile(libps_path.c_str(), error); const std::optional<DynamicHeapArray<u8>> exe_data = FileSystem::ReadBinaryFile(libps_path.c_str(), error);
okay = (exe_data.has_value() && InjectExecutable(exe_data.value(), false, error)); okay = (exe_data.has_value() && InjectExecutable(exe_data->cspan(), false, error));
if (!okay) if (!okay)
Error::AddPrefix(error, "Failed to load libps.exe: "); Error::AddPrefix(error, "Failed to load libps.exe: ");
} }
if (okay) if (okay)
{ {
const std::optional<std::vector<u8>> exe_data = FileSystem::ReadBinaryFile(System::GetExeOverride().c_str(), error); const std::optional<DynamicHeapArray<u8>> exe_data = FileSystem::ReadBinaryFile(System::GetExeOverride().c_str(), error);
okay = (exe_data.has_value() && InjectExecutable(exe_data.value(), true, error)); okay = (exe_data.has_value() && InjectExecutable(exe_data->cspan(), true, error));
if (!okay) if (!okay)
Error::AddPrefixFmt(error, "Failed to load {}: ", Path::GetFileName(path)); Error::AddPrefixFmt(error, "Failed to load {}: ", Path::GetFileName(path));
} }

View file

@ -7,6 +7,7 @@
#include "cpu_core_private.h" #include "cpu_core_private.h"
#include "system.h" #include "system.h"
#include "common/assert.h"
#include "common/log.h" #include "common/log.h"
#include "common/small_string.h" #include "common/small_string.h"
#include "common/string_util.h" #include "common/string_util.h"

View file

@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com> // SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) // SPDX-License-Identifier: (GPL-3.0 OR PolyForm-Strict-1.0.0)
#include "memory_card_image.h" #include "memory_card_image.h"
#include "gpu_types.h" #include "gpu_types.h"
@ -87,10 +87,10 @@ const T* GetFramePtr(const DataArray& data, u32 block, u32 frame)
} }
static std::optional<u32> GetNextFreeBlock(const DataArray& data); static std::optional<u32> GetNextFreeBlock(const DataArray& data);
static bool ImportCardMCD(DataArray* data, const char* filename, std::vector<u8> file_data, Error* error); static bool ImportCardMCD(DataArray* data, const char* filename, std::span<const u8> file_data, Error* error);
static bool ImportCardGME(DataArray* data, const char* filename, std::vector<u8> file_data, Error* error); static bool ImportCardGME(DataArray* data, const char* filename, std::span<const u8> file_data, Error* error);
static bool ImportCardVGS(DataArray* data, const char* filename, std::vector<u8> file_data, Error* error); static bool ImportCardVGS(DataArray* data, const char* filename, std::span<const u8> file_data, Error* error);
static bool ImportCardPSX(DataArray* data, const char* filename, std::vector<u8> file_data, Error* error); static bool ImportCardPSX(DataArray* data, const char* filename, std::span<const u8> file_data, Error* error);
static bool ImportSaveWithDirectoryFrame(DataArray* data, const char* filename, const FILESYSTEM_STAT_DATA& sd, static bool ImportSaveWithDirectoryFrame(DataArray* data, const char* filename, const FILESYSTEM_STAT_DATA& sd,
Error* error); Error* error);
static bool ImportRawSave(DataArray* data, const char* filename, const FILESYSTEM_STAT_DATA& sd, Error* error); static bool ImportRawSave(DataArray* data, const char* filename, const FILESYSTEM_STAT_DATA& sd, Error* error);
@ -324,7 +324,7 @@ bool MemoryCardImage::ReadFile(const DataArray& data, const FileInfo& fi, std::v
return true; return true;
} }
bool MemoryCardImage::WriteFile(DataArray* data, std::string_view filename, const std::vector<u8>& buffer, Error* error) bool MemoryCardImage::WriteFile(DataArray* data, std::string_view filename, const std::span<const u8> buffer, Error* error)
{ {
if (buffer.empty()) if (buffer.empty())
{ {
@ -481,7 +481,7 @@ bool MemoryCardImage::UndeleteFile(DataArray* data, const FileInfo& fi)
return true; return true;
} }
bool MemoryCardImage::ImportCardMCD(DataArray* data, const char* filename, std::vector<u8> file_data, Error* error) bool MemoryCardImage::ImportCardMCD(DataArray* data, const char* filename, std::span<const u8> file_data, Error* error)
{ {
if (file_data.size() != DATA_SIZE) if (file_data.size() != DATA_SIZE)
{ {
@ -494,7 +494,7 @@ bool MemoryCardImage::ImportCardMCD(DataArray* data, const char* filename, std::
return true; return true;
} }
bool MemoryCardImage::ImportCardGME(DataArray* data, const char* filename, std::vector<u8> file_data, Error* error) bool MemoryCardImage::ImportCardGME(DataArray* data, const char* filename, std::span<const u8> file_data, Error* error)
{ {
#pragma pack(push, 1) #pragma pack(push, 1)
struct GMEHeader struct GMEHeader
@ -529,15 +529,27 @@ bool MemoryCardImage::ImportCardGME(DataArray* data, const char* filename, std::
{ {
WARNING_LOG("GME memory card '{}' is too small (got {} expected {}), padding with zeroes", filename, WARNING_LOG("GME memory card '{}' is too small (got {} expected {}), padding with zeroes", filename,
file_data.size(), expected_size); file_data.size(), expected_size);
file_data.resize(expected_size); if (file_data.size() > sizeof(GMEHeader))
{
const size_t present = file_data.size() - sizeof(GMEHeader);
std::memcpy(data->data(), file_data.data() + sizeof(GMEHeader), present);
std::memset(data->data() + present, 0, DATA_SIZE - present);
}
else
{
std::memset(data->data(), 0, DATA_SIZE);
}
}
else
{
// we don't actually care about the header, just skip over it
std::memcpy(data->data(), file_data.data() + sizeof(GMEHeader), DATA_SIZE);
} }
// we don't actually care about the header, just skip over it
std::memcpy(data->data(), file_data.data() + sizeof(GMEHeader), DATA_SIZE);
return true; return true;
} }
bool MemoryCardImage::ImportCardVGS(DataArray* data, const char* filename, std::vector<u8> file_data, Error* error) bool MemoryCardImage::ImportCardVGS(DataArray* data, const char* filename, std::span<const u8> file_data, Error* error)
{ {
constexpr u32 HEADER_SIZE = 64; constexpr u32 HEADER_SIZE = 64;
constexpr u32 EXPECTED_SIZE = HEADER_SIZE + DATA_SIZE; constexpr u32 EXPECTED_SIZE = HEADER_SIZE + DATA_SIZE;
@ -560,7 +572,7 @@ bool MemoryCardImage::ImportCardVGS(DataArray* data, const char* filename, std::
return true; return true;
} }
bool MemoryCardImage::ImportCardPSX(DataArray* data, const char* filename, std::vector<u8> file_data, Error* error) bool MemoryCardImage::ImportCardPSX(DataArray* data, const char* filename, std::span<const u8> file_data, Error* error)
{ {
constexpr u32 HEADER_SIZE = 256; constexpr u32 HEADER_SIZE = 256;
constexpr u32 EXPECTED_SIZE = HEADER_SIZE + DATA_SIZE; constexpr u32 EXPECTED_SIZE = HEADER_SIZE + DATA_SIZE;
@ -583,7 +595,7 @@ bool MemoryCardImage::ImportCardPSX(DataArray* data, const char* filename, std::
return true; return true;
} }
bool MemoryCardImage::ImportCard(DataArray* data, const char* filename, std::vector<u8> file_data, Error* error) bool MemoryCardImage::ImportCard(DataArray* data, const char* filename, std::span<const u8> file_data, Error* error)
{ {
const std::string_view extension = Path::GetExtension(filename); const std::string_view extension = Path::GetExtension(filename);
if (extension.empty()) if (extension.empty())
@ -597,19 +609,19 @@ bool MemoryCardImage::ImportCard(DataArray* data, const char* filename, std::vec
StringUtil::EqualNoCase(extension, "psm") || StringUtil::EqualNoCase(extension, "ps") || StringUtil::EqualNoCase(extension, "psm") || StringUtil::EqualNoCase(extension, "ps") ||
StringUtil::EqualNoCase(extension, "ddf")) StringUtil::EqualNoCase(extension, "ddf"))
{ {
return ImportCardMCD(data, filename, std::move(file_data), error); return ImportCardMCD(data, filename, file_data, error);
} }
else if (StringUtil::EqualNoCase(extension, "gme")) else if (StringUtil::EqualNoCase(extension, "gme"))
{ {
return ImportCardGME(data, filename, std::move(file_data), error); return ImportCardGME(data, filename, file_data, error);
} }
else if (StringUtil::EqualNoCase(extension, "mem") || StringUtil::EqualNoCase(extension, "vgs")) else if (StringUtil::EqualNoCase(extension, "mem") || StringUtil::EqualNoCase(extension, "vgs"))
{ {
return ImportCardVGS(data, filename, std::move(file_data), error); return ImportCardVGS(data, filename, file_data, error);
} }
else if (StringUtil::EqualNoCase(extension, "psx")) else if (StringUtil::EqualNoCase(extension, "psx"))
{ {
return ImportCardPSX(data, filename, std::move(file_data), error); return ImportCardPSX(data, filename, file_data, error);
} }
else else
{ {
@ -620,11 +632,11 @@ bool MemoryCardImage::ImportCard(DataArray* data, const char* filename, std::vec
bool MemoryCardImage::ImportCard(DataArray* data, const char* filename, Error* error) bool MemoryCardImage::ImportCard(DataArray* data, const char* filename, Error* error)
{ {
std::optional<std::vector<u8>> file_data = FileSystem::ReadBinaryFile(filename, error); std::optional<DynamicHeapArray<u8>> file_data = FileSystem::ReadBinaryFile(filename, error);
if (!file_data.has_value()) if (!file_data.has_value())
return false; return false;
return ImportCard(data, filename, std::move(file_data.value()), error); return ImportCard(data, filename, file_data->cspan(), error);
} }
bool MemoryCardImage::ExportSave(DataArray* data, const FileInfo& fi, const char* filename, Error* error) bool MemoryCardImage::ExportSave(DataArray* data, const FileInfo& fi, const char* filename, Error* error)
@ -724,7 +736,7 @@ bool MemoryCardImage::ImportRawSave(DataArray* data, const char* filename, const
if (save_name.length() > DirectoryFrame::FILE_NAME_LENGTH) if (save_name.length() > DirectoryFrame::FILE_NAME_LENGTH)
save_name.erase(DirectoryFrame::FILE_NAME_LENGTH); save_name.erase(DirectoryFrame::FILE_NAME_LENGTH);
std::optional<std::vector<u8>> blocks = FileSystem::ReadBinaryFile(filename, error); std::optional<DynamicHeapArray<u8>> blocks = FileSystem::ReadBinaryFile(filename, error);
if (!blocks.has_value()) if (!blocks.has_value())
return false; return false;

View file

@ -1,9 +1,10 @@
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com> // SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) // SPDX-License-Identifier: (GPL-3.0 OR PolyForm-Strict-1.0.0)
#pragma once #pragma once
#include <array> #include <array>
#include <span>
#include <string> #include <string>
#include <string_view> #include <string_view>
#include <vector> #include <vector>
@ -51,11 +52,11 @@ bool IsValid(const DataArray& data);
u32 GetFreeBlockCount(const DataArray& data); u32 GetFreeBlockCount(const DataArray& data);
std::vector<FileInfo> EnumerateFiles(const DataArray& data, bool include_deleted); std::vector<FileInfo> EnumerateFiles(const DataArray& data, bool include_deleted);
bool ReadFile(const DataArray& data, const FileInfo& fi, std::vector<u8>* buffer, Error* error); bool ReadFile(const DataArray& data, const FileInfo& fi, std::vector<u8>* buffer, Error* error);
bool WriteFile(DataArray* data, std::string_view filename, const std::vector<u8>& buffer, Error* error); bool WriteFile(DataArray* data, std::string_view filename, std::span<const u8> buffer, Error* error);
bool DeleteFile(DataArray* data, const FileInfo& fi, bool clear_sectors); bool DeleteFile(DataArray* data, const FileInfo& fi, bool clear_sectors);
bool UndeleteFile(DataArray* data, const FileInfo& fi); bool UndeleteFile(DataArray* data, const FileInfo& fi);
bool ImportCard(DataArray* data, const char* filename, Error* error); bool ImportCard(DataArray* data, const char* filename, Error* error);
bool ImportCard(DataArray* data, const char* filename, std::vector<u8> file_data, Error* error); bool ImportCard(DataArray* data, const char* filename, std::span<const u8> file_data, Error* error);
bool ExportSave(DataArray* data, const FileInfo& fi, const char* filename, Error* error); bool ExportSave(DataArray* data, const FileInfo& fi, const char* filename, Error* error);
bool ImportSave(DataArray* data, const char* filename, Error* error); bool ImportSave(DataArray* data, const char* filename, Error* error);
} // namespace MemoryCardImage } // namespace MemoryCardImage

View file

@ -1,5 +1,6 @@
// SPDX-FileCopyrightText: 2002-2024 PCSX2 Dev Team, Connor McLaughlin <stenzek@gmail.com> // SPDX-FileCopyrightText: 2002-2024 PCSX2 Dev Team, Connor McLaughlin <stenzek@gmail.com>
// SPDX-License-Identifier: LGPL-3.0+ // SPDX-License-Identifier: (GPL-3.0 OR PolyForm-Strict-1.0.0)
// NOTE: File has been rewritten completely compared to the original, only the enums remain.
#include "pine_server.h" #include "pine_server.h"
#include "cpu_core.h" #include "cpu_core.h"
@ -11,6 +12,7 @@
#include "util/sockets.h" #include "util/sockets.h"
#include "common/assert.h"
#include "common/binary_reader_writer.h" #include "common/binary_reader_writer.h"
#include "common/error.h" #include "common/error.h"
#include "common/file_system.h" #include "common/file_system.h"

View file

@ -1,8 +1,8 @@
// SPDX-FileCopyrightText: 2002-2024 PCSX2 Dev Team, Connor McLaughlin <stenzek@gmail.com> // SPDX-FileCopyrightText: 2002-2024 PCSX2 Dev Team, Connor McLaughlin <stenzek@gmail.com>
// SPDX-License-Identifier: LGPL-3.0+ // SPDX-License-Identifier: (GPL-3.0 OR PolyForm-Strict-1.0.0)
/* A reference client implementation for interfacing with PINE is available // A reference client implementation for interfacing with PINE is available here:
* here: https://code.govanify.com/govanify/pine/ */ // https://code.govanify.com/govanify/pine/
#pragma once #pragma once

View file

@ -69,7 +69,7 @@ float PSFLoader::File::GetTagFloat(const char* tag_name, float default_value) co
bool PSFLoader::File::Load(const char* path, Error* error) bool PSFLoader::File::Load(const char* path, Error* error)
{ {
std::optional<std::vector<u8>> file_data(FileSystem::ReadBinaryFile(path, error)); std::optional<DynamicHeapArray<u8>> file_data(FileSystem::ReadBinaryFile(path, error));
if (!file_data.has_value() || file_data->empty()) if (!file_data.has_value() || file_data->empty())
return false; return false;

View file

@ -900,12 +900,12 @@ bool System::GetGameDetailsFromImage(CDImage* cdi, std::string* out_id, GameHash
System::GameHash System::GetGameHashFromFile(const char* path) System::GameHash System::GetGameHashFromFile(const char* path)
{ {
const std::optional<std::vector<u8>> data = FileSystem::ReadBinaryFile(path); const std::optional<DynamicHeapArray<u8>> data = FileSystem::ReadBinaryFile(path);
if (!data) if (!data)
return 0; return 0;
const std::string display_name = FileSystem::GetDisplayNameFromPath(path); const std::string display_name = FileSystem::GetDisplayNameFromPath(path);
return GetGameHashFromBuffer(display_name, data.value(), IsoReader::ISOPrimaryVolumeDescriptor{}, 0); return GetGameHashFromBuffer(display_name, data->cspan(), IsoReader::ISOPrimaryVolumeDescriptor{}, 0);
} }
std::string System::GetExecutableNameForImage(IsoReader& iso, bool strip_subdirectories) std::string System::GetExecutableNameForImage(IsoReader& iso, bool strip_subdirectories)

View file

@ -11,6 +11,7 @@
#include "util/http_downloader.h" #include "util/http_downloader.h"
#include "common/assert.h"
#include "common/error.h" #include "common/error.h"
#include "common/file_system.h" #include "common/file_system.h"
#include "common/log.h" #include "common/log.h"

View file

@ -7,6 +7,7 @@
#include "core/system.h" #include "core/system.h"
#include "common/assert.h"
#include "common/file_system.h" #include "common/file_system.h"
#include "common/path.h" #include "common/path.h"
#include "common/string_util.h" #include "common/string_util.h"

View file

@ -1950,10 +1950,10 @@ bool Host::ResourceFileExists(std::string_view filename, bool allow_override)
return FileSystem::FileExists(path.c_str()); return FileSystem::FileExists(path.c_str());
} }
std::optional<std::vector<u8>> Host::ReadResourceFile(std::string_view filename, bool allow_override) std::optional<DynamicHeapArray<u8>> Host::ReadResourceFile(std::string_view filename, bool allow_override)
{ {
const std::string path = QtHost::GetResourcePath(filename, allow_override); const std::string path = QtHost::GetResourcePath(filename, allow_override);
std::optional<std::vector<u8>> ret(FileSystem::ReadBinaryFile(path.c_str())); std::optional<DynamicHeapArray<u8>> ret(FileSystem::ReadBinaryFile(path.c_str()));
if (!ret.has_value()) if (!ret.has_value())
ERROR_LOG("Failed to read resource file '{}'", filename); ERROR_LOG("Failed to read resource file '{}'", filename);
return ret; return ret;

View file

@ -212,10 +212,10 @@ bool Host::ResourceFileExists(std::string_view filename, bool allow_override)
return FileSystem::FileExists(path.c_str()); return FileSystem::FileExists(path.c_str());
} }
std::optional<std::vector<u8>> Host::ReadResourceFile(std::string_view filename, bool allow_override) std::optional<DynamicHeapArray<u8>> Host::ReadResourceFile(std::string_view filename, bool allow_override)
{ {
const std::string path(Path::Combine(EmuFolders::Resources, filename)); const std::string path(Path::Combine(EmuFolders::Resources, filename));
std::optional<std::vector<u8>> ret(FileSystem::ReadBinaryFile(path.c_str())); std::optional<DynamicHeapArray<u8>> ret(FileSystem::ReadBinaryFile(path.c_str()));
if (!ret.has_value()) if (!ret.has_value())
ERROR_LOG("Failed to read resource file '{}'", filename); ERROR_LOG("Failed to read resource file '{}'", filename);
return ret; return ret;

View file

@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com> // SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) // SPDX-License-Identifier: (GPL-3.0 OR PolyForm-Strict-1.0.0)
#include "assert.h" #include "assert.h"
#include "cd_image.h" #include "cd_image.h"
@ -78,7 +78,7 @@ bool CDImageMds::OpenAndParse(const char* filename, Error* error)
return false; return false;
} }
std::optional<std::vector<u8>> mds_data_opt(FileSystem::ReadBinaryFile(mds_fp)); std::optional<DynamicHeapArray<u8>> mds_data_opt(FileSystem::ReadBinaryFile(mds_fp));
std::fclose(mds_fp); std::fclose(mds_fp);
if (!mds_data_opt.has_value() || mds_data_opt->size() < 0x54) if (!mds_data_opt.has_value() || mds_data_opt->size() < 0x54)
{ {
@ -95,7 +95,7 @@ bool CDImageMds::OpenAndParse(const char* filename, Error* error)
return false; return false;
} }
const std::vector<u8>& mds = mds_data_opt.value(); const DynamicHeapArray<u8>& mds = mds_data_opt.value();
static constexpr char expected_signature[] = "MEDIA DESCRIPTOR"; static constexpr char expected_signature[] = "MEDIA DESCRIPTOR";
if (std::memcmp(&mds[0], expected_signature, sizeof(expected_signature) - 1) != 0) if (std::memcmp(&mds[0], expected_signature, sizeof(expected_signature) - 1) != 0)
{ {

View file

@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2019-2023 Connor McLaughlin <stenzek@gmail.com> // SPDX-FileCopyrightText: 2019-2023 Connor McLaughlin <stenzek@gmail.com>
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) // SPDX-License-Identifier: (GPL-3.0 OR PolyForm-Strict-1.0.0)
#include "d3d11_device.h" #include "d3d11_device.h"
#include "core/host.h" // TODO: Remove me #include "core/host.h" // TODO: Remove me

View file

@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com> // SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) // SPDX-License-Identifier: (GPL-3.0 OR PolyForm-Strict-1.0.0)
#pragma once #pragma once

View file

@ -1,10 +1,11 @@
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com> // SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) // SPDX-License-Identifier: (GPL-3.0 OR PolyForm-Strict-1.0.0)
#include "d3d11_pipeline.h" #include "d3d11_pipeline.h"
#include "d3d11_device.h" #include "d3d11_device.h"
#include "d3d_common.h" #include "d3d_common.h"
#include "common/assert.h"
#include "common/error.h" #include "common/error.h"
#include "common/hash_combine.h" #include "common/hash_combine.h"

View file

@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2019-2023 Connor McLaughlin <stenzek@gmail.com> // SPDX-FileCopyrightText: 2019-2023 Connor McLaughlin <stenzek@gmail.com>
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) // SPDX-License-Identifier: (GPL-3.0 OR PolyForm-Strict-1.0.0)
#pragma once #pragma once

View file

@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com> // SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) // SPDX-License-Identifier: (GPL-3.0 OR PolyForm-Strict-1.0.0)
#include "d3d11_stream_buffer.h" #include "d3d11_stream_buffer.h"
#include "d3d11_device.h" #include "d3d11_device.h"

View file

@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com> // SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) // SPDX-License-Identifier: (GPL-3.0 OR PolyForm-Strict-1.0.0)
#pragma once #pragma once

View file

@ -1,10 +1,11 @@
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com> // SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) // SPDX-License-Identifier: (GPL-3.0 OR PolyForm-Strict-1.0.0)
#include "d3d11_texture.h" #include "d3d11_texture.h"
#include "d3d11_device.h" #include "d3d11_device.h"
#include "d3d_common.h" #include "d3d_common.h"
#include "common/assert.h"
#include "common/log.h" #include "common/log.h"
#include "common/string_util.h" #include "common/string_util.h"

View file

@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com> // SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) // SPDX-License-Identifier: (GPL-3.0 OR PolyForm-Strict-1.0.0)
#pragma once #pragma once

View file

@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com> // SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) // SPDX-License-Identifier: (GPL-3.0 OR PolyForm-Strict-1.0.0)
#include "d3d12_builders.h" #include "d3d12_builders.h"
#include "d3d12_device.h" #include "d3d12_device.h"

View file

@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com> // SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) // SPDX-License-Identifier: (GPL-3.0 OR PolyForm-Strict-1.0.0)
#pragma once #pragma once

View file

@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com> // SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) // SPDX-License-Identifier: (GPL-3.0 OR PolyForm-Strict-1.0.0)
#include "d3d12_descriptor_heap_manager.h" #include "d3d12_descriptor_heap_manager.h"

View file

@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com> // SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) // SPDX-License-Identifier: (GPL-3.0 OR PolyForm-Strict-1.0.0)
#pragma once #pragma once

View file

@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com> // SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) // SPDX-License-Identifier: (GPL-3.0 OR PolyForm-Strict-1.0.0)
#include "d3d12_device.h" #include "d3d12_device.h"
#include "d3d12_builders.h" #include "d3d12_builders.h"
@ -60,7 +60,7 @@ static std::mutex s_instance_mutex;
static constexpr GPUTexture::Format s_swap_chain_format = GPUTexture::Format::RGBA8; static constexpr GPUTexture::Format s_swap_chain_format = GPUTexture::Format::RGBA8;
// We just need to keep this alive, never reference it. // We just need to keep this alive, never reference it.
static std::vector<u8> s_pipeline_cache_data; static DynamicHeapArray<u8> s_pipeline_cache_data;
#ifdef _DEBUG #ifdef _DEBUG
#include "WinPixEventRuntime/pix3.h" #include "WinPixEventRuntime/pix3.h"
@ -268,7 +268,7 @@ void D3D12Device::DestroyDevice()
DestroyCommandLists(); DestroyCommandLists();
m_pipeline_library.Reset(); m_pipeline_library.Reset();
std::vector<u8>().swap(s_pipeline_cache_data); s_pipeline_cache_data.deallocate();
m_fence.Reset(); m_fence.Reset();
if (m_fence_event != NULL) if (m_fence_event != NULL)
{ {
@ -285,7 +285,7 @@ void D3D12Device::DestroyDevice()
bool D3D12Device::ReadPipelineCache(const std::string& filename) bool D3D12Device::ReadPipelineCache(const std::string& filename)
{ {
std::optional<std::vector<u8>> data = FileSystem::ReadBinaryFile(filename.c_str()); std::optional<DynamicHeapArray<u8>> data = FileSystem::ReadBinaryFile(filename.c_str());
HRESULT hr = HRESULT hr =
m_device->CreatePipelineLibrary(data.has_value() ? data->data() : nullptr, data.has_value() ? data->size() : 0, m_device->CreatePipelineLibrary(data.has_value() ? data->data() : nullptr, data.has_value() ? data->size() : 0,

View file

@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com> // SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) // SPDX-License-Identifier: (GPL-3.0 OR PolyForm-Strict-1.0.0)
#pragma once #pragma once

View file

@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com> // SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) // SPDX-License-Identifier: (GPL-3.0 OR PolyForm-Strict-1.0.0)
#include "d3d12_pipeline.h" #include "d3d12_pipeline.h"
#include "d3d12_builders.h" #include "d3d12_builders.h"

View file

@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2019-2023 Connor McLaughlin <stenzek@gmail.com> // SPDX-FileCopyrightText: 2019-2023 Connor McLaughlin <stenzek@gmail.com>
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) // SPDX-License-Identifier: (GPL-3.0 OR PolyForm-Strict-1.0.0)
#include "gpu_device.h" #include "gpu_device.h"

View file

@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com> // SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) // SPDX-License-Identifier: (GPL-3.0 OR PolyForm-Strict-1.0.0)
#include "d3d12_stream_buffer.h" #include "d3d12_stream_buffer.h"
#include "d3d12_device.h" #include "d3d12_device.h"

View file

@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com> // SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) // SPDX-License-Identifier: (GPL-3.0 OR PolyForm-Strict-1.0.0)
#pragma once #pragma once

View file

@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com> // SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) // SPDX-License-Identifier: (GPL-3.0 OR PolyForm-Strict-1.0.0)
#include "d3d12_texture.h" #include "d3d12_texture.h"
#include "d3d12_builders.h" #include "d3d12_builders.h"

View file

@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com> // SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) // SPDX-License-Identifier: (GPL-3.0 OR PolyForm-Strict-1.0.0)
#pragma once #pragma once

View file

@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com> // SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) // SPDX-License-Identifier: (GPL-3.0 OR PolyForm-Strict-1.0.0)
#include "d3d_common.h" #include "d3d_common.h"
#include "gpu_device.h" #include "gpu_device.h"

View file

@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com> // SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) // SPDX-License-Identifier: (GPL-3.0 OR PolyForm-Strict-1.0.0)
#pragma once #pragma once

View file

@ -1,8 +1,10 @@
// SPDX-FileCopyrightText: 2019-2023 Connor McLaughlin <stenzek@gmail.com> // SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) // SPDX-License-Identifier: (GPL-3.0 OR PolyForm-Strict-1.0.0)
#pragma once #pragma once
#include "common/assert.h"
#include "gpu_device.h" #include "gpu_device.h"
#include "gpu_texture.h" #include "gpu_texture.h"

View file

@ -1,10 +1,11 @@
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com> // SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) // SPDX-License-Identifier: (GPL-3.0 OR PolyForm-Strict-1.0.0)
#include "gpu_texture.h" #include "gpu_texture.h"
#include "gpu_device.h" #include "gpu_device.h"
#include "common/align.h" #include "common/align.h"
#include "common/assert.h"
#include "common/bitutils.h" #include "common/bitutils.h"
#include "common/log.h" #include "common/log.h"
#include "common/string_util.h" #include "common/string_util.h"

View file

@ -1,15 +1,15 @@
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com> // SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) // SPDX-License-Identifier: (GPL-3.0 OR PolyForm-Strict-1.0.0)
#pragma once #pragma once
#include "common/types.h" #include "common/types.h"
#include "common/heap_array.h"
#include <ctime> #include <ctime>
#include <optional> #include <optional>
#include <string> #include <string>
#include <string_view> #include <string_view>
#include <vector>
namespace Host { namespace Host {
/// Returns true if the specified resource file exists. /// Returns true if the specified resource file exists.
@ -17,7 +17,7 @@ bool ResourceFileExists(std::string_view filename, bool allow_override);
/// Reads a file from the resources directory of the application. /// Reads a file from the resources directory of the application.
/// This may be outside of the "normal" filesystem on platforms such as Mac. /// This may be outside of the "normal" filesystem on platforms such as Mac.
std::optional<std::vector<u8>> ReadResourceFile(std::string_view filename, bool allow_override); std::optional<DynamicHeapArray<u8>> ReadResourceFile(std::string_view filename, bool allow_override);
/// Reads a resource file file from the resources directory as a string. /// Reads a resource file file from the resources directory as a string.
std::optional<std::string> ReadResourceFileToString(std::string_view filename, bool allow_override); std::optional<std::string> ReadResourceFileToString(std::string_view filename, bool allow_override);

View file

@ -1,8 +1,9 @@
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com> // SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) // SPDX-License-Identifier: (GPL-3.0 OR PolyForm-Strict-1.0.0)
#include "image.h" #include "image.h"
#include "common/assert.h"
#include "common/bitutils.h" #include "common/bitutils.h"
#include "common/fastjmp.h" #include "common/fastjmp.h"
#include "common/file_system.h" #include "common/file_system.h"
@ -518,7 +519,7 @@ static bool WrapJPEGDecompress(RGBA8Image* image, T setup_func)
bool JPEGBufferLoader(RGBA8Image* image, const void* buffer, size_t buffer_size) bool JPEGBufferLoader(RGBA8Image* image, const void* buffer, size_t buffer_size)
{ {
return WrapJPEGDecompress(image, [buffer, buffer_size](jpeg_decompress_struct& info) { return WrapJPEGDecompress(image, [buffer, buffer_size](jpeg_decompress_struct& info) {
jpeg_mem_src(&info, static_cast<const unsigned char*>(buffer), buffer_size); jpeg_mem_src(&info, static_cast<const unsigned char*>(buffer), static_cast<unsigned long>(buffer_size));
}); });
} }
@ -763,7 +764,7 @@ bool WebPBufferSaver(const RGBA8Image& image, std::vector<u8>* buffer, u8 qualit
bool WebPFileLoader(RGBA8Image* image, std::string_view filename, std::FILE* fp) bool WebPFileLoader(RGBA8Image* image, std::string_view filename, std::FILE* fp)
{ {
std::optional<std::vector<u8>> data = FileSystem::ReadBinaryFile(fp); std::optional<DynamicHeapArray<u8>> data = FileSystem::ReadBinaryFile(fp);
if (!data.has_value()) if (!data.has_value())
return false; return false;

View file

@ -1,9 +1,8 @@
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com> // SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) // SPDX-License-Identifier: (GPL-3.0 OR PolyForm-Strict-1.0.0)
#pragma once #pragma once
#include "common/assert.h"
#include "common/types.h" #include "common/types.h"
#include <algorithm> #include <algorithm>

View file

@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com> // SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) // SPDX-License-Identifier: (GPL-3.0 OR PolyForm-Strict-1.0.0)
#include "imgui_fullscreen.h" #include "imgui_fullscreen.h"
#include "gpu_device.h" #include "gpu_device.h"
@ -315,7 +315,7 @@ std::optional<RGBA8Image> ImGuiFullscreen::LoadTextureImage(std::string_view pat
} }
else else
{ {
std::optional<std::vector<u8>> data = Host::ReadResourceFile(path, true); std::optional<DynamicHeapArray<u8>> data = Host::ReadResourceFile(path, true);
if (data.has_value()) if (data.has_value())
{ {
image = RGBA8Image(); image = RGBA8Image();

View file

@ -86,10 +86,10 @@ static ImFont* s_fixed_font;
static ImFont* s_medium_font; static ImFont* s_medium_font;
static ImFont* s_large_font; static ImFont* s_large_font;
static std::vector<u8> s_standard_font_data; static DynamicHeapArray<u8> s_standard_font_data;
static std::vector<u8> s_fixed_font_data; static DynamicHeapArray<u8> s_fixed_font_data;
static std::vector<u8> s_icon_fa_font_data; static DynamicHeapArray<u8> s_icon_fa_font_data;
static std::vector<u8> s_icon_pf_font_data; static DynamicHeapArray<u8> s_icon_pf_font_data;
static float s_window_width; static float s_window_width;
static float s_window_height; static float s_window_height;
@ -482,9 +482,9 @@ bool ImGuiManager::LoadFontData()
{ {
if (s_standard_font_data.empty()) if (s_standard_font_data.empty())
{ {
std::optional<std::vector<u8>> font_data = s_font_path.empty() ? std::optional<DynamicHeapArray<u8>> font_data = s_font_path.empty() ?
Host::ReadResourceFile("fonts/Roboto-Regular.ttf", true) : Host::ReadResourceFile("fonts/Roboto-Regular.ttf", true) :
FileSystem::ReadBinaryFile(s_font_path.c_str()); FileSystem::ReadBinaryFile(s_font_path.c_str());
if (!font_data.has_value()) if (!font_data.has_value())
return false; return false;
@ -493,7 +493,7 @@ bool ImGuiManager::LoadFontData()
if (s_fixed_font_data.empty()) if (s_fixed_font_data.empty())
{ {
std::optional<std::vector<u8>> font_data = Host::ReadResourceFile("fonts/RobotoMono-Medium.ttf", true); std::optional<DynamicHeapArray<u8>> font_data = Host::ReadResourceFile("fonts/RobotoMono-Medium.ttf", true);
if (!font_data.has_value()) if (!font_data.has_value())
return false; return false;
@ -502,7 +502,7 @@ bool ImGuiManager::LoadFontData()
if (s_icon_fa_font_data.empty()) if (s_icon_fa_font_data.empty())
{ {
std::optional<std::vector<u8>> font_data = Host::ReadResourceFile("fonts/fa-solid-900.ttf", true); std::optional<DynamicHeapArray<u8>> font_data = Host::ReadResourceFile("fonts/fa-solid-900.ttf", true);
if (!font_data.has_value()) if (!font_data.has_value())
return false; return false;
@ -511,7 +511,7 @@ bool ImGuiManager::LoadFontData()
if (s_icon_pf_font_data.empty()) if (s_icon_pf_font_data.empty())
{ {
std::optional<std::vector<u8>> font_data = Host::ReadResourceFile("fonts/promptfont.otf", true); std::optional<DynamicHeapArray<u8>> font_data = Host::ReadResourceFile("fonts/promptfont.otf", true);
if (!font_data.has_value()) if (!font_data.has_value())
return false; return false;

View file

@ -1,11 +1,12 @@
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com> // SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) // SPDX-License-Identifier: (GPL-3.0 OR PolyForm-Strict-1.0.0)
#include "media_capture.h" #include "media_capture.h"
#include "gpu_device.h" #include "gpu_device.h"
#include "host.h" #include "host.h"
#include "common/align.h" #include "common/align.h"
#include "common/assert.h"
#include "common/dynamic_library.h" #include "common/dynamic_library.h"
#include "common/error.h" #include "common/error.h"
#include "common/file_system.h" #include "common/file_system.h"

View file

@ -1108,7 +1108,7 @@ bool PostProcessing::ReShadeFXShader::CreatePasses(GPUTexture::Format backbuffer
{ {
// Might be a base file/resource instead. // Might be a base file/resource instead.
const std::string resource_name = Path::Combine("shaders/reshade/Textures", source); const std::string resource_name = Path::Combine("shaders/reshade/Textures", source);
if (std::optional<std::vector<u8>> resdata = Host::ReadResourceFile(resource_name.c_str(), true); if (std::optional<DynamicHeapArray<u8>> resdata = Host::ReadResourceFile(resource_name.c_str(), true);
!resdata.has_value() || !image.LoadFromBuffer(resource_name.c_str(), resdata->data(), resdata->size())) !resdata.has_value() || !image.LoadFromBuffer(resource_name.c_str(), resdata->data(), resdata->size()))
{ {
Error::SetString(error, fmt::format("Failed to load image '{}' (from '{}')", source, image_path).c_str()); Error::SetString(error, fmt::format("Failed to load image '{}' (from '{}')", source, image_path).c_str());

View file

@ -2244,7 +2244,7 @@ void VulkanDevice::FillPipelineCacheHeader(VK_PIPELINE_CACHE_HEADER* header)
bool VulkanDevice::ReadPipelineCache(const std::string& filename) bool VulkanDevice::ReadPipelineCache(const std::string& filename)
{ {
std::optional<std::vector<u8>> data; std::optional<DynamicHeapArray<u8>> data;
auto fp = FileSystem::OpenManagedCFile(filename.c_str(), "rb"); auto fp = FileSystem::OpenManagedCFile(filename.c_str(), "rb");
if (fp) if (fp)