|
31 | 31 | #include <boost/program_options.hpp> |
32 | 32 | #include <boost/filesystem.hpp> |
33 | 33 | #include <boost/filesystem/fstream.hpp> |
| 34 | +#include <boost/optional.hpp> |
34 | 35 |
|
35 | 36 | // Standard includes |
36 | 37 | #include <iostream> |
@@ -91,37 +92,36 @@ int main(int argc, char *argv[]) { |
91 | 92 | return 0; |
92 | 93 | } |
93 | 94 |
|
94 | | - if (!values.count(configOpt)) { |
95 | | - out << "Using default config file - pass a filename on the command " |
96 | | - "line to use a different one." |
97 | | - << endl; |
98 | | - } else { |
99 | | - configName = values[configOpt].as<std::string>(); |
100 | | - } |
| 95 | + configName = values[configOpt].as<std::string>(); |
101 | 96 |
|
102 | | - fs::path configPath(configName); |
103 | | - if (!fs::exists(configPath)) { |
104 | | - try { |
105 | | - out << "Creating blank config at \"" << configName << "\"" << endl; |
106 | | - fs::ofstream configOut{configPath}; |
107 | | - configOut << "{ }\n"; |
108 | | - configOut.close(); |
109 | | - } catch (fs::filesystem_error &e) { |
110 | | - err << "Could not create config file at \"" << configName << "\"" |
111 | | - << endl; |
112 | | - err << "Reason " << e.what() << endl; |
| 97 | + boost::optional<fs::path> configPath(configName); |
| 98 | + try { |
| 99 | + if (!fs::exists(*configPath)) { |
| 100 | + out << "File '" << configName |
| 101 | + << "' not found. Using blank config" << endl; |
| 102 | + configPath = boost::none; |
| 103 | + } else { |
| 104 | + if (fs::is_directory(*configPath)) { |
| 105 | + err << "'" << configName << "' is a directory" << endl; |
| 106 | + return -1; |
| 107 | + } else if (!fs::is_regular_file(*configPath)) { |
| 108 | + err << "'" << configName << "' is special file" << endl; |
| 109 | + return -1; |
| 110 | + } |
113 | 111 | } |
| 112 | + } catch (fs::filesystem_error &e) { |
| 113 | + err << "Could not open config file at '" << configName << "'" |
| 114 | + << endl; |
| 115 | + err << "Reason " << e.what() << endl; |
| 116 | + configPath = boost::none; |
| 117 | + } |
| 118 | + |
| 119 | + if (configPath) { |
| 120 | + server = osvr::server::configureServerFromFile(configName); |
114 | 121 | } else { |
115 | | - if (fs::is_directory(configPath)) { |
116 | | - err << "\"" << configName << "\" is a directory" << endl; |
117 | | - return -1; |
118 | | - } else if (!fs::is_regular_file(configPath)) { |
119 | | - err << "\"" << configName << "\" is special file" << endl; |
120 | | - return -1; |
121 | | - } |
| 122 | + server = osvr::server::configureServerFromString("{ }"); |
122 | 123 | } |
123 | | - |
124 | | - server = osvr::server::configureServerFromFile(configName); |
| 124 | + |
125 | 125 | if (!server) { |
126 | 126 | return -1; |
127 | 127 | } |
|
0 commit comments