Added save files and info file about all files

This commit is contained in:
Mixac1 2016-03-30 11:50:28 +03:00
parent 584be84d23
commit b9a9897451
2 changed files with 69 additions and 47 deletions

BIN
disk

Binary file not shown.

116
disk.cpp
View File

@ -3,6 +3,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <iomanip> #include <iomanip>
#include <sstream>
#define LOGBLOCK_LENGTH 512 #define LOGBLOCK_LENGTH 512
#define ALLOCBLOCK_LENGTH LOGBLOCK_LENGTH * 2 #define ALLOCBLOCK_LENGTH LOGBLOCK_LENGTH * 2
@ -177,26 +178,29 @@ public:
} }
} }
string printAll() { string printAll() {
return string("--------------------") + stringstream temp;
"\nflags " + to_string(flFIags) + temp << hex;
"\nversion number " + to_string(flTyp) + temp << "--------------------" << endl;
"\ninformation used by the Finder " + to_string(flUsrWds) + temp << "flags " << flFIags << endl;
"\nfile number " + to_string(flFINum) + temp << "version number " << flTyp << endl;
"\nfirst allocation block of data fork " + to_string(flStBlk) + temp << "information used by the Finder " << flUsrWds << endl;
"\nlogical end-of-file of data fork " + to_string(flLgLen) + temp << "file number " << flFINum << endl;
"\nphysical end-of-file of data fork " + to_string(flPyLen) + temp << "first allocation block of data fork " << flStBlk << endl;
"\nfirst allocation block of resource fork " + to_string(flRStBlk) + temp << "logical end-of-file of data fork " << flLgLen << endl;
"\nlogical end-of-file of resource fork " + to_string(flRLgLen) + temp << "physical end-of-file of data fork " << flPyLen << endl;
"\nphysical end-of-file of resource fork " + to_string(flRPyLen) + temp << "first allocation block of resource fork " << flRStBlk << endl;
"\ndate and time of creation " + to_string(flCrDat) + temp << "logical end-of-file of resource fork " << flRLgLen << endl;
"\ndate and time of last modification " + to_string(flMdDat) + temp << "physical end-of-file of resource fork " << flRPyLen << endl;
"\nlength of file name " + to_string(flNam) + temp << "date and time of creation " << flCrDat << endl;
"\n--------------------\n"; temp << "date and time of last modification " << flMdDat << endl;
temp << "length of file name " << flNam << endl;
temp << "--------------------" << endl;
return temp.str();
} }
string printFileName() { string printFileName() {
return string("File name: ") + flNamS + "\n"; return string("File name: ") + flNamS;
} }
string getValidFileName() { string getValidFileName() {
@ -209,18 +213,57 @@ public:
return temp; return temp;
} }
string saveFile() { void saveData(fstream& out, int point) {
string temp = "save file: \n"; int firstOffset = Disk::getFContOffset();
char str[ALLOCBLOCK_LENGTH + 1];
Disk::getDiskStream().seekg(Disk::getFContOffset() + (flRStBlk - 2) * ALLOCBLOCK_LENGTH); while ((point != 1) && (point != 0)) {
for (int i = 0; i < flRLgLen; ++i) { Disk::getDiskStream().seekg(firstOffset + (point - 2) * ALLOCBLOCK_LENGTH);
temp += (char)Disk::getDiskStream().get(); Disk::getDiskStream().get(str, ALLOCBLOCK_LENGTH + 1);
out.write(str, ALLOCBLOCK_LENGTH + 1);
point = Disk::getDisk().allocBlockMap[point - 2];
}
}
void saveFile(string path) {
if (flRStBlk != 0) {
fstream file(path + getValidFileName() + ".resourсe", ios_base::binary | ios_base::out);
if (!file.is_open()) {
cout << "error: file not created: " << flNamS << endl;
}
saveData(file, flRStBlk);
file.close();
}
if (flStBlk != 0) {
fstream file(path + getValidFileName() + ".data", ios_base::binary | ios_base::out);
if (!file.is_open()) {
cout << "error: file not created: " << flNamS << endl;
}
saveData(file, flStBlk);
file.close();
} }
return temp;
} }
}; };
void generInfoFile(string path, vector< File > files) {
fstream file(path + "Files.info", ios_base::binary | ios_base::out);
if (!file.is_open()) {
cout << "error: info-file not created: " << endl;
}
file << hex;
for (int i = 0; i < files.size(); ++i) {
file << files[i].printFileName() << endl;
file << files[i].printAll() << endl;
file << "firstOffset resource fork: " << (!files[i].flRStBlk ? 0 : Disk::getFContOffset() + (files[i].flRStBlk - 2) * ALLOCBLOCK_LENGTH) << endl;
file << "firstOffset data fork: " << (!files[i].flStBlk ? 0 : Disk::getFContOffset() + (files[i].flStBlk - 2) * ALLOCBLOCK_LENGTH) << endl;
file << endl << endl;
}
file.close();
}
int main() { int main() {
Disk::getDiskStream().seekg(VINF_OFFSET + 12); Disk::getDiskStream().seekg(VINF_OFFSET + 12);
@ -239,32 +282,11 @@ int main() {
system("rm -r Files"); system("rm -r Files");
system("mkdir Files"); system("mkdir Files");
vector< fstream > fileStreams(fileCount);
for (int i = 0; i < fileCount; ++i) { for (int i = 0; i < fileCount; ++i) {
fileStreams[i].open(string("Files/") + to_string(i) + ":" + files[i].getValidFileName() + ".txt", std::fstream::out); files[i].saveFile("Files/");
if (!fileStreams[i].is_open()) {
cout << "error: file not created: " << files[i].flNamS + ".txt" << endl;
}
fileStreams[i] << files[i].printAll() << endl;
fileStreams[i] << files[i].saveFile() << endl;
fileStreams[i].close();
} }
generInfoFile("Files/", files);
int q1 = Disk::getFContOffset();
int q2 = q1 + (files.back().flRStBlk - 2) * ALLOCBLOCK_LENGTH;
int q3 = q2 + files.back().flRPyLen;
cout << dec;
cout << "our first file " << q1/ 16 << endl;
cout << "our end file " << q2 / 16 << endl;
cout << "our end file end " << q3 / 16 << endl;
cout << "MB end file " << (q3 + LOGBLOCK_LENGTH * 3) / 16 << endl;
Disk::getDiskStream().seekg(0, ios::end);
cout << "Disk size " << Disk::getDiskStream().tellg() / 16 << endl;
return 1; return 1;
} }