-
Notifications
You must be signed in to change notification settings - Fork 1
/
MArc2.cpp
318 lines (262 loc) · 9.08 KB
/
MArc2.cpp
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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
// DiskArcher.
// MArc2.cpp : Defines the class behaviors for the application.
// (C) Marat Mirgaleev, 2001-2002.
// Modifications:
// (1) 05.03.2002. AddFiles() - Check is it directory.
// Enable drag'n'drop.
// (2) 01.05.2002. Changes in About box.
// CoInitialize() and CoUnitialize() moved here.
// (3) 10.05.2002. CAboutDlg moved into a separate file.
// CheckRegDataConformity() and CheckRegistration() added.
// Tip of the Day added.
// (4) 02.09.2002. Locator added.
// (5) 02.10.2002. try block.
// (6) 12.01.2003. "Excluded files" template.
// (7) 02.12.2003. Processing of a return code of CFilesToArc::Add().
// (8) 03.03.2004. GetPassedDays() added.
// (9) 24.05.2006. theArchive renamed into g_TheArchive.
// Copy protection changed.
//==============================================================================
#include "stdafx.h"
#include "MArc2.h"
#include "MArcCore/CMyArchive.h"
#include "MArcCore/CArchiveDB.h"
#include "MArcCore/CFileToArc.h"
#include "MainFrm.h"
#include "CFilesToArcFrame.h"
#include "CFilesToArcDoc.h"
#include "LeftView.h"
#include "CRoomsDoc.h" // M
#include "CRoomsFrame.h" // M
#include "CRoomsView.h" // M
#include "CCopiesDoc.h" // M
#include "CCopiesFrame.h" // M
#include "CCopiesView.h" // M
#include "CLogDoc.h" // M
#include "CLogFrame.h" // M
#include "CLogView.h" // M
#include "FileLocator/CNewFilesLocatorDoc.h"
#include "FileLocator/CNewFilesLocatorFrame.h"
#include "FileLocator/CNewFilesLocatorView.h"
#include "FileLocator/CLocatorExcludedFrame.h"
#include "FileLocator/CLocatorExcludedDoc.h"
#include "FileLocator/CLocatorExcludedView.h"
#include "CAboutDlg.h" // (3)
#include "UIfactory.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//= GLOBALS ====================================================================
wchar_t* strMyComp = L"My Computer";
// Tried to make it const, but didn't succeed. LATER: Move it to Resources?
CMArc2App theApp; // The one and only CMArc2App object
//==============================================================================
BEGIN_MESSAGE_MAP(CMArc2App, CWinApp)
// ON_COMMAND(CG_IDS_TIPOFTHEDAY, ShowTipOfTheDay) // (3)
//{{AFX_MSG_MAP(CMArc2App)
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
ON_UPDATE_COMMAND_UI(ID_HELP_TIPOFTHEDAY, OnUpdateHelpTipOfTheDay)
ON_COMMAND(ID_HELP_TIPOFTHEDAY, OnHelpTipOfTheDay)
//}}AFX_MSG_MAP
// Standard file based document commands
END_MESSAGE_MAP()
// CMArc2App initialization
//==============================================================================
BOOL CMArc2App::InitInstance()
{
if(FAILED(CoInitialize(NULL))) // (2)
return FALSE;
/*
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
*/
SetRegistryKey(_T("DiskArcher"));
//(3) LoadStdProfileSettings(0); // Load standard INI file options (including MRU)
// Register the application's document templates. Document templates
// serve as the connection between documents, frame windows and views.
//--------------------------------------------------------------------------
// FilesToArc window
m_pFilesToArcTemplate = new CMultiDocTemplate( IDR_FILESTOARC,
RUNTIME_CLASS( CFilesToArcDoc ), RUNTIME_CLASS( CFilesToArcFrame ),
RUNTIME_CLASS( CLeftView ));
AddDocTemplate( m_pFilesToArcTemplate );
// Archive Rooms window
m_pRoomsTemplate = new CMultiDocTemplate( IDR_ROOMS,
RUNTIME_CLASS( CRoomsDoc ), RUNTIME_CLASS( CRoomsFrame ),
RUNTIME_CLASS( CRoomsView ) );
AddDocTemplate( m_pRoomsTemplate );
// File Copies window
m_pCopiesTemplate = new CMultiDocTemplate( IDR_COPIES,
RUNTIME_CLASS( CCopiesDoc ), RUNTIME_CLASS( CCopiesFrame ),
RUNTIME_CLASS( CCopiesView ) );
AddDocTemplate( m_pCopiesTemplate );
// Log window
m_pLogTemplate = new CMultiDocTemplate( IDR_LOG,
RUNTIME_CLASS( CLogDoc ), RUNTIME_CLASS( CLogFrame ),
RUNTIME_CLASS( CLogView ) );
AddDocTemplate( m_pLogTemplate );
// (4) Locator window
m_pLocatorTemplate = new CMultiDocTemplate( IDR_LOCATOR,
RUNTIME_CLASS( CNewFilesLocatorDoc ), RUNTIME_CLASS( CNewFilesLocatorFrame ),
RUNTIME_CLASS( CNewFilesLocatorView ) );
AddDocTemplate( m_pLocatorTemplate );
// (6) "Excluded files" window
m_pLocatorExclTemplate = new CMultiDocTemplate( IDR_LOCATOR_EXCL,
RUNTIME_CLASS( CLocatorExcludedDoc ),
RUNTIME_CLASS( CLocatorExcludedFrame ),
RUNTIME_CLASS( CLocatorExcludedView ) );
AddDocTemplate( m_pLocatorExclTemplate );
// create main MDI Frame window
CMainFrame* pMainFrame = new CMainFrame;
if (!pMainFrame->LoadFrame( IDR_MAINFRAME ))
return FALSE;
m_pMainWnd = pMainFrame;
// Parse command line for standard shell commands, DDE, file open
CCommandLineInfo cmdInfo;
cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing; // M
ParseCommandLine(cmdInfo);
// Dispatch commands specified on the command line
if (!ProcessShellCommand(cmdInfo))
return FALSE;
// The main window has been initialized, so show and update it.
pMainFrame->ShowWindow(m_nCmdShow);
pMainFrame->UpdateWindow();
/*pMainFrame->m_pFilesToArcDoc =*/ m_pFilesToArcTemplate->OpenDocumentFile(NULL);
// M Enable drag/drop open
m_pMainWnd->DragAcceptFiles(); // (1)
// (3) CG: This line inserted by 'Tip of the Day' component.
ShowTipAtStartup();
m_UIfactory.init( &g_TheArchive );
return TRUE;
}
// App command to run the dialog
//==============================================================================
void CMArc2App::OnAppAbout()
{
CAboutDlg aboutDlg;
CString strName = GetProfileString( _T("Settings"), _T("User") );
if( strName.IsEmpty() )
aboutDlg.m_strLicensedTo = "Unregistered Copy";
else
aboutDlg.m_strLicensedTo = "Licensed to: " + strName; // (2)
aboutDlg.DoModal();
}
//==============================================================================
void CMArc2App::OnFileOpen()
{
if( AddFiles() )
UpdateTreeAndList();
}
//==============================================================================
bool CMArc2App::AddFiles()
{
bool success=true;
CFileDialog fileDialog( TRUE/*OpenDlg*/, NULL/*NoDefaultExtensionAdded*/,
_T("*.*")/*InitialFilename*/, OFN_ALLOWMULTISELECT );
// Replace default buffer for filenames with a larger one
wchar_t buffer[ 8192 ] = _T("*.*");
fileDialog.m_ofn.lpstrFile = buffer;
fileDialog.m_ofn.nMaxFile = 8191;
int result = fileDialog.DoModal();
if (result==IDOK)
{
// "Open" has been pressed - make a list of selected files
POSITION ps=fileDialog.GetStartPosition();
while (ps) // with each selected file
{
// Create an object for the current file or folder
CString curFilename = fileDialog.GetNextPathName(ps);
const MArcLib::error* result = g_TheArchive.addFile( curFilename );
if( result->getSeverity() > MArcLib::error::severity::everythingIsFine )
{
AfxMessageBox( result->getMessage() );
delete result;
break;
}
}
} // end of if (result==IDOK)
else
// User canceled selection
success = false;
return success;
}
//==============================================================================
void CMArc2App::FilesGetStatus()
{
int dummy;
g_TheArchive.m_FilesToArc.FilesGetStatus(dummy);
UpdateTreeAndList();
}
//==============================================================================
void CMArc2App::UpdateTreeAndList()
{
if( ((CMainFrame*)AfxGetMainWnd())->m_pFilesToArcFrame != NULL )
{
((CMainFrame*)AfxGetMainWnd())->m_pFilesToArcFrame->UpdateList();
((CMainFrame*)AfxGetMainWnd())->m_pFilesToArcFrame->UpdateTree();
}
}
// (2)
//==============================================================================
int CMArc2App::ExitInstance()
{
int retCode = 0; // (5)
try // (5)
{
::CoUninitialize();
retCode = CWinApp::ExitInstance();
}
catch(...)
{
Beep( 1000, 100 ); // (5)
retCode = -1;
}
return retCode; // (5) Was: CWinApp::ExitInstance();
}
// (3) CG: This function added by 'Tip of the Day' component.
//==============================================================================
void CMArc2App::ShowTipAtStartup(void)
{
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
if (cmdInfo.m_bShowSplash)
{
CTipDlg dlg;
if (dlg.m_bStartup)
dlg.DoModal();
}
}
/*
// (3) CG: This function added by 'Tip of the Day' component.
void CMArc2App::ShowTipOfTheDay(void)
{
}
*/
// (3)
//==============================================================================
void CMArc2App::OnUpdateHelpTipOfTheDay(CCmdUI* pCmdUI)
{
pCmdUI->Enable();
}
// (3)
//==============================================================================
void CMArc2App::OnHelpTipOfTheDay()
{
CTipDlg dlg;
dlg.DoModal();
}
//==============================================================================
LRESULT CMArc2App::ProcessWndProcException( CException* e, const MSG* pMsg )
{
UNREFERENCED_PARAMETER( pMsg );
g_TheArchive.m_bIsWorking = false; // Otherwise a question to stop will be shown by the OnClose handler
e->ReportError();
AfxGetMainWnd()->SendMessage(WM_CLOSE); // It's fatal, you know...
return 0;
}