本文整理汇总了C++中FileReader::Close方法的典型用法代码示例。如果您正苦于以下问题:C++ FileReader::Close方法的具体用法?C++ FileReader::Close怎么用?C++ FileReader::Close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileReader
的用法示例。
在下文中一共展示了FileReader::Close方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ReadCheckFile
void SPAuthCheckPrv::ReadCheckFile()
{
// Read check prevention file
mGameSecondsBeforeNextCheck = 1; // default -> check
try
{
FileReader aReader;
if(!aReader.Open(gSPAuthCheck_FileName))
return;
unsigned short aNumBytes = aReader.ReadShort();
if(aNumBytes==0 || aReader.Available()<aNumBytes)
return;
char *aBuf = new char[aNumBytes];
std::auto_ptr<char> aDelBuf(aBuf);
aReader.ReadBytes(aBuf,aNumBytes);
aReader.Close();
ByteBufferPtr aDecrypt = mEncryptKey.Decrypt(aBuf,aNumBytes);
if(aDecrypt.get()==NULL)
return;
WONFile aFile(gSPAuthCheck_FileName);
ReadBuffer aReadBuf(aDecrypt->data(),aDecrypt->length());
std::string aSig;
aReadBuf.ReadString(aSig);
if(aSig!="magic")
return;
time_t aCreateTime = aFile.GetCreateTime();
time_t aCompareCreateTime = aReadBuf.ReadLong();
if(aCompareCreateTime != aCreateTime)
return;
mGameSecondsBeforeNextCheck = aReadBuf.ReadLong();
if(mGameSecondsBeforeNextCheck==0) // don't remove file in this case
return;
aFile.Remove();
}
catch(FileReaderException&)
{
}
catch(ReadBufferException&)
{
}
}
示例2: BenchmarkDArray
void BenchmarkDArray(Sorter<char *> &sorter)
{
DArray<char *> data, rdata;
Stopwatch sw;
char buffer[512], format[64];
sprintf(format, "%s", "%4.3lfs");
FileReader file;
file.SetLineEndings(CC_LN_LF);
file.Open("dataset");
if (file.IsOpen()) {
data.setStepDouble();
rdata.setStepDouble();
console->Write("Loading... ");
sw.Start();
/* Load the file into the data DArray */
while (file.ReadLine(buffer, sizeof(buffer)) >= 0)
data.insert(cc_strdup(buffer));
sw.Stop();
console->WriteLine(format, sw.Elapsed());
file.Close();
console->WriteLine("Loaded %d items.", data.used());
console->Write("Random: ");
sw.Start();
data.sort(sorter);
sw.Stop();
console->WriteLine(format, sw.Elapsed());
/* Create a reverse-sorted DArray */
for (long i = (long)data.size(); i >= 0; i--) {
if (data.valid(i)) {
rdata.insert(data.get(i));
}
}
console->Write("Pre-sorted: ");
sw.Start();
data.sort(sorter);
sw.Stop();
console->WriteLine(format, sw.Elapsed());
console->Write("Reverse-sorted: ");
sw.Start();
rdata.sort(sorter);
sw.Stop();
console->WriteLine(format, sw.Elapsed());
for (size_t i = 0; i < data.size(); i++) {
if (data.valid(i)) {
free(data.get(i));
data.remove(i);
}
}
data.empty();
rdata.empty();
} else {
console->WriteLine("Dataset not found.");
}
}
示例3: Save
void PackageFile::Save(std::string savePath)
{
OutputFileName = savePath;
FileReader rdr;
int headerSize = HEADER_SIZE; // Header Size
int directorySize = 0; // Directory size
int bufPos = 0; // Data section size
auto it = filesList->GetContainer()->begin();
while (it != filesList->GetContainer()->end())
{
FileListEntry* fileListing = *it;
std::string fileName;
if (fileListing->RelativeDirectoryParentRoot == "")
{
fileName = fileListing->File->FileName;
}
else
{
fileName = StringSubtract(fileListing->File->FilePath, fileListing->RelativeDirectoryParentRoot);
}
rdr.OpenFile(fileListing->File->FilePath.c_str());
if (contents != NULL)
delete(contents);
contents = rdr.GetFileContents();
DirectoryEntry* newFileEntry = new DirectoryEntry();
strcpy(newFileEntry->fileName, const_cast<char*>(fileName.c_str()));
newFileEntry->fileLength = contents->fileSize;
newFileEntry->filePosition = bufPos;
newFileEntry->fileContents = new char[contents->fileSize];
memcpy(newFileEntry->fileContents, contents->buffer, contents->fileSize);
bufPos += contents->fileSize;
directorySize += sizeof(newFileEntry->fileName) + sizeof(newFileEntry->fileLength) + sizeof(newFileEntry->filePosition);
entries->Add(newFileEntry);
rdr.Close();
it++;
}
int fileSize = headerSize + bufPos + directorySize;
Header *packHeader = new Header();
strncpy(packHeader->sig, "PACK", 4);
packHeader->dirOffset = headerSize;
packHeader->dirLength = directorySize;
WriteBytes(packHeader->sig, 4, memStream);
WriteBytes((char*)&packHeader->dirOffset, 4, memStream);
WriteBytes((char*)&packHeader->dirLength, 4, memStream);
packageHeader = packHeader;
auto it2 = entries->GetContainer()->begin();
int currentDirectoryOffset = 0;
int currentDataSize = 0;
while (it2 != entries->GetContainer()->end())
{
DirectoryEntry* entry = *it2;
WriteBytes(entry->fileName, sizeof(entry->fileName), memStream);
int currPos = headerSize + directorySize + currentDataSize;
char* filePosCopy = new char[4];
memcpy(filePosCopy, (char*)&entry->filePosition, 4);
WriteBytes(filePosCopy, sizeof(filePosCopy), memStream);
char* fileLengthCopy = new char[4];
memcpy(fileLengthCopy, (char*)&entry->fileLength, 4);
WriteBytes(fileLengthCopy, sizeof(fileLengthCopy), memStream);
currentDataSize += entry->fileLength;
it2++;
}
auto it3 = entries->GetContainer()->begin();
while (it3 != entries->GetContainer()->end())
{
DirectoryEntry* entry = *it3;
WriteBytes(entry->fileContents, entry->fileLength, memStream);
it3++;
//.........这里部分代码省略.........