mirror of
https://github.com/DarkFlippers/unleashed-firmware.git
synced 2025-12-12 04:34:43 +04:00
NFC: Cache plugin name not full path, saves some RAM [ci skip]
by Willy-JL
This commit is contained in:
@@ -24,7 +24,7 @@ typedef enum {
|
||||
} NfcSupportedCardsPluginFeature;
|
||||
|
||||
typedef struct {
|
||||
FuriString* path;
|
||||
FuriString* name;
|
||||
NfcProtocol protocol;
|
||||
NfcSupportedCardsPluginFeature feature;
|
||||
} NfcSupportedCardsPluginCache;
|
||||
@@ -73,7 +73,7 @@ void nfc_supported_cards_free(NfcSupportedCards* instance) {
|
||||
!NfcSupportedCardsPluginCache_end_p(iter);
|
||||
NfcSupportedCardsPluginCache_next(iter)) {
|
||||
NfcSupportedCardsPluginCache* plugin_cache = NfcSupportedCardsPluginCache_ref(iter);
|
||||
furi_string_free(plugin_cache->path);
|
||||
furi_string_free(plugin_cache->name);
|
||||
}
|
||||
NfcSupportedCardsPluginCache_clear(instance->plugins_cache_arr);
|
||||
|
||||
@@ -111,16 +111,21 @@ static void nfc_supported_cards_load_context_free(NfcSupportedCardsLoadContext*
|
||||
|
||||
static const NfcSupportedCardsPlugin* nfc_supported_cards_get_plugin(
|
||||
NfcSupportedCardsLoadContext* instance,
|
||||
const FuriString* path,
|
||||
const char* name,
|
||||
const ElfApiInterface* api_interface) {
|
||||
furi_assert(instance);
|
||||
furi_assert(path);
|
||||
furi_assert(name);
|
||||
|
||||
const NfcSupportedCardsPlugin* plugin = NULL;
|
||||
do {
|
||||
if(instance->app) flipper_application_free(instance->app);
|
||||
instance->app = flipper_application_alloc(instance->storage, api_interface);
|
||||
if(flipper_application_preload(instance->app, furi_string_get_cstr(path)) !=
|
||||
|
||||
// Reconstruct path
|
||||
path_concat(NFC_SUPPORTED_CARDS_PLUGINS_PATH, name, instance->file_path);
|
||||
furi_string_cat(instance->file_path, NFC_SUPPORTED_CARDS_PLUGIN_SUFFIX);
|
||||
|
||||
if(flipper_application_preload(instance->app, furi_string_get_cstr(instance->file_path)) !=
|
||||
FlipperApplicationPreloadStatusSuccess)
|
||||
break;
|
||||
if(!flipper_application_is_plugin(instance->app)) break;
|
||||
@@ -155,9 +160,11 @@ static const NfcSupportedCardsPlugin* nfc_supported_cards_get_next_plugin(
|
||||
if(!furi_string_end_with_str(instance->file_path, NFC_SUPPORTED_CARDS_PLUGIN_SUFFIX))
|
||||
continue;
|
||||
|
||||
path_concat(NFC_SUPPORTED_CARDS_PLUGINS_PATH, instance->file_name, instance->file_path);
|
||||
size_t trim_suffix =
|
||||
furi_string_size(instance->file_path) - strlen(NFC_SUPPORTED_CARDS_PLUGIN_SUFFIX);
|
||||
instance->file_name[trim_suffix] = '\0';
|
||||
|
||||
plugin = nfc_supported_cards_get_plugin(instance, instance->file_path, api_interface);
|
||||
plugin = nfc_supported_cards_get_plugin(instance, instance->file_name, api_interface);
|
||||
} while(plugin == NULL); //-V654
|
||||
|
||||
return plugin;
|
||||
@@ -181,7 +188,7 @@ void nfc_supported_cards_load_cache(NfcSupportedCards* instance) {
|
||||
if(plugin == NULL) break; //-V547
|
||||
|
||||
NfcSupportedCardsPluginCache plugin_cache = {}; //-V779
|
||||
plugin_cache.path = furi_string_alloc_set(instance->load_context->file_path);
|
||||
plugin_cache.name = furi_string_alloc_set(instance->load_context->file_name);
|
||||
plugin_cache.protocol = plugin->protocol;
|
||||
if(plugin->verify) {
|
||||
plugin_cache.feature |= NfcSupportedCardsPluginFeatureHasVerify;
|
||||
@@ -233,7 +240,7 @@ bool nfc_supported_cards_read(NfcSupportedCards* instance, NfcDevice* device, Nf
|
||||
const ElfApiInterface* api_interface =
|
||||
composite_api_resolver_get(instance->api_resolver);
|
||||
const NfcSupportedCardsPlugin* plugin = nfc_supported_cards_get_plugin(
|
||||
instance->load_context, plugin_cache->path, api_interface);
|
||||
instance->load_context, furi_string_get_cstr(plugin_cache->name), api_interface);
|
||||
if(plugin == NULL) continue;
|
||||
|
||||
if(plugin->verify) {
|
||||
@@ -281,7 +288,7 @@ bool nfc_supported_cards_parse(
|
||||
const ElfApiInterface* api_interface =
|
||||
composite_api_resolver_get(instance->api_resolver);
|
||||
const NfcSupportedCardsPlugin* plugin = nfc_supported_cards_get_plugin(
|
||||
instance->load_context, plugin_cache->path, api_interface);
|
||||
instance->load_context, furi_string_get_cstr(plugin_cache->name), api_interface);
|
||||
if(plugin == NULL) continue;
|
||||
|
||||
if(plugin->parse) {
|
||||
|
||||
Reference in New Issue
Block a user