forked from gcsjsd/fileStorageEngine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSFArchive.cpp
More file actions
112 lines (89 loc) · 2.65 KB
/
Copy pathSFArchive.cpp
File metadata and controls
112 lines (89 loc) · 2.65 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
//
// Created by Ge Chang on 2018/3/1.
//
#include "SFArchive.h"
#include <vector>
SFArchive::SFArchive() {
//version and compile time
version_number = 0.0;
build_time = __DATE__;
//open create the arch.bin if it exists
this->archive.open("archive.bin",std::ios::out|std::ios::binary|std::ios::in);
std::cout << myfile.tellg() << std::endl;
std::cout << myfile.tellp() << std::endl;
bool exist = true; // the .bin file has existed
// if .bin doesnt exist, create the file
if (this->archive.tellg() == -1) {
std::cout << "Should Initialize archive.bin file with empty header" << std::endl;
this->archive.close();
std::ofstream archive1;
archive1.open("archive.bin", std::ios::out|std::ios::app);
this->initHeader(archive1); //initialize the header of the file
archive1.close();
exist = false;
}
// if just created, open this file again.
if (!exist) {
this->archive.open("archive.bin", std::ios::out|std::ios::binary|std::ios::in);
}
}
void SFArchive::initHeader(std::ofstream &file) {
block_i blocks[maxFileNumber]; // current we can write 20 files at most
for(int i=0;i<maxFileNumber;i++){
blocks[i].type = AVA;
for(int j=0; j<name_size; j++){
blocks[i].name[j] = 'x';
}
blocks[i].exist = false;
blocks[i].size = 0;
blocks[i].date = __DATE__;
}
this->archive.write((char*)&blocks, sizeof(blocks));
}
SFArchive::~SFArchive() {
this->archive.close();
}
SFArchive& SFArchive::add(std::string type, std::string name) {
/* 0.Init SFHeader header.
* 1.open the file, create block for this file.
* 2.addFileHeader, all archive header operation is done.
* 3.call SFile.writeArchive(archive, vector<int>chunks, file)
*/
SFHeader header;
header.readHeader(this->archive);
}
SFArchive& SFArchive::del(std::string type, std::string name) {
/* 0.Init SFHeader header
* 1.call header.delFileHeader().
* 2.Things are done
*/
}
SFArchive& SFArchive::extract(std::string type, std::string name) {
/* 0.Init SFHeader header
* 1.ofstream open file
* 2.call header.getFile()
* 3.call header.getFileSize()
* 4.call SFile.readArchive(archive, vector<int>chunks, file, size)
*/
}
void SFArchive::list(std::string content) {
/* 0.Init SFHeader header
* 1.call header.listFiles(content)
*/
}
void SFArchive::list(){
/* 0.Init SFHeader header
* 1.call header.listFiles()
*/
}
void SFArchive::search(std::string content) {
/*
*
*/
}
void SFArchive::version() {
}
void SFArchive::error() {
}
void SFArchive::info() {
}