changeset 2003:434ea827d505

Creating gameDataPath() in addition to userPath(), since in installed applications in Unix systems, the data should been shared by all of the users in the system, and thus in a system-wide accessible directory. Also properly defining macPath() in this file instead of the application.{h,cpp} files (it doesn't belong in there), with the proper #include. There's a bit of redundancy between macPath() and the other two functions, although my limited knowledge about Macs doesn't allow me to go beyond here.
author mafm
date Sun, 30 Oct 2011 21:52:18 +0000
parents 7ec08c4b808e
children 4607ce4447e2
files src/core/sumwarshelper.h
diffstat 1 files changed, 51 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/src/core/sumwarshelper.h	Sun Oct 30 21:44:39 2011 +0000
+++ b/src/core/sumwarshelper.h	Sun Oct 30 21:52:18 2011 +0000
@@ -16,20 +16,49 @@
 #ifndef SUMWARSHELPER_H
 #define SUMWARSHELPER_H
 
-#include "physfs.h"
-#include "OgreString.h"
-// Return the path to where files should be stored on mac
+#include "config.h"
+
+#include <physfs.h>
+#include <OgreString.h>
+
+#if defined (__APPLE__)
+#include <CoreFoundation/CFBundle.h>
+#endif
+
 
 /**
  * \brief Helper class. Used as a namespace to store utility static functions.
  */
 class SumwarsHelper
 {
+public:
+	/**
+	 * \fn static Ogre::String gameDataPath()
+	 *
+	 * \brief Returns the path where the game data is stored (e.g.,
+	 * /usr/share/games/sumwars in Unix)
+	 */
+	static Ogre::String gameDataPath()
+	{
+		Ogre::String path = userPath();
+
+#if defined (__unix__)
+		// redefine if necessary
+		path = CFG_FILES_DIR;
+#elif defined (__APPLE__)
+		// redefine if necessary
+#elif defined (_WIN32)
+		// redefine if necessary
+#endif
+
+		return path;
+	}
+
+
 	/**
 	 * \fn static Ogre::String userPath()
 	 * \brief Returns the writable sumwars directory in the users directory
 	 */
-public:
 	static Ogre::String userPath()
 	{
 		Ogre::String path = PHYSFS_getUserDir();
@@ -45,7 +74,7 @@
 	/**
 	 * \brief Gets the updated resolution string from a base resolution string.
 	 * Purpose: manage differences between Direct3D and OpenGL resolution strings.
-	 * 
+	 *
 	 * \param initialString The source resolution string.
 	 * \param newWidth The new width to use.
 	 * \param newHeight The new height to use.
@@ -57,7 +86,7 @@
 	/**
 	 * \brief Parse a basic resolution string and get the width and height.
 	 * Purpose: manage differences between Direct3D and OpenGL resolution strings.
-	 * 
+	 *
 	 * \param initialString The source resolution string.
 	 * \param[out] newWidth The width to read.
 	 * \param[out] newHeight The height to read.
@@ -66,25 +95,25 @@
 	 */
 	static void getSizesFromResolutionString (const std::string& initialString, int& videoModeWidth, int& videoModeHeight);
 
-#ifdef __APPLE__
+#if defined (__APPLE__)
 	// TODO: copied function here from application.h; Investigate integration with userPath function.
 	// TODO: investigate removal of original function from application.h
 
-    /**
-     * \fn Ogre::String macPath()
-     * \brief Returns the path to the Resources directory on mac.
-     */
-    Ogre::String macPath()
-    {
-        Ogre::String path;
-        CFBundleRef mainBundle = CFBundleGetMainBundle();
-        CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle);
-        char resPath[PATH_MAX];
-        CFURLGetFileSystemRepresentation(resourcesURL, TRUE, (UInt8 *)resPath, PATH_MAX);
-        CFRelease(resourcesURL);
-        path = resPath;
-        return path;
-    }
+	/**
+	 * \fn Ogre::String macPath()
+	 * \brief Returns the path to the Resources directory on mac.
+	 */
+	Ogre::String macPath()
+	{
+		Ogre::String path;
+		CFBundleRef mainBundle = CFBundleGetMainBundle();
+		CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle);
+		char resPath[PATH_MAX];
+		CFURLGetFileSystemRepresentation(resourcesURL, TRUE, (UInt8 *)resPath, PATH_MAX);
+		CFRelease(resourcesURL);
+		path = resPath;
+		return path;
+	}
 #endif
 
 };