Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/game/StarRootLoader.hpp
blob: 574fd46d406edb06fcd6a8bc22acb07566612fd6 (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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#pragma once

#include "StarVersionOptionParser.hpp"
#include "StarRoot.hpp"

namespace Star {

// Parses command line flags and loads and returns the Root singleton based on
// them.
//
// It is designed to load settings first from the settings passed into the
// constructor, then from the required boot config file , then from any passed
// in command line flags.  Besides -version, the accepted command line flags
// are:
//
// -bootconfig <bootconfig> - sets path to the boot configuration file, defaults to sbinit.config
// -logfile <logfile> - sets path to logfile, if any, relative to root storage directory
// -loglevel <level> - sets logging level
// -quiet - turns off stdout logging
// -verbose - turns on stdout logging
// -runtimeconfig - sets the path to the runtime configuration storage file, relative to root storage directory
//
// The boot config file can contain the following options:
// 'assetDirectories' - Asset source search directories
// 'logFileBackups' - Number of rotated backups of the target log file
// 'storageDirectory' - Primary Root storage directory
// 'assetsSettings' - Merged with base assets settings
// 'defaultConfiguration' - Merged with base default configuration
class RootLoader : public VersionOptionParser {
public:
  struct Defaults {
    // Merged on top of the base assets settings hard-coded in RootLoader.
    Json additionalAssetsSettings;

    // Merged on top of the base default configuration hard-coded in RootLoader.
    Json additionalDefaultConfiguration;

    // Name of the log file that should be written, if any, relative to the
    // storage directory
    Maybe<String> logFile;

    // The minimum log level to write to any log sink
    LogLevel logLevel;

    // If true, doesn't write any logging to stdout, only to the log file if
    // given.
    bool quiet;

    // If given, will write changed configuration to the given file within the
    // storage directory.
    Maybe<String> runtimeConfigFile;
  };

  RootLoader(Defaults defaults);

  pair<Root::Settings, Options> parseOrDie(StringList const& cmdLineArguments) const;
  pair<RootUPtr, Options> initOrDie(StringList const& cmdLineArguments) const;

  pair<Root::Settings, Options> commandParseOrDie(int argc, char** argv);
  pair<RootUPtr, Options> commandInitOrDie(int argc, char** argv);

private:
  Root::Settings rootSettingsForOptions(Options const& options) const;

  Defaults m_defaults;
};

}