Subversion Repositories spk

Rev

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