// --------------------------------------------------------------- int PackageDialog::insertDirectory(const QString& DirName, QDataStream& Stream) { QFile File; QDir myDir(DirName); // Put all files of this directory into the package. QStringList Entries = myDir.entryList("*", QDir::Files, QDir::Name); QStringList::iterator it; for(it = Entries.begin(); it != Entries.end(); ++it) { File.setName(myDir.absFilePath(*it)); Stream << Q_UINT32(CODE_FILE); if(insertFile(*it, File, Stream) < 0) return -1; } // Put all subdirectories into the package. Entries = myDir.entryList("*", QDir::Dirs, QDir::Name); Entries.pop_front(); // delete "." from list Entries.pop_front(); // delete ".." from list for(it = Entries.begin(); it != Entries.end(); ++it) { Stream << Q_UINT32(CODE_DIR) << (*it).latin1(); if(insertDirectory(myDir.absPath()+QDir::separator()+(*it), Stream) < 0) return -1; Stream << Q_UINT32(CODE_DIR_END) << Q_UINT32(0); } return 0; }
//Load Desktop Entry data void GofunWidget::loadData() { //We get the data sorted nicely std::vector<GofunDirectoryEntryData>* GfDirectoryData = GofunDataLoader::getData(); //Now we iterate to the category data GofunDirectoryButton* cat; GofunItem* gi; for(std::vector<GofunDirectoryEntryData>::iterator it = GfDirectoryData->begin(); it != GfDirectoryData->end(); ++it) { //We create a fresh category button, fill it with data and insert it //into the category-button-group if(it != GfDirectoryData->begin()) { cat = new GofunDirectoryButton((*it).Name, cats_bg); if(!dynamic_cast<GofunWidget*>(qApp->mainWidget())) insertDirectory(cat); } else { if(dynamic_cast<GofunWidget*>(qApp->mainWidget())) continue; cat = tools_cat; connectDirectoryIconview(cat); connect(cat,SIGNAL(clicked()),this,SLOT(changeToTools())); view_ws->addWidget(cat->iconview, 1001); } cat->setData(&(*it)); //Now we iterate through the actual item-data to create new GofunItems for(std::vector<GofunDesktopEntryData*>::iterator sit = (*it).ItemData->begin(); sit != (*it).ItemData->end(); ++sit) { if(GofunMisc::stringToBool((*sit)->Hidden)) { continue; } if((*sit)->Type == "Application") gi = new GofunApplicationItem(cat->iconview,(*sit)->Name,(*sit)); else if((*sit)->Type == "FSDevice") gi = new GofunFSDeviceItem(cat->iconview,(*sit)->Name,(*sit)); else if((*sit)->Type == "Link") gi = new GofunLinkItem(cat->iconview,(*sit)->Name,(*sit)); } delete (*it).ItemData; } tools_cat->setOn(true); current_cat = tools_cat; }
int LinnCreate::create(Size blockSize, Size blockNum, Size inodeNum) { LinnGroup *group; BitArray map(128); assert(image != ZERO); assert(prog != ZERO); assert(blockNum >= 2); assert(inodeNum > 0); /* Allocate blocks. */ blocks = new u8[blockSize * blockNum]; memset(blocks, 0, blockSize * blockNum); /* Create a superblock. */ super = (LinnSuperBlock *) (blocks + LINN_SUPER_OFFSET); super->magic0 = LINN_SUPER_MAGIC0; super->magic1 = LINN_SUPER_MAGIC1; super->majorRevision = LINN_SUPER_MAJOR; super->minorRevision = LINN_SUPER_MINOR; super->state = LINN_SUPER_VALID; super->blockSize = blockSize; super->blocksPerGroup = LINN_CREATE_BLOCKS_PER_GROUP; super->inodesCount = inodeNum; super->blocksCount = blockNum; super->inodesPerGroup = super->inodesCount / LINN_GROUP_COUNT(super); super->freeInodesCount = super->inodesCount; super->freeBlocksCount = blockNum - 3; super->creationTime = time(ZERO); super->mountTime = ZERO; super->mountCount = ZERO; super->lastCheck = ZERO; super->groupsTable = 2; /* Allocate LinnGroups. */ for (Size i = 0; i < LINN_GROUP_COUNT(super); i++) { /* Point to the correct LinnGroup. */ group = BLOCKPTR(LinnGroup, 2) + i; /* Fill the group. */ group->freeBlocksCount = super->blocksPerGroup; group->freeInodesCount = super->inodesPerGroup; group->blockMap = BLOCKS(super, LINN_GROUP_NUM_BLOCKMAP(super)); group->inodeMap = BLOCKS(super, LINN_GROUP_NUM_INODEMAP(super)); group->inodeTable = BLOCKS(super, LINN_GROUP_NUM_INODETAB(super)); } /* Create special inodes. */ createInode(LINN_INODE_ROOT, DirectoryFile, OwnerRWX | GroupRX | OtherRX); createInode(LINN_INODE_LOADER, RegularFile, OwnerRWX | GroupRX | OtherRX); createInode(LINN_INODE_BAD, RegularFile, OwnerRW | GroupR | OtherR); createInode(LINN_INODE_JOURNAL, RegularFile, OwnerRW | GroupR | OtherR); /* Insert into directory contents, if set. */ if (input) { insertDirectory(input, LINN_INODE_ROOT, LINN_INODE_ROOT); } /* Mark blocks used. */ for (le32 block = 0; block < super->freeBlocksCount; block++) { /* Point to group. */ group = BLOCKPTR(LinnGroup, super->groupsTable) + (block / super->blocksPerGroup); group->freeBlocksCount--; /* Mark the block used. */ map.setArray(BLOCKPTR(u8, group->blockMap), super->blocksPerGroup); map.set(block % super->blocksPerGroup); } /* Write the final image. */ return writeImage(); }
void LinnCreate::insertDirectory(char *inputDir, le32 inodeNum, le32 parentNum) { struct dirent *ent; struct stat st; DIR *dir; char path[255]; le32 child; bool skip = false; /* Create '.' and '..' */ insertEntry(inodeNum, inodeNum, ".", DirectoryFile); insertEntry(inodeNum, parentNum, "..", DirectoryFile); /* Open the input directory. */ if ((dir = opendir(inputDir)) == NULL) { printf("%s: failed to opendir() `%s': %s\n", prog, inputDir, strerror(errno)); exit(EXIT_FAILURE); } /* Read all it's entries. */ while ((ent = readdir(dir))) { /* Hidden files. */ skip = ent->d_name[0] == '.'; /* Excluded files. */ for (ListIterator<String *> e(&excludes); e.hasCurrent(); e++) { String dent = (const char *) ent->d_name; if (dent.match(**e.current())) { skip = true; break; } } /* Skip file? */ if (skip) continue; /* Construct local path. */ snprintf(path, sizeof(path), "%s/%s", inputDir, ent->d_name); /* Stat the file. */ if (stat(path, &st) != 0) { printf("%s: failed to stat() `%s': %s\n", prog, path, strerror(errno)); exit(EXIT_FAILURE); } /* Create an inode for the child. */ child = createInode(path, &st); /* Insert directory entry. */ insertEntry(inodeNum, child, ent->d_name, FILETYPE_FROM_ST(&st)); /* Traverse down. */ if (S_ISDIR(st.st_mode)) { insertDirectory(path, child, inodeNum); } } /* All done. */ closedir(dir); }
// --------------------------------------------------------------- void PackageDialog::slotCreate() { if(NameEdit->text().isEmpty()) { QMessageBox::critical(this, tr("Error"), tr("Please insert a package name!")); return; } QCheckBox *p; QListIterator<QCheckBox *> i(BoxList); if(!LibraryCheck->isChecked()) { int count=0; while(i.hasNext()){ p = i.next(); if(p->isChecked()) count++; } if(count < 1) { QMessageBox::critical(this, tr("Error"), tr("Please choose at least one project!")); return; } } QString s(NameEdit->text()); QFileInfo Info(s); if(Info.extension().isEmpty()) s += ".qucs"; NameEdit->setText(s); QFile PkgFile(s); if(PkgFile.exists()) if(QMessageBox::information(this, tr("Info"), tr("Output file already exists!")+"\n"+tr("Overwrite it?"), tr("&Yes"), tr("&No"), 0,1,1)) return; if(!PkgFile.open(QIODevice::ReadWrite)) { QMessageBox::critical(this, tr("Error"), tr("Cannot create package!")); return; } QDataStream Stream(&PkgFile); // First write header. char Header[HEADER_LENGTH]; memset(Header, 0, HEADER_LENGTH); strcpy(Header, "Qucs package " PACKAGE_VERSION); PkgFile.writeBlock(Header, HEADER_LENGTH); // Write project files to package. i.toFront(); while(i.hasNext()) { p = i.next(); if(p->isChecked()) { s = p->text() + "_prj"; Stream << Q_UINT32(CODE_DIR) << s.latin1(); s = QucsSettings.QucsHomeDir.absPath() + QDir::separator() + s; if(insertDirectory(s, Stream) < 0) { PkgFile.close(); PkgFile.remove(); return; } Stream << Q_UINT32(CODE_DIR_END) << Q_UINT32(0); } } // Write user libraries to package if desired. if(LibraryCheck->isChecked()) if(insertLibraries(Stream) < 0) { PkgFile.close(); PkgFile.remove(); return; } // Calculate checksum and write it to package file. PkgFile.at(0); QByteArray Content = PkgFile.readAll(); Q_UINT16 Checksum = qChecksum(Content.data(), Content.size()); PkgFile.at(HEADER_LENGTH-sizeof(Q_UINT16)); Stream << Checksum; PkgFile.close(); QMessageBox::information(this, tr("Info"), tr("Successfully created Qucs package!")); accept(); }