mirror of
https://github.com/eried/portapack-mayhem.git
synced 2025-06-29 17:17:28 -04:00
IQ Trim app and Capture auto-trim (#1456)
* Add IQ Trim app WIP * Add 'trim' checkbox to capture * Implement trimming * Finish auto-trim * Stray //
This commit is contained in:
parent
070eb4003e
commit
ef03f020ce
11 changed files with 537 additions and 51 deletions
|
@ -279,6 +279,46 @@ std::vector<std::filesystem::path> scan_root_directories(const std::filesystem::
|
|||
return directory_list;
|
||||
}
|
||||
|
||||
std::filesystem::filesystem_error trim_file(const std::filesystem::path& file_path, uint64_t start, uint64_t length) {
|
||||
constexpr size_t buffer_size = std::filesystem::max_file_block_size;
|
||||
uint8_t buffer[buffer_size];
|
||||
auto temp_path = file_path + u"-tmp";
|
||||
|
||||
/* Scope for File instances. */
|
||||
{
|
||||
File src;
|
||||
File dst;
|
||||
|
||||
auto error = src.open(file_path);
|
||||
if (error) return error.value();
|
||||
|
||||
error = dst.create(temp_path);
|
||||
if (error) return error.value();
|
||||
|
||||
src.seek(start);
|
||||
auto remaining = length;
|
||||
|
||||
while (true) {
|
||||
auto result = src.read(buffer, buffer_size);
|
||||
if (result.is_error()) return result.error();
|
||||
|
||||
auto to_write = std::min(remaining, *result);
|
||||
|
||||
result = dst.write(buffer, to_write);
|
||||
if (result.is_error()) return result.error();
|
||||
|
||||
remaining -= *result;
|
||||
|
||||
if (*result < buffer_size || remaining == 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Delete original and overwrite with temp file.
|
||||
delete_file(file_path);
|
||||
return rename_file(temp_path, file_path);
|
||||
}
|
||||
|
||||
std::filesystem::filesystem_error delete_file(const std::filesystem::path& file_path) {
|
||||
return {f_unlink(reinterpret_cast<const TCHAR*>(file_path.c_str()))};
|
||||
}
|
||||
|
@ -292,8 +332,7 @@ std::filesystem::filesystem_error rename_file(
|
|||
std::filesystem::filesystem_error copy_file(
|
||||
const std::filesystem::path& file_path,
|
||||
const std::filesystem::path& dest_path) {
|
||||
// 512 seems to be the largest block size FatFS likes.
|
||||
constexpr size_t buffer_size = 512;
|
||||
constexpr size_t buffer_size = std::filesystem::max_file_block_size;
|
||||
uint8_t buffer[buffer_size];
|
||||
File src;
|
||||
File dst;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue