Skip to content

Commit

Permalink
Remove dlopen bootstrap
Browse files Browse the repository at this point in the history
  • Loading branch information
Fernthedev committed Nov 12, 2023
1 parent abfdba3 commit 07bf8c5
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 74 deletions.
9 changes: 1 addition & 8 deletions qpm.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"info": {
"name": "Paper",
"id": "paper",
"version": "1.2.14",
"version": "3.0.0",
"url": "https://github.com/Fernthedev/paperlog",
"additionalData": {
"overrideSoName": "libpaperlog.so",
Expand All @@ -23,13 +23,6 @@
"id": "fmt",
"versionRange": "^10.0.0",
"additionalData": {}
},
{
"id": "scotland2",
"versionRange": "^0.1.2",
"additionalData": {
"private": true
}
}
]
}
25 changes: 3 additions & 22 deletions qpm.shared.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
"info": {
"name": "Paper",
"id": "paper",
"version": "1.2.14",
"version": "3.0.0",
"url": "https://github.com/Fernthedev/paperlog",
"additionalData": {
"overrideSoName": "libpaperlog.so"
"overrideSoName": "libpaperlog.so",
"cmake": true
}
},
"workspace": {
Expand All @@ -23,30 +24,10 @@
"id": "fmt",
"versionRange": "^10.0.0",
"additionalData": {}
},
{
"id": "scotland2",
"versionRange": "^0.1.2",
"additionalData": {
"private": true
}
}
]
},
"restoredDependencies": [
{
"dependency": {
"id": "scotland2",
"versionRange": "=0.1.2",
"additionalData": {
"soLink": "https://github.com/sc2ad/scotland2/releases/download/v0.1.2/libsl2.so",
"debugSoLink": "https://github.com/sc2ad/scotland2/releases/download/v0.1.2/debug_libsl2.so",
"overrideSoName": "libsl2.so",
"branchName": "version/v0_1_2"
}
},
"version": "0.1.2"
},
{
"dependency": {
"id": "fmt",
Expand Down
4 changes: 0 additions & 4 deletions shared/_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,3 @@
#warning Removing quest modloader dependency
#endif

#if defined(PAPER_QUEST_MODLOADER) || defined(PAPER_QUEST_SCOTLAND2)
#define PAPER_NO_INIT
// TODO: Add some more potentially specific includes here
#endif
5 changes: 2 additions & 3 deletions shared/logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,9 @@ inline auto Backtrace(uint16_t frameCount) {

std::filesystem::path getLogDirectoryPathGlobal();

#ifndef PAPER_NO_INIT
void Init(std::string_view logPath, LoggerConfig const& config = {});
void Init(std::string_view logPath);
void Init(std::string_view logPath, LoggerConfig const& config);
bool IsInited();
#endif

void RegisterFileContextId(std::string_view contextId, std::string_view logPath);

Expand Down
46 changes: 9 additions & 37 deletions src/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#include <unwind.h>

#define HAS_UNWIND
#else
#warning No unwind support, backtraces will do nothing
#endif


Expand Down Expand Up @@ -141,8 +143,12 @@ inline void writeLog(Paper::ThreadData const& threadData, std::tm const& time, s

#pragma region LoggerImpl

namespace Paper::Logger {
void Init(std::string_view logPath, LoggerConfig const& config) {
void Paper::Logger::Init(std::string_view logPath) {
LoggerConfig config{};
return Init(logPath, config);
}

void Paper::Logger::Init(std::string_view logPath, LoggerConfig const& config) {
if (inited) {
throw std::runtime_error("Already started the logger thread!");
}
Expand All @@ -162,44 +168,14 @@ void Init(std::string_view logPath, LoggerConfig const& config) {
inited = true;
}

bool IsInited() {
bool Paper::Logger::IsInited() {
return inited;
}

} // namespace Paper::Logger

#pragma endregion

#pragma region Internal

// TODO: Fix constructor memory crash
#ifdef PAPER_NO_INIT
#warning Using dlopen for initializing thread
void __attribute__((constructor(1000))) dlopen_initialize() {
WriteStdOut(ANDROID_LOG_INFO, "PAPERLOG", "DLOpen initializing");

#ifdef PAPER_QUEST_MODLOADER
std::string path = fmt::format("/sdcard/Android/data/{}/files/logs/paper", Modloader::getApplicationId());
#elif defined(PAPER_QUEST_SCOTLAND2)
std::string path = fmt::format("/sdcard/Android/data/{}/files/logs/paper", modloader::get_application_id());
#else
#warning "Must have a definition for globalLogPath if PAPER_NO_INIT is defined!
std::string path(globalLogPath);
#endif
try {
Paper::Logger::Init(path, Paper::LoggerConfig());
} catch (std::exception const& e) {
std::string error = fmt::format("Error occurred in logging thread! {}", e.what());
WriteStdOut(ANDROID_LOG_ERROR, "PAPERLOG", error);
throw e;
} catch (...) {
std::string error = fmt::format("Error occurred in logging thread!");
WriteStdOut(ANDROID_LOG_ERROR, "PAPERLOG", error);
throw;
}
}
#endif

void Paper::Internal::LogThread() {
try {
moodycamel::ConsumerToken token(Paper::Internal::logQueue);
Expand Down Expand Up @@ -340,16 +316,12 @@ void Paper::Internal::LogThread() {
} catch (std::exception const& e) {
std::string error = fmt::format("Error occurred in logging thread! {}", e.what());
logError(error);
#ifndef PAPER_NO_INIT
inited = false;
#endif
throw e;
} catch (...) {
std::string error = fmt::format("Error occurred in logging thread!");
logError(error);
#ifndef PAPER_NO_INIT
inited = false;
#endif
throw;
}

Expand Down

0 comments on commit 07bf8c5

Please sign in to comment.