/* These two functions are called by the USB and shutdown handlers */ void tree_flush(void) { #ifdef HAVE_TAGCACHE tagcache_shutdown(); #endif #ifdef HAVE_TC_RAMCACHE tagcache_unload_ramcache(); #endif #ifdef HAVE_DIRCACHE { int old_val = global_status.dircache_size; if (global_settings.dircache) { if (!dircache_is_initializing()) global_status.dircache_size = dircache_get_cache_size(); # ifdef HAVE_EEPROM_SETTINGS if (firmware_settings.initialized) dircache_save(); # endif dircache_disable(); } else { global_status.dircache_size = 0; } if (old_val != global_status.dircache_size) status_save(); } #endif }
static int load_plugin_screen(char *plug_path) { int ret_val; int old_previous = last_screen; last_screen = next_screen; global_status.last_screen = (char)next_screen; status_save(); switch (plugin_load(plug_path, NULL)) { case PLUGIN_GOTO_WPS: ret_val = GO_TO_WPS; break; case PLUGIN_OK: ret_val = audio_status() ? GO_TO_PREVIOUS : GO_TO_ROOT; break; default: ret_val = GO_TO_PREVIOUS; break; } if (ret_val == GO_TO_PREVIOUS) last_screen = (old_previous == next_screen) ? GO_TO_ROOT : old_previous; return ret_val; }
static inline int load_screen(int screen) { /* set the global_status.last_screen before entering, if we dont we will always return to the wrong screen on boot */ int old_previous = last_screen; int ret_val; enum current_activity activity = ACTIVITY_UNKNOWN; if (screen <= GO_TO_ROOT) return screen; if (screen == old_previous) old_previous = GO_TO_ROOT; global_status.last_screen = (char)screen; status_save(); if (screen == GO_TO_BROWSEPLUGINS) activity = ACTIVITY_PLUGINBROWSER; else if (screen == GO_TO_MAINMENU) activity = ACTIVITY_SETTINGS; else if (screen == GO_TO_SYSTEM_SCREEN) activity = ACTIVITY_SYSTEMSCREEN; if (activity != ACTIVITY_UNKNOWN) push_current_activity(activity); ret_val = items[screen].function(items[screen].param); if (activity != ACTIVITY_UNKNOWN) pop_current_activity(); last_screen = screen; if (ret_val == GO_TO_PREVIOUS) last_screen = old_previous; return ret_val; }
void remember_frequency(void) { const struct fm_region_data * const fmr = &fm_region_data[global_settings.fm_region]; global_status.last_frequency = (curr_freq - fmr->freq_min) / fmr->freq_step; status_save(); }
static inline int load_screen(int screen) { /* set the global_status.last_screen before entering, if we dont we will always return to the wrong screen on boot */ int old_previous = last_screen; int ret_val; if (screen <= GO_TO_ROOT) return screen; if (screen == old_previous) old_previous = GO_TO_ROOT; global_status.last_screen = (char)screen; status_save(); ret_val = items[screen].function(items[screen].param); last_screen = screen; if (ret_val == GO_TO_PREVIOUS) last_screen = old_previous; return ret_val; }
int ICACHE_FLASH_ATTR cgiApi(HttpdConnData *connData) { struct ApiData *api = (struct ApiData *)connData->cgiPrivData; int nbytes, status; char type; if (connData->conn == NULL) { goto done; } if (connData->requestType != HTTPD_METHOD_POST) { httpdStartResponse(connData, 501); httpdHeader(connData, "Content-Type", "text/html"); httpdEndHeaders(connData); return HTTPD_CGI_DONE; } if (connData->post->received <= MAX_POST) { api = malloc(sizeof(struct ApiData)); jsonparse_setup(&api->state, api->buff, MAX_POST); api->buffLen = 0; api->depth = 0; api->status = API_OK; connData->cgiPrivData = api; } if (api->status < API_OK) { goto finish; } while (true) { nbytes = API_MAX_BUFF - api->buffLen - 1; nbytes = connData->post->buffLen < nbytes ? connData->post->buffLen : nbytes; memcpy(&api->buff[api->buffLen], connData->post->buff, nbytes); api->buffLen += nbytes; memmove(connData->post->buff, &connData->post->buff[nbytes], connData->post->buffLen - nbytes); connData->post->buffLen -= nbytes; if (connData->post->buffLen == 0) { if (connData->post->received < connData->post->len) { return HTTPD_CGI_MORE; } break; } while (api->state.pos < API_MIN_CHUNK) { type = jsonparse_next(&api->state); if (type == ',') { /* do nothing */ } else if (type == '[') { api->depth = api->state.depth; } else { api->status = API_ERROR_PARSE; goto finish; } if ((status = api_parse(&api->state)) != API_OK) { api->status = status; if (status < API_OK) { goto finish; } } while (api->state.depth > api->depth) { if (!jsonparse_next(&api->state)) { api->status = API_ERROR_PARSE; goto finish; } } } memmove(api->buff, &api->buff[api->state.pos], api->buffLen - api->state.pos); api->buffLen -= api->state.pos; api->state.pos = 0; } api->buff[api->buffLen] = '\0'; api->state.len = api->buffLen; while (true) { type = jsonparse_next(&api->state); if (type == ',') { /* do nothing */ } else if (type == '[') { api->depth = api->state.depth; } else { if (api->state.error != JSON_ERROR_OK) { api->status = API_ERROR_PARSE; } goto finish; } if ((status = api_parse(&api->state)) != API_OK) { api->status = status; if (status < API_OK) { goto finish; } } while (api->state.depth > api->depth) { if (!jsonparse_next(&api->state)) { api->status = API_ERROR_PARSE; goto finish; } } } finish: if (connData->post->received < connData->post->len) { return HTTPD_CGI_MORE; } if (api->status < API_OK) { httpdStartResponse(connData, 500); httpdHeader(connData, "Content-Type", "text/html"); httpdEndHeaders(connData); goto done; } httpdStartResponse(connData, 200); httpdHeader(connData, "Content-Type", "application/json"); httpdEndHeaders(connData); httpdSend(connData, api->status == API_OK ? "true" : "false", -1); if (api_update) { api_update = false; master_update(true); } if (status_dirty) { status_save(); } done: free(api); connData->cgiPrivData = NULL; return HTTPD_CGI_DONE; }
static int init_dircache(bool preinit) { #ifdef HAVE_DIRCACHE int result = 0; bool clear = false; if (preinit) dircache_init(); if (!global_settings.dircache) return 0; # ifdef HAVE_EEPROM_SETTINGS if (firmware_settings.initialized && firmware_settings.disk_clean && preinit) { result = dircache_load(); if (result < 0) { firmware_settings.disk_clean = false; if (global_status.dircache_size <= 0) { /* This will be in default language, settings are not applied yet. Not really any easy way to fix that. */ splash(0, str(LANG_SCANNING_DISK)); clear = true; } dircache_build(global_status.dircache_size); } } else # endif { if (preinit) return -1; if (!dircache_is_enabled() && !dircache_is_initializing()) { if (global_status.dircache_size <= 0) { splash(0, str(LANG_SCANNING_DISK)); clear = true; } result = dircache_build(global_status.dircache_size); } if (result < 0) { /* Initialization of dircache failed. Manual action is * necessary to enable dircache again. */ splashf(0, "Dircache failed, disabled. Result: %d", result); global_settings.dircache = false; } } if (clear) { backlight_on(); show_logo(); global_status.dircache_size = dircache_get_cache_size(); status_save(); } return result; #else (void)preinit; return 0; #endif }
int ft_enter(struct tree_context* c) { int rc = GO_TO_PREVIOUS; char buf[MAX_PATH]; struct entry* file = tree_get_entry_at(c, c->selected_item); int file_attr = file->attr; if (c->currdir[1]) snprintf(buf,sizeof(buf),"%s/%s",c->currdir, file->name); else snprintf(buf,sizeof(buf),"/%s",file->name); if (file_attr & ATTR_DIRECTORY) { memcpy(c->currdir, buf, sizeof(c->currdir)); if ( c->dirlevel < MAX_DIR_LEVELS ) c->selected_item_history[c->dirlevel] = c->selected_item; c->dirlevel++; c->selected_item=0; } else { int seed = current_tick; bool play = false; int start_index=0; switch ( file_attr & FILE_ATTR_MASK ) { case FILE_ATTR_M3U: if (!bookmark_autoload(buf)) playlist_viewer_ex(buf); break; case FILE_ATTR_AUDIO: if (bookmark_autoload(c->currdir)) break; splash(0, ID2P(LANG_WAIT)); /* about to create a new current playlist... allow user to cancel the operation */ if (!warn_on_pl_erase()) break; if (global_settings.party_mode && audio_status()) { playlist_insert_track(NULL, buf, PLAYLIST_INSERT_LAST, true, true); splash(HZ, ID2P(LANG_QUEUE_LAST)); } else if (playlist_create(c->currdir, NULL) != -1) { start_index = ft_build_playlist(c, c->selected_item); if (global_settings.playlist_shuffle) { start_index = playlist_shuffle(seed, start_index); /* when shuffling dir.: play all files even if the file selected by user is not the first one */ if (!global_settings.play_selected) start_index = 0; } playlist_start(start_index, 0); play = true; } break; #if CONFIG_TUNER /* fmr preset file */ case FILE_ATTR_FMR: splash(0, ID2P(LANG_WAIT)); /* Preset inside the default folder. */ if(!strncasecmp(FMPRESET_PATH, buf, strlen(FMPRESET_PATH))) { set_file(buf, global_settings.fmr_file, MAX_FILENAME); radio_load_presets(global_settings.fmr_file); } /* * Preset outside default folder, we can choose such only * if we are out of the radio screen, so the check for the * radio status isn't neccessary */ else { radio_load_presets(buf); } rc = GO_TO_FM; break; case FILE_ATTR_FMS: splash(0, ID2P(LANG_WAIT)); set_file(buf, (char *)global_settings.fms_file, MAX_FILENAME); settings_apply_skins(); break; #ifdef HAVE_REMOTE_LCD case FILE_ATTR_RFMS: splash(0, ID2P(LANG_WAIT)); set_file(buf, (char *)global_settings.rfms_file, MAX_FILENAME); settings_apply_skins(); break; #endif #endif #ifdef HAVE_LCD_BITMAP case FILE_ATTR_SBS: splash(0, ID2P(LANG_WAIT)); set_file(buf, (char *)global_settings.sbs_file, MAX_FILENAME); settings_apply_skins(); break; #endif #ifdef HAVE_REMOTE_LCD case FILE_ATTR_RSBS: splash(0, ID2P(LANG_WAIT)); set_file(buf, (char *)global_settings.rsbs_file, MAX_FILENAME); settings_apply_skins(); break; #endif /* wps config file */ case FILE_ATTR_WPS: splash(0, ID2P(LANG_WAIT)); set_file(buf, (char *)global_settings.wps_file, MAX_FILENAME); settings_apply_skins(); break; #if defined(HAVE_REMOTE_LCD) && (NB_SCREENS > 1) /* remote-wps config file */ case FILE_ATTR_RWPS: splash(0, ID2P(LANG_WAIT)); set_file(buf, (char *)global_settings.rwps_file, MAX_FILENAME); settings_apply_skins(); break; #endif case FILE_ATTR_CFG: splash(0, ID2P(LANG_WAIT)); if (!settings_load_config(buf,true)) break; splash(HZ, ID2P(LANG_SETTINGS_LOADED)); break; case FILE_ATTR_BMARK: splash(0, ID2P(LANG_WAIT)); bookmark_load(buf, false); rc = GO_TO_FILEBROWSER; break; case FILE_ATTR_LNG: splash(0, ID2P(LANG_WAIT)); if (lang_core_load(buf)) { splash(HZ, ID2P(LANG_FAILED)); break; } set_file(buf, (char *)global_settings.lang_file, MAX_FILENAME); talk_init(); /* use voice of same language */ viewportmanager_theme_changed(THEME_LANGUAGE); settings_apply_skins(); splash(HZ, ID2P(LANG_LANGUAGE_LOADED)); break; #ifdef HAVE_LCD_BITMAP case FILE_ATTR_FONT: ft_load_font(buf); break; case FILE_ATTR_KBD: splash(0, ID2P(LANG_WAIT)); if (!load_kbd(buf)) splash(HZ, ID2P(LANG_KEYBOARD_LOADED)); set_file(buf, (char *)global_settings.kbd_file, MAX_FILENAME); break; #endif #if (CONFIG_PLATFORM & PLATFORM_NATIVE) /* firmware file */ case FILE_ATTR_MOD: splash(0, ID2P(LANG_WAIT)); audio_hard_stop(); rolo_load(buf); break; #endif /* plugin file */ case FILE_ATTR_ROCK: case FILE_ATTR_LUA: { char *plugin = buf, *argument = NULL, lua_path[MAX_PATH]; int ret; if ((file_attr & FILE_ATTR_MASK) == FILE_ATTR_LUA) { snprintf(lua_path, sizeof(lua_path)-1, "%s/lua.rock", VIEWERS_DIR); /* Use a #define here ? */ plugin = lua_path; argument = buf; } if (global_settings.party_mode && audio_status()) { splash(HZ, ID2P(LANG_PARTY_MODE)); break; } ret = plugin_load(plugin, argument); switch (ret) { case PLUGIN_GOTO_WPS: play = true; break; case PLUGIN_USB_CONNECTED: if(*c->dirfilter > NUM_FILTER_MODES) /* leave sub-browsers after usb, doing otherwise might be confusing to the user */ rc = GO_TO_ROOT; else rc = GO_TO_FILEBROWSER; break; /* case PLUGIN_ERROR: case PLUGIN_OK: */ default: break; } break; } case FILE_ATTR_CUE: display_cuesheet_content(buf); break; default: { const char* plugin; if (global_settings.party_mode && audio_status()) { splash(HZ, ID2P(LANG_PARTY_MODE)); break; } struct entry* file = tree_get_entry_at(c, c->selected_item); plugin = filetype_get_plugin(file); if (plugin) { switch (plugin_load(plugin,buf)) { case PLUGIN_USB_CONNECTED: rc = GO_TO_FILEBROWSER; break; case PLUGIN_GOTO_WPS: rc = GO_TO_WPS; break; /* case PLUGIN_OK: case PLUGIN_ERROR: */ default: break; } } break; } } if ( play ) { /* the resume_index must always be the index in the shuffled list in case shuffle is enabled */ global_status.resume_index = start_index; global_status.resume_offset = 0; status_save(); rc = GO_TO_WPS; } else { if (*c->dirfilter > NUM_FILTER_MODES && *c->dirfilter != SHOW_CFG && *c->dirfilter != SHOW_FONT && *c->dirfilter != SHOW_PLUGINS) { rc = GO_TO_ROOT; } } } return rc; }