blob: 443242fd99bfdc390071ffce101f5cb9a5e38c35 (
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
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
201
202
203
204
205
206
207
208
209
210
211
|
/*************************************************/
/* dir_access_psp.cpp */
/*************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/*************************************************/
/* Source code within this file is: */
/* (c) 2007-2016 Juan Linietsky, Ariel Manzur */
/* All Rights Reserved. */
/*************************************************/
#include "dir_access_flash.h"
#include "print_string.h"
DirAccess* DirAccessFlash::create_flash() {
return memnew( DirAccessFlash );
};
void DirAccessFlash::make_default() {
instance_func=create_flash;
}
bool DirAccessFlash::list_dir_begin() {
list_dir_end();
dir_stream = opendir(current_dir.utf8().get_data());
if (!dir_stream)
return true; //error!
return false;
};
String DirAccessFlash::get_next() {
if (!dir_stream)
return "";
dirent *entry;
entry=readdir(dir_stream);
if (entry==NULL) {
list_dir_end();
return "";
}
//typedef struct stat Stat;
struct stat flags;
String fname;
if (fname.parse_utf8(entry->d_name))
fname=entry->d_name; //no utf8, maybe latin?
String f=current_dir+"/"+fname;
if (stat(f.utf8().get_data(),&flags)==0) {
if (S_ISDIR(flags.st_mode)) {
_cisdir=true;
} else {
_cisdir=false;
}
} else {
_cisdir=false;
}
return fname;
};
bool DirAccessFlash::current_is_dir() const {
return _cisdir;
};
void DirAccessFlash::list_dir_end() {
if (dir_stream)
closedir(dir_stream);
dir_stream=0;
_cisdir=false;
};
int DirAccessFlash::get_drive_count() {
return 1;
};
String DirAccessFlash::get_drive(int p_drive) {
return "host0";
};
Error DirAccessFlash::change_dir(String p_dir) {
if (p_dir==".")
return OK;
if (p_dir.is_rel_path())
current_dir+="/"+p_dir;
else
current_dir=fix_path(p_dir);
current_dir=current_dir.simplify_path();
if (current_dir.length()>1 && current_dir.ends_with("/") && !current_dir.ends_with("//"))
current_dir=current_dir.substr(0,current_dir.length()-1);
return OK;
};
String DirAccessFlash::get_current_dir() {
return current_dir;
};
uint64_t DirAccessFlash::get_modified_time(String p_file) {
return 0;
};
Error DirAccessFlash::make_dir(String p_dir) {
return ERR_UNAVAILABLE;
};
bool DirAccessFlash::file_exists(String p_file) {
GLOBAL_LOCK_FUNCTION
if (p_file.is_rel_path())
p_file=current_dir+"/"+p_file;
else
p_file=fix_path(p_file);
struct stat flags;
bool success = (stat(p_file.utf8().get_data(),&flags)==0);
if (success && S_ISDIR(flags.st_mode)) {
success=false;
}
return success;
};
bool DirAccessFlash::dir_exists(String p_dir) {
GLOBAL_LOCK_FUNCTION
if (p_dir.is_rel_path())
p_dir=current_dir+"/"+p_dir;
else
p_dir=fix_path(p_dir);
struct stat flags;
bool success = (stat(p_dir.utf8().get_data(),&flags)==0);
if (success && S_ISDIR(flags.st_mode)) {
return true;
}
return false;
};
size_t DirAccessFlash::get_space_left() {
return 0;
};
Error DirAccessFlash::rename(String p_from, String p_to) {
return FAILED;
};
Error DirAccessFlash::remove(String p_name) {
return FAILED;
};
extern char* psp_drive;
DirAccessFlash::DirAccessFlash() {
dir_stream=0;
current_dir=".";
_cisdir=false;
/* determine drive count */
change_dir(current_dir);
}
DirAccessFlash::~DirAccessFlash() {
list_dir_end();
};
|