23 #ifdef ARDUINO_ARCH_ESP32
25 #if ENABLED(SDSUPPORT) && ENABLED(ESP3D_WIFISUPPORT)
26 #include MARLIN_PATH(sd/cardreader.h)
27 #include MARLIN_PATH(sd/SdVolume.h)
28 #include MARLIN_PATH(sd/SdFatStructs.h)
29 #include MARLIN_PATH(sd/SdFile.h)
47 if (((SdFile *)_sdfile)->isOpen())
close();
48 if (_sdfile)
delete (SdFile *) _sdfile;
52 return (((SdFile *)_sdfile)->isOpen());
56 if (!IS_SD_INSERTED() || !card.isMounted())
return 0;
57 if ( card.isPrinting() || card.isFileOpen() )
return -1;
62 if (path == NULL)
return false;
64 String pathname = fullpath.substring(0,fullpath.lastIndexOf(
"/"));
65 String filename =
makeshortname(fullpath.substring(fullpath.lastIndexOf(
"/")+1));
66 if (pathname.length() == 0)pathname=
"/";
67 if (!
openDir(pathname))
return false;
70 return ((SdFile *)_sdfile)->open(&workDir, filename.c_str(), readonly?O_READ:(O_CREAT | O_APPEND | O_WRITE | O_TRUNC));
74 if(((SdFile *)_sdfile)->isOpen()) {
75 _size = ((SdFile *)_sdfile)->fileSize();
81 if(!((SdFile *)_sdfile)->isOpen() || !_readonly)
return 0;
82 _size = ((SdFile *)_sdfile)->fileSize();
83 if (_size == 0)
return 0;
89 if(((SdFile *)_sdfile)->isOpen()) {
90 ((SdFile *)_sdfile)->sync();
91 _size = ((SdFile *)_sdfile)->fileSize();
92 ((SdFile *)_sdfile)->close();
97 return ((SdFile *)_sdfile)->write(data, len);
101 return ((SdFile *)_sdfile)->write(&
byte, 1);
106 bool response =
open(path);
107 if (response)
close();
112 if (path == NULL)
return false;
113 String fullpath=path;
114 String pathname = fullpath.substring(0,fullpath.lastIndexOf(
"/"));
115 String filename =
makeshortname(fullpath.substring(fullpath.lastIndexOf(
"/")+1));
116 if (pathname.length() == 0)pathname=
"/";
117 if (!
openDir(pathname))
return false;
119 return file.remove(&workDir, filename.c_str());
127 if (path == NULL)
return false;
128 String fullpath=path;
129 if (fullpath==
"/")
return false;
130 if (!
openDir(fullpath))
return false;
131 return workDir.rmRfStar();
135 if (path == NULL)
return false;
136 String fullpath=path;
137 String pathname = fullpath.substring(0,fullpath.lastIndexOf(
"/"));
138 String filename =
makeshortname(fullpath.substring(fullpath.lastIndexOf(
"/")+1));
139 if (pathname.length() == 0)pathname=
"/";
140 if (!
openDir(pathname))
return false;
142 return file.mkdir(&workDir, filename.c_str());
146 if (!_readonly)
return 0;
147 int16_t v = ((SdFile *)_sdfile)->read();
154 if (!_readonly)
return 0;
155 int16_t v = ((SdFile *)_sdfile)->read(buf, nbyte);
160 String ESP_SD::get_path_part(String data,
int index){
162 int strIndex[] = {0, -1};
167 if (s.length() == 0)
return no_res;
168 maxIndex = s.length()-1;
169 if ((s[0] ==
'/') && (s.length() > 1)){
173 for(
int i=0; i<=maxIndex && found<=index; i++){
174 if(s.charAt(i)==
'/' || i==maxIndex){
176 strIndex[0] = strIndex[1]+1;
177 strIndex[1] = (i == maxIndex) ? i+1 : i;
181 return found>index ? s.substring(strIndex[0], strIndex[1]) : no_res;
191 int pos = s.lastIndexOf(
".");
194 part_name = s.substring(0,pos);
195 if (part_name.lastIndexOf(
".") !=-1) {
196 part_name.replace(
".",
"");
200 part_ext = s.substring(pos+1,pos+4);
205 if (part_name.length() > 8) {
208 part_name = part_name.substring(0,6);
209 part_name +=
"~" + String(index);
212 part_name.replace(
" ",
"");
214 if (part_ext.length() > 0) part_name+=
"." + part_ext;
222 tmp = get_path_part(longpath,index);
223 while (tmp.length() > 0) {
228 tmp = get_path_part(longpath,index);
236 return (512.00) * (sd_volume.clusterCount()) * (sd_volume.blocksPerCluster());
239 return (512.00) * (sd_volume.clusterCount() - sd_volume.freeClusterCount() ) * (sd_volume.blocksPerCluster());
247 if(root.isOpen())root.close();
248 if (!sd_volume.init(&(card.getSd2Card()))) {
251 if (!root.openRoot(&sd_volume)){
257 name = get_path_part(path,index);
258 while ((name.length() > 0) && (name!=
"/")) {
260 if (!newDir.open(&root, name.c_str(), O_READ)) {
266 if (index > MAX_DIR_DEPTH) {
269 name = get_path_part(path,index);
275 if ((name == NULL) || (
size==NULL)) {
282 if ((workDir.readDir(&dir_info, NULL)) > 0){
283 workDir.dirName(dir_info,name);
284 *
size = dir_info.fileSize;
285 if (DIR_IS_FILE(&dir_info))*
isFile =
true;