-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfile_io.h
123 lines (97 loc) · 3.08 KB
/
file_io.h
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
/* Copyright (c) 2012 Cheese and Bacon Games, LLC */
/* This file is licensed under the MIT License. */
/* See the file docs/LICENSE.txt for the full license text. */
#ifndef file_io_h
#define file_io_h
#include <string>
#include <sstream>
#ifdef GAME_OS_ANDROID
#include <vector>
#include <stdint.h>
#include <dirent.h>
#include <sys/stat.h>
#else
#include <boost/filesystem.hpp>
#endif
class File_IO_Load{
public:
bool load_success;
std::istringstream data;
File_IO_Load();
File_IO_Load(std::string path,bool binary=false);
void load_file(std::string path,bool binary=false);
bool file_loaded();
bool eof();
void getline(std::string* line);
std::string get_data();
};
#ifdef GAME_OS_ANDROID
class File_IO{
public:
bool save_file(std::string path,std::string data,bool append=false,bool binary=false);
bool directory_exists(std::string path);
bool file_exists(std::string path);
bool is_directory(std::string path);
bool is_regular_file(std::string path);
void create_directory(std::string path);
void remove_file(std::string path);
void remove_directory(std::string path);
std::string get_file_name(std::string path);
bool external_storage_available();
};
class File_IO_Directory_Iterator{
public:
std::string directory;
std::vector<std::string> asset_list;
uint32_t entry;
File_IO_Directory_Iterator(std::string get_directory);
bool evaluate();
void iterate();
bool is_directory();
bool is_regular_file();
std::string get_full_path();
std::string get_file_name();
};
class File_IO_Directory_Iterator_User_Data{
public:
std::string directory;
DIR* dir;
struct dirent* dir_entry;
uint32_t entry;
uint32_t entries;
File_IO_Directory_Iterator_User_Data(std::string get_directory);
~File_IO_Directory_Iterator_User_Data();
bool evaluate();
void iterate();
bool file_exists();
bool is_regular_file();
bool is_directory();
std::string get_full_path();
std::string get_file_name();
};
#else
class File_IO{
public:
bool save_file(std::string path,std::string data,bool append=false,bool binary=false);
bool directory_exists(std::string path);
bool file_exists(std::string path);
bool is_directory(std::string path);
bool is_regular_file(std::string path);
void create_directory(std::string path);
void remove_file(std::string path);
void remove_directory(std::string path);
std::string get_file_name(std::string path);
};
class File_IO_Directory_Iterator{
public:
boost::filesystem::directory_iterator it;
File_IO_Directory_Iterator(std::string get_directory);
bool evaluate();
void iterate();
bool is_directory();
bool is_regular_file();
std::string get_full_path();
std::string get_file_name();
};
#endif
#endif