Fix of #4969: XDG path detection with wx3.0

This commit is contained in:
Lukas Matena 2020-10-26 12:54:00 +01:00
parent e14c122d12
commit f4311f67ef

View File

@ -360,12 +360,14 @@ bool static check_old_linux_datadir(const wxString& app_name) {
namespace fs = boost::filesystem; namespace fs = boost::filesystem;
// If running Linux, file layout should be already set to XDG.
assert(wxStandardPaths::Get().GetFileLayout() == wxStandardPaths::FileLayout_XDG);
std::string new_path = Slic3r::data_dir(); std::string new_path = Slic3r::data_dir();
if (new_path != (wxStandardPaths::Get().GetUserConfigDir() + "/" + app_name).ToUTF8().data()) { wxString dir;
if (! wxGetEnv(wxS("XDG_CONFIG_HOME"), &dir) || dir.empty() )
dir = wxFileName::GetHomeDir() + wxS("/.config");
std::string default_path = (dir + "/" + app_name).ToUTF8().data();
if (new_path != default_path) {
// This happens when the user specifies a custom --datadir. // This happens when the user specifies a custom --datadir.
// Do not show anything in that case. // Do not show anything in that case.
return true; return true;
@ -378,9 +380,7 @@ bool static check_old_linux_datadir(const wxString& app_name) {
int file_count = std::distance(fs::directory_iterator(data_dir), fs::directory_iterator()); int file_count = std::distance(fs::directory_iterator(data_dir), fs::directory_iterator());
if (file_count <= 1) { // just cache dir with an instance lock if (file_count <= 1) { // just cache dir with an instance lock
wxStandardPaths::Get().SetFileLayout(wxStandardPaths::FileLayout_Classic);
std::string old_path = wxStandardPaths::Get().GetUserDataDir().ToUTF8().data(); std::string old_path = wxStandardPaths::Get().GetUserDataDir().ToUTF8().data();
wxStandardPaths::Get().SetFileLayout(wxStandardPaths::FileLayout_XDG);
if (fs::is_directory(old_path)) { if (fs::is_directory(old_path)) {
wxString msg = from_u8((boost::format(_u8L("Starting with %1% 2.3, configuration " wxString msg = from_u8((boost::format(_u8L("Starting with %1% 2.3, configuration "
@ -697,8 +697,10 @@ void GUI_App::init_app_config()
#else #else
// Since version 2.3, config dir on Linux is in ${XDG_CONFIG_HOME}. // Since version 2.3, config dir on Linux is in ${XDG_CONFIG_HOME}.
// https://github.com/prusa3d/PrusaSlicer/issues/2911 // https://github.com/prusa3d/PrusaSlicer/issues/2911
wxStandardPaths::Get().SetFileLayout(wxStandardPaths::FileLayout_XDG); wxString dir;
set_data_dir((wxStandardPaths::Get().GetUserConfigDir() + "/" + GetAppName()).ToUTF8().data()); if (! wxGetEnv(wxS("XDG_CONFIG_HOME"), &dir) || dir.empty() )
dir = wxFileName::GetHomeDir() + wxS("/.config");
set_data_dir((dir + "/" + GetAppName()).ToUTF8().data());
#endif #endif
} }