forked from Sneeds-Feed-and-Seed/sneedacity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModuleSettings.cpp
92 lines (69 loc) · 2.63 KB
/
ModuleSettings.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
/**********************************************************************
Sneedacity: A Digital Audio Editor
@file ModuleSettings.cpp
Paul Licameli split from ModulePrefs.cpp
**********************************************************************/
#include "ModuleSettings.h"
#include "Prefs.h"
#include <unordered_set>
#include <wx/filename.h>
static const std::unordered_set<wxString> &autoEnabledModules()
{
// Add names to this list, of modules that are expected to ship
// with Sneedacity and enable automatically.
static std::unordered_set<wxString> modules{
};
return modules;
}
// static function that tells us about a module.
int ModuleSettings::GetModuleStatus(const FilePath &fname)
{
// Default status is NEW module, and we will ask once.
int iStatus = kModuleNew;
wxFileName FileName( fname );
wxString ShortName = FileName.GetName().Lower();
wxString PathPref = wxString( wxT("/ModulePath/") ) + ShortName;
wxString StatusPref = wxString( wxT("/Module/") ) + ShortName;
wxString DateTimePref = wxString( wxT("/ModuleDateTime/") ) + ShortName;
wxString ModulePath = gPrefs->Read( PathPref, wxEmptyString );
if( ModulePath.IsSameAs( fname ) )
{
gPrefs->Read( StatusPref, &iStatus, kModuleNew );
wxDateTime DateTime = FileName.GetModificationTime();
wxDateTime OldDateTime;
OldDateTime.ParseISOCombined( gPrefs->Read( DateTimePref, wxEmptyString ) );
// Some platforms return milliseconds, some do not...level the playing field
DateTime.SetMillisecond( 0 );
OldDateTime.SetMillisecond( 0 );
// fix up a bad status or reset for newer module
if( iStatus > kModuleNew || !OldDateTime.IsEqualTo( DateTime ) )
{
iStatus=kModuleNew;
}
}
else
{
// Remove previously saved since it's no longer valid
gPrefs->DeleteEntry( PathPref );
gPrefs->DeleteEntry( StatusPref );
gPrefs->DeleteEntry( DateTimePref );
}
if (iStatus == kModuleNew) {
if (autoEnabledModules().count(ShortName))
iStatus = kModuleEnabled;
}
return iStatus;
}
void ModuleSettings::SetModuleStatus(const FilePath &fname, int iStatus)
{
wxFileName FileName( fname );
wxDateTime DateTime = FileName.GetModificationTime();
wxString ShortName = FileName.GetName().Lower();
wxString PrefName = wxString( wxT("/Module/") ) + ShortName;
gPrefs->Write( PrefName, iStatus );
PrefName = wxString( wxT("/ModulePath/") ) + ShortName;
gPrefs->Write( PrefName, fname );
PrefName = wxString( wxT("/ModuleDateTime/") ) + ShortName;
gPrefs->Write( PrefName, DateTime.FormatISOCombined() );
gPrefs->Flush();
}