コード例 #1
0
ファイル: converter.cpp プロジェクト: SirAnthony/mpkg
int setver_package(const string& filename, const string& version) {
	SourcePackage spkg;
	BinaryPackage pkg;
	bool binary_pkg = false;
	string xml_path;
	string pkgType = getExtension(filename);
	if (pkgType=="tgz" || pkgType=="tbz" || pkgType=="txz" || pkgType=="tlz") {
		binary_pkg = true;
		pkg.setInputFile(filename);
		pkg.unpackFile();
		xml_path = pkg.getDataFilename();
	}
	if (filename.find(".spkg")!=std::string::npos) {

		spkg.setInputFile(filename);
		spkg.unpackFile();
		xml_path = spkg.getDataFilename();
	}
	if (!FileExists(xml_path)) return -2;
	XMLResults xmlErrCode;
	XMLNode _node = XMLNode::parseFile(xml_path.c_str(), "package", &xmlErrCode);
	if (xmlErrCode.error != eXMLErrorNone)
	{
		mError("parse error");
		fprintf(stderr, "%s\n", _node.getError(xmlErrCode.error));
		return -1;
	}
	mDebug("File opened");
	if (_node.nChildNode("version")==0)
	{
		mError("Invalid package");
		return -1;
	}
	string old_ver = _node.getChildNode("version").getText();
	_node.getChildNode("version").updateText(version.c_str());
	string url;
	if (_node.nChildNode("mbuild")!=0 && _node.getChildNode("mbuild").nChildNode("url")!=0) {
		url = _node.getChildNode("mbuild").getChildNode("url").getText();
		strReplace(&url, old_ver, version);
		_node.getChildNode("mbuild").getChildNode("url").updateText(url.c_str());
	}
	_node.writeToFile(xml_path.c_str());
	if (binary_pkg) pkg.packFile();
	else spkg.packFile();
	return 0;


}
コード例 #2
0
ファイル: converter.cpp プロジェクト: SirAnthony/mpkg
int buildup_package(const string& filename)
{
	SourcePackage spkg;
	BinaryPackage pkg;
	bool binary_pkg = false;
	string xml_path;
	string pkgType = getExtension(filename);
	if (pkgType=="tgz" || pkgType=="tbz" || pkgType=="txz" || pkgType=="tlz") {
		binary_pkg = true;
		pkg.setInputFile(filename);
		pkg.unpackFile();
		xml_path = pkg.getDataFilename();
	}
	if (filename.find(".spkg")!=std::string::npos) {

		spkg.setInputFile(filename);
		spkg.unpackFile();
		xml_path = spkg.getDataFilename();
	}
	if (!FileExists(xml_path)) return -2;
	XMLResults xmlErrCode;
	XMLNode _node = XMLNode::parseFile(xml_path.c_str(), "package", &xmlErrCode);
	if (xmlErrCode.error != eXMLErrorNone)
	{
		mError("parse error");
		fprintf(stderr, "%s\n", _node.getError(xmlErrCode.error));
		return -1;
	}
	mDebug("File opened");
	if (_node.nChildNode("build")==0)
	{
		mError("Invalid package");
		return -1;
	}
	int build_num = atoi(_node.getChildNode("build").getText());
	_node.getChildNode("build").updateText(IntToStr(build_num+1).c_str());
	_node.writeToFile(xml_path.c_str());
	if (binary_pkg) pkg.packFile();
	else spkg.packFile();
	return 0;

}