This commit moves the write function to where it should be (IOS),
especially when ES::ImportTicket() is the only place to use it.
Prevents misusing the ticket import function, and removes one unsafe
direct write to the NAND that does not go through IOS.
This also fixes the destination path: the session root is the one which
should be used for determining the ticket path, not the configured one.
The whole NANDContentLoader stuff is truly awful and will be removed
as soon as possible.
For now, this fixes a bug that was exposed by std::optional::operator*.
std::optional makes a few things a bit neater and less error prone.
However, we still cannot use C++17 (unfortunately), so this commit
adds an implementation of std::optional that we can use right now.
Based on https://github.com/tensorflow/tensorflow/blob/master/tensorflow/core/lib/gtl/optional.h
which seems to be fairly similar to C++17's <optional> and standards
compliant. It's one of the few implementations that handle propagating
type traits like copy constructibility, just like libc++/libstdc++.
`MainWindow` initializes a number of input interfaces but never shuts
them down. This was causing a crash-after-exit on macOS where the
ControllerInterface backend stores a `std::thread` object in a static
variable and only stops it when ControllerInterface::Shutdown is called.
pSysMem is of the type const void* -- because of this, it makes the
original delete[] call undefined behavior, as deleting a void pointer is
undefined behavior.
Also punning types into existence, like what was done for the stereo
image header is undefined behavior as well. The proper way to do this is
to either manually add all individual bytes manually, or memcpy the
struct into memory.
As we want to deallocate the memory before returning, and because
pSysMem is a const void*, we keep a unique_ptr to the data and just pass
pSysMem a raw pointer to the data.