aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/filesystem/asset_database.cpp
blob: 6214a4a6fdb25e527ca840fed1bc6875d44aec0c (plain)
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
#include "../core/configuration.h"
#if defined(jin_filesystem)

#include <string.h>
#include <stdlib.h>
#include <stdio.h>  /* defines FILENAME_MAX */

#include "../common/exception.h"

#include "asset_database.h"

namespace JinEngine
{
	namespace Filesystem
	{

		AssetDatabase* AssetDatabase::mAssetDatabase = 0;

		AssetDatabase::AssetDatabase()
		{
			mSmt = smtnewshared();
		}

		AssetDatabase* AssetDatabase::get()
		{
			return mAssetDatabase ? mAssetDatabase : (mAssetDatabase = new AssetDatabase());
		}

		void AssetDatabase::mount(const char * path)
		{
			int err = smtmount(mSmt, path);
			if (err)
			{
				printf("%s mounted path %s", smterrstr(err), path);
				exit(1); 
			}
		}

		void AssetDatabase::read(const char* path, Buffer& buffer)
		{
			size_t size;
			byte* data = (byte*)smtread(mSmt, path, &size);
			if (data == nullptr)
				throw Exception("Could not read file %s.", path);
			buffer.bind(data, size);
		}

		Buffer* read(const char* path)
		{
			return nullptr;
		}

		void* AssetDatabase::read(const char* path, unsigned int* len)
		{
			return smtread(mSmt, path, len);
		}

		const char* AssetDatabase::getFull(const char* path)
		{
			return smtfullpath(mSmt, path);
		}

		bool AssetDatabase::isDir(const char* path)
		{
			return smtisdir(mSmt, path);
		}

		bool AssetDatabase::isFile(const char* path)
		{
			return smtisreg(mSmt, path);
		}

		bool AssetDatabase::exists(const char* path)
		{
			return smtexists(mSmt, path) == 0;
		}
/*
		std::vector<std::string> AssetDatabase::getFiles(const char* path, bool recursive)
		{
		}
*/
	} // namespace Filesystem
} // namespace JinEngine

#endif // jin_filesystem