From d63db7bc7aad237c8351c108477aa90c47091c11 Mon Sep 17 00:00:00 2001 From: Mark Liversedge Date: Thu, 6 Oct 2011 19:00:02 +0100 Subject: [PATCH] Fix Split Ride file loss bug In some instances split ride will refuse to overwrite existing ride files (where they have the same date/time). This patch increments the start time by one (or more) seconds to ensure there is no conflict. Fixes #165. --- src/SplitRideDialog.cpp | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/src/SplitRideDialog.cpp b/src/SplitRideDialog.cpp index 441f4119a..b98d1bd17 100644 --- a/src/SplitRideDialog.cpp +++ b/src/SplitRideDialog.cpp @@ -132,9 +132,32 @@ SplitRideDialog::cancelClicked() void SplitRideDialog::CreateNewRideFile(const RideFile *ride, int nRecStart, int nRecEnd) { + // set the start time, taking care to include the offset for the interval QDateTime newStart = ride->startTime(); RideFilePoint *pointStart = ride->dataPoints().at(nRecStart); newStart = newStart.addMSecs(static_cast(pointStart->secs*1000 + 0.5)); + + QString fileName; + QString filePath; + + // adjust start time of file to avoid conflicts with existing files + int offset = 0; + QDateTime noConflicts; + do { + noConflicts = newStart.addSecs(offset); + + fileName.sprintf("%04d_%02d_%02d_%02d_%02d_%02d.gc", + noConflicts.date().year(), noConflicts.date().month(), + noConflicts.date().day(), noConflicts.time().hour(), noConflicts.time().minute(), + noConflicts.time().second()); + filePath = mainWindow->home.absolutePath() + "/" + fileName; + + offset++; + + } while (QFile(filePath).exists()); + newStart = newStart.addSecs(offset); + + // create the ridefile in memory boost::scoped_ptr newRideFile(new RideFile(newStart, ride->recIntSecs())); for (int nItem = nRecStart; nItemhome.absolutePath() + "/" + fileName; - + // should never, ever complain.. could wipe out, but lets check anyway + // it costs nothing and might save a file one day QFile file(filePath); if (file.exists()) { @@ -167,9 +185,11 @@ SplitRideDialog::CreateNewRideFile(const RideFile *ride, int nRecStart, int nRec return; } + // write to disk GcFileReader f; f.writeRideFile(newRideFile.get(), file); + // add to the ride list mainWindow->addRide(fileName, false); } void