Complete ring buffer and direct download support #26

This commit is contained in:
Scott E. Graves 2024-12-23 08:27:11 -06:00
parent ce1676f3d3
commit 1c2d2cd13c
2 changed files with 14 additions and 2 deletions

View File

@ -21,6 +21,8 @@
*/
#include "file_manager/direct_open_file.hpp"
#include "events/event_system.hpp"
#include "events/events.hpp"
#include "file_manager/open_file_base.hpp"
#include "providers/i_provider.hpp"
#include "types/repertory.hpp"
@ -56,6 +58,12 @@ auto direct_open_file::read(std::size_t read_size, std::uint64_t read_offset,
auto res = provider_.read_file_bytes(fsi_.api_path, read_size, read_offset,
data, stop_requested_);
if (res == api_error::success) {
auto progress = (static_cast<double>(read_offset + read_size) /
static_cast<double>(fsi_.size) * 100.0);
event_system::instance().raise<download_progress>(
fsi_.api_path, fsi_.source_path_, progress);
}
reset_timeout();
return res;

View File

@ -19,11 +19,11 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <algorithm>
#include "file_manager/ring_buffer_open_file.hpp"
#include "app_config.hpp"
#include "events/event_system.hpp"
#include "events/events.hpp"
#include "file_manager/events.hpp"
#include "file_manager/open_file_base.hpp"
#include "platform/platform.hpp"
@ -169,6 +169,10 @@ auto ring_buffer_open_file::download_chunk(std::size_t chunk, bool skip_active)
chunk_lock.lock();
if (res == api_error::success) {
auto progress = (static_cast<double>(chunk) /
static_cast<double>(total_chunks_) * 100.0);
event_system::instance().raise<download_progress>(fsi_.api_path,
source_path_, progress);
res = (chunk >= ring_begin_ && chunk <= ring_end_)
? do_io([&]() -> api_error {
std::size_t bytes_written{};