aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/Filesystem/je_asset_database.cpp
blob: c945d6a8025ccecdf1d94b3e9506e5ee6e0be38e (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
#include <string.h>
#include <stdlib.h>
#include <stdio.h>  /* defines FILENAME_MAX */

#include "je_asset_database.h"

namespace JinEngine
{
	namespace Filesystem
	{

		AssetDatabase* AssetDatabase::fs = 0;

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

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

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

		int AssetDatabase::read(const char* path, Buffer* buffer)
		{
			buffer->data = smtread(S, path, &buffer->size);
			if (buffer->data == 0)
				return 0;
			return 1;
		}

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

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

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

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

		bool AssetDatabase::exists(const char* path)
		{
			return smtexists(S, path) == 0;
		}

	} // namespace Filesystem
} // namespace JinEngine