#define I18N_DIR wxT("/i18n")
#define BRANDING_DIR wxT("/branding")
#define UTILITIES_INI wxT("/plugins/utilities.ini")
+#define SETTINGS_INI wxT("/settings.ini")
// Globals
frmMain *winMain=0;
wxString uiPath; // Where ui data is stored
wxString i18nPath; // Where i18n data is stored
wxString brandingPath; // Where branding data is stored
-wxString utilitiesIni; // The utilities.ini file
+wxString utilitiesIni; // The utilities.ini file
+wxString settingsIni; // The settings.ini file
wxLog *logger;
{wxCMD_LINE_NONE}
};
+ // Setup the basic paths for the app installation. Required by settings!
+ InitAppPaths();
+
// Load the Settings
#ifdef __WXMSW__
settings = new sysSettings(wxT("pgAdmin III"));
settings = new sysSettings(wxT("pgadmin3"));
#endif
- // we are here
- InitPaths();
+ // Setup additional helper paths etc. Requires settings!
+ InitXtraPaths();
frmConfig::tryMode configMode=frmConfig::NONE;
wxString configFile;
wxLogInfo(wxT("Doc path : %s"), docPath.c_str());
wxLogInfo(wxT("Branding path: %s"), brandingPath.c_str());
wxLogInfo(wxT("Utilities INI: %s"), utilitiesIni.c_str());
+ wxLogInfo(wxT("Settings INI : %s"), settingsIni.c_str());
wxLogInfo(wxT("PG pg_dump : %s"), pgBackupExecutable.c_str());
wxLogInfo(wxT("PG pg_dumpall : %s"), pgBackupAllExecutable.c_str());
}
#endif
-void pgAdmin3::InitPaths()
+// Setup the paths for the application itself
+void pgAdmin3::InitAppPaths()
{
- loadPath=wxPathOnly(argv[0]);
- if (loadPath.IsEmpty())
- loadPath = wxT(".");
-
-#ifdef __WXMSW__
-
- // Search for the right paths. We check the following locations:
- //
- // 1) ./xxx - Running as a standalone install
- // 2) ../pgAdmin/xxx - Running in a pgInstaller 8.1 installation
- // (with the .exe and dlls in the main bin dir)
- // 3) ../../xxx or ../xxx - Running in a development environment
-
- if (wxDir::Exists(loadPath + I18N_DIR))
- i18nPath = loadPath + I18N_DIR;
- else if (wxDir::Exists(loadPath + wxT("/../pgAdmin III") + I18N_DIR))
- i18nPath = loadPath + wxT("/../pgAdmin III") + I18N_DIR;
- else
- i18nPath = loadPath + wxT("/../..") + I18N_DIR;
-
- if (wxDir::Exists(loadPath + DOC_DIR))
- docPath = loadPath + DOC_DIR;
- else if (wxDir::Exists(loadPath + wxT("/../pgAdmin III") DOC_DIR))
- docPath = loadPath + wxT("/../pgAdmin III") DOC_DIR;
- else
- docPath = loadPath + wxT("/../..") DOC_DIR;
-
- if (wxDir::Exists(loadPath + UI_DIR))
- uiPath = loadPath + UI_DIR;
- if (wxDir::Exists(loadPath + wxT("/../pgAdmin III") + UI_DIR))
- uiPath = loadPath + wxT("/../pgAdmin III") + UI_DIR;
- else
- uiPath = loadPath + wxT("/..") UI_DIR;
-
- if (wxDir::Exists(loadPath + BRANDING_DIR))
- brandingPath = loadPath + BRANDING_DIR;
- else if (wxDir::Exists(loadPath + wxT("/../pgAdmin III") + BRANDING_DIR))
- brandingPath = loadPath + wxT("/../pgAdmin III") + BRANDING_DIR;
- else
- brandingPath = loadPath + wxT("/../..") + BRANDING_DIR;
-
- // utilities.ini
- if (wxFile::Exists(loadPath + UTILITIES_INI))
- utilitiesIni = loadPath + UTILITIES_INI;
- else if (wxFile::Exists(loadPath + wxT("/../pgAdmin III") + UTILITIES_INI))
- utilitiesIni = loadPath + wxT("/../pgAdmin III") + UTILITIES_INI;
- else if (wxFile::Exists(loadPath + wxT("/../..") + UTILITIES_INI))
- utilitiesIni = loadPath + wxT("/../..") + UTILITIES_INI;
-#else
-
- wxString dataDir;
-
-#ifdef __WXMAC__
-
- // When using wxStandardPaths on OSX, wx default to the unix,
- // not to the mac variants. Therefore, we request wxStandardPathsCF
- // directly.
- wxStandardPathsCF stdPaths ;
- dataDir = stdPaths.GetDataDir() ;
-
-#else // other *ixes
-
-// Data path (defined by configure under Unix).
-#ifndef DATA_DIR
-#define DATA_DIR "./"
-#endif
-
- dataDir = wxString::FromAscii(DATA_DIR);
-#endif
-
- // On unix systems, the search path is as follows:
- //
- // 1) DATADIR/xxx - DATADIR being defined by configure
- // 2) ./../share/pgadmin3/xxx - The default 'make install' layout, but allowing for relocation
- // 3) ./xxx - Windows-style standalone install
- // 4) ./../xxx - Unix-style standalone install (with binaries in a bin directory)
-
- if (wxDir::Exists(dataDir + I18N_DIR))
- i18nPath = dataDir + I18N_DIR;
-
- if (wxDir::Exists(dataDir + UI_DIR))
- uiPath = dataDir + UI_DIR;
-
- if (wxDir::Exists(dataDir + DOC_DIR))
- docPath = dataDir + DOC_DIR ;
-
- if (wxDir::Exists(dataDir + BRANDING_DIR))
- brandingPath = dataDir + BRANDING_DIR ;
-
- if (wxFile::Exists(dataDir + UTILITIES_INI))
- utilitiesIni = dataDir + UTILITIES_INI;
-
- if (i18nPath.IsEmpty())
- {
- if (wxDir::Exists(loadPath + wxT("/../share/pgadmin3") I18N_DIR))
- i18nPath = loadPath + wxT("/../share/pgadmin3") I18N_DIR;
- else if (wxDir::Exists(loadPath + I18N_DIR))
- i18nPath = loadPath + I18N_DIR;
- else
- i18nPath = loadPath + wxT("/..") I18N_DIR;
- }
- if (uiPath.IsEmpty())
- {
- if (wxDir::Exists(loadPath + wxT("/../share/pgadmin3") UI_DIR))
- uiPath = loadPath + wxT("/../share/pgadmin3") UI_DIR;
- else if (wxDir::Exists(loadPath + UI_DIR))
- uiPath = loadPath + UI_DIR;
- else
- uiPath = loadPath + wxT("/..") UI_DIR;
- }
- if (docPath.IsEmpty())
- {
- if (wxDir::Exists(loadPath + wxT("/../share/pgadmin3") DOC_DIR))
- docPath = loadPath + wxT("/../share/pgadmin3") DOC_DIR;
- else if (wxDir::Exists(loadPath + DOC_DIR))
- docPath = loadPath + DOC_DIR ;
- else
- docPath = loadPath + wxT("/..") DOC_DIR ;
- }
- if (brandingPath.IsEmpty())
- {
- if (wxDir::Exists(loadPath + wxT("/../share/pgadmin3") BRANDING_DIR))
- brandingPath = loadPath + wxT("/../share/pgadmin3") BRANDING_DIR;
- else if (wxDir::Exists(loadPath + BRANDING_DIR))
- brandingPath = loadPath + BRANDING_DIR ;
- else
- brandingPath = loadPath + wxT("/..") BRANDING_DIR ;
- }
-
- // utilities.ini
- if (utilitiesIni.IsEmpty())
- {
- if (wxFile::Exists(loadPath + wxT("/../share/pgadmin3") UTILITIES_INI))
- utilitiesIni = loadPath + wxT("/../share/pgadmin3") UTILITIES_INI;
- else if (wxFile::Exists(loadPath + UTILITIES_INI))
- utilitiesIni = loadPath + UTILITIES_INI;
- else if (wxFile::Exists(loadPath + wxT("/..") UTILITIES_INI))
- utilitiesIni = loadPath + wxT("/..") UTILITIES_INI;
- }
-#endif
+ i18nPath = LocatePath(I18N_DIR, false);
+ docPath = LocatePath(DOC_DIR, false);
+ uiPath = LocatePath(UI_DIR, false);
+ brandingPath = LocatePath(BRANDING_DIR, false);
+ utilitiesIni = LocatePath(UTILITIES_INI, true);
+ settingsIni = LocatePath(SETTINGS_INI, true);
+}
+// Setup the paths for the helper apps etc.
+void pgAdmin3::InitXtraPaths()
+{
//////////////////////////////////
// Now setup the app helper paths
//////////////////////////////////
wxPathList path;
#ifdef __WXMSW__
+ path.Add(wxT("C:\\PostgresPlus\\8.4\\dbserver\\bin"));
+ path.Add(wxT("C:\\PostgresPlus\\8.3\\dbserver\\bin"));
+ path.Add(wxT("C:\\Program Files\\PostgreSQL\\8.4\\bin"));
path.Add(wxT("C:\\Program Files\\PostgreSQL\\8.3\\bin"));
path.Add(wxT("C:\\Program Files\\PostgreSQL\\8.2\\bin"));
path.Add(wxT("C:\\Program Files\\PostgreSQL\\8.1\\bin"));
wxFileName tmp = path.FindValidPath(wxT("pg_dump.exe"));
#else
+ // Mac paths
+ path.Add(wxT("/Library/PostgresPlus/8.4/dbserver/bin"));
+ path.Add(wxT("/Library/PostgresPlus/8.3/bin"));
+
+ // Generic Unix paths
+ path.Add(wxT("/opt/PostgresPlus/8.4/dbserver/bin"));
+ path.Add(wxT("/opt/PostgresPlus/8.3/dbserver/bin"));
+ path.Add(wxT("/opt/PostgresPlus/8.3/bin"));
path.Add(wxT("/usr/local/pgsql/bin"));
path.Add(wxT("/usr/local/bin"));
path.Add(wxT("/usr/bin"));
wxPathList path;
#ifdef __WXMSW__
- path.Add(wxT("C:\\EnterpriseDB\\8.3\\dbserver\\bin"));
+ path.Add(wxT("C:\\PostgresPlus\\8.4AS\\dbserver\\bin"));
+ path.Add(wxT("C:\\PostgresPlus\\8.3AS\\dbserver\\bin"));
path.Add(wxT("C:\\EnterpriseDB\\8.2\\dbserver\\bin"));
path.Add(wxT("C:\\EnterpriseDB\\8.1\\dbserver\\bin"));
path.Add(wxT("C:\\EnterpriseDB\\8.0\\dbserver\\bin"));
wxFileName tmp = path.FindValidPath(wxT("pg_dump.exe"));
#else
- path.Add(wxT("/opt/EnterpriseDB/8.3/dbserver/bin"));
+ // Mac paths
+ path.Add(wxT("/Library/PostgresPlus/8.4AS/dbserver/bin"));
+ path.Add(wxT("/Library/PostgresPlus/8.3AS/dbserver/bin"));
+
+ // Generic Unix paths
+ path.Add(wxT("/opt/PostgresPlus/8.4AS/dbserver/bin"));
+ path.Add(wxT("/opt/PostgresPlus/8.3AS/dbserver/bin"));
path.Add(wxT("/usr/local/enterpriseDB/bin"));
path.Add(wxT("/usr/local/enterprisedb/bin"));
path.Add(wxT("/usr/local/edb/bin"));
edbBackupAllExecutable = wxEmptyString;
if (!isEdbApp(edbRestoreExecutable))
edbRestoreExecutable = wxEmptyString;
+}
+
+wxString pgAdmin3::LocatePath(const wxString &pathToFind, const bool isFile)
+{
+ loadPath = wxPathOnly(argv[0]);
+
+ if (loadPath.IsEmpty())
+ loadPath = wxT(".");
+
+ loadPath = sanitizePath(loadPath);
+
+#if defined(__WXMSW__)
+
+ // Search for the right paths. We check the following locations:
+ //
+ // 1) ./xxx - Running as a standalone install
+ // 2) ../pgAdmin/xxx - Running in a pgInstaller 8.1 installation
+ // (with the .exe and dlls in the main bin dir)
+ // 3) ../xxx or ../../xxx - Running in a development environment
+
+ if (!isFile)
+ {
+ if (wxDir::Exists(loadPath + pathToFind))
+ return sanitizePath(loadPath + pathToFind);
+ else if (wxDir::Exists(loadPath + wxT("/../pgAdmin III") + pathToFind))
+ return sanitizePath(loadPath + wxT("/../pgAdmin III") + pathToFind);
+ else if (wxDir::Exists(loadPath + wxT("/..") + pathToFind))
+ return sanitizePath(loadPath + wxT("/..") + pathToFind);
+ else if (wxDir::Exists(loadPath + wxT("/../..") + pathToFind))
+ return sanitizePath(loadPath + wxT("/../..") + pathToFind);
+ else
+ return wxEmptyString;
+ }
+ else
+ {
+ if (wxFile::Exists(loadPath + pathToFind))
+ return sanitizePath(loadPath + pathToFind);
+ else if (wxFile::Exists(loadPath + wxT("/../pgAdmin III") + pathToFind))
+ return sanitizePath(loadPath + wxT("/../pgAdmin III") + pathToFind);
+ else if (wxFile::Exists(loadPath + wxT("/..") + pathToFind))
+ return sanitizePath(loadPath + wxT("/..") + pathToFind);
+ else if (wxFile::Exists(loadPath + wxT("/../..") + pathToFind))
+ return sanitizePath(loadPath + wxT("/../..") + pathToFind);
+ else
+ return wxEmptyString;
+ }
+
+#else
+ wxString dataDir, thePath;
+
+#ifdef __WXMAC__
- // Now sanitize all the paths
- loadPath = sanitizePath(loadPath);
- docPath = sanitizePath(docPath);
- uiPath = sanitizePath(uiPath);
- i18nPath = sanitizePath(i18nPath);
- brandingPath = sanitizePath(brandingPath);
- utilitiesIni = sanitizePath(utilitiesIni);
+ // When using wxStandardPaths on OSX, wx default to the unix,
+ // not to the mac variants. Therefore, we request wxStandardPathsCF
+ // directly.
+ wxStandardPathsCF stdPaths ;
+ dataDir = stdPaths.GetDataDir() ;
+
+#else // other *ixes
+
+// Data path (defined by configure under Unix).
+#ifndef DATA_DIR
+#define DATA_DIR "./"
+#endif
+
+ dataDir = wxString::FromAscii(DATA_DIR);
+#endif
+
+ // On unix systems, the search path is as follows:
+ //
+ // 1) DATADIR/xxx - DATADIR being defined by configure
+ // 2) ./../share/pgadmin3/xxx - The default 'make install' layout, but allowing for relocation
+ // 3) ./xxx - Windows-style standalone install
+ // 4) ./../xxx - Unix-style standalone install (with binaries in a bin directory)
+
+ if (!isFile)
+ {
+ if (wxDir::Exists(dataDir + pathToFind))
+ return sanitizePath(dataDir + pathToFind);
+ else if (wxDir::Exists(loadPath + wxT("/../share/pgadmin3") + pathToFind))
+ return sanitizePath(loadPath + wxT("/../share/pgadmin3") + pathToFind);
+ else if (wxDir::Exists(loadPath + pathToFind))
+ return sanitizePath(loadPath + pathToFind);
+ else if (wxFile::Exists(loadPath + wxT("/..") + pathToFind))
+ return sanitizePath(loadPath + wxT("/..") + pathToFind);
+ else
+ return wxEmptyString;
+ }
+ else
+ {
+ if (wxFile::Exists(dataDir + pathToFind))
+ return sanitizePath(dataDir + pathToFind);
+ else if (wxFile::Exists(loadPath + wxT("/../share/pgadmin3") + pathToFind))
+ return sanitizePath(loadPath + wxT("/../share/pgadmin3") + pathToFind);
+ else if (wxFile::Exists(loadPath + pathToFind))
+ return sanitizePath(loadPath + pathToFind);
+ else if (wxFile::Exists(loadPath + wxT("/..") + pathToFind))
+ return sanitizePath(loadPath + wxT("/..") pathToFind);
+ else
+ return wxEmptyString;
+ }
+
+#endif
}
void pgAdmin3::InitHelp()
// wxWindows headers
#include <wx/wx.h>
#include <wx/config.h>
+#include <wx/fileconf.h>
#include <wx/url.h>
#include <wx/stdpaths.h>
+#include <wx/wfstream.h>
// App headers
#include "utils/sysSettings.h"
#include "utils/sysLogger.h"
#include "utils/misc.h"
-extern wxString docPath;
-
-
-
sysSettings::sysSettings(const wxString& name) : wxConfig(name)
{
+ // Open the default settings file
+ defaultSettings = NULL;
+ if (!settingsIni.IsEmpty())
+ {
+ wxFileStream fst(settingsIni);
+ defaultSettings = new wxFileConfig(fst);
+ }
// Convert setting from pre-1.3
#ifdef __WXMSW__
moveLongValue(wxT("Servers/SSL%d"), wxT("Servers/%d/SSL"), i);
}
}
-
// Tip Of The Day
Read(wxT("ShowTipOfTheDay"), &showTipOfTheDay, true);
Write(wxT("Font"), fontName);
}
+// Read a string value
+bool sysSettings::Read(const wxString& key, wxString* str, const wxString& defaultVal) const
+{
+ wxString actualDefault = defaultVal;
+
+ // Get the default from the defaults file, in preference
+ // to the hardcoded value
+ if (defaultSettings)
+ defaultSettings->Read(key, &actualDefault, defaultVal);
+
+ return wxConfig::Read(key, str, actualDefault);
+}
+
+// Return a string value
+wxString sysSettings::Read(const wxString& key, const wxString &defaultVal) const
+{
+ wxString actualDefault = defaultVal;
+
+ // Get the default from the defaults file, in preference
+ // to the hardcoded value
+ if (defaultSettings)
+ defaultSettings->Read(key, &actualDefault, defaultVal);
+
+ return wxConfig::Read(key, actualDefault);
+}
+
+// Read an int value
+bool sysSettings::Read(const wxString& key, int* i, int defaultVal) const
+{
+ int actualDefault = defaultVal;
+
+ // Get the default from the defaults file, in preference
+ // to the hardcoded value
+ if (defaultSettings)
+ defaultSettings->Read(key, &actualDefault, defaultVal);
+
+ return wxConfig::Read(key, i, actualDefault);
+}
+
+// Read a long value
+bool sysSettings::Read(const wxString& key, long* l, long defaultVal) const
+{
+ long actualDefault = defaultVal;
+
+ // Get the default from the defaults file, in preference
+ // to the hardcoded value
+ if (defaultSettings)
+ defaultSettings->Read(key, &actualDefault, defaultVal);
+
+ return wxConfig::Read(key, l, actualDefault);
+}
+
+
+// Return a long value
+long sysSettings::Read(const wxString& key, long defaultVal) const
+{
+ long actualDefault = defaultVal;
+
+ // Get the default from the defaults file, in preference
+ // to the hardcoded value
+ if (defaultSettings)
+ defaultSettings->Read(key, &actualDefault, defaultVal);
+
+ return wxConfig::Read(key, actualDefault);
+}
+
+// Read a boolean value
bool sysSettings::Read(const wxString& key, bool *val, bool defaultVal) const
{
+ wxString actualDefault = BoolToStr(defaultVal);
wxString str;
- Read(key, &str, BoolToStr(defaultVal));
+
+ // Get the default from the defaults file, in preference
+ // to the hardcoded value
+ if (defaultSettings)
+ defaultSettings->Read(key, &actualDefault, BoolToStr(defaultVal));
+
+ Read(key, &str, actualDefault);
*val = StrToBool(str);
return true;
}
+// Read a point value
+wxPoint sysSettings::Read(const wxString& key, const wxPoint &defaultVal) const
+{
+ wxPoint actualDefault = defaultVal;
+
+ // Get the default from the defaults file, in preference
+ // to the hardcoded value
+ if (defaultSettings)
+ {
+ actualDefault.x = defaultSettings->Read(key + wxT("/Left"), defaultVal.x);
+ actualDefault.y = defaultSettings->Read(key + wxT("/Top"), defaultVal.y);
+ }
+
+ return wxPoint(wxConfig::Read(key + wxT("/Left"), actualDefault.x),
+ wxConfig::Read(key + wxT("/Top"), actualDefault.y));
+}
+
+// Read a size value
+wxSize sysSettings::Read(const wxString& key, const wxSize &defaultVal) const
+{
+ wxSize actualDefault = defaultVal;
+
+ // Get the default from the defaults file, in preference
+ // to the hardcoded value
+ if (defaultSettings)
+ {
+ actualDefault.x = defaultSettings->Read(key + wxT("/Width"), defaultVal.x);
+ actualDefault.y = defaultSettings->Read(key + wxT("/Height"), defaultVal.y);
+ }
+
+ return wxSize(wxConfig::Read(key + wxT("/Width"), actualDefault.x),
+ wxConfig::Read(key + wxT("/Height"), actualDefault.y));
+}
+
+// Write a boolean value
bool sysSettings::Write(const wxString &key, bool value)
{
return Write(key, BoolToStr(value));
}
+// Write a point value
bool sysSettings::Write(const wxString &key, const wxPoint &value)
{
bool rc=wxConfig::Write(key + wxT("/Left"), value.x);
return rc;
}
-
+// Write a size value
bool sysSettings::Write(const wxString &key, const wxSize &value)
{
bool rc=wxConfig::Write(key + wxT("/Width"), value.x);
return rc;
}
-
-wxPoint sysSettings::Read(const wxString& key, const wxPoint &defaultVal) const
-{
- return wxPoint(wxConfig::Read(key + wxT("/Left"), defaultVal.x),
- wxConfig::Read(key + wxT("/Top"), defaultVal.y));
-}
-
-
-wxSize sysSettings::Read(const wxString& key, const wxSize &defaultVal) const
-{
- return wxSize(wxConfig::Read(key + wxT("/Width"), defaultVal.x),
- wxConfig::Read(key + wxT("/Height"), defaultVal.y));
-}
-
//////////////////////////////////////////////////////////////////////////
// Tip of the Day
//////////////////////////////////////////////////////////////////////////