[FL-1537] NFC launch from archive (#580)
* archive: pass full file path as App argument * nfc: add starting emulation from Archive * nfc, ibutton: rework setting key name with path lib * archive: revert launching app with full file path Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
		
							parent
							
								
									851a44dc59
								
							
						
					
					
						commit
						a837bc5d00
					
				@ -3,6 +3,7 @@
 | 
				
			|||||||
#include <callback-connector.h>
 | 
					#include <callback-connector.h>
 | 
				
			||||||
#include <m-string.h>
 | 
					#include <m-string.h>
 | 
				
			||||||
#include <file-worker-cpp.h>
 | 
					#include <file-worker-cpp.h>
 | 
				
			||||||
 | 
					#include <path.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const char* iButtonApp::app_folder = "ibutton";
 | 
					const char* iButtonApp::app_folder = "ibutton";
 | 
				
			||||||
const char* iButtonApp::app_extension = ".ibtn";
 | 
					const char* iButtonApp::app_extension = ".ibtn";
 | 
				
			||||||
@ -325,17 +326,10 @@ bool iButtonApp::load_key(const char* key_name) {
 | 
				
			|||||||
    string_t key_path;
 | 
					    string_t key_path;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    string_init_set_str(key_path, key_name);
 | 
					    string_init_set_str(key_path, key_name);
 | 
				
			||||||
    if(!string_start_with_str_p(key_path, app_folder) ||
 | 
					 | 
				
			||||||
       !string_end_with_str_p(key_path, app_extension)) {
 | 
					 | 
				
			||||||
        string_clear(key_path);
 | 
					 | 
				
			||||||
        return false;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    result = load_key_data(key_path);
 | 
					    result = load_key_data(key_path);
 | 
				
			||||||
    if(result) {
 | 
					    if(result) {
 | 
				
			||||||
        uint8_t folder_end = strlen(app_folder) + 1;
 | 
					        path_extract_filename_no_ext(key_name, key_path);
 | 
				
			||||||
        uint8_t extension_start = string_size(key_path) - strlen(app_extension);
 | 
					 | 
				
			||||||
        string_mid(key_path, folder_end, extension_start - folder_end);
 | 
					 | 
				
			||||||
        get_key()->set_name(string_get_cstr(key_path));
 | 
					        get_key()->set_name(string_get_cstr(key_path));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    string_clear(key_path);
 | 
					    string_clear(key_path);
 | 
				
			||||||
 | 
				
			|||||||
@ -95,9 +95,6 @@ Nfc* nfc_alloc() {
 | 
				
			|||||||
        NfcViewMifareUl,
 | 
					        NfcViewMifareUl,
 | 
				
			||||||
        nfc_mifare_ul_get_view(nfc->nfc_mifare_ul));
 | 
					        nfc_mifare_ul_get_view(nfc->nfc_mifare_ul));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Run first scene
 | 
					 | 
				
			||||||
    scene_manager_next_scene(nfc->scene_manager, NfcSceneStart);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    return nfc;
 | 
					    return nfc;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -169,6 +166,13 @@ void nfc_free(Nfc* nfc) {
 | 
				
			|||||||
int32_t nfc_task(void* p) {
 | 
					int32_t nfc_task(void* p) {
 | 
				
			||||||
    Nfc* nfc = nfc_alloc();
 | 
					    Nfc* nfc = nfc_alloc();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Check argument and run corresponding scene
 | 
				
			||||||
 | 
					    if(p && nfc_device_load(&nfc->device, p)) {
 | 
				
			||||||
 | 
					        scene_manager_next_scene(nfc->scene_manager, NfcSceneEmulateUid);
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					        scene_manager_next_scene(nfc->scene_manager, NfcSceneStart);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    view_dispatcher_run(nfc->nfc_common.view_dispatcher);
 | 
					    view_dispatcher_run(nfc->nfc_common.view_dispatcher);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    nfc_free(nfc);
 | 
					    nfc_free(nfc);
 | 
				
			||||||
 | 
				
			|||||||
@ -1,6 +1,7 @@
 | 
				
			|||||||
#include "nfc_device.h"
 | 
					#include "nfc_device.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <file-worker.h>
 | 
					#include <file-worker.h>
 | 
				
			||||||
 | 
					#include <path.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define NFC_DEVICE_MAX_DATA_LEN 14
 | 
					#define NFC_DEVICE_MAX_DATA_LEN 14
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -86,10 +87,25 @@ static bool nfc_device_load_data(FileWorker* file_worker, string_t path, NfcDevi
 | 
				
			|||||||
    return true;
 | 
					    return true;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool nfc_device_load(NfcDevice* dev, const char* dev_name) {
 | 
					bool nfc_device_load(NfcDevice* dev, const char* file_path) {
 | 
				
			||||||
    furi_assert(dev);
 | 
					    furi_assert(dev);
 | 
				
			||||||
 | 
					    furi_assert(file_path);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return true;
 | 
					    FileWorker* file_worker = file_worker_alloc(false);
 | 
				
			||||||
 | 
					    // Load device data
 | 
				
			||||||
 | 
					    string_t path;
 | 
				
			||||||
 | 
					    string_init_set_str(path, file_path);
 | 
				
			||||||
 | 
					    bool dev_load = nfc_device_load_data(file_worker, path, dev);
 | 
				
			||||||
 | 
					    if(dev_load) {
 | 
				
			||||||
 | 
					        // Set device name
 | 
				
			||||||
 | 
					        path_extract_filename_no_ext(file_path, path);
 | 
				
			||||||
 | 
					        nfc_device_set_name(dev, string_get_cstr(path));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    string_clear(path);
 | 
				
			||||||
 | 
					    file_worker_close(file_worker);
 | 
				
			||||||
 | 
					    file_worker_free(file_worker);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return dev_load;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool nfc_file_select(NfcDevice* dev) {
 | 
					bool nfc_file_select(NfcDevice* dev) {
 | 
				
			||||||
 | 
				
			|||||||
@ -55,6 +55,6 @@ void nfc_device_set_name(NfcDevice* dev, const char* name);
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
bool nfc_device_save(NfcDevice* dev, const char* dev_name);
 | 
					bool nfc_device_save(NfcDevice* dev, const char* dev_name);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool nfc_device_load(NfcDevice* dev, const char* dev_name);
 | 
					bool nfc_device_load(NfcDevice* dev, const char* file_path);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool nfc_file_select(NfcDevice* dev);
 | 
					bool nfc_file_select(NfcDevice* dev);
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user