int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QStringList args = a.arguments(); if (args.size() < 4) { out << "Usage: " << args[0] << " <version> <qtdir> <platform> [load]\n" << flush; return 1; } const QString version = args[1]; const QDir qtdir = QDir(args[2]); const QString platform = args[3]; if (args.size() > 5) { if (args[4] == "load") { silent = false; } } if (!QRegularExpression("\\d\\.\\d\\.\\d").match(version).hasMatch()) { out << "<version> has to be in the format #.#.#\n" << flush; return 1; } const QString short_version = version.left(3); GetFiles::version = version; // mappings etc. QList<FileGroup> mappings; mappings.append(FileGroup("bin", &GetFiles::binaryFiles)); mappings.append(FileGroup("doc", &GetFiles::docFiles)); mappings.append(FileGroup("examples", &GetFiles::exampleFiles)); mappings.append(FileGroup("imports", &GetFiles::importsFiles)); mappings.append(FileGroup("include", &GetFiles::includeFolders)); mappings.append(FileGroup("lib", &GetFiles::libFiles)); mappings.append(FileGroup("libexec", &GetFiles::libExecFiles)); mappings.append(FileGroup("mkspecs", &GetFiles::mkSpecFiles)); mappings.append(FileGroup("phrasebooks", &GetFiles::phrasebookFiles)); mappings.append(FileGroup("plugins", &GetFiles::pluginNames)); mappings.append(FileGroup("qml", &GetFiles::qmlFiles)); mappings.append(FileGroup("translations", &GetFiles::translationFiles)); QStringList modules; for (const FileGroup &files : mappings) { modules.append((files.fileGetter)().keys()); } modules.removeDuplicates(); out << "Copying files for the following modules: " << modules.join(", ") << "\n" << flush; QDir baseDir; for (const QString &module : modules) { if (baseDir.exists(module + ".tar.gz")) { out << "Skiping already existing module " << module << "\n" << flush; continue; } out << "Copying files for module " << module << "\n" << flush; baseDir.mkdir(module); QDir dir(baseDir); dir.cd(module); for (const FileGroup &files : mappings) { QStringList fs = (files.fileGetter)()[module]; if (fs.isEmpty()) { continue; } out << " Copying " << files.name << " files...\n" << flush; QDir fromDir(qtdir); fromDir.cd(files.name); QDir toDir(dir); toDir.mkdir(files.name); toDir.cd(files.name); copyFiles(fs, fromDir, toDir); } out << " Creating install file for module " << module << "...\n" << flush; { QFile installFile(dir.absoluteFilePath("install.js")); if (!installFile.open(QFile::WriteOnly | QFile::Truncate)) { out << "Error opening install file: " << installFile.errorString() << "\n"; return -1; } QTextStream js(&installFile); js << "FileSystem.mkpath(Paths.installPath);\n"; for (const FileGroup &groups : mappings) { if (groups.fileGetter().contains(module)) { js << "FileSystem.install(\"" << groups.name << "\", Paths.installPath + \"/" << groups.name << "\");\n"; } } js << "\n"; js.flush(); installFile.close(); } out << " Creating removal file for module " << module << "...\n" << flush; { QFile removalFile(dir.absoluteFilePath("remove.js")); if (!removalFile.open(QFile::WriteOnly | QFile::Truncate)) { out << "Error opening remove file: " << removalFile.errorString() << "\n"; return -1; } QTextStream js(&removalFile); for (const FileGroup &group : mappings) { QStringList files = (group.fileGetter)()[module]; for (const QString &file : files) { js << "FileSystem.remove(Paths.installPath + \"/" << group.name << "/" << file << "\");\n"; } } js << "\n"; js.flush(); removalFile.close(); } out << " Creating archive for module " << module << "...\n" << flush; { KArchive *arch = new KTar(baseDir.absoluteFilePath( QString("%1-%2-%3.tar.gz").arg(module, version, platform))); arch->open(QIODevice::ReadWrite); for (const QString &directory : dir.entryList(QDir::NoDotAndDotDot | QDir::Dirs)) { arch->addLocalDirectory(dir.absoluteFilePath(directory), directory); } for (const QString &file : dir.entryList(QDir::NoDotAndDotDot | QDir::Files)) { arch->addLocalFile(dir.absoluteFilePath(file), file); } arch->close(); } } out << "Creating metadata file...\n" << flush; { QFile meta(baseDir.absoluteFilePath("meta.json")); meta.open(QFile::WriteOnly | QFile::Truncate); QMap<QString, QString> descs = GetFiles::descriptions(); QMap<QString, QStringList> deps = GetFiles::dependencies(); QMap<QString, QMap<QString, QStringList>> ndeps = GetFiles::nativeDependencies(); QJsonArray root; for (const QString &module : modules) { QStringList dependencies = deps[module]; dependencies.removeAll(""); dependencies.removeDuplicates(); QMap<QString, QStringList> nDependencies = ndeps[module]; QJsonObject m; m.insert("id", module); m.insert("description", descs[module]); m.insert("version", version); m.insert("platform", platform); m.insert("url", QString("http://localhost/soqute/archives/%1-%2-%3.tar.gz") .arg(module, version, platform)); QJsonArray deps; for (const QString &dep : dependencies) { QJsonObject obj; obj.insert("id", dep); obj.insert("version", version); deps.append(obj); } m.insert("dependencies", deps); QJsonObject nativeDependencies; for (const QString &manager : nDependencies.keys()) { QJsonArray packages = QJsonArray::fromStringList(nDependencies[manager]); nativeDependencies.insert(manager, packages); } m.insert("nativeDependencies", nativeDependencies); root.append(m); } meta.write(QJsonDocument(root).toJson()); } out << "Installing files to server...\n" << flush; { QDir serverRoot("/var/www"); if (!serverRoot.exists("soqute")) { serverRoot.mkdir("soqute"); } serverRoot.cd("soqute"); if (!serverRoot.exists("archives")) { serverRoot.mkdir("archives"); } serverRoot.cd("archives"); for (const QString &archive : baseDir.entryList(QStringList() << "*.tar.gz", QDir::Files)) { out << " Installing " << archive << " to server...\n" << flush; if (serverRoot.exists(archive)) { serverRoot.remove(archive); } QFile::copy(baseDir.absoluteFilePath(archive), serverRoot.absoluteFilePath(archive)); } serverRoot.cdUp(); out << " Installing meta.json to server...\n" << flush; if (serverRoot.exists("meta.json")) { QFile server(serverRoot.absoluteFilePath("meta.json")); Q_ASSERT(server.open(QFile::ReadOnly | QFile::Truncate)); QFile local(baseDir.absoluteFilePath("meta.json")); Q_ASSERT(local.open(QFile::ReadOnly)); QJsonDocument serverDoc = QJsonDocument::fromJson(server.readAll()); server.close(); QJsonArray serverArray = serverDoc.array(); QJsonDocument localDoc = QJsonDocument::fromJson(local.readAll()); local.close(); QJsonArray localArray = localDoc.array(); QVariantList res = serverArray.toVariantList(); res.append(localArray.toVariantList()); Q_ASSERT(server.open(QFile::WriteOnly | QFile::Truncate)); server.write(QJsonDocument(QJsonArray::fromVariantList(res)).toJson()); server.close(); } else { QFile::copy(baseDir.absoluteFilePath("meta.json"), serverRoot.absoluteFilePath("meta.json")); } } out << "Done\n" << flush; return 0; }
void MyView::startFolderEncode(TQStringList selec,TQStringList encryptOptions,bool ,bool symetric) { TQString extension; if (compressionScheme==0) extension=".zip"; else if (compressionScheme==1) extension=".tar.gz"; else extension=".tar.bz2"; if (encryptOptions.find("armor")!=encryptOptions.end () ) extension+=".asc"; else if (KGpgSettings::pgpExtension()) extension+=".pgp"; else extension+=".gpg"; KURL encryptedFile(droppedUrls.first().path()+extension); TQFile encryptedFolder(droppedUrls.first().path()+extension); if (encryptedFolder.exists()) { dialogue->hide(); TDEIO::RenameDlg *over=new TDEIO::RenameDlg(0,i18n("File Already Exists"),TQString(),encryptedFile.path(),TDEIO::M_OVERWRITE); if (over->exec()==TQDialog::Rejected) { delete over; return; } encryptedFile=over->newDestURL(); delete over; dialogue->show(); /////// strange, but if dialogue is hidden, the passive popup is not displayed... } pop = new KPassivePopup(); pop->setView(i18n("Processing folder compression and encryption"),i18n("Please wait..."),TDEGlobal::iconLoader()->loadIcon("kgpg",TDEIcon::Desktop)); pop->setAutoDelete(false); pop->show(); kapp->processEvents(); dialogue->slotAccept(); dialogue=0L; KArchive *arch; if (compressionScheme==0) arch=new KZip(kgpgfoldertmp->name()); else if (compressionScheme==1) arch=new KTar(kgpgfoldertmp->name(), "application/x-gzip"); else arch=new KTar(kgpgfoldertmp->name(), "application/x-bzip2"); if (!arch->open( IO_WriteOnly )) { KMessageBox::sorry(0,i18n("Unable to create temporary file")); delete arch; return; } arch->addLocalDirectory (droppedUrls.first().path(),droppedUrls.first().fileName()); arch->close(); delete arch; KgpgInterface *folderprocess=new KgpgInterface(); folderprocess->KgpgEncryptFile(selec,KURL(kgpgfoldertmp->name()),encryptedFile,encryptOptions,symetric); connect(folderprocess,TQT_SIGNAL(encryptionfinished(KURL)),TQT_TQOBJECT(this),TQT_SLOT(slotFolderFinished(KURL))); connect(folderprocess,TQT_SIGNAL(errormessage(TQString)),TQT_TQOBJECT(this),TQT_SLOT(slotFolderFinishedError(TQString))); }