1
0
Fork 0

Base texture-cache-dir on actual download dir

Previously we always used the default download dir, and ignored any
user override of this. Use the active download dir as the base for
the cache dir.

Also write the cache dir to the property tree, and wipe it on a
clean uninstall.
This commit is contained in:
James Turner 2021-06-14 13:54:32 +01:00
parent bcc728f4e5
commit 0243b996fe
4 changed files with 47 additions and 23 deletions

19
src/Main/fg_init.cxx Normal file → Executable file
View file

@ -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<Root> 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

View file

@ -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);
}

View file

@ -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()

View file

@ -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,6 +176,12 @@ public:
* @return
*/
string_list extractOptions() const;
/**
@brief the actual download dir in use, which may be the default or a user-supplied value
*/
SGPath actualDownloadDir();
private:
void showUsage() const;
void showVersion() const;