Jelajahi Sumber

Cleanup to finish log viewer, increase stack size to accommodate

0xchocolate 2 tahun lalu
induk
melakukan
d4354b8ac5

+ 1 - 1
applications/external/wifi_marauder_companion/application.fam

@@ -5,7 +5,7 @@ App(
     entry_point="wifi_marauder_app",
     cdefines=["APP_WIFI_MARAUDER"],
     requires=["gui"],
-    stack_size=1 * 1024,
+    stack_size=4 * 1024,
     order=90,
     fap_icon="wifi_10px.png",
     fap_category="GPIO",

+ 9 - 8
applications/external/wifi_marauder_companion/scenes/wifi_marauder_scene_log_viewer.c

@@ -11,8 +11,7 @@ void wifi_marauder_scene_log_viewer_widget_callback(
 }
 
 static void _read_log_page_into_text_store(WifiMarauderApp* app) {
-    static char temp[257];
-    bzero(temp, sizeof(temp));
+    char temp[64 + 1];
     storage_file_seek(
         app->log_file, WIFI_MARAUDER_TEXT_BOX_STORE_SIZE * (app->open_log_file_page - 1), true);
     furi_string_reset(app->text_box_store);
@@ -28,15 +27,17 @@ static void _read_log_page_into_text_store(WifiMarauderApp* app) {
 
 void wifi_marauder_scene_log_viewer_setup_widget(WifiMarauderApp* app, bool called_from_browse) {
     Widget* widget = app->widget;
-
-    if(storage_file_is_open(app->log_file)) {
+    bool is_open = storage_file_is_open(app->log_file);
+    bool should_open_log = (app->has_saved_logs_this_session || called_from_browse);
+    if(is_open) {
         _read_log_page_into_text_store(app);
     } else if(
-        (app->has_saved_logs_this_session || called_from_browse) &&
+        should_open_log &&
         storage_file_open(app->log_file, app->log_file_path, FSAM_READ, FSOM_OPEN_EXISTING)) {
-        app->open_log_file_num_pages =
-            storage_file_size(app->log_file) / WIFI_MARAUDER_TEXT_BOX_STORE_SIZE +
-            (storage_file_size(app->log_file) % WIFI_MARAUDER_TEXT_BOX_STORE_SIZE != 0);
+        uint64_t filesize = storage_file_size(app->log_file);
+        app->open_log_file_num_pages = filesize / WIFI_MARAUDER_TEXT_BOX_STORE_SIZE;
+        int extra_page = (filesize % WIFI_MARAUDER_TEXT_BOX_STORE_SIZE != 0) ? 1 : 0;
+        app->open_log_file_num_pages = (filesize / WIFI_MARAUDER_TEXT_BOX_STORE_SIZE) + extra_page;
         app->open_log_file_page = 1;
         _read_log_page_into_text_store(app);
     } else {

+ 2 - 0
applications/external/wifi_marauder_companion/wifi_marauder_app.c

@@ -72,6 +72,8 @@ WifiMarauderApp* wifi_marauder_app_alloc() {
     view_dispatcher_add_view(
         app->view_dispatcher, WifiMarauderAppViewWidget, widget_get_view(app->widget));
 
+    app->has_saved_logs_this_session = false;
+
     // if user hasn't confirmed whether to save pcaps and logs to sdcard, then prompt when scene starts
     app->need_to_prompt_settings_init =
         (!storage_file_exists(app->storage, SAVE_PCAP_SETTING_FILEPATH) ||

+ 1 - 1
applications/external/wifi_marauder_companion/wifi_marauder_pcap.c

@@ -59,6 +59,6 @@ void wifi_marauder_create_log_file(WifiMarauderApp* app) {
     if(!storage_file_open(app->log_file, log_file_path, FSAM_WRITE, FSOM_CREATE_ALWAYS)) {
         dialog_message_show_storage_error(app->dialogs, "Cannot open log file");
     } else {
-        strncpy(app->log_file_path, log_file_path, strlen(log_file_path));
+        strcpy(app->log_file_path, log_file_path);
     }
 }