-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathByakhee.cpp
More file actions
280 lines (234 loc) · 8.72 KB
/
Byakhee.cpp
File metadata and controls
280 lines (234 loc) · 8.72 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
279
280
// Byakhee.cpp : Defines the class behaviors for the application.
/**
* Copyright (C) 1998 David Harvey
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "stdafx.h"
#include "Byakhee.h"
#include <shlobj.h> //for SHGetSpecialFolderLocation and SHGetPathFromIDList
#include "MainFrm.h"
#include "ChildFrm.h"
#include "MultiFileMultiDocTemplate.h"
#include "InvestigatorDoc.h"
#include "InvestigatorView.h"
#include "ScriptEditDoc.h"
#include "ScriptEditView.h"
#include "HandoutDoc.h"
#include "HandoutView.h"
#include "Splash.h"
#include "SkillManager.h"
#include "AboutDlg.h"
#include "OptionsDlg.h"
#include "Wizard_NewInvestigator.h"
#include "NewDocumentDlg.h"
#include "QuickInfoDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CByakheeApp
BEGIN_MESSAGE_MAP(CByakheeApp, CWinApp)
//{{AFX_MSG_MAP(CByakheeApp)
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
ON_COMMAND(ID_TOOLS_OPTIONS, OnToolsOptions)
ON_COMMAND(ID_FILE_NEW, OnFileNew)
//}}AFX_MSG_MAP
// Standard file based document commands
ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
// Standard print setup command
ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CByakheeApp construction
CByakheeApp::CByakheeApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CByakheeApp object
CByakheeApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CByakheeApp initialization
BOOL CByakheeApp::InitInstance()
{
//display the splash screen
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
CSplashWnd::EnableSplashScreen(cmdInfo.m_bShowSplash);
//initialise the random number generator
srand( GetTickCount() );
//set the program's registry key
SetRegistryKey(_T("DHSoft"));
//load the standard profile
LoadStdProfileSettings(8);
//register document templates
//add main byakhee file types
AddDocTemplate( new CMultiFileMultiDocTemplate( IDR_SHEETTYPE, RUNTIME_CLASS(CInvestigatorDoc), RUNTIME_CLASS(CChildFrame), RUNTIME_CLASS(CInvestigatorView) ) );
AddDocTemplate( new CMultiFileMultiDocTemplate( IDR_HANDOUTTYPE, RUNTIME_CLASS(CHandoutDoc), RUNTIME_CLASS(CChildFrame), RUNTIME_CLASS(CHandoutView) ) );
RegisterShellFileTypes(TRUE);
//add non-print non-shellnew etc file types (scripts etc)
AddDocTemplate( new CMultiFileMultiDocTemplate( IDR_SCRIPTEDITTYPE_SHEET, RUNTIME_CLASS(CScriptEditDoc), RUNTIME_CLASS(CChildFrame), RUNTIME_CLASS(CScriptEditView), IDR_SCRIPTEDITTYPE ) );
AddDocTemplate( new CMultiFileMultiDocTemplate( IDR_SCRIPTEDITTYPE_HANDOUT, RUNTIME_CLASS(CScriptEditDoc), RUNTIME_CLASS(CChildFrame), RUNTIME_CLASS(CScriptEditView), IDR_SCRIPTEDITTYPE ) );
AddDocTemplate( new CMultiFileMultiDocTemplate( IDR_SCRIPTEDITTYPE, RUNTIME_CLASS(CScriptEditDoc), RUNTIME_CLASS(CChildFrame), RUNTIME_CLASS(CScriptEditView) ) );
RegisterShellFileTypes(FALSE);
//create the MDI window
CMainFrame* pMainFrame = new CMainFrame;
if( !pMainFrame->LoadFrame(IDR_MAINFRAME) ) return FALSE;
m_pMainWnd = pMainFrame;
//show tip of the day if required
if( cmdInfo.m_bShowSplash ) pMainFrame->m_wndMDIClientArea.ShowTip();
//enable drag & drop file opening
m_pMainWnd->DragAcceptFiles();
//enable DDE file opening
EnableShellOpen();
//dispatch commands specified on the command line
BOOL fCreateNew = FALSE;
if( cmdInfo.m_nShellCommand == CCommandLineInfo::FileNew )
{
cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing;
fCreateNew = TRUE;
}
if( !ProcessShellCommand(cmdInfo) ) return FALSE;
//the main window has been initialised, so show and update it.
pMainFrame->ShowWindow(SW_MAXIMIZE);
pMainFrame->UpdateWindow();
//create a new document now
if( fCreateNew ) OnFileNew();
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CByakheeApp commands
BOOL CByakheeApp::PreTranslateMessage(MSG* pMsg)
{
if (CSplashWnd::PreTranslateAppMessage(pMsg))
return TRUE;
return CWinApp::PreTranslateMessage(pMsg);
}
void CByakheeApp::OnFileNew()
{
//display the new document dialog
CNewDocumentDlg NewDocumentDlg;
NewDocumentDlg.DoModal();
}
void CByakheeApp::OnToolsOptions()
{
COptionsDlg OptionsDlg;
if( OptionsDlg.DoModal() == IDOK )
{
CMainFrame* pMainFrame = (CMainFrame*)AfxGetMainWnd();
if( pMainFrame )
{
//apply all settings
pMainFrame->GetOutputWindow().LoadDisplaySettings();
//walk all documents and send them an update message
POSITION p;
p = GetFirstDocTemplatePosition();
CMultiDocTemplate* pTemplate = NULL;
while( p )
{
pTemplate = (CMultiDocTemplate*)GetNextDocTemplate( p );
if( pTemplate )
{
POSITION pp = pTemplate->GetFirstDocPosition();
while( pp )
{
CDocument* pDoc = (CDocument*)pTemplate->GetNextDoc( pp );
if( pDoc )
{
POSITION ppp = pDoc->GetFirstViewPosition();
while( ppp )
{
CView* pView = pDoc->GetNextView(ppp);
if( pView ) pView->SendMessage( MY_APPSETTINGSCHANGE );
}
}
}
}
}
}
}
}
BOOL CByakheeApp::BrowseForPicture(CString & strFilename, CWnd* pWndOwner /*NULL*/)
{
if( pWndOwner == NULL ) pWndOwner = AfxGetMainWnd();
//build a file open dialog
char* szFilter = "Image Files|*.bmp;*.gif;*.jpg;*.jpeg;*.png|Bitmap Files (*.BMP)|*.bmp|CompuServe GIF Files (*.GIF)|*.gif|JPEG Files (*.JPG)|*.jpg;*.jpeg|Portable Network Graphics Files (*.PNG)|*.png|All Files (*.*)|*.*||";
CFileDialog FileDialog( TRUE, ".bmp", strFilename, OFN_FILEMUSTEXIST|OFN_HIDEREADONLY|OFN_NOCHANGEDIR|OFN_PATHMUSTEXIST, szFilter, pWndOwner );
//set default folder to current directory
char szDocumentsFolder[MAX_PATH+1];
GetCurrentDirectory( MAX_PATH, szDocumentsFolder );
//get the path to their documents folder
LPITEMIDLIST lpItemIDList;
if( SHGetSpecialFolderLocation( pWndOwner->GetSafeHwnd(), CSIDL_PERSONAL, &lpItemIDList ) == NOERROR ) SHGetPathFromIDList( lpItemIDList, szDocumentsFolder );
//make the file dialog start in their documents folder
FileDialog.m_ofn.lpstrInitialDir = szDocumentsFolder;
//show the file dialog
if( FileDialog.DoModal() == IDOK )
{
strFilename = FileDialog.GetPathName();
return TRUE;
}
else
return FALSE;
}
CString CByakheeApp::GetDefaultDirectory()
{
//get application's name
char szBuffer[MAX_PATH+1];
GetModuleFileName( AfxGetInstanceHandle(), szBuffer, MAX_PATH );
//find the last path separator
char* pszEndOfPath = strrchr( szBuffer,'\\' );
if( pszEndOfPath )
{
//terminate the string just after it
pszEndOfPath++;
*pszEndOfPath = '\0';
return CString( szBuffer );
}
else
//there was no path!
return "";
}
BOOL CByakheeApp::FileExists(CString strFile)
{
//build full path
CString strFileName = GetDefaultDirectory() + strFile;
//try and open it
WIN32_FIND_DATA wfd;
HANDLE hFind = FindFirstFile( strFileName, &wfd );
if( hFind != INVALID_HANDLE_VALUE )
{
//close the search
FindClose( hFind );
return TRUE;
}
else
return FALSE;
}
void CByakheeApp::ShowScriptExecutionQuickInfo()
{
CQuickInfoDlg QuickInfo;
QuickInfo.Show( "RunScript", "Byakhee is about to run an external script file.\nYou can press Ctrl+Break to stop the script at any point." );
}
void CByakheeApp::OnAppAbout()
{
CAboutDlg AboutDlg;
AboutDlg.DoModal();
}