Audacity 3.2.0
ModuleSettings.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 @file ModuleSettings.cpp
6
7 Paul Licameli split from ModulePrefs.cpp
8
9**********************************************************************/
10
11#include "ModuleSettings.h"
12
13#include "Prefs.h"
14
15#include <unordered_set>
16#include <wx/filename.h>
17
18static const std::unordered_set<wxString> &autoEnabledModules()
19{
20 // Add names to this list, of modules that are expected to ship
21 // with Audacity and enable automatically.
22 static std::unordered_set<wxString> modules{
23 };
24 return modules;
25}
26
27// static function that tells us about a module.
29{
30 // Default status is NEW module, and we will ask once.
31 int iStatus = kModuleNew;
32
33 wxFileName FileName( fname );
34 wxString ShortName = FileName.GetName().Lower();
35
36 wxString PathPref = wxString( wxT("/ModulePath/") ) + ShortName;
37 wxString StatusPref = wxString( wxT("/Module/") ) + ShortName;
38 wxString DateTimePref = wxString( wxT("/ModuleDateTime/") ) + ShortName;
39
40 wxString ModulePath = gPrefs->Read( PathPref, wxEmptyString );
41 if( ModulePath.IsSameAs( fname ) )
42 {
43 gPrefs->Read( StatusPref, &iStatus, kModuleNew );
44
45 wxDateTime DateTime = FileName.GetModificationTime();
46 wxDateTime OldDateTime;
47 OldDateTime.ParseISOCombined( gPrefs->Read( DateTimePref, wxEmptyString ) );
48
49 // Some platforms return milliseconds, some do not...level the playing field
50 DateTime.SetMillisecond( 0 );
51 OldDateTime.SetMillisecond( 0 );
52
53 // fix up a bad status or reset for newer module
54 if( iStatus > kModuleNew || !OldDateTime.IsEqualTo( DateTime ) )
55 {
56 iStatus=kModuleNew;
57 }
58 }
59 else
60 {
61 // Remove previously saved since it's no longer valid
62 gPrefs->DeleteEntry( PathPref );
63 gPrefs->DeleteEntry( StatusPref );
64 gPrefs->DeleteEntry( DateTimePref );
65 }
66
67 if (iStatus == kModuleNew) {
68 if (autoEnabledModules().count(ShortName))
69 iStatus = kModuleEnabled;
70 }
71
72 return iStatus;
73}
74
75void ModuleSettings::SetModuleStatus(const FilePath &fname, int iStatus)
76{
77 wxFileName FileName( fname );
78 wxDateTime DateTime = FileName.GetModificationTime();
79 wxString ShortName = FileName.GetName().Lower();
80
81 wxString PrefName = wxString( wxT("/Module/") ) + ShortName;
82 gPrefs->Write( PrefName, iStatus );
83
84 PrefName = wxString( wxT("/ModulePath/") ) + ShortName;
85 gPrefs->Write( PrefName, fname );
86
87 PrefName = wxString( wxT("/ModuleDateTime/") ) + ShortName;
88 gPrefs->Write( PrefName, DateTime.FormatISOCombined() );
89
90 gPrefs->Flush();
91}
92
wxT("CloseDown"))
static const std::unordered_set< wxString > & autoEnabledModules()
@ kModuleNew
@ kModuleEnabled
FileConfig * gPrefs
Definition: Prefs.cpp:70
wxString FilePath
Definition: Project.h:21
virtual bool DeleteEntry(const wxString &key, bool bDeleteGroupIfEmpty=true) wxOVERRIDE
Definition: FileConfig.cpp:209
virtual bool Flush(bool bCurrentOnly=false) wxOVERRIDE
Definition: FileConfig.cpp:143
MODULE_MANAGER_API void SetModuleStatus(const FilePath &fname, int iStatus)
MODULE_MANAGER_API int GetModuleStatus(const FilePath &fname)