[Scummvm-cvs-logs] SF.net SVN: scummvm: [27472] scummvm/branches/gsoc2007-fsnode/base/ commandLine.cpp

david_corrales at users.sourceforge.net david_corrales at users.sourceforge.net
Sat Jun 16 19:20:46 CEST 2007


Revision: 27472
          http://scummvm.svn.sourceforge.net/scummvm/?rev=27472&view=rev
Author:   david_corrales
Date:     2007-06-16 10:20:46 -0700 (Sat, 16 Jun 2007)

Log Message:
-----------
Fixed several TODO's concerning path validation.

Modified Paths:
--------------
    scummvm/branches/gsoc2007-fsnode/base/commandLine.cpp

Modified: scummvm/branches/gsoc2007-fsnode/base/commandLine.cpp
===================================================================
--- scummvm/branches/gsoc2007-fsnode/base/commandLine.cpp	2007-06-16 17:12:08 UTC (rev 27471)
+++ scummvm/branches/gsoc2007-fsnode/base/commandLine.cpp	2007-06-16 17:20:46 UTC (rev 27472)
@@ -32,6 +32,7 @@
 
 #include "common/config-manager.h"
 #include "common/system.h"
+#include "common/fs.h"
 
 #include "sound/mididrv.h"
 #include "sound/mixer.h"
@@ -48,10 +49,6 @@
 
 #define DETECTOR_TESTING_HACK
 
-#ifdef DETECTOR_TESTING_HACK
-#include "common/fs.h"
-#endif
-
 namespace Base {
 
 static const char USAGE_STRING[] =
@@ -313,7 +310,7 @@
 	for (int i = 1; i < argc; ++i) {
 		s = argv[i];
 		s2 = (i < argc-1) ? argv[i+1] : 0;
-
+		
 		if (s[0] != '-') {
 			// The argument doesn't start with a dash, so it's not an option.
 			// Hence it must be the target name. We currently enforce that
@@ -390,7 +387,12 @@
 			END_OPTION
 
 			DO_OPTION('p', "path")
-				// TODO: Verify whether the path is valid
+				FilesystemNode path(option);
+				if(!path.exists()) {
+					usage("Non-existent game path '%s'", option);
+				} else if(!path.isReadable()) {
+					usage("Non-readable game path '%s'", option);
+				}
 			END_OPTION
 
 			DO_OPTION('q', "language")
@@ -428,7 +430,12 @@
 			END_OPTION
 
 			DO_LONG_OPTION("soundfont")
-				// TODO: Verify whether the path is valid
+				FilesystemNode path(option);
+				if(!path.exists()) {
+					usage("Non-existent soundfont path '%s'", option);
+				} else if(!path.isReadable()) {
+					usage("Non-readable soundfont path '%s'", option);
+				}
 			END_OPTION
 
 			DO_LONG_OPTION_BOOL("disable-sdl-parachute")
@@ -453,7 +460,12 @@
 			END_OPTION
 
 			DO_LONG_OPTION("savepath")
-				// TODO: Verify whether the path is valid
+				FilesystemNode path(option);
+				if(!path.exists()) {
+					usage("Non-existent savegames path '%s'", option);
+				} else if(!path.isWritable()) {
+					usage("Non-writable savegames path '%s'", option);
+				}
 			END_OPTION
 
 			DO_LONG_OPTION_INT("talkspeed")
@@ -466,7 +478,12 @@
 			END_OPTION
 
 			DO_LONG_OPTION("themepath")
-				// TODO: Verify whether the path is valid
+				FilesystemNode path(option);
+				if(!path.exists()) {
+					usage("Non-existent theme path '%s'", option);
+				} else if(!path.isReadable()) {
+					usage("Non-readable theme path '%s'", option);
+				}
 			END_OPTION
 
 			DO_LONG_OPTION("target-md5")
@@ -657,13 +674,18 @@
 	if (!settings.contains("savepath")) {
 		const char *dir = getenv("SCUMMVM_SAVEPATH");
 		if (dir && *dir && strlen(dir) < MAXPATHLEN) {
-			// TODO: Verify whether the path is valid
-			settings["savepath"] = dir;
+			FilesystemNode saveDir(dir);
+			if(!saveDir.exists()) {
+				warning("Non-existent SCUMMVM_SAVEPATH save path. It will be ignored.");
+			} else if(!saveDir.isWritable()) {
+				warning("Non-writable SCUMMVM_SAVEPATH save path. It will be ignored.");
+			} else {
+				settings["savepath"] = dir;
+			}
 		}
 	}
 #endif
 
-
 	// Finally, store the command line settings into the config manager.
 	for (Common::StringMap::const_iterator x = settings.begin(); x != settings.end(); ++x) {
 		Common::String key(x->_key);


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list