Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#5108: Move ArchivedMapResource implementation to .cpp file.
Prevent saving of read-only resources.
- Loading branch information
1 parent
07aed61
commit 4bd351d
Showing
6 changed files
with
108 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#include "ArchivedMapResource.h" | ||
|
||
#include "i18n.h" | ||
#include "ifilesystem.h" | ||
|
||
namespace map | ||
{ | ||
|
||
ArchivedMapResource::ArchivedMapResource(const std::string& archivePath, const std::string& filePathWithinArchive) : | ||
MapResource(filePathWithinArchive), | ||
_archivePath(archivePath), | ||
_filePathWithinArchive(filePathWithinArchive) | ||
{} | ||
|
||
bool ArchivedMapResource::isReadOnly() | ||
{ | ||
return true; | ||
} | ||
|
||
void ArchivedMapResource::save(const MapFormatPtr& mapFormat) | ||
{ | ||
assert(false); | ||
rError() << "ArchivedMapResources cannot be saved." << std::endl; | ||
} | ||
|
||
stream::MapResourceStream::Ptr ArchivedMapResource::openMapfileStream() | ||
{ | ||
ensureArchiveOpened(); | ||
|
||
return openFileInArchive(_filePathWithinArchive); | ||
} | ||
|
||
stream::MapResourceStream::Ptr ArchivedMapResource::openInfofileStream() | ||
{ | ||
ensureArchiveOpened(); | ||
|
||
try | ||
{ | ||
auto infoFilename = _filePathWithinArchive.substr(0, _filePathWithinArchive.rfind('.')); | ||
infoFilename += GetInfoFileExtension(); | ||
|
||
return openFileInArchive(infoFilename); | ||
} | ||
catch (const OperationException& ex) | ||
{ | ||
// Info file load file does not stop us, just issue a warning | ||
rWarning() << ex.what() << std::endl; | ||
return stream::MapResourceStream::Ptr(); | ||
} | ||
} | ||
|
||
stream::MapResourceStream::Ptr ArchivedMapResource::openFileInArchive(const std::string& filePathWithinArchive) | ||
{ | ||
assert(_archive); | ||
|
||
auto archiveFile = _archive->openTextFile(filePathWithinArchive); | ||
|
||
if (!archiveFile) | ||
{ | ||
throw OperationException(fmt::format(_("Could not open file in archive: {0}"), _archivePath)); | ||
} | ||
|
||
return stream::MapResourceStream::OpenFromArchiveFile(archiveFile); | ||
} | ||
|
||
void ArchivedMapResource::ensureArchiveOpened() | ||
{ | ||
if (_archive) | ||
{ | ||
return; | ||
} | ||
|
||
_archive = GlobalFileSystem().openArchiveInAbsolutePath(_archivePath); | ||
|
||
if (!_archive) | ||
{ | ||
throw OperationException(fmt::format(_("Could not open archive: {0}"), _archivePath)); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters