// ZAVBfile.cpp.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <opencv2/core/cvdef.h>
#include <highgui.h>
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char* argv[])
ZAVBFile::ZAVBFile () {
this->RecordCount = 0;
}
//! Ֆայլի փակում
void ZAVBFile::close(){
if(hFile.is_open()) hFile.close();
}
//Ֆայլի վիճակի ստուգում
bool ZAVBFile::is_open(){
return hFile.is_open();
}
// Ֆայլերի քանակի ստացում
DWORD ZAVBFile::getRecordCount (){
return this->RecordCount;
}
// Ֆայլի բացում
bool ZAVBFileWriter::open(PCSTR FileName){
if (FileName == NULL) return false;
//Եթե ֆայլը չի գտնվել, ապա ստեղծում ենք նրա պրոտոտիպը
if(!isFileExist(FileName)){
hFile.open(FileName, ios::out | ios::binary);
if(!hFile.is_open()) return false;
hFile.write("AVB", 3);
hFile.write((PCSTR)&this->RecordCount, sizeof(DWORD)); //Գրառումների քանակը
}
//Հակառակ դեպքում բացում ր ստուգում ենք վավերությունը
else
{
hFile.open(FileName, ios::in | ios::out | ios::binary);
if (!hFile.is_open()) return false;
// Ստորագրության ստուգում
CHAR Sign[3];
hFile.read((PSTR)Sign, 3);
if(memcmp(Sign, "AVB", 3)){
hFile.close(); // Սա օտար ֆայլ է
return false;
}
//Կարդում ենք գրառումների քանակը
hFile.read((PSTR)&this->RecordCount, sizeof(DWORD));
}
return true;
}
62bool ZAVBFileWriter::addRecord(PSAVRecord Record){
if (Record == NULL || !hFile.is_open()) return false;
//Տեղափոխվենք ֆայլի վերջը
hFile.seekp(0, ios::end);
//Ավելացնենք գրառում
hFile.write ((PSTR)&Record->Signature.Offset, sizeof(DWORD)); // -
//Ստորագրության փոխանցումը
hFile.write((PSTR)&Record->Signature.Lenght, sizeof(DWORD)); // -
Ստորագրության քանակը
hFile.write((PSTR)&Record->Signature.Hash, 4 * sizeof(DWORD)); // -
Ստուգող գումարը
hFile.write((PSTR)&Record->NameLen, sizeof(BYTE)); // Անվան չափսը
hFile.write((PSTR)Record->Name, Record->NameLen); // Անունը
//Անցում ենք կատարում գրառումների քանակին
hFile.seekp(3, ios::beg);
//Ավելացնում ենք գրառումների հաշվիչը
this->RecordCount++;
hFile.write((PSTR)&this->RecordCount, sizeof(DWORD));
return true;
}
bool ZAVBFileReader::open(PCSTR FileName){
if(FileName == NULL) return false;
// Եթե ֆայլը գտնված չէ, ապա ստեղծեք դրա նախատիպը
if(isFileExist(FileName)){
hFile.open(FileName, ios::in | ios::out | ios::binary);
if(!hFile.is_open()) return false;
// - Կարդացեք մուտքերի քանակը
CHAR Sign[3];
hFile.read((PSTR)Sign, 3);
if(memcmp(Sign, "AVB", 3)){
hFile.close(); // Սա օտար ֆայլ է
return false;
}
//Ստորագրության ստուգում
hFile.read((PSTR)&this->RecordCount, sizeof(DWORD));
}else{ return false; }
return true;
}
bool ZAVBFileReader::readNextRecord(PSAVRecord Record){
if(Record == NULL || !hFile.is_open()) return false;
hFile.read((PSTR)&Record->Signature.Offset,
sizeof(DWORD));
hFile.read((PSTR)&Record->Signature.Lenght, sizeof(DWORD));
hFile.read((PSTR)&Record->Signature.Hash, 4 * sizeof(DWORD)); /
hFile.read((PSTR)&Record->NameLen, sizeof(BYTE));
Record->allocName(Record->NameLen);
hFile.read((PSTR)Record->Name, Record->NameLen);
return true;
}
int _tmain(int argc, _TCHAR* argv[])
{
return 0;
}