** Function name: pasteFile ** Description: paste file to new folder ***************************************************************************************/
| 157 | ** Description: paste file to new folder |
| 158 | ***************************************************************************************/ |
| 159 | bool pasteFile(String path) { |
| 160 | // Tamanho do buffer para leitura/escrita |
| 161 | const size_t bufferSize = 2048 * 2; // Ajuste conforme necessário para otimizar a performance |
| 162 | uint8_t buffer[bufferSize]; |
| 163 | |
| 164 | // Abrir o arquivo original |
| 165 | File sourceFile = SDM.open(fileToCopy, FILE_READ); |
| 166 | if (!sourceFile) { |
| 167 | // Serial.println("Falha ao abrir o arquivo original para leitura"); |
| 168 | return false; |
| 169 | } |
| 170 | |
| 171 | // Criar o arquivo de destino |
| 172 | File destFile = |
| 173 | SDM.open(path + "/" + fileToCopy.substring(fileToCopy.lastIndexOf('/') + 1), FILE_WRITE, true); |
| 174 | if (!destFile) { |
| 175 | // Serial.println("Falha ao criar o arquivo de destino"); |
| 176 | sourceFile.close(); |
| 177 | return false; |
| 178 | } |
| 179 | |
| 180 | // Ler dados do arquivo original e escrever no arquivo de destino |
| 181 | size_t bytesRead; |
| 182 | int tot = sourceFile.size(); |
| 183 | int prog = 0; |
| 184 | // tft->drawRect(5,tftHeight-12, (tftWidth-10), 9, FGCOLOR); |
| 185 | while ((bytesRead = sourceFile.read(buffer, bufferSize)) > 0) { |
| 186 | if (destFile.write(buffer, bytesRead) != bytesRead) { |
| 187 | // Serial.println("Falha ao escrever no arquivo de destino"); |
| 188 | sourceFile.close(); |
| 189 | destFile.close(); |
| 190 | return false; |
| 191 | } else { |
| 192 | prog += bytesRead; |
| 193 | float rad = (tot > 0) ? (360.0f * prog / tot) : 0.0f; |
| 194 | tft->drawArc(tftWidth / 2, tftHeight / 2, tftHeight / 4, tftHeight / 5, 0, int(rad), ALCOLOR); |
| 195 | // tft->fillRect(7,tftHeight-10, (tftWidth-14)*prog/tot, 5, FGCOLOR); |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | // Fechar ambos os arquivos |
| 200 | sourceFile.close(); |
| 201 | destFile.close(); |
| 202 | return true; |
| 203 | } |
| 204 | |
| 205 | /*************************************************************************************** |
| 206 | ** Function name: createFolder |