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,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<OptionsPrivate> p;
class OptionsPrivate;
std::unique_ptr<OptionsPrivate> p;
};
} // of namespace flightgear