diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx old mode 100644 new mode 100755 index 8ec77a60a..1fb3e6530 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -1413,16 +1413,11 @@ void fgInitPackageRoot() return; } - SGPath packageAircraftDir = flightgear::Options::sharedInstance()->valueForOption("download-dir"); - if (packageAircraftDir.isNull()) { - packageAircraftDir = flightgear::defaultDownloadDir(); - } - + SGPath packageAircraftDir = flightgear::Options::sharedInstance()->actualDownloadDir(); packageAircraftDir.append("Aircraft"); SG_LOG(SG_GENERAL, SG_INFO, "init package root at:" << packageAircraftDir); - SGSharedPtr pkgRoot(new Root(packageAircraftDir, FLIGHTGEAR_VERSION)); // set the http client later (too early in startup right now) globals->setPackageRoot(pkgRoot); @@ -1454,7 +1449,7 @@ int fgUninstall() if (terrasyncPath.exists()) { simgear::Dir dir(terrasyncPath); if (!dir.remove(true /*recursive*/)) { - fprintf(stderr, "Errors occurred trying to remove Documents/FlightGear/TerraSync"); + std::cerr << "Errors occurred trying to remove " << terrasyncPath << std::endl; } } @@ -1462,7 +1457,15 @@ int fgUninstall() if (packagesPath.exists()) { simgear::Dir dir(packagesPath); if (!dir.remove(true /*recursive*/)) { - fprintf(stderr, "Errors occurred trying to remove Documents/FlightGear/Aircraft"); + std::cerr << "Errors occurred trying to remove " << packagesPath << std::endl; + } + } + + SGPath cachePath = p / "TextureCache"; + if (cachePath.exists()) { + simgear::Dir dir(cachePath); + if (!dir.remove(true /*recursive*/)) { + std::cerr << "Errors occurred trying to remove " << cachePath << std::endl; } } #endif diff --git a/src/Main/globals.cxx b/src/Main/globals.cxx index 84e0a8afc..588ad6038 100644 --- a/src/Main/globals.cxx +++ b/src/Main/globals.cxx @@ -300,6 +300,10 @@ void FGGlobals::set_fg_home (const SGPath &home) void FGGlobals::set_texture_cache_dir(const SGPath &textureCache) { texture_cache_dir = textureCache.realpath(); + auto node = fgGetNode("/sim/rendering/texture-cache/dir", true); + node->setAttribute(SGPropertyNode::WRITE, true); + node->setStringValue(textureCache.utf8Str()); + node->setAttribute(SGPropertyNode::WRITE, false); } diff --git a/src/Main/options.cxx b/src/Main/options.cxx index 52bc2ab70..f0f9c43e3 100644 --- a/src/Main/options.cxx +++ b/src/Main/options.cxx @@ -2680,9 +2680,19 @@ SGPath defaultDownloadDir() return globals->get_fg_home(); } +SGPath Options::actualDownloadDir() +{ + SGPath downloadDir = SGPath::fromUtf8(valueForOption("download-dir")); + if (!downloadDir.isNull()) { + return downloadDir; + } + + return defaultDownloadDir(); +} + SGPath defaultTextureCacheDir() { - return defaultDownloadDir() / "TextureCache"; + return Options::sharedInstance()->actualDownloadDir() / "TextureCache"; } OptionResult Options::processOptions() diff --git a/src/Main/options.hxx b/src/Main/options.hxx index 5d0f72955..50a057f25 100644 --- a/src/Main/options.hxx +++ b/src/Main/options.hxx @@ -44,6 +44,7 @@ namespace flightgear */ SGPath defaultDownloadDir(); + /// option processing can have various result values /// depending on what the user requested. Note processOptions only /// returns a subset of these. @@ -175,31 +176,37 @@ public: * @return */ string_list extractOptions() const; -private: - void showUsage() const; - void showVersion() const; - // Write info such as FG version, FG_ROOT, FG_HOME, scenery paths, aircraft - // paths, etc. to stdout in JSON format, using the UTF-8 encoding. - void printJSONReport() const; - // The 'fromConfigFile' parameter indicates whether the option comes from a - // config file or directly from the command line. - int parseOption(const std::string& s, bool fromConfigFile); + /** + @brief the actual download dir in use, which may be the default or a user-supplied value + */ + SGPath actualDownloadDir(); - void processArgResult(int result); + private: + void showUsage() const; + void showVersion() const; + // Write info such as FG version, FG_ROOT, FG_HOME, scenery paths, aircraft + // paths, etc. to stdout in JSON format, using the UTF-8 encoding. + void printJSONReport() const; - /** + // The 'fromConfigFile' parameter indicates whether the option comes from a + // config file or directly from the command line. + int parseOption(const std::string& s, bool fromConfigFile); + + void processArgResult(int result); + + /** * Setup the root base, and check it's valid. If * the root package was not found or is the incorrect version, * returns FG_OPTIONS_ERROR. Argv/argv * are passed since we might potentially show a GUI dialog at this point * to help the user our (finding a base package), and hence need to init Qt. */ - OptionResult setupRoot(int argc, char** argv); + OptionResult setupRoot(int argc, char** argv); - class OptionsPrivate; - std::unique_ptr p; + class OptionsPrivate; + std::unique_ptr p; }; } // of namespace flightgear