Skip to content

Commit

Permalink
Misc updates and a fix
Browse files Browse the repository at this point in the history
* Imagine: Properly catch exception in DocumentsContract.buildChildDocumentsUriUsingTree()
* Imagine: Add/Update ArchiveFS utility functions
* MSX.emu: Add option to select a default Coleco machine type when loading .col files
* MSX.emu: Add support for loading BIOS directly from an archive file
  • Loading branch information
Robert Broglia committed Dec 26, 2023
1 parent 10de9bc commit 3e17f15
Show file tree
Hide file tree
Showing 12 changed files with 391 additions and 245 deletions.
4 changes: 2 additions & 2 deletions C64.emu/src/main/EmuMenuViews.cc
Original file line number Diff line number Diff line change
Expand Up @@ -329,14 +329,14 @@ class CustomFilePathOptionView : public FilePathOptionView, public MainAppHelper
const auto &sysFilePath = system().sysFilePath;
if(type == FS::file_type::none && sysFilePath.size() > 1)
{
system().setSystemFilesPath(appContext(), path, type);
system().setSystemFilesPath(path, type);
app().postMessage(5, false, std::format("Using fallback paths:\n{}\n{}", sysFilePath[1], sysFilePath[2]));
}
else
{
try
{
system().setSystemFilesPath(appContext(), path, type);
system().setSystemFilesPath(path, type);
}
catch(std::exception &err)
{
Expand Down
6 changes: 3 additions & 3 deletions C64.emu/src/main/MainSystem.hh
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public:
struct video_canvas_s *activeCanvas{};
const char *sysFileDir{};
VicePlugin plugin{};
mutable FS::ArchiveIterator viceSysFilesArchiveIt;
mutable FS::ArchiveIterator firmwareArchiveIt;
std::string defaultPaletteName{};
std::string lastMissingSysFile;
IG::PixmapView canvasSrcPix{};
Expand Down Expand Up @@ -184,8 +184,8 @@ public:
bool currSystemIsC64Or128() const;
void setRuntimeReuSize(int size);
void resetCanvasSourcePixmap(struct video_canvas_s *c);
FS::ArchiveIterator &systemFilesArchiveIterator(ApplicationContext, std::string_view path) const;
void setSystemFilesPath(ApplicationContext, CStringView path, FS::file_type);
FS::ArchiveIterator &firmwareArchiveIterator(CStringView path) const;
void setSystemFilesPath(CStringView path, FS::file_type);
void execC64Frame();

// required API functions
Expand Down
38 changes: 15 additions & 23 deletions C64.emu/src/main/sysfile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ static ArchiveIO *archiveIOForSysFile(C64System &system, IG::CStringView archive
auto sysFilePath = FS::pathString(subPath, sysFileName);
try
{
for(auto &entry : system.systemFilesArchiveIterator(gAppContext(), archivePath))
for(auto &entry : system.firmwareArchiveIterator(archivePath))
{
if(entry.type() == FS::file_type::directory)
{
Expand Down Expand Up @@ -123,62 +123,54 @@ static AssetIO assetIOForSysFile(IG::ApplicationContext ctx, std::string_view sy
return file;
}

FS::ArchiveIterator &C64System::systemFilesArchiveIterator(ApplicationContext ctx, std::string_view path) const
FS::ArchiveIterator &C64System::firmwareArchiveIterator(CStringView path) const
{
if(!viceSysFilesArchiveIt.hasArchive())
if(!firmwareArchiveIt.hasArchive())
{
log.info("{} not cached, opening archive", path);
viceSysFilesArchiveIt = {ctx.openFileUri(path)};
firmwareArchiveIt = {appContext().openFileUri(path)};
}
else
{
viceSysFilesArchiveIt.rewind();
firmwareArchiveIt.rewind();
}
return viceSysFilesArchiveIt;
return firmwareArchiveIt;
}

static bool archiveHasDirectory(ApplicationContext ctx, CStringView path, std::string_view dirName)
static bool archiveHasDrivesDirectory(ApplicationContext ctx, CStringView path)
{
for(auto &entry : FS::ArchiveIterator{ctx.openFileUri(path)})
{
if(entry.type() == FS::file_type::directory &&
entry.name().ends_with(dirName))
{
return true;
}
}
return false;
return bool(FS::findDirectoryInArchive(ctx.openFileUri(path), [&](auto &entry){ return entry.name().ends_with("DRIVES/"); }));
}

void C64System::setSystemFilesPath(ApplicationContext ctx, CStringView path, FS::file_type type)
void C64System::setSystemFilesPath(CStringView path, FS::file_type type)
{
auto ctx = appContext();
log.info("set firmware path:{}", path);
if((type == FS::file_type::directory && !ctx.fileUriExists(FS::uriString(path, "DRIVES")))
|| (EmuApp::hasArchiveExtension(path) && !archiveHasDirectory(ctx, path, "DRIVES/")))
|| (FS::hasArchiveExtension(path) && !archiveHasDrivesDirectory(ctx, path)))
{
throw std::runtime_error{"Path is missing DRIVES folder"};
}
sysFilePath[0] = path;
viceSysFilesArchiveIt = {};
firmwareArchiveIt = {};
}

std::vector<std::string> C64System::systemFilesWithExtension(const char *ext) const
{
logMsg("looking for system files with extension:%s", ext);
auto appContext = gAppContext();
std::vector<std::string> filenames{};
try
{
for(const auto &basePath : sysFilePath)
{
if(basePath.empty())
continue;
auto displayName = appContext.fileUriDisplayName(basePath);
auto displayName = appContext().fileUriDisplayName(basePath);
if(displayName.empty())
continue;
if(EmuApp::hasArchiveExtension(displayName))
{
for(auto &entry : systemFilesArchiveIterator(appContext, basePath))
for(auto &entry : firmwareArchiveIterator(basePath))
{
if(entry.type() == FS::file_type::directory)
{
Expand All @@ -196,7 +188,7 @@ std::vector<std::string> C64System::systemFilesWithExtension(const char *ext) co
}
else
{
appContext.forEachInDirectoryUri(FS::uriString(basePath, sysFileDir),
appContext().forEachInDirectoryUri(FS::uriString(basePath, sysFileDir),
[&filenames, ext](auto &entry)
{
auto name = entry.name();
Expand Down

0 comments on commit 3e17f15

Please sign in to comment.