-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathsync.h
118 lines (94 loc) · 2.52 KB
/
sync.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
* sync.h - Proof of concept for a Delphi Obfuscator
*
* Copyright (c) 2005 Sebastian Porst ([email protected])
* All rights reserved.
*
* This software is licensed under the zlib/libpng License.
* For more details see http://www.opensource.org/licenses/zlib-license.php
*/
#ifndef SYNC_H
#define SYNC_H
#include "DFMParser.h"
#include "VMTDir.h"
#include "helpers.h"
#include <string>
void synchronize(DFMData& dfmres, const VMTDir& vmtdir);
void synchronizeProperties(DFMResource* dfm, const std::string& classname, DFMProperty& property, const VMTDir& vmtdir, const DFMData& dfmres);
/**
* Used to synchronize the names of objects in the DFM tree with the
* names of fields in the VMT tree.
**/
class SynchronizeName
{
private:
const VMTDir& vmtdir_;
public:
SynchronizeName(const VMTDir& vmtdir) : vmtdir_(vmtdir) {}
void operator()(DFMResource* dfm)
{
if (dfm && dfm->parent)
{
DFMResource* parent = dfm;
VMT* vmt = 0;
std::string* str = 0;
if (dfm)
parent = parent->parent;
do
{
vmt = find<FindByName>(vmtdir_, *parent->classname);
parent = parent->parent;
if (vmt)
{
str = getVMTAttribute(vmt->fields, *dfm->name);
if (str)
break;
}
}
while (parent);
if (!str)
return;
delete dfm->name;
dfm->name = str;
}
}
};
/**
* Used to synchronize the class names of objects in the DFM tree with the
* names of classes in the VMT tree.
**/
class SynchronizeClassName
{
private:
const VMTDir& vmtdir_;
public:
SynchronizeClassName(const VMTDir& vmtdir) : vmtdir_(vmtdir) {}
void operator()(DFMResource* dfm)
{
VMT* vmt = find<FindByName>(vmtdir_, *dfm->classname);
if (!vmt) return;
delete dfm->classname;
dfm->classname = vmt->name;
}
};
/**
* Used to synchronize the names and values in the DFM tree with elements
* of the VMT tree.
**/
class SynchronizeProperties
{
private:
const VMTDir& vmtdir_;
const DFMData& dfmres_;
public:
SynchronizeProperties(const VMTDir& vmtdir, const DFMData& dfmres)
: vmtdir_(vmtdir), dfmres_(dfmres) {}
void operator()(DFMResource* dfm)
{
for (unsigned int i=0;i<dfm->properties.size();++i)
{
synchronizeProperties(dfm, *dfm->classname, dfm->properties[i], vmtdir_, dfmres_);
}
}
};
#endif