1 /*
2 *  Open Fodder
3 *  ---------------
4 *
5 *  Copyright (C) 2008-2018 Open Fodder
6 *
7 *  This program is free software; you can redistribute it and/or modify
8 *  it under the terms of the GNU General Public License as published by
9 *  the Free Software Foundation; either version 3 of the License, or
10 *  (at your option) any later version.
11 *
12 *  This program is distributed in the hope that it will be useful,
13 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 *  GNU General Public License for more details.
16 *
17 *  You should have received a copy of the GNU General Public License along
18 *  with this program; if not, write to the Free Software Foundation, Inc.,
19 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 */
22 
23 class cResourceMan {
24 	typedef std::map<std::string, std::string> tStringMap;
25 
26 	std::vector<std::string> mAllPaths;
27 	std::vector<std::string> mValidPaths;
28 
29 	std::map<const sGameVersion*, std::string> mReleasePath;
30 	std::map<std::string, std::string> mCampaigns;
31 
32 	std::map<std::string, std::string> mMaps;
33 	std::map<std::string, std::string> mSaves;
34 	std::map<std::string, std::string> mTests;
35 
36 	std::multimap<const sGameVersion*, tStringMap> mReleaseFiles;
37 
38 	std::string mCustomMapPath;
39 
40 protected:
41 	void addBaseDir(std::string pPath);
42 	void addDefaultDirs();
43 	void validatePaths();
44 
45 
46 	std::string FileMD5(const std::string& pFile);
47 
48 	void findCampaigns();
49 	void findVersions();
50 	void findSaves();
51 	void findCustomMaps();
52 
53 public:
54 
55 	cResourceMan();
56 
57 	void addDir(const std::string& pPath);
58 
59 	void refresh();
60 
61 	std::string	FindVersionPath(const sGameVersion* pVersion) const;
62 	std::string GetFilePath(const sGameVersion* pVersion, std::string pFile) const;
63 
64 	tSharedBuffer FileRead(const std::string& pFile);
65 	std::string	FileReadStr(const std::string& pFile);
66 
67 	std::string PathGenerate(const std::string& pFile, eDataType pDataType) const;
68 
69 	std::string GetAboutFile() const;
70 	std::string GetWavPath(const std::string& pFile) const;
71 
72 	std::string GetCampaignData(const std::string& pName);
73 	std::string GetMapPath(const std::string& pName) const;
74 
75 	std::string GetSave(const std::string &pName) const;
76 	std::string GetSaveNewName() const;
77 
78 	std::string GetTestPath(const sGameVersion* pVersion, const std::string pFile) const;
79 	std::string GetScriptPath(const std::string& pType) const;
80 
81 	std::vector<const sGameVersion*> GetAvailable() const;
82 	std::vector<std::string> GetCampaigns() const;
83 	std::vector<std::string> GetSaves() const;
84 	std::vector<std::string> GetMaps() const;
85 
86 	bool isCampaignAvailable(std::string pName) const;
87 	bool isDataAvailable() const;
88 
89 	std::vector<std::string> getValidPaths() const;
90 	std::vector<std::string> getAllPaths() const;
91 
getCustomMapPath() const92 	std::string getCustomMapPath() const { return mCustomMapPath;  }
93 
94 
95 	std::vector<std::string> DirectoryList(const std::string& pPath, const std::string& pExtension);
96 	bool				FileExists(const std::string& pPath) const;
97 
98 	std::string			getcwd();
99 
100 };