<!--
 Copyright (c) 2019 Emilian Roman
 
 This software is provided 'as-is', without any express or implied
 warranty. In no event will the authors be held liable for any damages
 arising from the use of this software.
 
 Permission is granted to anyone to use this software for any purpose,
 including commercial applications, and to alter it and redistribute it
 freely, subject to the following restrictions:
 
 1. The origin of this software must not be misrepresented; you must not
    claim that you wrote the original software. If you use this software
    in a product, an acknowledgment in the product documentation would be
    appreciated but is not required.
 2. Altered source versions must be plainly marked as such, and must not be
    misrepresented as being the original software.
 3. This notice may not be removed or altered from any source distribution.
-->

DATA STORAGE
============

This document covers the system used for storing SPV3 data, including
user profiles, progress and settings.

INTRODUCTION
------------

The SPV3 project deals with two principal directories:

  directory      description
  -------------- -------------------------------------------------------------
  installation   directory specified by the user to store the HCE & SPV3 mod
  data storage   directory used by SPV3 to store user profiles and settings

In SPV3.2, the SPV3 data would be stored in a singular location at the
following path:

    %APPDATA%\SPV3

This meant that all SPV3 installations would refer to the same directory
for profiles and settings:

    +--------------------+
    |SPV3 Installation 01| (e.g. C:\ABC\SPV3)
    +---------+----------+
              |
              v
        %APPDATA%\SPV3
              ^
              |
    +---------+----------+
    |SPV3 Installation 02| (e.g. D:\XYZ\SPV3)
    +--------------------+

This approach kept the data decoupled from the installation, meaning
that:

-   deleting/reinstalling SPV3 wouldn't remove any user profiles,
    progress and settings
-   data can be saved even if SPV3 was installed to a restricted
    directory

In SPV3.3, a similar system is used, except the difference is that an
unique data directory is dedicated to each SPV3 installation. Refer to
the section below for further information.

------------------------------------------------------------------------

ISOLATION
---------

To handle multiple SPV3.3 installations on the filesystem without data
conflicts, the loader now stores the data for each SPV3 installation in
isolation.

This is accomplished by having a dedicated data storage directory for
each installation. By mapping an unique directory to each SPV3
installation, we can avoid any data-related conflicts:

  spv3 installation   data directory
  ------------------- --------------------------------------
  C:\ABC\SPV3         a6896754-5cf9-4beb-bdba-9bd11c4ccd95
  D:\XYZ\SPV3         d52af2bd-79dc-42e0-9968-033d9a82d3b7

All data directories are named using universally unique identifiers
(UUID/GUID), and are located at the following path:

    %APPDATA%\SPV3

DATABASE
--------

To ensure that the mapping between a SPV3 installation and its
respective data directory is persistent, a record is kept of each SPV3
installation's data path in the following file:

    %APPDATA%\SPV3\database.xml

Unlike other files, this one stores the data directly in XML for the
sake of permitting savvy users to modify the mappings as they see fit.

IDENTIFYING
-----------

Each SPV3 installation is uniquely identified by its path on the
filesystem. With this in mind, moving/renaming the folder for an SPV3
installation will practically result in a new data folder being created
for it.
