Fix ~/.celestia.cfg reading

pull/151/head
Hleb Valoshka 2018-11-05 22:52:32 +03:00
parent 34ab3bd829
commit 6fcaadb207
5 changed files with 15 additions and 21 deletions

View File

@ -4020,8 +4020,8 @@ using StarLoader = CatalogLoader<StarDatabase>;
using DeepSkyLoader = CatalogLoader<DSODatabase>;
bool CelestiaCore::initSimulation(const string* configFileName,
const vector<string>* extrasDirs,
bool CelestiaCore::initSimulation(const string& configFileName,
const vector<string>& extrasDirs,
ProgressNotifier* progressNotifier)
{
// Say we're not ready to render yet.
@ -4038,9 +4038,9 @@ bool CelestiaCore::initSimulation(const string* configFileName,
}
#endif
if (configFileName != nullptr)
if (!configFileName.empty())
{
config = ReadCelestiaConfig(*configFileName);
config = ReadCelestiaConfig(configFileName);
}
else
{
@ -4072,14 +4072,14 @@ bool CelestiaCore::initSimulation(const string* configFileName,
// Insert additional extras directories into the configuration. These
// additional directories typically come from the command line. It may
// be useful to permit other command line overrides of config file fields.
if (extrasDirs != nullptr)
if (!extrasDirs.empty())
{
// Only insert the additional extras directories that aren't also
// listed in the configuration file. The additional directories are added
// after the ones from the config file and the order in which they were
// specified is preserved. This process in O(N*M), but the number of
// additional extras directories should be small.
for (const auto& dir : *extrasDirs)
for (const auto& dir : extrasDirs)
{
if (find(config->extrasDirs.begin(), config->extrasDirs.end(), dir) ==
config->extrasDirs.end())

View File

@ -233,8 +233,8 @@ class CelestiaCore // : public Watchable<CelestiaCore>
CelestiaCore();
~CelestiaCore();
bool initSimulation(const std::string* = nullptr,
const std::vector<std::string>* extrasDirs = nullptr,
bool initSimulation(const std::string& configFileName = "",
const std::vector<std::string>& extrasDirs = {},
ProgressNotifier* progressNotifier = nullptr);
bool initRenderer();
void start(double t);

View File

@ -365,11 +365,9 @@ int main(int argc, char* argv[])
g_assert(app->renderer);
/* Parse simulation arguments */
string cf;
string altConfig;
if (configFile != NULL)
cf = string(configFile);
string* altConfig = (configFile != NULL) ? &cf : NULL;
altConfig = string(configFile);
vector<string> configDirs;
if (extrasDir != NULL)
@ -384,7 +382,7 @@ int main(int argc, char* argv[])
}
/* Initialize the simulation */
if (!app->core->initSimulation(altConfig, &configDirs, ss->notifier))
if (!app->core->initSimulation(altConfig, configDirs, ss->notifier))
return 1;
app->simulation = app->core->getSimulation();

View File

@ -77,7 +77,6 @@
using namespace std;
QString DEFAULT_CONFIG_FILE = "celestia.cfg";
QString BOOKMARKS_FILE = "bookmarks.xbel";
const QSize DEFAULT_MAIN_WINDOW_SIZE(800, 600);
@ -217,9 +216,7 @@ void CelestiaAppWindow::init(const QString& qConfigFileName,
// Get the config file name
string configFileName;
if (qConfigFileName.isEmpty())
configFileName = DEFAULT_CONFIG_FILE.toStdString();
else
if (!qConfigFileName.isEmpty())
configFileName = qConfigFileName.toStdString();
// Translate extras directories from QString -> std::string
@ -265,8 +262,8 @@ void CelestiaAppWindow::init(const QString& qConfigFileName,
setWindowIcon(QIcon(":/icons/celestia.png"));
if (!m_appCore->initSimulation(&configFileName,
&extrasDirectories,
if (!m_appCore->initSimulation(configFileName,
extrasDirectories,
progress))
{
// Error message is shown by celestiacore so we silently exit here.

View File

@ -3363,8 +3363,7 @@ int APIENTRY WinMain(HINSTANCE hInstance,
if (!skipSplashScreen)
progressNotifier = new WinSplashProgressNotifier(s_splash);
string* altConfig = useAlternateConfigFile ? &configFileName : NULL;
bool initSucceeded = appCore->initSimulation(altConfig, &extrasDirectories, progressNotifier);
bool initSucceeded = appCore->initSimulation(configFileName, extrasDirectories, progressNotifier);
delete progressNotifier;