forked from Sneeds-Feed-and-Seed/sneedacity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathActiveProjects.cpp
98 lines (70 loc) · 1.81 KB
/
ActiveProjects.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/**********************************************************************
Sneedacity: A Digital Audio Editor
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{};
}