How best to persist parented "directories and files" data?

Hi everyone,

I’m prototyping a game that involves working with simulated Linux-type servers; the player logs into a host, and can explore and manipulate files, etc.

This will require storing structured, parented data in the ways you’d expect: Each host contains a number of directories, and each directory contains a number of directories and files.

Players will be able to copy and move files and directories around within a host and between hosts.

I’m considering three different ways of storing this data: SQLite, XML, and the native filesystem of the player’s machine.

SQLite Pros:

  • Relational data uses easy to understand IDs and primary key/foreign key relationships
  • Database transaction support and data integrity auto-enforced; much more difficult to get data in a bad state
  • I’m more familiar with SQL than the other options

SQLite Cons:

  • The game now has an external dependency to SQLite
  • Cross-platform testing (Windows vs Mac) possibly more complex
  • SQLite does not support stored procedures

XML Pros:

  • Seems like the most portable option, no external dependencies
  • C# XElement seems like it could do everything I’d need, not sure though

XML Cons:

  • No data integrity enforcement
  • I would need to become an expert with XElement

Native Filesystem Pros:

  • Possibly the most intuitive
  • C# comes with mature methods for manipulating filesystems, and abstracts platform-specific stuff (Path.DirectorySeparatorChar, etc)

Native Filesystem Cons:

  • No idea if this would work on mobile or console platforms

I’d love to hear what you all think. Thanks!

Relational databases are generally a poor match for storing tree-like structures, which a filesystem is. XML or native filesystem should both be fine, or you could just serialize your own tree data-structure somehow (you’re going to need one anyway).

The native filesystem sounds kinda weird. Will your save file be a literal set of folders and files that represents the simulated servers?

Now, using a native filesystem to generate the file data is probably a lot easier than writing your own editor or (ugh) manipulating xml by hand. But I would parse that data into some kind of data representation that your game works (and ships) with.