Explorar o código

95% done with github installation

jblanked hai 1 ano
pai
achega
9b637e6ca8

+ 6 - 2
callback/flip_store_callback.c

@@ -438,13 +438,17 @@ static char *flip_store_parse_github(DataLoaderModel *model)
         {
             return "Failed to parse Github contents";
         }
-        return "Repository contents fetched...";
+        if (!flip_store_install_all_github_files(model->fhttp, author, repo))
+        {
+            return "Failed to install all Github files";
+        }
+        return "Repository downloaded successfully";
     }
     return "Failed to download repository.";
 }
 static void flip_store_github_switch_to_view(FlipStoreApp *app)
 {
-    flip_store_generic_switch_to_view(app, "Downloading Repository..", flip_store_fetch_github, flip_store_parse_github, 1, callback_to_submenu_options, FlipStoreViewLoader);
+    flip_store_generic_switch_to_view(app, "Downloading Repository..", flip_store_fetch_github, flip_store_parse_github, 2, callback_to_submenu_options, FlipStoreViewLoader);
 }
 static void flip_store_text_updated_repo(void *context)
 {

+ 1 - 1
flipper_http/flipper_http.c

@@ -1321,7 +1321,7 @@ void flipper_http_rx_callback(const char *line, void *context)
     }
 
     // Uncomment below line to log the data received over UART
-    FURI_LOG_I(HTTP_TAG, "Received UART line: %s", line);
+    // FURI_LOG_I(HTTP_TAG, "Received UART line: %s", line);
 
     // Check if we've started receiving data from a GET request
     if (fhttp->started_receiving_get)

+ 1 - 1
flipper_http/flipper_http.h

@@ -23,7 +23,7 @@
 #define BAUDRATE (115200)                 // UART baudrate
 #define RX_BUF_SIZE 2048                  // UART RX buffer size
 #define RX_LINE_BUFFER_SIZE 2048          // UART RX line buffer size (increase for large responses)
-#define MAX_FILE_SHOW 12000               // Maximum data from file to show
+#define MAX_FILE_SHOW 10000               // Maximum data from file to show
 #define FILE_BUFFER_SIZE 512              // File buffer size
 
 // Forward declaration for callback

+ 70 - 2
github/flip_store_github.c

@@ -52,6 +52,14 @@ bool flip_store_get_github_contents(FlipperHTTP *fhttp, const char *author, cons
     snprintf(dir, sizeof(dir), STORAGE_EXT_PATH_PREFIX "/apps_data/flip_store/data/%s/%s", author, repo);
     storage_common_mkdir(storage, dir);
 
+    // example path: /ext/apps_data/flip_store/author
+    snprintf(dir, sizeof(dir), STORAGE_EXT_PATH_PREFIX "/apps_data/flip_store/%s", author);
+    storage_common_mkdir(storage, dir);
+
+    // example path: /ext/apps_data/flip_store/author/repo
+    snprintf(dir, sizeof(dir), STORAGE_EXT_PATH_PREFIX "/apps_data/flip_store/%s/%s", author, repo);
+    storage_common_mkdir(storage, dir);
+
     furi_record_close(RECORD_STORAGE);
 
     // get the contents of the repo
@@ -136,7 +144,6 @@ bool flip_store_parse_github_contents(char *file_path, const char *author, const
         {
             FURI_LOG_E(TAG, "Failed to allocate json.");
 
-            furi_string_free(json_data_array);
             furi_string_free(download_url);
             furi_string_free(name);
             break;
@@ -153,7 +160,7 @@ bool flip_store_parse_github_contents(char *file_path, const char *author, const
 
         // save the json to the data folder: /ext/apps_data/flip_store/data/author/repo
         char dir[256];
-        snprintf(dir, sizeof(dir), STORAGE_EXT_PATH_PREFIX "/apps_data/flip_store/data/%s/%s/%s.json", author, repo, furi_string_get_cstr(name));
+        snprintf(dir, sizeof(dir), STORAGE_EXT_PATH_PREFIX "/apps_data/flip_store/data/%s/%s/file%d.json", author, repo, file_count);
         if (!save_char_with_path(dir, furi_string_get_cstr(json)))
         {
             FURI_LOG_E(TAG, "Failed to save json.");
@@ -171,4 +178,65 @@ bool flip_store_parse_github_contents(char *file_path, const char *author, const
     char file_count_dir[256]; // /ext/apps_data/flip_store/data/author/file_count.txt
     snprintf(file_count_dir, sizeof(file_count_dir), STORAGE_EXT_PATH_PREFIX "/apps_data/flip_store/data/%s/file_count.txt", author);
     return save_char_with_path(file_count_dir, file_count_str);
+}
+
+bool flip_store_install_all_github_files(FlipperHTTP *fhttp, const char *author, const char *repo)
+{
+    if (!fhttp)
+    {
+        FURI_LOG_E(TAG, "FlipperHTTP is NULL");
+        return false;
+    }
+    // get the file count
+    char file_count_dir[256]; // /ext/apps_data/flip_store/data/author/file_count.txt
+    snprintf(file_count_dir, sizeof(file_count_dir), STORAGE_EXT_PATH_PREFIX "/apps_data/flip_store/data/%s/file_count.txt", author);
+    FuriString *file_count = flipper_http_load_from_file(file_count_dir);
+    if (file_count == NULL)
+    {
+        FURI_LOG_E(TAG, "Failed to load file count.");
+        return false;
+    }
+    int count = atoi(furi_string_get_cstr(file_count));
+    furi_string_free(file_count);
+
+    // install all files
+    for (int i = 0; i < count; i++)
+    {
+        char file_dir[256]; // /ext/apps_data/flip_store/data/author/repo/file.json
+        snprintf(file_dir, sizeof(file_dir), STORAGE_EXT_PATH_PREFIX "/apps_data/flip_store/data/%s/%s/file%d.json", author, repo, i);
+        FuriString *file = flipper_http_load_from_file(file_dir);
+        if (file == NULL)
+        {
+            FURI_LOG_E(TAG, "Failed to load file.");
+            return false;
+        }
+        FuriString *name = get_json_value_furi("name", file);
+        if (!name)
+        {
+            FURI_LOG_E(TAG, "Failed to get name.");
+            furi_string_free(file);
+            return false;
+        }
+        FuriString *link = get_json_value_furi("link", file);
+        if (!link)
+        {
+            FURI_LOG_E(TAG, "Failed to get link.");
+            furi_string_free(file);
+            furi_string_free(name);
+            return false;
+        }
+        furi_string_free(file);
+
+        // download the file
+        if (!flip_store_download_github_file(fhttp, furi_string_get_cstr(name), author, repo, furi_string_get_cstr(link)))
+        {
+            FURI_LOG_E(TAG, "Failed to download file.");
+            furi_string_free(name);
+            furi_string_free(link);
+            return false;
+        }
+        furi_string_free(name);
+        furi_string_free(link);
+    }
+    return true;
 }

+ 14 - 1
github/flip_store_github.h

@@ -1,6 +1,13 @@
 #pragma once
 #include <flip_store.h>
 
+/*
+I did try downloading a zip file from Github but a few issues
+- unsure how to unzip the file
+- either Github redirected us to a loading page, or their was no response on if using an IoT device
+- any contributions to this would be appreciated
+*/
+
 // Helper to download a file from Github and save it to the storage
 bool flip_store_download_github_file(
     FlipperHTTP *fhttp,
@@ -9,5 +16,11 @@ bool flip_store_download_github_file(
     const char *repo,
     const char *link);
 
+// Helper to get the contents of a Github repo (from https://api.github.com/repos/author/repo/contents)
 bool flip_store_get_github_contents(FlipperHTTP *fhttp, const char *author, const char *repo);
-bool flip_store_parse_github_contents(char *file_path, const char *author, const char *repo);
+
+// Helper to parse the contents of a Github repo (takes parts of the data and saves it for easy access later)
+bool flip_store_parse_github_contents(char *file_path, const char *author, const char *repo);
+
+// Helper to install all files from the parsed Github repo contents in flip_store_parse_github_contents
+bool flip_store_install_all_github_files(FlipperHTTP *fhttp, const char *author, const char *repo);