1 /*
2 ** filesys.h
3 **
4 **---------------------------------------------------------------------------
5 ** Copyright 2011 Braden Obrzut
6 ** All rights reserved.
7 **
8 ** Redistribution and use in source and binary forms, with or without
9 ** modification, are permitted provided that the following conditions
10 ** are met:
11 **
12 ** 1. Redistributions of source code must retain the above copyright
13 **    notice, this list of conditions and the following disclaimer.
14 ** 2. Redistributions in binary form must reproduce the above copyright
15 **    notice, this list of conditions and the following disclaimer in the
16 **    documentation and/or other materials provided with the distribution.
17 ** 3. The name of the author may not be used to endorse or promote products
18 **    derived from this software without specific prior written permission.
19 **
20 ** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 ** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 ** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 ** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 ** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 ** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 ** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 **---------------------------------------------------------------------------
31 **
32 **
33 */
34 
35 #ifndef __FILESYS_H__
36 #define __FILESYS_H__
37 
38 #include "tarray.h"
39 #include "zstring.h"
40 
41 #ifdef _WIN32
42 #define PATH_SEPARATOR "\\"
43 #else
44 #define PATH_SEPARATOR "/"
45 #endif
46 
47 namespace FileSys
48 {
49 	enum ESpecialDirectory
50 	{
51 		DIR_Program,
52 		DIR_Configuration,
53 		DIR_Saves,
54 		DIR_ApplicationSupport,
55 		DIR_Documents,
56 		DIR_Screenshots,
57 
58 		NUM_SPECIAL_DIRECTORIES
59 	};
60 
61 	enum ESteamApp
62 	{
63 		APP_Wolfenstein3D,
64 		APP_SpearOfDestiny,
65 		APP_ThrowbackPack,
66 		APP_NoahsArk,
67 
68 		NUM_STEAM_APPS
69 	};
70 
71 	FString GetDirectoryPath(ESpecialDirectory dir);
72 	FString GetSteamPath(ESteamApp game);
73 	FString GetGOGPath(ESteamApp game);
74 	void SetDirectoryPath(ESpecialDirectory dir, const FString &path);
75 	void SetupPaths(int argc, const char* const *argv);
76 
77 #ifdef __APPLE__
78 	FString OSX_FindFolder(ESpecialDirectory dir);
79 #endif
80 }
81 
82 class File
83 {
84 	public:
85 		File(const FString &filename);
86 		File(const File &dir, const FString &filename);
~File()87 		~File() {}
88 
exists()89 		bool					exists() const { return existing; }
90 		FString					getDirectory() const;
91 		FString					getFileName() const;
getFileList()92 		const TArray<FString>	&getFileList() const { return files; }
93 		FString					getInsensitiveFile(const FString &filename, bool sensitiveExtension) const;
isDirectory()94 		bool					isDirectory() const { return directory; }
isFile()95 		bool					isFile() const { return !directory; }
isWritable()96 		bool					isWritable() const { return writable; }
97 		FILE					*open(const char* mode) const;
98 		void					rename(const FString &newname);
99 		bool					remove();
100 
101 	protected:
102 		void					init(FString filename);
103 
104 		FString	filename;
105 
106 		TArray<FString>	files;
107 		bool			directory;
108 		bool			existing;
109 		bool			writable;
110 };
111 
112 #endif /* __FILESYS_H__ */
113