本文整理汇总了C++中FileIO::write方法的典型用法代码示例。如果您正苦于以下问题:C++ FileIO::write方法的具体用法?C++ FileIO::write怎么用?C++ FileIO::write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileIO
的用法示例。
在下文中一共展示了FileIO::write方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: cleanGPD
void XDBF::cleanGPD()
{
// create a new fileIo for writing the new gpd
FileIO *newFile = new FileIO(filePath.append(".4253efd018451c05326e15f1e1bcf402"));
// set the free mem table count to 0, because we're overwriting all the unused memory
h->freeMemoryTableEntryCount = 0;
// write the header to the file
newFile->write(h->magic);
newFile->write(h->version);
newFile->write(h->entryTableLength);
newFile->write(h->entryCount);
newFile->write(h->freeMemoryTableLength);
newFile->write(h->freeMemoryTableEntryCount);
// length of the entry table and free mem table in bytes
int paddingLen = get_offset(0) - 0x18;
// null out that part of the file
char *nullData = new char[paddingLen];
memset(nullData, 0, paddingLen);
newFile->write(nullData, paddingLen);
delete[] nullData;
// write all of the entries
for (int i = 0; i < privateEntries->size(); i++)
{
// allocate some memory to hold the entry in
char *temp = new char[privateEntries->at(i).length];
// read the entry
openedFile->setPosition(privateEntries->at(i).address);
openedFile->read(temp, privateEntries->at(i).length);
// update the entry's address
privateEntries->at(i).address = newFile->getPosition();
// write the new entry
newFile->write(temp, privateEntries->at(i).length);
// deallocate the memory
delete[] temp;
}
// write all the entry table with the updated addresses
writeEntryTable(newFile);
// get the length of the file
newFile->setPosition(0, ios_base::end);
unsigned int addr = getFakeOffset(newFile->getPosition());
// write file info free mem setting entry
newFile->setPosition((h->entryTableLength * 0x12) + 0x18);
newFile->write(addr);
newFile->write(0xFFFFFFFF - addr);
// the file to read/write from now will be the one we just created
openedFile->close();
delete openedFile;
newFile->close();
delete newFile;
string s = filePath.substr(0, filePath.length() - 33);
// delete the old file
if (remove(s.c_str()) != 0)
throw "Error deleting file.";
// rename the new file to the original file's name
if (rename(filePath.c_str(), s.c_str()) != 0)
throw "Error renaming file.";
filePath = s;
openedFile = new FileIO(filePath);
}