void cPluginManager::FindPlugins(void) { AString PluginsPath = FILE_IO_PREFIX + AString( "Plugins/" ); // First get a clean list of only the currently running plugins, we don't want to mess those up for (PluginMap::iterator itr = m_Plugins.begin(); itr != m_Plugins.end();) { if (itr->second == NULL) { PluginMap::iterator thiz = itr; ++thiz; m_Plugins.erase( itr ); itr = thiz; continue; } ++itr; } AStringList Files = GetDirectoryContents(PluginsPath.c_str()); for (AStringList::const_iterator itr = Files.begin(); itr != Files.end(); ++itr) { if ((*itr == ".") || (*itr == "..") || (!cFile::IsFolder(PluginsPath + *itr))) { // We only want folders, and don't want "." or ".." continue; } // Add plugin name/directory to the list if (m_Plugins.find(*itr) == m_Plugins.end()) { m_Plugins[*itr] = NULL; } } }
unsigned int NameToClusterNumber(const char* name) { struct DirectoryEntry* tmp = GetDirectoryContents(GetCurrentDirectoryClusterNum()); unsigned int index = 0; while (!tmp[index].END_OF_ARRAY) { if (strcmp(tmp[index].DIR_Name, name) == 0) { return tmp[index].DIR_FstClus; } index++; } return 0xFFFFFFFF; }
bool ff::DeleteDirectory(StringRef path, bool bMustBeEmpty) { if (bMustBeEmpty) { String szRealPath = CanonicalizePath(path, true); return ::RemoveDirectory(szRealPath.c_str()) ? true : false; } else if (DirectoryExists(path)) { Vector<String> dirs; Vector<String> files; if (GetDirectoryContents(path, dirs, files)) { String szRealPath = CanonicalizePath(path, true); for (size_t i = 0; i < files.Size(); i++) { String szDelete = szRealPath; AppendPathTail(szDelete, files[i]); if (!DeleteFile(szDelete)) { return false; } } for (size_t i = 0; i < dirs.Size(); i++) { String szDelete = szRealPath; AppendPathTail(szDelete, dirs[i]); if (!DeleteDirectory(szDelete, false)) { return false; } } return DeleteDirectory(path, true); } } return false; }
void ShowAll() { DeleteAllChildren(); PackEnd(new Gui::Label(m_title)); m_tentry = new Gui::TextEntry(); PackEnd(m_tentry); std::list<std::string> files; GetDirectoryContents(GetFullSavefileDirPath().c_str(), files); Gui::HBox *hbox = new Gui::HBox(); PackEnd(hbox); Gui::HBox *buttonBox = new Gui::HBox(); buttonBox->SetSpacing(5.0f); Gui::Button *b = new Gui::LabelButton(new Gui::Label(m_type == SAVE ? Lang::SAVE : Lang::LOAD)); b->onClick.connect(sigc::mem_fun(this, &FileDialog::OnClickAction)); buttonBox->PackEnd(b); b = new Gui::LabelButton(new Gui::Label(Lang::CANCEL)); b->onClick.connect(sigc::mem_fun(this, &FileDialog::OnClickCancel)); buttonBox->PackEnd(b); PackEnd(buttonBox); Gui::VScrollBar *scroll = new Gui::VScrollBar(); Gui::VScrollPortal *portal = new Gui::VScrollPortal(390); portal->SetTransparency(false); scroll->SetAdjustment(&portal->vscrollAdjust); hbox->PackEnd(portal); hbox->PackEnd(scroll); Gui::Box *vbox = new Gui::VBox(); for (std::list<std::string>::iterator i = files.begin(); i!=files.end(); ++i) { b = new SimpleLabelButton(new Gui::Label(*i)); b->onClick.connect(sigc::bind(sigc::mem_fun(this, &FileDialog::OnClickFile), *i)); vbox->PackEnd(b); } portal->Add(vbox); Gui::VBox::ShowAll(); }
void cd(const char* path) { if (strcmp(path, "..") == 0) { unsigned int previousClus = PopPreviousDirectoryClusterNum(); if (previousClus == 0xFFFFFFFF) { } else { SetCurrentDirectoryClusterNum(previousClus); } } else { char parsed_dir[USER_INPUT_BUFFER_LENGTH]; strcpy(parsed_dir, path); ToFAT32(parsed_dir); struct DirectoryEntry* tmp = GetDirectoryContents(GetCurrentDirectoryClusterNum()); unsigned int index = 0; unsigned char somethingFound = 0; while (!tmp[index].END_OF_ARRAY) { if (strcmp(tmp[index].DIR_Name, parsed_dir) == 0 && tmp[index].DIR_Attr & 0x10) { PushPreviousDirectoryClusterNum(GetCurrentDirectoryClusterNum()); SetCurrentDirectoryClusterNum(tmp[index].DIR_FstClus); somethingFound = 1; } ++index; } if (somethingFound == 0) { printf("Not a valid directory.\n"); } } }
void RunProgram(void) { int running = 1; //USER_INPUT[0] = USER_INPUT_0; //USER_INPUT[1] = USER_INPUT_1; //USER_INPUT[2] = USER_INPUT_2; //USER_INPUT[3] = USER_INPUT_3; //USER_INPUT[4] = NULL; while (running) { PrintPrompt(); GetUserInput(); if (strcmp(USER_INPUT[0], "exit") == 0) { running = 0; } else if (strcmp(USER_INPUT[0], "ls") == 0) { if (strcmp(USER_INPUT[1], ". . . . .") == 0) { //printf("Requires an argument for path name\n"); list(GetCurrentDirectoryClusterNum()); } else { ls(USER_INPUT[1]); } } else if (strcmp(USER_INPUT[0], "cd") == 0) { if (strcmp(USER_INPUT[1], ". . . . .") == 0) { printf("Requires an argument for path name\n"); } else if (strcmp(USER_INPUT[1], ".") == 0) { // do nothing } else { //char parsed_dir[USER_INPUT_BUFFER_LENGTH]; //strcpy(parsed_dir, USER_INPUT[1]); //ToFAT32(parsed_dir); //printf("!%s!\n", parsed_dir); cd(USER_INPUT[1]); } } else if (strcmp(USER_INPUT[0], "size") == 0) { if (strcmp(USER_INPUT[1], ". . . . .") == 0) { printf("Requires a file name argument\n"); } else { size(USER_INPUT[1]); } } else if (strcmp(USER_INPUT[0], "open") == 0) { if (strcmp(USER_INPUT[1], ". . . . .") == 0 || strcmp(USER_INPUT[2], ". . . . .") == 0) { printf("Requires a file name argument followed by a mode argument\n"); } else { char parsed_dir[USER_INPUT_BUFFER_LENGTH]; strcpy(parsed_dir, USER_INPUT[1]); ToFAT32(parsed_dir); open(parsed_dir, USER_INPUT[2]); } } else if (strcmp(USER_INPUT[0], "close") == 0) { if (strcmp(USER_INPUT[1], ". . . . .") == 0) { printf("Requires a file name argument\n"); } else { char parsed_dir[USER_INPUT_BUFFER_LENGTH]; strcpy(parsed_dir, USER_INPUT[1]); ToFAT32(parsed_dir); close(parsed_dir); } } else if (strcmp(USER_INPUT[0], "read") == 0) { if (strcmp(USER_INPUT[1],". . . . .") == 0 || strcmp(USER_INPUT[2],". . . . .") == 0 || strcmp(USER_INPUT[3],". . . . .") == 0) { printf("Requires arguments for filename, position, and size\n"); } else { char parsed_dir[USER_INPUT_BUFFER_LENGTH]; strcpy(parsed_dir, USER_INPUT[1]); ToFAT32(parsed_dir); read(parsed_dir, atoi(USER_INPUT[2]), atoi(USER_INPUT[3])); } } else if (strcmp(USER_INPUT[0], "create") == 0) { if (strcmp(USER_INPUT[1],". . . . .") == 0) { printf("Requires an argument for the file name\n"); } else if (strcmp(USER_INPUT[1],".") == 0) { printf("Invalid file name\n"); } else if (strcmp(USER_INPUT[1],"..") == 0) { printf("Invalid file name\n"); } else { char parsed_dir[USER_INPUT_BUFFER_LENGTH]; strcpy(parsed_dir, USER_INPUT[1]); ToFAT32(parsed_dir); create(parsed_dir); } } else if (strcmp(USER_INPUT[0], "mkdir") == 0) { if (strcmp(USER_INPUT[1],". . . . .") == 0) { printf("Requires an argument for the directory name\n"); } else if (strcmp(USER_INPUT[1],".") == 0) { printf("Invalid directory name\n"); } else if (strcmp(USER_INPUT[1],"..") == 0) { printf("Invalid directory name\n"); } else { char parsed_dir[USER_INPUT_BUFFER_LENGTH]; strcpy(parsed_dir, USER_INPUT[1]); ToFAT32(parsed_dir); mkdir(parsed_dir); } } else if (strcmp(USER_INPUT[0], "rm") == 0) { if (strcmp(USER_INPUT[1],". . . . .") == 0) { printf("Requires an argument for the file name\n"); } else if (strcmp(USER_INPUT[1],".") == 0) { printf("Invalid file name\n"); } else if (strcmp(USER_INPUT[1],"..") == 0) { printf("Invalid file name\n"); } else { char parsed_dir[USER_INPUT_BUFFER_LENGTH]; strcpy(parsed_dir, USER_INPUT[1]); ToFAT32(parsed_dir); rm(parsed_dir); } } else if (strcmp(USER_INPUT[0], "rmdir") == 0) { if (strcmp(USER_INPUT[1],". . . . .") == 0) { printf("Requires an argument for the directory name\n"); } else if (strcmp(USER_INPUT[1],".") == 0) { printf("Invalid directory name\n"); } else if (strcmp(USER_INPUT[1],"..") == 0) { printf("Invalid directory name\n"); } else { char parsed_dir[USER_INPUT_BUFFER_LENGTH]; strcpy(parsed_dir, USER_INPUT[1]); ToFAT32(parsed_dir); rmdir(parsed_dir); } } else if (strcmp(USER_INPUT[0], "write") == 0) { if (strcmp(USER_INPUT[1],". . . . .") == 0 || strcmp(USER_INPUT[2],". . . . .") == 0 || strcmp(USER_INPUT[3],". . . . .") == 0 || strcmp(USER_INPUT[4],". . . . .") == 0) { printf("Requires arguments for file name, position, number of bytes, and string to write\n"); } else { char parsed_dir[USER_INPUT_BUFFER_LENGTH]; strcpy(parsed_dir, USER_INPUT[1]); ToFAT32(parsed_dir); write(parsed_dir, atoi(USER_INPUT[2]), atoi(USER_INPUT[3]), USER_INPUT[4]); } } else if (strcmp(USER_INPUT[0], "debug") == 0) { printf("CURRENT_CLUSTER: %d\n", GetCurrentDirectoryClusterNum()); printf("CURRENT_CLUSTER BYTE_ADDRESS: 0x%x\n", FindFirstSectorOfCluster(GetCurrentDirectoryClusterNum())); FTPrint(); PrintDirectoryVector(GetDirectoryContents(GetCurrentDirectoryClusterNum())); } } int k; for (k = 0; k < 5; k++) { free(USER_INPUT[k]); } }
bool cPlugin_NewLua::Initialize(void) { cCSLock Lock(m_CriticalSection); if (m_LuaState == NULL) { m_LuaState = lua_open(); luaL_openlibs(m_LuaState); tolua_AllToLua_open(m_LuaState); ManualBindings::Bind(m_LuaState); luaopen_lsqlite3(m_LuaState); luaopen_lxp(m_LuaState); // Inject the identification global variables into the state: lua_pushlightuserdata(m_LuaState, this); lua_setglobal(m_LuaState, LUA_PLUGIN_INSTANCE_VAR_NAME); lua_pushstring(m_LuaState, GetName().c_str()); lua_setglobal(m_LuaState, LUA_PLUGIN_NAME_VAR_NAME); } std::string PluginPath = FILE_IO_PREFIX + GetLocalDirectory() + "/"; // Load all files for this plugin, and execute them AStringList Files = GetDirectoryContents(PluginPath.c_str()); for (AStringList::const_iterator itr = Files.begin(); itr != Files.end(); ++itr) { if (itr->rfind(".lua") == AString::npos) { continue; } AString Path = PluginPath + *itr; int s = luaL_loadfile(m_LuaState, Path.c_str() ); if( report_errors( m_LuaState, s ) ) { LOGERROR("Can't load plugin %s because of an error in file %s", GetLocalDirectory().c_str(), Path.c_str() ); lua_close( m_LuaState ); m_LuaState = 0; return false; } s = lua_pcall(m_LuaState, 0, LUA_MULTRET, 0); if( report_errors( m_LuaState, s ) ) { LOGERROR("Error in plugin %s in file %s", GetLocalDirectory().c_str(), Path.c_str() ); lua_close( m_LuaState ); m_LuaState = 0; return false; } } // for itr - Files[] // Call intialize function if (!PushFunction("Initialize")) { lua_close( m_LuaState ); m_LuaState = 0; return false; } tolua_pushusertype(m_LuaState, this, "cPlugin_NewLua"); if (!CallFunction(1, 1, "Initialize")) { lua_close( m_LuaState ); m_LuaState = 0; return false; } if( !lua_isboolean( m_LuaState, -1 ) ) { LOGWARN("Error in plugin %s Initialize() must return a boolean value!", GetLocalDirectory().c_str() ); lua_close( m_LuaState ); m_LuaState = 0; return false; } bool bSuccess = (tolua_toboolean(m_LuaState, -1, 0) > 0); return bSuccess; }