-
Notifications
You must be signed in to change notification settings - Fork 0
/
Fbk.cpp
96 lines (77 loc) · 1.54 KB
/
Fbk.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
#include "stdafx.h"
#include "3dfstbrk.h"
#include "fbk.h"
Fbk::Fbk()
{
m_DataOK=FALSE;
m_fpFbk=NULL;
m_fFileName="";
}
Fbk::Fbk(CString FbkFile)
{
Set(FbkFile);
}
BOOL Fbk::Set(CString FbkFile)
{
m_fFileName=FbkFile;
// 保证该文件的存在。
m_fpFbk=fopen(FbkFile,"rb+");
if(!m_fpFbk){
m_fpFbk=fopen(FbkFile,"w");
fclose(m_fpFbk);
m_fpFbk=fopen(FbkFile,"rb+");
}
// 计算该文件中包含的总道数。
fseek(m_fpFbk,0,SEEK_END);
long n=ftell(m_fpFbk);
m_TraceNumber=n/sizeof(DataInFstBrkFile);
m_DataOK=TRUE;
return TRUE;
}
void Fbk::close()
{
if(m_DataOK)
fclose(m_fpFbk);
}
Fbk::~Fbk()
{
if(m_DataOK)
fclose(m_fpFbk);
}
long Fbk::Get(DataInFstBrkFile *room,long pos,long n)
{
long l=0;
for(int i=0;i<n;i++){
room[i].FileNumber=0;
room[i].FirstBreak=0;
}
if(m_DataOK){
long p=pos*sizeof(DataInFstBrkFile);
fseek(m_fpFbk,p,SEEK_SET);
l=fread(room,sizeof(DataInFstBrkFile),n,m_fpFbk);
}
return l;
}
long Fbk::Put(DataInFstBrkFile *room,long pos,long n)
{
long l=0;
if(m_DataOK){
long p=pos*sizeof(DataInFstBrkFile);
fseek(m_fpFbk,p,SEEK_SET);
l=fwrite(room,sizeof(DataInFstBrkFile),n,m_fpFbk);
}
return l;
}
bool Fbk::Save(CString sFile, DataInFstBrkFile * pRoom, long nDataNumber)
{
FILE *fp=fopen(sFile,"w");
if(!fp){
AfxMessageBox("无法建立文件: "+sFile+" !");
return false;
}
for(int i=0;i<nDataNumber;i++){
fprintf(fp,"%i,%i,%ld\n",i,pRoom[i].FileNumber,pRoom[i].FirstBreak);
}
fclose(fp);
return true;
}