Skip to content

Commit

Permalink
Merge branch 'dev' into release-candidate
Browse files Browse the repository at this point in the history
  • Loading branch information
skotopes committed Feb 10, 2022
2 parents 3cdcd64 + 2c61698 commit 661b4b1
Show file tree
Hide file tree
Showing 224 changed files with 4,427 additions and 3,288 deletions.
6 changes: 3 additions & 3 deletions applications/accessor/helpers/wiegand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ int WIEGAND::getWiegandType() {

bool WIEGAND::available() {
bool ret;
__disable_irq();
FURI_CRITICAL_ENTER();
ret = DoWiegandConversion();
__enable_irq();
FURI_CRITICAL_EXIT();
return ret;
}

Expand Down Expand Up @@ -221,4 +221,4 @@ bool WIEGAND::DoWiegandConversion() {
}
} else
return false;
}
}
6 changes: 3 additions & 3 deletions applications/accessor/scene/accessor_scene_start.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ bool AccessorSceneStart::on_event(AccessorApp* app, AccessorEvent* event) {
data[i] = wiegand->getCodeHigh() >> ((i - 4) * 8);
}
} else {
__disable_irq();
FURI_CRITICAL_ENTER();
if(onewire->reset()) {
type = 255;
onewire->write(0x33);
Expand All @@ -49,7 +49,7 @@ bool AccessorSceneStart::on_event(AccessorApp* app, AccessorEvent* event) {
data[i] = data[i + 1];
}
}
__enable_irq();
FURI_CRITICAL_EXIT();
}

if(type > 0) {
Expand Down Expand Up @@ -85,4 +85,4 @@ void AccessorSceneStart::on_exit(AccessorApp* app) {
Popup* popup = app->get_view_manager()->get_popup();
popup_set_header(popup, NULL, 0, 0, AlignCenter, AlignBottom);
popup_set_text(popup, NULL, 0, 0, AlignCenter, AlignTop);
}
}
6 changes: 6 additions & 0 deletions applications/archive/archive.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ ArchiveApp* archive_alloc() {
view_dispatcher_add_view(
archive->view_dispatcher, ArchiveViewTextInput, text_input_get_view(archive->text_input));

archive->widget = widget_alloc();
view_dispatcher_add_view(
archive->view_dispatcher, ArchiveViewWidget, widget_get_view(archive->widget));

return archive;
}

Expand All @@ -47,6 +51,8 @@ void archive_free(ArchiveApp* archive) {

view_dispatcher_remove_view(archive->view_dispatcher, ArchiveViewBrowser);
view_dispatcher_remove_view(archive->view_dispatcher, ArchiveViewTextInput);
view_dispatcher_remove_view(archive->view_dispatcher, ArchiveViewWidget);
widget_free(archive->widget);
view_dispatcher_free(archive->view_dispatcher);
scene_manager_free(archive->scene_manager);
browser_free(archive->browser);
Expand Down
3 changes: 3 additions & 0 deletions applications/archive/archive_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <gui/view_dispatcher.h>
#include <gui/scene_manager.h>
#include <gui/modules/text_input.h>
#include <gui/modules/widget.h>
#include <loader/loader.h>

#include "views/archive_browser_view.h"
Expand All @@ -15,6 +16,7 @@
typedef enum {
ArchiveViewBrowser,
ArchiveViewTextInput,
ArchiveViewWidget,
ArchiveViewTotal,
} ArchiveViewEnum;

Expand All @@ -24,6 +26,7 @@ struct ArchiveApp {
SceneManager* scene_manager;
ArchiveBrowserView* browser;
TextInput* text_input;
Widget* widget;
char text_store[MAX_NAME_LEN];
char file_extension[MAX_EXT_LEN + 1];
};
74 changes: 74 additions & 0 deletions applications/archive/helpers/archive_apps.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#include "archive_files.h"
#include "archive_apps.h"
#include "archive_browser.h"

static const char* known_apps[] = {
[ArchiveAppTypeU2f] = "u2f",
};

ArchiveAppTypeEnum archive_get_app_type(const char* path) {
for(size_t i = 0; i < SIZEOF_ARRAY(known_apps); i++) {
if(strncmp(path, known_apps[i], strlen(known_apps[i])) != STRING_FAILURE) {
return i;
}
}
return ArchiveAppTypeUnknown;
}

bool archive_app_is_available(void* context, const char* path) {
furi_assert(path);

ArchiveAppTypeEnum app = archive_get_app_type(path);

if(app == ArchiveAppTypeU2f) {
FileWorker* file_worker = file_worker_alloc(true);
bool file_exists = false;
file_worker_is_file_exist(file_worker, "/any/u2f/key.u2f", &file_exists);
if(file_exists) {
file_worker_is_file_exist(file_worker, "/any/u2f/cnt.u2f", &file_exists);
}
file_worker_free(file_worker);
return file_exists;
} else {
return false;
}
}

bool archive_app_read_dir(void* context, const char* path) {
furi_assert(context);
furi_assert(path);
ArchiveBrowserView* browser = context;

ArchiveAppTypeEnum app = archive_get_app_type(path);

if(app == ArchiveAppTypeU2f) {
archive_add_app_item(browser, "/app:u2f/U2F Token");
return true;
} else {
return false;
}
}

void archive_app_delete_file(void* context, const char* path) {
furi_assert(context);
furi_assert(path);
ArchiveBrowserView* browser = context;

ArchiveAppTypeEnum app = archive_get_app_type(path);
bool res = false;

if(app == ArchiveAppTypeU2f) {
FileWorker* file_worker = file_worker_alloc(true);
res = file_worker_remove(file_worker, "/any/u2f/key.u2f");
res |= file_worker_remove(file_worker, "/any/u2f/cnt.u2f");
file_worker_free(file_worker);

if(archive_is_favorite("/app:u2f/U2F Token")) {
archive_favorites_delete("/app:u2f/U2F Token");
}
}

if(res) {
archive_file_array_rm_selected(browser);
}
}
21 changes: 21 additions & 0 deletions applications/archive/helpers/archive_apps.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pragma once

typedef enum {
ArchiveAppTypeU2f,
ArchiveAppTypeUnknown,
ArchiveAppsTotal,
} ArchiveAppTypeEnum;

static const ArchiveFileTypeEnum app_file_types[] = {
[ArchiveAppTypeU2f] = ArchiveFileTypeU2f,
[ArchiveAppTypeUnknown] = ArchiveFileTypeUnknown,
};

static inline const ArchiveFileTypeEnum archive_get_app_filetype(ArchiveAppTypeEnum app) {
return app_file_types[app];
}

ArchiveAppTypeEnum archive_get_app_type(const char* path);
bool archive_app_is_available(void* context, const char* path);
bool archive_app_read_dir(void* context, const char* path);
void archive_app_delete_file(void* context, const char* path);
65 changes: 50 additions & 15 deletions applications/archive/helpers/archive_browser.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "archive_files.h"
#include "archive_apps.h"
#include "archive_browser.h"
#include "math.h"
#include <math.h>

void archive_update_offset(ArchiveBrowserView* browser) {
furi_assert(browser);
Expand Down Expand Up @@ -177,24 +179,53 @@ void archive_set_last_tab(ArchiveBrowserView* browser, ArchiveTabEnum tab) {
});
}

void archive_add_item(ArchiveBrowserView* browser, FileInfo* file_info, const char* name) {
void archive_add_app_item(ArchiveBrowserView* browser, const char* name) {
furi_assert(browser);
furi_assert(name);

ArchiveFile_t item;

string_t full_name;

string_init_set(full_name, browser->path);
string_cat_printf(full_name, "/%s", name);

char* app_name = strchr(string_get_cstr(full_name), ':');
if(app_name == NULL) {
string_clear(full_name);
return;
}

ArchiveFile_t_init(&item);
string_init_set_str(item.name, name);
set_file_type(&item, NULL, app_name + 1, true);

with_view_model(
browser->view, (ArchiveBrowserViewModel * model) {
files_array_push_back(model->files, item);
return false;
});
ArchiveFile_t_clear(&item);
string_clear(full_name);
}

void archive_add_file_item(ArchiveBrowserView* browser, FileInfo* file_info, const char* name) {
furi_assert(browser);
furi_assert(file_info);
furi_assert(name);

ArchiveFile_t item;

if(filter_by_extension(file_info, get_tab_ext(archive_get_tab(browser)), name)) {
if(filter_by_extension(file_info, archive_get_tab_ext(archive_get_tab(browser)), name)) {
ArchiveFile_t_init(&item);
string_init_set_str(item.name, name);
set_file_type(&item, file_info);
set_file_type(&item, file_info, archive_get_path(browser), false);

with_view_model(
browser->view, (ArchiveBrowserViewModel * model) {
files_array_push_back(model->files, item);
return false;
});

ArchiveFile_t_clear(&item);
}
}
Expand All @@ -208,8 +239,7 @@ void archive_show_file_menu(ArchiveBrowserView* browser, bool show) {

if(show) {
ArchiveFile_t* selected = files_array_get(model->files, model->idx);
selected->fav = archive_is_favorite(
"%s/%s", string_get_cstr(browser->path), string_get_cstr(selected->name));
selected->fav = archive_is_favorite("%s", string_get_cstr(selected->name));
}

return true;
Expand Down Expand Up @@ -245,12 +275,18 @@ void archive_switch_tab(ArchiveBrowserView* browser, InputKey key) {

archive_set_tab(browser, tab);

if((tab != ArchiveTabFavorites &&
!archive_dir_empty(browser, archive_get_default_path(tab))) ||
(tab == ArchiveTabFavorites && !archive_favorites_count(browser))) {
if(tab != ArchiveTabBrowser) {
archive_switch_tab(browser, key);
}
const char* path = archive_get_default_path(tab);
bool tab_empty = true;
if(tab == ArchiveTabFavorites) {
if(archive_favorites_count(browser) > 0) tab_empty = false;
} else if(strncmp(path, "/app:", 5) == 0) {
if(archive_app_is_available(browser, path)) tab_empty = false;
} else {
if(archive_dir_not_empty(browser, archive_get_default_path(tab))) tab_empty = false;
}

if((tab_empty) && (tab != ArchiveTabBrowser)) {
archive_switch_tab(browser, key);
} else {
with_view_model(
browser->view, (ArchiveBrowserViewModel * model) {
Expand All @@ -277,8 +313,7 @@ void archive_enter_dir(ArchiveBrowserView* browser, string_t name) {
return false;
});

string_cat(browser->path, "/");
string_cat(browser->path, name);
string_set(browser->path, name);

archive_switch_dir(browser, string_get_cstr(browser->path));
}
Expand Down
44 changes: 27 additions & 17 deletions applications/archive/helpers/archive_browser.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ static const char* tab_default_paths[] = {
[ArchiveTabSubGhz] = "/any/subghz",
[ArchiveTabLFRFID] = "/any/lfrfid",
[ArchiveTabIrda] = "/any/irda",
[ArchiveTabBadUsb] = "/any/badusb",
[ArchiveTabU2f] = "/app:u2f",
[ArchiveTabBrowser] = "/any",
};

Expand All @@ -20,30 +22,37 @@ static const char* known_ext[] = {
[ArchiveFileTypeSubGhz] = ".sub",
[ArchiveFileTypeLFRFID] = ".rfid",
[ArchiveFileTypeIrda] = ".ir",
[ArchiveFileTypeBadUsb] = ".txt",
[ArchiveFileTypeU2f] = "?",
[ArchiveFileTypeFolder] = "?",
[ArchiveFileTypeUnknown] = "*",
};

static inline const char* get_tab_ext(ArchiveTabEnum tab) {
switch(tab) {
case ArchiveTabIButton:
return known_ext[ArchiveFileTypeIButton];
case ArchiveTabNFC:
return known_ext[ArchiveFileTypeNFC];
case ArchiveTabSubGhz:
return known_ext[ArchiveFileTypeSubGhz];
case ArchiveTabLFRFID:
return known_ext[ArchiveFileTypeLFRFID];
case ArchiveTabIrda:
return known_ext[ArchiveFileTypeIrda];
default:
return "*";
}
static const ArchiveFileTypeEnum known_type[] = {
[ArchiveTabFavorites] = ArchiveFileTypeUnknown,
[ArchiveTabIButton] = ArchiveFileTypeIButton,
[ArchiveTabNFC] = ArchiveFileTypeNFC,
[ArchiveTabSubGhz] = ArchiveFileTypeSubGhz,
[ArchiveTabLFRFID] = ArchiveFileTypeLFRFID,
[ArchiveTabIrda] = ArchiveFileTypeIrda,
[ArchiveTabBadUsb] = ArchiveFileTypeBadUsb,
[ArchiveTabU2f] = ArchiveFileTypeU2f,
[ArchiveTabBrowser] = ArchiveFileTypeUnknown,
};

static inline const ArchiveFileTypeEnum archive_get_tab_filetype(ArchiveTabEnum tab) {
return known_type[tab];
}

static inline const char* archive_get_tab_ext(ArchiveTabEnum tab) {
return known_ext[archive_get_tab_filetype(tab)];
}

static inline const char* archive_get_default_path(ArchiveTabEnum tab) {
return tab_default_paths[tab];
}

inline bool is_known_app(ArchiveFileTypeEnum type) {
inline bool archive_is_known_app(ArchiveFileTypeEnum type) {
return (type != ArchiveFileTypeFolder && type != ArchiveFileTypeUnknown);
}

Expand All @@ -62,7 +71,8 @@ uint8_t archive_get_depth(ArchiveBrowserView* browser);
const char* archive_get_path(ArchiveBrowserView* browser);
const char* archive_get_name(ArchiveBrowserView* browser);

void archive_add_item(ArchiveBrowserView* browser, FileInfo* file_info, const char* name);
void archive_add_app_item(ArchiveBrowserView* browser, const char* name);
void archive_add_file_item(ArchiveBrowserView* browser, FileInfo* file_info, const char* name);
void archive_show_file_menu(ArchiveBrowserView* browser, bool show);
void archive_favorites_move_mode(ArchiveBrowserView* browser, bool active);

Expand Down
Loading

0 comments on commit 661b4b1

Please sign in to comment.