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 {
|
197 |
cycrow |
18 |
Utils::WString 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 {
|
197 |
cycrow |
27 |
SDiffEntryChange() : iPos(0) { iType = DIFFTYPE_CHANGE; }
|
1 |
cycrow |
28 |
int iPos;
|
197 |
cycrow |
29 |
Utils::WString sFrom;
|
|
|
30 |
Utils::WString sEntry;
|
1 |
cycrow |
31 |
} SDiffEntryChange;
|
|
|
32 |
|
|
|
33 |
tstruct SDiffFile {
|
197 |
cycrow |
34 |
Utils::WString 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
|
197 |
cycrow |
50 |
static bool CanBeDiffed(const Utils::WString &file);
|
1 |
cycrow |
51 |
|
|
|
52 |
// constructors
|
197 |
cycrow |
53 |
CModDiff(const Utils::WString &dir, const Utils::WString &sAddon, int maxPatch = 0);
|
1 |
cycrow |
54 |
~CModDiff(void);
|
|
|
55 |
|
|
|
56 |
// public functions
|
197 |
cycrow |
57 |
void SetTempDirectory(const Utils::WString &temp) { m_sTempDir = temp; }
|
|
|
58 |
bool LoadDirectory(const Utils::WString &dir);
|
1 |
cycrow |
59 |
bool IsLoaded() { return m_bLoaded; }
|
197 |
cycrow |
60 |
const Utils::WString &GetDirectory() const { return m_sCurrentDir; }
|
|
|
61 |
bool CreateDiff(const Utils::WString &mod);
|
58 |
cycrow |
62 |
bool startDiff(const Utils::String &sModFile);
|
197 |
cycrow |
63 |
bool doDiff(const Utils::WString &sModFile);
|
|
|
64 |
SDiffFile *diffFile(const Utils::WString &baseFile, const Utils::WString &modFile, const Utils::WString &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
|
197 |
cycrow |
79 |
int _amountPosition(const Utils::WString &fileType);
|
|
|
80 |
bool _isLineComplete(const Utils::WString &line, const Utils::WString &fileType, bool first);
|
|
|
81 |
bool _readGameFile(const Utils::WString &file, Utils::WStringList &lines, int *id);
|
|
|
82 |
void _compareLine(const Utils::WString &line1, const Utils::WString &line2, int type, int id, SDiffFile *diffFile);
|
|
|
83 |
bool _validFile(const Utils::WString &file);
|
1 |
cycrow |
84 |
|
197 |
cycrow |
85 |
void _adjustFile(const Utils::WString &sFile, SDiffFile *pDiff, bool bReverse);
|
58 |
cycrow |
86 |
bool _adjustTShips(SDiffFile *pDiff, bool bReserve);
|
196 |
cycrow |
87 |
int _specialType(const Utils::WString &sFile) const;
|
197 |
cycrow |
88 |
Utils::WString _extractFile(const Utils::WString &sFile, const Utils::WString &sTo);
|
58 |
cycrow |
89 |
|
1 |
cycrow |
90 |
// Variables
|
197 |
cycrow |
91 |
Utils::WString m_sAddon;
|
|
|
92 |
Utils::WString m_sCurrentDir; // the current game directory (that the VFS is opened too)
|
|
|
93 |
Utils::WString 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 |
};
|