2017-11-17 18:48:56 -05:00
|
|
|
#include "../ui_shared/BootablesProcesses.h"
|
|
|
|
#include "../ui_shared/BootablesDbClient.h"
|
2023-11-09 13:58:32 +00:00
|
|
|
#include "DiskUtils.h"
|
2017-11-17 18:48:56 -05:00
|
|
|
#include "com_virtualapplications_play_Bootable.h"
|
|
|
|
#include "NativeShared.h"
|
|
|
|
|
2019-01-06 12:27:31 +00:00
|
|
|
void fullScan(JNIEnv* env, jobjectArray rootDirectories)
|
2019-01-06 00:14:08 +00:00
|
|
|
{
|
|
|
|
auto rootDirectoryCount = env->GetArrayLength(rootDirectories);
|
|
|
|
for(int i = 0; i < rootDirectoryCount; i++)
|
|
|
|
{
|
|
|
|
auto rootDirectoryString = static_cast<jstring>(env->GetObjectArrayElement(rootDirectories, i));
|
|
|
|
auto rootDirectory = GetStringFromJstring(env, rootDirectoryString);
|
|
|
|
ScanBootables(rootDirectory, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-23 09:25:31 -04:00
|
|
|
extern "C" JNIEXPORT void JNICALL Java_com_virtualapplications_play_BootablesInterop_scanBootables(JNIEnv* env, jclass clazz, jobjectArray rootDirectories)
|
2017-11-17 18:48:56 -05:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2017-11-24 18:31:04 -05:00
|
|
|
auto activeDirectories = GetActiveBootableDirectories();
|
|
|
|
if(activeDirectories.empty())
|
|
|
|
{
|
2019-01-06 00:14:08 +00:00
|
|
|
fullScan(env, rootDirectories);
|
2017-11-24 18:31:04 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for(const auto& activeDirectory : activeDirectories)
|
|
|
|
{
|
|
|
|
ScanBootables(activeDirectory, false);
|
|
|
|
}
|
|
|
|
}
|
2017-11-17 18:48:56 -05:00
|
|
|
}
|
|
|
|
catch(const std::exception& exception)
|
|
|
|
{
|
2021-10-23 09:48:25 -04:00
|
|
|
Log_Error("Caught an exception: '%s'\r\n", exception.what());
|
2017-11-17 18:48:56 -05:00
|
|
|
}
|
2017-11-24 18:31:04 -05:00
|
|
|
FetchGameTitles();
|
2017-11-17 18:48:56 -05:00
|
|
|
}
|
|
|
|
|
2021-10-23 09:25:31 -04:00
|
|
|
extern "C" JNIEXPORT void JNICALL Java_com_virtualapplications_play_BootablesInterop_fullScanBootables(JNIEnv* env, jclass clazz, jobjectArray rootDirectories)
|
2019-01-06 00:14:08 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
fullScan(env, rootDirectories);
|
|
|
|
}
|
2019-01-06 12:27:31 +00:00
|
|
|
catch(const std::exception& exception)
|
2019-01-06 00:14:08 +00:00
|
|
|
{
|
2021-10-23 09:48:25 -04:00
|
|
|
Log_Error("Caught an exception in fullScan: '%s'\r\n", exception.what());
|
2019-01-06 00:14:08 +00:00
|
|
|
}
|
|
|
|
FetchGameTitles();
|
|
|
|
}
|
|
|
|
|
2021-10-23 09:25:31 -04:00
|
|
|
extern "C" JNIEXPORT jobjectArray Java_com_virtualapplications_play_BootablesInterop_getBootables(JNIEnv* env, jclass clazz, jint sortedMethod)
|
2017-11-17 18:48:56 -05:00
|
|
|
{
|
2021-10-23 09:48:25 -04:00
|
|
|
std::vector<BootablesDb::Bootable> bootables;
|
2018-08-29 13:53:51 -04:00
|
|
|
|
2021-10-23 09:48:25 -04:00
|
|
|
try
|
|
|
|
{
|
|
|
|
bootables = BootablesDb::CClient::GetInstance().GetBootables(sortedMethod);
|
|
|
|
}
|
|
|
|
catch(const std::exception& exception)
|
|
|
|
{
|
|
|
|
Log_Error("Caught an exception in GetBootables: '%s'\r\n", exception.what());
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto& bootableClassInfo = com::virtualapplications::play::Bootable_ClassInfo::GetInstance();
|
2017-11-17 18:48:56 -05:00
|
|
|
auto bootablesJ = env->NewObjectArray(bootables.size(), bootableClassInfo.clazz, NULL);
|
2018-08-29 13:53:51 -04:00
|
|
|
|
2017-11-17 18:48:56 -05:00
|
|
|
for(unsigned int i = 0; i < bootables.size(); i++)
|
|
|
|
{
|
|
|
|
const auto& bootable = bootables[i];
|
|
|
|
auto bootableJ = env->NewObject(bootableClassInfo.clazz, bootableClassInfo.init);
|
2018-08-29 13:53:51 -04:00
|
|
|
|
2017-11-17 18:48:56 -05:00
|
|
|
jstring pathString = env->NewStringUTF(bootable.path.string().c_str());
|
|
|
|
env->SetObjectField(bootableJ, bootableClassInfo.path, pathString);
|
2018-08-29 13:53:51 -04:00
|
|
|
|
2017-11-17 18:48:56 -05:00
|
|
|
jstring titleString = env->NewStringUTF(bootable.title.c_str());
|
|
|
|
env->SetObjectField(bootableJ, bootableClassInfo.title, titleString);
|
2018-08-29 13:53:51 -04:00
|
|
|
|
2017-11-30 11:29:13 -05:00
|
|
|
jstring coverUrlString = env->NewStringUTF(bootable.coverUrl.c_str());
|
|
|
|
env->SetObjectField(bootableJ, bootableClassInfo.coverUrl, coverUrlString);
|
2018-08-29 13:53:51 -04:00
|
|
|
|
2019-01-06 00:05:04 +00:00
|
|
|
jstring discIdString = env->NewStringUTF(bootable.discId.c_str());
|
|
|
|
env->SetObjectField(bootableJ, bootableClassInfo.discId, discIdString);
|
|
|
|
|
|
|
|
jstring overviewString = env->NewStringUTF(bootable.overview.c_str());
|
|
|
|
env->SetObjectField(bootableJ, bootableClassInfo.overview, overviewString);
|
|
|
|
|
2017-11-17 18:48:56 -05:00
|
|
|
env->SetObjectArrayElement(bootablesJ, i, bootableJ);
|
|
|
|
}
|
2018-08-29 13:53:51 -04:00
|
|
|
|
2017-11-17 18:48:56 -05:00
|
|
|
return bootablesJ;
|
|
|
|
}
|
|
|
|
|
2021-10-20 09:05:22 -04:00
|
|
|
extern "C" JNIEXPORT jboolean Java_com_virtualapplications_play_BootablesInterop_tryRegisterBootable(JNIEnv* env, jclass clazz, jstring bootablePathString)
|
2021-08-13 17:21:17 -04:00
|
|
|
{
|
|
|
|
auto bootablePath = fs::path(GetStringFromJstring(env, bootablePathString));
|
2021-10-20 09:05:22 -04:00
|
|
|
return TryRegisterBootable(bootablePath);
|
2021-08-13 17:21:17 -04:00
|
|
|
}
|
|
|
|
|
2021-10-23 09:25:31 -04:00
|
|
|
extern "C" JNIEXPORT void Java_com_virtualapplications_play_BootablesInterop_setLastBootedTime(JNIEnv* env, jclass clazz, jstring bootablePathString, jlong lastBootedTime)
|
2017-11-17 18:48:56 -05:00
|
|
|
{
|
2019-10-17 18:15:16 -04:00
|
|
|
auto bootablePath = fs::path(GetStringFromJstring(env, bootablePathString));
|
2017-11-17 18:48:56 -05:00
|
|
|
BootablesDb::CClient::GetInstance().SetLastBootedTime(bootablePath, lastBootedTime);
|
|
|
|
}
|
2019-01-06 03:09:05 +00:00
|
|
|
|
2021-10-23 09:25:31 -04:00
|
|
|
extern "C" JNIEXPORT jboolean Java_com_virtualapplications_play_BootablesInterop_IsBootableExecutablePath(JNIEnv* env, jclass clazz, jstring bootablePathString)
|
2021-08-04 13:47:28 -04:00
|
|
|
{
|
|
|
|
auto bootablePath = fs::path(GetStringFromJstring(env, bootablePathString));
|
2023-11-09 13:58:32 +00:00
|
|
|
return DiskUtils::IsBootableExecutablePath(bootablePath);
|
2021-08-04 13:47:28 -04:00
|
|
|
}
|
|
|
|
|
2021-10-23 09:25:31 -04:00
|
|
|
extern "C" JNIEXPORT jboolean Java_com_virtualapplications_play_BootablesInterop_DoesBootableExist(JNIEnv* env, jclass clazz, jstring bootablePathString)
|
2021-08-04 13:47:28 -04:00
|
|
|
{
|
|
|
|
auto bootablePath = fs::path(GetStringFromJstring(env, bootablePathString));
|
|
|
|
return DoesBootableExist(bootablePath);
|
|
|
|
}
|
|
|
|
|
2021-10-23 09:25:31 -04:00
|
|
|
extern "C" JNIEXPORT void Java_com_virtualapplications_play_BootablesInterop_UnregisterBootable(JNIEnv* env, jclass clazz, jstring bootablePathString)
|
2019-01-06 03:09:05 +00:00
|
|
|
{
|
2019-10-17 18:15:16 -04:00
|
|
|
auto bootablePath = fs::path(GetStringFromJstring(env, bootablePathString));
|
2019-01-06 03:09:05 +00:00
|
|
|
BootablesDb::CClient::GetInstance().UnregisterBootable(bootablePath);
|
|
|
|
}
|
|
|
|
|
2021-11-08 12:26:06 -05:00
|
|
|
extern "C" JNIEXPORT void Java_com_virtualapplications_play_BootablesInterop_fetchGameTitles(JNIEnv* env, jclass clazz)
|
|
|
|
{
|
|
|
|
FetchGameTitles();
|
|
|
|
}
|
|
|
|
|
2021-10-23 09:25:31 -04:00
|
|
|
extern "C" JNIEXPORT void Java_com_virtualapplications_play_BootablesInterop_PurgeInexistingFiles(JNIEnv* env, jclass clazz)
|
2019-01-06 03:09:05 +00:00
|
|
|
{
|
|
|
|
PurgeInexistingFiles();
|
|
|
|
}
|