int Init(const char *pApplicationName, int StorageType, int NumArgs, const char **ppArguments) { // get userdir fs_storage_path(pApplicationName, m_aUserdir, sizeof(m_aUserdir)); // get datadir FindDatadir(ppArguments[0]); // get currentdir if(!fs_getcwd(m_aCurrentdir, sizeof(m_aCurrentdir))) m_aCurrentdir[0] = 0; // load paths from storage.cfg LoadPaths(ppArguments[0]); if(!m_NumPaths) { dbg_msg("storage", "using standard paths"); AddDefaultPaths(); } // add save directories if(StorageType != STORAGETYPE_BASIC) { if(m_NumPaths && (!m_aaStoragePaths[TYPE_SAVE][0] || !fs_makedir(m_aaStoragePaths[TYPE_SAVE]))) { char aPath[MAX_PATH_LENGTH]; if(StorageType == STORAGETYPE_CLIENT) { fs_makedir(GetPath(TYPE_SAVE, "screenshots", aPath, sizeof(aPath))); fs_makedir(GetPath(TYPE_SAVE, "screenshots/auto", aPath, sizeof(aPath))); fs_makedir(GetPath(TYPE_SAVE, "maps", aPath, sizeof(aPath))); fs_makedir(GetPath(TYPE_SAVE, "downloadedmaps", aPath, sizeof(aPath))); fs_makedir(GetPath(TYPE_SAVE, "downloadedassets", aPath, sizeof(aPath))); fs_makedir(GetPath(TYPE_SAVE, "downloadedassets/universes", aPath, sizeof(aPath))); fs_makedir(GetPath(TYPE_SAVE, "downloadedassets/worlds", aPath, sizeof(aPath))); fs_makedir(GetPath(TYPE_SAVE, "downloadedassets/lands", aPath, sizeof(aPath))); fs_makedir(GetPath(TYPE_SAVE, "skins", aPath, sizeof(aPath))); } fs_makedir(GetPath(TYPE_SAVE, "assets", aPath, sizeof(aPath))); fs_makedir(GetPath(TYPE_SAVE, "assets/universes", aPath, sizeof(aPath))); fs_makedir(GetPath(TYPE_SAVE, "assets/worlds", aPath, sizeof(aPath))); fs_makedir(GetPath(TYPE_SAVE, "assets/lands", aPath, sizeof(aPath))); fs_makedir(GetPath(TYPE_SAVE, "editorresources", aPath, sizeof(aPath))); fs_makedir(GetPath(TYPE_SAVE, "dumps", aPath, sizeof(aPath))); fs_makedir(GetPath(TYPE_SAVE, "demos", aPath, sizeof(aPath))); fs_makedir(GetPath(TYPE_SAVE, "demos/auto", aPath, sizeof(aPath))); fs_makedir(GetPath(TYPE_SAVE, "configs", aPath, sizeof(aPath))); } else { dbg_msg("storage", "unable to create save directory"); return 1; } } return m_NumPaths ? 0 : 1; }
static char *get_filename(const char **extensions) { static char result[16]; Menu *filemenu; char *namebuf; char cwd[1024]; unsigned long p_num, dummy; GPDIRENTRY gpentry; GPFILEATTR gpentry_attr; int selected; unsigned int i, j; fs_chdir("."); do { fs_getcwd(cwd, sizeof(cwd)); GpDirEnumNum(cwd, &p_num); filemenu = malloc((p_num+1) * sizeof(Menu)); if (filemenu == NULL) return NULL; namebuf = malloc(p_num * 16); if (namebuf == NULL) { free(filemenu); return NULL; } for (i = 0, j = 0; i < p_num; i++) { GpDirEnumList(cwd, i, 1, &gpentry, &dummy); if (strcmp(gpentry.name, ".") == 0) continue; GpFileAttr(gpentry.name, &gpentry_attr); if ((gpentry_attr.attr & 16) || valid_extension(gpentry.name, extensions)) { memcpy(namebuf + j * 16, gpentry.name, 16); filemenu[j].label = namebuf + j * 16; filemenu[j].default_opt = NULL; filemenu[j].cur_opt = gpentry_attr.attr; filemenu[j].num_opts = 0; filemenu[j].select_callback = NULL; filemenu[j].modify_callback = NULL; j++; } } filemenu[j].label = NULL; qsort(filemenu, j, sizeof(Menu), dirsort); selected = show_menu(filemenu, 1, 1, 38, 18); if (selected >= 0) { if (filemenu[selected].cur_opt & 16) { fs_chdir(filemenu[selected].label); selected = 0; } else { memcpy(result, filemenu[selected].label, 16); selected = -2; } } free(namebuf); free(filemenu); } while (selected >= 0); if (selected == -2) return result; return NULL; }
int Init(const char *pApplicationName, int StorageType, int NumArgs, const char **ppArguments) { // get userdir fs_storage_path(pApplicationName, m_aUserdir, sizeof(m_aUserdir)); // get datadir FindDatadir(ppArguments[0]); // get currentdir if(!fs_getcwd(m_aCurrentdir, sizeof(m_aCurrentdir))) m_aCurrentdir[0] = 0; // load paths from storage.cfg LoadPaths(ppArguments[0]); if(!m_NumPaths) { dbg_msg("storage", "using standard paths"); AddDefaultPaths(); } // add save directories if(StorageType != STORAGETYPE_BASIC && m_NumPaths && (!m_aaStoragePaths[TYPE_SAVE][0] || !fs_makedir(m_aaStoragePaths[TYPE_SAVE]))) { char aPath[MAX_PATH_LENGTH]; if(StorageType == STORAGETYPE_CLIENT) { fs_makedir(GetPath(TYPE_SAVE, "screenshots", aPath, sizeof(aPath))); fs_makedir(GetPath(TYPE_SAVE, "screenshots/auto", aPath, sizeof(aPath))); fs_makedir(GetPath(TYPE_SAVE, "screenshots/auto/stats", aPath, sizeof(aPath))); fs_makedir(GetPath(TYPE_SAVE, "maps", aPath, sizeof(aPath))); fs_makedir(GetPath(TYPE_SAVE, "downloadedmaps", aPath, sizeof(aPath))); fs_makedir(GetPath(TYPE_SAVE, "identities", aPath, sizeof(aPath))); fs_makedir(GetPath(TYPE_SAVE, "tmp", aPath, sizeof(aPath))); fs_makedir(GetPath(TYPE_SAVE, "tmp/cache", aPath, sizeof(aPath))); fs_makedir("rsa"); } fs_makedir(GetPath(TYPE_SAVE, "dumps", aPath, sizeof(aPath))); fs_makedir(GetPath(TYPE_SAVE, "dumps/console_local", aPath, sizeof(aPath))); fs_makedir(GetPath(TYPE_SAVE, "dumps/console_remote", aPath, sizeof(aPath))); fs_makedir(GetPath(TYPE_SAVE, "dumps/memory", aPath, sizeof(aPath))); fs_makedir(GetPath(TYPE_SAVE, "dumps/tilelayer", aPath, sizeof(aPath))); fs_makedir(GetPath(TYPE_SAVE, "dumps/network", aPath, sizeof(aPath))); fs_makedir(GetPath(TYPE_SAVE, "demos", aPath, sizeof(aPath))); fs_makedir(GetPath(TYPE_SAVE, "demos/auto", aPath, sizeof(aPath))); fs_makedir(GetPath(TYPE_SAVE, "editor", aPath, sizeof(aPath))); fs_makedir(GetPath(TYPE_SAVE, "ghosts", aPath, sizeof(aPath))); } return m_NumPaths ? 0 : 1; }
/* pwd command */ LOCAL void cmd_pwd(INT ac, B *av[]) { B buf[FILENAME_MAX + 1]; ER er; er = fs_getcwd(buf, sizeof(buf) -1); if (er >= E_OK) { P("== '%s'\n", buf); } else { P("fs_getcwd(..) ERR [%#x]\n", er); } }
IStorage *CreateLocalStorage() { CStorage *pStorage = new CStorage(); if(pStorage) { if(!fs_getcwd(pStorage->m_aCurrentdir, sizeof(pStorage->m_aCurrentdir))) { delete pStorage; return NULL; } pStorage->AddPath("$CURRENTDIR"); } return pStorage; }
void app_shell(void){ timers_add_timer(0, 500, blinkCBack); canvas = (Canvas*)sdk_prc_getCanvas(); sdk_scr_clearScreen(canvas, SCR_COLOR_BLACK); if (mount_drive_and_mkfs_if_needed(canvas) == 2) while(1){}; fs_getcwd(current_path, 256); sdk_scr_printf(canvas, "CR Shell. Version 1.0.\nWelcome!\nType 'help' for commands list\n"); sdk_scr_printf(canvas, "%s>", current_path); while(1){ if (sdk_prc_is_focused()){ if (sdk_prc_haveNewMessage()){ sdk_prc_handleMessage(msgHandlerShell); } } } }
/* ls command */ LOCAL void cmd_ls(INT ac, B *av[]) { ER er; DIR *dir; struct dirent ent, *entp; B path[FILENAME_MAX + 1]; struct stat_ms st; struct tm ctm; INT n, opt; opt = 0; for (n = 1; n < ac; n++) { if (*av[n] != '-') break; switch(*(av[n] + 1)) { case 't': opt |= 0x01; break; case 'a': opt |= 0x02; break; } } if (ac <= n) { fs_getcwd(path, sizeof(path) -1); } else { strcpy(path, av[n]); } dir = opendir(path); if (dir == NULL) { P("opendir ERR\n"); return; } n = strlen(path); path[n++] = '/'; while (readdir_r(dir, &ent, &entp) >= 0) { if (entp == NULL) break; if (strcmp(entp->d_name, ".") == 0 || strcmp(entp->d_name, "..") == 0) continue; strcpy(&path[n], entp->d_name); er = fs_stat_ms(path, &st); if (er < E_OK) { P("fs_stat(%s) ERR [%#x]\n", path, er); continue; } dt_localtime_ms(&st.st_mtime, NULL, &ctm); if (S_ISDIR(st.st_mode)) strcat(path, "/"); else if (! S_ISREG(st.st_mode)) strcat(path, "#"); P("%-16s %8d %04o %d/%02d/%02d %02d:%02d:%02d", &path[n], st.st_size, st.st_mode & 0x1FF, ctm.tm_year + 1900, ctm.tm_mon + 1, ctm.tm_mday, ctm.tm_hour, ctm.tm_min, ctm.tm_sec); if (opt & 0x01) { dt_localtime_ms(&st.st_ctime, NULL, &ctm); P(" c:%d/%02d/%02d %02d:%02d:%02d", ctm.tm_year + 1900, ctm.tm_mon + 1, ctm.tm_mday, ctm.tm_hour, ctm.tm_min, ctm.tm_sec); dt_localtime_ms(&st.st_atime, NULL, &ctm); P(" a:%d/%02d/%02d", ctm.tm_year + 1900, ctm.tm_mon + 1, ctm.tm_mday); } if (opt & 0x02) { P(" b:%-4d m:%#04x i:%d", (W)st.st_blocks, st.st_mode, (W)st.st_ino); } P("\n"); } closedir(dir); }