Ejemplo n.º 1
0
void createDiffFile(string fileName) {
	string fileDirectory = getFilePath(fileName);
	string diff = fileName + "-diff.dat";
	ofstream diffFile(fileDirectory + '\\' + diff);
	diffFile << "0\nV0\n0";
	diffFile.close();
}
Ejemplo n.º 2
0
bool HGTController::expandDiff(CourgetteInstance* ci, MCFCore::MCFFile* file)
{
	m_hFile.close();

	UTIL::FS::Path path(m_szInstallDir, file->getName(), false);
	path += file->getPath();

	gcString oldFile = path.getFullPath();
	gcString diffFile("{0}_diff", m_szFile);

	try
	{
		UTIL::FS::FileHandle fhSrc(m_szFile, UTIL::FS::FILE_READ);
		UTIL::FS::FileHandle fhDest(diffFile.c_str(), UTIL::FS::FILE_WRITE);
		fhSrc.seek(file->getOffSet());

		decompressDiff(file->getDiffSize(), fhSrc, fhDest);

		UTIL::FS::delFile(diffFile);
	}
	catch (gcException)
	{
		UTIL::FS::delFile(diffFile);
		return false;
	}

	MD5Progressive md5;

	try
	{
		m_hFile.open(m_szFile, UTIL::FS::FILE_APPEND);
		m_hFile.seek(file->getOffSet());
	}
	catch (...)
	{
		return false;
	}

	uint64 fsize = file->getSize();
	uint64 tot = 0;

	bool res = ci->applyDiff(oldFile.c_str(), diffFile.c_str(), [this, &md5, &tot, fsize](const char* buff, size_t size) -> bool
	{
		md5.update(buff, size);
		return writeDiff(tot, fsize, buff, size);
	});

	return (res && md5.finish() == file->getCsum());
}
Ejemplo n.º 3
0
bool addExistingFile(string fileName, string address, string owner) {
	string fileDirectory = getFilePath(fileName);

	if (!isSaved(fileName)) throw accessError(NOT_SAVED);
	if (!isExisting(address)) throw accessError(NO_FILE);
	if (!isAccessable(fileName, owner)) throw accessError(NOT_USER);

	diffTree tree(fileName);

	diffNode* start = tree.getTreePathByID(tree.currentVersion);
	diffNode* finish = tree.getTreePath();

	modernizeFile(fileName, tree.getVersionsPath(start, finish));

	vector<diffString> exf;
	vector<diffString> newf;
	ifstream existingFile(fileDirectory + '\\' + fileName);
	ifstream newFile(address);
	while (!existingFile.eof()) {
		diffString buf;
		buf.text = new char[MAX];
		existingFile.getline(buf.text, MAX);
		buf.length = strlen(buf.text);
		exf.push_back(buf);
	}
	while (!newFile.eof()) {
		diffString buf;
		buf.text = new char[MAX];
		newFile.getline(buf.text, MAX);
		buf.length = strlen(buf.text);
		newf.push_back(buf);
	}
	vector<diffString> difference = diff(exf, newf);
	showChangesVector(difference);
	diffNode* child = new diffNode;
	child->diffLine = difference;
	tree.addNode(finish, child);

	ofstream diffFile(fileDirectory + '\\' + fileName + "-diff.dat");
	diffFile.close();

	tree.printDiffTreeFile(fileName);

	deleteFile(fileName);
	addFile(fileName, address);

	return true;
}
Ejemplo n.º 4
0
int bsdiff(const char* old, const char* newf, const char* patch) {
	return diffFile(old, newf, patch);//diff(argc, argv);
}
Ejemplo n.º 5
0
int C3dsTool::Action()
{
	if (m_eAction == kActionExtract)
	{
		if (!extractFile())
		{
			printf("ERROR: extract file failed\n\n");
			return 1;
		}
	}
	if (m_eAction == kActionCreate)
	{
		if (!createFile())
		{
			printf("ERROR: create file failed\n\n");
			return 1;
		}
	}
	if (m_eAction == kActionEncrypt)
	{
		if (!encryptFile())
		{
			printf("ERROR: encrypt file failed\n\n");
			return 1;
		}
	}
	if (m_eAction == kActionUncompress)
	{
		if (!uncompressFile())
		{
			printf("ERROR: uncompress file failed\n\n");
			return 1;
		}
	}
	if (m_eAction == kActionCompress)
	{
		if (!compressFile())
		{
			printf("ERROR: compress file failed\n\n");
			return 1;
		}
	}
	if (m_eAction == kActionTrim)
	{
		if (!trimFile())
		{
			printf("ERROR: trim file failed\n\n");
			return 1;
		}
	}
	if (m_eAction == kActionPad)
	{
		if (!padFile())
		{
			printf("ERROR: pad file failed\n\n");
			return 1;
		}
	}
	if (m_eAction == kActionDiff)
	{
		if (!diffFile())
		{
			printf("ERROR: create patch file failed\n\n");
			return 1;
		}
	}
	if (m_eAction == kActionPatch)
	{
		if (!patchFile())
		{
			printf("ERROR: apply patch file failed\n\n");
			return 1;
		}
	}
	if (m_eAction == kActionSample)
	{
		return sample();
	}
	if (m_eAction == kActionHelp)
	{
		return Help();
	}
	return 0;
}