write method

  1. @override
bool write(
  1. String name,
  2. String contents
)
override

Writes contents, and says whether it managed to.

Never throws, whatever the platform did: a disk that filled up mid-save is a bad day and a game that will not launch is a bug report nobody can act on. The boolean is for a caller that wants to say so on screen.

Implementation

@override
bool write(String name, String contents) {
  try {
    final where = directory;
    final file = _file(name);
    if (where == null || file == null) return false;
    _makeRoomFor(file);
    // Through a temporary file and a rename — see [writeFileAtomicallySync],
    // which is where this now lives because the level editor needed the same
    // thing and had written the unsafe version instead.
    writeFileAtomicallySync(file.path, contents);
    return true;
  } catch (error) {
    onIssue(Issue('storage: could not write $name ($error)'));
    return false;
  }
}