#pragma once #include #include #include "Error.h" #include "Token.h" typedef enum NetResType { NRT_WORKER, NRT_NETWORK, NRT_DOMAIN, NRT_COMPUTER, NRT_SHARE } NetResType; typedef struct COLUMNS { unsigned count; struct { int left; int width; } item[10]; } COLUMNS, *PCOLUMNS; extern const DWORD MSG_NETNOTIFY; typedef enum NetNotifyMessages { NNM_ENUMSTARTED, NNM_ENUMFINISHED, NNM_ITEMADDED, // lParam : item ptr NNM_THREADCNTCHANGED, // lParam : lo = active / hi = total NNM_EMPTYDETECTED // lParam : this } NetNotifyMessages; // Thread count limiting extern LONG ThreadCount; // currently running threads (including waiting for start) extern LONG ActiveThreads; extern HANDLE semThreadLimit; // semaphore for limiting simulatneous threads extern CRITICAL_SECTION secLogin; // only one thread can login at once extern LPCTSTR semName; class CWorker; typedef void (*OnItemSelect)(CWorker* obj); class CWorker { public: typedef enum _ThreadState{ STOPPED, WAITING, RUNNING, COMPLETED, FAIL_RUN, FAIL_FINISHED } ThreadState; // GUI LRESULT OnNotifyMsg(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, OnItemSelect selproc); virtual int Filter(CToken *filter, int col); void Sort(bool recurse); virtual bool Save(HANDLE file); virtual void Draw(LPNMTVCUSTOMDRAW nmcd, PCOLUMNS cols); void Unfold(); void Expand(); // void SetState(ThreadState newstate); void DebugWrite(LPCTSTR str); CWorker( HWND control ); CWorker( HANDLE file, CWorker* parentnode, HWND control ); virtual ~CWorker(); virtual bool Search(LPCTSTR mask, DWORD minSizeMB, DWORD maxSizeMB); void Start(bool AutoRecurse);// = false); void Stop(unsigned timeout, bool recursive = false); // List manage CWorker* AddItem(CWorker *item); // return -1 on error; CWorker* AddNoCheck(CWorker *item, bool TreeOnly = false); bool RemoveItem(unsigned index); // false on error bool RemoveItem(CWorker *item); // false on error void ClearList(); unsigned GetItemIndex(CWorker *ptr); CWorker* GetParentNode(); NetResType GetType(); virtual inline bool HasAnything(); virtual inline unsigned GetCount(); virtual inline CWorker* operator[](unsigned index); LPTSTR m_Name; bool expanded; HTREEITEM tvItem; const NetResType type; protected: typedef struct NETPROPBAG { NetResType type; unsigned children; unsigned NameLen; } NETPROPBAG; struct LOCK { HANDLE event; DWORD ThreadID; DWORD locks; } lock; bool ExclusiveLock(DWORD timeout = INFINITE); void ExclusiveRelease(); void PostNotify(NetNotifyMessages code, LPARAM lParam); virtual void UpdateStatus(); virtual void Work(); CWorker* parent; HWND hwndNotify; bool cancelWork; bool AutoStart; Error err; unsigned children_to_load; HANDLE hEnum; HANDLE hThread; DWORD idThread; private: CRITICAL_SECTION exclusive1; bool AllocList(unsigned size); void SignalRecursive(bool value); unsigned allocated; unsigned count; CWorker **lpList; ThreadState state; struct { int col; CToken *token; } filter; RECT rcItem; static DWORD WINAPI AsyncFilterThread( void * This ); static DWORD WINAPI AsyncStartThread( void * This ); };