diff --git a/src_main/io/pibinarylog.cpp b/src_main/io/pibinarylog.cpp index 61318375..c49b1d2a 100644 --- a/src_main/io/pibinarylog.cpp +++ b/src_main/io/pibinarylog.cpp @@ -87,8 +87,10 @@ bool PIBinaryLog::openDevice() { if (ld.isExists()) { PIVector es = ld.allEntries(); piForeachC(PIFile::FileInfo &i, es) { - if (i.extension() == "binlog" && i.isFile()) + if (i.extension() == "binlog" && i.isFile() && i.baseName().startsWith(filePrefix())) { setPath(i.path); + piBreak; + } } } } @@ -120,7 +122,7 @@ bool PIBinaryLog::openDevice() { fileEnd(); } play_time = 0; - if (!rapidStart()) is_started = true; + if (!rapid_start) is_started = true; } startlogtime = PISystemTime::current(); pause_time = PISystemTime(); @@ -531,6 +533,30 @@ PIBinaryLog::BinLogInfo PIBinaryLog::getLogInfo(const PIString & path) { } +bool PIBinaryLog::cutBinLog(const PIBinaryLog::BinLogInfo & src, const PIString & dst, int from, int to) { + PIBinaryLog slog; + if (!slog.open(src.path, PIIODevice::ReadOnly)) return false; + PIVector ids = src.records.keys(); + slog.seekTo(from); + PIBinaryLog dlog; + dlog.createNewFile(dst); + bool first = true; + BinLogRecord br; + PISystemTime st; + while (!slog.isEnd() && ((slog.pos() <= to) || to < 0)) { + br = slog.readRecord(); + if (first) { + st = br.timestamp; + first = false; + } + if (ids.contains(br.id)) { + dlog.writeBinLog_raw(br.id, br.timestamp - st, br.data); + } + } + return true; +} + + PIString PIBinaryLog::constructFullPathDevice() const { PIString ret; ret << logDir() << ":" << filePrefix() << ":" << defaultID() << ":"; diff --git a/src_main/io/pibinarylog.h b/src_main/io/pibinarylog.h index 4c474df5..1f45e6c9 100644 --- a/src_main/io/pibinarylog.h +++ b/src_main/io/pibinarylog.h @@ -266,6 +266,7 @@ public: //! Get binlog info and statistic static BinLogInfo getLogInfo(const PIString & path); + static bool cutBinLog(const BinLogInfo & src, const PIString & dst, int from, int to); protected: PIString fullPathPrefix() const {return PIStringAscii("binlog");}