void ofPackageManager::generateDatabaseEntryFile() { ofJson dataBaseEntryJson; if (hasPackageFile(getAbsolutePath(_cwdPath))) { ofFile packageFile(getAbsolutePath(_cwdPath)); ofJson packageJson; packageJson << packageFile; dataBaseEntryJson["name"] = packageJson["name"]; dataBaseEntryJson["author"] = packageJson["author"]; dataBaseEntryJson["url"] = packageJson["url"]; dataBaseEntryJson["cloneUrl"] = packageJson["cloneUrl"]; dataBaseEntryJson["license"] = packageJson["license"]; dataBaseEntryJson["type"] = packageJson["type"]; } else { dataBaseEntryJson["name"] = getStringAnswer("package name?"); dataBaseEntryJson["author"] = getStringAnswer("author?"); dataBaseEntryJson["url"] = getStringAnswer("url?"); dataBaseEntryJson["cloneUrl"] = getStringAnswer("cloneUrl?"); dataBaseEntryJson["license"] = getStringAnswer("license?"); dataBaseEntryJson["type"] = getOptionAnswer("type", {"app", "addon"}); } std::string name = dataBaseEntryJson["name"]; ofFile dataBaseEntryFile(ofFilePath::addTrailingSlash(getAbsolutePath(_cwdPath)) + name + ".json", ofFile::ReadWrite); if (!dataBaseEntryFile.exists()) { dataBaseEntryFile.create(); } dataBaseEntryFile << dataBaseEntryJson.dump(4); }
bool MimeTypeWriter::write() { const QString packageFileName = d->localFilePath(); kDebug() << "writing" << packageFileName; QFile packageFile(packageFileName); if (!packageFile.open(QIODevice::WriteOnly)) { kError() << "Couldn't open" << packageFileName << "for writing"; return false; } QXmlStreamWriter writer(&packageFile); writer.setAutoFormatting(true); writer.writeStartDocument(); if (!d->m_marker.isEmpty()) { writer.writeComment(d->m_marker); } const QString nsUri = "http://www.freedesktop.org/standards/shared-mime-info"; writer.writeDefaultNamespace(nsUri); writer.writeStartElement("mime-info"); writer.writeStartElement(nsUri, "mime-type"); writer.writeAttribute("type", d->m_mimeType); if (!d->m_comment.isEmpty()) { writer.writeStartElement(nsUri, "comment"); writer.writeCharacters(d->m_comment); writer.writeEndElement(); // comment } if (!d->m_iconName.isEmpty()) { // User-specified icon name if (sharedMimeInfoSupportsIcon()) { writer.writeStartElement(nsUri, "icon"); writer.writeAttribute("name", d->m_iconName); writer.writeEndElement(); // icon } } // Allow this local definition to override the global definition writer.writeStartElement(nsUri, "glob-deleteall"); writer.writeEndElement(); // glob-deleteall foreach(const QString& pattern, d->m_patterns) { writer.writeStartElement(nsUri, "glob"); writer.writeAttribute("pattern", pattern); writer.writeEndElement(); // glob } writer.writeEndElement(); // mime-info writer.writeEndElement(); // mime-type writer.writeEndDocument(); return true; }
QString computePackageHash( const QString &path ) { QFile packageFile( path ); if ( !packageFile.open( QIODevice::ReadOnly ) ) printf( "failed to open package file\n" ); QCryptographicHash packageHash( QCryptographicHash::Md5 ); while ( !packageFile.atEnd() ) packageHash.addData( packageFile.read( std::numeric_limits<int>::max() ) ); packageFile.close(); return QString( packageHash.result().toBase64() ); }
void Wizard::installExtraMimes(QString baseName, QStringList globs) { QString mimefile = baseName; mimefile.replace('/', '-'); KMimeType::Ptr mime = KMimeType::mimeType(baseName); if (!mime) { kDebug() << "KMimeTypeTrader: mimeType " << baseName << " not found"; } else { QStringList extensions = mime->patterns(); QString comment = mime->comment(); foreach(const QString &glob, globs) { if (!extensions.contains(glob)) extensions << glob; } kDebug() << "EXTS: " << extensions; QString packageFileName = KStandardDirs::locateLocal("xdgdata-mime", "packages/" + mimefile + ".xml"); kDebug() << "INSTALLING NEW MIME TO: " << packageFileName; QFile packageFile(packageFileName); if (!packageFile.open(QIODevice::WriteOnly)) { kError() << "Couldn't open" << packageFileName << "for writing"; return; } QXmlStreamWriter writer(&packageFile); writer.setAutoFormatting(true); writer.writeStartDocument(); const QString nsUri = "http://www.freedesktop.org/standards/shared-mime-info"; writer.writeDefaultNamespace(nsUri); writer.writeStartElement("mime-info"); writer.writeStartElement(nsUri, "mime-type"); writer.writeAttribute("type", baseName); if (!comment.isEmpty()) { writer.writeStartElement(nsUri, "comment"); writer.writeCharacters(comment); writer.writeEndElement(); // comment } foreach(const QString& pattern, extensions) { writer.writeStartElement(nsUri, "glob"); writer.writeAttribute("pattern", pattern); writer.writeEndElement(); // glob } writer.writeEndElement(); // mime-info writer.writeEndElement(); // mime-type writer.writeEndDocument(); }
Components::Cookie* AssemblyFactoryImpl::create_assembly (const char* assembly_loc) throw (Components::Deployment::InvalidLocation, Components::CreateFailure) { DEBUG_OUT2( "AssemblyFactoryImpl: creating new assembly for ", assembly_loc ); // // exclusive // QedoLock lock(&mutex_); // // get path // XMLURL uri(assembly_loc); const XMLCh* p = uri.getPath(); if(!p) { NORMAL_ERR2( "AssemblyFactoryImpl: invalid assembly location: ", assembly_loc ); throw Components::Deployment::InvalidLocation(); } std::string name = Qedo::transcode(p); std::string::size_type pos = name.find_last_of("/"); if (pos != std::string::npos) { name.erase(0, pos + 1); } // // make input stream // URLInputSource inputSource(uri); BinInputStream* inputStream; try { inputStream = inputSource.makeStream(); } catch(...) { NORMAL_ERR2( "AssemblyFactoryImpl: invalid assembly location: ", assembly_loc ); throw Components::Deployment::InvalidLocation(); } if (!inputStream) { NORMAL_ERR2( "AssemblyFactoryImpl: invalid assembly location", assembly_loc ); throw Components::Deployment::InvalidLocation(); } // // create new cookie // Cookie_impl* new_cookie = new Cookie_impl(); const char * s = new_cookie->to_string(); std::string uuid = s; CORBA::string_free(const_cast<char*>(s)); // // store the package // std::string dir = getPath( packageDirectory_ ) + uuid; if( makeDir(dir) ) { NORMAL_ERR3( "AssemblyFactoryImpl: directory ", dir, " can not be created"); throw Components::CreateFailure(); } std::string package_name = getPath( dir ) + name; std::ofstream packageFile(package_name.c_str(), std::ios::binary|std::ios::app); if ( ! packageFile) { NORMAL_ERR2( "AssemblyFactoryImpl: cannot open file ", package_name ); throw Components::CreateFailure(); } unsigned char* buf = new unsigned char[4096]; unsigned int len = inputStream->readBytes(buf, 4096); while (len) { packageFile.write((const char*)buf, len); len = inputStream->readBytes(buf, 4096); } delete [] buf; packageFile.close(); delete inputStream; // // create new assembly // AssemblyImpl* ass = new AssemblyImpl(package_name, new_cookie, nameService_); assemblies_.push_back(ass); DEBUG_OUT( "..... done" ); return new_cookie; }