Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

Diff Revisions 831 vs 832 for /trunk/Source Code/Platform/File/FileManagement.cpp

Diff revisions: vs.
  @@ -18,6 +18,7 @@
18 18 stringImplAligned g_xmlDataLocation;
19 19 stringImplAligned g_navMeshesLocation;
20 20 stringImplAligned g_scenesLocation;
21 + stringImplAligned g_saveLocation;
21 22 stringImplAligned g_GUILocation;
22 23 stringImplAligned g_FontsPath;
23 24
  @@ -59,7 +60,7 @@
59 60 g_texturesLocation = config.defaultTextureLocation + "/";
60 61 g_xmlDataLocation = entryData.scriptLocation + "/";
61 62 g_scenesLocation = entryData.scenesLocation + "/";
62 -
63 + g_saveLocation = "SaveData/";
63 64 g_imagesLocation = "misc_images/";
64 65 g_materialsLocation = "materials/";
65 66 g_navMeshesLocation = "navMeshes/";
  @@ -68,8 +69,8 @@
68 69 g_soundsLocation = "sounds/";
69 70
70 71 Shaders::g_CacheLocation = "shaderCache/";
71 - Shaders::g_CacheLocationText = Util::StringFormat("%s/Text/", Shaders::g_CacheLocation);
72 - Shaders::g_CacheLocationBin = Util::StringFormat("%s/Binary/", Shaders::g_CacheLocation);
72 + Shaders::g_CacheLocationText = Shaders::g_CacheLocation + "Text/";
73 + Shaders::g_CacheLocationBin = Shaders::g_CacheLocation + "Binary/";
73 74 // these must match the last 4 characters of the atom file
74 75 Shaders::GLSL::g_fragAtomExt = "frag";
75 76 Shaders::GLSL::g_vertAtomExt = "vert";
  @@ -78,7 +79,8 @@
78 79 Shaders::GLSL::g_teseAtomExt = "tese";
79 80 Shaders::GLSL::g_compAtomExt = ".cpt";
80 81 Shaders::GLSL::g_comnAtomExt = ".cmn";
81 - Shaders::GLSL::g_parentShaderLoc = "GLSL";
82 +
83 + Shaders::GLSL::g_parentShaderLoc = "GLSL/";
82 84 Shaders::GLSL::g_fragAtomLoc = "fragmentAtoms/";
83 85 Shaders::GLSL::g_vertAtomLoc = "vertexAtoms/";
84 86 Shaders::GLSL::g_geomAtomLoc = "geometryAtoms/";
  @@ -91,52 +93,106 @@
91 93 }
92 94 };
93 95
94 - void ReadTextFile(const stringImpl& filePath, stringImpl& contentOut) {
95 - std::ifstream inFile(filePath.c_str(), std::ios::in);
96 + bool readFile(const stringImpl& filePath, stringImpl& contentOut, FileType fileType) {
97 + if (!filePath.empty()) {
98 + std::ifstream inFile(filePath.c_str(), fileType == FileType::BINARY
99 + ? std::ios::in | std::ios::binary
100 + : std::ios::in);
101 +
102 + if (!inFile.eof() && !inFile.fail()) {
103 + inFile.seekg(0, std::ios::end);
104 + size_t fsize = inFile.tellg();
105 + inFile.seekg(0, std::ios::beg);
106 + contentOut.reserve(fsize);
107 +
108 + std::copy_n(std::istreambuf_iterator<char>(inFile), fsize, std::back_inserter(contentOut));
109 + return true;
110 + }
96 111
97 - if (!inFile.eof() && !inFile.fail())
98 - {
99 - assert(inFile.good());
100 - inFile.seekg(0, std::ios::end);
101 - contentOut.reserve(inFile.tellg());
102 - inFile.seekg(0, std::ios::beg);
112 + inFile.close();
113 + };
103 114
104 - contentOut.assign((std::istreambuf_iterator<char>(inFile)),
105 - std::istreambuf_iterator<char>());
115 + return false;
116 + }
117 +
118 + bool readFile(const stringImpl& filePath, vectorImpl<Byte>& contentOut, FileType fileType) {
119 + stringImpl content;
120 + contentOut.resize(0);
121 + if (readFile(filePath, content, fileType)) {
122 + contentOut.insert(std::cbegin(contentOut), std::cbegin(content), std::cend(content));
123 + return true;
106 124 }
107 125
108 - inFile.close();
126 + return false;
109 127 }
110 128
111 - stringImpl ReadTextFile(const stringImpl& filePath) {
129 + bool readFile(const stringImpl& filePath, vectorImpl<U8>& contentOut, FileType fileType) {
112 130 stringImpl content;
113 - ReadTextFile(filePath, content);
114 - return content;
131 + contentOut.resize(0);
132 + if (readFile(filePath, content, fileType)) {
133 + contentOut.insert(std::cbegin(contentOut), std::cbegin(content), std::cend(content));
134 + return true;
135 + }
136 + return false;
115 137 }
116 138
117 - void WriteTextFile(const stringImpl& filePath, const stringImpl& content) {
118 - if (filePath.empty()) {
119 - return;
139 + bool writeFile(const stringImpl& filePath, const char* content, size_t length, FileType fileType) {
140 + if (!filePath.empty() && content != nullptr && length > 0) {
141 + std::ofstream outputFile(filePath.c_str(), fileType == FileType::BINARY
142 + ? std::ios::out | std::ios::binary
143 + : std::ios::out);
144 + outputFile.write(content, length);
145 + outputFile.close();
146 + return outputFile.good();
120 147 }
121 - std::ofstream outputFile(filePath.c_str(), std::ios::out);
122 - outputFile << content;
123 - outputFile.close();
124 - assert(outputFile.good());
148 +
149 + return false;
125 150 }
126 151
127 - std::pair<stringImpl/*fileName*/, stringImpl/*filePath*/>
128 - SplitPathToNameAndLocation(const stringImpl& input) {
129 - size_t pathNameSplitPoint = input.find_last_of('/') + 1;
152 + bool writeFile(const stringImpl& filePath, const char* content, FileType fileType) {
153 + return writeFile(filePath, content, strlen(content), fileType);
154 + }
155 +
156 + bool writeFile(const stringImpl& filePath, const vectorImpl<U8>& content, FileType fileType) {
157 + return writeFile(filePath, content, content.size(), fileType);
158 + }
159 +
160 + bool writeFile(const stringImpl& filePath, const vectorImpl<U8>& content, size_t length, FileType fileType) {
161 + return writeFile(filePath, reinterpret_cast<const char*>(content.data()), length, fileType);
162 + }
163 +
164 + bool writeFile(const stringImpl& filePath, const vectorImpl<Byte>& content, FileType fileType) {
165 + return writeFile(filePath, content, content.size(), fileType);
166 + }
130 167
131 - return std::make_pair(input.substr(pathNameSplitPoint, stringImpl::npos),
132 - input.substr(0, pathNameSplitPoint));
168 + bool writeFile(const stringImpl& filePath, const vectorImpl<Byte>& content, size_t length, FileType fileType) {
169 + return writeFile(filePath, content.data(), length, fileType);
170 + }
171 +
172 + FileWithPath splitPathToNameAndLocation(const stringImpl& input) {
173 + size_t pathNameSplitPoint = input.find_last_of('/') + 1;
174 + return FileWithPath{
175 + input.substr(pathNameSplitPoint, stringImpl::npos),
176 + input.substr(0, pathNameSplitPoint)
177 + };
133 178 }
134 179
135 - bool FileExists(const char* filePath) {
180 + bool fileExists(const char* filePath) {
136 181 return std::ifstream(filePath).good();
137 182 }
138 183
139 - bool HasExtension(const stringImpl& filePath, const stringImpl& extension) {
184 + bool createFile(const char* filePath, bool overwriteExisting) {
185 + if (overwriteExisting && fileExists(filePath)) {
186 + return std::ifstream(filePath, std::fstream::in | std::fstream::trunc).good();
187 + }
188 +
189 + createDirectories(splitPathToNameAndLocation(filePath)._path.c_str());
190 +
191 + return std::ifstream(filePath, std::fstream::in).good();
192 +
193 + }
194 +
195 + bool hasExtension(const stringImpl& filePath, const stringImpl& extension) {
140 196 stringImpl ext("." + extension);
141 197 return Util::CompareIgnoreCase(Util::GetTrailingCharacters(filePath, ext.length()), ext);
142 198 }