From 57a475b3b78ea6bff5e3ec38f11ce35f753b5ddf Mon Sep 17 00:00:00 2001 From: altalk23 <45172705+altalk23@users.noreply.github.com> Date: Sun, 15 Oct 2023 16:43:21 +0300 Subject: [PATCH] add the logcat writer --- loader/src/internal/crashlog.cpp | 2 +- loader/src/internal/crashlog.hpp | 2 ++ loader/src/platform/android/crashlog.cpp | 17 +++++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/loader/src/internal/crashlog.cpp b/loader/src/internal/crashlog.cpp index 7f698616c..76459efc8 100644 --- a/loader/src/internal/crashlog.cpp +++ b/loader/src/internal/crashlog.cpp @@ -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; diff --git a/loader/src/internal/crashlog.hpp b/loader/src/internal/crashlog.hpp index 4ed85293a..4590bbc3c 100644 --- a/loader/src/internal/crashlog.hpp +++ b/loader/src/internal/crashlog.hpp @@ -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); } diff --git a/loader/src/platform/android/crashlog.cpp b/loader/src/platform/android/crashlog.cpp index e1ed7bd9c..2ceac82ea 100644 --- a/loader/src/platform/android/crashlog.cpp +++ b/loader/src/platform/android/crashlog.cpp @@ -15,6 +15,10 @@ using namespace geode::prelude; #include #include + +#include +#include + #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; }