//-------------------------------------------------------------- string ofApp::getFirstFile( ofDirectory& directory, const string ext){ if (!directory.exists()) { return ""; } directory.open( directory.path() ); directory.allowExt(ext); directory.listDir(); unsigned int i = directory.size(); string firstFile = ""; bool got = false; while (i--) { string currentFile = directory.getName(i); if ( !got || (currentFile.compare(firstFile) < 0) ){ firstFile = currentFile; got = true; } } return firstFile; }
void Menu::loadMenuItems(ofDirectory directory, ofPtr< MenuItem > currentItem){ // Each directory in the Presentations directory is a MenuItem: // - Directories with a presentation.xml file are Presentations. // - Directories with subdirectories are Categories. int i, size; // Check if there is a presentation.xml file. directory.listDir(); directory.sort(); size = directory.size(); for(i = 0; i < size; i++){ ofFile file = directory.getFile(i); if (file.isDirectory()){ ofPtr<MenuItem> item(new MenuItem()); item->name = file.getFileName(); item->parent = currentItem; ofFile presentation = ofFile(file.getAbsolutePath() + "/presentation.xml"); if(presentation.exists()){ // Directory is a Presentation. item->isCategory = false; item->path = file.getAbsolutePath(); } else { // Directory is a Category. item->isCategory = true; item->path = currentItem->path + " \/ " + item->name; // Add MenuItem to navigate up. ofPtr<MenuItem> itemUp(new MenuItem); itemUp->name = "..."; itemUp->isMenuUp = true; itemUp->font = &font_small; itemUp->parent = item; item->items.push_back(itemUp); loadMenuItems(ofDirectory(file.path()), item); } item->font = &font_small; currentItem->items.push_back(item); } } if(currentItem->items.size() > 0){ currentItem->items[0]->select(); } }
//-------------------------------------------------------------- bool ofApp::deletePrevious( ofDirectory& directory, string filename) { if (!directory.exists()) { return 0; } directory.open( directory.path() ); directory.allowExt( ofFilePath::getFileExt(filename) ); directory.listDir(); unsigned int i = directory.size(); string* toDelete = new string [i]; unsigned int n = 0; while (i--) { string currentFile = directory.getName(i); if ( currentFile.compare(filename) < 0 ){ toDelete[n] = currentFile; n++; } } while (n--) { ofFile::removeFile( directory.path() + "/" + toDelete[n] ); } delete [] toDelete; directory.open( directory.path() ); return 1; }