1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-16 08:09:32 +02:00
audacity/src/ActiveProjects.cpp
Panagiotis Vasilopoulos 44968d3ac3
Rebranding: Replace 'Audacity: A Digital Audio Editor' in source files (#248)
List of commands that were executed in the `src directory`:
* sed -i 's/Audacity: A Digital Audio Editor/Tenacity/g' *.h
* sed -i 's/Audacity: A Digital Audio Editor/Tenacity/g' *.cpp

Signed-off-by: Panagiotis Vasilopoulos <hello@alwayslivid.com>
2021-07-13 09:30:42 +00:00

99 lines
1.8 KiB
C++

/**********************************************************************
Tenacity
ActiveProjects.cpp
********************************************************************//**
\class ActiveProjects
\brief Manages a list of active projects
*//********************************************************************/
#include "ActiveProjects.h"
#include "Prefs.h"
#include <wx/filename.h>
FilePaths ActiveProjects::GetAll()
{
FilePaths files;
wxString key;
long ndx;
wxString configPath = gPrefs->GetPath();
gPrefs->SetPath(wxT("/ActiveProjects"));
bool more = gPrefs->GetFirstEntry(key, ndx);
while (more)
{
wxFileName path = gPrefs->Read(key, wxT(""));
files.Add(path.GetFullPath());
more = gPrefs->GetNextEntry(key, ndx);
}
gPrefs->SetPath(configPath);
return files;
}
void ActiveProjects::Add(const FilePath &path)
{
wxString key = Find(path);
if (key.empty())
{
int i = 0;
do
{
key.Printf(wxT("/ActiveProjects/%d"), ++i);
} while (gPrefs->HasEntry(key));
gPrefs->Write(key, path);
gPrefs->Flush();
}
}
void ActiveProjects::Remove(const FilePath &path)
{
wxString key = Find(path);
if (!key.empty())
{
gPrefs->DeleteEntry(wxT("/ActiveProjects/" + key));
gPrefs->Flush();
}
}
wxString ActiveProjects::Find(const FilePath &path)
{
bool found = false;
wxString key;
long ndx;
wxString configPath = gPrefs->GetPath();
gPrefs->SetPath(wxT("/ActiveProjects"));
bool more = gPrefs->GetFirstEntry(key, ndx);
while (more)
{
if (gPrefs->Read(key, wxT("")).IsSameAs(path))
{
found = true;
break;
}
more = gPrefs->GetNextEntry(key, ndx);
}
gPrefs->SetPath(configPath);
return found ? key : wxString{};
}