diff --git a/tools/replay/route.cc b/tools/replay/route.cc index 301f7aba8e..c76e169e72 100644 --- a/tools/replay/route.cc +++ b/tools/replay/route.cc @@ -52,10 +52,7 @@ bool Route::loadFromCommaApi() { rInfo("invalid route format"); return false; } - - struct tm tm_time = {0}; - strptime(route_.timestamp.c_str(), "%Y-%m-%d--%H-%M-%S", &tm_time); - date_time_ = mktime(&tm_time); + date_time_ = strToTime(route_.timestamp); bool load_success = data_dir_.empty() ? loadFromServer() : loadFromLocal(); if (!load_success) { @@ -89,10 +86,21 @@ bool Route::loadFromAutoSource() { for (int i = 0; i < log_files.size(); ++i) { addFileToSegment(i, log_files[i]); } + static const std::regex pattern(R"(([a-z0-9]{16})\|(\d{4}-\d{2}-\d{2}--\d{2}-\d{2}-\d{2}))"); + std::smatch matches; + if (std::regex_search(route_string_, matches, pattern)) { + route_.str = matches[0]; + route_.dongle_id = matches[1]; + route_.timestamp = matches[2]; + date_time_ = strToTime(route_.timestamp); + } else { + route_.dongle_id = route_string_; + route_.timestamp = route_string_; + route_.str = route_string_; + } route_.begin_segment = 0; route_.end_segment = log_files.size() - 1; - route_.dongle_id = route_string_; - route_.str = route_string_; + return !segments_.empty(); } @@ -182,6 +190,12 @@ void Route::addFileToSegment(int n, const std::string &file) { } } +std::time_t Route::strToTime(const std::string ×tamp) { + struct tm tm_time = {0}; + strptime(timestamp.c_str(), "%Y-%m-%d--%H-%M-%S", &tm_time); + return mktime(&tm_time); +} + // class Segment Segment::Segment(int n, const SegmentFile &files, uint32_t flags, const std::vector &filters, diff --git a/tools/replay/route.h b/tools/replay/route.h index 21090264f5..b299ee9a65 100644 --- a/tools/replay/route.h +++ b/tools/replay/route.h @@ -58,6 +58,7 @@ protected: bool loadFromServer(int retries = 3); bool loadFromJson(const std::string &json); void addFileToSegment(int seg_num, const std::string &file); + std::time_t strToTime(const std::string ×tamp); RouteIdentifier route_ = {}; std::string data_dir_; std::map segments_;