Subversion Repositories spk

Rev

Rev 58 | Rev 161 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
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
 
58 cycrow 10
class CCatFile;
11
 
1 cycrow 12
enum {DIFFTYPE_ADDITION, DIFFTYPE_REMOVAL, DIFFTYPE_CHANGE};
13
 
14
tstruct SDiffEntry {
15
	int			iType;
16
	int			iID;
17
} SDiffEntry;
18
 
19
tstruct SDiffEntryAddition : SDiffEntry {
58 cycrow 20
	Utils::String	sEntry;
1 cycrow 21
	SDiffEntryAddition() { iType = DIFFTYPE_ADDITION; }
22
} SDiffEntryAddition;
23
 
24
tstruct SDiffEntryRemoval : SDiffEntry {
25
	SDiffEntryRemoval() { iType = DIFFTYPE_REMOVAL; }
26
} SDiffEntryRemoval;
27
 
28
tstruct SDiffEntryChange : SDiffEntry {
29
	SDiffEntryChange() { iType = DIFFTYPE_CHANGE; }
30
	int			iPos;
58 cycrow 31
	Utils::String	sFrom;
32
	Utils::String	sEntry;
1 cycrow 33
} SDiffEntryChange;
34
 
35
tstruct SDiffFile {
58 cycrow 36
	Utils::String sFile;
1 cycrow 37
	CLinkList<SDiffEntry> m_lEntries;
38
} SDiffFile;
39
 
40
enum {MDERR_NONE, MDERR_FILENOTFOUND, MDERR_CANTOPEN, MDERR_CANTOPENMOD};
41
 
42
tclass CModDiff
43
{
58 cycrow 44
private:
45
	enum {
46
		MERGETYPE_NONE,
47
		MERGETYPE_TSHIPS,
48
	};
49
 
1 cycrow 50
public:
51
	// static
58 cycrow 52
	static bool CanBeDiffed(const Utils::String &file);
1 cycrow 53
 
54
	// constructors
58 cycrow 55
	CModDiff(const Utils::String &dir, const Utils::String &sAddon, int maxPatch = 0);
1 cycrow 56
	~CModDiff(void);
57
 
58
	// public functions
58 cycrow 59
	void SetTempDirectory(const Utils::String &temp) { m_sTempDir = temp; }
60
	bool LoadDirectory(const Utils::String &dir);
1 cycrow 61
	bool IsLoaded() { return m_bLoaded; }
58 cycrow 62
	const Utils::String &GetDirectory() const { return m_sCurrentDir; }
63
	bool CreateDiff(const Utils::String &mod);
64
	bool startDiff(const Utils::String &sModFile);
65
	bool doDiff(const Utils::String &sModFile);
66
	SDiffFile *diffFile(const Utils::String &baseFile, const  Utils::String &modFile, const Utils::String &fileType);
1 cycrow 67
	void Clean();
58 cycrow 68
	bool WriteDiff(const Utils::String &file);
69
	bool ReadDiff(const Utils::String &file);
70
	bool ApplyDiff(const Utils::String &mod);
71
	bool ApplyMod(const Utils::String &mod);
1 cycrow 72
	void SetMaxPatch(int patch) { m_iMaxPatch = patch; }
73
 
74
	CLinkList<SDiffFile> &GetDiffFiles() { return m_lFiles; }
75
 
76
	void ClearError() { m_iError = MDERR_NONE; }
77
	int Error() { return m_iError; }
78
 
79
private:
80
	// private functions
58 cycrow 81
	int _amountPosition(const Utils::String &fileType);
82
	bool _isLineComplete(const Utils::String &line, const Utils::String &fileType, bool first);
160 cycrow 83
	bool _readGameFile(const Utils::String &file, Utils::CStringList &lines, int *id);
58 cycrow 84
	void _compareLine(const Utils::String &line1, const Utils::String &line2, int type, int id, SDiffFile *diffFile);
85
	bool _validFile(const Utils::String &file);
1 cycrow 86
 
58 cycrow 87
	void _adjustFile(const Utils::String &sFile, SDiffFile *pDiff, bool bReverse);
88
	bool _adjustTShips(SDiffFile *pDiff, bool bReserve);
89
	int _specialType(const Utils::String &sFile);
90
	Utils::String _extractFile(const Utils::String &sFile, const Utils::String &sTo);
91
 
1 cycrow 92
	// Variables
58 cycrow 93
	Utils::String m_sAddon;
94
	Utils::String m_sCurrentDir;		// the current game directory (that the VFS is opened too)
95
	Utils::String m_sTempDir;				// temporary dir (used to write temporary files to)
1 cycrow 96
 
97
	CVirtualFileSystem m_fileSystem;	// the VFS of the game directory (for finding the files to use)
98
	CLinkList<SDiffFile> m_lFiles;		// list of files that have changed
99
 
100
	bool	m_bLoaded;					// if the directory is loaded and ready to be diffed
101
	int		m_iError;					// error id of process
102
	int		m_iMaxPatch;				// The max fake patch to check to
58 cycrow 103
 
104
	CCatFile		*m_pCatFile;
1 cycrow 105
};