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
STL namespace.
Filename()=default
void serialize(Archive &ar, unsigned version)
Definition: Filename.cc:45
const std::string & getOriginal() const
Definition: Filename.hh:26
FileContext userFileContext(string_view savePath)
Definition: FileContext.cc:161
std::unique_ptr< Context > context
Definition: GLContext.cc:9
void updateAfterLoadState()
After a loadstate we prefer to use the exact same file as before savestate.
Definition: Filename.cc:25
constexpr const char *const filename
This class represents a filename.
Definition: Filename.hh:17
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
bool exists(string_view filename)
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
Definition: serialize.hh:981
const std::string & getResolved() const
Definition: Filename.hh:27
bool empty() const
Convenience method to test for empty filename.
Definition: Filename.cc:38
string getAbsolutePath(string_view path)