add the logcat writer

This commit is contained in:
altalk23 2023-10-15 16:43:21 +03:00
parent cd012df57e
commit 57a475b3b7
3 changed files with 20 additions and 1 deletions

View file

@ -3,7 +3,7 @@
using namespace geode::prelude;
static std::string getDateString(bool filesafe) {
std::string crashlog::getDateString(bool filesafe) {
auto const now = std::time(nullptr);
auto const tm = *std::localtime(&now);
std::ostringstream oss;

View file

@ -26,4 +26,6 @@ namespace crashlog {
ghc::filesystem::path GEODE_DLL getCrashLogDirectory();
std::string GEODE_DLL writeCrashlog(geode::Mod* faultyMod, std::string const& info, std::string const& stacktrace, std::string const& registers);
std::string getDateString(bool filesafe);
}

View file

@ -15,6 +15,10 @@ using namespace geode::prelude;
#include <link.h>
#include <unwind.h>
#include <jni.h>
#include <Geode/cocos/platform/android/jni/JniHelper.h>
#include "backtrace/execinfo.hpp"
static constexpr size_t FRAME_SIZE = 64;
@ -413,6 +417,19 @@ ghc::filesystem::path crashlog::getCrashLogDirectory() {
}
bool crashlog::setupPlatformHandler() {
auto path = crashlog::getCrashLogDirectory() / (getDateString(true) + ".log");
JniMethodInfo t;
if (JniHelper::getStaticMethodInfo(t, "com/geode/launcher/utils/GeodeUtils", "writeLogcatCrashBuffer", "(Ljava/lang/String;)Z")) {
jstring stringArg1 = t.env->NewStringUTF(path.string().c_str());
jboolean result = t.env->CallStaticBooleanMethod(t.classID, t.methodID, stringArg1);
t.env->DeleteLocalRef(stringArg1);
t.env->DeleteLocalRef(t.classID);
return result;
}
return false;
}