std::string FileSystem::read(const std::string & saveFile) { int r = mMemblockDevice.LoadFromFile(saveFile); if (r == -1) return "File not found.\n"; Directory* temp = new Directory; temp->Read(&mMemblockDevice, r); if (r == -1) return "Error"; delete mCurrDir; mCurrDir = temp; system("cls"); return "State loaded.\n"; }
std::string FileSystem::rename(const std::string & source, const std::string & newName) { int r = mCurrDir->GetChildFile(&mMemblockDevice, source); if (r != -1) { File file; file.Read(&mMemblockDevice, r); file.SetName(&mMemblockDevice, newName); return ""; } r = mCurrDir->GetChildDir(&mMemblockDevice, source); if (r != -1) { Directory dir; dir.Read(&mMemblockDevice, r); dir.SetName(&mMemblockDevice, newName); return ""; } return "No such file or directory.\n"; }
bool Directory::Read ( istream &input ) { // // Start marker char marker[DIRECTORY_MARKERSIZE]; input.read( marker, DIRECTORY_MARKERSIZE ); if( strncmp( marker, DIRECTORY_MARKERSTART, DIRECTORY_MARKERSIZE ) != 0 ) { return false; } // // Our own information if ( m_name ) { delete[] m_name; m_name = NULL; } m_name = ReadDynamicString( input, DIRECTORY_MAXSTRINGLENGTH, DIRECTORY_SAFESTRING ); // // Our data // Indexes are not important and can be forgotten int numUsed = ReadPackedInt(input); if( numUsed < 0 || numUsed > DIRECTORY_MAXDIRSIZE ) { return false; } for ( int d = 0; d < numUsed; ++d ) { DirectoryData *data = new DirectoryData(); if (!data->Read( input )) { AppDebugOut("Warning: failed to read directory data from stream\n"); delete data; return false; } m_data.PutData( data ); } // // Our subdirectories int numSubdirs = ReadPackedInt( input ); if( numUsed < 0 || numUsed > DIRECTORY_MAXDIRSIZE ) { return false; } for ( int s = 0; s < numSubdirs; ++s ) { Directory *newDir = new Directory(); if( !newDir->Read( input ) ) { AppDebugOut("Warning failed to read directory from stream\n"); delete newDir; return false; } m_subDirectories.PutData( newDir ); } // // End marker input.read( marker, DIRECTORY_MARKERSIZE ); if( strncmp( marker, DIRECTORY_MARKEREND, DIRECTORY_MARKERSIZE ) != 0 ) { return false; } return true; }