ReplicaNet and RNLobby  1
ScanPath.h
1 /* START_LICENSE_HEADER
2 
3 Copyright (C) 2000 Martin Piper, original design and program code
4 Copyright (C) 2001 Replica Software
5 
6 This program file is copyright (C) Replica Software and can only be used under license.
7 For more information visit: http://www.replicanet.com/
8 Or email: info@replicanet.com
9 
10 END_LICENSE_HEADER */
11 #include "RNPlatform/Inc/MemoryTracking.h"
12 #ifndef _SCANPATH_H_
13 #define _SCANPATH_H_
14 #include <string>
15 #include <list>
16 #include <stddef.h>
17 // MPi: TODO: Make cross platform
18 #include <windows.h>
19 #include "RNPlatform/Inc/ThreadClass.h"
20 #include "RNPlatform/Inc/Thread.h"
21 
22 namespace RNReplicaNet
23 {
24 
25 namespace RNLobby
26 {
27 
29 class ScanPath : private ThreadClass , private Thread
30 {
31 public:
32  struct FileChecksum
33  {
34  int mValue[8];
35  };
37  struct Entry
38  {
39  Entry();
40  std::string mName;
41  unsigned int mSize;
42  bool mIsDirectory;
43  bool mIsLink;
44  bool mIsFile;
45 // MPi: TODO: Make cross platform
46  FILETIME mLastWriteTime;
47  FileChecksum mChecksum;
48  };
49 
50  ScanPath();
51  virtual ~ScanPath();
52 
53 
61  bool Start(const char *path,std::list<Entry> &result,const bool recurse = false,const bool justFiles = true,const bool multiThread = false);
62 
65  bool Stop(void);
66 
69  bool GetCompleted(void);
70 
73  virtual bool CallbackUpdate(const size_t numFiles,const size_t numFolders);
74 
76  virtual void CallbackComplete(void);
77 
79  static bool Write(const char *path,const std::list<Entry> &entries);
80 
82  static bool Read(const char *path,std::list<Entry> &entries);
83 
84 private:
85 
86  int ThreadEntry(void);
87  int RealThreadEntry(const std::string path,std::list<Entry> &results,const bool recurse,const bool justFiles);
88 
89  std::string mPath;
90  std::list<Entry> *mResult;
91  bool mRecurse;
92  bool mJustFiles;
93  HANDLE mhSearch;
94 };
95 
96 // Can be used for STL less<> tests
97 bool operator< (const ScanPath::Entry& a,const ScanPath::Entry& b);
98 
99 } // namespace RNLobby
100 
101 } // namespace RNReplicaNet
102 
103 #endif
bool Start(const char *path, std::list< Entry > &result, const bool recurse=false, const bool justFiles=true, const bool multiThread=false)
static bool Write(const char *path, const std::list< Entry > &entries)
A utility function to write the entries to a file.
virtual bool CallbackUpdate(const size_t numFiles, const size_t numFolders)
unsigned int mSize
The size of the entry. This can be the length of the file or the size of the directory.
Definition: ScanPath.h:41
virtual void CallbackComplete(void)
A virtual callback that is triggered when the scanning is complete.
This scans a supplied path and stores the results.
Definition: ScanPath.h:29
std::string mName
The name of the entry.
Definition: ScanPath.h:40
An entry in the list updated by ScanPath::Start()
Definition: ScanPath.h:37
static bool Read(const char *path, std::list< Entry > &entries)
A utility function to read the entries from a file.
Definition: ThreadClass.h:96
Definition: Thread.h:29