|
From: <pst...@us...> - 2008-03-30 12:07:04
|
Revision: 363
http://jazzplusplus.svn.sourceforge.net/jazzplusplus/?rev=363&view=rev
Author: pstieber
Date: 2008-03-30 05:07:02 -0700 (Sun, 30 Mar 2008)
Log Message:
-----------
1. Changed File to GetFileName and made it private.
2. Added a data member to record the name of the configuration file. If
this variable is set, GetFileName can avoid calls to FindFile.
Modified Paths:
--------------
trunk/jazz/src/Configuration.cpp
trunk/jazz/src/Configuration.h
Modified: trunk/jazz/src/Configuration.cpp
===================================================================
--- trunk/jazz/src/Configuration.cpp 2008-03-30 12:00:14 UTC (rev 362)
+++ trunk/jazz/src/Configuration.cpp 2008-03-30 12:07:02 UTC (rev 363)
@@ -114,7 +114,8 @@
tConfig::tConfig()
- : mDrumNames(),
+ : mFileName(),
+ mDrumNames(),
mDrumSets(),
mCtrlNames(),
mVoiceNames(),
@@ -336,16 +337,27 @@
return -1;
}
-// Return the Jazz++ configuration file name, normally jazz.cfg.
-// Search in the path provided by FindFile()
-wxString tConfig::File()
+//-----------------------------------------------------------------------------
+// Description:
+// Return the Jazz++ configuration file name, normally jazz.cfg. If the
+// value has not been set by an earlier call to LoadConfig, attempt to find
+// the file using FindFile().
+//-----------------------------------------------------------------------------
+wxString tConfig::GetFileName()
{
- wxString FileName = FindFile("jazz.cfg");
- if (FileName.IsEmpty())
+ if (!mFileName.empty())
{
- FileName = FindFile(".jazz");
+ return mFileName;
}
- return FileName;
+
+ mFileName = FindFile("jazz.cfg");
+
+ if (mFileName.empty())
+ {
+ mFileName = FindFile(".jazz");
+ }
+
+ return mFileName;
}
int tConfig::Load(char* buf)
@@ -418,7 +430,7 @@
{
assert((entry >= 0) && (entry < NumConfigNames));
- wxString FileName = File();
+ wxString FileName = GetFileName();
if (FileName.IsEmpty())
{
return false;
@@ -458,15 +470,17 @@
return false;
}
+//-----------------------------------------------------------------------------
// Description:
// Write a configuration entry by making a temp file, and copying all
// entries to there. If the name/value pair is found, replace it, otherwise
// write it. Finally copy the temp file over the old configuration file.
+//-----------------------------------------------------------------------------
bool tConfig::Put(int Index, const char *value)
{
assert((Index >= 0) && (Index < NumConfigNames));
- wxString FileName = File();
+ wxString FileName = GetFileName();
if (FileName.IsEmpty())
{
return false;
@@ -539,9 +553,16 @@
//-----------------------------------------------------------------------------
void tConfig::LoadConfig(const wxString& FileName)
{
+ if (!::wxFileExists(FileName))
+ {
+ return;
+ }
+
+ mFileName = FileName;
+
wxString OriginalCurrentWorkingDirectory = ::wxGetCwd();
- wxFileName FileNameObject(FileName);
+ wxFileName FileNameObject(mFileName);
wxString Path = FileNameObject.GetPath();
::wxSetWorkingDirectory(Path);
@@ -562,10 +583,12 @@
FdArr[i] = NULL;
}
- cout << "tConfig::LoadConfig \"" << FileName << '"' << endl;
+ cout
+ << "tConfig::LoadConfig:" << '\n'
+ << " \"" << mFileName << '"'
+ << endl;
- FdArr[IncLevel] = fopen(FileName.c_str(), "r");
- cout << FileName << endl;
+ FdArr[IncLevel] = fopen(mFileName.c_str(), "r");
if (FdArr[IncLevel] == NULL)
{
wxMessageBox(
Modified: trunk/jazz/src/Configuration.h
===================================================================
--- trunk/jazz/src/Configuration.h 2008-03-30 12:00:14 UTC (rev 362)
+++ trunk/jazz/src/Configuration.h 2008-03-30 12:07:02 UTC (rev 363)
@@ -181,8 +181,6 @@
void LoadConfig(const wxString& FileName);
- wxString File();
-
int Check(const char* pName) const;
int Load(char* buf);
@@ -232,6 +230,16 @@
private:
+ // Description:
+ // Return the Jazz++ configuration file name, normally jazz.cfg. If the
+ // value has not been set by an earlier call to LoadConfig, attempt to
+ // find the file using FindFile().
+ wxString GetFileName();
+
+ private:
+
+ wxString mFileName;
+
tConfigEntry* Names[NumConfigNames];
std::vector<std::pair<std::string, int> > mDrumNames;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|