diff --git a/src/Main/bootstrap.cxx b/src/Main/bootstrap.cxx index e1648b2ce..db16c69db 100644 --- a/src/Main/bootstrap.cxx +++ b/src/Main/bootstrap.cxx @@ -63,6 +63,7 @@ #include "main.hxx" #include #include
+#include
#include
#include
#include @@ -312,6 +313,10 @@ int main ( int argc, char **argv ) setlocale(LC_NUMERIC, "C"); setlocale(LC_COLLATE, "C"); + if (flightgear::Options::checkForArg(argc, argv, "uninstall")) { + return fgUninstall(); + } + bool fgviewer = flightgear::Options::checkForArg(argc, argv, "fgviewer"); int exitStatus = EXIT_FAILURE; try { diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index 8bd45ded9..c6fc1cce6 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -1195,3 +1195,43 @@ void fgInitPackageRoot() globals->setPackageRoot(pkgRoot); } + +int fgUninstall() +{ + SGPath dataPath = SGPath::fromEnv("FG_HOME", platformDefaultDataPath()); + simgear::Dir fgHome(dataPath); + if (fgHome.exists()) { + if (!fgHome.remove(true /* recursive */)) { + fprintf(stderr, "Errors occurred trying to remove FG_HOME"); + return EXIT_FAILURE; + } + } + + if (fgHome.exists()) { + fprintf(stderr, "unable to remove FG_HOME"); + return EXIT_FAILURE; + } + +#if defined(SG_WINDOWS) + SGPath p = flightgear::defaultDownloadDir(); + // we don't want to remove the whole dir, let's nuke specific + // subdirs which are (hopefully) safe + + SGPath terrasyncPath = p / "TerraSync"; + if (terrasyncPath.exists()) { + simgear::Dir dir(terrasyncPath); + if (!dir.remove(true /*recursive*/)) { + fprintf(stderr, "Errors occurred trying to remove Documents/FlightGear/TerraSync"); + } + } + + SGPath packagesPath = p / "Aircraft"; + if (packagesPath.exists()) { + simgear::Dir dir(packagesPath); + if (!dir.remove(true /*recursive*/)) { + fprintf(stderr, "Errors occurred trying to remove Documents/FlightGear/Aircraft"); + } + } +#endif + return EXIT_SUCCESS; +} diff --git a/src/Main/fg_init.hxx b/src/Main/fg_init.hxx index 8b741c261..cafba02c7 100644 --- a/src/Main/fg_init.hxx +++ b/src/Main/fg_init.hxx @@ -74,6 +74,10 @@ void fgStartNewReset(); // setup the package system including the global root void fgInitPackageRoot(); +// wipe FG_HOME. (The removing of the program data is assumed to be done +// by the real installer). +int fgUninstall(); + #endif // _FG_INIT_HXX