Rev 58 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
#pragma once
#include "CyString.h"
#include "VirtualFileSystem.h"
#include "lists.h"
#include "StringList.h"
enum {DIFFTYPE_ADDITION, DIFFTYPE_REMOVAL, DIFFTYPE_CHANGE};
tstruct SDiffEntry {
int iType;
int iID;
} SDiffEntry;
tstruct SDiffEntryAddition : SDiffEntry {
CyString sEntry;
SDiffEntryAddition() { iType = DIFFTYPE_ADDITION; }
} SDiffEntryAddition;
tstruct SDiffEntryRemoval : SDiffEntry {
SDiffEntryRemoval() { iType = DIFFTYPE_REMOVAL; }
} SDiffEntryRemoval;
tstruct SDiffEntryChange : SDiffEntry {
SDiffEntryChange() { iType = DIFFTYPE_CHANGE; }
int iPos;
CyString sFrom;
CyString sEntry;
} SDiffEntryChange;
tstruct SDiffFile {
CyString sFile;
CLinkList<SDiffEntry> m_lEntries;
} SDiffFile;
enum {MDERR_NONE, MDERR_FILENOTFOUND, MDERR_CANTOPEN, MDERR_CANTOPENMOD};
tclass CModDiff
{
public:
// static
static bool CanBeDiffed(const CyString &file);
// constructors
CModDiff(CyString &dir, int maxPatch = 0);
~CModDiff(void);
// public functions
void SetTempDirectory(CyString &temp) { m_sTempDir = temp; }
bool LoadDirectory(CyString &dir);
bool IsLoaded() { return m_bLoaded; }
const CyString &GetDirectory() { return m_sCurrentDir; }
bool CreateDiff(CyString &mod);
bool DiffFile(CyString &baseFile, CyString &modFile, CyString &fileType);
void Clean();
bool WriteDiff(CyString &file);
bool ReadDiff(CyString &file);
bool ApplyDiff(CyString &mod);
bool ApplyMod(CyString &mod);
void SetMaxPatch(int patch) { m_iMaxPatch = patch; }
CLinkList<SDiffFile> &GetDiffFiles() { return m_lFiles; }
void ClearError() { m_iError = MDERR_NONE; }
int Error() { return m_iError; }
private:
// private functions
int GetAmountPosition(const CyString &fileType);
bool IsLineComplete(CyString &line, CyString &fileType, bool first);
bool ReadGameFile(CyString &file, CyStringList *lines, int *id);
void CompareLine(CyString &line1, CyString &line2, int type, int id, SDiffFile *diffFile);
bool ValidFile(CyString &file);
// Variables
CyString m_sCurrentDir; // the current game directory (that the VFS is opened too)
CyString m_sTempDir; // temporary dir (used to write temporary files to)
CVirtualFileSystem m_fileSystem; // the VFS of the game directory (for finding the files to use)
CLinkList<SDiffFile> m_lFiles; // list of files that have changed
bool m_bLoaded; // if the directory is loaded and ready to be diffed
int m_iError; // error id of process
int m_iMaxPatch; // The max fake patch to check to
};