aboutsummaryrefslogtreecommitdiff
path: root/V3/Data/Internal/PathManager.cs
blob: 3f4ad9da2eaf6e08c5972204723b785a59216aa7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System;
using System.IO;

namespace V3.Data.Internal {
    /// <summary>
    /// Default implementation of IPathManager.
    /// </summary>
    // ReSharper disable once ClassNeverInstantiated.Global
    internal sealed class PathManager : IPathManager
    {
        /// <summary>
        /// The base directory for persistent application data.
        /// </summary>
        public string AppDirectory { get; }

        /// <summary>
        /// The file to store the options in.
        /// </summary>
        public string OptionsFile { get; }

        /// <summary>
        /// The directory for save games.
        /// </summary>
        public string SaveGameDirectory { get; }

        /// <summary>
        /// Creates a new path manager and initializes the paths, but does not
        /// create the directories if they don�t already exist.
        /// </summary>
        public PathManager()
        {
            var localAppDir = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
            AppDirectory = $"{localAppDir}/V3";
            SaveGameDirectory = $"{AppDirectory}/SaveGames";
            OptionsFile = $"{AppDirectory}/Options.xml";
        }

        /// <summary>
        /// Creates the application directories that do not already exist.
        /// </summary>
        public void CreateMissingDirectories()
        {
            string[] directories = { AppDirectory, SaveGameDirectory };
            foreach (var directory in directories)
            {
                if (!Directory.Exists(directory))
                    Directory.CreateDirectory(directory);
            }
        }
    }
}