Add infos into target window
[ryzomcore.git] / ryzom / server / src / general_utilities_service / repository.h
blob3b4100c3513f492ef5a6b01b4c60f26c627b0eb2
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #ifndef REPOSITORY_H
18 #define REPOSITORY_H
21 //-----------------------------------------------------------------------------
22 // includes
23 //-----------------------------------------------------------------------------
25 #include "nel/misc/sstring.h"
26 #include "nel/misc/md5.h"
28 #include "rr_module_itf.h"
31 //-----------------------------------------------------------------------------
32 // utility routines
33 //-----------------------------------------------------------------------------
35 NLMISC::CSString getRepositoryIndexFileName(const NLMISC::CSString& repositoryName);
38 //-----------------------------------------------------------------------------
39 // class CRepository
40 //-----------------------------------------------------------------------------
42 class CRepository
44 public:
45 // local data types
46 struct CFilesMapEntry
48 uint32 FileSize;
49 uint32 FileTime;
50 NLMISC::CHashKeyMD5 Checksum;
52 CFilesMapEntry(): FileSize(0), FileTime(0) {}
53 void set(uint32 fileSize,uint32 fileTime,const NLMISC::CHashKeyMD5& checksum)
55 FileSize= fileSize;
56 FileTime= fileTime;
57 Checksum= checksum;
60 typedef std::map<NLMISC::CSString,CFilesMapEntry> TFiles;
61 typedef TFiles::iterator iterator;
62 typedef TFiles::const_iterator const_iterator;
64 public:
65 // setup the target directory and scan for files
66 // <name> defines the name used for temporary files and index files
67 // <directory> defines the root directory to be managed by the repository
68 // <filespec> defines the file specs that should be checked. eg: "*" or "*.bat;*.btm"
69 // <avoid> defines the vector of files that block the normal update behaviour eg "toto/tata/??_busy_*" or "abc/def;ghi/jkl"
70 // - if any of the 'avoid' files exist then we assume that some process is modifying the repository and we should wait for it to finish
71 bool init(const NLMISC::CSString& name,const NLMISC::CSString& directory,const NLMISC::CSString& filespec,const NLMISC::CSString& lockFilespecs);
73 // rescan target directory looking for new files and files that have changed
74 uint32 update();
76 // create a stub entry for a given file
77 // - this needs to be called before calling 'updateFile()' for the first time
78 void addFileStub(NLMISC::CSString fileName);
80 // update the entry for a given file
81 // - if the file is new then addFileStub() needs to be called first
82 void updateFile(NLMISC::CSString fileName);
84 // write index file to disk
85 // this is called automatically by init() and update() but needs to be called by hand after manual
86 // manipulation of map entries
87 void writeIndexFile();
89 // wrapping of the stl map container interface
90 uint32 size() const;
92 const CFilesMapEntry& operator[](const NLMISC::CSString&) const;
94 iterator find(const NLMISC::CSString&);
95 const_iterator find(const NLMISC::CSString&) const;
97 iterator begin();
98 const_iterator begin() const;
100 iterator end();
101 const_iterator end() const;
103 void fillShortList(std::vector<GUS_SCM::TFileRecord> &files) const;
105 private:
107 // private data
108 NLMISC::CSString _Name;
109 NLMISC::CSString _TargetDirectory;
110 NLMISC::CVectorSString _Filespec;
111 NLMISC::CVectorSString _LockFilespecs;
112 NLMISC::CSString _BlockingFiles;
113 TFiles _Files;
117 //-----------------------------------------------------------------------------
118 #endif