diff --git a/corelib/src/Parameters.cpp b/corelib/src/Parameters.cpp index ed7e981b..935233bf 100644 --- a/corelib/src/Parameters.cpp +++ b/corelib/src/Parameters.cpp @@ -1247,7 +1247,12 @@ void readINIImpl(const CSimpleIniA & ini, const std::string & configFilePath, Pa { if(RTABMAP_VERSION_COMPARE(<, std::atoi(version[0].c_str()), std::atoi(version[1].c_str()), std::atoi(version[2].c_str()))) { - if(configFilePath.find(".rtabmap") != std::string::npos) + // Detect the user's private config - matches both the legacy + // ~/.rtabmap/rtabmap.ini and the Windows %LOCALAPPDATA%/rtabmap/rtabmap.ini + // (".rtabmap/rtabmap.ini" also contains "rtabmap/rtabmap.ini"): downgrade-on-save is fine there. + // Accept both forward and backward slashes (native Windows paths). + if(configFilePath.find("rtabmap/rtabmap.ini") != std::string::npos || + configFilePath.find("rtabmap\\rtabmap.ini") != std::string::npos) { UWARN("Version in the config file \"%s\" is more recent (\"%s\") than " "current RTAB-Map version used (\"%s\"). The config file will be downgraded " diff --git a/guilib/src/DatabaseViewer.cpp b/guilib/src/DatabaseViewer.cpp index 63afea48..5ef206f6 100644 --- a/guilib/src/DatabaseViewer.cpp +++ b/guilib/src/DatabaseViewer.cpp @@ -39,6 +39,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include +#include +#include #include #include #include @@ -583,12 +586,33 @@ QString DatabaseViewer::getIniFilePath() const { return iniFilePath_; } +#ifdef WIN32 + // Windows: store settings in the standard per-user config location (%LOCALAPPDATA%\rtabmap) + // instead of a Unix-style dotfile in the home root. A fixed "rtabmap" folder (not the app name) + // is used so the main GUI and DatabaseViewer share the same rtabmap.ini. Other platforms keep + // ~/.rtabmap for consistency. + QString privatePath = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + "/rtabmap"; +#else QString privatePath = QDir::homePath() + "/.rtabmap"; +#endif if(!QDir(privatePath).exists()) { - QDir::home().mkdir(".rtabmap"); + QDir().mkpath(privatePath); } - return privatePath + "/rtabmap.ini"; + QString iniPath = privatePath + "/rtabmap.ini"; +#ifdef WIN32 + // One-time migration: if there's no ini at the new location but the legacy ~/.rtabmap/rtabmap.ini + // exists, copy it over so users keep their existing settings. + if(!QFile::exists(iniPath)) + { + QString legacyIni = QDir::homePath() + "/.rtabmap/rtabmap.ini"; + if(QFile::exists(legacyIni)) + { + QFile::copy(legacyIni, iniPath); + } + } +#endif + return iniPath; } void DatabaseViewer::readSettings() diff --git a/guilib/src/PreferencesDialog.cpp b/guilib/src/PreferencesDialog.cpp index 7b8276d1..899fb1f4 100644 --- a/guilib/src/PreferencesDialog.cpp +++ b/guilib/src/PreferencesDialog.cpp @@ -39,6 +39,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include +#include +#include #include #include @@ -2579,12 +2581,33 @@ QString PreferencesDialog::getWorkingDirectory() const QString PreferencesDialog::getIniFilePath() const { +#ifdef WIN32 + // Windows: store settings in the standard per-user config location (%LOCALAPPDATA%\rtabmap) + // instead of a Unix-style dotfile in the home root. A fixed "rtabmap" folder (not the app name) + // is used so the main GUI and DatabaseViewer share the same rtabmap.ini. Other platforms keep + // ~/.rtabmap for consistency. + QString privatePath = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + "/rtabmap"; +#else QString privatePath = QDir::homePath() + "/.rtabmap"; +#endif if(!QDir(privatePath).exists()) { - QDir::home().mkdir(".rtabmap"); + QDir().mkpath(privatePath); } - return privatePath + "/rtabmap.ini"; + QString iniPath = privatePath + "/rtabmap.ini"; +#ifdef WIN32 + // One-time migration: if there's no ini at the new location but the legacy ~/.rtabmap/rtabmap.ini + // exists, copy it over so users keep their existing settings. + if(!QFile::exists(iniPath)) + { + QString legacyIni = QDir::homePath() + "/.rtabmap/rtabmap.ini"; + if(QFile::exists(legacyIni)) + { + QFile::copy(legacyIni, iniPath); + } + } +#endif + return iniPath; } QString PreferencesDialog::getTmpIniFilePath() const