[chronojump] Done paths for user multimedia



commit f58691c81bd3fb239cb0ca35d07fabe9e01b59e8
Author: Xavier de Blas <xaviblas gmail com>
Date:   Fri Feb 4 13:19:19 2011 +0100

    Done paths for user multimedia

 src/chronojump.cs         |    3 ++
 src/constants.cs          |   21 ++++++++++++-
 src/gui/chronojump.cs     |   11 ++++++-
 src/sqlite/main.cs        |   20 ++++++++++--
 src/sqlite/preferences.cs |    2 +
 src/util.cs               |   71 +++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 121 insertions(+), 7 deletions(-)
---
diff --git a/src/chronojump.cs b/src/chronojump.cs
index f69feb1..672387d 100644
--- a/src/chronojump.cs
+++ b/src/chronojump.cs
@@ -140,6 +140,9 @@ public class ChronoJump
 
 		Log.WriteLine(string.Format("Chronojump version: {0}", progVersion));
 
+		//to store user videos and photos
+		Util.CreateMultimediaDirsIfNeeded();
+		
 		//move database to new location if chronojump version is before 0.7
 		moveDatabaseToNewLocationIfNeeded();
 
diff --git a/src/constants.cs b/src/constants.cs
index 982b865..d81f3c3 100644
--- a/src/constants.cs
+++ b/src/constants.cs
@@ -53,7 +53,7 @@ public class Constants
 	public const string IeIndexFormula = "IE (cmj-sj)/sj *100";
 	public const string IubIndexFormula = "IUB (abk-cmj)/cmj *100";
 
-	//tests types
+	//tests types (dont' use character '-' will be used multimedia file names)
 	public enum TestTypes { JUMP, JUMP_RJ, RUN, RUN_I, RT, PULSE, MULTICHRONOPIC }
 	public static string JumpSimpleName = "Jump simple";
 	public static string JumpReactiveName = "Jump reactive";
@@ -458,5 +458,22 @@ public class Constants
 	}
 	
 	public const string PrefVersionAvailable = "versionAvailable";
-
+	
+	/*
+	MultimediaStorage
+	BYSESSION samples:
+	Chronojump/multimedia/videos/sessionID/JUMP-jumpID
+	Chronojump/multimedia/photos/sessionID/RUN_I-runIntervalID
+	//see Constants.TestTypes 
+	*/
+	public enum MultimediaStorage {
+		BYSESSION
+	}
+	
+	public enum MultimediaItems {
+		PHOTO, VIDEO
+	}
+	public const string ExtensionVideo = ".avi";
+	public const string ExtensionPhoto = ".jpg";
+	
 }
diff --git a/src/gui/chronojump.cs b/src/gui/chronojump.cs
index f5592b8..3f191d6 100644
--- a/src/gui/chronojump.cs
+++ b/src/gui/chronojump.cs
@@ -2154,7 +2154,16 @@ public class ChronoJumpWindow
 		CapturerBin capturer = new CapturerBin();
 		CapturePropertiesStruct s = new CapturePropertiesStruct();
 
-		s.OutputFile = "/tmp/test_longomatch_is_very_cool.avi";
+		//s.OutputFile = "/tmp/test_longomatch_is_very_cool.avi";
+		
+		Util.CreateMultimediaSessionDirIfNeeded(Constants.MultimediaItems.VIDEO, 111);
+		s.OutputFile = Util.GetMultimediaFileName(
+			Constants.MultimediaItems.VIDEO,
+			111, //sessionID
+			Constants.TestTypes.JUMP,
+			123 //jump uniqueID
+			);
+
 		s.VideoBitrate =  1000;
 		s.CaptureSourceType = CaptureSourceType.Raw;
 		s.Width = 360;
diff --git a/src/sqlite/main.cs b/src/sqlite/main.cs
index 69e67df..d0fdff8 100644
--- a/src/sqlite/main.cs
+++ b/src/sqlite/main.cs
@@ -72,7 +72,7 @@ class Sqlite
 	 * Important, change this if there's any update to database
 	 * Important2: if database version get numbers higher than 1, check if the comparisons with currentVersion works ok
 	 */
-	static string lastChronojumpDatabaseVersion = "0.78";
+	static string lastChronojumpDatabaseVersion = "0.79";
 
 	public Sqlite() {
 	}
@@ -1023,19 +1023,30 @@ class Sqlite
 			}
 			if(currentVersion == "0.77") {
 				dbcon.Open();
-				
+
 				SqliteJumpType.UpdateOther ("weight", Constants.TakeOffWeightName, "1"); 
 
 				Random rnd = new Random();
 				string machineID = rnd.Next().ToString();
 				SqlitePreferences.Insert ("machineID", machineID); 
-				
+
 				SqlitePreferences.Update ("databaseVersion", "0.78", true); 
 				Log.WriteLine("Converted DB to 0.78 (Added machineID to preferences, takeOffWeight has no weight in db conversions since 0.66)"); 
-				
+
 				dbcon.Close();
 				currentVersion = "0.78";
 			}
+			if(currentVersion == "0.78") {
+				dbcon.Open();
+
+				SqlitePreferences.Insert ("multimediaStorage", Constants.MultimediaStorage.BYSESSION.ToString());
+
+				SqlitePreferences.Update ("databaseVersion", "0.79", true); 
+				Log.WriteLine("Converted DB to 0.79 (Added multimediaStorage structure id)"); 
+
+				dbcon.Close();
+				currentVersion = "0.79";
+			}
 		}
 
 		//if changes are made here, remember to change also in CreateTables()
@@ -1168,6 +1179,7 @@ class Sqlite
 		SqliteCountry.initialize();
 		
 		//changes [from - to - desc]
+		//0.78 - 0.79 Converted DB to 0.79 (Added multimediaStorage structure id)
 		//0.77 - 0.78 Converted DB to 0.78 (Added machineID to preferences, takeOffWeight has no weight in db conversions since 0.66)
 		//0.76 - 0.77 Converted DB to 0.77 (person77, personSession77)
 		//0.75 - 0.76 Converted DB to 0.76 (jump & jumpRj falls as double)
diff --git a/src/sqlite/preferences.cs b/src/sqlite/preferences.cs
index c0f38b1..7d2a175 100644
--- a/src/sqlite/preferences.cs
+++ b/src/sqlite/preferences.cs
@@ -65,6 +65,8 @@ class SqlitePreferences : Sqlite
 		Random rnd = new Random();
 		string machineID = rnd.Next().ToString();
 		Insert ("machineID", machineID);
+		
+		Insert ("multimediaStorage", Constants.MultimediaStorage.BYSESSION.ToString());
 	}
 
 	public static void Insert(string myName, string myValue)
diff --git a/src/util.cs b/src/util.cs
index 38e7ea8..1e8ddac 100644
--- a/src/util.cs
+++ b/src/util.cs
@@ -681,6 +681,76 @@ public class Util
 		return Path.Combine(Path.GetTempPath(), "Chronojump");
 	}
 
+	
+	/********** start of multimedia paths ************/
+
+	public static string GetMultimediaDir() {
+		return Path.Combine(
+				Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
+				"Chronojump" + Path.DirectorySeparatorChar + "multimedia");
+	}
+	
+	public static string GetPhotosDir() {
+		return Path.Combine(
+				Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
+				"Chronojump" + Path.DirectorySeparatorChar + "multimedia" +
+				Path.DirectorySeparatorChar + "photos");
+	}
+	
+	public static string GetVideosDir() {
+		return Path.Combine(
+				Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
+				"Chronojump" + Path.DirectorySeparatorChar + "multimedia" +
+				Path.DirectorySeparatorChar + "videos");
+	}
+	
+	public static string GetMultimediaSessionDir (Constants.MultimediaItems multimediaItem, int sessionID) {
+		string dir = "";
+		if(multimediaItem == Constants.MultimediaItems.VIDEO)
+			dir = GetVideosDir();
+		else //multimediaItem = Constants.MultimediaItems.PHOTO
+			dir = GetPhotosDir();
+
+		return dir + Path.DirectorySeparatorChar + sessionID.ToString();
+	}
+	
+	//to store user videos and photos
+	public static void CreateMultimediaDirsIfNeeded () {
+		string [] dirs = { GetMultimediaDir(), GetPhotosDir(), GetVideosDir() }; 
+		foreach (string d in dirs) {
+			if( ! Directory.Exists(d)) {
+				Directory.CreateDirectory (d);
+				Log.WriteLine (string.Format("created dir: {0}", d));
+			}
+		}
+	}
+	
+	public static void CreateMultimediaSessionDirIfNeeded (Constants.MultimediaItems multimediaItem, int sessionID) {
+		string sessionDir = GetMultimediaSessionDir(multimediaItem, sessionID);
+		if( ! Directory.Exists(sessionDir)) {
+			Directory.CreateDirectory (sessionDir);
+			Log.WriteLine (string.Format("created dir: {0}", sessionDir));
+		}
+	}
+
+	public static string GetMultimediaFileName (Constants.MultimediaItems multimediaItem, 
+			int sessionID, Constants.TestTypes testType, int uniqueID) {
+		
+		return GetMultimediaSessionDir(multimediaItem, sessionID) + Path.DirectorySeparatorChar + 
+			testType.ToString() + "-" + uniqueID.ToString() + GetMultimediaExtension(multimediaItem);
+	}
+	
+	public static string GetMultimediaExtension (Constants.MultimediaItems multimediaItem) {
+		if(multimediaItem == Constants.MultimediaItems.VIDEO)
+			return Constants.ExtensionVideo;
+		else //multimediaItem = Constants.MultimediaItems.PHOTO
+			return Constants.ExtensionPhoto;
+	}
+
+
+	/********** end of multimedia paths ************/
+	
+
 	public static string GetManualDir() {
 		//we are on:
 		//lib/chronojump/ (Unix) or bin/ (win32)
@@ -730,6 +800,7 @@ public class Util
 			Log.WriteLine("Error, chronojump.db file doesn't exist!");
 		}
 	}
+	
 
 	public static void RunRScript(string rScript){
 		ProcessStartInfo pinfo;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]