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:
parent
bcc728f4e5
commit
0243b996fe
4 changed files with 47 additions and 23 deletions
19
src/Main/fg_init.cxx
Normal file → Executable file
19
src/Main/fg_init.cxx
Normal file → Executable file
|
@ -1413,16 +1413,11 @@ void fgInitPackageRoot()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SGPath packageAircraftDir = flightgear::Options::sharedInstance()->valueForOption("download-dir");
|
SGPath packageAircraftDir = flightgear::Options::sharedInstance()->actualDownloadDir();
|
||||||
if (packageAircraftDir.isNull()) {
|
|
||||||
packageAircraftDir = flightgear::defaultDownloadDir();
|
|
||||||
}
|
|
||||||
|
|
||||||
packageAircraftDir.append("Aircraft");
|
packageAircraftDir.append("Aircraft");
|
||||||
|
|
||||||
SG_LOG(SG_GENERAL, SG_INFO, "init package root at:" << packageAircraftDir);
|
SG_LOG(SG_GENERAL, SG_INFO, "init package root at:" << packageAircraftDir);
|
||||||
|
|
||||||
|
|
||||||
SGSharedPtr<Root> pkgRoot(new Root(packageAircraftDir, FLIGHTGEAR_VERSION));
|
SGSharedPtr<Root> pkgRoot(new Root(packageAircraftDir, FLIGHTGEAR_VERSION));
|
||||||
// set the http client later (too early in startup right now)
|
// set the http client later (too early in startup right now)
|
||||||
globals->setPackageRoot(pkgRoot);
|
globals->setPackageRoot(pkgRoot);
|
||||||
|
@ -1454,7 +1449,7 @@ int fgUninstall()
|
||||||
if (terrasyncPath.exists()) {
|
if (terrasyncPath.exists()) {
|
||||||
simgear::Dir dir(terrasyncPath);
|
simgear::Dir dir(terrasyncPath);
|
||||||
if (!dir.remove(true /*recursive*/)) {
|
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()) {
|
if (packagesPath.exists()) {
|
||||||
simgear::Dir dir(packagesPath);
|
simgear::Dir dir(packagesPath);
|
||||||
if (!dir.remove(true /*recursive*/)) {
|
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
|
#endif
|
||||||
|
|
|
@ -300,6 +300,10 @@ void FGGlobals::set_fg_home (const SGPath &home)
|
||||||
void FGGlobals::set_texture_cache_dir(const SGPath &textureCache)
|
void FGGlobals::set_texture_cache_dir(const SGPath &textureCache)
|
||||||
{
|
{
|
||||||
texture_cache_dir = textureCache.realpath();
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2680,9 +2680,19 @@ SGPath defaultDownloadDir()
|
||||||
return globals->get_fg_home();
|
return globals->get_fg_home();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SGPath Options::actualDownloadDir()
|
||||||
|
{
|
||||||
|
SGPath downloadDir = SGPath::fromUtf8(valueForOption("download-dir"));
|
||||||
|
if (!downloadDir.isNull()) {
|
||||||
|
return downloadDir;
|
||||||
|
}
|
||||||
|
|
||||||
|
return defaultDownloadDir();
|
||||||
|
}
|
||||||
|
|
||||||
SGPath defaultTextureCacheDir()
|
SGPath defaultTextureCacheDir()
|
||||||
{
|
{
|
||||||
return defaultDownloadDir() / "TextureCache";
|
return Options::sharedInstance()->actualDownloadDir() / "TextureCache";
|
||||||
}
|
}
|
||||||
|
|
||||||
OptionResult Options::processOptions()
|
OptionResult Options::processOptions()
|
||||||
|
|
|
@ -44,6 +44,7 @@ namespace flightgear
|
||||||
*/
|
*/
|
||||||
SGPath defaultDownloadDir();
|
SGPath defaultDownloadDir();
|
||||||
|
|
||||||
|
|
||||||
/// option processing can have various result values
|
/// option processing can have various result values
|
||||||
/// depending on what the user requested. Note processOptions only
|
/// depending on what the user requested. Note processOptions only
|
||||||
/// returns a subset of these.
|
/// returns a subset of these.
|
||||||
|
@ -175,6 +176,12 @@ public:
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
string_list extractOptions() const;
|
string_list extractOptions() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
@brief the actual download dir in use, which may be the default or a user-supplied value
|
||||||
|
*/
|
||||||
|
SGPath actualDownloadDir();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void showUsage() const;
|
void showUsage() const;
|
||||||
void showVersion() const;
|
void showVersion() const;
|
||||||
|
|
Loading…
Add table
Reference in a new issue