QString Project::locationOfObject( QObject *o ) { if ( !o ) return QString::null; if ( MainWindow::self ) { QWidgetList windows = MainWindow::self->qWorkspace()->windowList(); for ( QWidget *w = windows.first(); w; w = windows.next() ) { FormWindow *fw = ::qt_cast<FormWindow*>(w); SourceEditor *se = ::qt_cast<SourceEditor*>(w); if ( fw ) { if ( fw->isFake() ) return objectForFakeForm( fw )->name() + QString( " [Source]" ); else return fw->name() + QString( " [Source]" ); } else if ( se ) { if ( !se->object() ) continue; if ( se->formWindow() ) return se->formWindow()->name() + QString( " [Source]" ); else return makeRelative( se->sourceFile()->fileName() ); } } } if ( ::qt_cast<SourceFile*>(o) ) { for ( QPtrListIterator<SourceFile> sources = sourceFiles(); sources.current(); ++sources ) { SourceFile* f = sources.current(); if ( f == o ) return makeRelative( f->fileName() ); } } extern QMap<QWidget*, QString> *qwf_forms; if ( !qwf_forms ) { qWarning( "Project::locationOfObject: qwf_forms is NULL!" ); return QString::null; } QString s = makeRelative( *qwf_forms->find( (QWidget*)o ) ); s += " [Source]"; return s; }
// Copies files to dstDir so that their name relative to dstDir is the same as their name relative to root void copyFiles(const std::vector<Path> &fileNames, const Path &root, const Path &dstDir) { std::set<Path> dirs; BOOST_FOREACH (const Path &fileName, fileNames) { Path dirName = dstDir / makeRelative(fileName.parent_path(), root); if (dirs.insert(dirName).second) boost::filesystem::create_directories(dirName); Path outputName = dirName / fileName.filename(); copyFile(fileName, outputName); }
void Project::save( bool onlyProjectFile ) { bool anythingModified = FALSE; // save sources and forms if ( !onlyProjectFile ) { saveConnections(); for ( SourceFile *sf = sourcefiles.first(); sf; sf = sourcefiles.next() ) { anythingModified = anythingModified || sf->isModified(); if ( !sf->save() ) return; } for ( FormFile *ff = formfiles.first(); ff; ff = formfiles.next() ) { anythingModified = anythingModified || ff->isModified(); if ( !ff->save() ) return; } } if ( isDummy() || filename.isEmpty() ) return; if ( !modified ) { if ( singleProjectMode() ) { LanguageInterface *iface = MetaDataBase::languageInterface( language() ); if ( iface && iface->supports( LanguageInterface::CompressProject ) ) iface->compressProject( makeAbsolute( filename ), singleProFileName, anythingModified ); } return; } QFile f( filename ); QString original = ""; // read the existing file bool hasPreviousContents = FALSE; if ( f.open( IO_ReadOnly ) ) { QTextStream ts( &f ); original = ts.read(); f.close(); hasPreviousContents = TRUE; remove_contents( original, "{SOURCES+=" ); // ### compatibility with early 3.0 betas remove_contents( original, "DBFILE" ); remove_contents( original, "LANGUAGE" ); remove_contents( original, "TEMPLATE" ); removePlatformSettings( original, "CONFIG" ); removePlatformSettings( original, "DEFINES" ); removePlatformSettings( original, "LIBS" ); removePlatformSettings( original, "INCLUDEPATH" ); removePlatformSettings( original, "SOURCES" ); removePlatformSettings( original, "HEADERS" ); remove_multiline_contents( original, "FORMS" ); remove_multiline_contents( original, "INTERFACES" ); // compatibility remove_multiline_contents( original, "IMAGES" ); for ( QStringList::Iterator it = csList.begin(); it != csList.end(); ++it ) remove_contents( original, *it ); } if (!original.isEmpty()) { // Removes any new lines at the beginning of the file while (original.startsWith("\n")) original.remove(0, 1); } // the contents of the saved file QString contents; // template contents += "TEMPLATE\t= " + templ + "\n"; // language contents += "LANGUAGE\t= " + lang + "\n"; contents += "\n"; // config writePlatformSettings( contents, "CONFIG", cfg ); LanguageInterface *iface = MetaDataBase::languageInterface( lang ); if ( iface ) { QStringList sourceKeys; iface->sourceProjectKeys( sourceKeys ); for ( QStringList::Iterator spit = sourceKeys.begin(); spit != sourceKeys.end(); ++spit ) remove_multiline_contents( contents, *spit ); } // libs, defines, includes writePlatformSettings( contents, "LIBS", lbs ); writePlatformSettings( contents, "DEFINES", defs ); writePlatformSettings( contents, "INCLUDEPATH", inclPath ); writePlatformSettings( contents, "SOURCES", sources ); writePlatformSettings( contents, "HEADERS", headers ); // unix if ( !hasPreviousContents ) { contents += "unix|os2 {\n" " UI_DIR = .ui\n" " MOC_DIR = .moc\n" " OBJECTS_DIR = .obj\n" "}\n\n"; } // sources if ( !sourcefiles.isEmpty() && iface ) { QMap<QString, QStringList> sourceToKey; for ( SourceFile *f = sourcefiles.first(); f; f = sourcefiles.next() ) { QString key = iface->projectKeyForExtension( QFileInfo( f->fileName() ).extension() ); QStringList lst = sourceToKey[ key ]; lst << makeRelative( f->fileName() ); sourceToKey.replace( key, lst ); } for ( QMap<QString, QStringList>::Iterator skit = sourceToKey.begin(); skit != sourceToKey.end(); ++skit ) { QString part = skit.key() + "\t+= "; QStringList lst = *skit; for ( QStringList::Iterator sit = lst.begin(); sit != lst.end(); ++sit ) { part += *sit; part += ++sit != lst.end() ? " \\\n\t" : ""; --sit; } part += "\n\n"; contents += part; } } // forms and interfaces if ( !formfiles.isEmpty() ) { contents += "FORMS\t= "; for ( QPtrListIterator<FormFile> fit = formfiles; fit.current(); ++fit ) { contents += fit.current()->fileName() + (fit != formfiles.last() ? " \\\n\t" : ""); } contents += "\n\n"; } // images if ( !pixCollection->isEmpty() ) { contents += "IMAGES\t= "; QValueList<PixmapCollection::Pixmap> pixmaps = pixCollection->pixmaps(); for ( QValueList<PixmapCollection::Pixmap>::Iterator it = pixmaps.begin(); it != pixmaps.end(); ++it ) { contents += makeRelative( (*it).absname ); contents += ++it != pixmaps.end() ? " \\\n\t" : ""; --it; } contents += "\n\n"; } // database if ( !dbFile.isEmpty() ) contents += "DBFILE\t= " + dbFile + "\n"; // custom settings for ( QStringList::Iterator it = csList.begin(); it != csList.end(); ++it ) { QString val = *customSettings.find( *it ); if ( !val.isEmpty() ) contents += *it + "\t= " + val + "\n"; } if ( !f.open( IO_WriteOnly | IO_Translate ) ) { QMessageBox::warning( messageBoxParent(), "Save Project Failed", "Couldn't write project file " + filename ); return; } QTextStream os( &f ); os << contents; if (hasPreviousContents) os << original; f.close(); setModified( FALSE ); if ( singleProjectMode() ) { LanguageInterface *iface = MetaDataBase::languageInterface( language() ); if ( iface && iface->supports( LanguageInterface::CompressProject ) ) iface->compressProject( makeAbsolute( filename ), singleProFileName, TRUE ); } }
int main(int argc, char** argv) try { po::options_description desc("Required options"); desc.add_options() ("help,h", "produce help message") ("force,f", "overwrite existing files") ("mpq", po::value<std::string>(), "the mpq to create") ("files", po::value<std::vector<std::string> >(), "input files"); po::positional_options_description p; p.add("mpq", 1); p.add("files", -1); po::variables_map vm; po::store(po::command_line_parser(argc, argv).options(desc).positional(p).run(), vm); po::notify(vm); if (!vm.count("files") || !vm.count("mpq") || vm.count("help")) { std::cout << "usage: <mpq> [<files> ...]" << std::endl << std::endl << desc << std::endl; return 1; } std::vector<std::string> files(vm["files"].as< std::vector<std::string> >()); std::vector<FileEntry> toAdd; fs::path mpqPath(vm["mpq"].as<std::string>()); if(fs::exists(mpqPath)) { if(vm.count("force")) fs::remove(mpqPath); else throw std::runtime_error("mpq does already exist"); } for(std::vector<std::string>::iterator path = files.begin(); path != files.end(); ++path) { if(fs::is_regular_file(*path)) toAdd.push_back(FileEntry(*path, *path)); if(!fs::is_directory(*path)) //no symlinks etc continue; for(fs::recursive_directory_iterator file(*path), end; file != end; ++file) if(fs::is_regular_file(file->path())) toAdd.push_back(FileEntry(file->path(), makeRelative(*path, file->path()))); } for(std::vector<FileEntry>::iterator it = toAdd.begin(); it != toAdd.end(); ++it) std::cout << it->realPath << " >> " << it->mpqPath << std::endl; HANDLE mpq; if(!SFileCreateArchive(mpqPath.string().c_str(), MPQ_CREATE_ARCHIVE_V2, toAdd.size(), &mpq)) throw std::runtime_error("couldn't create mpq"); SFileSetLocale(0); size_t counter(0); for(std::vector<FileEntry>::iterator it = toAdd.begin(); it != toAdd.end(); ++it) { loadbar(++counter, toAdd.size()); if(!SFileAddFileEx(mpq, it->realPath.string().c_str(), it->mpqPath.string().c_str(), MPQ_FILE_COMPRESS, MPQ_COMPRESSION_BZIP2, MPQ_COMPRESSION_BZIP2)) std::cout << "couldn't add file " << it->realPath << std::endl; } std::cout << std::endl; SFileCompactArchive(mpq, NULL, false); SFileFlushArchive(mpq); SFileCloseArchive(mpq); return 0; } catch (const std::exception& e) { std::cerr << "error: " << e.what() << "\n"; }
int KProtocolTAR::OpenDir(KURL *url) { //debug("KProtocolTAR::OpenDir(%s)",url->url().data()); dirpath = url->path(); // extracting /xxx from a tarfile containing the file xxx won't work while( dirpath[0] == '/' ) dirpath.remove(0,1); QString Command( "tar -%stvf -"); if (dirpath[0] != '\0') { Command += " \""; Command += dirpath; Command += "\""; } int rc = AttachTAR( Command.data() ); if (rc == FAIL) return FAIL; dirfile = fdopen( Slave.out, "r" ); // debug ("Tar: opendir for %s", dirpath.data()); dirlist.clear(); char buffer[1024]; char *readstr = "ok"; // to prevent breaking the loop at startup int moredata = 1; KProtocolDirEntry *de; do { int iomask = Slave.WaitIO( 1, 0 ); if( iomask & KSlave::IN || iomask == 0 ) moredata = HandleRefill(); if( iomask & KSlave::OUT || !moredata ) { char p_access[80], p_owner[80], p_group[80]; char p_size[80], p_date[80], p_name[250]; readstr = fgets(buffer,1024,dirfile); if (readstr && (sscanf(buffer, " %[-dlrwxst] %[0-9.a-zA-Z_]/%[0-9.a-zA-Z_] %[0-9] %17[a-zA-Z0-9:- ] %[^\n]", // is \r necessary, together with \n ? Not here... p_access, p_owner, p_group, p_size, p_date, p_name) == 6)) { // Link? QString tmp( p_name ); if ( p_access[0] == 'l' ) { int i = tmp.findRev( " -> " ); if ( i != -1 ) tmp.truncate( i ); //forget link } if (makeRelative(tmp)==FAIL) { if (tmp.right(1)!="/") tmp+="/"; // Try again with slash appended if (makeRelative(tmp)!=FAIL) // The file exists but not the directory return Error(KIO_ERROR_NotADirectory, "No such dir", 0); else return Error(KIO_ERROR_CouldNotList, "No such dir", 0); } int i = tmp.find ("/"); // this is first slash; If there is something behind this slash, // these are files in that subdir and we don't want to see them. if (i != -1) { if (tmp[i+1] != '\0') // yes there is something { // debug("there is something : %s, tmp1=%s",tmp.data(),tmp1.data()); // hack to add missing parent directories if necessary. tmp.truncate(i); if (isDirStored(tmp.data())) continue; // Ignore it debug("emulating dir %s",tmp.data()); // otherwise, create wrong information about a directory and // add it to dirlist, which is done below. strcpy(p_access, "d?????????"); strcpy(p_size, "0"); strcpy(p_owner, "???"); strcpy(p_group, "???"); } else tmp.truncate(i); } // else? this is a file; // now when we removed the path and slashes, If this an // empty string, then it can be either dir name itself // or a file with that name if (tmp.isEmpty()) { if (p_access[0] != 'd') { debug ("bad, you tried to openDir a file"); CloseDir(); return FAIL; } } else { de = new KProtocolDirEntry; de->access = p_access; de->owner = p_owner; de->group = p_group; de->size = atoi(p_size); de->isdir = ( p_access[0] == 'd' ); de->name = tmp.data(); if( de->isdir ) de->name += "/"; de->date = p_date; dirlist.append(de); // debug ("Tar: openDir: %s", de->name.data()); } } else if (readstr) { fprintf(stderr,"!! Couldn't parse %s",buffer); } } } while( readstr ); if (dirlist.count()==0) // tar returned nothing : probably a wrong dir return Error(KIO_ERROR_CouldNotList, "No such dir", 0); dirlist.first(); return SUCCESS; }