mirror of
https://github.com/LNH-team/pico-launcher.git
synced 2026-09-18 13:12:33 +02:00
Add support for custom BMP icons and custom NDS banners for games and folders. Closes #53 and Closes #62
This commit is contained in:
65
arm9/source/romBrowser/IconRepository.cpp
Normal file
65
arm9/source/romBrowser/IconRepository.cpp
Normal file
@@ -0,0 +1,65 @@
|
||||
#include "common.h"
|
||||
#include <string.h>
|
||||
#include "core/mini-printf.h"
|
||||
#include "fat/Directory.h"
|
||||
#include "FileType/NullFileTypeProvider.h"
|
||||
#include "FileType/BmpFileIconData.h"
|
||||
#include "SdFolderFactory.h"
|
||||
#include "IconRepository.h"
|
||||
|
||||
void IconRepository::Initialize()
|
||||
{
|
||||
InitializeFolders("/_pico/icons/");
|
||||
}
|
||||
|
||||
SharedPtr<BmpFileIconData> IconRepository::GetIconForFile(const FileInfo& fileInfo, const char* gameCode) const
|
||||
{
|
||||
char nameBuffer[256];
|
||||
const auto& fileType = fileInfo.GetFileType();
|
||||
|
||||
if (fileType->GetClassification() == FileTypeClassification::Folder)
|
||||
{
|
||||
// Look for icon.bmp inside the folder (path relative to FatFs CWD = current browse dir).
|
||||
// Scan with the already-open directory handle so the match can be turned directly into a
|
||||
// FastFileRef, instead of stat'ing then re-opening the same path by name.
|
||||
Directory folderDir;
|
||||
if (folderDir.Open(fileInfo.GetFileName()) == FR_OK)
|
||||
{
|
||||
FILINFO folderFileInfo;
|
||||
while (folderDir.Read(&folderFileInfo) == FR_OK && folderFileInfo.fname[0] != 0)
|
||||
{
|
||||
if (!(folderFileInfo.fattrib & AM_DIR) && !strcasecmp(folderFileInfo.fname, "icon.bmp"))
|
||||
{
|
||||
return SharedPtr<BmpFileIconData>::MakeShared(
|
||||
FastFileRef(folderDir.GetFatFsDirectory(), &folderFileInfo));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const FileInfo* iconFile = nullptr;
|
||||
|
||||
// Try to get an icon based on the filename in the user folder
|
||||
if (_userFolder)
|
||||
{
|
||||
mini_snprintf(nameBuffer, sizeof(nameBuffer), "%s.bmp", fileInfo.GetFileName());
|
||||
iconFile = _userFolder->BinarySearch(nameBuffer);
|
||||
}
|
||||
|
||||
// Try to get an icon based on an internal game code
|
||||
if (!iconFile && gameCode)
|
||||
{
|
||||
const auto* iconFolder = GetFileTypeFolder(fileType->GetShortName());
|
||||
if (iconFolder)
|
||||
{
|
||||
mini_snprintf(nameBuffer, sizeof(nameBuffer), "%s.bmp", gameCode);
|
||||
iconFile = iconFolder->BinarySearch(nameBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
return iconFile
|
||||
? SharedPtr<BmpFileIconData>::MakeShared(iconFile->GetFastFileRef())
|
||||
: nullptr;
|
||||
}
|
||||
Reference in New Issue
Block a user