virtual bool FindFile(const char *pFilename, const char *pPath, int Type, char *pBuffer, int BufferSize) { if(BufferSize < 1) return false; pBuffer[0] = 0; char aBuf[MAX_PATH_LENGTH]; CFindCBData Data; Data.pStorage = this; Data.pFilename = pFilename; Data.pPath = pPath; Data.pBuffer = pBuffer; Data.BufferSize = BufferSize; if(Type == TYPE_ALL) { // search within all available directories for(int i = 0; i < m_NumPaths; ++i) { fs_listdir(GetPath(i, pPath, aBuf, sizeof(aBuf)), FindFileCallback, i, &Data); if(pBuffer[0]) return true; } } else if(Type >= 0 && Type < m_NumPaths) { // search within wanted directory fs_listdir(GetPath(Type, pPath, aBuf, sizeof(aBuf)), FindFileCallback, Type, &Data); } return pBuffer[0] != 0; }
virtual void ListDirectory(int Type, const char *pPath, FS_LISTDIR_CALLBACK pfnCallback, void *pUser) { char aBuffer[MAX_PATH_LENGTH]; if(Type == TYPE_ALL) { // list all available directories for(int i = 0; i < m_NumPaths; ++i) fs_listdir(GetPath(i, pPath, aBuffer, sizeof(aBuffer)), pfnCallback, i, pUser); } else if(Type >= 0 && Type < m_NumPaths) { // list wanted directory fs_listdir(GetPath(Type, pPath, aBuffer, sizeof(aBuffer)), pfnCallback, Type, pUser); } }
static int FindFileCallback(const char *pName, int IsDir, int Type, void *pUser) { CFindCBData Data = *static_cast<CFindCBData *>(pUser); if(IsDir) { if(pName[0] == '.') return 0; // search within the folder char aBuf[MAX_PATH_LENGTH]; char aPath[MAX_PATH_LENGTH]; str_format(aPath, sizeof(aPath), "%s/%s", Data.pPath, pName); Data.pPath = aPath; fs_listdir(Data.pStorage->GetPath(Type, aPath, aBuf, sizeof(aBuf)), FindFileCallback, Type, &Data); if(Data.pBuffer[0]) return 1; } else if(!str_comp(pName, Data.pFilename)) { // found the file = end str_format(Data.pBuffer, Data.BufferSize, "%s/%s", Data.pPath, Data.pFilename); return 1; } return 0; }
void MENUS::demolist_populate() { if(demos) mem_free(demos); demos = 0; num_demos = 0; char buf[512]; str_format(buf, sizeof(buf), "%s/demos", client_user_directory()); fs_listdir(buf, demolist_count_callback, &num_demos); fs_listdir("demos", demolist_count_callback, &num_demos); demos = (DEMOITEM *)mem_alloc(sizeof(DEMOITEM)*num_demos, 1); mem_zero(demos, sizeof(DEMOITEM)*num_demos); FETCH_CALLBACKINFO info = {this, buf, 0}; fs_listdir(buf, demolist_fetch_callback, &info); info.prefix = "demos"; fs_listdir("demos", demolist_fetch_callback, &info); }
void CMenus::DemolistPopulate() { m_lDemos.clear(); if(strncmp(m_aCurrentDemoFolder, "demos", 256)) //add parent folder { CDemoItem Item; str_copy(Item.m_aName, "..", sizeof(Item.m_aName)); str_copy(Item.m_aFilename, "..", sizeof(Item.m_aFilename)); m_lDemos.add(Item); } char aBuf[512]; str_format(aBuf, sizeof(aBuf), "%s/%s", Client()->UserDirectory(), m_aCurrentDemoFolder); FETCH_CALLBACKINFO Info = {this, aBuf, 0}; fs_listdir(aBuf, DemolistFetchCallback, &Info); Info.m_pPrefix = m_aCurrentDemoFolder; fs_listdir(m_aCurrentDemoFolder, DemolistFetchCallback, &Info); }
virtual void ListDirectory(int Types, const char *pPath, FS_LISTDIR_CALLBACK pfnCallback, void *pUser) { char aBuffer[1024]; // list current directory if(Types&TYPE_CURRENT) { fs_listdir(pPath, pfnCallback, pUser); } // list users directory if(Types&TYPE_SAVE) { str_format(aBuffer, sizeof(aBuffer), "%s/%s", m_aApplicationSavePath, pPath); fs_listdir(aBuffer, pfnCallback, pUser); } // list datadir directory if(Types&TYPE_DATA) { str_format(aBuffer, sizeof(aBuffer), "%s/%s", m_aDatadir, pPath); fs_listdir(aBuffer, pfnCallback, pUser); } }
void engine_listdir(int types, const char *path, FS_LISTDIR_CALLBACK cb, void *user) { char buffer[1024]; /* list current directory */ if(types&LISTDIRTYPE_CURRENT) { fs_listdir(path, cb, user); } /* list users directory */ if(types&LISTDIRTYPE_SAVE) { engine_savepath(path, buffer, sizeof(buffer)); fs_listdir(buffer, cb, user); } /* list datadir directory */ if(types&LISTDIRTYPE_DATA) { str_format(buffer, sizeof(buffer), "%s/%s", datadir, path); fs_listdir(buffer, cb, user); } }
static int FindFileCallback(const char *pName, int IsDir, int Type, void *pUser) { CFindCBData *Data = static_cast<CFindCBData *>(pUser); if(IsDir) { if(pName[0] == '.') return 0; // search within the folder char aBuf[MAX_PATH_LENGTH]; char aPath[MAX_PATH_LENGTH]; str_format(aPath, sizeof(aPath), "%s/%s", Data->pPath, pName); Data->pPath = aPath; fs_listdir(Data->pStorage->GetPath(Type, aPath, aBuf, sizeof(aBuf)), FindFileCallback, Type, Data); if(Data->pBuffer[0]) return 1; } else { if(!str_comp(pName, Data->pFilename)) { // found the file str_format(Data->pBuffer, Data->BufferSize, "%s/%s", Data->pPath, Data->pFilename); // check crc and size if(Data->pCrcSizeMatch != 0) { unsigned Crc = 0; unsigned Size = 0; if(!Data->pStorage->GetCrcSize(Data->pBuffer, Type, &Crc, &Size) || Crc != Data->WantedCrc || Size != Data->WantedSize) { *Data->pCrcSizeMatch = false; Data->pBuffer[0] = 0; return 0; } else *Data->pCrcSizeMatch = true; } return 1; } } return 0; }
void CMenus::RenderDemoList(CUIRect MainView) { static int s_Inited = 0; if(!s_Inited) DemolistPopulate(); s_Inited = 1; // render background RenderTools()->DrawUIRect(&MainView, ms_ColorTabbarActive, CUI::CORNER_ALL, 10.0f); MainView.Margin(10.0f, &MainView); CUIRect ButtonBar; MainView.HSplitBottom(ms_ButtonHeight+5.0f, &MainView, &ButtonBar); ButtonBar.HSplitTop(5.0f, 0, &ButtonBar); static int s_SelectedItem = -1; static int s_DemoListId = 0; static float s_ScrollValue = 0; UiDoListboxStart(&s_DemoListId, &MainView, 17.0f, Localize("Demos"), "", m_lDemos.size(), 1, s_SelectedItem, s_ScrollValue); //for(int i = 0; i < num_demos; i++) for(sorted_array<CDemoItem>::range r = m_lDemos.all(); !r.empty(); r.pop_front()) { CListboxItem Item = UiDoListboxNextItem((void*)(&r.front())); if(Item.m_Visible) UI()->DoLabel(&Item.m_Rect, r.front().m_aName, Item.m_Rect.h*ms_FontmodHeight, -1); } bool Activated = false; s_SelectedItem = UiDoListboxEnd(&s_ScrollValue, &Activated); CUIRect RefreshRect, PlayRect; ButtonBar.VSplitRight(250.0f, &ButtonBar, &RefreshRect); RefreshRect.VSplitRight(130.0f, &RefreshRect, &PlayRect); PlayRect.VSplitRight(120.0f, 0x0, &PlayRect); bool IsDir = false; if(!strncmp(m_lDemos[s_SelectedItem].m_aName, "..", 256)) //parent folder IsDir = true; else fs_listdir(m_lDemos[s_SelectedItem].m_aFilename, IsDirCallback, &IsDir); static int s_RefreshButton = 0; if(DoButton_Menu(&s_RefreshButton, Localize("Refresh"), 0, &RefreshRect)) { DemolistPopulate(); } static int s_PlayButton = 0; char aTitleButton[8]; if(IsDir) str_copy(aTitleButton, "Open", sizeof(aTitleButton)); else str_copy(aTitleButton, "Play", sizeof(aTitleButton)); // /!\ TODO: Add "Open" in Localization /!\ if(DoButton_Menu(&s_PlayButton, Localize(aTitleButton), 0, &PlayRect) || Activated) { if(s_SelectedItem >= 0 && s_SelectedItem < m_lDemos.size()) { if(!strncmp(m_lDemos[s_SelectedItem].m_aName, "..", 256)) { DemoSetParentDirectory(); DemolistPopulate(); s_SelectedItem = 0; } else if(IsDir) { str_format(m_aCurrentDemoFolder, sizeof(m_aCurrentDemoFolder), "%s/%s", m_aCurrentDemoFolder, m_lDemos[s_SelectedItem].m_aName); DemolistPopulate(); s_SelectedItem = 0; } else { const char *pError = Client()->DemoPlayer_Play(m_lDemos[s_SelectedItem].m_aFilename); if(pError) PopupMessage(Localize("Error"), pError, Localize("Ok")); } } } }