Subversion Repositories spk

Rev

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