Play-/tools/PsfPlayer/Source/ui_js/Main.cpp

112 lines
2.6 KiB
C++
Raw Normal View History

2021-10-28 15:38:10 -04:00
#include "PsfVmJs.h"
2021-09-02 14:02:13 -04:00
#include <cstdio>
#include "filesystem_def.h"
#include "PsfArchive.h"
#include "PsfStreamProvider.h"
#include "SH_OpenALProxy.h"
2021-09-02 14:02:13 -04:00
#include "SH_FileOutput.h"
2021-09-14 09:45:20 -04:00
#include "../SH_OpenAL.h"
#include <emscripten/bind.h>
2021-09-02 14:02:13 -04:00
2021-10-28 15:38:10 -04:00
CPsfVmJs* g_virtualMachine = nullptr;
CSH_OpenAL* g_soundHandler = nullptr;
2021-09-22 11:26:06 -04:00
CPsfBase::TagMap g_tags;
2021-09-02 14:02:13 -04:00
int main(int argc, const char** argv)
{
2025-02-08 20:25:05 -05:00
printf("PsfPlayer - Version %s\r\n", PLAY_VERSION);
2021-09-02 14:02:13 -04:00
return 0;
}
extern "C" void initVm()
{
try
{
2021-10-28 15:38:10 -04:00
g_virtualMachine = new CPsfVmJs();
2021-09-02 14:02:13 -04:00
2021-10-21 13:16:02 -04:00
//g_soundHandler = new CSH_FileOutput();
g_soundHandler = new CSH_OpenAL();
2021-10-28 15:38:10 -04:00
g_virtualMachine->SetSpuHandler(CSH_OpenALProxy::GetFactoryFunction(g_soundHandler));
2021-09-02 14:02:13 -04:00
}
catch(const std::exception& ex)
{
printf("Exception: %s\r\n", ex.what());
}
}
void resumePsf()
2021-09-02 14:02:13 -04:00
{
assert(g_virtualMachine);
g_virtualMachine->Resume();
}
void pausePsf()
{
assert(g_virtualMachine);
g_virtualMachine->Pause();
}
void loadPsf(std::string archivePath, std::string psfPath)
{
printf("Loading '%s' from '%s'.\r\n", psfPath.c_str(), archivePath.c_str());
2021-09-02 14:02:13 -04:00
try
{
assert(g_virtualMachine);
g_virtualMachine->Pause();
2021-10-28 15:38:10 -04:00
g_tags = g_virtualMachine->LoadPsf(archivePath, psfPath);
2021-09-02 14:02:13 -04:00
}
catch(const std::exception& ex)
{
printf("Exception: %s\r\n", ex.what());
}
}
std::vector<std::string> getPsfArchiveFileList(std::string rawArchivePath)
{
std::vector<std::string> result;
try
{
fs::path archivePath(rawArchivePath);
auto archive = std::unique_ptr<CPsfArchive>(CPsfArchive::CreateFromPath(archivePath));
auto files = archive->GetFiles();
for(const auto& file : files)
{
result.push_back(file.name);
}
}
catch(const std::exception& ex)
{
printf("Exception: %s\r\n", ex.what());
}
return result;
}
CPsfBase::TagMap getPsfArchiveItemTags(std::string rawArchivePath, std::string psfPath)
{
fs::path archivePath(rawArchivePath);
auto streamProvider = CreatePsfStreamProvider(archivePath);
std::unique_ptr<Framework::CStream> inputStream(streamProvider->GetStreamForPath(psfPath));
CPsfBase psfFile(*inputStream);
return CPsfBase::TagMap(psfFile.GetTagsBegin(), psfFile.GetTagsEnd());
}
2021-09-22 11:26:06 -04:00
CPsfBase::TagMap getCurrentPsfTags()
{
return g_tags;
}
EMSCRIPTEN_BINDINGS(PsfPlayer)
{
using namespace emscripten;
register_vector<std::string>("StringList");
2021-09-22 11:26:06 -04:00
register_map<std::string, std::string>("StringMap");
function("pausePsf", &pausePsf);
function("resumePsf", &resumePsf);
function("loadPsf", &loadPsf);
function("getPsfArchiveFileList", &getPsfArchiveFileList);
function("getPsfArchiveItemTags", &getPsfArchiveItemTags);
2021-09-22 11:26:06 -04:00
function("getCurrentPsfTags", &getCurrentPsfTags);
}