#pragma once

class KbFpvSearcher
{
private:
    CRITICAL_SECTION m_cs;
    wchar_t   m_szFpvPath[MAX_PATH];
    wchar_t **m_ppFileNames;
    int       m_nCount;
    int       m_nCapacity;
    HANDLE    m_hFind;
    HANDLE    m_hEvent;
    HANDLE    m_hThread;
    unsigned  m_uThreadId;
    static unsigned WINAPI ThreadProc(void *pThis);
    unsigned __fastcall ThreadProc(void);
    void __fastcall Lock(void){EnterCriticalSection(&m_cs);}
    void __fastcall Unlock(void){LeaveCriticalSection(&m_cs);}
    void __fastcall SearchFpvInternal(const wchar_t *cszBasePath);
    void __fastcall Add(const wchar_t *cszFileName);
    void __fastcall FreeFileNames(void);
public:
    KbFpvSearcher(void);
    ~KbFpvSearcher(void);
    wchar_t* __fastcall Find(wchar_t* szDest, const wchar_t* cszFpv, int Size);
    void  __fastcall SearchFpv(const wchar_t *cszFpvPath);
};
