From fb95f7b74c1a4286e02b95c461bdc5068f2532e4 Mon Sep 17 00:00:00 2001
From: Stijn Buys <ingar@osirion.org>
Date: Mon, 15 Feb 2010 18:02:33 +0000
Subject: Changed screenshot naming convention to yyyyddmm-nnnn

---
 src/render/screenshot.cc | 38 +++++++++++++++++++++-----------------
 src/render/screenshot.h  |  3 ++-
 2 files changed, 23 insertions(+), 18 deletions(-)

(limited to 'src/render')

diff --git a/src/render/screenshot.cc b/src/render/screenshot.cc
index 342977a..adab01b 100644
--- a/src/render/screenshot.cc
+++ b/src/render/screenshot.cc
@@ -24,7 +24,8 @@ core::Cvar *Screenshot::screenshotformat = 0;
 core::Cvar *Screenshot::screenshotquality = 0;
 
 
-int Screenshot::number = 0;
+int Screenshot::current_number = 0;
+int Screenshot::current_date = 0;
 
 void Screenshot::save()
 {
@@ -66,36 +67,39 @@ void Screenshot::save()
 		(*screenshotformat) = "tga";
 	}
 
-	// find the first available screenshots/osirion-yyyymmdd-hhmm-xxxx.ext
+	// check if the date has changed since the previous screenshot;
 	std::stringstream filenamestr;
 	int day, month, year, hour, min;
+	int date_serial;
 
 	sys::get_datetime(year, month, day, hour, min);
-
-	filenamestr << filesystem::writedir() << "screenshots/osirion" << '-';
-	// date
-	filenamestr << std::setfill('0') << std::setw(4) << year << std::setw(2) << month << std::setw(2) << day << '-';
-	// time
-	filenamestr << std::setfill('0') << std::setw(2) << hour << std::setw(2) << min << '-';
+	date_serial = (day - 1) + (month - 1) * 31 + (year - 2000) * 31 * 12;
+	if (current_date != date_serial) {
+		current_number = 0;
+		current_date = date_serial;
+	}
 
 	do {
-		std::stringstream nstr;
-		nstr << std::setw(4) << std::setfill('0') << number;
-
+		std::stringstream filenamestr;
+		// screenshots directory
+		filenamestr << filesystem::writedir() << "screenshots/";
+		// date
+		filenamestr << std::setw(4) << std::setfill('0') << year << "-";
+		filenamestr << std::setw(2) << month << "-";
+		filenamestr << std::setw(2) << day << '-';
 		// sequence number
-		filename.assign(filenamestr.str());
-		filename.append(nstr.str());
+		filenamestr << std::setw(4) << std::setfill('0') << current_number;
 		// extension
-		filename.append(".");
-		filename.append(screenshotformat->str());
+		filenamestr << "." << screenshotformat->str();
 
-		FILE *handle = fopen(filename.c_str(), "r");
+		// try to open the file
+		FILE *handle = fopen(filenamestr.str().c_str(), "r");
 		if (handle) {
 			fclose(handle);
 		} else {
 			available = true;
 		}
-		number++;
+		current_number++;
 	} while (!available);
 
 	render::Image image(State::width(), State::height(), 3);
diff --git a/src/render/screenshot.h b/src/render/screenshot.h
index 4be57fa..5c0e22c 100644
--- a/src/render/screenshot.h
+++ b/src/render/screenshot.h
@@ -21,7 +21,8 @@ public:
 	static core::Cvar *screenshotquality;
 
 private:
-	static int number;
+	static int current_number;
+	static int current_date;
 };
 
 } // namespace render
-- 
cgit v1.2.3