-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathMainForm.cs
859 lines (705 loc) · 32.3 KB
/
MainForm.cs
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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.IO;
using System.Windows.Forms;
using iTunesLib;
using System.Xml;
using System.Xml.Serialization;
using System.Runtime.InteropServices;
using System.Threading;
using System.Diagnostics;
using Notpod.Configuration12;
using Notpod.Properties;
using System.Security.AccessControl;
using log4net;
namespace Notpod
{
public partial class MainForm : Form
{
private ILog l = LogManager.GetLogger(typeof(MainForm));
//Constants used when intercepting system messages
public const int WM_SYSCOMMAND = 0x112;
public const int SC_MINIMIZE = 0xF020;
/// <summary>
/// The path where the configuration is stored.
/// </summary>
public static readonly string DATA_PATH = ConfigurationHelper.GetAppDataPath();
private ITunesAppFactory itunesAppFactory = new DefaultITunesAppFactory();
private iTunesApp itunes;
private IITUserPlaylist folderMyDevices;
private IConnectedDevicesManager connectedDevices;
private DeviceConfiguration deviceConfiguration;
private SyncPatternCollection syncPatterns;
private Configuration configuration;
private ISynchronizeForm syncForm;
private Hashtable deviceInitialPlaylists = new Hashtable();
/// <summary>
/// Create a new instance of MainForm.
/// </summary>
public MainForm()
{
InitializeComponent();
}
/// <summary>
/// Event handler for the form load event.
/// </summary>
/// <param name="sender">Sender</param>
/// <param name="e">Event arguments</param>
private void MainForm_Load(object sender, EventArgs e)
{
l.Info("Notpod is initializing...");
this.Visible = false;
this.ShowInTaskbar = true;
// Check application configuration
if (!File.Exists(MainForm.DATA_PATH + "\\.ita-convert"))
{
if (!ConfigurationHelper.MovePreNotpodConfiguration())
{
Application.Exit();
return;
}
}
//Try loading the configuration
StreamReader stream = null;
XmlTextReader reader = null;
try
{
XmlSerializer serializer = new XmlSerializer(typeof(Configuration));
stream = new StreamReader(MainForm.DATA_PATH + "\\notpod-config.xml");
reader = new XmlTextReader(stream);
configuration = (Configuration)serializer.Deserialize(reader);
}
catch (Exception ex)
{
string message = "I could not locate 'notpod-config.xml' which contains configuration data,"
+ " or the file exists, but is invalid. Please make sure this file is "
+ "valid and restart me.\n\nError message: " + ex.Message;
l.Error(message, ex);
MessageBox.Show(message, "Configuration not available",
MessageBoxButtons.OK, MessageBoxIcon.Error);
Application.Exit();
return;
}
finally
{
if (stream != null)
stream.Close();
if (reader != null)
reader.Close();
}
//Load devices that the agent recognizes
StreamReader dcStream = null;
XmlTextReader dcReader = null;
try
{
XmlSerializer serializer = new XmlSerializer(typeof(DeviceConfiguration));
dcStream = new StreamReader(MainForm.DATA_PATH + "\\device-config.xml");
dcReader = new XmlTextReader(dcStream);
deviceConfiguration = (DeviceConfiguration)serializer.Deserialize(dcReader);
}
catch (Exception ex)
{
l.Error(ex);
MessageBox.Show("Unable to locate list of known devices. The agent needs this list.\n\nReason for failure: " + ex.Message,
"Missing list of devices", MessageBoxButtons.OK, MessageBoxIcon.Error);
Application.Exit();
}
finally
{
if (dcStream != null)
dcStream.Close();
if (dcReader != null)
dcReader.Close();
}
LoadSyncPatterns();
deviceConfiguration.SyncPattern = syncPatterns.SyncPatterns;
if (!CreateITunesInstance())
{
Application.Exit();
return;
}
if (configuration.UseListFolder)
CreateMyDevicesFolder();
//Create ConnectedDevice instance which maintains a list of connected devices.
connectedDevices = new ConnectedDevicesManagerImpl();
connectedDevices.DeviceConfig = deviceConfiguration;
connectedDevices.DeviceConnected += new DeviceConnectedEventHandler(OnDeviceConnected);
connectedDevices.DeviceDisconnected += new DeviceDisconnectedEventHandler(OnDeviceDisconnect);
timerDriveListUpdate.Start();
}
private void LoadSyncPatterns() {
//Load devices that the agent recognizes
StreamReader stream = null;
XmlTextReader reader = null;
try
{
XmlSerializer serializer = new XmlSerializer(typeof(SyncPatternCollection));
stream = new StreamReader(Application.StartupPath + "\\Resources\\syncpatterns.xml");
reader = new XmlTextReader(stream);
syncPatterns = (SyncPatternCollection)serializer.Deserialize(reader);
}
catch (Exception ex)
{
l.Error(ex);
MessageBox.Show("Unable to load available synchronize patterns.\n\nReason for failure: " + ex.Message,
"Missing synchronize patterns", MessageBoxButtons.OK, MessageBoxIcon.Error);
Application.Exit();
}
finally
{
if (stream != null)
stream.Close();
if (reader != null)
reader.Close();
}
}
/// <summary>
/// Check if the My Devices folder exists, if not create it.
/// </summary>
private void CreateMyDevicesFolder()
{
try
{
foreach (IITPlaylist p in itunes.LibrarySource.Playlists)
{
if (p.Name == "My Devices" && p.Kind == ITPlaylistKind.ITPlaylistKindUser)
{
folderMyDevices = (IITUserPlaylist)p;
return;
}
}
}
catch (Exception ex)
{
l.Error(ex);
}
try
{
object src = itunes.LibrarySource;
folderMyDevices = (IITUserPlaylist)itunes.CreateFolderInSource("My Devices", ref src);
}
catch (COMException ex)
{
l.Error(ex);
MessageBox.Show(this, "Unable to create 'My Devices' folder. This may "
+ "be due to iTunes being busy with an other operation. If this error "
+ "continues to occur, please turn the option off in the Preferences dialog.\n\n(" + ex.Message + ")",
"Failed to create My Devices folder", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
/// <summary>
/// Creates connection to iTunes.
/// </summary>
/// <returns>True if an instance of iTunes interface was successfully made,
/// false otherwise.</returns>
public bool CreateITunesInstance()
{
//Try to create a COM connection to iTunes.
bool retry = true;
while (retry)
{
try
{
SetITunesInstance();
string version = itunes.Version;
SetStatusMessage("Notpod", "I have found iTunes (" + version
+ ") on your computer and I am ready to synchronize your devices.",
ToolTipIcon.Info);
SetEventHandlers();
retry = false;
}
catch (Exception ex)
{
l.Warn(ex);
if (MessageBox.Show(this, "Unable to communicate with iTunes. Do you want to retry?\n\n("
+ ex.Message + ")", "Communication error", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
{
retry = true;
}
else
{
SetStatusMessage("Notpod", "An error occured while communicating with iTunes. Please "
+ "make sure iTunes is properly installed and running before restarting the application.",
ToolTipIcon.Error);
return false;
}
}
}
return true;
}
public void SetITunesInstance() {
itunes = itunesAppFactory.GetNewInstance();
}
/// <summary>
/// Event handler for iTunes quit events.
/// </summary>
protected void OniTunesQuitEvent()
{
Console.Out.WriteLine("OniTunesQuitEvent");
CancelEventArgs e = new CancelEventArgs(false);
this.OnClosing(e);
Application.Exit();
}
/// <summary>
/// Event handler for connected devices.
/// </summary>
/// <param name="sender">Sender of the event.</param>
/// <param name="args">Event arguments.</param>
private void OnDeviceConnected(object sender, CDMEventArgs args)
{
Device device = args.Device;
if (configuration.ShowNotificationPopups)
{
string message = "'" + device.Name + "' has been connected. "
+ "You may now synchronize the device "
+ "with the playlist for this device.\n\nDevices currently connected:";
foreach (Device d in connectedDevices.GetConnectedDevices())
message += "\n - " + d.Name;
itaTray.ShowBalloonTip(5, "Device connected!", message, ToolTipIcon.Info);
}
IITPlaylist playlist = PlaylistExists(device);
//Delete playlist if it exists.
//if (playlist != null)
// playlist.Delete();
if (playlist == null)
{
try
{
if (configuration.UseListFolder)
{
CreateMyDevicesFolder();
playlist = folderMyDevices.CreatePlaylist(device.Name);
}
else
playlist = itunes.CreatePlaylist(device.Name);
}
catch (Exception e)
{
l.Error(e);
MessageBox.Show("Failed to create list for device '" + device.Name
+ "'. You will not be able to synchronize this device with iTunes.",
"Playlist error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
else
{
//If the option to use "My Devices" folder is set, move the playlist to that folder.
if (configuration.UseListFolder && (playlist.Kind == ITPlaylistKind.ITPlaylistKindUser)
&& (device.Playlist == null || device.Playlist.Length == 0))
{
CreateMyDevicesFolder();
object parent = (object)folderMyDevices;
((IITUserPlaylist)playlist).set_Parent(ref parent);
}
}
}
/// <summary>
/// Checks if an iTunes playlist exists.
/// </summary>
/// <param name="device">Device to check playlist for.</param>
/// <returns>The playlist if it exists, null otherwise.</returns>
private IITPlaylist PlaylistExists(Device device)
{
string name = (device.Playlist == null || device.Playlist.Length == 0) ? device.Name : device.Playlist;
bool retry = true;
while (retry)
{
try
{
foreach (IITPlaylist playlist in itunes.LibrarySource.Playlists)
{
if (playlist.Name == name)
return playlist;
}
return null;
}
catch (Exception comex)
{
l.Warn(comex);
if (MessageBox.Show("Failed to get playlists from iTunes. This is most likely due to iTunes being busy or an open dialog. Do you want to try again?\n\n(" + comex.Message + ")", "Communication error", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
{
retry = true;
}
else
{
retry = false;
}
continue;
}
}
return null;
}
/// <summary>
/// Event handler for disconnected devices.
/// </summary>
/// <param name="sender">Sender of the event.</param>
/// <param name="driveName">Name of drive where the device was connected.</param>
/// <param name="args">Event arguments.</param>
private void OnDeviceDisconnect(object sender, string driveName, CDMEventArgs args)
{
Device device = args.Device;
if (configuration.ShowNotificationPopups)
itaTray.ShowBalloonTip(5, "Device disconnected", "'" + device.Name + "' was disconnected.", ToolTipIcon.Info);
}
/// <summary>
/// Overriding OnClosing to remove playlists for devices.
/// </summary>
/// <param name="e"></param>
protected override void OnClosing(CancelEventArgs e)
{
Hashtable cd = connectedDevices.GetConnectedDevicesWithDrives();
IDictionaryEnumerator cdenum = cd.GetEnumerator();
while (cdenum.MoveNext())
{
CDMEventArgs args = new CDMEventArgs(null, (Device)cdenum.Value);
OnDeviceDisconnect(this, (string)cdenum.Key, args);
}
itunes = null;
base.OnClosing(e);
}
/// <summary>
/// Set event handlers for iTunes events.
/// </summary>
private void SetEventHandlers()
{
itunes.OnQuittingEvent += new _IiTunesEvents_OnQuittingEventEventHandler(OniTunesQuitEvent);
itunes.OnAboutToPromptUserToQuitEvent
+= new _IiTunesEvents_OnAboutToPromptUserToQuitEventEventHandler(OniTunesQuitEvent);
}
/// <summary>
/// Set the status message in the main window.
/// </summary>
/// <param name="message">Status message to set.</param>
/// <param name="icon">The type of icon to use on the baloon.</param>
public void SetStatusMessage(string title, string message, ToolTipIcon icon)
{
if (configuration.ShowNotificationPopups)
itaTray.ShowBalloonTip(5, title, message, icon);
}
/// <summary>
/// Event handler for ticks on the DriveListUpdate timer.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void timerDriveListUpdate_Tick(object sender, EventArgs e)
{
DriveInfo[] driveInfos = DriveInfo.GetDrives();
//Create a list of all removable drives, which are the only ones
//of interest to Notpod.
ArrayList interestingDrives = new ArrayList();
foreach (DriveInfo di in driveInfos)
{
if (di.Name == "A:\\" || di.Name == "B:\\" || !di.IsReady)
continue;
if (di.DriveType != DriveType.CDRom && di.DriveType != DriveType.Network)
interestingDrives.Add(di);
}
connectedDevices.Synchronize(interestingDrives);
}
/// <summary>
/// WndProc override to enable minimize to tray.
/// </summary>
/// <param name="m"></param>
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_SYSCOMMAND)
{
switch (m.WParam.ToInt32())
{
case SC_MINIMIZE:
{
Hide();
return;
}
default:
{
break;
}
}
}
//Let the base class handle the rest.
base.WndProc(ref m);
}
private void ctxTraySynchronize_Click(object sender, EventArgs e)
{
// There are no devices connected.
if (connectedDevices.GetConnectedDevices().Count == 0)
{
if (configuration.ShowNotificationPopups)
itaTray.ShowBalloonTip(3, "No devices", "There are no connected devices to synchronize.", ToolTipIcon.Info);
return;
}
if (configuration.WarnOnSystemDrives && !PerformDeviceCheck())
{
return;
}
syncForm = new StandardSynchronizerForm();
syncForm.Show();
Thread thread = new Thread(new ThreadStart(PerformSynchronize));
thread.Start();
}
private bool GetMusicLocationConfirmation(string path)
{
DialogResult confirmedMediaRoot = MessageBox.Show("Please confirm that the path below represents a folder on your portable media player, NOT on your local hard drive:\n\n" + path + "\n\nIf you agree that the path above is the location on your portable device where you want the music to be copied TO, click OK to continue. Otherwise click Cancel and reconfigure your device under Preferences.", "Confirm music location", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
if (confirmedMediaRoot == DialogResult.Cancel)
{
return false;
}
return true;
}
/// <summary>
/// Perform a simple check of the devices. Warn the user if a device
/// is associated with a drive which may be a system drive.
/// </summary>
/// <returns>False if the user chooses to abort, true if all is good.</returns>
private bool PerformDeviceCheck()
{
Hashtable deviceinfo = connectedDevices.GetConnectedDevicesWithDrives();
IEnumerator keys = deviceinfo.Keys.GetEnumerator();
while (keys.MoveNext())
{
string drive = (string)keys.Current;
Device device = (Device)deviceinfo[keys.Current];
DriveInfo driveInfo = new DriveInfo(drive);
if(driveInfo.DriveType == DriveType.Fixed) {
l.Warn(String.Format("Detected fixed drive for {0} ({1}).", device.Name, drive));
DialogResult choice = MessageBox.Show("The device '" + device.Name
+ "' is mapping to a fixed hard drive in your computer, not a removable storage. The drive currently associated"
+ " with this device is:\n\n\t" + drive + "\n\nIf you are sure this is "
+ "correct, you may continue. If you are unsure, or have misconfigured, "
+ "you should click 'Cancel' and make sure your device configuration is "
+ "correct before attempting a new synchronization.\n\nAre you sure you "
+ "want to continue?",
"Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
if (choice == DialogResult.Cancel)
return false;
}
if (CheckIfSystemDrive(drive))
{
l.Warn(String.Format("Detected possible system drive for {0} ({1}).", device.Name, drive));
DialogResult choice = MessageBox.Show("The device '" + device.Name
+ "' looks like it's mapping to a system hard drive. The drive currently associated"
+ " with this device is:\n\n\t" + drive + "\n\nIf you are sure this is "
+ "correct, you may continue. If you are unsure, or have misconfigured, "
+ "you should click 'Cancel' and make sure your device configuration is "
+ "correct before attempting a new synchronization.\n\nAre you sure you "
+ "want to continue?",
"Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
if (choice == DialogResult.Cancel)
return false;
}
if(CheckIfiTunesLibrary(drive))
{
l.Warn(String.Format("Detected possible iTunes library location for {0} ({1}).",
device.Name, drive));
DialogResult choice = MessageBox.Show("The device '" + device.Name
+ "' looks like it's mapping to your local iTunes library. The drive currently associated"
+ " with this device is:\n\n\t" + drive + "\n\nIf you are sure this is "
+ "correct, you may continue. If you are unsure, or have misconfigured, "
+ "you should click 'Cancel' and make sure your device configuration is correct "
+ "before attempting a new synchronization.\n\nAre you sure you want to continue?",
"Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
if (choice == DialogResult.Cancel)
return false;
}
}
return true;
}
public void PerformSynchronize()
{
Hashtable deviceinfo = connectedDevices.GetConnectedDevicesWithDrives();
IEnumerator keys = deviceinfo.Keys.GetEnumerator();
try
{
// Create synchronizer and form.
ISynchronizer synchronizer = new StandardSynchronizer();
synchronizer.Form = syncForm;
while (keys.MoveNext())
{
string drive = (string)keys.Current;
Device device = (Device)deviceinfo[keys.Current];
if (configuration.ConfirmMusicLocation && !GetMusicLocationConfirmation(drive + device.MediaRoot))
{
syncForm.CloseSafe();
syncForm = null;
synchronizer = null;
return;
}
IITPlaylist playlist = PlaylistExists(device);
if (playlist == null)
{
MessageBox.Show("I could not synchronize '" + device.Name + "' because "
+ "the playlist does not exist! Try reconnecting the device. If the problem continues"
+ " please report the problem to the Notpod developers at http://www.sourceforge.net/projects/ita.",
"Internal synchronization error", MessageBoxButtons.OK, MessageBoxIcon.Error);
continue;
}
synchronizer.Configuration = deviceConfiguration;
synchronizer.SynchronizeError += new SynchronizeErrorEventHandler(OnSynchronizeError);
synchronizer.SynchronizeComplete += new SynchronizeCompleteEventHandler(OnSynchronizeComplete);
synchronizer.SynchronizeCancelled += new SynchronizeCancelledEventHandler(OnSynchronizeCancelled);
synchronizer.SynchronizeDevice((IITUserPlaylist)playlist, drive, device);
}
}
catch (Exception ex)
{
l.Error(ex);
string message = "I encountered an unexpected error while synchronizing your device(s). "
+ "\n\nPlease make sure your devices are properly "
+ "connected and try again.";
itaTray.ShowBalloonTip(7, "Synchronize error", message, ToolTipIcon.Error);
}
if (syncForm != null && configuration.CloseSyncWindowOnSuccess)
syncForm.CloseSafe();
}
private void OnSynchronizeError(object sender, SyncErrorArgs args)
{
itaTray.ShowBalloonTip(5, "Synchronize error", args.ErrorMessage, ToolTipIcon.Error);
}
private void OnSynchronizeComplete(object sender)
{
if (configuration.ShowNotificationPopups)
itaTray.ShowBalloonTip(5, "Synchronize complete", "Your device was successfully synchronized with iTunes.", ToolTipIcon.Info);
}
private void OnSynchronizeCancelled(object sender)
{
if (configuration.ShowNotificationPopups)
itaTray.ShowBalloonTip(5, "Synchronization cancelled", "The synchronization was cancelled.", ToolTipIcon.Warning);
}
/// <summary>
/// Event handler for the exit menu item.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void menuAgentExit_Click(object sender, EventArgs e)
{
Close();
}
/// <summary>
/// Event handler for Help->About
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void menuHelpAbout_Click(object sender, EventArgs e)
{
}
/// <summary>
/// Event handler for the Help->Online documentation menu item.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void menuHelpOnlineDoc_Click(object sender, EventArgs e)
{
}
private void menuAgentConfigure_Click(object sender, EventArgs e)
{
}
private void menuAgentFormat_Click(object sender, EventArgs e)
{
DialogResult dr = MessageBox.Show("WARNING! This will delete all music on the device and will synchronize your device with the current playlist for that device in iTunes.\n\nContinue?", "Warning!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
}
private void ctxTrayExit_Click(object sender, EventArgs e)
{
menuAgentExit_Click(sender, e);
}
private void linkJaranweb_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
//Open URL in default browser
ProcessStartInfo info = new ProcessStartInfo("http://notpod.com/");
info.Verb = "open";
Process.Start(info);
}
/// <summary>
/// Event handler for the tray context menu "About Notpod..."
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ctxTrayAbout_Click(object sender, EventArgs e)
{
AboutBox about = new AboutBox();
about.ShowDialog();
}
/// <summary>
/// Event handler for the tray context menu "Online help..."
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ctxTrayHelp_Click(object sender, EventArgs e)
{
//Open URL in default browser
ProcessStartInfo info = new ProcessStartInfo("http://notpod.com/support.html");
info.Verb = "open";
Process.Start(info);
}
private void ctxTrayReportBug_Click(object sender, EventArgs e)
{
//Open URL in default browser
ProcessStartInfo info = new ProcessStartInfo("https://github.com/notpod/Notpod-1.x/issues/new");
info.Verb = "open";
Process.Start(info);
}
/// <summary>
/// Event handler for the tray context menu "Preferences..."
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ctxTrayPreferences_Click(object sender, EventArgs e)
{
ConfigurationForm conf = new ConfigurationForm(ref configuration, ref deviceConfiguration, ref itunes);
conf.ShowDialog();
}
/// <summary>
/// Check the provided path against the list of potential system drives
/// </summary>
/// <param name="path">Path to check.</param>
/// <returns>False if all is good, true if the provided path might be a system drive.</returns>
private bool CheckIfSystemDrive(string drive)
{
string[] warnOnPatterns = new string[] { "WINDOWS\\system32", "WINNT\\system32", "Users",
"Documents and Settings"};
foreach (string pattern in warnOnPatterns)
{
DirectoryInfo di = new DirectoryInfo(drive + "\\" + pattern);
if (di.Exists)
{
return true;
}
}
return false;
}
/// <summary>
/// Check if device drive may be iTunes library folder. This could happen in case
/// the user misconfigure the device and this check should help prevent loss of data.
/// </summary>
/// <param name="drive"></param>
/// <returns></returns>
public bool CheckIfiTunesLibrary(string drive)
{
string libraryPath = itunes.LibraryXMLPath;
l.Debug("LibraryXMLPath: " + libraryPath);
if(libraryPath == null)
{
return false;
}
if(libraryPath.StartsWith("\\\\")) // network drive
{
libraryPath = libraryPath.Substring(2);
}
else
{
libraryPath = libraryPath.Substring(3);
}
FileInfo fi = new FileInfo(drive + "\\" + libraryPath);
return fi.Exists;
}
public ITunesAppFactory ITunesAppFactory {
set { this.itunesAppFactory = value; }
get { return this.itunesAppFactory; }
}
}
}