From cc5cc00060dbcacf15b9f602b94627dcd9ee880a Mon Sep 17 00:00:00 2001 From: lsv Date: Thu, 25 Dec 2025 17:39:53 +0500 Subject: [PATCH] The data path of the linux application has been changed to XDG_DATA_HOME. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Файлы которые создаёт приложение помещаются в $XDG_DATA_HOME/pgadmin3 или ~/.local/share/pgadmin3. Уже существующие файлы копируются из ~/postgresql на новое место. Каталог postgresql преименовывается в postgresql-no_use. Его можно будет удалить. Иконки в формате SVG теперь можно размещать и в $XDG_DATA_HOME/pgadmin3 в каталоге svg. Такая структуры каталога данных приложения: ~/.local/share/pgadmin3 ├── icons # иконки для баз данных ├── recovery # сохранённые вкладки ├── svg # каталог svg иконок приложения ├── filter_load.txt # фильтры csv лога для Log view ├── gitlab.json # настройки подключения к git ├── pgadmin3opt.json # дополнительные настройки приложения └── pgadmin_autoreplace.xml # списки автозамены --- .vscode/settings.json | 3 ++- ctl/ctlGitPanel.cpp | 3 ++- frm/frmMain.cpp | 13 +++++++------ frm/frmQuery.cpp | 18 +++++++++--------- pgAdmin3.cpp | 27 ++++++++++++++++++++++++++ utils/WaitSample.cpp | 14 +++++++------- utils/log/Storage.cpp | 6 +++--- utils/sysSettings.cpp | 44 ++++++++++--------------------------------- 8 files changed, 67 insertions(+), 61 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 71215e4..a6cdc29 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -7,7 +7,8 @@ "string.h": "c", "libpq-fe.h": "c", "new": "cpp", - "ostream": "cpp" + "ostream": "cpp", + "sstream": "cpp" }, "cmake.configureArgs": [ diff --git a/ctl/ctlGitPanel.cpp b/ctl/ctlGitPanel.cpp index 1730eab..1c7a989 100644 --- a/ctl/ctlGitPanel.cpp +++ b/ctl/ctlGitPanel.cpp @@ -318,7 +318,8 @@ ctlGitPanel::~ctlGitPanel() wxJSONValue ctlGitPanel::GetConfig() { wxString c; wxJSONValue cfg; - wxString p = wxStandardPaths::Get().GetUserConfigDir() + wxFileName::GetPathSeparator() + "postgresql"+ wxFileName::GetPathSeparator() +"gitlab.json"; + extern wxString dataDir; + wxString p = dataDir+ wxFileName::GetPathSeparator() +"gitlab.json"; if (!wxFileExists(p)) return cfg; wxFileInputStream input(p); if (input.IsOk()) { diff --git a/frm/frmMain.cpp b/frm/frmMain.cpp index 5fd93e2..b601671 100644 --- a/frm/frmMain.cpp +++ b/frm/frmMain.cpp @@ -306,12 +306,13 @@ wxBitmapBundle GetBundleSVG(wxBitmap* std, wxString name, wxSize sz) { wxBitmapBundle *b=NULL; bb = bundleHash[name]; if (bb.IsOk()) return bb; - - if (wxFile::Exists(loadPath + sepPath +"svg" + sepPath + name)) { - //b = new wxBitmapBundle(wxBitmapBundle::FromSVGFile(loadPath + sepPath + "svg" + sepPath + name, sz)); - bb=wxBitmapBundle::FromSVGFile(loadPath + sepPath + "svg" + sepPath + name, sz); + extern wxString dataDir; + wxString fullpath=dataDir+ sepPath +"svg" + sepPath + name; // 1. local data application + if (!wxFile::Exists(fullpath)) fullpath=loadPath + sepPath +"svg" + sepPath + name; // 2. execute path + if (wxFile::Exists(fullpath)) { // name only filename.svg + bb=wxBitmapBundle::FromSVGFile(fullpath, sz); } - else if (wxFile::Exists(name)) { + else if (wxFile::Exists(name)) { // name = fullpath if (name.AfterLast('.') == "png") { wxBitmap bitmap(name, wxBITMAP_TYPE_PNG); if (!bitmap.Ok()) @@ -330,7 +331,7 @@ wxBitmapBundle GetBundleSVG(wxBitmap* std, wxString name, wxSize sz) { } if (!bb.IsOk() && std){ - //b=new wxBitmapBundle(*std); + // file not found use standart bitmap bb = wxBitmapBundle::FromBitmap(*std); } diff --git a/frm/frmQuery.cpp b/frm/frmQuery.cpp index dc7dc3e..430fb58 100644 --- a/frm/frmQuery.cpp +++ b/frm/frmQuery.cpp @@ -92,7 +92,7 @@ #define XML_FROM_WXSTRING(s) ((const xmlChar *)(const char *)s.mb_str(wxConvUTF8)) #define WXSTRING_FROM_XML(s) wxString((char *)s, wxConvUTF8) #define XML_STR(s) ((const xmlChar *)s) - +extern wxString dataDir; // Initialize execution 'mutex'. As this will always run in the // main thread, there aren't any real concurrency issues, so // a simple flag will suffice. @@ -255,7 +255,7 @@ void frmQuery::seticon() wxString str; wxString filename; - wxString tempDir = wxStandardPaths::Get().GetUserConfigDir() + wxFileName::GetPathSeparator()+"postgresql"+wxFileName::GetPathSeparator()+"icons"+wxFileName::GetPathSeparator(); + wxString tempDir = dataDir+wxFileName::GetPathSeparator()+"icons"+wxFileName::GetPathSeparator(); wxString db = conn->GetDbname(); wxString host = conn->GetHostName(); @@ -525,7 +525,7 @@ frmQuery::frmQuery(frmMain *form, const wxString &_title, pgConn *_conn, const w mapping["MNU_UNCOMMENT_TEXT"] = MNU_UNCOMMENT_TEXT; mapping["MNU_DOROLLBACK"] = MNU_DOROLLBACK; mapping["MNU_DOCOMMIT"] = MNU_DOCOMMIT; - wxString tempDir = wxStandardPaths::Get().GetUserConfigDir() +wxFileName::GetPathSeparator()+"postgresql"+wxFileName::GetPathSeparator()+"keymap.txt"; + wxString tempDir = dataDir+wxFileName::GetPathSeparator()+"keymap.txt"; wxLogInfo(wxT("frmQuery::Create key map ...")); int idx = 0; if (wxFileName::FileExists(tempDir) ) @@ -867,7 +867,7 @@ frmQuery::frmQuery(frmMain *form, const wxString &_title, pgConn *_conn, const w // load temp file wxString str; wxString filename; - tempDir = wxStandardPaths::Get().GetUserConfigDir() +wxFileName::GetPathSeparator()+"postgresql"; + tempDir = dataDir; if (!wxDirExists(tempDir)) { wxMkdir(tempDir); } @@ -2496,7 +2496,7 @@ void frmQuery::SaveTempFile() wxString pref=conn->GetDbname(); //if (filename.StartsWith(pref)) filename+=wxT(".a"); - wxString tempDir = wxStandardPaths::Get().GetUserConfigDir() +wxFileName::GetPathSeparator()+"postgresql"+wxFileName::GetPathSeparator()+"recovery"+wxFileName::GetPathSeparator(); + wxString tempDir = dataDir+wxFileName::GetPathSeparator()+"recovery"+wxFileName::GetPathSeparator(); if (autoSave) { wxUtfFile file(tempDir + filename, wxFile::write, modeUnicode ? wxFONTENCODING_UTF8 : wxFONTENCODING_DEFAULT); if (file.IsOpened()) @@ -4436,7 +4436,7 @@ void frmQuery::SetOutputPaneCaption(bool update) // Methods related to SQL tabs // void frmQuery::fileMarkerActive(bool addOrRemove, const wxString &sqlTabName) { - wxString tempDir = wxStandardPaths::Get().GetUserConfigDir() +wxFileName::GetPathSeparator()+"postgresql"+wxFileName::GetPathSeparator()+"recovery"+wxFileName::GetPathSeparator(); + wxString tempDir = dataDir+wxFileName::GetPathSeparator()+"recovery"+wxFileName::GetPathSeparator(); wxString tabname = sqlTabName; if (sqlTabName.Find("*")>=0) tabname = sqlTabName.BeforeLast('*'); @@ -4619,7 +4619,7 @@ void frmQuery::OnSqlBookTabRDown (wxAuiNotebookEvent &event) { pref, wxOK | wxCANCEL); //setName( dlg.GetValue().wc_str() ); if (dialog.ShowModal() == wxID_OK) { - wxString tempDir = wxStandardPaths::Get().GetUserConfigDir() +wxFileName::GetPathSeparator()+"postgresql"+wxFileName::GetPathSeparator()+"recovery"+wxFileName::GetPathSeparator(); + wxString tempDir = dataDir+wxFileName::GetPathSeparator()+"recovery"+wxFileName::GetPathSeparator(); wxString filename=sqlQuery->GetTitle(false); wxString tf=tempDir+filename+".a"; if (wxFileName::FileExists(tf)) wxRemoveFile(tf); @@ -4668,7 +4668,7 @@ void frmQuery::OnSqlBookPageClose(wxAuiNotebookEvent &event) SqlBookDisconnectPage(); //drop temp file - wxString tempDir = wxStandardPaths::Get().GetUserConfigDir() +wxFileName::GetPathSeparator()+"postgresql"+wxFileName::GetPathSeparator()+"recovery"+wxFileName::GetPathSeparator(); + wxString tempDir = dataDir+wxFileName::GetPathSeparator()+"recovery"+wxFileName::GetPathSeparator(); wxString filename=sqlQuery->GetTitle(false)+wxT(".a"); if (wxFileName::FileExists(tempDir+filename)) wxRemoveFile(tempDir+filename); fileMarkerActive(false, sqlQuery->GetTitle(false)); @@ -4764,7 +4764,7 @@ bool frmQuery::SqlBookRemovePage() SqlBookDisconnectPage(); pageidx = sqlQueryBook->GetSelection(); - wxString tempDir = wxStandardPaths::Get().GetUserConfigDir() +wxFileName::GetPathSeparator()+"postgresql"+wxFileName::GetPathSeparator()+"recovery"+wxFileName::GetPathSeparator(); + wxString tempDir = dataDir+wxFileName::GetPathSeparator()+"recovery"+wxFileName::GetPathSeparator(); ctlSQLBox *box; box = wxDynamicCast(sqlQueryBook->GetPage(pageidx), ctlSQLBox); wxString filename=box->GetTitle(false); diff --git a/pgAdmin3.cpp b/pgAdmin3.cpp index 3899958..5d98b2e 100644 --- a/pgAdmin3.cpp +++ b/pgAdmin3.cpp @@ -1054,6 +1054,33 @@ void pgAdmin3::InitAppPaths() brandingPath = LocatePath(BRANDING_DIR, false); pluginsDir = LocatePath(PLUGINS_DIR, false); settingsIni = LocatePath(SETTINGS_INI, true); +#ifdef __LINUX__ + wxString newdir; + wxString olddatadir=wxFileName::GetHomeDir()+sepPath+"postgresql"; + + if ( !wxGetEnv(wxS("XDG_DATA_HOME"), &newdir) || newdir.empty() ) + newdir = wxFileName::GetHomeDir() + wxT("/.local/share/pgadmin3"); + dataDir=newdir ; + if (!wxDir::Exists(newdir)) { + wxMkDir(newdir,wxS_IRUSR|wxS_IWUSR|wxS_IXUSR); + + if (wxDir::Exists(olddatadir)) { + if (!wxShell(wxString::Format("cp -r %s/* %s",olddatadir,newdir))) { + wxLogError(wxString::Format("Error copy dirictory 'cp -r %s %s'",olddatadir,newdir)); + dataDir=wxFileName::GetHomeDir() + sepPath + "postgresql"; + + } else { + wxShell(wxString::Format("mv %s %s",olddatadir,olddatadir+"-no_use")); + wxShell(wxString::Format("mv ~/.pgadmin3autoreplace %s",newdir+"/pgadmin_autoreplace.xml")); + } + } + + } +#else + dataDir= wxStandardPaths::Get().GetUserConfigDir() + wxFileName::GetPathSeparator() + "postgresql"; +#endif + + } // Setup the paths for the helper apps etc. diff --git a/utils/WaitSample.cpp b/utils/WaitSample.cpp index 17076f7..148603c 100644 --- a/utils/WaitSample.cpp +++ b/utils/WaitSample.cpp @@ -4,7 +4,7 @@ #include "utils/utffile.h" #include "utils/json/jsonval.h" #include "frm/frmStatus.h" - +extern wxString dataDir; void WaitSample::Init() { wxString clr = "h1 { \ region: \"IO:DataFileRead\", #2132bd;\n\ @@ -132,7 +132,7 @@ region: \"Timeout:PgSleep\", #6ce4c6;\n\ if (cc1.IsOk()) color_gui.push_back(wxColour(cc1)); else color_gui.push_back(wxColour(def["label"].AsString())); - wxString tempDir = wxStandardPaths::Get().GetUserConfigDir() + wxFileName::GetPathSeparator() + "postgresql" + wxFileName::GetPathSeparator() + "cache_sql.txt"; + wxString tempDir = dataDir + wxFileName::GetPathSeparator() + "cache_sql.txt"; m_file_cache_sql = tempDir; wxTextFile file(tempDir); if (file.Exists()) file.Open(); @@ -279,8 +279,8 @@ int WaitSample::GetGroupingData(int timeEnd, int needCountGroup, int groupInterv wxString groupRule, wxArrayString& nameGroup, std::vector& xAxisValue, std::vector& yAxisValue, - std::vector& Values, // - std::vector& clr // groupRule.Count() + std::vector& Values, // ������ �������� ������ �� ���� + std::vector& clr // ���� ���� ������������ groupRule.Count() ) { int idx_grp = wait_id.size(); @@ -493,7 +493,7 @@ wxString WaitSample::GetQueryByQid(long long qid) { } void WaitSample::LoadFileSamples() { - wxString tempDir = wxStandardPaths::Get().GetUserConfigDir() + wxFileName::GetPathSeparator() + "postgresql" + wxFileName::GetPathSeparator() + "sample.dat"; + wxString tempDir = dataDir + wxFileName::GetPathSeparator() + "sample.dat"; wxTextFile file(tempDir); file.Open(); if (file.IsOpened()) @@ -603,7 +603,7 @@ void WaitSample::LoadFileSamples() { } } void WaitSample::SaveFileSamples() { - wxString tempDir = wxStandardPaths::Get().GetUserConfigDir() + wxFileName::GetPathSeparator() + "postgresql" + wxFileName::GetPathSeparator() + "sample.dat"; + wxString tempDir = dataDir + wxFileName::GetPathSeparator() + "sample.dat"; wxUtfFile file(tempDir, wxFile::write, wxFONTENCODING_UTF8); if (file.IsOpened()) { @@ -668,7 +668,7 @@ bool WaitSample::RemoveFiles() { } void WaitSample::AddSample(int pid, bool isXidTransation, wxString& btype, const wxString& sample) { //PidWait pw(pid, basetime);; - // + // ����� int pw; auto iter = pids.find(pid); if (iter != pids.end()) { diff --git a/utils/log/Storage.cpp b/utils/log/Storage.cpp index 863831c..d097bc0 100644 --- a/utils/log/Storage.cpp +++ b/utils/log/Storage.cpp @@ -3,7 +3,7 @@ #include "utils/utffile.h" #include #include - +extern wxString dataDir; int Storage::getCountStore() { return storage.size(); } @@ -83,7 +83,7 @@ void Storage::Reset() { m_cacheIndex = -1; ClearRowsStat(); // load filter - wxString tempDir = wxStandardPaths::Get().GetUserConfigDir() + wxFileName::GetPathSeparator() + "postgresql" + wxFileName::GetPathSeparator(); + wxString tempDir = dataDir + wxFileName::GetPathSeparator(); wxString f = tempDir + "filter_load.txt"; if (wxFileExists(f)) { @@ -199,7 +199,7 @@ int Storage::getFilterNames(wxArrayString& arr) { } void Storage::saveFilters() { if (filterload.size() == 0) return; - wxString tempDir = wxStandardPaths::Get().GetUserConfigDir() + wxFileName::GetPathSeparator() + "postgresql" + wxFileName::GetPathSeparator(); + wxString tempDir = dataDir + wxFileName::GetPathSeparator(); wxString f = tempDir + "filter_load.txt"; wxUtfFile file(f, wxFile::write, wxFONTENCODING_UTF8); if (file.IsOpened()) diff --git a/utils/sysSettings.cpp b/utils/sysSettings.cpp index a775eac..cf7df30 100644 --- a/utils/sysSettings.cpp +++ b/utils/sysSettings.cpp @@ -32,6 +32,7 @@ #include "utils/json/jsonval.h" #include "utils/json/jsonreader.h" #include "utils/json/jsonwriter.h" +extern wxString dataDir; sysSettings::sysSettings(const wxString& name) : wxConfig(name) { appName = name; @@ -68,7 +69,7 @@ sysSettings::~sysSettings() #ifdef WIN32 wxRegKey key(wxRegKey::HKCU, "Software\\"+appName); - wxString fn= wxStandardPaths::Get().GetUserConfigDir() + wxT("\\postgresql\\autoSaveConfig.reg"); + wxString fn= dataDir + wxT("\\autoSaveConfig.reg"); if (wxFileName::FileExists(fn)) wxRemoveFile(fn); key.Export(fn); #endif @@ -467,7 +468,7 @@ bool sysSettings::WriteJsonObect(const wxString& key, wxJSONValue& value) return true; } bool sysSettings::ReloadJsonFileIfNeed() { - wxString path = wxStandardPaths::Get().GetUserConfigDir() + sepPath + "postgresql" + sepPath + "pgadmin3opt.json"; + wxString path = dataDir + sepPath + "pgadmin3opt.json"; if (wxFileExists(path)) { wxDateTime fmod = wxFileName(path).GetModificationTime(); if ((!jsonfilemod.IsValid() || fmod != jsonfilemod) && !jsonchange) { @@ -496,7 +497,7 @@ bool sysSettings::WriteJsonFile() if (!jsoncfg.IsNull() && jsonchange) { //wxString s = jsoncfg.Dump(true, 0); { - wxString p = wxStandardPaths::Get().GetUserConfigDir() + sepPath + "postgresql" + sepPath + "pgadmin3opt.json"; + wxString p = dataDir + sepPath + "pgadmin3opt.json"; { wxFileOutputStream out(p); if (out.IsOk()) { @@ -865,7 +866,7 @@ wxString sysSettings::GetConfigFile(configFileName cfgname) { fname = stdp.GetUserConfigDir(); #ifdef WIN32 - fname += wxT("\\postgresql"); + fname = dataDir; if (!wxDirExists(fname)) wxMkdir(fname); fname += wxT("\\pgpass.conf"); @@ -927,15 +928,8 @@ wxString sysSettings::GetConfigFile(configFileName cfgname) wxString sysSettings::GetFavouritesFile() { wxString s, tmp; - -#if wxCHECK_VERSION(2, 9, 5) - wxStandardPaths &stdp = wxStandardPaths::Get(); -#else - wxStandardPaths stdp; -#endif - tmp = stdp.GetUserConfigDir(); + tmp = dataDir; #ifdef WIN32 - tmp += wxT("\\postgresql"); if (!wxDirExists(tmp)) wxMkdir(tmp); tmp += wxT("\\pgadmin_favourites.xml"); @@ -953,14 +947,8 @@ wxString sysSettings::GetMacrosFile() { wxString s, tmp; -#if wxCHECK_VERSION(2, 9, 5) - wxStandardPaths &stdp = wxStandardPaths::Get(); -#else - wxStandardPaths stdp; -#endif - tmp = stdp.GetUserConfigDir(); + tmp = dataDir; #ifdef WIN32 - tmp += wxT("\\postgresql"); if (!wxDirExists(tmp)) wxMkdir(tmp); tmp += wxT("\\pgadmin_macros.xml"); @@ -976,19 +964,13 @@ wxString sysSettings::GetAutoReplaceFile() { wxString s, tmp; -#if wxCHECK_VERSION(2, 9, 5) - wxStandardPaths &stdp = wxStandardPaths::Get(); -#else - wxStandardPaths stdp; -#endif - tmp = stdp.GetUserConfigDir(); + tmp = dataDir; #ifdef WIN32 - tmp += wxT("\\postgresql"); if (!wxDirExists(tmp)) wxMkdir(tmp); tmp += wxT("\\pgadmin_autoreplace.xml"); #else - tmp += wxT("/.pgadminautoreplace"); + tmp += wxT("/pgadmin_autoreplace.xml"); #endif Read(wxT("AutoReplaceFile"), &s, tmp); @@ -1001,14 +983,8 @@ wxString sysSettings::GetHistoryFile() { wxString s, tmp; -#if wxCHECK_VERSION(2, 9, 5) - wxStandardPaths &stdp = wxStandardPaths::Get(); -#else - wxStandardPaths stdp; -#endif - tmp = stdp.GetUserConfigDir(); + tmp = dataDir; #ifdef WIN32 - tmp += wxT("\\postgresql"); if (!wxDirExists(tmp)) wxMkdir(tmp); tmp += wxT("\\pgadmin_histoqueries.xml");