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


C++ SFileOpenFileEx函数代码示例

本文整理汇总了C++中SFileOpenFileEx函数的典型用法代码示例。如果您正苦于以下问题:C++ SFileOpenFileEx函数的具体用法?C++ SFileOpenFileEx怎么用?C++ SFileOpenFileEx使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了SFileOpenFileEx函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: getFileType

int getFileType(const char *szFileName)
{
  if ( !szFileName )
    return 0;

  int rVal = 0;
  HANDLE hMPQ;
  HANDLE hFile;
  // Open archive for map checking
  if ( SFileOpenArchive(szFileName, 0, 0, &hMPQ) && hMPQ )
  {
    // Open scenario.chk file
    if ( SFileOpenFileEx(hMPQ, "staredit\\scenario.chk", SFILE_FROM_MPQ, &hFile) && hFile )
    {
      rVal = 1;
      SFileCloseFile(hFile);
    }
    // Close archive
    SFileCloseArchive(hMPQ);
  }
  else if ( SFileOpenFileEx(NULL, szFileName, SFILE_FROM_ABSOLUTE, &hFile) && hFile )
  {
    DWORD dwRead = 0;
    char tbuff[16];
    DWORD dwSize = SFileGetFileSize(hFile, 0);
    // Read file data to check if it's a replay
    if ( dwSize > 16 && SFileReadFile(hFile, &tbuff, 16, &dwRead, 0) && dwRead == 16 && *(DWORD*)&tbuff[12] == 'SRer' )
      rVal = 2;
    // Close file
    SFileCloseFile(hFile);
  }
  return rVal;
}
开发者ID:RadicalZephyr,项目名称:bwapi,代码行数:33,代码来源:DLLMain.cpp

示例2: SFileAddInternalListFile

static int SFileAddInternalListFile(
    TMPQArchive * ha,
    HANDLE hMpq)
{
    TMPQArchive * haMpq = (TMPQArchive *)hMpq;
    TMPQHash * pFirstHash;
    TMPQHash * pHash;
    HANDLE hListFile;
    LCID lcSaveLocale = lcFileLocale;
    int nError = ERROR_SUCCESS;

    // If there is hash table, we need to support multiple listfiles
    // with different locales (BrooDat.mpq)
    if(haMpq->pHashTable != NULL)
    {
        pFirstHash = pHash = GetFirstHashEntry(haMpq, LISTFILE_NAME);
        while(nError == ERROR_SUCCESS && pHash != NULL)
        {
            // Set the prefered locale to that from list file
            SFileSetLocale(pHash->lcLocale);
            if(SFileOpenFileEx(hMpq, LISTFILE_NAME, 0, &hListFile))
            {
                // Add the data from the listfile to MPQ
                nError = SFileAddArbitraryListFile(ha, hListFile);
                SFileCloseFile(hListFile);
            }
            
            // Restore the original locale
            SFileSetLocale(lcSaveLocale);

            // Move to the next hash
            pHash = GetNextHashEntry(haMpq, pFirstHash, pHash);
        }
    }
    else
    {
        // Open the external list file
        if(SFileOpenFileEx(hMpq, LISTFILE_NAME, 0, &hListFile))
        {
            // Add the data from the listfile to MPQ
            // The function also closes the listfile handle
            nError = SFileAddArbitraryListFile(ha, hListFile);
            SFileCloseFile(hListFile);
        }
    }

    // Return the result of the operation
    return nError;
}
开发者ID:DoGoodS,项目名称:StormLib,代码行数:49,代码来源:SFileListFile.cpp

示例3: ExtractFile

bool ExtractFile( char const* mpq_name, std::string const& filename )
{
    for(ArchiveSet::const_reverse_iterator i=gOpenArchives.rbegin(); i!=gOpenArchives.rend();++i)
    {
        HANDLE fileHandle;
        if (!SFileOpenFileEx(*i, mpq_name, SFILE_OPEN_PATCHED_FILE, &fileHandle))
            continue;

        if (SFileGetFileSize(fileHandle, NULL) == 0)              // some files removed in next updates and its reported  size 0
        {
            SFileCloseFile(fileHandle);
            return true;
        }

        SFileCloseFile(fileHandle);

        if (!SFileExtractFile(*i, mpq_name, filename.c_str(), SFILE_OPEN_PATCHED_FILE))
        {
            printf("Can't extract file: %s\n", mpq_name);
            return false;
        }

        return true;
    }

    printf("Extracting file not found: %s\n", filename.c_str());
    return false;
}
开发者ID:AnthoDevMoP,项目名称:mangos4,代码行数:28,代码来源:loadlib.cpp

示例4: MPQ_stat

static int MPQ_stat(void *opaque, const char *filename, PHYSFS_Stat *stat)
{
    char *filename2 = NULL;
    HANDLE hFile;
    char success;
    DWORD fileSize = 0;

    if (!opaque)
        return 0;

    filename2 = MPQ_getValidFilename(filename);
    if (!filename2)
        return 0;

    success = SFileOpenFileEx(((MPQHandle *)opaque)->mpqHandle, filename2, 0, &hFile);
    allocator.Free(filename2);

    if (!success)
        return 0;

    SFileGetFileInfo(hFile, SFileInfoFileSize, &fileSize, sizeof(fileSize), NULL);
    stat->filesize = fileSize;

    stat->modtime = 0;
    SFileGetFileInfo(hFile, SFileInfoFileTime, &stat->modtime, sizeof(stat->modtime), NULL);
    stat->createtime = stat->modtime;
    stat->accesstime = 0;
    stat->filetype = PHYSFS_FILETYPE_REGULAR;
    stat->readonly = 1; /* .MPQ files are always read only */

    SFileCloseFile(hFile);

    return 1;
}
开发者ID:dgengin,项目名称:physfs,代码行数:34,代码来源:physfs_archiver_mpq.c

示例5: eof

MPQFile::MPQFile(const char* filename):
    eof(false),
    buffer(0),
    pointer(0),
    size(0)
{
    for(ArchiveSet::const_iterator i=gOpenArchives.archives.begin(); i!=gOpenArchives.archives.end();++i)
    {
        HANDLE hFile = "";
        hMPQ = i->hMPQ;
        BOOL succ = SFileOpenFileEx(hMPQ,filename,0, &hFile);
        if (succ)
        {
            DWORD s = SFileGetFileSize(hFile, 0);
            if (!s)
            {
                eof = true;
                buffer = 0;
                return;
            }
            size = (size_t)s;
            buffer = new char[s];
            SFileReadFile(hFile, buffer, s, 0, 0);
            SFileCloseFile(hFile);

            eof = false;
            return;
        }
    }

    eof = true;
    buffer = 0;
}
开发者ID:web0316,项目名称:WOW,代码行数:33,代码来源:mpq.cpp

示例6: ReadMapDBC

uint32 ReadMapDBC(int const locale)
{
    HANDLE localeFile;
    char localMPQ[512];
    sprintf(localMPQ, "%s/Data/%s/locale-%s.MPQ", input_path, langs[locale], langs[locale]);
    if (!SFileOpenArchive(localMPQ, 0, MPQ_OPEN_READ_ONLY, &localeFile))
        exit(1);

    printf("Read Map.dbc file... ");

    HANDLE dbcFile;
    if (!SFileOpenFileEx(localeFile, "DBFilesClient\\Map.dbc", SFILE_OPEN_PATCHED_FILE, &dbcFile))
    {
        printf("Fatal error: Cannot find Map.dbc in archive!\n");
        exit(1);
    }

    DBCFile dbc(dbcFile);
    if(!dbc.open())
    {
        printf("Fatal error: Invalid Map.dbc file format!\n");
        exit(1);
    }

    size_t map_count = dbc.getRecordCount();
    map_ids = new map_id[map_count];
    for(uint32 x = 0; x < map_count; ++x)
    {
        map_ids[x].id = dbc.getRecord(x).getUInt(0);
        strcpy(map_ids[x].name, dbc.getRecord(x).getString(1));
    }
    printf("Done! (%u maps loaded)\n", map_count);
    return map_count;
}
开发者ID:Erotix8210,项目名称:StrawberryCore,代码行数:34,代码来源:System.cpp

示例7: ReadMapDBC

uint32 ReadMapDBC()
{
    printf("Read Map.dbc file... ");

    HANDLE dbcFile;
    if (!SFileOpenFileEx(LocaleMpq, "DBFilesClient\\Map.dbc", SFILE_OPEN_PATCHED_FILE, &dbcFile))
    {
        printf("Fatal error: Cannot find Map.dbc in archive!\n");
        exit(1);
    }

    DBCFile dbc(dbcFile);
    if (!dbc.open())
    {
        printf("Fatal error: Invalid Map.dbc file format!\n");
        exit(1);
    }

    size_t map_count = dbc.getRecordCount();
    map_ids = new map_id[map_count];
    for(uint32 x = 0; x < map_count; ++x)
    {
        map_ids[x].id = dbc.getRecord(x).getUInt(0);
        strcpy(map_ids[x].name, dbc.getRecord(x).getString(1));
    }

    SFileCloseFile(dbcFile);
    printf("Done! (%u maps loaded)\n", map_count);
    return map_count;
}
开发者ID:FirstCore,项目名称:PandaCore,代码行数:30,代码来源:System.cpp

示例8: free

bool FileLoader::loadFile(HANDLE mpq, char* filename, bool log)
{
    free();
    HANDLE file;
    if (!SFileOpenFileEx(mpq, filename, SFILE_OPEN_PATCHED_FILE, &file))
    {
        if (log)
            printf("No such file %s\n", filename);
        return false;
    }

    data_size = SFileGetFileSize(file, NULL);
    data = new uint8[data_size];
    if (data)
    {
        SFileReadFile(file, data, data_size, NULL/*bytesRead*/, NULL);
        if (prepareLoadedData())
        {
            SFileCloseFile(file);
            return true;
        }
    }

    printf("Error loading %s\n", filename);
    SFileCloseFile(file);
    free();
    return false;
}
开发者ID:AwkwardDev,项目名称:5.4.1,代码行数:28,代码来源:loadlib.cpp

示例9: ReadLiquidTypeTableDBC

void ReadLiquidTypeTableDBC(int const locale)
{
    HANDLE localeFile;
    char localMPQ[512];
    sprintf(localMPQ, "%s/Data/%s/locale-%s.MPQ", input_path, langs[locale], langs[locale]);
    if (!SFileOpenArchive(localMPQ, 0, MPQ_OPEN_READ_ONLY, &localeFile))
        exit(1);

    printf("Read LiquidType.dbc file...");

    HANDLE dbcFile;
    if (!SFileOpenFileEx(localeFile, "DBFilesClient\\LiquidType.dbc", SFILE_OPEN_PATCHED_FILE, &dbcFile))
    {
        printf("Fatal error: Cannot find LiquidType.dbc in archive!\n");
        exit(1);
    }

    DBCFile dbc(dbcFile);
    if(!dbc.open())
    {
        printf("Fatal error: Invalid LiquidType.dbc file format!\n");
        exit(1);
    }

    size_t LiqType_count = dbc.getRecordCount();
    size_t LiqType_maxid = dbc.getMaxId();
    LiqType = new uint16[LiqType_maxid + 1];
    memset(LiqType, 0xff, (LiqType_maxid + 1) * sizeof(uint16));

    for(uint32 x = 0; x < LiqType_count; ++x)
        LiqType[dbc.getRecord(x).getUInt(0)] = dbc.getRecord(x).getUInt(3);

    printf("Done! (%u LiqTypes loaded)\n", LiqType_count);
}
开发者ID:Erotix8210,项目名称:StrawberryCore,代码行数:34,代码来源:System.cpp

示例10: IsMatchingPatchFile

static int IsMatchingPatchFile(
    TMPQArchive * ha,
    const char * szFileName,
    unsigned char * pbFileMd5)
{
    MPQ_PATCH_HEADER PatchHeader = {0};
    void * hFile = NULL;
    size_t dwTransferred = 0;
    int bResult = 0;

    /* Open the file and load the patch header */
    if(SFileOpenFileEx((void *)ha, szFileName, SFILE_OPEN_BASE_FILE, &hFile))
    {
        /* Load the patch header */
        SFileReadFile(hFile, &PatchHeader, sizeof(MPQ_PATCH_HEADER), &dwTransferred);
        BSWAP_ARRAY32_UNSIGNED(pPatchHeader, sizeof(uint32_t) * 6);

        /* If the file contains an incremental patch, */
        /* compare the "MD5 before patching" with the base file MD5 */
        if(dwTransferred == sizeof(MPQ_PATCH_HEADER) && PatchHeader.dwSignature == PATCH_SIGNATURE_HEADER)
            bResult = (!memcmp(PatchHeader.md5_before_patch, pbFileMd5, MD5_DIGEST_SIZE));

        /* Close the file */
        SFileCloseFile(hFile);
    }

    return bResult;
}
开发者ID:DarkAyron,项目名称:libThunderStorm,代码行数:28,代码来源:SFilePatchArchives.c

示例11: IsMatchingPatchFile

static bool IsMatchingPatchFile(
    TMPQArchive * ha,
    const char * szFileName,
    LPBYTE pbFileMd5)
{
    MPQ_PATCH_HEADER PatchHeader = {0};
    HANDLE hFile = NULL;
    DWORD dwTransferred = 0;
    bool bResult = false;

    // Open the file and load the patch header
    if(SFileOpenFileEx((HANDLE)ha, szFileName, SFILE_OPEN_BASE_FILE, &hFile))
    {
        // Load the patch header
        SFileReadFile(hFile, &PatchHeader, sizeof(MPQ_PATCH_HEADER), &dwTransferred, NULL);
        BSWAP_ARRAY32_UNSIGNED(pPatchHeader, sizeof(DWORD) * 6);

        // If the file contains an incremental patch,
        // compare the "MD5 before patching" with the base file MD5
        if(dwTransferred == sizeof(MPQ_PATCH_HEADER) && PatchHeader.dwSignature == PATCH_SIGNATURE_HEADER)
            bResult = (!memcmp(PatchHeader.md5_before_patch, pbFileMd5, MD5_DIGEST_SIZE));

        // Close the file
        SFileCloseFile(hFile);
    }

    return bResult;
}
开发者ID:Gargash,项目名称:StormLib,代码行数:28,代码来源:SFilePatchArchives.cpp

示例12: FileToBuffer

bool FileToBuffer(MPQHANDLE &hMpq, const std::string &fileName, buffer &buf)
{
    if ( hMpq == nullptr )
        CHKD_ERR("NULL MPQ file specified for opening %s", fileName.c_str());
    else
    {
        u32 bytesRead = 0;
        HANDLE openFile = NULL;
        if ( SFileGetFileInfo(hMpq, SFILE_INFO_NUM_FILES) != 0xFFFFFFFF )
        {
            if ( SFileOpenFileEx(hMpq, fileName.c_str(), SFILE_SEARCH_CURRENT_ONLY, &openFile) )
            {
                u32 fileSize = (u32)SFileGetFileSize(openFile, NULL);
                if ( buf.setSize(fileSize) )
                {
                    buf.sizeUsed = fileSize;
                    SFileReadFile(openFile, (LPVOID)buf.data, buf.sizeUsed, (LPDWORD)(&bytesRead), NULL);
                    SFileCloseFile(openFile);

                    if ( buf.sizeUsed == bytesRead )
                        return true;
                }
                else
                    SFileCloseFile(openFile);
            }
            else
                CHKD_ERR("Failed to get %s from MPQ file", fileName.c_str());
        }
        else
            CHKD_ERR("File is already open", fileName.c_str());
    }
    return false;
}
开发者ID:jjf28,项目名称:Chkdraft,代码行数:33,代码来源:FileIO.cpp

示例13: ReadLiquidTypeTableDBC

void ReadLiquidTypeTableDBC()
{
    printf("Read LiquidType.dbc file...");
    HANDLE dbcFile;
    if (!SFileOpenFileEx(LocaleMpq, "DBFilesClient\\LiquidType.dbc", SFILE_OPEN_PATCHED_FILE, &dbcFile))
    {
        printf("Fatal error: Cannot find LiquidType.dbc in archive!\n");
        exit(1);
    }

    DBCFile dbc(dbcFile);
    if(!dbc.open())
    {
        printf("Fatal error: Invalid LiquidType.dbc file format!\n");
        exit(1);
    }

    size_t liqTypeCount = dbc.getRecordCount();
    size_t liqTypeMaxId = dbc.getMaxId();
    LiqType = new uint16[liqTypeMaxId + 1];
    memset(LiqType, 0xff, (liqTypeMaxId + 1) * sizeof(uint16));

    for(uint32 x = 0; x < liqTypeCount; ++x)
        LiqType[dbc.getRecord(x).getUInt(0)] = dbc.getRecord(x).getUInt(3);

    SFileCloseFile(dbcFile);
    printf("Done! (%u LiqTypes loaded)\n", liqTypeCount);
}
开发者ID:FirstCore,项目名称:PandaCore,代码行数:28,代码来源:System.cpp

示例14: _SFileOpenFileEx

BOOL __stdcall _SFileOpenFileEx(HANDLE hMpq, const char *szFileName, DWORD dwSearchScope, HANDLE *phFile)
{
  /* Store the name of the last-opened file to retrieve the pointer once it's allocated */
  lastFile = szFileName;

  if ( !phFile )
    return FALSE;

  if ( !SFileOpenFileEx(NULL, szFileName, SFILE_FROM_ABSOLUTE | SFILE_FROM_RELATIVE, phFile) || !(*phFile) )
  {
    if ( _SFileOpenFileExOld )
      return _SFileOpenFileExOld(hMpq, szFileName, dwSearchScope, phFile);
    return SFileOpenFileEx(hMpq, szFileName, dwSearchScope, phFile);
  }
  return TRUE;
}
开发者ID:oenayet,项目名称:bwapi,代码行数:16,代码来源:Detours.cpp

示例15: ReadAreaTableDBC

void ReadAreaTableDBC()
{
    printf("Read AreaTable.dbc file...");
    HANDLE dbcFile;
    if (!SFileOpenFileEx(LocaleMpq, "DBFilesClient\\AreaTable.dbc", SFILE_OPEN_PATCHED_FILE, &dbcFile))
    {
        printf("Fatal error: Cannot find AreaTable.dbc in archive!\n");
        exit(1);
    }

    DBCFile dbc(dbcFile);
    if(!dbc.open())
    {
        printf("Fatal error: Invalid AreaTable.dbc file format!\n");
        exit(1);
    }

    size_t area_count = dbc.getRecordCount();
    maxAreaId = dbc.getMaxId();
    areas = new uint16[maxAreaId + 1];

    for (uint32 x = 0; x < area_count; ++x)
        areas[dbc.getRecord(x).getUInt(0)] = dbc.getRecord(x).getUInt(3);

    SFileCloseFile(dbcFile);
    printf("Done! (%u areas loaded)\n", area_count);
}
开发者ID:FirstCore,项目名称:PandaCore,代码行数:27,代码来源:System.cpp


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