openMSX
Filename.cc
Go to the documentation of this file.
1 #include "Filename.hh"
2 #include "FileContext.hh"
3 #include "FileOperations.hh"
4 #include "MSXException.hh"
5 #include "serialize.hh"
6 #include <cassert>
7 
8 using std::string;
9 
10 namespace openmsx {
11 
13  : originalFilename(std::move(filename))
14  , resolvedFilename(originalFilename)
15 {
16 }
17 
19  : originalFilename(std::move(filename))
20  , resolvedFilename(FileOperations::getAbsolutePath(
21  context.resolve(originalFilename)))
22 {
23 }
24 
26 {
27  if (empty()) return;
28  if (FileOperations::exists(resolvedFilename)) return;
29 
30  try {
31  resolvedFilename = FileOperations::getAbsolutePath(
32  userFileContext().resolve(originalFilename));
33  } catch (MSXException&) {
34  // nothing
35  }
36 }
37 
38 bool Filename::empty() const
39 {
40  assert(getOriginal().empty() == getResolved().empty());
41  return getOriginal().empty();
42 }
43 
44 template<typename Archive>
45 void Filename::serialize(Archive& ar, unsigned /*version*/)
46 {
47  ar.serialize("original", originalFilename,
48  "resolved", resolvedFilename);
49 }
51 
52 } // namespace openmsx
serialize.hh
openmsx::Filename::getResolved
const std::string & getResolved() const
Definition: Filename.hh:27
MSXException.hh
openmsx::MSXException
Definition: MSXException.hh:9
openmsx::userFileContext
FileContext userFileContext(string_view savePath)
Definition: FileContext.cc:161
Filename.hh
openmsx::Filename::updateAfterLoadState
void updateAfterLoadState()
After a loadstate we prefer to use the exact same file as before savestate.
Definition: Filename.cc:25
openmsx::FileContext
Definition: FileContext.hh:9
openmsx::Filename::serialize
void serialize(Archive &ar, unsigned version)
Definition: Filename.cc:45
openmsx::FileOperations::exists
bool exists(string_view filename)
Definition: FileOperations.cc:675
openmsx::Filename::getOriginal
const std::string & getOriginal() const
Definition: Filename.hh:26
openmsx::filename
constexpr const char *const filename
Definition: FirmwareSwitch.cc:10
INSTANTIATE_SERIALIZE_METHODS
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
Definition: serialize.hh:981
openmsx::Filename::Filename
Filename()=default
openmsx::Filename::empty
bool empty() const
Convenience method to test for empty filename.
Definition: Filename.cc:38
FileContext.hh
FileOperations.hh
gl::context
std::unique_ptr< Context > context
Definition: GLContext.cc:9
openmsx::Filename
This class represents a filename.
Definition: Filename.hh:17
openmsx::FileOperations::getAbsolutePath
string getAbsolutePath(string_view path)
Definition: FileOperations.cc:488
openmsx
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5