| 1 | cycrow | 1 | #pragma once
 | 
        
           |  |  | 2 |   | 
        
           |  |  | 3 | #include "CyString.h"
 | 
        
           |  |  | 4 | #include "VirtualFileSystem.h"
 | 
        
           |  |  | 5 | #include "lists.h"
 | 
        
           |  |  | 6 | #include "StringList.h"
 | 
        
           |  |  | 7 |   | 
        
           | 35 | cycrow | 8 | using namespace SPK;
 | 
        
           |  |  | 9 |   | 
        
           | 1 | cycrow | 10 | enum {DIFFTYPE_ADDITION, DIFFTYPE_REMOVAL, DIFFTYPE_CHANGE};
 | 
        
           |  |  | 11 |   | 
        
           |  |  | 12 | tstruct SDiffEntry {
 | 
        
           |  |  | 13 | 	int			iType;
 | 
        
           |  |  | 14 | 	int			iID;
 | 
        
           |  |  | 15 | } SDiffEntry;
 | 
        
           |  |  | 16 |   | 
        
           |  |  | 17 | tstruct SDiffEntryAddition : SDiffEntry {
 | 
        
           |  |  | 18 | 	CyString	sEntry;
 | 
        
           |  |  | 19 | 	SDiffEntryAddition() { iType = DIFFTYPE_ADDITION; }
 | 
        
           |  |  | 20 | } SDiffEntryAddition;
 | 
        
           |  |  | 21 |   | 
        
           |  |  | 22 | tstruct SDiffEntryRemoval : SDiffEntry {
 | 
        
           |  |  | 23 | 	SDiffEntryRemoval() { iType = DIFFTYPE_REMOVAL; }
 | 
        
           |  |  | 24 | } SDiffEntryRemoval;
 | 
        
           |  |  | 25 |   | 
        
           |  |  | 26 | tstruct SDiffEntryChange : SDiffEntry {
 | 
        
           |  |  | 27 | 	SDiffEntryChange() { iType = DIFFTYPE_CHANGE; }
 | 
        
           |  |  | 28 | 	int			iPos;
 | 
        
           |  |  | 29 | 	CyString	sFrom;
 | 
        
           |  |  | 30 | 	CyString	sEntry;
 | 
        
           |  |  | 31 | } SDiffEntryChange;
 | 
        
           |  |  | 32 |   | 
        
           |  |  | 33 | tstruct SDiffFile {
 | 
        
           |  |  | 34 | 	CyString sFile;
 | 
        
           |  |  | 35 | 	CLinkList<SDiffEntry> m_lEntries;
 | 
        
           |  |  | 36 | } SDiffFile;
 | 
        
           |  |  | 37 |   | 
        
           |  |  | 38 | enum {MDERR_NONE, MDERR_FILENOTFOUND, MDERR_CANTOPEN, MDERR_CANTOPENMOD};
 | 
        
           |  |  | 39 |   | 
        
           |  |  | 40 | tclass CModDiff
 | 
        
           |  |  | 41 | {
 | 
        
           |  |  | 42 | public:
 | 
        
           |  |  | 43 | 	// static
 | 
        
           |  |  | 44 | 	static bool CanBeDiffed(const CyString &file);
 | 
        
           |  |  | 45 |   | 
        
           |  |  | 46 | 	// constructors
 | 
        
           |  |  | 47 | 	CModDiff(CyString &dir, int maxPatch = 0);
 | 
        
           |  |  | 48 | 	~CModDiff(void);
 | 
        
           |  |  | 49 |   | 
        
           |  |  | 50 | 	// public functions
 | 
        
           |  |  | 51 | 	void SetTempDirectory(CyString &temp) { m_sTempDir = temp; }
 | 
        
           |  |  | 52 | 	bool LoadDirectory(CyString &dir);
 | 
        
           |  |  | 53 | 	bool IsLoaded() { return m_bLoaded; }
 | 
        
           |  |  | 54 | 	const CyString &GetDirectory() { return m_sCurrentDir; }
 | 
        
           |  |  | 55 | 	bool CreateDiff(CyString &mod);
 | 
        
           |  |  | 56 | 	bool DiffFile(CyString &baseFile, CyString &modFile, CyString &fileType);
 | 
        
           |  |  | 57 | 	void Clean();
 | 
        
           |  |  | 58 | 	bool WriteDiff(CyString &file);
 | 
        
           |  |  | 59 | 	bool ReadDiff(CyString &file);
 | 
        
           |  |  | 60 | 	bool ApplyDiff(CyString &mod);
 | 
        
           |  |  | 61 | 	bool ApplyMod(CyString &mod);
 | 
        
           |  |  | 62 | 	void SetMaxPatch(int patch) { m_iMaxPatch = patch; }
 | 
        
           |  |  | 63 |   | 
        
           |  |  | 64 | 	CLinkList<SDiffFile> &GetDiffFiles() { return m_lFiles; }
 | 
        
           |  |  | 65 |   | 
        
           |  |  | 66 | 	void ClearError() { m_iError = MDERR_NONE; }
 | 
        
           |  |  | 67 | 	int Error() { return m_iError; }
 | 
        
           |  |  | 68 |   | 
        
           |  |  | 69 | private:
 | 
        
           |  |  | 70 | 	// private functions
 | 
        
           |  |  | 71 | 	int GetAmountPosition(const CyString &fileType);
 | 
        
           |  |  | 72 | 	bool IsLineComplete(CyString &line, CyString &fileType, bool first);
 | 
        
           |  |  | 73 | 	bool ReadGameFile(CyString &file, CyStringList *lines, int *id);
 | 
        
           |  |  | 74 | 	void CompareLine(CyString &line1, CyString &line2, int type, int id, SDiffFile *diffFile);
 | 
        
           |  |  | 75 | 	bool ValidFile(CyString &file);
 | 
        
           |  |  | 76 |   | 
        
           |  |  | 77 | 	// Variables
 | 
        
           |  |  | 78 | 	CyString m_sCurrentDir;				// the current game directory (that the VFS is opened too)
 | 
        
           |  |  | 79 | 	CyString m_sTempDir;				// temporary dir (used to write temporary files to)
 | 
        
           |  |  | 80 |   | 
        
           |  |  | 81 | 	CVirtualFileSystem m_fileSystem;	// the VFS of the game directory (for finding the files to use)
 | 
        
           |  |  | 82 | 	CLinkList<SDiffFile> m_lFiles;		// list of files that have changed
 | 
        
           |  |  | 83 |   | 
        
           |  |  | 84 | 	bool	m_bLoaded;					// if the directory is loaded and ready to be diffed
 | 
        
           |  |  | 85 | 	int		m_iError;					// error id of process
 | 
        
           |  |  | 86 | 	int		m_iMaxPatch;				// The max fake patch to check to
 | 
        
           |  |  | 87 | };
 |