diff --git a/CMakeLists.txt b/CMakeLists.txt index 2c48196d2..5423a5949 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,6 +4,9 @@ cmake_minimum_required(VERSION 3.12) project(luanti) set(PROJECT_NAME_CAPITALIZED "Luanti") +set(LEGACY_PROJECT_NAME "minetest") +set(LEGACY_PROJECT_NAME_CAPITALIZED "Minetest") + set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED TRUE) set(GCC_MINIMUM_VERSION "7.5") diff --git a/src/cmake_config.h.in b/src/cmake_config.h.in index 2ec91dfd1..2f387ac5b 100644 --- a/src/cmake_config.h.in +++ b/src/cmake_config.h.in @@ -4,6 +4,8 @@ #define PROJECT_NAME "@PROJECT_NAME@" #define PROJECT_NAME_C "@PROJECT_NAME_CAPITALIZED@" +#define LEGACY_PROJECT_NAME "@LEGACY_PROJECT_NAME@" +#define LEGACY_PROJECT_NAME_C "@LEGACY_PROJECT_NAME_CAPITALIZED@" #define VERSION_MAJOR @VERSION_MAJOR@ #define VERSION_MINOR @VERSION_MINOR@ #define VERSION_PATCH @VERSION_PATCH@ diff --git a/src/porting.cpp b/src/porting.cpp index 8ca5c7d46..fc0f06c4d 100644 --- a/src/porting.cpp +++ b/src/porting.cpp @@ -457,6 +457,17 @@ bool setSystemPaths() return true; } +void migrateLegacyDirs() { + char buf[BUFSIZ]; + + DWORD len = GetEnvironmentVariable("APPDATA", buf, sizeof(buf)); + FATAL_ERROR_IF(len == 0 || len > sizeof(buf), "Failed to get APPDATA"); + std::string legacy_path_user = std::string(buf) + DIR_DELIM LEGACY_PROJECT_NAME_C; + std::string new_path_user = std::string(buf) + DIR_DELIM PROJECT_NAME_C; + + if (fs::PathExists(legacy_path_user)) + fs::MoveDir(legacy_path_user, new_path_user); +} //// Android @@ -525,6 +536,21 @@ bool setSystemPaths() return true; } +void migrateLegacyDirs() { + const char *const xdg_data = getenv("XDG_DATA_HOME"); + std::string legacy_path_user; + std::string new_path_user; + + legacy_path_user = std::string(getHomeOrFail()) + DIR_DELIM "." LEGACY_PROJECT_NAME; + if (xdg_data) { + new_path_user = std::string(xdg_data); + } else { + new_path_user = std::string(getHomeOrFail()) + DIR_DELIM ".local" DIR_DELIM "share" DIR_DELIM PROJECT_NAME; + } + + if (fs::PathExists(legacy_path_user)) + fs::MoveDir(legacy_path_user, new_path_user); +} //// Mac OS X #elif defined(__APPLE__) @@ -553,6 +579,18 @@ bool setSystemPaths() return true; } +void migrateLegacyDirs() { + std::string legacy_path_user = std::string(getHomeOrFail()) + + "/Library/Application Support/" + LEGACY_PROJECT_NAME; + + std::string new_path_user = std::string(getHomeOrFail()) + + "/Library/Application Support/" + PROJECT_NAME; + + if (fs::PathExists(legacy_path_user)) + fs::MoveDir(legacy_path_user, new_path_user); +} #else @@ -568,6 +606,15 @@ bool setSystemPaths() return true; } +void migrateLegacyDirs() { + std::string legacy_path_user = std::string(getHomeOrFail()) + DIR_DELIM "." LEGACY_PROJECT_NAME; + + std::string new_path_user = std::string(getHomeOrFail()) + DIR_DELIM "." PROJECT_NAME; + + if (fs::PathExists(legacy_path_user)) + fs::MoveDir(legacy_path_user, new_path_user); +} + #endif @@ -682,6 +729,8 @@ void initializePaths() // Migrate cache folder to new location if possible migrateCachePath(); + migrateLegacyDirs(); + #endif // RUN_IN_PLACE assert(!path_share.empty()); diff --git a/src/porting.h b/src/porting.h index f7d623d33..e44dfb79d 100644 --- a/src/porting.h +++ b/src/porting.h @@ -119,6 +119,8 @@ std::string getDataPath(const char *subpath); */ void initializePaths(); +void migrateLegacyDirs(); + /* Return system information e.g. "Linux/3.12.7 x86_64"