From d4bacf93cd61d80af8b1507c016f9fcd2c331680 Mon Sep 17 00:00:00 2001 From: Don BURNS Date: Tue, 24 Jan 2006 17:43:53 +0000 Subject: [PATCH] Changes to zip and tgz plug-ins to allow for use of TEMP variable on Windows. Submitted by Zach Deedler --- src/osgPlugins/tgz/ReaderWriterTGZ.cpp | 22 +++++++++++++--------- src/osgPlugins/zip/ReaderWriterZIP.cpp | 16 ++++++++++++---- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/osgPlugins/tgz/ReaderWriterTGZ.cpp b/src/osgPlugins/tgz/ReaderWriterTGZ.cpp index 096e4cc37..a32d319f4 100644 --- a/src/osgPlugins/tgz/ReaderWriterTGZ.cpp +++ b/src/osgPlugins/tgz/ReaderWriterTGZ.cpp @@ -50,12 +50,18 @@ class ReaderWriterTGZ : public osgDB::ReaderWriter char command[1024]; #if defined(_WIN32) && !defined(__CYGWIN__) - strcpy(dirname, "C:/Windows/Temp/.osgdb_tgz"); + if ( getenv("TEMP") != NULL ){ + strcpy(dirname, getenv("TEMP")); + }else{ + //TEMP environment variable not set so pick current directory. + strcpy(dirname, "./"); + } + strcat(dirname, ".osgdb_tgz"); mkdir( dirname); - // note, the following C option under windows does not seem to work... - // will pursue an better tar.exe later. RO. + // Using tar.exe from http://www.cygwin.com/ + // tar.exe must be in your path. (PATH environment variable). sprintf( command, - "tar xfz %s %s", + "tar xfCz \"%s\" \"%s\"", fileName.c_str(), dirname ); #endif @@ -113,14 +119,12 @@ class ReaderWriterTGZ : public osgDB::ReaderWriter osgDB::Registry::instance()->setCreateNodeFromImage(prevCreateNodeFromImage); #if defined(_WIN32) && !defined(__CYGWIN__) - // note, is this the right command for windows? - // is there any way of overiding the Y/N option? RO. - sprintf( command, "erase %s", dirname ); - system( command ); + sprintf( command, "erase /F /Q /S \"%s\"", dirname ); #else sprintf( command, "rm -rf %s", dirname ); - system( command ); #endif + osg::notify(osg::NOTICE)<<"Running command '"<getNumChildren() == 0 ) { diff --git a/src/osgPlugins/zip/ReaderWriterZIP.cpp b/src/osgPlugins/zip/ReaderWriterZIP.cpp index bab820254..3512b7380 100644 --- a/src/osgPlugins/zip/ReaderWriterZIP.cpp +++ b/src/osgPlugins/zip/ReaderWriterZIP.cpp @@ -44,14 +44,21 @@ class ReaderWriterZIP : public osgDB::ReaderWriter char command[1024]; #if defined(WIN32) && !defined(__CYGWIN__) - strcpy(dirname, getenv("TEMP")); + if ( getenv("TEMP") != NULL ){ + strcpy(dirname, getenv("TEMP")); + }else{ + //TEMP environment variable not set so pick current directory. + strcpy(dirname, "./"); + } strcat(dirname, "\\.osgdb_zip"); mkdir(dirname); + // Using unzip.exe from http://www.info-zip.org/pub/infozip/UnZip.html + // unzip.exe must be in your path. (PATH environment variable). sprintf( command, - "unzip -o -qq %s -d %s", + "unzip -o -qq \"%s\" -d \"%s\"", fileName.c_str(), dirname); - + osg::notify(osg::NOTICE)<<"Running command '"< local_options = options ? static_cast(options->clone(osg::CopyOp::SHALLOW_COPY)) : new osgDB::ReaderWriter::Options; local_options->getDatabasePathList().push_front(dirname); + // deactivate the automatic generation of images to geode's. bool prevCreateNodeFromImage = osgDB::Registry::instance()->getCreateNodeFromImage(); osgDB::Registry::instance()->setCreateNodeFromImage(false); @@ -93,7 +101,7 @@ class ReaderWriterZIP : public osgDB::ReaderWriter #if defined(WIN32) && !defined(__CYGWIN__) // note, is this the right command for windows? // is there any way of overiding the Y/N option? RO. - sprintf( command, "erase /S /Q %s", dirname ); + sprintf( command, "erase /S /Q \"%s\"", dirname ); system( command ); #else