Subversion Repository Public Repository

Divide-Framework

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#include "Headers/FileManagement.h"

#include "Core/Headers/StringHelper.h"
#include "Core/Headers/XMLEntryData.h"
#include "Core/Headers/Configuration.h"
#include "Core/Headers/PlatformContext.h"

namespace Divide {

namespace Paths {

    stringImplAligned g_assetsLocation;
    stringImplAligned g_shadersLocation;
    stringImplAligned g_texturesLocation;
    stringImplAligned g_imagesLocation;
    stringImplAligned g_materialsLocation;
    stringImplAligned g_soundsLocation;
    stringImplAligned g_xmlDataLocation;
    stringImplAligned g_navMeshesLocation;
    stringImplAligned g_scenesLocation;
    stringImplAligned g_saveLocation;
    stringImplAligned g_GUILocation;
    stringImplAligned g_FontsPath;

    namespace Shaders {
        stringImplAligned g_CacheLocation;
        stringImplAligned g_CacheLocationText;
        stringImplAligned g_CacheLocationBin;

        namespace GLSL {
            // these must match the last 4 characters of the atom file
            stringImplAligned g_fragAtomExt;
            stringImplAligned g_vertAtomExt;
            stringImplAligned g_geomAtomExt;
            stringImplAligned g_tescAtomExt;
            stringImplAligned g_teseAtomExt;
            stringImplAligned g_compAtomExt;
            stringImplAligned g_comnAtomExt;

            // Shader subfolder name that contains shader files for OpenGL
            stringImplAligned g_parentShaderLoc;
            // Atom folder names in parent shader folder
            stringImplAligned g_fragAtomLoc;
            stringImplAligned g_vertAtomLoc;
            stringImplAligned g_geomAtomLoc;
            stringImplAligned g_tescAtomLoc;
            stringImplAligned g_teseAtomLoc;
            stringImplAligned g_compAtomLoc;
            stringImplAligned g_comnAtomLoc;
        };
    };
    std::regex g_includePattern;

    void updatePaths(const PlatformContext& context) {
        const Configuration& config = context.config();
        const XMLEntryData& entryData = context.entryData();
        
        g_assetsLocation = entryData.assetsLocation + "/";
        g_shadersLocation = config.defaultShadersLocation + "/";
        g_texturesLocation = config.defaultTextureLocation + "/";
        g_xmlDataLocation = entryData.scriptLocation + "/";
        g_scenesLocation = entryData.scenesLocation + "/";
        g_saveLocation = "SaveData/";
        g_imagesLocation = "misc_images/";
        g_materialsLocation = "materials/";
        g_navMeshesLocation = "navMeshes/";
        g_GUILocation = "GUI/";
        g_FontsPath = "fonts/";
        g_soundsLocation = "sounds/";

        Shaders::g_CacheLocation = "shaderCache/";
        Shaders::g_CacheLocationText = Shaders::g_CacheLocation + "Text/";
        Shaders::g_CacheLocationBin = Shaders::g_CacheLocation + "Binary/";
        // these must match the last 4 characters of the atom file
        Shaders::GLSL::g_fragAtomExt = "frag";
        Shaders::GLSL::g_vertAtomExt = "vert";
        Shaders::GLSL::g_geomAtomExt = "geom";
        Shaders::GLSL::g_tescAtomExt = "tesc";
        Shaders::GLSL::g_teseAtomExt = "tese";
        Shaders::GLSL::g_compAtomExt = ".cpt";
        Shaders::GLSL::g_comnAtomExt = ".cmn";

        Shaders::GLSL::g_parentShaderLoc = "GLSL/";
        Shaders::GLSL::g_fragAtomLoc = "fragmentAtoms/";
        Shaders::GLSL::g_vertAtomLoc = "vertexAtoms/";
        Shaders::GLSL::g_geomAtomLoc = "geometryAtoms/";
        Shaders::GLSL::g_tescAtomLoc = "tessellationCAtoms/";
        Shaders::GLSL::g_teseAtomLoc = "tessellationEAtoms/";
        Shaders::GLSL::g_compAtomLoc = "computeAtoms/";
        Shaders::GLSL::g_comnAtomLoc = "common/";

        g_includePattern = std::regex("^[ ]*#[ ]*include[ ]+[\"<](.*)[\">].*");
    }
};

bool readFile(const stringImpl& filePath, stringImpl& contentOut, FileType fileType) {
    if (!filePath.empty()) {
        std::ifstream inFile(filePath.c_str(), fileType == FileType::BINARY
                                                         ? std::ios::in | std::ios::binary
                                                         : std::ios::in);

        if (!inFile.eof() && !inFile.fail()) {
            inFile.seekg(0, std::ios::end);
            size_t fsize = inFile.tellg();
            inFile.seekg(0, std::ios::beg);
            contentOut.reserve(fsize);

            std::copy_n(std::istreambuf_iterator<char>(inFile), fsize, std::back_inserter(contentOut));
            return true;
        }

        inFile.close();
    };

    return false;
}

bool readFile(const stringImpl& filePath, vectorImpl<Byte>& contentOut, FileType fileType) {
    stringImpl content;
    contentOut.resize(0);
    if (readFile(filePath, content, fileType)) {
        contentOut.insert(std::cbegin(contentOut), std::cbegin(content), std::cend(content));
        return true;
    }

    return false;
}

bool readFile(const stringImpl& filePath, vectorImpl<U8>& contentOut, FileType fileType) {
    stringImpl content;
    contentOut.resize(0);
    if (readFile(filePath, content, fileType)) {
        contentOut.insert(std::cbegin(contentOut), std::cbegin(content), std::cend(content));
        return true;
    }
    return false;
}

bool writeFile(const stringImpl& filePath, const char* content, size_t length, FileType fileType) {
    if (!filePath.empty() && content != nullptr && length > 0) {
        std::ofstream outputFile(filePath.c_str(), fileType == FileType::BINARY 
                                                             ? std::ios::out | std::ios::binary
                                                             : std::ios::out);
        outputFile.write(content, length);
        outputFile.close();
        return outputFile.good();
    }

    return false;
}

bool writeFile(const stringImpl& filePath, const char* content, FileType fileType) {
    return writeFile(filePath, content, strlen(content), fileType);
}

bool writeFile(const stringImpl& filePath, const vectorImpl<U8>& content, FileType fileType) {
    return writeFile(filePath, content, content.size(), fileType);
}

bool writeFile(const stringImpl& filePath, const vectorImpl<U8>& content, size_t length, FileType fileType) {
    return writeFile(filePath, reinterpret_cast<const char*>(content.data()), length, fileType);
}

bool writeFile(const stringImpl& filePath, const vectorImpl<Byte>& content, FileType fileType) {
    return writeFile(filePath, content, content.size(), fileType);
}

bool writeFile(const stringImpl& filePath, const vectorImpl<Byte>& content, size_t length, FileType fileType) {
    return writeFile(filePath, content.data(), length, fileType);
}

FileWithPath splitPathToNameAndLocation(const stringImpl& input) {
    size_t pathNameSplitPoint = input.find_last_of('/') + 1;
    return FileWithPath{
        input.substr(pathNameSplitPoint, stringImpl::npos),
        input.substr(0, pathNameSplitPoint)
    };
}

bool fileExists(const char* filePath) {
    return std::ifstream(filePath).good();
}

bool createFile(const char* filePath, bool overwriteExisting) {
    if (overwriteExisting && fileExists(filePath)) {
        return std::ifstream(filePath, std::fstream::in | std::fstream::trunc).good();
    }

    createDirectories(splitPathToNameAndLocation(filePath)._path.c_str());

    return std::ifstream(filePath, std::fstream::in).good();

}

bool hasExtension(const stringImpl& filePath, const stringImpl& extension) {
    stringImpl ext("." + extension);
    return Util::CompareIgnoreCase(Util::GetTrailingCharacters(filePath, ext.length()), ext);
}

}; //namespace Divide

Commits for Divide-Framework/trunk/Source Code/Platform/File/FileManagement.cpp

Diff revisions: vs.
Revision Author Commited Message
832 Diff Diff IonutCava picture IonutCava Thu 26 Jan, 2017 17:23:11 +0000

[IonutCava]
- More path related work
- Initial code to centralize file I/O (does not compile yet)

831 Diff Diff IonutCava picture IonutCava Wed 25 Jan, 2017 23:52:34 +0000

[IonutCava]
- More path related updates

830 IonutCava picture IonutCava Wed 25 Jan, 2017 17:29:44 +0000

[IonutCava]
- Add a new Platform element: File
— Move all predefined paths to FileManagement System
- Split MathHelper into MathHelper and StringHelper