Do not hardcode PERFORMANCE_DIR

switch_perf_dir
probonopd 12 months ago committed by GitHub
parent 27688f323e
commit 2eb2809a61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 32
      src/performanceconfig.cpp

@ -25,6 +25,7 @@
#include "mididevice.h" #include "mididevice.h"
#include <cstring> #include <cstring>
#include <algorithm> #include <algorithm>
#include "minidexed.h"
LOGMODULE ("Performance"); LOGMODULE ("Performance");
@ -796,7 +797,7 @@ bool CPerformanceConfig::CreateNewPerformanceFile(void)
m_nPerformanceFileName[nLastPerformance]= nFileName; m_nPerformanceFileName[nLastPerformance]= nFileName;
nPath = "SD:/" ; nPath = "SD:/" ;
nPath += PERFORMANCE_DIR; nPath += GetPerformanceDir();
nPath += "/"; nPath += "/";
nFileName = nPath + nFileName; nFileName = nPath + nFileName;
@ -833,7 +834,10 @@ bool CPerformanceConfig::ListPerformances()
FILINFO FileInfo; FILINFO FileInfo;
FRESULT Result; FRESULT Result;
// Check if internal "performance" directory exists // Check if internal "performance" directory exists
Result = f_opendir (&Directory, "SD:/" PERFORMANCE_DIR); std::string Path = "SD:/" ;
Path += GetPerformanceDir();
Result = f_opendir (&Directory, Path.c_str());
if (Result == FR_OK) if (Result == FR_OK)
{ {
nInternalFolderOk=true; nInternalFolderOk=true;
@ -841,14 +845,14 @@ bool CPerformanceConfig::ListPerformances()
} }
else else
{ {
// attenpt to create the folder // attempt to create the folder
Result = f_mkdir("SD:/" PERFORMANCE_DIR); Result = f_mkdir(Path.c_str());
nInternalFolderOk = (Result == FR_OK); nInternalFolderOk = (Result == FR_OK);
} }
if (nInternalFolderOk) if (nInternalFolderOk)
{ {
Result = f_findfirst (&Directory, &FileInfo, "SD:/" PERFORMANCE_DIR, "*.ini"); Result = f_findfirst (&Directory, &FileInfo, Path.c_str(), "*.ini");
for (unsigned i = 0; Result == FR_OK && FileInfo.fname[0]; i++) for (unsigned i = 0; Result == FR_OK && FileInfo.fname[0]; i++)
{ {
if (nLastPerformance >= NUM_PERFORMANCES) { if (nLastPerformance >= NUM_PERFORMANCES) {
@ -892,7 +896,7 @@ void CPerformanceConfig::SetNewPerformance (unsigned nID)
std::string FileN = ""; std::string FileN = "";
if (nID != 0) // in order to assure retrocompatibility if (nID != 0) // in order to assure retrocompatibility
{ {
FileN += PERFORMANCE_DIR; FileN += GetPerformanceDir();
FileN += "/"; FileN += "/";
} }
FileN += m_nPerformanceFileName[nID]; FileN += m_nPerformanceFileName[nID];
@ -928,8 +932,7 @@ bool CPerformanceConfig::DeletePerformance(unsigned nID)
DIR Directory; DIR Directory;
FILINFO FileInfo; FILINFO FileInfo;
std::string FileN = "SD:/"; std::string FileN = "SD:/";
FileN += PERFORMANCE_DIR; FileN += GetPerformanceDir();
FRESULT Result = f_findfirst (&Directory, &FileInfo, FileN.c_str(), m_nPerformanceFileName[nID].c_str()); FRESULT Result = f_findfirst (&Directory, &FileInfo, FileN.c_str(), m_nPerformanceFileName[nID].c_str());
if (Result == FR_OK && FileInfo.fname[0]) if (Result == FR_OK && FileInfo.fname[0])
@ -951,3 +954,16 @@ bool CPerformanceConfig::DeletePerformance(unsigned nID)
} }
return bOK; return bOK;
} }
const char *CPerformanceConfig::GetPerformanceDir (void) const
{
return m_PerformanceDir.c_str();
}
void CPerformanceConfig::SetPerformanceDir (const char *pDir)
{
m_PerformanceDir = pDir;
// TODO: Load performance files from new directory
}

Loading…
Cancel
Save