Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

[b967c1]: CFBDialog.cpp Maximize Restore History

Download this file

CFBDialog.cpp    279 lines (245 with data), 6.4 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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
// CFBDialog.cpp : implementation file
//
#include "stdafx.h"
#include <fcntl.h>
#include <direct.h>
#include <sys/stat.h>
#include <shlobj.h>
#include "chitem.h"
#include "CFBDialog.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCFBDialog dialog
CCFBDialog::CCFBDialog(CWnd* pParent /*=NULL*/)
: CDialog(CCFBDialog::IDD, pParent)
{
//{{AFX_DATA_INIT(CCFBDialog)
m_etitle = _T("");
m_event = _T("");
//}}AFX_DATA_INIT
m_output=bgfolder+"cfb";
}
BOOL CCFBDialog::OnInitDialog()
{
CString tmpstr;
CDialog::OnInitDialog();
tmpstr.Format("%s all %s in the override folder",(mode&1)?"Add CFB to":"Remove CFB from",(mode&2)?"items":"spells");
SetWindowText(tmpstr);
m_outputbutton.SetBitmap(theApp.m_bbmp);
{
m_tooltip.Create(this,TTS_NOPREFIX);
m_tooltip.SetMaxTipWidth(200);
m_tooltip.SetTipBkColor(RGB(240,224,160));
tmpstr.LoadString(IDS_CFBHELP); //too long string
m_tooltip.AddTool(GetDlgItem(IDC_FILENAME), tmpstr);
m_tooltip.AddTool(GetDlgItem(IDC_OUTFOLDER), IDS_CFBFOLDER);
m_tooltip.AddTool(GetDlgItem(IDC_OUTPUT), IDS_CFBFOLDER);
m_tooltip.AddTool(GetDlgItem(IDC_OPENFILE), IDS_CFBOPEN);
m_tooltip.AddTool(GetDlgItem(IDC_EVENT), IDS_EVENT);
}
return TRUE;
}
void CCFBDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCFBDialog)
DDX_Control(pDX, IDC_OUTPUT, m_outputbutton);
DDX_Control(pDX, IDC_EVENT, m_event_control);
DDX_Text(pDX, IDC_EVENT_TYPE, m_etitle);
DDX_Text(pDX, IDC_EVENT, m_event);
DDX_Text(pDX, IDC_OUTFOLDER, m_output);
DDV_MaxChars(pDX, m_output, 200);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCFBDialog, CDialog)
//{{AFX_MSG_MAP(CCFBDialog)
ON_BN_CLICKED(IDC_OPENFILE, OnOpenfile)
ON_WM_CONTEXTMENU()
ON_WM_HELPINFO()
ON_EN_KILLFOCUS(IDC_OUTFOLDER, OnKillfocusOutfolder)
ON_BN_CLICKED(IDC_OUTPUT, OnOutput)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCFBDialog message handlers
void CCFBDialog::log(CString format, ...)
{
int x;
va_list arglist;
CString str;
if(newitem)
{
newitem=FALSE;
log(itemname);
}
m_etitle="Event log:";
m_event_control.SetReadOnly(true);
if(format)
{
va_start(arglist, format);
str.FormatV(format,arglist);
va_end(arglist);
if(m_event.IsEmpty())
{
m_event=str;
x=0;
}
else
{
x=m_event_control.LineIndex(MAX_LINE);
if(x>-1)
{
m_event=m_event.Right(m_event.GetLength()-x);
}
m_event+=CString("\r\n")+str;
}
UpdateData(UD_DISPLAY);
m_event_control.LineScroll(MAX_LINE);
}
}
void CCFBDialog::OnOpenfile()
{
POSITION pos;
CString tmpstr;
CString key;
loc_entry fileloc;
int featcount, featnum;
feat_block *cfb;
int flg, ret;
int fhandle;
int ext;
newitem=FALSE;
mkdir(m_output);
log("%s",m_output+" created");
if(mode&2) ext=determinetype(REF_ITM);
else ext=determinetype(REF_SPL);
if(mode&1)
{
flg=OFN_FILEMUSTEXIST|OFN_HIDEREADONLY|OFN_ENABLESIZING|OFN_EXPLORER;
CFileDialog m_getfiledlg(TRUE, "bin", bgfolder+"cfb.bin", flg, cfbFilter);
restart:
if( m_getfiledlg.DoModal() == IDOK )
{
tmpstr=m_getfiledlg.GetPathName();
fhandle=open(tmpstr,O_RDONLY|O_BINARY);
featcount=filelength(fhandle);
if(featcount%sizeof(feat_block) || !featcount)
{
close(fhandle);
MessageBox("This is not a valid cfb file. (It must contain feature blocks)","Warning",MB_ICONEXCLAMATION|MB_OK);
goto restart;
}
cfb = new feat_block[featnum=featcount/sizeof(feat_block)];
if(!cfb)
{
close(fhandle);
MessageBox("Not enough memory.","Error",MB_ICONSTOP|MB_OK);
return;
}
}
else return;
read(fhandle,cfb,featcount);
close(fhandle);
}
pos=resources[ext]->GetStartPosition();
while(pos)
{
resources[ext]->GetNextAssoc(pos,key,fileloc);
if(fileloc.bifindex!=0xffff)
{
continue;
}
changeitemname(key);
fhandle=locate_file(fileloc, 0);
if(fhandle<1)
{
log("Cannot open file.");
continue;
}
if(mode&2) ret=the_item.ReadItemFromFile(fhandle, fileloc.size);
else ret=the_spell.ReadSpellFromFile(fhandle, fileloc.size);
close(fhandle);
if(ret)
{
log("Invalid file.");
continue;
}
if(ModifyCFB(mode, featnum, cfb))
{
log("No CFB... skipping file");
continue;
}
if(mode&2) tmpstr=".itm";
else tmpstr=".spl";
fhandle=open(m_output+"/"+key+tmpstr,O_RDWR|O_BINARY|O_TRUNC|O_CREAT,S_IREAD|S_IWRITE);
if(mode&2) the_item.WriteItemToFile(fhandle,0);
else the_spell.WriteSpellToFile(fhandle,0);
close(fhandle);
log("done");
}
//cfb usually gets initialized once if mode==true and
//execution doesn't reach this point if it was not
//(the warning of uninitialized local is unwarranted)
if(mode&1) delete [] cfb;
}
void CCFBDialog::OnContextMenu(CWnd* pWnd, CPoint point)
{
CRect tmp;
GetClientRect(tmp);
ClientToScreen(tmp);
if(tmp.PtInRect(point) )
{
PostMessage(WM_SYSCOMMAND,SC_CONTEXTHELP,0);
}
else CDialog::OnContextMenu(pWnd, point);
}
BOOL CCFBDialog::OnHelpInfo(HELPINFO* pHelpInfo)
{
CString helpstring;
if(pHelpInfo->iContextType!=HELPINFO_WINDOW) return false;
switch(pHelpInfo->iCtrlId)
{
case IDC_OUTPUT: case IDC_OUTFOLDER:
helpstring.LoadString(IDS_CFBFOLDER);
break;
case IDC_FILENAME:
helpstring.LoadString(IDS_CFBHELP);
break;
case IDC_OPENFILE:
helpstring.LoadString(IDS_CFBOPEN);
break;
case IDC_EVENT:
helpstring.LoadString(IDS_EVENT);
break;
default:
helpstring="?";
break;
}
MessageBox(helpstring,"Help",MB_ICONINFORMATION|MB_OK);
return true;
}
BOOL CCFBDialog::PreTranslateMessage(MSG* pMsg)
{
m_tooltip.RelayEvent(pMsg);
return CDialog::PreTranslateMessage(pMsg);
}
void CCFBDialog::OnKillfocusOutfolder()
{
UpdateData(UD_RETRIEVE);
UpdateData(UD_DISPLAY);
}
void CCFBDialog::OnOutput()
{
folderbrowse_t fb;
fb.initial=m_output;
fb.title="Select output folder for CFB";
if(BrowseForFolder(&fb, m_hWnd)==IDOK)
{
m_output=fb.initial;
UpdateData(UD_DISPLAY);
}
}