示例#1
0
static void * FetchAndVerifyConfigFile(TCascStorage * hs, PQUERY_KEY pFileKey)
{
    TCHAR * szFileName;
    void * pvListFile = NULL;

    // Construct the local file name
    szFileName = CascNewStr(hs->szDataPath, 8 + 3 + 3 + 32);
    if(szFileName != NULL)
    {
        // Add the part where the config file path is
        AppendConfigFilePath(szFileName, pFileKey);

        // Load and verify the external listfile
        pvListFile = ListFile_OpenExternal(szFileName);
        if(pvListFile != NULL)
        {
            if(!ListFile_VerifyMD5(pvListFile, pFileKey->pbData))
            {
                ListFile_Free(pvListFile);
                pvListFile = NULL;
            }
        }

        // Free the file name
        CASC_FREE(szFileName);
    }

    return pvListFile;
}
示例#2
0
 void teardown()
 {
     MallocFailureInject_Restore();
     ListFile_Free(m_pListFile);
     LONGS_EQUAL(noException, getExceptionCode());
     printfSpy_Unhook();
 }
示例#3
0
static TListFileCache * CreateListFileCache(RELOAD_CACHE pfnReloadCache, CLOSE_STREAM pfnCloseStream, void * pvCacheContext, DWORD dwFileSize)
{
    TListFileCache * pCache = NULL;
    DWORD dwBytesToRead;

    // Allocate cache for one file block
    pCache = (TListFileCache *)CASC_ALLOC(BYTE, sizeof(TListFileCache));
    if(pCache != NULL)
    {
        // Clear the entire structure
        memset(pCache, 0, sizeof(TListFileCache));
        pCache->pfnReloadCache = pfnReloadCache;
        pCache->pfnCloseStream = pfnCloseStream;
        pCache->pvCacheContext = pvCacheContext;
        pCache->dwFileSize = dwFileSize;

        // Load the file cache from the file
        dwBytesToRead = CASCLIB_MIN(CACHE_BUFFER_SIZE, dwFileSize);
        if(pfnReloadCache(pvCacheContext, pCache->Buffer, dwBytesToRead))
        {
            // Allocate pointers
            pCache->pBegin = pCache->pPos = &pCache->Buffer[0];
            pCache->pEnd   = pCache->pBegin + dwBytesToRead;
        }
        else
        {
            ListFile_Free(pCache);
            pCache = NULL;
        }
    }

    // Return the cache
    return pCache;
}
示例#4
0
void * ListFile_OpenExternal(const TCHAR * szListFile)
{
    PLISTFILE_CACHE pCache = NULL;
    TFileStream * pStream;
    ULONGLONG FileSize = 0;

    // Open the external listfile
    pStream = FileStream_OpenFile(szListFile, STREAM_FLAG_READ_ONLY);
    if(pStream != NULL)
    {
        // Retrieve the size of the external listfile
        FileStream_GetSize(pStream, &FileSize);
        if(0 < FileSize && FileSize <= 0x30000000)
        {
            // Create the in-memory cache for the entire listfile
            // The listfile does not have any data loaded yet
            pCache = CreateListFileCache((DWORD)FileSize);
            if(pCache != NULL)
            {
                if(!FileStream_Read(pStream, NULL, pCache->pBegin, (DWORD)FileSize))
                {
                    ListFile_Free(pCache);
                    pCache = NULL;
                }
            }
        }

        // Close the file stream
        FileStream_Close(pStream);
    }

    return pCache;
}
示例#5
0
static int LoadTextFile(TCascStorage * hs, PARSEINFOFILE PfnParseProc)
{
    void * pvListFile;
    int nError = ERROR_FILE_NOT_FOUND;

    // Load the text file for line-to-line parsing
    pvListFile = ListFile_OpenExternal(hs->szBuildFile);
    if (pvListFile != NULL)
    {
        // Parse the text file
        nError = PfnParseProc(hs, pvListFile);
        ListFile_Free(pvListFile);
    }

    return nError;
}
示例#6
0
static int FetchAndLoadConfigFile(TCascStorage * hs, PQUERY_KEY pFileKey, PARSEINFOFILE PfnParseProc)
{
    TCHAR * szFileName;
    void * pvListFile = NULL;
    int nError = ERROR_CAN_NOT_COMPLETE;

    // Construct the local file name
    szFileName = CascNewStr(hs->szDataPath, 8 + 3 + 3 + 32);
    if (szFileName != NULL)
    {
        // Add the part where the config file path is
        AppendConfigFilePath(szFileName, pFileKey);

        // Load and verify the external listfile
        pvListFile = ListFile_OpenExternal(szFileName);
        if (pvListFile != NULL)
        {
            if (ListFile_VerifyMD5(pvListFile, pFileKey->pbData))
            {
                nError = PfnParseProc(hs, pvListFile);
            }
            else
            {
                nError = ERROR_FILE_CORRUPT;
            }
            ListFile_Free(pvListFile);
        }
        else
        {
            nError = ERROR_FILE_NOT_FOUND;
        }
        CASC_FREE(szFileName);
    }
    else
    {
        nError = ERROR_NOT_ENOUGH_MEMORY;
    }

    return nError;
}
示例#7
0
PLISTFILE_MAP ListFile_CreateMap(const TCHAR * szListFile)
{
    PLISTFILE_MAP pListMap = NULL;
    void * pvListFile;
    char szFileName[MAX_PATH+1];
    size_t nLength;

    // Only if the listfile name has been given
    if(szListFile != NULL)
    {
        // Create map for the listfile
        pListMap = ListMap_Create();
        if(pListMap != NULL)
        {
            // Open the external listfile
            pvListFile = ListFile_OpenExternal(szListFile);
            if(pvListFile != NULL)
            {
                // Go through the entire listfile and insert each name to the map
                while((nLength = ListFile_GetNext(pvListFile, "*", szFileName, MAX_PATH)) != 0)
                {
                    // Insert the file name to the map
                    pListMap = ListMap_InsertName(pListMap, szFileName, nLength);
                    if(pListMap == NULL)
                        break;
                }

                // Finish the listfile map
                pListMap = ListMap_Finish(pListMap);

                // Free the listfile
                ListFile_Free(pvListFile);
            }
        }
    }

    // Return the created map
    return pListMap;
}
示例#8
0
int LoadBuildInfo(TCascStorage * hs)
{
    TCHAR * szAgentFile;
    TCHAR * szInfoFile;
    void * pvListFile;
    bool bBuildConfigComplete = false;
    int nError = ERROR_SUCCESS;

    // Since HOTS build 30027, the game uses .build.info file for storage info
    if(bBuildConfigComplete == false)
    {
        szInfoFile = CombinePath(hs->szRootPath, _T(".build.info"));
        if(szInfoFile != NULL)
        {
            pvListFile = ListFile_OpenExternal(szInfoFile);
            if(pvListFile != NULL)
            {
                // Parse the info file
                nError = ParseInfoFile(hs, pvListFile);
                if(nError == ERROR_SUCCESS)
                    bBuildConfigComplete = true;
                
                ListFile_Free(pvListFile);
            }

            CASC_FREE(szInfoFile);
        }
    }

    // If the info file has not been loaded, try the legacy .build.db
    if(bBuildConfigComplete == false)
    {
        szAgentFile = CombinePath(hs->szRootPath, _T(".build.db"));
        if(szAgentFile != NULL)
        {
            pvListFile = ListFile_OpenExternal(szAgentFile);
            if(pvListFile != NULL)
            {
                nError = ParseAgentFile(hs, pvListFile);
                if(nError == ERROR_SUCCESS)
                    bBuildConfigComplete = true;

                ListFile_Free(pvListFile);
            }
            CASC_FREE(szAgentFile);
        }
    }

    // If the .build.info OR .build.db file has been loaded,
    // proceed with loading the CDN config file and CDN build file
    if(nError == ERROR_SUCCESS && bBuildConfigComplete)
    {
        // Load the configuration file
        pvListFile = FetchAndVerifyConfigFile(hs, &hs->CdnConfigKey);
        if(pvListFile != NULL)
        {
            nError = LoadCdnConfigFile(hs, pvListFile);
            ListFile_Free(pvListFile);
        }
        else
            nError = ERROR_FILE_NOT_FOUND;
    }

    // Load the build file
    if(nError == ERROR_SUCCESS && bBuildConfigComplete)
    {
        pvListFile = FetchAndVerifyConfigFile(hs, &hs->CdnBuildKey);
        if(pvListFile != NULL)
        {
            nError = LoadCdnBuildFile(hs, pvListFile);
            ListFile_Free(pvListFile);
        }
        else
            nError = ERROR_FILE_NOT_FOUND;
    }

    // Fill the index directory
    if(nError == ERROR_SUCCESS)
    {
        // First, check for more common "data" subdirectory
        if((hs->szIndexPath = CheckForIndexDirectory(hs, _T("data"))) != NULL)
            return ERROR_SUCCESS;

        // Second, try the "darch" subdirectory (older builds of HOTS - Alpha)
        if((hs->szIndexPath = CheckForIndexDirectory(hs, _T("darch"))) != NULL)
            return ERROR_SUCCESS;

        nError = ERROR_FILE_NOT_FOUND;
    }

    return nError;
}
示例#9
0
unsigned char handlepub_main_disk(T_EVT_CODE event, T_EVT_PARAM *pEventParm)
{
    T_U32 ret;
    T_BOOL isFile= AK_FALSE;
    T_BOOL bListRet;
    T_EVT_PARAM evtParam;
    if(AK_NULL == pEventParm)
    {
        pEventParm= &evtParam;
    }

    
    if(M_EVT_MDISK_LIST == event)
    {
        T_U16 shortName[MAX_FILE_LEN];
        T_BOOL isFile= AK_FALSE;
        T_hFILE fh;
        if(pEventParm->p.pParam1 == AK_NULL)
        {
            m_triggerEvent(M_EVT_EXIT, pEventParm); //exit
            return 0;
        }
        pFileSel= (PFileSel)pEventParm->p.pParam1;

        #ifdef SUPPORT_SDCARD
        {
            Printf_UC(pEventParm->p.pParam1);
            if ((!Fwl_MemDevIsMount(MMC_SD_CARD))&& ((FileList_GetCurDriver() == MMC_SD_CARD)))
            {
                pFileSel->selResult = eFail;
                m_triggerEvent(M_EVT_EXIT, pEventParm); //exit
                return 0;
            }
        }
        #endif

        AK_DEBUG_OUTPUT("\nhandlepub_main_disk M_EVT_MDISK_LIST == event\n");
        Printf_UC(pFileSel->file);

        fh= Fwl_FileOpen(pFileSel->file, _FMODE_READ, _FMODE_READ);
        if( fh != FS_INVALID_HANDLE)
        {
            isFile= AK_TRUE;
            Fwl_FileClose(fh);
            Fwl_GetShortPath(shortName, pFileSel->file);
            Fwl_GetSelfParentDir(pFileSel->file);
        }

        if(pFileSel->displayStyle ==eFolderOnly)
        {
            AK_DEBUG_OUTPUT("\nhandlepub_main_disk displayStyle == eFolderOnly\n");

            #if USE_COLOR_LCD
            bListRet = ListFile_InitEx(pListFile, pFileSel->file, eRES_STR_PUB_DEL_HINT, CTRL_LISTFILE_DISP_FOLDONLY, (T_U16* )pFileSel->filter
                ,0, TITLE_HIGHT, MAIN_LCD_WIDTH, (T_LEN)(MAIN_LCD_HEIGHT- TITLE_HIGHT) );
             flashFlag= AK_TRUE;
            #else
            bListRet = ListFile_Init(pListFile, pFileSel->file, MDISK_TITLE, CTRL_LISTFILE_DISP_FOLDONLY, (T_U16* )pFileSel->filter);
            #endif
            //ListFile_InitShowMode(pListFile, 40, 5, DIAGRAM_MODE);
            #ifdef USE_HIDE_DRIVER
            if (AudioRecord_GetRecState() != eSTAT_REC_STOP)
            {
                ListFile_SetStyle(pListFile, (CTRL_LISTFILE_STYLE_ROOTDIR_DISPSHOW | CTRL_LISTFILE_STYLE_ROOTDISK_DISPNONE));
            }
            #endif
        }
        else
        {
            AK_DEBUG_OUTPUT("\nhandlepub_main_disk displayStyle != eFolderOnly\n");

            #if USE_COLOR_LCD
            bListRet=  ListFile_InitEx(pListFile, pFileSel->file, eRES_STR_PUB_DEL_HINT, CTRL_LISTFILE_DISP_ALL|CTRL_LISTFILE_DISP_PATTERONLY, (T_U16* )pFileSel->filter
                ,0, TITLE_HIGHT, MAIN_LCD_WIDTH, (T_LEN)(MAIN_LCD_HEIGHT- TITLE_HIGHT) );
             flashFlag= AK_TRUE;
            #else
            bListRet=  ListFile_Init(pListFile, pFileSel->file, MDISK_TITLE, CTRL_LISTFILE_DISP_ALL|CTRL_LISTFILE_DISP_PATTERONLY, (T_U16* )pFileSel->filter);
            #endif
            //ListFile_InitShowMode(pListFile, 40, 5, DIAGRAM_MODE);
            while(bListRet != AK_TRUE)
            {
                if(!Fwl_GetSelfParentDir(pFileSel->file))
                {
                    //pEventParam is pFileSel
                    #ifdef SUPPORT_SDCARD
                    pEventParm->w.Param1 = FileList_GetCurDriver();                     
                    #endif
                    //need updata file list
                    //Aud_AudCtrSetListUpdata();
                    m_triggerEvent(M_EVT_NO_FILE, pEventParm);
                    return 0;//without paint
                }
                ListFile_Free(pListFile);
                #if USE_COLOR_LCD
                bListRet=  ListFile_InitEx(pListFile, pFileSel->file, eRES_STR_PUB_DEL_HINT, CTRL_LISTFILE_DISP_ALL|CTRL_LISTFILE_DISP_PATTERONLY, (T_U16* )pFileSel->filter
                    ,0, TITLE_HIGHT, MAIN_LCD_WIDTH, (T_LEN)(MAIN_LCD_HEIGHT- TITLE_HIGHT) );
                 flashFlag= AK_TRUE;
                #else
                bListRet=  ListFile_Init(pListFile, pFileSel->file, MDISK_TITLE, CTRL_LISTFILE_DISP_ALL|CTRL_LISTFILE_DISP_PATTERONLY, (T_U16* )pFileSel->filter);
                #endif
                //ListFile_InitShowMode(pListFile, 40, 5, DIAGRAM_MODE);
            }

            if(isFile)
            {
               ListFile_SetCurFile(pListFile, shortName);
            }
#ifdef USE_HIDE_DRIVER
    #ifdef SUPPORT_SDCARD
            if (FileList_GetCurDriver() == MMC_SD_CARD)
            {
                ListFile_SetStyle(pListFile, (CTRL_LISTFILE_STYLE_ROOTDIR_DISPSHOW | CTRL_LISTFILE_STYLE_ROOTDISK_DISPNONE));
            }
            else
    #endif
            {
                ListFile_SetStyle(pListFile, (CTRL_LISTFILE_STYLE_ROOTDIR_DISPSHOW | CTRL_LISTFILE_STYLE_ROOTDISK_DISPSHOW));
            }
#endif
        }
        
        if (AK_FALSE == bListRet)
        {        
            pFileSel->selResult = eFail;
            m_triggerEvent(M_EVT_EXIT, pEventParm); //exit       
        }       
#if (LCD_TYPE == 3)
        VME_EvtQueueClearTimerEvent();
#endif
        return 1;
    }


    if(event == M_EVT_EXIT)
    {
//        flashFlag= AK_TRUE;
//        ListFile_SetRefresh(pListFile);
        m_triggerEvent(M_EVT_EXIT, pEventParm);
        return 0;
    }

    if(event == M_EVT_USER_KEY)
    {
        if(pEventParm->c.Param1 == kbMODE && pEventParm->c.Param2 == PRESS_SHORT)
        {
            pFileSel->selResult= eFail;
            pEventParm->p.pParam1 = pFileSel;// save the origal 
            m_triggerEvent(M_EVT_EXIT, pEventParm);
            return 0;
        }
    }

    if(event == M_EVT_RETURN)
    {
        event= M_EVT_USER_KEY;
        pEventParm->c.Param1 = kbMODE;
        pEventParm->c.Param2= PRESS_SHORT;
    }
    ret= ListFile_Handler(pListFile, event, pEventParm);
    switch(ret)
    {
    case CTRL_RESPONSE_QUIT:
        if(pFileSel != AK_NULL)
        {
            pFileSel->selResult= eFail;
        }
        pEventParm->p.pParam1= pFileSel;
        m_triggerEvent(M_EVT_EXIT, pEventParm);
        break;
    case CTRL_RESPONSE_NONE:
        //do nothing
        break;
        
    default:
        if(ret != 0)
        {
            Utl_UStrCpy(pFileSel->file, (T_U16* )ret);
            ListFile_GetFocusFile(pListFile, &isFile);    
            if(isFile)
            {
                pFileSel->selResult= eFile;
            }
            else
            {
                pFileSel->selResult= ePath;
            }            
        }
        else
        {
            pFileSel->selResult= eFail;
        }
        
        pEventParm->p.pParam1= pFileSel;
        m_triggerEvent(M_EVT_EXIT, pEventParm);
        break;
    }    
    if (event >= M_EVT_Z00_POWEROFF)
    {
        return 1;
    }
    else
        return 0;
}
示例#10
0
void exitpub_main_disk(void)
{
    ListFile_Free(pListFile);
    pListFile= (CListFileCtrl *)Fwl_Free(pListFile);
    Fwl_FreqPop();
}
示例#11
0
int LoadBuildInfo(TCascStorage * hs)
{
    PARSEINFOFILE PfnParseProc = NULL;
    void * pvListFile;
    int nError = ERROR_SUCCESS;

    switch(hs->BuildFileType)
    {
        case CascBuildInfo:
            PfnParseProc = ParseFile_BuildInfo;
            break;

        case CascBuildDb:
            PfnParseProc = ParseFile_BuildDb;
            break;

        default:
            nError = ERROR_NOT_SUPPORTED;
            break;
    }

    // Parse the appropriate build file
    if(nError == ERROR_SUCCESS)
    {
        pvListFile = ListFile_OpenExternal(hs->szBuildFile);
        if(pvListFile != NULL)
        {
            // Parse the info file
            nError = PfnParseProc(hs, pvListFile);
            ListFile_Free(pvListFile);
        }
        else
            nError = ERROR_FILE_NOT_FOUND;
    }

    // If the .build.info OR .build.db file has been loaded,
    // proceed with loading the CDN config file and CDN build file
    if(nError == ERROR_SUCCESS)
    {
        // Load the configuration file
        pvListFile = FetchAndVerifyConfigFile(hs, &hs->CdnConfigKey);
        if(pvListFile != NULL)
        {
            nError = LoadCdnConfigFile(hs, pvListFile);
            ListFile_Free(pvListFile);
        }
        else
            nError = ERROR_FILE_NOT_FOUND;
    }

    // Load the build file
    if(nError == ERROR_SUCCESS)
    {
        pvListFile = FetchAndVerifyConfigFile(hs, &hs->CdnBuildKey);
        if(pvListFile != NULL)
        {
            nError = LoadCdnBuildFile(hs, pvListFile);
            ListFile_Free(pvListFile);
        }
        else
            nError = ERROR_FILE_NOT_FOUND;
    }

    // Fill the index directory
    if(nError == ERROR_SUCCESS)
    {
        // First, check for more common "data" subdirectory
        if((hs->szIndexPath = CheckForIndexDirectory(hs, _T("data"))) != NULL)
            return ERROR_SUCCESS;

        // Second, try the "darch" subdirectory (older builds of HOTS - Alpha)
        if((hs->szIndexPath = CheckForIndexDirectory(hs, _T("darch"))) != NULL)
            return ERROR_SUCCESS;

        nError = ERROR_FILE_NOT_FOUND;
    }

    return nError;
}