virtual bool RemoveFile(const char *pFilename, int Type) { if(Type < 0 || Type >= m_NumPaths) return false; char aBuffer[MAX_PATH_LENGTH]; return !fs_remove(GetPath(Type, pFilename, aBuffer, sizeof(aBuffer))); }
virtual bool RemoveBinaryFile(const char *pFilename) { char aBuffer[MAX_PATH_LENGTH]; GetBinaryPath(pFilename, aBuffer, sizeof(aBuffer)); bool success = !fs_remove(aBuffer); if(!success) dbg_msg("storage", "failed to remove: %s", aBuffer); return success; }
int16_t parse_cmd_fs_remove (char *cmd, char *output, uint16_t len) { /* ignore leading spaces */ while (*cmd == ' ') cmd ++; fs_status_t ret = fs_remove (&fs, cmd); return (ret == FS_OK) ? ECMD_FINAL_OK : ECMD_ERR_PARSE_ERROR; }
void Process(IStorage *pStorage, const char *pMapName, const char *pConfigName) { CDataFileReader Map; if(!Map.Open(pStorage, pMapName, IStorage::TYPE_ALL)) { dbg_msg("config_retrieve", "error opening map '%s'", pMapName); return; } bool ConfigFound = false; int Start, Num; Map.GetType(MAPITEMTYPE_INFO, &Start, &Num); for(int i = Start; i < Start + Num; i++) { int ItemID; CMapItemInfoSettings *pItem = (CMapItemInfoSettings *)Map.GetItem(i, 0, &ItemID); int ItemSize = Map.GetItemSize(i) - 8; if(!pItem || ItemID != 0) continue; if(ItemSize < (int)sizeof(CMapItemInfoSettings)) break; if(!(pItem->m_Settings > -1)) break; ConfigFound = true; IOHANDLE Config = pStorage->OpenFile(pConfigName, IOFLAG_WRITE, IStorage::TYPE_ALL); if(!Config) { dbg_msg("config_retrieve", "error opening config for writing '%s'", pConfigName); return; } int Size = Map.GetUncompressedDataSize(pItem->m_Settings); char *pSettings = (char *)Map.GetData(pItem->m_Settings); char *pNext = pSettings; while(pNext < pSettings + Size) { int StrSize = str_length(pNext) + 1; io_write(Config, pNext, StrSize - 1); io_write_newline(Config); pNext += StrSize; } Map.UnloadData(pItem->m_Settings); io_close(Config); break; } Map.Close(); if(!ConfigFound) { fs_remove(pConfigName); } }
virtual bool RemoveFile(const char *pFilename, int Type) { if(Type < 0 || Type >= m_NumPaths) return false; char aBuffer[MAX_PATH_LENGTH]; GetPath(Type, pFilename, aBuffer, sizeof(aBuffer)); bool success = !fs_remove(aBuffer); if(!success) dbg_msg("storage", "failed to remove: %s", aBuffer); return success; }
/** * Called when the Delete list element is long pressed to remove a file * @param del pointer to the Delete button * @param dispi pointer to the caller display input * @return LV_ACTION_RES_OK because the list is NOT deleted in the function */ static lv_action_res_t win_del_lpr_action(lv_obj_t * del, lv_dispi_t * dispi) { lv_app_inst_t * app = lv_obj_get_free_p(del); my_app_data_t * app_data = app->app_data; char path_fn[LV_APP_FILES_PATH_MAX_LEN + LV_APP_FILES_FN_MAX_LEN]; sprintf(path_fn, "%s/%s", app_data->path, app_data->fn); fs_res_t res = fs_remove(path_fn); if(res == FS_RES_OK) lv_app_notice_add("%s deleted", app_data->fn); else lv_app_notice_add("Can not delete\n%s", app_data->fn); return LV_ACTION_RES_OK; }
int fs_open(char *file_name, int mode) { //printf("Função não implementada: fs_open\n"); int flag = 0, i; if(formatado == 0) { printf("Disco não formatado\n"); return -1; } for (i = 0; i < 128; i++) { if(dir[i].used != '0' && strcmp(dir[i].name,file_name) == 0) { flag = 1; break; } } if ((flag = 0) && (mode == FS_R)) { printf("Arquivo inexistente\n"); return -1; } else { if((flag = 0) && (mode == FS_W)) { i = fs_create(file_name); arquivo[i].aberto = 1; arquivo[i].bytes_lidos = 0; arquivo[i].byte_bloco = 0; arquivo[i].bloco = dir[i].first_block; } else { if((flag = 1) && (mode == FS_R)) { arquivo[i].aberto = 0; 0 arquivo[i].bytes_lidos = 0; arquivo[i].byte_bloco = 0; arquivo[i].bloco = dir[i].first_block; } else { if((flag = 1) && (mode == FS_W)) { fs_remove(file_name); i = fs_create(file_name); arquivo[i].aberto = 1; arquivo[i].bytes_lidos = 0; arquivo[i].byte_bloco = 0; arquivo[i].bloco = dir[i].first_block; } } } } return i; }
bool CUpdater::SelfDelete() { #ifdef CONF_FAMILY_WINDOWS IOHANDLE bhFile = io_open("du.bat", IOFLAG_WRITE); if (!bhFile) return false; const char *fileCode = ":_R\r\ndel \"teeworlds.exe\"\r\nif exist \"teeworlds.exe\" goto _R\r\nrename \"tw_tmp.exe\" \"teeworlds.exe\"\r\n:_T\r\nif not exist \"teeworlds.exe\" goto _T\r\nstart teeworlds.exe\r\ndel \"du.bat\"\r\n\0"; io_write(bhFile, fileCode, str_length(fileCode)); io_close(bhFile); #else fs_remove("teeworlds"); #endif return true; }
/** * Remove given file path. * * def remove(path) */ static mp_obj_t os_remove(mp_obj_t path_in) { const char *path_p; int res; path_p = mp_obj_str_get_str(path_in); res = fs_remove(path_p); if (res != 0) { nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError, "Error removing file '%s'", path_p)); } return (mp_const_none); }
void FifoConsole::ListenFifoThread(void *pUser) { FifoConsole *pData = (FifoConsole *)pUser; if(!gs_FifoLock) { dbg_msg("fifo", "FIFO not properly initialized"); exit(2); } lock_wait(gs_FifoLock); if(gs_stopFifoThread) return; mkfifo(pData->m_pFifoFile, 0600); struct stat attribute; stat(pData->m_pFifoFile, &attribute); if(!S_ISFIFO(attribute.st_mode)) { dbg_msg("fifo", "'%s' is not a FIFO, removing", pData->m_pFifoFile); fs_remove(pData->m_pFifoFile); mkfifo(pData->m_pFifoFile, 0600); stat(pData->m_pFifoFile, &attribute); if(!S_ISFIFO(attribute.st_mode)) { dbg_msg("fifo", "Can't remove file, quitting"); exit(2); } } lock_unlock(gs_FifoLock); std::ifstream f; char aBuf[8192]; while (true) { f.open(pData->m_pFifoFile); while (f.getline(aBuf, sizeof(aBuf))) pData->m_pConsole->ExecuteLineFlag(aBuf, pData->m_flag, -1); f.close(); } }
virtual bool RemoveBinaryFile(const char *pFilename) { char aBuffer[MAX_PATH_LENGTH]; return !fs_remove(GetBinaryPath(pFilename, aBuffer, sizeof(aBuffer))); }
void CUpdater::CheckUpdates(CMenus *pMenus) { dbg_msg("autoupdate", "Checking for updates..."); if (!CHttpDownloader::GetToFile("http://" UPDATES_HOST UPDATES_BASE_PATH UPDATES_MANIFEST_FILE, UPDATES_MANIFEST_FILE)) { dbg_msg("autoupdate", "Error downloading updates manifest :/"); return; } Reset(); IOHANDLE fileAutoUpdate = io_open(UPDATES_MANIFEST_FILE, IOFLAG_READ); io_seek(fileAutoUpdate, 0, IOSEEK_END); std::streamsize size = io_tell(fileAutoUpdate); io_seek(fileAutoUpdate, 0, IOSEEK_START); std::vector<char> buffer(size); if (io_read(fileAutoUpdate, buffer.data(), size)) { bool needUpdate = false; json_settings JsonSettings; mem_zero(&JsonSettings, sizeof(JsonSettings)); char aError[256]; json_value *pJsonNodeMain = json_parse_ex(&JsonSettings, buffer.data(), size, aError); if (pJsonNodeMain == 0) { dbg_msg("autoupdate", "Error: %s", aError); return; } int verCode = -1; for(int j=pJsonNodeMain->u.object.length-1; j>=0; j--) // Ascendent Search: Manifest has descendant order { sscanf((const char *)pJsonNodeMain->u.object.values[j].name, "%d", &verCode); json_value *pNodeCode = pJsonNodeMain->u.object.values[j].value; if (verCode <= HCLIENT_VERSION_CODE) continue; needUpdate = true; const json_value &rVersion = (*pNodeCode)["version"]; str_copy(m_NewVersion, (const char *)rVersion, sizeof(m_NewVersion)); // Need update client? const json_value &rClient = (*pNodeCode)["client"]; m_NeedUpdateClient = (rClient.u.boolean); // Need update server? const json_value &rServer = (*pNodeCode)["server"]; m_NeedUpdateServer = (rServer.u.boolean); // Get files to download const json_value &rDownload = (*pNodeCode)["download"]; for(unsigned k = 0; k < rDownload.u.array.length; k++) AddFileToDownload((const char *)rDownload[k]); // Get files to remove const json_value &rRemove = (*pNodeCode)["remove"]; for(unsigned k = 0; k < rRemove.u.array.length; k++) AddFileToRemove((const char *)rRemove[k]); } if (needUpdate) pMenus->SetPopup(CMenus::POPUP_UPDATER); else m_Updated = true; } io_close(fileAutoUpdate); fs_remove(UPDATES_MANIFEST_FILE); }
void CUpdater::DoUpdates(CMenus *pMenus) { bool noErrors = true; // Remove Files for (int i=0; i<m_vToRemove.size(); i++) if (fs_is_file(m_vToRemove[i].c_str()) && fs_remove(m_vToRemove[i].c_str()) != 0) noErrors = false; m_vToRemove.clear(); // Download Files for (int i=0; i<m_vToDownload.size(); i++) if (!CHttpDownloader::GetToFile(m_vToDownload[i].c_str(), m_vToDownload[i].c_str())) noErrors = false; m_vToDownload.clear(); if (m_NeedUpdateClient) { #ifdef CONF_FAMILY_WINDOWS #ifdef CONF_PLATFORM_WIN64 if (!CHttpDownloader::GetToFile("http://" UPDATES_HOST UPDATES_BASE_PATH "teeworlds64.exe", "tw_tmp")) #else if (!CHttpDownloader::GetToFile("http://" UPDATES_HOST UPDATES_BASE_PATH "teeworlds.exe", "tw_tmp")) #endif #elif defined(CONF_FAMILY_UNIX) #ifdef CONF_PLATFORM_MACOSX if (!CHttpDownloader::GetToFile("http://" UPDATES_HOST UPDATES_BASE_PATH "teeworlds_mac", "tw_tmp")) #elif defined(CONF_ARCH_IA64) || defined(CONF_ARCH_AMD64) if (!CHttpDownloader::GetToFile("http://" UPDATES_HOST UPDATES_BASE_PATH "teeworlds64", "tw_tmp")) #else if (!CHttpDownloader::GetToFile("http://" UPDATES_HOST UPDATES_BASE_PATH "teeworlds", "tw_tmp")) #endif #endif { noErrors = false; } } if (m_NeedUpdateServer) { #ifdef CONF_FAMILY_WINDOWS #ifdef CONF_PLATFORM_WIN64 if (!CHttpDownloader::GetToFile("http://" UPDATES_HOST UPDATES_BASE_PATH "teeworlds_srv64.exe", "teeworlds_srv.exe")) #else if (!CHttpDownloader::GetToFile("http://" UPDATES_HOST UPDATES_BASE_PATH "teeworlds_srv.exe", "teeworlds_srv.exe")) #endif #elif defined(CONF_FAMILY_UNIX) #ifdef CONF_PLATFORM_MACOSX if (!CHttpDownloader::GetToFile("http://" UPDATES_HOST UPDATES_BASE_PATH "teeworlds_srv_mac", "teeworlds_srv")) #elif defined(CONF_ARCH_IA64) || defined(CONF_ARCH_AMD64) if (!CHttpDownloader::GetToFile("http://" UPDATES_HOST UPDATES_BASE_PATH "teeworlds_srv64", "teeworlds_srv")) #else if (!CHttpDownloader::GetToFile("http://" UPDATES_HOST UPDATES_BASE_PATH "teeworlds_srv", "teeworlds_srv")) #endif #endif { noErrors = false; } } if (noErrors) m_Updated = true; pMenus->SetPopup(CMenus::POPUP_UPDATER_RESULT); }
void CMain::JSONUpdateThread(void *pUser) { CJSONUpdateThreadData *m_pJSONUpdateThreadData = (CJSONUpdateThreadData *)pUser; CClient *pClients = m_pJSONUpdateThreadData->pClients; CConfig *pConfig = m_pJSONUpdateThreadData->pConfig; while(gs_Running) { char aFileBuf[2048*NET_MAX_CLIENTS]; char *pBuf = aFileBuf; str_format(pBuf, sizeof(aFileBuf), "{\n\"servers\": [\n"); pBuf += strlen(pBuf); for(int i = 0; i < NET_MAX_CLIENTS; i++) { if(!pClients[i].m_Active || pClients[i].m_Disabled) continue; if(pClients[i].m_Connected) { // Connectivity bool Online4; bool Online6; Online4 = pClients[i].m_Stats.m_Online4; Online6 = pClients[i].m_Stats.m_Online6; // Uptime char aUptime[16]; int Days = pClients[i].m_Stats.m_Uptime/60.0/60.0/24.0; if(Days > 0) { if(Days > 1) str_format(aUptime, sizeof(aUptime), "%d days", Days); else str_format(aUptime, sizeof(aUptime), "%d day", Days); } else str_format(aUptime, sizeof(aUptime), "%02d:%02d:%02d", (int)(pClients[i].m_Stats.m_Uptime/60.0/60.0), (int)((pClients[i].m_Stats.m_Uptime/60)%60), (int)((pClients[i].m_Stats.m_Uptime)%60)); // Load float Load = pClients[i].m_Stats.m_Load; // CPU int CPU = pClients[i].m_Stats.m_CPU; // Memory int Memory; if(pClients[i].m_Stats.m_MemTotal) Memory = round(((float)pClients[i].m_Stats.m_MemUsed/pClients[i].m_Stats.m_MemTotal)*100.0); else Memory = 0; // HDD int HDD; if(pClients[i].m_Stats.m_HDDTotal) HDD = round(((float)pClients[i].m_Stats.m_HDDUsed/pClients[i].m_Stats.m_HDDTotal)*100.0); else HDD = 0; str_format(pBuf, sizeof(aFileBuf) - (pBuf - aFileBuf), "{ \"name\": \"%s\", \"type\": \"%s\", \"host\": \"%s\", \"location\": \"%s\", \"online4\": %s, \"online6\": %s, \"uptime\": \"%s\", \"load\": \"%.2f\", \"network_rx\": %d, \"network_tx\": %d, \"cpu\": %d, \"memory\": %d, \"memory_total\": %" PRId64 ", \"memory_used\": %" PRId64 ", \"hdd\": %d, \"hdd_total\": %" PRId64 ", \"hdd_used\": %" PRId64 " },\n", pClients[i].m_aName, pClients[i].m_aType, pClients[i].m_aHost, pClients[i].m_aLocation, Online4 ? "true" : "false", Online6 ? "true" : "false", aUptime, Load, pClients[i].m_Stats.m_NetworkRx, pClients[i].m_Stats.m_NetworkTx, CPU, Memory, pClients[i].m_Stats.m_MemTotal, pClients[i].m_Stats.m_MemUsed, HDD, pClients[i].m_Stats.m_HDDTotal, pClients[i].m_Stats.m_HDDUsed); pBuf += strlen(pBuf); } else { str_format(pBuf, sizeof(aFileBuf) - (pBuf - aFileBuf), "{ \"name\": \"%s\", \"type\": \"%s\", \"host\": \"%s\", \"location\": \"%s\", \"online4\": false, \"online6\": false },\n", pClients[i].m_aName, pClients[i].m_aType, pClients[i].m_aHost, pClients[i].m_aLocation); pBuf += strlen(pBuf); } } if(!m_pJSONUpdateThreadData->m_ReloadRequired) str_format(pBuf - 2, sizeof(aFileBuf) - (pBuf - aFileBuf), "\n],\n\"updated\": \"%lld\"\n}", (long long)time(/*ago*/0)); else { str_format(pBuf - 2, sizeof(aFileBuf) - (pBuf - aFileBuf), "\n],\n\"updated\": \"%lld\",\n\"reload\": true\n}", (long long)time(/*ago*/0)); m_pJSONUpdateThreadData->m_ReloadRequired--; } pBuf += strlen(pBuf); char aJSONFileTmp[1024]; str_format(aJSONFileTmp, sizeof(aJSONFileTmp), "%s~", pConfig->m_aJSONFile); IOHANDLE File = io_open(aJSONFileTmp, IOFLAG_WRITE); if(!File) { dbg_msg("main", "Couldn't open %s", aJSONFileTmp); exit(1); } io_write(File, aFileBuf, (pBuf - aFileBuf)); io_flush(File); io_close(File); fs_rename(aJSONFileTmp, pConfig->m_aJSONFile); thread_sleep(1000); } fs_remove(pConfig->m_aJSONFile); }
int main(int argc, const char **argv) // ignore_convention { dbg_logger_stdout(); char aPath[256] = {0}; char aPathEscaped[512] = {0}; str_copy(aPath, argv[0], sizeof(aPath)); char *pBackSlash = (char *)str_find_rev(aPath, "\\"); if (pBackSlash) pBackSlash[0] = 0; int x = 0; for (int i = 0; i < str_length(aPath); i++) { aPathEscaped[x++] = aPath[i]; if (aPath[i] == '\\') aPathEscaped[x++] = aPath[i]; } dbg_msg("argv0", argv[0]); dbg_msg("aPath", aPath); dbg_msg("ePath", aPathEscaped); dbg_msg("", "Generating registry information"); IOHANDLE File = io_open("tw.reg", IOFLAG_WRITE); io_write(File, "Windows Registry Editor Version 5.00\n", str_length("Windows Registry Editor Version 5.00\n")); io_write(File, "[HKEY_CLASSES_ROOT\\tw]\n", str_length("[HKEY_CLASSES_ROOT\\tw]\n")); io_write(File, "\"URL Protocol\"=\"\"\n", str_length("\"URL Protocol\"=\"\"\n")); io_write(File, "@=\"URL:Teeworlds Protocol\"\n", str_length("@=\"URL:Teeworlds Protocol\"\n")); io_write(File, "[HKEY_CLASSES_ROOT\\tw\\DefaultIcon]\n", str_length("[HKEY_CLASSES_ROOT\\tw\\DefaultIcon]\n")); io_write(File, "@=\"", str_length("@=\"")); io_write(File, aPathEscaped, str_length(aPathEscaped)); io_write(File, "n-client.exe", str_length("n-client.exe")); io_write(File, "\"\n", str_length("\"\n")); io_write(File, "[HKEY_CLASSES_ROOT\\tw\\shell]\n", str_length("[HKEY_CLASSES_ROOT\\tw\\shell]\n")); io_write(File, "@=\"open\"\n", str_length("@=\"open\"\n")); io_write(File, "[HKEY_CLASSES_ROOT\\tw\\shell\\open]\n", str_length("[HKEY_CLASSES_ROOT\\tw\\shell\\open]\n")); io_write(File, "[HKEY_CLASSES_ROOT\\tw\\shell\\open\\command]\n", str_length("[HKEY_CLASSES_ROOT\\tw\\shell\\open\\command]\n")); io_write(File, "@=\"", str_length("@=\"")); io_write(File, aPathEscaped, str_length(aPathEscaped)); io_write(File, "tw_proto_start.bat %1\"\n", str_length("tw_proto_start.bat %1\"\n")); io_close(File); dbg_msg("", "Registering protocol"); int i = system("tw.reg"); if (i) dbg_msg("", "Errorcode: %i"); dbg_msg("", "Cleaning up"); fs_remove("tw.reg"); return 0; }
static PRESULT hdmi_factest_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2) { struct hdmi_device *hdmi_dev = (struct hdmi_device *)dev_get_by_type(NULL,HLD_DEV_TYPE_HDMI); PRESULT ret = PROC_PASS; UINT8 bID; POBJECT_HEAD nxtObj; POBJECT_HEAD topmenu; bID = OSD_GetObjID(pObj); extern sys_state_t system_state; UINT8 buf[512]; UINT32 v_key, i; FILE *fp; MULTISEL *pMsel; static BOOL log_edid_info = FALSE, log_dbg_info = FALSE, ignore_hotplug = FALSE; switch(event) { case EVN_PRE_OPEN: //ap_enable_key_task_get_key(TRUE); //key_set_upgrade_check_flag(0); last_system_state = system_state; //system_state = SYS_STATE_UPGRAGE_HOST; memset(hdmi_info_name_str,0x00,sizeof(hdmi_info_name_str)); memset(hdmi_info1_str,0x00,sizeof(hdmi_info1_str)); memset(hdmi_info2_str,0x00,sizeof(hdmi_info2_str)); memset(hdmi_info3_str,0x00,sizeof(hdmi_info3_str)); memset(hdmi_info4_str,0x00,sizeof(hdmi_info4_str)); wincom_close_title(); if(menu_stack_get(0) == (POBJECT_HEAD)&g_win_mainmenu) { OSD_ClearObject( (POBJECT_HEAD) &g_win_mainmenu, C_UPDATE_ALL); topmenu = menu_stack_get_top(); if(topmenu) OSD_ClearObject( topmenu, C_UPDATE_ALL); } break; case EVN_POST_OPEN: hdmi_dev->io_control(hdmi_dev,HDMI_CMD_REG_CALLBACK, HDMI_CB_DBG_MSG, (UINT32)hdmi_debug_message_callback); hdmi_display_info_set(); break; case EVN_POST_CLOSE: if(menu_stack_get(0) == (POBJECT_HEAD)&g_win_mainmenu) OSD_TrackObject( (POBJECT_HEAD) &g_win_mainmenu, C_UPDATE_ALL); system_state = last_system_state; break; case EVN_UNKNOWN_ACTION: break; case EVN_UNKNOWNKEY_GOT: ap_hk_to_vk(0, param1, &v_key); switch(v_key) { case V_KEY_RED: // Red Button : Log EDID Information //old IR Red key is 65 if(log_edid_info == FALSE) { log_edid_info = TRUE; // Check log file exist or not, if exist delete it. edid_log_file= fs_open("/c/hdmi_edid_log.txt", O_RDONLY, 0666); // if(edid_log_file >= 0) /*always is true ,clean the warning */ { fs_close(edid_log_file); fs_remove("/c/hdmi_edid_log.txt"); } edid_log_file = fs_open("/c/hdmi_edid_log.txt", O_RDWR | O_CREAT, S_IFREG | S_IRWXU); hdmi_log_edid_start(); win_com_popup_open(WIN_POPUP_TYPE_SMSG,"Start to Log EDID Information", 0); } else { log_edid_info = FALSE; fs_close( edid_log_file ); fs_sync("/c/"); hdmi_log_edid_stop(); win_com_popup_open(WIN_POPUP_TYPE_SMSG,"Stop to Log EDID Information", 0); } osal_task_sleep(2000); win_compopup_close(); hdmi_display_info_set(); break; case V_KEY_GREEN: // Green Button : Log debug Information if(log_dbg_info == FALSE) { log_dbg_info = TRUE; // Check log file exist or not, if exist delete it. debug_log_file= fs_open("/c/hdmi_debug_log.txt", O_RDONLY, 0666); // if(debug_log_file >= 0) /*always is true ,clean the warning */ { fs_close(debug_log_file); fs_remove("/c/hdmi_debug_log.txt"); } debug_log_file = fs_open("/c/hdmi_debug_log.txt", O_RDWR | O_CREAT, S_IFREG | S_IRWXU); hdmi_log_debug_start(); win_com_popup_open(WIN_POPUP_TYPE_SMSG,"Start to Log Debug Information", 0); } else { log_dbg_info = FALSE; fs_close( debug_log_file ); fs_sync("/c/"); hdmi_log_debug_stop(); win_com_popup_open(WIN_POPUP_TYPE_SMSG,"Stop to Log Debug Information", 0); } osal_task_sleep(2000); win_compopup_close(); hdmi_display_info_set(); break; case V_KEY_YELLOW: // Yellow Button : Switch on/off HDCP if(api_get_hdmi_hdcp_onoff() == TRUE) { api_set_hdmi_hdcp_onoff(FALSE); win_com_popup_open(WIN_POPUP_TYPE_SMSG,"Turn HDCP Off", 0); } else { api_set_hdmi_hdcp_onoff(TRUE); win_com_popup_open(WIN_POPUP_TYPE_SMSG,"Turn HDCP On", 0); } osal_task_sleep(2000); win_compopup_close(); hdmi_display_info_set(); break; default: break; } break; } return ret; }
int io_remv(const char *name) { return fs_remove(io_find(name)); }
/* pre: takes in int 'argc' and char** 'argv' command line arguments which * include: * -f <file_list> * -d <dir_list> * -s <disk size> * -b <block size> * post: runs the filesystem simulation program * return: 0 on sucessful exit, something else on error */ int main(int argc, char** argv) { int n; char* line; char** v; /* parse args and setup global environment */ parse_args(argc, argv); /* read input files and initialize filesystem */ init(); /* main command reading loop */ line = (char*)malloc(CMD_LEN * sizeof(char)); bzero((void*)line, CMD_LEN * sizeof(char)); while (1) { /* prompt */ printf("%s ", PROMPT); fflush(stdout); /* fd 0 is stdin */ if ((n = read(0, line, CMD_LEN)) == -1) { perror(argv[0]); fs_exit(); exit(-1); } else if (n == 0) { fs_exit(); break; } else { /* overwrite newline with NULL-byte */ line[n - 1] = '\0'; #ifdef DEBUG printf("[DEBUG]\tRead line: <%s>\n", line); fflush(stdout); #endif /* use str2vect to break 'line' into a list of whitespace separated * strings */ v = str2vect(line); /* check for commands and execute the proper function */ if (!strcmp(v[0], "append")) { if (v[1] != NULL && v[2] != NULL) fs_append(v[1], atoi(v[2])); else { printf("usage: append name size\n"); fflush(stdout); } } else if (!strcmp(v[0], "cd")) { if (v[1] != NULL) fs_cd(v[1]); else { printf("usage: cd directory\n"); fflush(stdout); } } else if (!strcmp(v[0], "cd..")) /* just in case this is the intended command */ { fs_cd(".."); } else if (!strcmp(v[0], "create")) { if (v[1] != NULL) fs_create(v[1]); else { printf("usage: create name\n"); fflush(stdout); } } else if (!strcmp(v[0], "delete")) { if (v[1] != NULL) fs_delete(v[1]); else { printf("usage: delete name\n"); fflush(stdout); } } else if (!strcmp(v[0], "dir")) { fs_dir(); } else if (!strcmp(v[0], "exit")) { /* free the vector immediately and break to exit */ free_vect(v); break; } else if (!strcmp(v[0], "ls")) { fs_ls(); } else if (!strcmp(v[0], "mkdir")) { if (v[1] != NULL) fs_mkdir(v[1]); else { printf("usage: mkdir directory\n"); fflush(stdout); } } else if (!strcmp(v[0], "prdisk")) { fs_prdisk(); } else if (!strcmp(v[0], "prfiles")) { fs_prfiles(); } else if (!strcmp(v[0], "remove")) { if (v[1] != NULL && v[2] != NULL) fs_remove(v[1], atoi(v[2])); else { printf("usage: remove name size\n"); fflush(stdout); } } else { printf("%s: command not found: %s\n", argv[0], v[0]); fflush(stdout); } /* free the vector to avoid memory leaks */ free_vect(v); } } free(line); fs_exit(); return 0; }
void user_init(void) { uart_set_baud(0, 921600); printf("\n\nESP8266 UMAC\n\n"); bridge_init(); umac_cfg um_cfg = { .timer_fn = umac_impl_request_future_tick, .cancel_timer_fn = umac_impl_cancel_future_tick, .now_fn = umac_impl_now_tick, .tx_byte_fn = umac_impl_tx_byte, .tx_buf_fn = umac_impl_tx_buf, .rx_pkt_fn = umac_impl_rx_pkt, .rx_pkt_ack_fn = bridge_pkt_acked, .timeout_fn = bridge_timeout, .nonprotocol_data_fn = NULL }; umac_init(&um, &um_cfg, rx_buf); um_tim_hdl = xTimerCreate( (signed char *)"umac_tim", 10, false, (void *)um_tim_id, um_tim_cb); char ap_cred[128]; struct sdk_station_config config; bool setup_ap = true; systask_init(); device_id = 0; fs_init(); if (fs_mount() >= 0) { #if 0 spiffs_DIR d; struct spiffs_dirent e; struct spiffs_dirent *pe = &e; fs_opendir("/", &d); while ((pe = fs_readdir(&d, pe))) { printf("%s [%04x] size:%i\n", pe->name, pe->obj_id, pe->size); } fs_closedir(&d); #endif // read preferred ssid spiffs_file fd_ssid = fs_open(".ssid", SPIFFS_RDONLY, 0); if (fd_ssid > 0) { if (fs_read(fd_ssid, (uint8_t *)ap_cred, sizeof(ap_cred)) > 0) { fs_close(fd_ssid); char *nl_ix = strchr(ap_cred, '\n'); if (nl_ix > 0) { memset(&config, 0, sizeof(struct sdk_station_config)); strncpy((char *)&config.ssid, ap_cred, nl_ix - ap_cred); char *nl_ix2 = strchr(nl_ix + 1, '\n'); if (nl_ix2 > 0) { strncpy((char *)&config.password, nl_ix + 1, nl_ix2 - (nl_ix + 1)); setup_ap = false; } } printf("ssid:%s\n", config.ssid); } // if read else { printf("could not read .ssid\n"); } } // if fs_ssid else { printf("no .ssid found, running softAP\n"); } // find device id or create one spiffs_file fd_devid = fs_open(".devid", SPIFFS_RDONLY, 0); if (fd_devid < 0) { device_id = hwrand(); fd_devid = fs_open(".devid", SPIFFS_O_CREAT | SPIFFS_O_TRUNC | SPIFFS_O_WRONLY | SPIFFS_O_APPEND, 0); fs_write(fd_devid, &device_id, 4); printf("create devid\n"); } else { fs_read(fd_devid, &device_id, 4); } fs_close(fd_devid); printf("devid %08x\n", device_id); // remove previous scan results fs_remove(SYSTASK_AP_SCAN_FILENAME); } // if mount if (setup_ap) { sdk_wifi_set_opmode(SOFTAP_MODE); struct ip_info ap_ip; IP4_ADDR(&ap_ip.ip, 192, 169, 1, 1); IP4_ADDR(&ap_ip.gw, 0, 0, 0, 0); IP4_ADDR(&ap_ip.netmask, 255, 255, 255, 0); sdk_wifi_set_ip_info(1, &ap_ip); struct sdk_softap_config ap_cfg = { .ssid = "WISLEEP", .password = "", .ssid_len = 7, .channel = 1, .authmode = AUTH_OPEN, .ssid_hidden = false, .max_connection = 255, .beacon_interval = 100 }; sdk_wifi_softap_set_config(&ap_cfg); ip_addr_t first_client_ip; IP4_ADDR(&first_client_ip, 192, 169, 1, 100); dhcpserver_start(&first_client_ip, 4); } else { // required to call wifi_set_opmode before station_set_config sdk_wifi_set_opmode(STATION_MODE); sdk_wifi_station_set_config(&config); } server_init(server_actions); um_mutex = xSemaphoreCreateMutex(); xTaskCreate(uart_task, (signed char * )"uart_task", 512, NULL, 2, NULL); xTaskCreate(server_task, (signed char *)"server_task", 1024, NULL, 2, NULL); }