|
|
@@ -10,25 +10,26 @@
|
|
|
|
|
|
ARRAY_DEF(FileArray, FuriString*, FURI_STRING_OPLIST);
|
|
|
|
|
|
-ItemsView* item_get_items_view_from_path(void* context, FuriString* input_path) {
|
|
|
+ItemsView* item_get_items_view_from_path(void* context, const FuriString* input_path) {
|
|
|
App* app = context;
|
|
|
|
|
|
// Handle the app start condition
|
|
|
+ FuriString* in_path;
|
|
|
if(input_path == NULL) {
|
|
|
- input_path = furi_string_alloc_set_str(QUAC_DATA_PATH);
|
|
|
+ in_path = furi_string_alloc_set_str(QUAC_DATA_PATH);
|
|
|
+ } else {
|
|
|
+ in_path = furi_string_alloc_set(input_path);
|
|
|
}
|
|
|
- const char* cpath = furi_string_get_cstr(input_path);
|
|
|
+ const char* cpath = furi_string_get_cstr(in_path);
|
|
|
|
|
|
- FURI_LOG_I(TAG, "Getting items from: %s", cpath);
|
|
|
+ FURI_LOG_I(TAG, "Reading items from path: %s", cpath);
|
|
|
ItemsView* iview = malloc(sizeof(ItemsView));
|
|
|
- iview->path = furi_string_alloc_set(input_path);
|
|
|
+ iview->path = furi_string_alloc_set(in_path);
|
|
|
|
|
|
iview->name = furi_string_alloc();
|
|
|
if(app->depth == 0) {
|
|
|
- FURI_LOG_I(TAG, "Depth is ZERO!");
|
|
|
furi_string_set_str(iview->name, QUAC_NAME);
|
|
|
} else {
|
|
|
- FURI_LOG_I(TAG, "Depth is %d", app->depth);
|
|
|
path_extract_basename(cpath, iview->name);
|
|
|
item_prettify_name(iview->name);
|
|
|
}
|
|
|
@@ -43,17 +44,17 @@ ItemsView* item_get_items_view_from_path(void* context, FuriString* input_path)
|
|
|
FuriString* filename_tmp;
|
|
|
filename_tmp = furi_string_alloc();
|
|
|
|
|
|
- // FURI_LOG_I(TAG, "About to walk the dir");
|
|
|
+ // Walk the directory and store all file names in sorted order
|
|
|
if(dir_walk_open(dir_walk, cpath)) {
|
|
|
while(dir_walk_read(dir_walk, path, NULL) == DirWalkOK) {
|
|
|
- FURI_LOG_I(TAG, "> dir_walk: %s", furi_string_get_cstr(path));
|
|
|
+ // FURI_LOG_I(TAG, "> dir_walk: %s", furi_string_get_cstr(path));
|
|
|
const char* cpath = furi_string_get_cstr(path);
|
|
|
|
|
|
// Skip "hidden" files
|
|
|
path_extract_filename(path, filename_tmp, false);
|
|
|
char first_char = furi_string_get_char(filename_tmp, 0);
|
|
|
if(first_char == '.') {
|
|
|
- FURI_LOG_I(TAG, ">> skipping hidden file: %s", furi_string_get_cstr(filename_tmp));
|
|
|
+ // FURI_LOG_I(TAG, ">> skipping hidden file: %s", furi_string_get_cstr(filename_tmp));
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
@@ -78,6 +79,7 @@ ItemsView* item_get_items_view_from_path(void* context, FuriString* input_path)
|
|
|
furi_string_free(filename_tmp);
|
|
|
furi_string_free(path);
|
|
|
|
|
|
+ // Generate our Item list
|
|
|
FileArray_it_t iter;
|
|
|
ItemArray_init(iview->items);
|
|
|
for(FileArray_it(iter, flist); !FileArray_end_p(iter); FileArray_next(iter)) {
|
|
|
@@ -89,20 +91,7 @@ ItemsView* item_get_items_view_from_path(void* context, FuriString* input_path)
|
|
|
// Action files have extensions, so item->ext starts with '.'
|
|
|
item->ext[0] = 0;
|
|
|
path_extract_extension(path, item->ext, MAX_EXT_LEN);
|
|
|
- // FURI_LOG_I(TAG, ". EXT = %s", item->ext);
|
|
|
- if(item->ext[0] == '.') {
|
|
|
- // TODO: hack alert - make a helper fn here, or something
|
|
|
- if(item->ext[1] == 's')
|
|
|
- item->type = Item_SubGhz;
|
|
|
- else if(item->ext[1] == 'r')
|
|
|
- item->type = Item_RFID;
|
|
|
- else if(item->ext[1] == 'q')
|
|
|
- item->type = Item_Playlist;
|
|
|
- else if(item->ext[1] == 'i')
|
|
|
- item->type = Item_IR;
|
|
|
- } else {
|
|
|
- item->type = Item_Group;
|
|
|
- }
|
|
|
+ item->type = item_get_item_type_from_extension(item->ext);
|
|
|
|
|
|
item->name = furi_string_alloc();
|
|
|
path_extract_filename_no_ext(found_path, item->name);
|
|
|
@@ -114,6 +103,7 @@ ItemsView* item_get_items_view_from_path(void* context, FuriString* input_path)
|
|
|
// FURI_LOG_I(TAG, "Path: %s", furi_string_get_cstr(item->path));
|
|
|
}
|
|
|
|
|
|
+ furi_string_free(in_path);
|
|
|
FileArray_clear(flist);
|
|
|
dir_walk_free(dir_walk);
|
|
|
|
|
|
@@ -121,7 +111,6 @@ ItemsView* item_get_items_view_from_path(void* context, FuriString* input_path)
|
|
|
}
|
|
|
|
|
|
void item_items_view_free(ItemsView* items_view) {
|
|
|
- FURI_LOG_I(TAG, "item_items_view_free - begin");
|
|
|
furi_string_free(items_view->name);
|
|
|
furi_string_free(items_view->path);
|
|
|
ItemArray_it_t iter;
|
|
|
@@ -131,7 +120,6 @@ void item_items_view_free(ItemsView* items_view) {
|
|
|
}
|
|
|
ItemArray_clear(items_view->items);
|
|
|
free(items_view);
|
|
|
- FURI_LOG_I(TAG, "item_items_view_free - end");
|
|
|
}
|
|
|
|
|
|
void item_prettify_name(FuriString* name) {
|
|
|
@@ -148,4 +136,19 @@ void item_prettify_name(FuriString* name) {
|
|
|
}
|
|
|
furi_string_replace_str(name, "_", " ", 0);
|
|
|
// FURI_LOG_I(TAG, "... %s", furi_string_get_cstr(name));
|
|
|
+}
|
|
|
+
|
|
|
+ItemType item_get_item_type_from_extension(const char* ext) {
|
|
|
+ ItemType type = Item_Group;
|
|
|
+
|
|
|
+ if(!strcmp(ext, ".sub")) {
|
|
|
+ type = Item_SubGhz;
|
|
|
+ } else if(!strcmp(ext, ".rfid")) {
|
|
|
+ type = Item_RFID;
|
|
|
+ } else if(!strcmp(ext, ".ir")) {
|
|
|
+ type = Item_IR;
|
|
|
+ } else if(!strcmp(ext, ".qpl")) {
|
|
|
+ type = Item_Playlist;
|
|
|
+ }
|
|
|
+ return type;
|
|
|
}
|