summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings2/networksettings2/systemfile.cpp
Unidiff
Diffstat (limited to 'noncore/settings/networksettings2/networksettings2/systemfile.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings2/networksettings2/systemfile.cpp70
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;
13 13
14SystemFile::SystemFile( const QString & N, 14SystemFile::SystemFile( const QString & N,
15 const QString & P, 15 const QString & P,
16 bool KDI ){ 16 bool KDI ){
17 Name = N; 17 Name = N;
18 Path = P; 18 Path = P;
19 InAppend = 0;
19 F = 0; 20 F = 0;
20 // get template info 21 // get template info
21 { QString S; 22 { QString S;
22 QFileInfo FI; 23 QFileInfo FI;
23 24
24 // find location of templates 25 // find location of templates
@@ -60,43 +61,88 @@ SystemFile::SystemFile( const QString & N,
60 hasPostDeviceSection = ( FI.exists() && FI.isReadable() ); 61 hasPostDeviceSection = ( FI.exists() && FI.isReadable() );
61 } 62 }
62 63
63 KnowsDeviceInstances = KDI; 64 KnowsDeviceInstances = KDI;
64} 65}
65 66
67SystemFile::SystemFile( const QString & N, bool KDI ){
68 Name = N;
69 Path = "";
70 InAppend = 0;
71 F =0;
72 KnowsDeviceInstances = KDI;
73 hasPreSection =
74 hasPostSection =
75 hasPreNodeSection =
76 hasPostNodeSection =
77 hasPreDeviceSection =
78 hasPostDeviceSection = 0;
79}
80
66SystemFile::~SystemFile( void ) { 81SystemFile::~SystemFile( void ) {
67 if( F ) 82 close();
68 delete F;
69} 83}
70 84
71bool SystemFile::open( void ) { 85bool SystemFile::open( void ) {
72 if( F ) { 86 QString Prefix = getenv( "NS2OUTPUTTO" );
73 F->close(); 87
74 delete F; 88 if( Prefix != "stderr" /* && Name != "interfaces" */ ) {
75 } 89 // generate files where the need to be
90 if( F ) {
91 F->close();
92 delete F;
93 }
76 94
77 F = new QFile( Path + "bup" ); 95 F = new QFile( Prefix + Path + ((InAppend)?"":"bup") );
78 if( ! F->open( IO_WriteOnly ) ) { 96 Log(( "Open systemfile %s\n", F->name().latin1() ));
79 return 0; 97 if( ! F->open( ((InAppend)?IO_Append : 0 ) | IO_WriteOnly ) ) {
98 return 0;
99 }
100 } else {
101 if( ! F ) {
102 owarn << "!!!!!!!!!!!!!!!!!! " << oendl;
103 owarn << "!!!! TESTMODE !!!!" << oendl;
104 owarn << "!!!!!!!!!!!!!!!!!! " << oendl;
105 owarn << "!!!!" << oendl;
106 owarn << "!!!! GENERATE " << Path << oendl;
107 if( InAppend ) {
108 owarn << "!!!! In APPEND mode" << oendl;
109 }
110 owarn << "!!!!" << oendl;
111 owarn << "!!!!!!!!!!!!!!!!!!" << oendl;
112
113 F = new QFile();
114 F->open( IO_WriteOnly, stderr );
115 }
80 } 116 }
81 setDevice( F ); 117 setDevice( F );
82 return 1; 118 return 1;
83} 119}
84 120
85bool SystemFile::close( void ) { 121bool SystemFile::close( void ) {
86 if( ! F ) { 122 if( ! F || ! F->isOpen() ) {
87 return 1 ; 123 return 1 ;
88 } 124 }
89 125
90 QString OldP = Path + "bup"; 126 QString Prefix = getenv( "NS2OUTPUTTO" );
127
128 if( Prefix == "stderr" ) {
129 return 1;
130 }
131
132 QString OldP = Prefix + Path + "bup";
91 133
92 F->close(); 134 F->close();
93 delete F; 135 delete F;
94 F = 0; 136 F = 0;
95 137
96 return ( rename( OldP.latin1(), Path.latin1() ) >= 0 ); 138 if( ! InAppend ) {
139 owarn << "Rename " << OldP << " to " << Path << oendl;
140 return ( rename( OldP.latin1(), Path.latin1() ) >= 0 );
141 }
142 return 1;
97} 143}
98 144
99bool SystemFile::preSection( void ) { 145bool SystemFile::preSection( void ) {
100 if( hasPreSection ) { 146 if( hasPreSection ) {
101 QFile Fl( TemplDir + Name + "/presection" ); 147 QFile Fl( TemplDir + Name + "/presection" );
102 if( ! Fl.open( IO_ReadOnly ) ) 148 if( ! Fl.open( IO_ReadOnly ) )