-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathObjectEditorDoc.cpp
More file actions
executable file
·215 lines (172 loc) · 4.45 KB
/
Copy pathObjectEditorDoc.cpp
File metadata and controls
executable file
·215 lines (172 loc) · 4.45 KB
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
// ObjectEditorDoc.cpp : implementation of the CObjectEditorDoc class
//
#include "stdafx.h"
#include "ObjectEditor.h"
#include "ObjectEditorDoc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CObjectEditorDoc
IMPLEMENT_DYNCREATE(CObjectEditorDoc, CDocument)
BEGIN_MESSAGE_MAP(CObjectEditorDoc, CDocument)
//{{AFX_MSG_MAP(CObjectEditorDoc)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CObjectEditorDoc construction/destruction
CObjectEditorDoc::CObjectEditorDoc()
{
gpoobject = NULL;
}
CObjectEditorDoc::~CObjectEditorDoc()
{
}
BOOL CObjectEditorDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CObjectEditorDoc serialization
void CObjectEditorDoc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
}
else
{
}
}
/////////////////////////////////////////////////////////////////////////////
// CObjectEditorDoc diagnostics
#ifdef _DEBUG
void CObjectEditorDoc::AssertValid() const
{
CDocument::AssertValid();
}
void CObjectEditorDoc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CObjectEditorDoc commands
BOOL CObjectEditorDoc::OnOpenDocument(LPCTSTR lpszPathName)
{
if (!CDocument::OnOpenDocument(lpszPathName))
return FALSE;
// TODO: Add your specialized creation code here
// car = LoadCar(lpszPathName);
gpoobject = ImportGPOObject(lpszPathName);
gpoobject->parse(0);
//OnFileimport();
((CObjectEditorApp*)AfxGetApp())->m_MainTree->InsertGPOObject(this,gpoobject);
return TRUE;
}
static char * getObjectline(FILE *fp)
{
static char buffer[512];
fscanf(fp,"%[^\n]\n",buffer);
return buffer;
}
GPOObject * CObjectEditorDoc::ImportGPOObject(CString filename)
{
FILE *fp = fopen(filename,"r");
if (fp==NULL)
{
AfxMessageBox("Failed to open import file");
return FALSE;
}
GPOObject *obj = new GPOObject();
// get number of datavalues
int listsize=0;
while(!feof(fp))
{
char *line = getObjectline(fp);
if (line == NULL) continue;
if (line[0] == '#' && line[1] == '#')
{
obj->ParseAdditionalCommands(line);
}
if (line[0] == '#') continue;
if (line[0] == '/' && line[1] == '/') continue;
sscanf(line,"%d",&listsize);break;
}
int objectLength = 0;
int count=0;
for(int i=0;i<listsize;i++)
{
char *line = getObjectline(fp);
// don't gobble lines
if (line[0] == '#')
{
i--;
continue;
}
if (line[0] == '/' && line[1] == '/')
{
i--;
continue;
}
int offset;
int size;
int value;
sscanf(line,"%d %d 0x%x",&offset,&size,&value);
objectLength+=size;
switch(size)
{
case 2:
obj->data[count++] = LOBYTE(value);
obj->data[count++] = HIBYTE(value);
break;
case 4:
obj->data[count++] = LOBYTE(LOWORD(value));
obj->data[count++] = HIBYTE(LOWORD(value));
obj->data[count++] = LOBYTE(HIWORD(value));
obj->data[count++] = HIBYTE(HIWORD(value));
break;
}
}
while(!feof(fp))
{
char *line = getObjectline(fp);
if (line == NULL) continue;
if (line[0] == '#' && line[1] == '#')
{
obj->ParseAdditionalCommands(line);
}
if (line[0] == '#') continue;
if (line[0] == '/' && line[1] == '/') continue;
}
fclose(fp);
return obj;
}
BOOL CObjectEditorDoc::OnSaveDocument(LPCTSTR lpszPathName)
{
// TODO: Add your specialized code here and/or call the base class
//return CDocument::OnSaveDocument(lpszPathName);
FILE *fp = fopen(lpszPathName,"w");
if (fp == NULL)
{
AfxMessageBox("Failed to open file for output");
return FALSE;
}
if (gpoobject && fp)
{
gpoobject->write(fp);
fclose(fp);
}
return TRUE;
}
void CObjectEditorDoc::OnCloseDocument()
{
// TODO: Add your specialized code here and/or call the base class
if (gpoobject) {
((CObjectEditorApp*)AfxGetApp())->m_MainTree->m_CarTree.DeleteItem(gpoobject->carNode);
}
CDocument::OnCloseDocument();
}