Subversion Repositories spk

Rev

Rev 35 | Rev 160 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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