fix(native): custom emoji font crash

This commit is contained in:
rhunk 2024-05-30 19:42:30 +02:00
parent 07282e7b48
commit 5d5a067319
2 changed files with 11 additions and 3 deletions

View File

@ -16,7 +16,9 @@ fun FileHandleManager.getFileHandleLocalPath(
fileUniqueIdentifier: String,
): String? {
return getFileHandle(scope.key, name)?.open(ParcelFileDescriptor.MODE_READ_ONLY)?.use { pfd ->
val cacheFile = context.androidContext.cacheDir.resolve((fileUniqueIdentifier + Build.FINGERPRINT).longHashCode().absoluteValue.toString(16))
val cacheFile = context.androidContext.cacheDir.also {
it.mkdirs()
}.resolve((fileUniqueIdentifier + Build.FINGERPRINT).longHashCode().absoluteValue.toString(16))
if (!cacheFile.exists() || pfd.statSize != cacheFile.length()) {
FileOutputStream(cacheFile).use { output ->
ParcelFileDescriptor.AutoCloseInputStream(pfd).use { input ->

View File

@ -1,9 +1,15 @@
#pragma once
#include <sys/stat.h>
namespace CustomEmojiFont {
HOOK_DEF(int, open_hook, const char *pathname, int flags, mode_t mode) {
if (strstr(pathname, "/system/fonts/NotoColorEmoji.ttf") != 0 && common::native_config->custom_emoji_font_path[0] != 0) {
pathname = common::native_config->custom_emoji_font_path;
auto custom_path = common::native_config->custom_emoji_font_path;
if (strstr(pathname, "/system/fonts/NotoColorEmoji.ttf") != 0 && custom_path[0] != 0) {
struct stat buffer;
if (stat(custom_path, &buffer) == 0) {
pathname = custom_path;
}
}
return open_hook_original(pathname, flags, mode);
}