-
Notifications
You must be signed in to change notification settings - Fork 2
/
HuiReversiDoc.cpp
executable file
·166 lines (138 loc) · 3.46 KB
/
HuiReversiDoc.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
// HuiReversiDoc.cpp : implementation of the CHuiReversiDoc class
//
#include "stdafx.h"
#include "HuiReversi.h"
#include "HuiReversiDoc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CHuiReversiDoc
IMPLEMENT_DYNCREATE(CHuiReversiDoc, CDocument)
BEGIN_MESSAGE_MAP(CHuiReversiDoc, CDocument)
//{{AFX_MSG_MAP(CHuiReversiDoc)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CHuiReversiDoc construction/destruction
CHuiReversiDoc::CHuiReversiDoc()
{
}
CHuiReversiDoc::~CHuiReversiDoc()
{
}
BOOL CHuiReversiDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CHuiReversiDoc serialization
void CHuiReversiDoc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
// TODO: add storing code here
}
else
{
// TODO: add loading code here
}
}
/////////////////////////////////////////////////////////////////////////////
// CHuiReversiDoc diagnostics
#ifdef _DEBUG
void CHuiReversiDoc::AssertValid() const
{
CDocument::AssertValid();
}
void CHuiReversiDoc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CHuiReversiDoc commands
BOOL CHuiReversiDoc::OnOpenDocument(LPCTSTR lpszPathName)
{
CFileException fe;
CFile* pFile = GetFile(lpszPathName, CFile::modeRead|CFile::shareDenyWrite, &fe);
if (pFile == NULL)
{
ReportSaveLoadException(lpszPathName, &fe,
FALSE, AFX_IDP_FAILED_TO_OPEN_DOC);
return FALSE;
}
DeleteContents();
CArchive loadArchive(pFile, CArchive::load | CArchive::bNoFlushOnDelete,4096*8);
loadArchive.m_pDocument = this;
loadArchive.m_bForceFlat = FALSE;
TRY
{
CWaitCursor wait;
if (pFile->GetLength() != 0)
{
theReversiWnd.m_wndBoard->Serialize(loadArchive);
}
loadArchive.Close();
ReleaseFile(pFile, FALSE);
}
CATCH_ALL(e)
{
ReleaseFile(pFile, TRUE);
DeleteContents(); // remove failed contents
TRY
{
ReportSaveLoadException(lpszPathName, e,
FALSE, AFX_IDP_FAILED_TO_OPEN_DOC);
}
END_TRY
//DELETE_EXCEPTION(e);
return FALSE;
}
END_CATCH_ALL
return TRUE;
}
BOOL CHuiReversiDoc::OnSaveDocument(LPCTSTR lpszPathName)
{
CFileException fe;
CFile* pFile = NULL;
pFile = GetFile(lpszPathName, CFile::modeCreate |
CFile::modeReadWrite | CFile::shareExclusive, &fe);
if (pFile == NULL)
{
ReportSaveLoadException(lpszPathName, &fe,
TRUE, AFX_IDP_INVALID_FILENAME);
return FALSE;
}
CArchive saveArchive(pFile, CArchive::store | CArchive::bNoFlushOnDelete,4096*8);
saveArchive.m_pDocument = this;
saveArchive.m_bForceFlat = FALSE;
//Åжϣº
TRY
{
CWaitCursor wait;
theReversiWnd.m_wndBoard->Serialize(saveArchive);
saveArchive.Close();
ReleaseFile(pFile, FALSE);
}
CATCH_ALL(e)
{
ReleaseFile(pFile, TRUE);
TRY
{
ReportSaveLoadException(lpszPathName, e,
TRUE, AFX_IDP_FAILED_TO_SAVE_DOC);
}
END_TRY
//DELETE_EXCEPTION(e);
return FALSE;
}
END_CATCH_ALL
return TRUE;
}