当前位置: 首页>>代码示例>>C++>>正文


C++ FileIO::close方法代码示例

本文整理汇总了C++中FileIO::close方法的典型用法代码示例。如果您正苦于以下问题:C++ FileIO::close方法的具体用法?C++ FileIO::close怎么用?C++ FileIO::close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FileIO的用法示例。


在下文中一共展示了FileIO::close方法的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);
}
开发者ID:changbiao,项目名称:XDBF-Manager,代码行数:76,代码来源:xdbf.cpp


注:本文中的FileIO::close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。