-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestCSharpDll.cs
More file actions
267 lines (231 loc) · 11.5 KB
/
Copy pathTestCSharpDll.cs
File metadata and controls
267 lines (231 loc) · 11.5 KB
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
using System;
using System.Collections.Generic;
using System.Data.SQLite;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
namespace MusicBeePlugin
{
public partial class Plugin
{
private MusicBeeApiInterface mbApiInterface;
private PluginInfo about = new PluginInfo();
System.Windows.Forms.ComboBox textBox;
System.Windows.Forms.NumericUpDown skipThresholdBox;
int? savedSeconds=null;
int? savedSkipThreshold=null;
public PluginInfo Initialise(IntPtr apiInterfacePtr)
{
try
{
mbApiInterface = new MusicBeeApiInterface();
mbApiInterface.Initialise(apiInterfacePtr);
about.PluginInfoVersion = PluginInfoVersion;
about.Name = "Detailed History";
about.Description = "A history plugin for MusicBee. Sees (nearly) everything that happens to the playhead.";
about.Author = "mkDaniel";
about.TargetApplication = "Detailed History"; // the name of a Plugin Storage device or panel header for a dockable panel
about.Type = PluginType.General;
about.VersionMajor = 1; // your plugin version
about.VersionMinor = 0;
about.Revision = 1;
about.MinInterfaceVersion = MinInterfaceVersion;
about.MinApiRevision = MinApiRevision;
about.ReceiveNotifications = (ReceiveNotificationFlags)0xff;
about.ConfigurationPanelHeight = 25; // height in pixels that musicbee should reserve in a panel for config settings. When set, a handle to an empty panel will be passed to the Configure function
InitDatabase();
return about;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message + "\n\n" + ex.StackTrace);
return null;
}
}
public bool Configure(IntPtr panelHandle)
{
string dataPath = mbApiInterface.Setting_GetPersistentStoragePath();
if (panelHandle != IntPtr.Zero)
{
Panel configPanel = (Panel)Control.FromHandle(panelHandle);
Label prompt = new Label();
prompt.AutoSize = true;
prompt.Location = new Point(0, 0);
prompt.Text = "time to show:";
configPanel.Controls.Add(prompt);
textBox = new System.Windows.Forms.ComboBox();
var options = new[]
{
new KeyValuePair<string, int>("1 hour", 3600),
new KeyValuePair<string, int>("6 hours", 21600),
new KeyValuePair<string, int>("12 hours", 43200),
new KeyValuePair<string, int>("1 day", 86400),
new KeyValuePair<string, int>("3 days", 259200),
new KeyValuePair<string, int>("1 week", 604800),
new KeyValuePair<string, int>("2 weeks", 1209600),
new KeyValuePair<string, int>("1 month", 2592000),
new KeyValuePair<string, int>("3 months", 5184000),
new KeyValuePair<string, int>("6 months", 15552000),
new KeyValuePair<string, int>("1 year", 31536000),
new KeyValuePair<string, int>("All time", int.MaxValue)
};
textBox.DisplayMember = "Key";
textBox.ValueMember = "Value";
textBox.DataSource = options;
textBox.Bounds = new Rectangle(prompt.Location.X + prompt.Width + 10, 0, 100, textBox.Height);
string appDataPath = mbApiInterface.Setting_GetPersistentStoragePath();
string dbFullPath = Path.Combine(appDataPath, DBNAME);
if (savedSeconds is null)
{
using (SQLiteConnection conn = new SQLiteConnection($"Data Source={dbFullPath};Version=3;"))
{
conn.Open();
using (SQLiteCommand c = new SQLiteCommand("SELECT VALUE FROM SETTINGS WHERE ID='history_time'", conn))
{
object result = c.ExecuteScalar();
if (result != null && result != DBNull.Value)
{
savedSeconds = Convert.ToInt32(result);
}
}
}
}
configPanel.Controls.Add(textBox);
textBox.SelectedValue = savedSeconds ?? options[5].Value;
Label prompt2 = new Label();
prompt2.AutoSize = true;
prompt2.Location = new Point(textBox.Bounds.Right + 20, 0);
prompt2.Text = "skip threshold:";
configPanel.Controls.Add(prompt2);
skipThresholdBox = new System.Windows.Forms.NumericUpDown();
skipThresholdBox.Minimum = 0;
skipThresholdBox.Maximum = 100;
skipThresholdBox.Increment = 5;
skipThresholdBox.DecimalPlaces = 0;
skipThresholdBox.Bounds = new Rectangle(prompt2.Location.X + prompt2.Width + 10, 0, 50, skipThresholdBox.Height);
if (savedSkipThreshold is null)
{
using (SQLiteConnection conn = new SQLiteConnection($"Data Source={dbFullPath};Version=3;"))
{
conn.Open();
using (SQLiteCommand c = new SQLiteCommand("SELECT VALUE FROM SETTINGS WHERE ID='skip_threshold'", conn))
{
object result = c.ExecuteScalar();
if (result != null && result != DBNull.Value)
{
savedSkipThreshold = Convert.ToInt32(result);
}
}
}
}
configPanel.Controls.Add(skipThresholdBox);
skipThresholdBox.Value = savedSkipThreshold ?? 30;
}
return true;
}
// called by MusicBee when the user clicks Apply or Save in the MusicBee Preferences screen.
// its up to you to figure out whether anything has changed and needs updating
public void SaveSettings()
{
string appDataPath = mbApiInterface.Setting_GetPersistentStoragePath();
string dbFullPath = Path.Combine(appDataPath, DBNAME);
if (textBox.SelectedValue != null)
{
savedSeconds = (int?)textBox.SelectedValue;
using (SQLiteConnection conn = new SQLiteConnection($"Data Source={dbFullPath};Version=3;"))
{
conn.Open();
using (SQLiteCommand c = new SQLiteCommand("INSERT OR REPLACE INTO SETTINGS (ID, VALUE) VALUES ('history_time', @value)", conn))
{
c.Parameters.AddWithValue("@value", savedSeconds);
c.ExecuteNonQuery();
}
}
}
savedSkipThreshold = (int)skipThresholdBox.Value;
using (SQLiteConnection conn = new SQLiteConnection($"Data Source={dbFullPath};Version=3;"))
{
conn.Open();
using (SQLiteCommand c = new SQLiteCommand("INSERT OR REPLACE INTO SETTINGS (ID, VALUE) VALUES ('skip_threshold', @value)", conn))
{
c.Parameters.AddWithValue("@value", savedSkipThreshold);
c.ExecuteNonQuery();
}
}
}
// MusicBee is closing the plugin (plugin is being disabled by user or MusicBee is shutting down)
public void Close(PluginCloseReason reason)
{
ReceiveNotification("", NotificationType.ShutdownStarted);
}
// uninstall this plugin - clean up any persisted files
public void Uninstall()
{
}
// return an array of lyric or artwork provider names this plugin supports
// the providers will be iterated through one by one and passed to the RetrieveLyrics/ RetrieveArtwork function in order set by the user in the MusicBee Tags(2) preferences screen until a match is found
//public string[] GetProviders()
//{
// return null;
//}
// return lyrics for the requested artist/title from the requested provider
// only required if PluginType = LyricsRetrieval
// return null if no lyrics are found
//public string RetrieveLyrics(string sourceFileUrl, string artist, string trackTitle, string album, bool synchronisedPreferred, string provider)
//{
// return null;
//}
// return Base64 string representation of the artwork binary data from the requested provider
// only required if PluginType = ArtworkRetrieval
// return null if no artwork is found
//public string RetrieveArtwork(string sourceFileUrl, string albumArtist, string album, string provider)
//{
// //Return Convert.ToBase64String(artworkBinaryData)
// return null;
//}
// presence of this function indicates to MusicBee that this plugin has a dockable panel. MusicBee will create the control and pass it as the panel parameter
// you can add your own controls to the panel if needed
// you can control the scrollable area of the panel using the mbApiInterface.MB_SetPanelScrollableArea function
// to set a MusicBee header for the panel, set about.TargetApplication in the Initialise function above to the panel header text
public int OnDockablePanelCreated(Control panel)
{
void BuildPanel()
{
panel.SuspendLayout();
panel.Controls.Clear();
var historyPanel = new HistoryControl(Path.Combine(mbApiInterface.Setting_GetPersistentStoragePath(), DBNAME), mbApiInterface)
{
AutoSize = false,
Dock = DockStyle.None,
Margin = Padding.Empty,
Padding = Padding.Empty
};
panel.Controls.Add(historyPanel);
void ResizeChild(object s, EventArgs e)
{
historyPanel.Bounds = panel.ClientRectangle;
}
panel.Resize -= ResizeChild;
panel.Resize += ResizeChild;
ResizeChild(panel, EventArgs.Empty);
panel.ResumeLayout(true);
}
if (panel.InvokeRequired) panel.Invoke((MethodInvoker)BuildPanel);
else BuildPanel();
return -1;
}
// presence of this function indicates to MusicBee that the dockable panel created above will show menu items when the panel header is clicked
// return the list of ToolStripMenuItems that will be displayed
//public List<ToolStripItem> GetHeaderMenuItems()
//{
// List<ToolStripItem> list = new List<ToolStripItem>();
// list.Add(new ToolStripMenuItem("A menu item"));
// return list;
//}
//private void panel_Paint(object sender, PaintEventArgs e)
//{
// e.Graphics.Clear(Color.Red);
// TextRenderer.DrawText(e.Graphics, "hello", SystemFonts.CaptionFont, new Point(10, 10), Color.Blue);
//}
}
}