mirror of
https://github.com/LNH-team/pico-loader.git
synced 2026-01-10 08:29:29 +01:00
24 lines
797 B
C++
24 lines
797 B
C++
#include "common.h"
|
|
#include "SaveListFactory.h"
|
|
|
|
SaveList* SaveListFactory::CreateFromFile(const TCHAR *path)
|
|
{
|
|
FIL file;
|
|
if (f_open(&file, path, FA_OPEN_EXISTING | FA_READ) != FR_OK)
|
|
{
|
|
LOG_FATAL("Failed to open save list file\n");
|
|
return nullptr;
|
|
}
|
|
const u32 entryCount = f_size(&file) / sizeof(SaveListEntry);
|
|
auto entries = std::make_unique_for_overwrite<SaveListEntry[]>(entryCount);
|
|
UINT bytesRead = 0;
|
|
FRESULT result = f_read(&file, entries.get(), entryCount * sizeof(SaveListEntry), &bytesRead);
|
|
if (result != FR_OK || bytesRead != entryCount * sizeof(SaveListEntry))
|
|
{
|
|
LOG_FATAL("Failed to read save list file\n");
|
|
return nullptr;
|
|
}
|
|
f_close(&file);
|
|
|
|
return new SaveList(std::move(entries), entryCount);
|
|
} |