void MEditor::init(void) { clear(); // load preferences { m_preferences.load("Resources/preferences.xml"); m_preferences.load("Resources/themes/grey/grey.xml"); } // load font { const char * filename = m_preferences.getFontFilename(); m_guiData.loadFont(filename); } // load gui { const char * path = m_preferences.getGuiPath(); char tmp[256]; vector<string> files; readDirectory(path, &files); unsigned int size = files.size(); for(unsigned int i=0; i<size; i++) { getGlobalFilename(tmp, path, files[i].c_str()); MTextureRef * ref = m_guiData.loadTexture(tmp); ref->setFilename(files[i].c_str()); // use only the file name } } // load meshes { const char * path = "Resources/meshes/gui"; char tmp[256]; vector<string> files; readDirectory(path, &files); unsigned int size = files.size(); for(unsigned int i=0; i<size; i++) { getGlobalFilename(tmp, path, files[i].c_str()); MMeshRef * ref = m_guiData.loadMesh(tmp); ref->setFilename(files[i].c_str()); // use only the file name } } }
// Non-Standard Constructor for the class // Input Argument is the path to the root directory // Sets initial values // Performs a read on Initalization Explore::Explore(std::string rootDirectory) { initialPath = rootDirectory; numberOfFilesRead = 0; numberOfDirectoriesRead = 0; readDirectory(initialPath); }
void Find::readDirectory( const char* aDirectoryName ) const { char resolved_path[PATH_MAX]; if( NULL == realpath( aDirectoryName , resolved_path ) ) { return; } DIR *dir = opendir(resolved_path); if( NULL == dir ) { return; } struct dirent *ent; while((ent = readdir(dir)) != NULL) { char path[PATH_MAX]; if( isDirectory( ent->d_type ) ) { if( !isCurrentDirectory( ent->d_name ) && !isParentDirectory( ent->d_name) ) { // std::cout << "Directory "<< (ent->d_name) << std::endl; createDirectoryPath( resolved_path , ent->d_name , path ); readDirectory( path ); } } else { if( isFile( ent->d_type ) ) { createDirectoryPath( resolved_path , ent->d_name , path ); // std::cout << "File "<< path << std::endl; } else { // std::cout << "Type"<< (ent->d_type) << std::endl; } } } closedir( dir ); }
static jobjectArray java_io_File_listImpl(JNIEnv* env, jobject, jbyteArray pathBytes) { // Read the directory entries into an intermediate form. DirEntries files; if (!readDirectory(env, pathBytes, files)) { return NULL; } // Translate the intermediate form into a Java String[]. jclass stringClass = env->FindClass("java/lang/String"); if (stringClass == NULL) { return NULL; } jobjectArray result = env->NewObjectArray(files.size(), stringClass, NULL); for (int i = 0; files.size() != 0; files.pop_front(), ++i) { jstring javaFilename = env->NewStringUTF(files.front()); if (env->ExceptionCheck()) { return NULL; } env->SetObjectArrayElement(result, i, javaFilename); if (env->ExceptionCheck()) { return NULL; } env->DeleteLocalRef(javaFilename); } return result; }
void FileSelectionDialog::setSelectedPathButton(int newSelectedPathButton) { /* Get the style sheet: */ const StyleSheet& ss=*getManager()->getStyleSheet(); if(selectedPathButton>=0) { /* Un-"arm" the previously selected path button: */ Button* oldButton=static_cast<Button*>(pathButtonBox->getChild(selectedPathButton)); oldButton->setBorderType(Widget::RAISED); oldButton->setBackgroundColor(ss.bgColor); oldButton->setArmedBackgroundColor(ss.buttonArmedBackgroundColor); } /* Set the index of the selected path button: */ selectedPathButton=newSelectedPathButton; /* "Arm" the new selected path button: */ Button* newButton=static_cast<Button*>(pathButtonBox->getChild(selectedPathButton)); newButton->setBorderType(Widget::LOWERED); newButton->setBackgroundColor(ss.buttonArmedBackgroundColor); newButton->setArmedBackgroundColor(ss.bgColor); /* Read the directory corresponding to the path button: */ readDirectory(); }
DirectoryListDialog::DirectoryListDialog(QWidget *parent, QString dirName) : QDialog(parent) { if(dirName == "") { //Create error message } setFixedSize(150,200); setWindowFlags(Qt::Window | Qt::WindowCloseButtonHint); listEdit = new QTextEdit(this); okButton = new QPushButton(this); dir = new QDir(dirName); okButton->setText("Ok"); okButton->setGeometry(width()/2-75/2,height()-32,75,23); listEdit->setGeometry(8,8,134,160); readDirectory(); listEdit->setReadOnly(true); connect(okButton,SIGNAL(clicked()),this,SLOT(okClicked())); show(); }
int myMount(MyFileSystem *myFileSystem, char *backupFileName){ if ((myFileSystem->fdVirtualDisk = open(backupFileName, O_RDWR))==-1){ perror(backupFileName); return 1; } if (readBitmap(myFileSystem)!=0){ fprintf(stderr,"Can't read bitmap\n"); return 2; } if (readSuperblock(myFileSystem)!=0){ fprintf(stderr,"Can't read superblock\n"); return 3; } if (readInodes(myFileSystem)!=0){ fprintf(stderr,"Can't read inodes\n"); return 4; } if (readDirectory(myFileSystem)!=0){ fprintf(stderr,"Can't read directory\n"); return 5; } printf("SF: %s, %d B (%d B/block), %d blocks\n", backupFileName, myFileSystem->superBlock.diskSizeInBlocks*BLOCK_SIZE_BYTES, BLOCK_SIZE_BYTES, myFileSystem->superBlock.diskSizeInBlocks); printf("1 block for SUPERBLOCK (%u B)\n", (unsigned int)sizeof(SuperBlockStruct)); printf("1 block for BITMAP, covering %u blocks, %u B\n", (unsigned int)NUM_BITS, (unsigned int)(NUM_BITS * BLOCK_SIZE_BYTES)); printf("1 block for DIRECTORY (%u B)\n", (unsigned int)sizeof(DirectoryStruct)); printf("%d blocks for inodes (%u B/inode, %u inodes)\n", MAX_BLOCKS_WITH_NODES, (unsigned int)sizeof(NodeStruct), (unsigned int)MAX_NODES); printf("%d blocks for data (%d B)\n", myFileSystem->superBlock.numOfFreeBlocks, BLOCK_SIZE_BYTES * myFileSystem->superBlock.numOfFreeBlocks); printf("Volume mounted successfully!\n"); return 0; }
int main(int argc, char **argv) { std::string folder; int i; omp_set_num_threads(8); //assert(argc == 2); //folder = std::string(argv[1]); folder = std::string("images"); sumPositive = new mpf_class[1024]; sumSqPositive = new mpf_class[1024]; sumNegative = new mpf_class[1024]; sumSqNegative = new mpf_class[1024]; for (i = 0; i < 1024; i++) { sumPositive[i] = mpf_class(0.); sumSqPositive[i] = mpf_class(0.); sumNegative[i] = mpf_class(0.); sumSqNegative[i] = mpf_class(0.); } readDirectory(folder, functionFilePositive, functionFileNegative); calculateValues(sumPositive, sumSqPositive, sumNegative, sumSqNegative, numberOfPositive, numberOfNegatives); std::cout << numberOfPositive << " " << numberOfNegatives << std::endl; return EXIT_SUCCESS; }
// Method reads all bodies in the Iges input file. // Returns the number of the bodies read. bool InputIges::readCadGeometry() { bool result; //--Read directory section and find the start position of the // of parameters-section in the file. // Paramter-section line-counter is set to 0. // NOTE: This counter is updated by: readDataLine and // locateParamEntry functions. paramSecStart = readDirectory(); //--If model type is unknown if (modelDimension == ECIF_ND) { modelDimension = findCadModelDimension(); } //--Update entry references ans states checkEntryReferences(); //--Create bodies in each entry which defines a body createBodies(); //--Read body elements readBodyElements(); // After reading all body-information, data can be checked! //result = this->model->checkBodies(); // if (!modelIsOk) // exit(1); return true; }
void MtpFolder::Rename(MtpNode& newParent, const std::string& newName) { if (newName.length() > MAX_MTP_NAME_LENGTH) throw MtpNameTooLong(); MtpNodeMetadata md = m_cache.getItem(m_id, *this); uint32_t parentId = GetParentNodeId(); if ((newParent.FolderId() == md.self.parentId) && (newParent.StorageId() == m_storageId)) { // we can do a real rename m_device.RenameFile(m_id, newName); } else { // we have to do a copy and delete newParent.mkdir(newName); std::unique_ptr<MtpNode> destDir(newParent.getNode(FilesystemPath(newName.c_str()))); std::vector<std::string> contents = readDirectory(); for(std::vector<std::string>::iterator i = contents.begin(); i != contents.end(); i++) { std::unique_ptr<MtpNode> child(getNode(FilesystemPath(i->c_str()))); child->Rename(*destDir, *i); } Remove(); } m_cache.clearItem(newParent.Id()); m_cache.clearItem(parentId); }
/** * Retrieve a resource from the File system * * @param uri The URI sent in the request * @return NULL if unable to load the resource. Resource object */ Resource* ResourceHost::getResource(std::string uri) { if(uri.length() > 255 || uri.empty()) return NULL; std::string path = baseDiskPath + uri; Resource* res = NULL; // Gather info about the resource with stat: determine if it's a directory or file, check if its owned by group/user, modify times struct stat sb; if(stat(path.c_str(), &sb) == -1) return NULL; // File not found // Determine file type if(sb.st_mode & S_IFDIR) { // Directory // Read a directory list or index into memory from FS res = readDirectory(path, sb); } else if(sb.st_mode & S_IFREG) { // Regular file // Attempt to load the file into memory from the FS res = readFile(path, sb); } else { // Something else..device, socket, symlink return NULL; } return res; }
void FileSelectionDialog::filterListValueChangedCallback(DropdownBox::ValueChangedCallbackData* cbData) { /* Set the current file name filters to the new selected item: */ fileNameFilters=cbData->newSelectedItem>0?cbData->dropdownBox->getItem(cbData->newSelectedItem):0; /* Re-read the current directory: */ readDirectory(); }
void Player::loadDirectory() { QStringList files; QString path = KFileDialog::getExistingDirectory(); //TODO filter for only audio files if (path == "") return; readDirectory(path, files); loadFiles(files); }
extern "C" jobjectArray Java_java_io_File_listImpl(JNIEnv* env, jclass, jstring javaPath) { // Read the directory entries into an intermediate form. DirEntries entries; if (!readDirectory(env, javaPath, entries)) { return NULL; } // Translate the intermediate form into a Java String[]. return toStringArray(env, entries); }
/* ResArchive::open * Reads res format data from a MemChunk * Returns true if successful, false otherwise *******************************************************************/ bool ResArchive::open(MemChunk& mc) { // Check data was given if (!mc.hasData()) return false; // Read res header uint32_t dir_size = 0; uint32_t dir_offset = 0; char magic[4] = ""; mc.seek(0, SEEK_SET); mc.read(&magic, 4); // "Res!" mc.read(&dir_offset, 4); // Offset to directory mc.read(&dir_size, 4); // No. of lumps in res // Byteswap values for big endian if needed dir_size = wxINT32_SWAP_ON_BE(dir_size); dir_offset = wxINT32_SWAP_ON_BE(dir_offset); // Check the header if (magic[0] != 'R' || magic[1] != 'e' || magic[2] != 's' || magic[3] != '!') { LOG_MESSAGE(1, "ResArchive::openFile: File %s has invalid header", filename); Global::error = "Invalid res header"; return false; } if (dir_size % RESDIRENTRYSIZE) { LOG_MESSAGE(1, "ResArchive::openFile: File %s has invalid directory size", filename); Global::error = "Invalid res directory size"; return false; } uint32_t num_lumps = dir_size / RESDIRENTRYSIZE; // Stop announcements (don't want to be announcing modification due to entries being added etc) setMuted(true); // Read the directory mc.seek(dir_offset, SEEK_SET); UI::setSplashProgressMessage("Reading res archive data"); if (!readDirectory(mc, dir_offset, num_lumps, getRoot())) return false; // Detect maps (will detect map entry types) UI::setSplashProgressMessage("Detecting maps"); detectMaps(); // Setup variables setMuted(false); setModified(false); announce("opened"); UI::setSplashProgressMessage(""); return true; }
void CiffDirectory::read(const byte* buf, uint32_t len, uint32_t start, ByteOrder byteOrder, int32_t /*shift*/) { CiffComponent::read(buf, len, start, byteOrder); readDirectory(buf + offset(), size(), 0, byteOrder, 0); } // CiffDirectory::read
void MtpFolder::Remove() { if (readDirectory().size()>0) throw MtpDirectoryNotEmpty(); uint32_t parentId = GetParentNodeId(); m_device.DeleteObject(m_id); m_cache.clearItem(parentId); m_cache.clearItem(m_id); }
void FileModel::refreshFull() { if (!m_active) { m_dirty = true; return; } readDirectory(); m_dirty = false; }
int mksfs(int fresh) { int diskinit; //Create a new filesystem if the fresh variable is set if(fresh==1){ diskinit = init_fresh_disk(FILESYSTEMNAME, BLOCKSIZE, NUMBEROFBLOCKS); if(diskinit != 0){ //perror("Error creating disk"); exit(-1); } else { //To keep the root directory in memory initDirectory(); //Initialize SuperBlock mySuperBlock.magic = MAGIC; mySuperBlock.blockSize = BLOCKSIZE; mySuperBlock.fileSystemSize = NUMBEROFBLOCKS; mySuperBlock.iNodeTableLength = NUMBEROFINODES; mySuperBlock.rootINode = 0; //Use a block sized buffer unsigned char buffer[512]; memset(buffer,255,512); memcpy(buffer,&mySuperBlock,512); write_blocks(0,1,buffer); initializeFreeBitMap(); initializeFDTable(); //Now for the Inodes: initialize the first one: (for root dir) int numRootINode = createINode(RWE, 1, ROOT_UID, ROOT_GID, 1); readDirectory(); return 0; } } //if the free variable is not set, load else if (fresh==0) { diskinit = init_disk(FILESYSTEMNAME, BLOCKSIZE, NUMBEROFBLOCKS); if(diskinit != 0){ //perror("Error reading disc"); exit(-1); } else { return 0; } } return -1; }
void Filesystem::removeDir(const std::string& dir) { std::vector<std::string> c; if(readDirectory(dir, c)) { for(unsigned i = 0; i < c.size(); i++) { std::string name(append(dir, c[i])); removeDir(name); removeFile(name); } removeEmptyDir(dir.c_str()); } }
// Function for using same reader to read a different directory // path to new directory is to be provided // will update all storage structures void Explore::readNewDirectory(std::string newPath) { directoryMap.clear(); fileMap.clear(); numberOfFilesRead = 0; numberOfDirectoriesRead = 0; initialPath = newPath; readDirectory(newPath); }
ZipFileSystem :: ZipFileSystem(const std::string& fName) : Resource(), fileName(fName) { int file = open(fileName.c_str(), O_BINARY | O_RDONLY); if(file == -1) { LOG_WARNING("ZipFileSystem: File \"%s\" not detected.", fileName.c_str()); return; } broken = false; readDirectory(file); close(file); LOG_INFO("ZipFileSystem: Created resource source \"%s\" (files %i)", fileName.c_str(), dir.size()); }
void Player::readDirectory(const QDir &dir, QStringList &files) { QFileInfoList children = dir.entryInfoList(); QFileInfoList::iterator itt, end = children.end(); for (itt = children.begin(); itt != end; ++itt) { QString name = itt->fileName(); if (name != "." && name != "..") { if (itt->isDir()) readDirectory(QDir(itt->absoluteFilePath()), files); else files.push_back(itt->absoluteFilePath()); } } }
ZipArchive::FileID ZipArchive::findFile(const char* fileName) { /* Read the archive's central directory: */ for(DirectoryIterator dIt=readDirectory();dIt.isValid();getNextEntry(dIt)) { /* Check if the file was found: */ if(strcmp(dIt.getFileName(),fileName)==0) return dIt; } /* File was not found; throw exception: */ throw FileNotFoundError(fileName); }
void FileModel::setActive(bool active) { if (m_active == active) return; m_active = active; emit activeChanged(); if (m_dirty) readDirectory(); m_dirty = false; }
ZipFileSystem :: ZipFileSystem ( const string& zipName ) : fileName ( zipName ) { int file = open ( fileName.c_str (), O_BINARY | O_RDONLY ); if ( file == -1 ) return; broken = false; readDirectory ( file ); close ( file ); printf ( "Added zip source: %s\n", zipName.c_str () ); }
void MaratisPlayer::loadGamePlugin(void) { char gameFile[256]; MWindow * window = MWindow::getInstance(); #ifdef WIN32 getGlobalFilename(gameFile, window->getWorkingDirectory(), "Game.dll"); #elif __APPLE__ getGlobalFilename(gameFile, window->getWorkingDirectory(), "Game.dylib"); #elif linux getGlobalFilename(gameFile, window->getWorkingDirectory(), "Game.so"); #endif // try to load any other plugins in the game directory first // as the game may expect these to be loaded vector<string> files; readDirectory(window->getWorkingDirectory(), &files); for(vector<string>::iterator iFile = files.begin(); iFile != files.end(); iFile++) { if(*iFile == gameFile) continue; #ifdef WIN32 if(iFile->find(".dll") != string::npos) #elif __APPLE__ if(iFile->find(".dylib") != string::npos) #elif linux if(iFile->find(".so") != string::npos) #endif { char pluginPath[256]; getGlobalFilename(pluginPath, window->getWorkingDirectory(), iFile->c_str()); MPlugin* plugin = new MPlugin(); plugin->load(pluginPath); if(plugin->getFilename()) m_plugins.push_back(plugin); else SAFE_DELETE(plugin); } } // After all other plugins are loaded, we can load the game // as we assume all prerequisites are loaded SAFE_DELETE(m_gamePlugin); m_gamePlugin = new MPlugin(); m_gamePlugin->load(gameFile); }
static void copyDirFiles(const char * src, const char * dest, const char * filter) { vector<string> files; readDirectory(src, &files); for(int i = 0; i < files.size(); ++i) { if(strstr(files[i].c_str(), filter)) { char filename[256]; getGlobalFilename(filename, dest, files[i].c_str()); copyFile(files[i].c_str(), filename); } } }
void FileModel::setDir(QString dir) { if (m_dir == dir) return; // update watcher to watch the new directory if (!m_dir.isEmpty()) m_watcher->removePath(m_dir); if (!dir.isEmpty()) m_watcher->addPath(dir); m_dir = dir; readDirectory(); m_dirty = false; emit dirChanged(); }
void DDiskImageMem::MountDiskFromFile(const char *fname) { DEBUG_OUT<<"DDiskImageMem::MountDiskFromFile("<<fname<<")\n"; if(imageData) free(imageData); diskMounted=false; unsigned int t=0; unsigned int err=0; imageDataSize=getSize(fname); #ifdef USE_FAKE_CHDIR #endif // USE_FAKE_CHDIR FILE *fd=fopen(fname,"rb"); if(fd) { DEBUG_OUT<<"Going to allocate "<<imageDataSize<<" sized chunk...\n"; imageData=(BYTE *)malloc(imageDataSize*sizeof(BYTE)); if(imageData) { bool ww=true; BYTE c; t=0; while(ww) { err=fread(&c,1,1,fd); if(err!=1) ww=false; else { imageData[t]=c; t++; } } diskMounted=true; for(t=0;t<DDISK_MAX_NAMELEN;t++) diskName[t]=0; for(t=0;t<strlen(fname);t++) diskName[t]=fname[t]; DEBUG_OUT<<"Mounted disk image "<<diskName<<"\n"; // (Have to do this outside of DDiskImage due to overloaded readDir's) // Oops...probably not, but its working so leave it silly... //readDir(); fclose(fd); } else { std::cerr<<"No mem for disk image!"; } } else { std::cerr<<"Couldn't find disk image!"; } readDirectory(); }