mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-02-28 00:03:53 +08:00
* initial version
* print all message's in ncurses window
* show download progress bar
* move all to class ConsoleUI
* timeline
* improve timeline&stats
* fix logMessage
* add warning indicator
* continue
* cleanup
* cast type to int
* simplify seekToFlag
* more
* <=
* handle enter
* add box to logging window
* fix multiple threads problem
* fix concurrency issues
* draw indicator
* many improvements
* more
* fix multipe threads logging
* stop replay before exit
* use lambda instead of std::bind
* cleanup
* small cleanup
* use carFingerPrint
* don't emit signal in replay::stream
* merge car_events into timeline
* cleanup DonloadStats
* cleanup
* rename carname to carFingerprint
* improve alert
* add comments
* add help functions
templete function
* handle term resize
* display replaying status
* rename to INSTANT
* helper function pauseReplay
* more
* cleanup
use rDebug
* no template
* less colors
* remove function mv_add_str
* use BORDER_SIZE
* tune colors
* add spaces
* apply reviews
use /
old-commit-hash: 3ca8e3653b
46 lines
1.4 KiB
C++
46 lines
1.4 KiB
C++
#include "selfdrive/ui/replay/filereader.h"
|
|
|
|
#include <fstream>
|
|
|
|
#include "selfdrive/common/util.h"
|
|
#include "selfdrive/ui/replay/util.h"
|
|
|
|
std::string cacheFilePath(const std::string &url) {
|
|
static std::string cache_path = [] {
|
|
const std::string comma_cache = util::getenv("COMMA_CACHE", "/tmp/comma_download_cache/");
|
|
util::create_directories(comma_cache, 0755);
|
|
return comma_cache.back() == '/' ? comma_cache : comma_cache + "/";
|
|
}();
|
|
|
|
return cache_path + sha256(getUrlWithoutQuery(url));
|
|
}
|
|
|
|
std::string FileReader::read(const std::string &file, std::atomic<bool> *abort) {
|
|
const bool is_remote = file.find("https://") == 0;
|
|
const std::string local_file = is_remote ? cacheFilePath(file) : file;
|
|
std::string result;
|
|
|
|
if ((!is_remote || cache_to_local_) && util::file_exists(local_file)) {
|
|
result = util::read_file(local_file);
|
|
} else if (is_remote) {
|
|
result = download(file, abort);
|
|
if (cache_to_local_ && !result.empty()) {
|
|
std::ofstream fs(local_file, std::ios::binary | std::ios::out);
|
|
fs.write(result.data(), result.size());
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
std::string FileReader::download(const std::string &url, std::atomic<bool> *abort) {
|
|
for (int i = 0; i <= max_retries_ && !(abort && *abort); ++i) {
|
|
if (i > 0) rWarning("download failed, retrying %d", i);
|
|
|
|
std::string result = httpGet(url, chunk_size_, abort);
|
|
if (!result.empty()) {
|
|
return result;
|
|
}
|
|
}
|
|
return {};
|
|
}
|