Пример #1
0
void HHCObject::fromDir(int level,QString dir,QString temp){
    QDir dirModel;
    dirModel.setCurrent(dir);
    QStringList list = dirModel.entryList();
    if(list.contains("index.html",Qt::CaseInsensitive)){
        QFileInfo fileInfo(dir+"/index.html");
        QString absDir = temp.length()>0?temp+"/index.html":"index.html";
        treeModel->addModelData(level, "index.html",absDir);
    }else if(list.contains("index.htm",Qt::CaseInsensitive)){
        QFileInfo fileInfo(dir+"/index.htm");
        QString absDir = temp.length()>0?temp+"/index.htm":"index.htm";
        treeModel->addModelData(level, "index.htm",absDir);
    }
    foreach(QString fileName,list){        
        if(fileName.compare(".")==0||fileName.compare("..")==0||fileName.compare("index.htm")==0||fileName.compare("index.html")==0){
            continue;
        }
        if(!(fileName.endsWith(".htm",Qt::CaseInsensitive)||fileName.endsWith(".html",Qt::CaseInsensitive))){
            continue;
        }
        QFileInfo fileInfo(dir+"/"+fileName);
        QString absDir = temp.length()>0?temp+"/"+fileName:fileName;
        treeModel->addModelData(level, fileName,absDir);
        if(fileInfo.isDir()){
            level++;
            fromDir(level*4,dir+"/"+fileName,absDir);
            level--;
        }
    }
    save();
}
Пример #2
0
QVariant AbifReader::data(const QString &key)
{
    if (!mDirs.contains(key))
        return QVariant();

    AbifDir dir = directory(key);
    return fromDir(dir);
}
Пример #3
0
        bool DeepCopyDirectory(const char* from, const char* to)
        {
            if (!from || !to) return false;

            DirectoryTree fromDir(from);

            if (!fromDir) return false;

            CreateDirectoryIfNotExists(to);
            DirectoryTree toDir(to);

            if (!toDir) return false;

            bool success(true);            

            auto visitor = [to,&success](const DirectoryTree*, const DirectoryEntry& entry)
            {
                auto newPath = Aws::FileSystem::Join(to, entry.relativePath);

                if (entry.fileType == Aws::FileSystem::FileType::File)
                {
                    Aws::OFStream copyOutStream(newPath.c_str());
                    Aws::IFStream originalStream(entry.path.c_str());

                    if(!copyOutStream.good() || !originalStream.good())
                    {
                        success = false; 
                        return false;
                    }

                    std::copy(std::istreambuf_iterator<char>(originalStream),
                        std::istreambuf_iterator<char>(), std::ostreambuf_iterator<char>(copyOutStream));
                }
                else if (entry.fileType == Aws::FileSystem::FileType::Directory)
                {
                    success = CreateDirectoryIfNotExists(newPath.c_str());
                    return success;
                }

                return success;
            };

            fromDir.TraverseDepthFirst(visitor);
            return success;
        }
Пример #4
0
HHCObject::HHCObject(QString title,QString fileName)
{
    this->title = title;
    this->fileName = fileName;

    treeModel = new QTreeModel(title);

    if(fileName.endsWith(".hhc")){
        QTreeModelHandler handler(treeModel);
        QHHCParser parser;
        parser.parse(fileName,&handler);
    }else{
        QFileInfo fileInfo(fileName);
        if(fileInfo.isDir())
            fromDir(0,fileName,"");
    }

    connect(treeModel,SIGNAL(dataChanged(QModelIndex,QModelIndex)),this,SLOT(dataChanged(QModelIndex,QModelIndex)));
}
Пример #5
0
void backup(char* from, char* to) {
  JFile fromDir(from);
  JFile toDir(to);
  if (fromDir == toDir) {
    printf("Destination and Source are the same!\n");
    return;
  }
  if (!fromDir.exists()) {
    printf("Source Directory Not Exist!\n");
    return;
  }
  if (!toDir.exists()) {
    if (!toDir.makeDir()) {
      printf("Can not create Distination Directory!\n");
      return;
    }
  }
  printf("Backup from %s to %s\n", 
    (char*)fromDir.getPath(), (char*)toDir.getPath());
  recursive(fromDir, toDir);
}
Пример #6
0
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;
}