-
Notifications
You must be signed in to change notification settings - Fork 1
/
PlaylistAutoStop_Defines.pas
175 lines (145 loc) · 4.52 KB
/
PlaylistAutoStop_Defines.pas
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
unit PlaylistAutoStop_Defines;
interface
uses
Windows, Classes,
AIMPCustomPlugin,
apiObjects;
type
TSettings = record
SwitchOff: Boolean;
Playlists: TStrings;
end;
TOnSettingsChange = procedure(const OldSettings, NewSettings: TSettings) of object;
TPlaylistType = (ptActive, ptPlaying);
const
myPluginName = 'Playlist autostop';
myPluginVersion = '1.2';
myPluginAuthor = 'Korney San';
myPluginShortDescription = 'Automatic stopping of selected playlist.';
myPluginFullDescription = '';
myPluginDLLName = 'PlaylistAutoStop';
myPluginDLLName1 = myPluginDLLName + '\';
myPluginLogName = myPluginDLLName1 + myPluginDLLName + '.log';
myPluginIniName = myPluginDLLName + '.ini';
//actions and menus
idActionSelectPlaylist = 'aimp.' + myPluginDLLName + '.action.selectplaylist';
sActionSelectPlaylist = 'Autostop current playlist';
idMenuSelectPlaylist = 'aimp.' + myPluginDLLName + '.menuitem.selectplaylist';
//ini
sectionOptions = 'Options';
sectionPlaylists = 'Playlists';
optSwitchOff = 'SwitchOff';
optSwitchOffDefault = True;
//localization
optFrameName = 'Plugin_FrameName';
categoryAutostop = 'catAutostop';
categoryAutostopDefault = 'Autostop settings';
var
StaticWideString: array[0..MAX_PATH - 1] of WideChar;
mySettings: TSettings;
procedure InitializeSettings(AUserProfilePath: string);
procedure LoadSettings(var Settings: TSettings);
procedure SaveSettings(const Settings: TSettings);
procedure UpdateSettings(var Settings: TSettings; const PID2Remove: string);
procedure FinalizeSettings;
function LocalizedFrameName: WideString;
function MakeSettingName(const Section, Value: WideString): WideString;
function GetLocalization(const Item: WideString; Default: WideString = ''): WideString;
function GetLocalizationEx(const Section, Item: UnicodeString; Default: UnicodeString = ''; TryCommon: Boolean = true): IAIMPString; overload;
implementation
uses
SysUtils, IniFiles, apiWrappers;
const
sFormatSettingValueName = '%s\%s';
var
myPlugin: TAIMPCustomPlugin = nil;
myIniFile: TIniFile = nil;
UserProfilePath: string = '';
function MakeSettingName(const Section, Value: WideString): WideString;
begin
Result := Format(sFormatSettingValueName, [Section, Value]);
end;
procedure InitializeSettings(AUserProfilePath: string);
begin
mySettings.Playlists := TStringList.Create;
UserProfilePath := IncludeTrailingPathDelimiter(AUserProfilePath);
myIniFile := TIniFile.Create(UserProfilePath + myPluginIniName);
end;
procedure LoadSettings(var Settings: TSettings);
begin
with Settings, myIniFile do
begin
SwitchOff := ReadBool(sectionOptions, optSwitchOff, optSwitchOffDefault);
Playlists.Clear;
ReadSection(sectionPlaylists, Playlists);
end;
end;
procedure SaveSettings(const Settings: TSettings);
var
i: Integer;
begin
with Settings, myIniFile do
begin
WriteBool(sectionOptions, optSwitchOff, SwitchOff);
EraseSection(sectionPlaylists);
for i := 0 to Playlists.Count - 1 do
WriteString(sectionPlaylists, Playlists[i], '');
end;
end;
procedure UpdateSettings(var Settings: TSettings; const PID2Remove: string);
var
i: Integer;
begin
with Settings, myIniFile do
begin
i := Playlists.IndexOf(PID2Remove);
if i >= 0 then
begin
myIniFile.DeleteKey(sectionPlaylists, PID2Remove);
Playlists.Delete(i);
end;
end;
end;
procedure FinalizeSettings;
begin
if Assigned(myIniFile) then
begin
myIniFile.UpdateFile;
FreeAndNil(myIniFile);
end;
if Assigned(mySettings.Playlists) then
FreeAndNil(mySettings.Playlists);
myPlugin := nil;
end;
function LocalizedFrameName: WideString;
begin
Result := LangLoadString(MakeSettingName(myPluginDLLName, optFrameName));
if Result = '' then
Result := myPluginName;
end;
function GetLocalization(const Item: WideString; Default: WideString = ''): WideString;
begin
Result := LangLoadString(MakeSettingName(myPluginDLLName, Item));
if Result = '' then
begin
Result := LangLoadString(MakeSettingName('Common', Item));
if Result = '' then
Result := Default;
end;
end;
function GetLocalizationEx(const Section, Item: UnicodeString; Default: UnicodeString = ''; TryCommon: Boolean = true): IAIMPString; overload;
begin
Result := LangLoadStringEx(MakeSettingName(Section, Item));
if Result.GetLength = 0 then
begin
if TryCommon then
begin
Result := LangLoadStringEx(MakeSettingName('Common', Item));
if Result.GetLength = 0 then
Result := MakeString(Default);
end
else
Result := MakeString(Default);
end;
end;
end.