namespace AIStudio.Tools.DataBackup; /// /// How a prepared restore waits for the next start, which applies it. /// /// /// This is the contract between the app, which prepares a restore, and the runtime, which applies it /// before the app starts again, when no file is in use: /// /// Below the data folder and below the configuration folder, PENDING_DIRECTORY holds what the /// backup brings for that folder, in the layout of that folder. Staging lies on the same disk as its /// target, so the runtime can move every element into place instead of copying it. /// The plan, PLAN_FILE_NAME in the pending directory of the data folder, names the elements to /// replace, cf. DataRestorePlan. /// READY_FILE_NAME in the same directory comes last. Without it, the restore was not prepared /// completely, and the runtime leaves everything as it is. /// /// What the runtime adds, cf. runtime/src/data_restore.rs: /// /// PREVIOUS_DIRECTORY, below both folders, keeps what the restore replaced. The app removes it /// once it loaded the restored settings. /// JOURNAL_FILE_NAME in the pending directory of the data folder lists every move. While it lies /// next to READY_FILE_NAME, the runtime moves everything back at the next start, so the app never /// removes a pending directory which holds READY_FILE_NAME. /// RESULT_FILE_NAME in the data folder tells the app how the restore ended, cf. DataRestoreReport. /// /// Keep in sync with the runtime, which applies the restore. /// public static class DataRestoreFormat { /// /// The version of the plan this version of AI Studio writes. /// public const int PLAN_FORMAT_VERSION = 1; /// /// The directory, below the data folder and below the configuration folder, which holds what a /// prepared restore brings for that folder. /// public const string PENDING_DIRECTORY = ".restore-pending/"; /// /// The plan of the restore, in the pending directory of the data folder. /// public const string PLAN_FILE_NAME = "restore.json"; /// /// Marks a restore as prepared completely, in the pending directory of the data folder. /// public const string READY_FILE_NAME = "READY"; /// /// The directory, below the data folder and below the configuration folder, which keeps what the /// runtime replaced, in the layout of that folder. /// public const string PREVIOUS_DIRECTORY = ".restore-previous/"; /// /// How the runtime applied a restore, in the data folder. /// public const string RESULT_FILE_NAME = ".restore-result.json"; /// /// The journal of the runtime, in the pending directory of the data folder. Next to READY_FILE_NAME, /// it tells that the runtime has not finished a restore: it moves it back at the next start. /// public const string JOURNAL_FILE_NAME = "journal.json"; /// /// The path of one of the directories above, below the given folder. /// /// The data or the configuration folder. /// PENDING_DIRECTORY or PREVIOUS_DIRECTORY. /// The path of the directory. public static string DirectoryIn(string folder, string directory) => Path.Join(folder, directory.TrimEnd(DataBackupContents.SEPARATOR)); }