| 165 | } |
| 166 | |
| 167 | bool PersistenceManager::readFile(const char* fileName) |
| 168 | { |
| 169 | // Clear our previous file buffers just in |
| 170 | // case saveDirtyFile() didn't catch it |
| 171 | clearFileData(); |
| 172 | |
| 173 | // Handle an object writing out to a new file |
| 174 | if ( !Torque::FS::IsFile( fileName ) ) |
| 175 | { |
| 176 | // Set our current file |
| 177 | mCurrentFile = dStrdup(fileName); |
| 178 | |
| 179 | return true; |
| 180 | } |
| 181 | |
| 182 | // Try to open the file |
| 183 | FileStream stream; |
| 184 | stream.open( fileName, Torque::FS::File::Read ); |
| 185 | |
| 186 | if ( stream.getStatus() != Stream::Ok ) |
| 187 | { |
| 188 | Con::errorf("PersistenceManager::readFile() - Failed to open %s", fileName); |
| 189 | |
| 190 | return false; |
| 191 | } |
| 192 | |
| 193 | // The file is good so read it in |
| 194 | mCurrentFile = dStrdup(fileName); |
| 195 | |
| 196 | while(stream.getStatus() != Stream::EOS) |
| 197 | { |
| 198 | U8* buffer = ( U8* ) dMalloc( 2048 ); |
| 199 | dMemset(buffer, 0, 2048); |
| 200 | |
| 201 | stream.readLine(buffer, 2048); |
| 202 | |
| 203 | mLineBuffer.push_back((const char*)buffer); |
| 204 | } |
| 205 | |
| 206 | // Because of the way that writeLine() works we need to |
| 207 | // make sure we don't have an empty last line or else |
| 208 | // we will get an extra line break |
| 209 | if (mLineBuffer.size() > 0) |
| 210 | { |
| 211 | if (mLineBuffer.last() && mLineBuffer.last()[0] == 0) |
| 212 | { |
| 213 | dFree(mLineBuffer.last()); |
| 214 | |
| 215 | mLineBuffer.pop_back(); |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | stream.close(); |
| 220 | |
| 221 | //Con::printf("Successfully opened and read %s", mCurrentFile); |
| 222 | |
| 223 | return true; |
| 224 | } |
nothing calls this directly
no test coverage detected