Diffstat (limited to 'noncore/settings/networksettings2/networksettings2/systemfile.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/networksettings2/networksettings2/systemfile.cpp | 70 |
1 files changed, 58 insertions, 12 deletions
diff --git a/noncore/settings/networksettings2/networksettings2/systemfile.cpp b/noncore/settings/networksettings2/networksettings2/systemfile.cpp index 2b40834..82fd43a 100644 --- a/noncore/settings/networksettings2/networksettings2/systemfile.cpp +++ b/noncore/settings/networksettings2/networksettings2/systemfile.cpp @@ -13,12 +13,13 @@ QString TemplDir; SystemFile::SystemFile( const QString & N, const QString & P, bool KDI ){ Name = N; Path = P; + InAppend = 0; F = 0; // get template info { QString S; QFileInfo FI; // find location of templates @@ -60,43 +61,88 @@ SystemFile::SystemFile( const QString & N, hasPostDeviceSection = ( FI.exists() && FI.isReadable() ); } KnowsDeviceInstances = KDI; } +SystemFile::SystemFile( const QString & N, bool KDI ){ + Name = N; + Path = ""; + InAppend = 0; + F =0; + KnowsDeviceInstances = KDI; + hasPreSection = + hasPostSection = + hasPreNodeSection = + hasPostNodeSection = + hasPreDeviceSection = + hasPostDeviceSection = 0; +} + SystemFile::~SystemFile( void ) { - if( F ) - delete F; + close(); } bool SystemFile::open( void ) { - if( F ) { - F->close(); - delete F; - } + QString Prefix = getenv( "NS2OUTPUTTO" ); + + if( Prefix != "stderr" /* && Name != "interfaces" */ ) { + // generate files where the need to be + if( F ) { + F->close(); + delete F; + } - F = new QFile( Path + "bup" ); - if( ! F->open( IO_WriteOnly ) ) { - return 0; + F = new QFile( Prefix + Path + ((InAppend)?"":"bup") ); + Log(( "Open systemfile %s\n", F->name().latin1() )); + if( ! F->open( ((InAppend)?IO_Append : 0 ) | IO_WriteOnly ) ) { + return 0; + } + } else { + if( ! F ) { + owarn << "!!!!!!!!!!!!!!!!!! " << oendl; + owarn << "!!!! TESTMODE !!!!" << oendl; + owarn << "!!!!!!!!!!!!!!!!!! " << oendl; + owarn << "!!!!" << oendl; + owarn << "!!!! GENERATE " << Path << oendl; + if( InAppend ) { + owarn << "!!!! In APPEND mode" << oendl; + } + owarn << "!!!!" << oendl; + owarn << "!!!!!!!!!!!!!!!!!!" << oendl; + + F = new QFile(); + F->open( IO_WriteOnly, stderr ); + } } setDevice( F ); return 1; } bool SystemFile::close( void ) { - if( ! F ) { + if( ! F || ! F->isOpen() ) { return 1 ; } - QString OldP = Path + "bup"; + QString Prefix = getenv( "NS2OUTPUTTO" ); + + if( Prefix == "stderr" ) { + return 1; + } + + QString OldP = Prefix + Path + "bup"; F->close(); delete F; F = 0; - return ( rename( OldP.latin1(), Path.latin1() ) >= 0 ); + if( ! InAppend ) { + owarn << "Rename " << OldP << " to " << Path << oendl; + return ( rename( OldP.latin1(), Path.latin1() ) >= 0 ); + } + return 1; } bool SystemFile::preSection( void ) { if( hasPreSection ) { QFile Fl( TemplDir + Name + "/presection" ); if( ! Fl.open( IO_ReadOnly ) ) |