From 668f32f55789326da4fb9799cabb8d94698c6a99 Mon Sep 17 00:00:00 2001 From: mj-xmr Date: Fri, 4 Mar 2022 09:47:25 +0100 Subject: [PATCH] default data dir's Backward compatibility --- src/common/util.cpp | 46 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/src/common/util.cpp b/src/common/util.cpp index 4d24887f3..943df8bf4 100644 --- a/src/common/util.cpp +++ b/src/common/util.cpp @@ -597,6 +597,32 @@ std::string get_nix_version_display_string() } #endif + std::string DEPRECATED_get_default_data_dir() + { + // Kept for backward compatibility + /* Please for the love of god refactor the ifdefs out of this */ + + // namespace fs = boost::filesystem; + // Windows < Vista: C:\Documents and Settings\Username\Application Data\CRYPTONOTE_NAME + // Windows >= Vista: C:\Users\Username\AppData\Roaming\CRYPTONOTE_NAME + // Unix & Mac: ~/.CRYPTONOTE_NAME + std::string config_folder; + +#ifdef WIN32 + config_folder = get_special_folder_path(CSIDL_COMMON_APPDATA, true) + "\\" + CRYPTONOTE_NAME; +#else + std::string pathRet; + char* pszHome = getenv("HOME"); + if (pszHome == NULL || strlen(pszHome) == 0) + pathRet = "/"; + else + pathRet = pszHome; + config_folder = (pathRet + "/." + CRYPTONOTE_NAME); +#endif + + return config_folder; + } + std::string get_default_data_dir() { /* Please for the love of god refactor the ifdefs out of this */ @@ -606,10 +632,10 @@ std::string get_nix_version_display_string() // Windows >= Vista: C:\Users\Username\AppData\Roaming\CRYPTONOTE_NAME // Linux: XDG_DATA_HOME or ~/.local/share/CRYPTONOTE_NAME // Mac: ~/Library/Application Support/CRYPTONOTE_NAME - std::string config_folder; + std::string data_folder; #ifdef WIN32 - config_folder = get_special_folder_path(CSIDL_COMMON_APPDATA, true) + "\\" + CRYPTONOTE_NAME; + data_folder = get_special_folder_path(CSIDL_COMMON_APPDATA, true) + "\\" + CRYPTONOTE_NAME; #else // Posix std::string pathRet; const std::string dirSep = "/"; @@ -635,10 +661,22 @@ std::string get_nix_version_display_string() { pathRet = pszFallback; } - config_folder = (pathRet + dirSep + CRYPTONOTE_NAME); + data_folder = (pathRet + dirSep + CRYPTONOTE_NAME); #endif - return config_folder; + const std::string & data_folder_deprecated = DEPRECATED_get_default_data_dir(); + if (boost::filesystem::exists(data_folder_deprecated)) + { + MWARNING("Your data are still located in the deprecated folder: '" << data_folder_deprecated << "'. " + << "Please consider moving the data to the new folder: '" << data_folder << "'. " + << "Until then, the deprecated folder shall be used." + ); + return data_folder_deprecated; + } + else + { + return data_folder; + } } bool create_directories_if_necessary(const std::string& path)