From: Torsten Dreyer Date: Fri, 24 Jun 2011 22:04:44 +0000 (+0200) Subject: Terrasync: make whitespace in pathnames work under windows X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=d36170879c9394064b37fc9acb3d12d451f2be82;p=simgear.git Terrasync: make whitespace in pathnames work under windows --- diff --git a/simgear/misc/sg_path.cxx b/simgear/misc/sg_path.cxx index 6e549f6d..20dd4fbc 100644 --- a/simgear/misc/sg_path.cxx +++ b/simgear/misc/sg_path.cxx @@ -366,3 +366,20 @@ bool SGPath::isNull() const { return path.empty() || (path == ""); } + +std::string SGPath::str_native() const +{ +#ifdef _WIN32 + std::string s = str(); + std::string::size_type pos; + std::string nativeSeparator; + nativeSeparator = sgDirPathSepBad; + + while( (pos=s.find( sgDirPathSep )) != std::string::npos ) { + s.replace( pos, 1, nativeSeparator ); + } + return s; +#else + return str(); +#endif +} diff --git a/simgear/misc/sg_path.hxx b/simgear/misc/sg_path.hxx index 69dd5944..0684d570 100644 --- a/simgear/misc/sg_path.hxx +++ b/simgear/misc/sg_path.hxx @@ -141,6 +141,11 @@ public: */ const char* c_str() const { return path.c_str(); } + /** + * Get the path string in OS native form + */ + std::string str_native() const; + /** * Determine if file exists by attempting to fopen it. * @return true if file exists, otherwise returns false. diff --git a/simgear/scene/tsync/terrasync.cxx b/simgear/scene/tsync/terrasync.cxx index 1d9bf8ea..d1162e35 100644 --- a/simgear/scene/tsync/terrasync.cxx +++ b/simgear/scene/tsync/terrasync.cxx @@ -312,7 +312,9 @@ bool SGTerraSync::SvnThread::start() return false; } -#ifdef SG_WINDOWS +#if 0 +// whitespace support should work now +//#ifdef SG_WINDOWS if ((_use_svn)&&(!use_int_svn)) { // external SVN support is used @@ -492,11 +494,20 @@ bool SGTerraSync::SvnThread::syncTreeExternal(const char* dir) if (_use_svn) { #ifdef SG_WINDOWS - // no support for white-space paths + SGPath localPath( _local_dir ); + localPath.append( dir ); + + // windows command line parsing is just lovely... + // to allow white spaces, the system call needs this: + // ""C:\Program Files\something.exe" somearg "some other arg"" + // Note: whitespace strings quoted by a pair of "" _and_ the + // entire string needs to be wrapped by "" too. + // The svn url needs forward slashes (/) as a path separator while + // the local path needs windows-native backslash as a path separator. snprintf( command, 512, - "%s %s %s/%s %s/%s", _svn_command.c_str(), svn_options, + "\"\"%s\" %s %s/%s \"%s\"\"", _svn_command.c_str(), svn_options, _svn_server.c_str(), dir, - _local_dir.c_str(), dir ); + localPath.str_native().c_str() ); #else // support white-space paths (use '"') snprintf( command, 512,