From: <pst...@us...> - 2008-11-15 23:51:10
|
Revision: 630 http://jazzplusplus.svn.sourceforge.net/jazzplusplus/?rev=630&view=rev Author: pstieber Date: 2008-11-15 23:51:07 +0000 (Sat, 15 Nov 2008) Log Message: ----------- Changed the way the Jazz++ configuration file is found. Modified Paths: -------------- trunk/jazz/src/Project.cpp trunk/jazz/src/Project.h Modified: trunk/jazz/src/Project.cpp =================================================================== --- trunk/jazz/src/Project.cpp 2008-11-15 23:18:35 UTC (rev 629) +++ trunk/jazz/src/Project.cpp 2008-11-15 23:51:07 UTC (rev 630) @@ -21,6 +21,8 @@ //***************************************************************************** #include "WxWidgets.h" + +#include <wx/stdpaths.h> #include <wx/config.h> #include <wx/filename.h> #include <wx/file.h> @@ -363,63 +365,48 @@ //----------------------------------------------------------------------------- void JZProject::ReadConfiguration() { - wxConfigBase* pConfig = wxConfigBase::Get(); + wxString ConfigDir = wxStandardPaths::Get().GetUserDataDir(); - // Get the current working directory and append a directory separator. - wxString CurrentWorkingDirectory = - ::wxGetCwd() + wxFileName::GetPathSeparator(); + wxString JazzCfgFile = + ConfigDir + + wxFileName::GetPathSeparator() + + mConfFileName; - // Jazz++ should be distributed with a conf subdirectory under the - // executable directory. This will be our initial guess for the location of - // the Jazz++ configuration file. - wxString ConfFileDirectoryGuess = - CurrentWorkingDirectory + "conf" + wxFileName::GetPathSeparator(); - - // Attempt to obtain the path to the Jazz++ configuration file from the - // wxWidgets Jazz++ configuration file. - wxString ConfFilePath; - bool WasConfPathRead = false; - if (pConfig) - { - WasConfPathRead = pConfig->Read( - "/Paths/Conf", - &ConfFilePath, - ConfFileDirectoryGuess); - } - - // Construct a full Jazz++ configuration path and file name. - wxString ConfFileNameAndPath = ConfFilePath + mConfFileName; - // Test for the existence of the Jazz++ configuration file. - if (!::wxFileExists(ConfFileNameAndPath)) + bool ConfigurationFileFound = false; + if (!::wxFileExists(JazzCfgFile)) { // Return a valid path to the data. - FindAndRegisterConfFilePath(ConfFilePath); - ConfFileNameAndPath = ConfFilePath + mConfFileName; - - // Try one more time. - if (!::wxFileExists(ConfFileNameAndPath)) + wxString ConfFilePath; + if (FindAndRegisterConfFilePath(ConfFilePath)) { - ConfFileNameAndPath.clear(); + JazzCfgFile = ConfFilePath + mConfFileName; + + // Try one more time. + if (!::wxFileExists(JazzCfgFile)) + { + JazzCfgFile.clear(); + } + else + { + ConfigurationFileFound = true; + } } } + else + { + ConfigurationFileFound = true; + } - if (!ConfFileNameAndPath.IsEmpty()) + if (ConfigurationFileFound) { cout - << "JZProject::ReadConfiguration() ConfFileNameAndPath:" << '\n' - << " \"" << ConfFileNameAndPath << '"' + << "JZProject::ReadConfiguration() JazzCfgFile:" << '\n' + << " \"" << JazzCfgFile << '"' << endl; - mpConfig->LoadConfig(ConfFileNameAndPath); + mpConfig->LoadConfig(JazzCfgFile); } - else - { - wxMessageBox( - "Could not find configuration file.", - "Warning", - wxOK); - } } //----------------------------------------------------------------------------- @@ -429,25 +416,28 @@ // configuration entry so the code will find the configuration file path the // next time it starts. // -// Returns: +// Outputs: // wxString&: // A user selected path to the Jazz++ configuration file. +// +// Returns: +// bool: +// True if the configuration file path was set; false otherwise. //----------------------------------------------------------------------------- -void JZProject::FindAndRegisterConfFilePath(wxString& ConfFilePath) +bool JZProject::FindAndRegisterConfFilePath(wxString& ConfFilePath) const { wxString DialogTitle; DialogTitle = "Please Indicate the Location of " + mConfFileName; // Use an open dialog to find the Jazz++ configuration file. - // wxFD_CHANGE_DIR - Change the current working directory to the directory - // where the file(s) chosen by the user are. wxFileDialog OpenDialog( 0, DialogTitle, "", mConfFileName, "*.cfg", - wxFD_OPEN | wxFD_CHANGE_DIR); + wxFD_OPEN); + if (OpenDialog.ShowModal() == wxID_OK) { // Generate a c-style string that contains a path to the help file. @@ -463,7 +453,11 @@ // Return the user selected help file path. ConfFilePath = TempConfFilePath; + + return true; } + + return false; } //----------------------------------------------------------------------------- Modified: trunk/jazz/src/Project.h =================================================================== --- trunk/jazz/src/Project.h 2008-11-15 23:18:35 UTC (rev 629) +++ trunk/jazz/src/Project.h 2008-11-15 23:51:07 UTC (rev 630) @@ -165,7 +165,7 @@ void ReadConfiguration(); - void FindAndRegisterConfFilePath(wxString& ConfFilePath); + bool FindAndRegisterConfFilePath(wxString& ConfFilePath) const; private: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |