44#include " base.h"
55#include " log.hpp"
66
7- DataPaths& DataPaths::get_instance () {
8- static auto paths_instance = DataPaths () ;
9- return paths_instance;
10- }
7+ std::string DataPaths::original_data_path{};
8+ std::string DataPaths::data_path{} ;
9+
10+ bool DataPaths::patch_exceptions{};
1111
1212extern " C"
1313JNIEXPORT void JNICALL Java_com_geode_launcher_LauncherFix_setDataPath (
@@ -18,25 +18,11 @@ JNIEXPORT void JNICALL Java_com_geode_launcher_LauncherFix_setDataPath(
1818 auto is_copy = jboolean ();
1919 auto data_path_str = env->GetStringUTFChars (data_path, &is_copy);
2020
21- DataPaths::get_instance (). data_path = std::string (data_path_str);
21+ DataPaths::data_path = std::string (data_path_str);
2222
2323 env->ReleaseStringUTFChars (data_path, data_path_str);
2424}
2525
26- extern " C"
27- JNIEXPORT void JNICALL Java_com_geode_launcher_LauncherFix_enableCustomSymbolList (
28- JNIEnv* env,
29- jobject,
30- jstring symbol_path
31- ) {
32- auto is_copy = jboolean ();
33- auto symbol_path_str = env->GetStringUTFChars (symbol_path, &is_copy);
34-
35- DataPaths::get_instance ().load_symbols_from = std::string (symbol_path_str);
36-
37- env->ReleaseStringUTFChars (symbol_path, symbol_path_str);
38- }
39-
4026extern " C"
4127JNIEXPORT void JNICALL Java_com_geode_launcher_LauncherFix_setOriginalDataPath (
4228 JNIEnv *env,
@@ -46,14 +32,14 @@ JNIEXPORT void JNICALL Java_com_geode_launcher_LauncherFix_setOriginalDataPath(
4632 auto is_copy = jboolean ();
4733 auto data_path_str = env->GetStringUTFChars (data_path, &is_copy);
4834
49- DataPaths::get_instance (). original_data_path = std::string (data_path_str);
35+ DataPaths::original_data_path = std::string (data_path_str);
5036
5137 env->ReleaseStringUTFChars (data_path, data_path_str);
5238}
5339
5440extern " C"
5541JNIEXPORT void JNICALL Java_com_geode_launcher_LauncherFix_enableExceptionsRenaming (JNIEnv*, jobject) {
56- DataPaths::get_instance (). patch_exceptions = true ;
42+ DataPaths::patch_exceptions = true ;
5743}
5844
5945// this should be called after gd is loaded but before geode
@@ -62,14 +48,24 @@ extern "C" JNIEXPORT void JNICALL Java_com_geode_launcher_LauncherFix_performPat
6248}
6349
6450std::optional<std::string> redirect_path (const char * pathname) {
65- std::string_view data_path = DataPaths::get_instance ().data_path ;
66- std::string_view original_data_path = DataPaths::get_instance ().original_data_path ;
67-
68- if (!data_path.empty () && !original_data_path.empty ()) {
69- // call this a c string optimization
70- if (std::strncmp (pathname, original_data_path.data (), original_data_path.size ()) == 0 ) {
71- return std::format (" {}{}" , data_path, (pathname + original_data_path.size ()));
72- }
51+ std::string_view data_path = DataPaths::data_path;
52+ std::string_view original_data_path = DataPaths::original_data_path;
53+
54+ if (data_path.empty () || original_data_path.empty ()) [[unlikely]] {
55+ return std::nullopt ;
56+ }
57+
58+ // call this a c string optimization
59+ if (std::strncmp (pathname, original_data_path.data (), original_data_path.size ()) == 0 ) {
60+ auto remaining_path = (pathname + original_data_path.size ());
61+ auto remaining_len = strlen (remaining_path);
62+
63+ std::string x;
64+ x.reserve (data_path.size () + remaining_len);
65+ x.append (data_path);
66+ x.append (remaining_path, remaining_len);
67+
68+ return x;
7369 }
7470
7571 return std::nullopt ;
0 commit comments