Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Archive can open img files and mount them (Needs fixing for browser view) ($50 ETH or BTC BOUNTY) #1046

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ This software is for experimental purposes only and is not meant for any illegal

- Last Synced/Checked OFW, changes in [commits](https://github.com/flipperdevices/flipperzero-firmware/commits/dev): `2024-03-11 16:04 EST`
- Last Synced/Checked Unleashed, changes in [changelog](https://github.com/RogueMaster/flipperzero-firmware-wPlugins/blob/420/CHANGELOG.md): `2024-03-11 16:04 EST`
- [Updated Archive Plugin for Disk Image support (By Willy-JL)](https://github.com/RogueMaster/flipperzero-firmware-wPlugins/commit/321a768fa9bab94980fccdec0fb17fd6e836ee16)
- Updated: [J305 Geiger Counter v1.2 (By nmrr)](https://github.com/nmrr/flipperzero-geigercounter)

<a name="release">
Expand Down
7 changes: 7 additions & 0 deletions applications/main/archive/archive.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ void archive_free(ArchiveApp* archive) {
furi_assert(archive);
ViewDispatcher* view_dispatcher = archive->view_dispatcher;

if(archive->browser->disk_image) {
storage_virtual_quit(furi_record_open(RECORD_STORAGE));
furi_record_close(RECORD_STORAGE);
storage_file_free(archive->browser->disk_image);
archive->browser->disk_image = NULL;
}

// Loading
loading_free(archive->loading);

Expand Down
12 changes: 8 additions & 4 deletions applications/main/archive/helpers/archive_browser.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ static void
browser->is_root = is_root;
ArchiveTabEnum tab = archive_get_tab(browser);

if((item_cnt == 0) && (archive_is_home(browser)) && (tab != ArchiveTabBrowser)) {
if((item_cnt == 0) && (archive_is_home(browser)) && (tab != ArchiveTabBrowser) &&
(tab != ArchiveTabDiskImage || !browser->disk_image)) {
archive_switch_tab(browser, browser->last_tab_switch_dir);
} else if(!furi_string_start_with_str(browser->path, "/app:")) {
with_view_model(
Expand All @@ -28,7 +29,7 @@ static void
{
files_array_reset(model->files);
model->item_cnt = item_cnt;
model->item_idx = (file_idx > 0) ? file_idx : 0;
model->item_idx = file_idx;
load_offset =
CLAMP(model->item_idx - FILE_LIST_BUF_LEN / 2, (int32_t)model->item_cnt, 0);
model->array_offset = 0;
Expand Down Expand Up @@ -452,7 +453,9 @@ void archive_favorites_move_mode(ArchiveBrowserView* browser, bool active) {
}

static bool archive_is_dir_exists(FuriString* path) {
if(furi_string_equal(path, STORAGE_ANY_PATH_PREFIX)) {
if(furi_string_equal(path, STORAGE_INT_PATH_PREFIX) ||
furi_string_equal(path, STORAGE_EXT_PATH_PREFIX) ||
furi_string_equal(path, STORAGE_MNT_PATH_PREFIX)) {
return true;
}
bool state = false;
Expand Down Expand Up @@ -509,7 +512,8 @@ void archive_switch_tab(ArchiveBrowserView* browser, InputKey key) {
}
}

if((tab_empty) && (tab != ArchiveTabBrowser)) {
if(tab_empty && tab != ArchiveTabBrowser && tab != ArchiveTabInternal &&
(tab != ArchiveTabDiskImage || !browser->disk_image)) {
archive_switch_tab(browser, key);
} else {
with_view_model(
Expand Down
3 changes: 3 additions & 0 deletions applications/main/archive/helpers/archive_browser.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ static const char* tab_default_paths[] = {
[ArchiveTabBadUsb] = ANY_PATH("badusb"),
[ArchiveTabU2f] = "/app:u2f",
[ArchiveTabApplications] = ANY_PATH("apps"),
[ArchiveTabDiskImage] = STORAGE_MNT_PATH_PREFIX,
[ArchiveTabInternal] = STORAGE_INT_PATH_PREFIX,
[ArchiveTabBrowser] = STORAGE_ANY_PATH_PREFIX,
};
Expand All @@ -34,6 +35,7 @@ static const char* known_ext[] = {
[ArchiveFileTypeApplication] = ".fap",
[ArchiveFileTypeJS] = ".js",
[ArchiveFileTypeUpdateManifest] = ".fuf",
[ArchiveFileTypeDiskImage] = ".img",
[ArchiveFileTypeFolder] = "?",
[ArchiveFileTypeUnknown] = "*",
[ArchiveFileTypeAppOrJs] = ".fap|.js",
Expand All @@ -50,6 +52,7 @@ static const ArchiveFileTypeEnum known_type[] = {
[ArchiveTabBadUsb] = ArchiveFileTypeBadUsb,
[ArchiveTabU2f] = ArchiveFileTypeU2f,
[ArchiveTabApplications] = ArchiveFileTypeAppOrJs,
[ArchiveTabDiskImage] = ArchiveFileTypeUnknown,
[ArchiveTabInternal] = ArchiveFileTypeUnknown,
[ArchiveTabBrowser] = ArchiveFileTypeUnknown,
};
Expand Down
1 change: 1 addition & 0 deletions applications/main/archive/helpers/archive_files.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ typedef enum {
ArchiveFileTypeU2f,
ArchiveFileTypeApplication,
ArchiveFileTypeUpdateManifest,
ArchiveFileTypeDiskImage,
ArchiveFileTypeJS,
ArchiveFileTypeFolder,
ArchiveFileTypeUnknown,
Expand Down
59 changes: 55 additions & 4 deletions applications/main/archive/scenes/archive_scene_browser.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ static const char* archive_get_flipper_app_name(ArchiveFileTypeEnum file_type) {
return "U2F";
case ArchiveFileTypeUpdateManifest:
return "UpdaterApp";
case ArchiveFileTypeDiskImage:
return EXT_PATH("apps/USB/mass_storage.fap");
case ArchiveFileTypeJS:
return EXT_PATH("apps/Main/js_app.fap");
default:
Expand All @@ -51,6 +53,50 @@ static void archive_loader_callback(const void* message, void* context) {
}
}

static void archive_mount_disk_image(ArchiveBrowserView* browser, ArchiveFile_t* selected) {
Storage* storage = furi_record_open(RECORD_STORAGE);
File* disk_image = NULL;
do {
if(browser->disk_image) {
// Deinit and recycle File object
if(storage_virtual_quit(storage) != FSE_OK) break;
storage_file_close(browser->disk_image);
disk_image = browser->disk_image;
browser->disk_image = NULL;
} else {
disk_image = storage_file_alloc(storage);
}

if(!storage_file_open(
disk_image,
furi_string_get_cstr(selected->path),
FSAM_READ | FSAM_WRITE,
FSOM_OPEN_EXISTING))
break;

FS_Error init = storage_virtual_init(storage, disk_image);
if(init == FSE_ALREADY_OPEN) {
if(storage_virtual_quit(storage) == FSE_OK) {
init = storage_virtual_init(storage, disk_image);
}
}
if(init != FSE_OK) break;

if(storage_virtual_mount(storage) != FSE_OK) {
storage_virtual_quit(storage);
break;
}

browser->disk_image = disk_image;

while(archive_get_tab(browser) != ArchiveTabDiskImage) {
archive_switch_tab(browser, TAB_LEFT);
}
} while(0);
if(disk_image && !browser->disk_image) storage_file_free(disk_image);
furi_record_close(RECORD_STORAGE);
}

static void archive_run_in_app(ArchiveBrowserView* browser, ArchiveFile_t* selected) {
UNUSED(browser);
Loader* loader = furi_record_open(RECORD_LOADER);
Expand Down Expand Up @@ -242,10 +288,15 @@ bool archive_scene_browser_on_event(void* context, SceneManagerEvent event) {
consumed = true;
break;
case ArchiveBrowserEventFileMenuShow:
archive_show_file_menu(browser, false);
scene_manager_set_scene_state(
archive->scene_manager, ArchiveAppSceneBrowser, SCENE_STATE_DEFAULT);
scene_manager_next_scene(archive->scene_manager, ArchiveAppSceneShow);
if(selected->type == ArchiveFileTypeDiskImage &&
archive_get_tab(browser) != ArchiveTabDiskImage) {
archive_mount_disk_image(browser, selected);
} else {
archive_show_file_menu(browser, false);
scene_manager_set_scene_state(
archive->scene_manager, ArchiveAppSceneBrowser, SCENE_STATE_DEFAULT);
scene_manager_next_scene(archive->scene_manager, ArchiveAppSceneShow);
}
consumed = true;
break;
case ArchiveBrowserEventFileMenuDelete:
Expand Down
15 changes: 13 additions & 2 deletions applications/main/archive/views/archive_browser_view.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ static const char* ArchiveTabNames[] = {
[ArchiveTabBadUsb] = "Bad USB",
[ArchiveTabU2f] = "U2F",
[ArchiveTabApplications] = "Apps",
[ArchiveTabDiskImage] = "Disk Image",
[ArchiveTabInternal] = "Internal",
[ArchiveTabBrowser] = "Browser",
};
Expand All @@ -35,6 +36,7 @@ static const Icon* ArchiveItemIcons[] = {
[ArchiveFileTypeU2f] = &I_u2f_10px,
[ArchiveFileTypeApplication] = &I_Apps_10px,
[ArchiveFileTypeUpdateManifest] = &I_update_10px,
[ArchiveFileTypeDiskImage] = &I_floppydisk_10px,
[ArchiveFileTypeFolder] = &I_dir_10px,
[ArchiveFileTypeUnknown] = &I_unknown_10px,
[ArchiveFileTypeLoading] = &I_loading_10px,
Expand Down Expand Up @@ -222,6 +224,12 @@ static void render_item_menu(Canvas* canvas, ArchiveBrowserViewModel* model) {
"Show",
ArchiveBrowserEventFileMenuShow);
}
if(selected->type == ArchiveFileTypeDiskImage) {
archive_menu_add_item(
menu_array_push_raw(model->context_menu),
"Mount",
ArchiveBrowserEventFileMenuShow);
}
}
}
} /*else {
Expand Down Expand Up @@ -317,16 +325,19 @@ static void draw_list(Canvas* canvas, ArchiveBrowserViewModel* model) {
ArchiveFile_t* file = files_array_get(
model->files, CLAMP(idx - model->array_offset, (int32_t)(array_size - 1), 0));
file_type = file->type;
bool ext = model->tab_idx == ArchiveTabBrowser ||
model->tab_idx == ArchiveTabInternal ||
model->tab_idx == ArchiveTabDiskImage;
if(file_type == ArchiveFileTypeApplication) {
if(file->custom_icon_data) {
custom_icon_data = file->custom_icon_data;
furi_string_set(str_buf, file->custom_name);
} else {
file_type = ArchiveFileTypeUnknown;
path_extract_filename(file->path, str_buf, archive_is_known_app(file->type));
path_extract_filename(file->path, str_buf, !ext);
}
} else {
path_extract_filename(file->path, str_buf, archive_is_known_app(file->type));
path_extract_filename(file->path, str_buf, !ext);
}
} else {
furi_string_set(str_buf, "---");
Expand Down
2 changes: 2 additions & 0 deletions applications/main/archive/views/archive_browser_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ typedef enum {
ArchiveTabBadUsb,
ArchiveTabU2f,
ArchiveTabApplications,
ArchiveTabDiskImage,
ArchiveTabInternal,
ArchiveTabBrowser,
ArchiveTabTotal,
Expand Down Expand Up @@ -93,6 +94,7 @@ struct ArchiveBrowserView {
InputKey last_tab_switch_dir;
bool is_root;
FuriTimer* scroll_timer;
File* disk_image;
};

typedef struct {
Expand Down
Binary file added assets/icons/Archive/floppydisk_10px.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.