-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForm1.vb
901 lines (842 loc) · 36.6 KB
/
Form1.vb
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
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
#Region "Import Declaratives"
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Drawing.Imaging
Imports System.IO
Imports System.Text
Imports System.Xml
Imports System.Xml.Serialization
Imports Toub.MediaCenter.Dvrms.Metadata
#End Region
Public Class Form1
#Region "Private Variables"
Private DVRMS As DVRMSItem = Nothing
Private bIsDirty As Boolean = False
Private SaveFolder As String = Nothing
Private WMTags() As MetadataItem
Private RedoBuffer As New Queue(Of String)
Private xmlDVDProfiler As XmlDocument
#End Region
#Region " Form Events "
''' <summary>
'''
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks></remarks>
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
LoadMetaTags()
InitUI()
End Sub
''' <summary>
'''
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks></remarks>
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
If bIsDirty Then
If MessageBox.Show("You have unsaved information. Are you certain you want to exit?", _
"DVR-MS Editor", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Cancel Then
e.Cancel = True
End If
End If
End Sub
#End Region
#Region " Control Events "
''' <summary>
'''
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks></remarks>
Private Sub ToolStripItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles OpenToolStripMenuItem.Click, OpenToolStripButton.Click, _
SaveToolStripMenuItem.Click, SaveToolStripButton.Click, _
CustomizeToolStripMenuItem.Click, _
DVDProfilerToolStripMenuItem.Click, _
ExitToolStripMenuItem.Click, DVDProfilerImagesToolStripMenuItem.Click
Select Case True
Case sender.Equals(OpenToolStripMenuItem), _
sender.Equals(OpenToolStripButton)
LoadDVRMSFiles()
Case sender.Equals(SaveAsToolStripMenuItem)
SaveFiles()
Case sender.Equals(SaveToolStripMenuItem), _
sender.Equals(SaveToolStripButton)
SaveDVRMSFiles()
Case sender.Equals(CustomizeToolStripMenuItem)
XMLDVRMSFiles()
Case sender.Equals(DVDProfilerToolStripMenuItem)
UpdateFromDVDProfilerInfo()
Case sender.Equals(DVDProfilerImagesToolStripMenuItem)
Me.GetDVDProfilerImageDir()
Case sender.Equals(ExitToolStripMenuItem)
SaveDVRMSFiles()
Me.Close()
End Select
End Sub
''' <summary>
'''
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks></remarks>
Private Sub CheckedListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles CheckedListBox1.SelectedIndexChanged
Dim clb As CheckedListBox = CType(sender, CheckedListBox)
If bIsDirty Then
SaveMetaAttributes(DVRMS)
End If
DVRMS = CType(clb.SelectedItem, CheckedListBoxItem).item
RefreshEditData(DVRMS)
End Sub
''' <summary>
'''
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks></remarks>
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles CheckBox1.CheckedChanged
Dim ii As Integer = Me.CheckedListBox1.SelectedIndex
If ii >= 0 Then
Me.CheckedListBox1.SetItemCheckState(Me.CheckedListBox1.SelectedIndex, CheckState.Unchecked)
End If
bIsDirty = True
End Sub
''' <summary>
'''
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks></remarks>
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles ComboBox1.SelectedIndexChanged
Dim ii As Integer = Me.CheckedListBox1.SelectedIndex
If ii >= 0 Then
Me.CheckedListBox1.SetItemCheckState(Me.CheckedListBox1.SelectedIndex, CheckState.Unchecked)
End If
bIsDirty = True
End Sub
''' <summary>
'''
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks></remarks>
Private Sub CheckedListBox2_SelectedValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles CheckedListBox2.SelectedValueChanged
Dim ii As Integer = Me.CheckedListBox1.SelectedIndex
If ii >= 0 Then
Me.CheckedListBox1.SetItemCheckState(Me.CheckedListBox1.SelectedIndex, CheckState.Unchecked)
End If
bIsDirty = True
End Sub
''' <summary>
'''
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks></remarks>
Private Sub TextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles TextBox7.TextChanged, TextBox6.TextChanged, TextBox5.TextChanged, TextBox4.TextChanged, _
TextBox3.TextChanged, TextBox2.TextChanged, TextBox1.TextChanged
Dim ii As Integer = Me.CheckedListBox1.SelectedIndex
If ii >= 0 Then
Me.CheckedListBox1.SetItemCheckState(Me.CheckedListBox1.SelectedIndex, CheckState.Unchecked)
End If
bIsDirty = True
End Sub
''' <summary>
'''
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks></remarks>
Private Sub EditToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _
UndoToolStripMenuItem.Click, UndoToolStripMenuItem1.Click, _
CutToolStripMenuItem.Click, CutToolStripMenuItem1.Click, _
CopyToolStripMenuItem.Click, CopyToolStripMenuItem1.Click, _
PasteToolStripMenuItem.Click, PasteToolStripMenuItem1.Click, _
SelectAllToolStripMenuItem.Click, SelectAllToolStripMenuItem1.Click
Dim tb As TextBox
Select Case True
Case Me.TextBox1.Focused : tb = Me.TextBox1
Case Me.TextBox2.Focused : tb = Me.TextBox2
Case Me.TextBox3.Focused : tb = Me.TextBox3
Case Me.TextBox4.Focused : tb = Me.TextBox4
Case Me.TextBox5.Focused : tb = Me.TextBox5
Case Me.TextBox6.Focused : tb = Me.TextBox6
Case Me.TextBox7.Focused : tb = Me.TextBox7
Case Else : Exit Sub
End Select
Select Case CType(sender, ToolStripMenuItem).Name
Case UndoToolStripMenuItem.Name, UndoToolStripMenuItem1.Name
If tb.CanUndo Then
tb.Undo()
tb.ClearUndo()
End If
Case CutToolStripMenuItem.Name, CutToolStripMenuItem1.Name : If tb.SelectionLength > 0 Then tb.Cut()
Case CopyToolStripMenuItem.Name, CopyToolStripMenuItem1.Name : If tb.SelectionLength > 0 Then tb.Copy()
Case PasteToolStripMenuItem.Name, PasteToolStripMenuItem1.Name
If Clipboard.GetDataObject.GetDataPresent(DataFormats.Text) Then
If tb.SelectionLength > 0 Then
End If
tb.Paste()
End If
Case SelectAllToolStripMenuItem.Name, SelectAllToolStripMenuItem1.Name : tb.SelectAll()
End Select
End Sub
''' <summary>
'''
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks></remarks>
Private Sub AboutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutToolStripMenuItem.Click
Dim oAbout As New AboutBox1
oAbout.ShowDialog()
End Sub
#End Region
#Region " Support Functions "
''' <summary>
'''
''' </summary>
''' <remarks></remarks>
Private Sub LoadMetaTags()
Dim fTags As String = System.AppDomain.CurrentDomain.BaseDirectory & "\" & "DVRMSTags.xml"
If Not IO.File.Exists(fTags) Then
IO.File.WriteAllText(fTags, My.Resources.DVRMSTags)
End If
Try
Dim xmlDoc As XmlDocument = New XmlDocument()
xmlDoc.Load(fTags)
Dim xmlNode As XmlNode
ReDim WMTags(xmlDoc.DocumentElement.ChildNodes.Count - 1)
Dim ii As Integer = 0
For Each xmlNode In xmlDoc.DocumentElement.ChildNodes
If Not CType(xmlNode, XmlElement).HasAttribute("Name") Then Continue For
If Not CType(xmlNode, XmlElement).HasAttribute("Type") Then Continue For
Dim Name As String, Type As String, Value As String
Dim oVal As Object, oType As MetadataItemType
Name = CType(xmlNode, XmlElement).Attributes("Name").Value
Type = CType(xmlNode, XmlElement).Attributes("Type").Value
Value = CType(xmlNode, XmlElement).InnerText
oType = [Enum].Parse(GetType(MetadataItemType), Type)
Select Case oType
Case MetadataItemType.Binary : oVal = Encoding.ASCII.GetBytes(Value)
Case MetadataItemType.Boolean : oVal = CBool(Value)
Case MetadataItemType.Dword : oVal = Int32.Parse(Value)
Case MetadataItemType.Guid : oVal = Value
Case MetadataItemType.String : oVal = Value
Case MetadataItemType.Word : oVal = Int16.Parse(Value)
Case MetadataItemType.Qword : oVal = Int64.Parse(Value)
Case Else : Continue For
End Select
Dim item As New MetadataItem(Name, oVal, oType)
WMTags(ii) = item : ii += 1
Next
xmlDoc = Nothing
Catch ex As Exception
End Try
End Sub
''' <summary>
'''
''' </summary>
''' <remarks></remarks>
Private Sub InitUI()
Try
Dim sfGenre As String = AppDomain.CurrentDomain.BaseDirectory & "genre.txt"
If IO.File.Exists(sfGenre) Then
Dim sGenre As String = IO.File.ReadAllText(sfGenre)
Dim genres() As String = sGenre.Replace(Environment.NewLine, "|").Split("|"c)
Me.CheckedListBox2.Items.AddRange(genres)
Else
Me.CheckedListBox2.Items.Add("Action")
End If
Catch ex As Exception
End Try
End Sub
''' <summary>
'''
''' </summary>
''' <remarks></remarks>
Private Sub XMLDVRMSFiles()
If SaveFolder Is Nothing Then
If SaveFiles() Is Nothing Then Return
End If
Me.ofdDVRMS.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.MyDocuments
If Me.ofdDVRMS.ShowDialog <> Windows.Forms.DialogResult.OK Then Return
Dim sfname() As String = Me.ofdDVRMS.FileNames
For Each fname As String In sfname
Using editor As New DvrmsMetadataEditor(fname)
WriteXMLMetaData(editor.GetAttributes, IO.Path.GetFileNameWithoutExtension(fname))
End Using
Next
End Sub
''' <summary>
'''
''' </summary>
''' <returns></returns>
''' <remarks></remarks>
Private Function GetDVDProfilerImageDir() As String
Dim ofd As New FolderBrowserDialog
If My.Settings.ImageDir = "~" Then
ofd.SelectedPath = My.Computer.FileSystem.SpecialDirectories.MyDocuments
Else
ofd.SelectedPath = My.Settings.ImageDir
End If
If ofd.ShowDialog <> Windows.Forms.DialogResult.OK Then Return Nothing
My.Settings.ImageDir = ofd.SelectedPath
Return ofd.SelectedPath
End Function
''' <summary>
'''
''' </summary>
''' <remarks></remarks>
Private Function GetDVDProfilerXMLFile() As String
Dim ofd As New OpenFileDialog
If My.Settings.XMLDir = "~" Then
ofd.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.MyDocuments
Else
ofd.InitialDirectory = My.Settings.XMLDir
End If
ofd.Filter = "XML Files (*.xml)|*.xml|All Files (*.*)|*.*"
ofd.FilterIndex = 0
ofd.RestoreDirectory = True
ofd.DefaultExt = "xml"
ofd.CheckFileExists = True
ofd.FileName = Nothing
If ofd.ShowDialog <> Windows.Forms.DialogResult.OK Then Return Nothing
My.Settings.XMLDir = IO.Path.GetDirectoryName(ofd.FileName)
Return ofd.FileName
End Function
''' <summary>
'''
''' </summary>
''' <param name="DVRMS"></param>
''' <remarks></remarks>
Private Sub RefreshEditData(ByVal DVRMS As DVRMSItem)
If DVRMS.meta Is Nothing Then Exit Sub
Me.TextBox7.Text = DVRMS.Title
If String.IsNullOrEmpty(Me.TextBox7.Text) Then
Me.TextBox7.Text = DVRMS.ToString
End If
Me.ComboBox1.Text = DVRMS.ParentalRating
For ii As Integer = 0 To Me.CheckedListBox2.Items.Count - 1
Me.CheckedListBox2.SetItemChecked(ii, False)
Next
Me.TextBox6.Text = ""
Dim genres() As String = DVRMS.Genres.Split(","c)
For Each genre As String In genres
genre = genre.Trim
If genre.ToUpper Like "MOVIE*" Then Continue For
If Me.CheckedListBox2.Items.Contains(genre) Then
Dim ii As Integer = Me.CheckedListBox2.Items.IndexOf(genre)
Me.CheckedListBox2.SetItemChecked(ii, True)
Else
Dim str As String = Me.TextBox6.Text
str += genre + Environment.NewLine
Me.TextBox6.Text = str
End If
Next
Me.CheckBox1.Checked = DVRMS.IsMovie
Dim MediaCredits As String = DVRMS.Credits
Dim persona As String = MediaCredits + ";;;;;"
Dim credits() As String = persona.Split(";"c)
Me.TextBox3.Text = credits(0)
Me.TextBox4.Text = credits(1)
Me.TextBox5.Text = credits(3)
Me.TextBox1.Text = DVRMS.Subtitle
Me.TextBox2.Text = DVRMS.Synopsis
'bIsDirty = False
'DVRMS.Save()
End Sub
''' <summary>
'''
''' </summary>
''' <remarks></remarks>
Private Sub UpdateFromDVDProfilerInfo()
Dim DVDProfilerXMLFile As String = GetDVDProfilerXMLFile()
If DVDProfilerXMLFile Is Nothing Then Return
Me.ToolStripProgressBar1.Value = 0
Me.ToolStripProgressBar1.Maximum = Me.CheckedListBox1.Items.Count
Dim ds As New DataSet
ds.ReadXml(DVDProfilerXMLFile)
Dim checked() As Integer = {}, unchecked() As Integer = {}
For Each clbi As CheckedListBoxItem In Me.CheckedListBox1.Items
Dim dvrms As DVRMSItem = clbi.item
Dim ii As Integer = Me.ToolStripProgressBar1.Value
Me.ToolStripProgressBar1.Value += 1
Dim dvds() As DataRow = {}
Dim sTitle As String = dvrms.ToString.Replace("'", "'")
dvds = ds.Tables("DVD").Select(String.Format("Title='{0}'", sTitle))
If dvds.Length = 0 Then
If Not String.IsNullOrEmpty(dvrms.Title) Then
sTitle = dvrms.Title.Replace("'", "''")
dvds = ds.Tables("DVD").Select(String.Format("Title='{0}'", sTitle))
End If
If dvds.Length = 0 Then
If Not String.IsNullOrEmpty(dvrms.Title) Then
sTitle = dvrms.Title.Replace("'", "''")
dvds = ds.Tables("DVD").Select(String.Format("SortTitle='{0}'", sTitle))
End If
If dvds.Length = 0 Then
ReDim Preserve unchecked(unchecked.Length)
unchecked(unchecked.Length - 1) = ii
Continue For
End If
End If
End If
Dim sRlsd As String, sPrdYr As String, sCountryOfOrigin As String
Dim sRating As String, sDuration As String, sOverview As String
Dim dtRlsd As DateTime, yrRlsd As String = Nothing, rInt As Integer
Dim sID As String
For Each dvd As DataRow In dvds
ReDim Preserve checked(checked.Length)
checked(checked.Length - 1) = ii
sID = String.Empty
sRlsd = String.Empty
sPrdYr = String.Empty
sCountryOfOrigin = String.Empty
sRating = String.Empty
sDuration = String.Empty
sOverview = String.Empty
If Not IsDBNull(dvd("ID")) Then sID = CStr(dvd("ID"))
If Not String.IsNullOrEmpty(sID) Then
If Not String.IsNullOrEmpty(My.Settings.ImageDir) Then
Dim sFrom As String = IO.Path.Combine(My.Settings.ImageDir, sID + "f.jpg")
Dim sTo As String = IO.Path.Combine(IO.Path.GetDirectoryName(dvrms.filename), _
IO.Path.GetFileNameWithoutExtension(dvrms.filename) + ".jpg")
If IO.File.Exists(sTo) Then IO.File.Delete(sTo)
Me.OMLThumb(sFrom, sTo)
End If
End If
Dim lsTitle As String = CStr(dvd("Title"))
If Not IsDBNull(dvd("Released")) Then
sRlsd = dvd("Released")
If DateTime.TryParse(sRlsd, dtRlsd) Then yrRlsd = dtRlsd.Year.ToString
If Not IsDBNull(dvd("ProductionYear")) Then
sPrdYr = dvd("ProductionYear")
If String.IsNullOrEmpty(sPrdYr) Then sPrdYr = yrRlsd
End If
End If
If Not IsDBNull(dvd("CountryOfOrigin")) Then sCountryOfOrigin = dvd("CountryOfOrigin")
If Not IsDBNull(dvd("Rating")) Then sRating = dvd("Rating")
If Not IsDBNull(dvd("RunningTime")) Then sDuration = dvd("RunningTime")
If Not IsDBNull(dvd("Overview")) Then sOverview = dvd("Overview")
Dim genre() As DataRow = {}
Dim studio() As DataRow = {}
Dim actor() As DataRow = {}
Dim credit() As DataRow = {}
Dim Genres() As DataRow = dvd.GetChildRows("DVD_Genres")
If Genres.Length > 0 Then
genre = Genres(0).GetChildRows("Genres_Genre")
End If
Dim Studios() As DataRow = dvd.GetChildRows("DVD_Studios")
If Studios.Length > 0 Then
studio = Studios(0).GetChildRows("Studios_Studio")
End If
Dim Actors() As DataRow = dvd.GetChildRows("DVD_Actors")
If Actors.Length > 0 Then
actor = Actors(0).GetChildRows("Actors_Actor")
End If
Dim Credits() As DataRow = dvd.GetChildRows("DVD_Credits")
If Credits.Length > 0 Then
credit = Credits(0).GetChildRows("Credits_Credit")
End If
If String.IsNullOrEmpty(dvrms.Title) Then dvrms.Title = dvrms.ToString
dvrms.ParentalRating = sRating
If String.IsNullOrEmpty(dvrms.Synopsis) Then dvrms.Synopsis = sOverview
If String.IsNullOrEmpty(sPrdYr) Then
sPrdYr = DateTime.Today.Year.ToString
End If
dvrms.ReleaseDate = New Date(sPrdYr, 1, 1)
If Int32.TryParse(sDuration, rInt) Then dvrms.RunningTime = rInt
If studio.Length > 0 Then
dvrms.Station = studio(0)(0)
End If
'dvrms.Genre.Clear()
If genre.Length > 0 Then
For Each g As DataRow In genre
Dim sGenre As String = CStr(g(0)).Replace("-"c, " "c)
If Not String.IsNullOrEmpty(sGenre.Trim) Then
dvrms.AddGenre(sGenre)
End If
Next
End If
'dvrms.Actors.Clear()
If actor.Length > 0 Then
For Each a As DataRow In actor
Dim sActor As String = a("FirstName") + " " + a("LastName")
dvrms.AddActor(sActor)
Next
End If
'dvrms.Directors.Clear()
If credit.Length > 0 Then
For Each d As DataRow In credit
If d("CreditType") = "Direction" Then
Dim sActor As String = d("FirstName") + " " + d("LastName")
dvrms.AddDirector(sActor)
End If
Next
End If
Exit For
Next
Next
ds.Dispose()
xmlDVDProfiler = Nothing
Me.ToolStripProgressBar1.Value = 0
Me.ToolStripProgressBar1.Maximum = checked.Length
For ii As Integer = 0 To checked.Length - 1
Me.ToolStripProgressBar1.Value += 1
Dim dvrms As DVRMSItem = CType(Me.CheckedListBox1.Items(ii), CheckedListBoxItem).item
dvrms.Save()
Me.CheckedListBox1.SetItemCheckState(checked(ii), CheckState.Checked)
Next
For ii As Integer = 0 To unchecked.Length - 1
Me.CheckedListBox1.SetItemCheckState(unchecked(ii), CheckState.Unchecked)
Next
bIsDirty = False
Me.CheckedListBox1.SetSelected(0, True)
End Sub
''' <summary>
'''
''' </summary>
''' <remarks></remarks>
Private Sub XMLUpdateFromDVDProfilerInfo()
Dim DVDProfilerXMLFile As String = GetDVDProfilerXMLFile()
If DVDProfilerXMLFile Is Nothing Then Return
Me.ToolStripProgressBar1.Value = 0
Me.ToolStripProgressBar1.Maximum = Me.CheckedListBox1.Items.Count
xmlDVDProfiler = New XmlDocument
xmlDVDProfiler.Load(DVDProfilerXMLFile)
Dim oNode As XmlNode
Const xNode As String = "//Collection/DVD[Title='{0}']"
Dim ActorAttrs() As String = {"FirstName", "LastName", "Role"}
Dim CrewAttrs() As String = {"FirstName", "LastName", "CreditType"}
Dim checked() As Integer = {}, unchecked() As Integer = {}
'Dim ListItems As CheckedListBox.ObjectCollection = Me.CheckedListBox1.Items
For Each clbi As CheckedListBoxItem In Me.CheckedListBox1.Items
Dim dvrms As DVRMSItem = clbi.item
Dim ii As Integer = Me.ToolStripProgressBar1.Value
Me.ToolStripProgressBar1.Value += 1
Try
Dim sTitle As String = dvrms.ToString.Replace("'", "'")
oNode = xmlDVDProfiler.SelectSingleNode(String.Format(xNode, sTitle))
If oNode Is Nothing AndAlso Not String.IsNullOrEmpty(dvrms.Title) Then
oNode = xmlDVDProfiler.SelectSingleNode(String.Format(xNode, dvrms.Title))
End If
Catch ex As Exception
ReDim Preserve unchecked(unchecked.Length)
unchecked(unchecked.Length - 1) = ii
oNode = Nothing
End Try
If oNode Is Nothing Then Continue For
ReDim Preserve checked(checked.Length)
checked(checked.Length - 1) = ii
Dim sRlsd As String = NodeInnerText(oNode, "Released")
Dim dtRlsd As DateTime, yrRlsd As String = Nothing, rInt As Integer
If DateTime.TryParse(sRlsd, dtRlsd) Then yrRlsd = dtRlsd.Year.ToString
Dim sPrdYr As String = NodeInnerText(oNode, "ProductionYear", yrRlsd)
Dim sCountryOfOrigin As String = NodeInnerText(oNode, "CountryOfOrigin", "")
Dim sRating As String = NodeInnerText(oNode, "Rating", "--")
Dim sDuration As String = NodeInnerText(oNode, "RunningTime", "0")
Dim sOverview As String = NodeInnerText(oNode, "Overview", "")
Dim sGenre() As String = NodeInnerList(oNode, "Genres")
Dim sActor() As String = NodeInnerList(oNode, "Actors", ActorAttrs)
Dim sCrew() As String = NodeInnerList(oNode, "Credits", CrewAttrs)
Dim sStudio() As String = NodeInnerList(oNode, "Studios")
oNode = Nothing
If String.IsNullOrEmpty(dvrms.Title) Then dvrms.Title = dvrms.ToString
dvrms.ParentalRating = sRating
If String.IsNullOrEmpty(dvrms.Synopsis) Then dvrms.Synopsis = sOverview
dvrms.ReleaseDate = New Date(sPrdYr, 1, 1)
If Int32.TryParse(sDuration, rInt) Then dvrms.RunningTime = rInt
If sStudio IsNot Nothing Then
dvrms.Station = sStudio(0)
End If
If sGenre IsNot Nothing Then
For Each g As String In sGenre
If Not String.IsNullOrEmpty(g.Trim) Then
dvrms.AddGenre(g)
End If
Next
End If
If sActor IsNot Nothing Then
For Each a As String In sActor
Dim n() As String = a.Split("|")
dvrms.AddActor(n(0) + " " + n(1))
Next
End If
If sCrew IsNot Nothing Then
For Each d As String In sCrew
Dim n() As String = d.Split("|")
If n(2) = "Direction" Then
dvrms.AddDirector(n(0) + " " + n(1))
End If
Next
End If
dvrms.Save()
Next
xmlDVDProfiler = Nothing
For ii As Integer = 0 To checked.Length - 1
Me.CheckedListBox1.SetItemCheckState(checked(ii), CheckState.Checked)
Next
For ii As Integer = 0 To unchecked.Length - 1
Me.CheckedListBox1.SetItemCheckState(unchecked(ii), CheckState.Unchecked)
Next
bIsDirty = False
Me.CheckedListBox1.SetSelected(0, True)
End Sub
''' <summary>
'''
''' </summary>
''' <param name="meta"></param>
''' <param name="sf"></param>
''' <remarks></remarks>
Private Sub WriteXMLMetaData(ByVal meta As IDictionary, ByVal sf As String)
Dim inWM As Boolean = False
Dim settings As New XmlWriterSettings
settings.Indent = True
settings.OmitXmlDeclaration = True
Using writer As XmlWriter = XmlWriter.Create(SaveFolder & "\" & sf & ".xml", settings)
writer.WriteStartDocument(True)
writer.WriteStartElement("dvrms")
Dim xs As SortedList = New SortedList(meta)
For Each name As String In xs.Keys
Dim item As MetadataItem = meta(name)
If item.Name.StartsWith("WM/") Then
If Not inWM Then
writer.WriteStartElement("WM")
inWM = True
End If
name = item.Name.Substring(3)
ElseIf inWM Then
writer.WriteEndElement()
inWM = False
End If
writer.WriteStartElement("item")
writer.WriteAttributeString("name", name)
writer.WriteAttributeString("type", item.Type.ToString)
writer.WriteString(item.Value.ToString)
writer.WriteEndElement()
Next
If inWM Then
writer.WriteEndElement()
End If
writer.WriteEndElement()
writer.WriteEndDocument()
writer.Close()
End Using
End Sub
''' <summary>
'''
''' </summary>
''' <returns></returns>
''' <remarks></remarks>
Private Function SaveFiles() As String
If SaveFolder IsNot Nothing Then
Me.fbdSave.SelectedPath = SaveFolder
Else
Me.fbdSave.SelectedPath = Environment.SpecialFolder.MyDocuments
End If
If Me.fbdSave.ShowDialog = Windows.Forms.DialogResult.OK Then
SaveFolder = Me.fbdSave.SelectedPath
End If
Return SaveFolder
End Function
''' <summary>
'''
''' </summary>
''' <remarks></remarks>
Private Sub LoadDVRMSFiles()
Me.ofdDVRMS.InitialDirectory = My.Settings.RootDir
If Me.ofdDVRMS.ShowDialog <> Windows.Forms.DialogResult.OK Then Return
Dim sfname() As String = Me.ofdDVRMS.FileNames
If sfname.Length = 0 Then Return
My.Settings.RootDir = IO.Path.GetDirectoryName(sfname(0))
Me.CheckedListBox1.Items.Clear()
For Each fname As String In sfname
FileMetaAttributes(fname)
Dim dvrms As New DVRMSItem(fname)
Dim clbi As New CheckedListBoxItem(dvrms, dvrms.ToString, CheckState.Indeterminate)
Me.CheckedListBox1.Items.Add(clbi, clbi.state)
Next
'Me.DVRMS = Me.CheckedListBox1.Items(0)
Me.bIsDirty = False
Me.CheckedListBox1.SetSelected(0, True)
End Sub
''' <summary>
'''
''' </summary>
''' <param name="fName"></param>
''' <remarks></remarks>
Private Sub FileMetaAttributes(ByVal fName As String)
Using editor As New DvrmsMetadataEditor(fName)
Dim meta As IDictionary = editor.GetAttributes
For Each item As MetadataItem In WMTags
If Not meta.Contains(item.Name) Then
Dim i As MetadataItem = item.Clone
meta.Add(i.Name, i)
End If
Next
Try
editor.SetAttributes(meta)
Catch ex As Exception
End Try
End Using
End Sub
''' <summary>
'''
''' </summary>
''' <param name="DVRMS"></param>
''' <remarks></remarks>
Private Sub SaveMetaAttributes(ByVal DVRMS As DVRMSItem)
DVRMS.Title = Me.TextBox7.Text
DVRMS.IsMovie = Me.CheckBox1.Checked
Dim sCredits As String = Me.TextBox3.Text + ";" + Me.TextBox4.Text + ";;" + Me.TextBox5.Text
DVRMS.Credits = sCredits
DVRMS.Subtitle = Me.TextBox1.Text
DVRMS.Synopsis = Me.TextBox2.Text
DVRMS.ParentalRating = Me.ComboBox1.Text
Dim checkedItems As CheckedListBox.CheckedItemCollection = Me.CheckedListBox2.CheckedItems
DVRMS.ClearGenre()
For Each ci As String In checkedItems
DVRMS.AddGenre(ci)
Next
Dim sGenre() As String = Me.TextBox6.Text.Split(System.Environment.NewLine)
For Each ci As String In sGenre
DVRMS.AddGenre(ci)
Next
DVRMS.Save()
bIsDirty = False
Me.CheckedListBox1.SetItemCheckState(Me.CheckedListBox1.SelectedIndex, CheckState.Checked)
End Sub
Private Sub SaveDVRMSFiles()
My.Settings.Save()
If bIsDirty Then
Dim obj As CheckedListBoxItem = Me.CheckedListBox1.SelectedItem
If obj IsNot Nothing Then _
Me.SaveMetaAttributes(obj.item)
End If
For Each clbi As CheckedListBoxItem In Me.CheckedListBox1.Items
CType(clbi.item, DVRMSItem).Save()
Next
End Sub
#Region "Node Parsing"
''' <summary>
'''
''' </summary>
''' <param name="oNode"></param>
''' <param name="xPath"></param>
''' <returns></returns>
''' <remarks></remarks>
Private Function NodeInnerText(ByVal oNode As XmlNode, ByVal xPath As String) As String
Return NodeInnerText(oNode, xPath, Nothing)
End Function
''' <summary>
'''
''' </summary>
''' <param name="oNode"></param>
''' <param name="xPath"></param>
''' <param name="sDefault"></param>
''' <returns></returns>
''' <remarks></remarks>
Private Function NodeInnerText(ByVal oNode As XmlNode, ByVal xPath As String, ByVal sDefault As String) As String
Dim aNode As XmlNode = oNode.SelectSingleNode("./" + xPath)
If aNode IsNot Nothing Then Return CType(aNode, XmlElement).InnerText
Return sDefault
End Function
''' <summary>
'''
''' </summary>
''' <param name="oNode"></param>
''' <param name="xPath"></param>
''' <returns></returns>
''' <remarks></remarks>
Private Function NodeInnerList(ByVal oNode As XmlNode, ByVal xPath As String) As String()
Dim aNode As XmlNode = oNode.SelectSingleNode("./" + xPath)
If aNode IsNot Nothing Then
If Not aNode.HasChildNodes Then Return Nothing
Dim rslt(aNode.ChildNodes.Count - 1) As String, ii As Integer = 0
For Each cNode As XmlNode In aNode.ChildNodes
rslt(ii) = cNode.InnerText : ii += 1
Next
Return rslt
End If
Return Nothing
End Function
''' <summary>
'''
''' </summary>
''' <param name="oNode"></param>
''' <param name="xPath"></param>
''' <param name="xAttr"></param>
''' <returns></returns>
''' <remarks></remarks>
Private Function NodeInnerList(ByVal oNode As XmlNode, ByVal xPath As String, ByVal xAttr() As String) As String()
Dim aNode As XmlNode = oNode.SelectSingleNode("./" + xPath)
If aNode IsNot Nothing Then
If Not aNode.HasChildNodes Then Return Nothing
Dim rslt(aNode.ChildNodes.Count - 1) As String, ii As Integer = 0
For Each cNode As XmlNode In aNode.ChildNodes
If CType(cNode, XmlElement).HasAttributes Then
For Each attr As String In xAttr
If CType(cNode, XmlElement).HasAttribute(attr) Then
rslt(ii) += cNode.Attributes(attr).Value
End If
rslt(ii) += "|"
Next
ii += 1
Else
Return Nothing
End If
Next
Return rslt
End If
Return Nothing
End Function
#End Region
Private Sub CheckedListBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckedListBox2.SelectedIndexChanged
End Sub
#End Region
#Region " Image Functions "
Private Sub OMLThumb(ByVal sFileName As String, ByVal sNewFileName As String)
If Not IO.File.Exists(sFileName) Then Exit Sub
Dim bImage() As Byte = File.ReadAllBytes(sFileName)
Dim nImage() As Byte = ResizeImageFile(bImage, 378)
IO.File.WriteAllBytes(sNewFileName, nImage)
End Sub
Private Function ResizeImageFile(ByVal imageFile() As Byte, ByVal targetSize As Integer) As Byte()
Dim mstr As MemoryStream = New MemoryStream(imageFile)
Dim oldImage As Image = Image.FromStream(mstr)
Dim newSize As Size = CalculateDimensions(oldImage.Size, targetSize)
Dim newImage As Bitmap = New Bitmap(newSize.Width, newSize.Height, PixelFormat.Format24bppRgb)
Dim canvas As Graphics = Graphics.FromImage(newImage)
canvas.SmoothingMode = SmoothingMode.AntiAlias
canvas.InterpolationMode = InterpolationMode.HighQualityBicubic
canvas.PixelOffsetMode = PixelOffsetMode.HighQuality
canvas.DrawImage(oldImage, New Rectangle(New Point(0, 0), newSize))
Dim m As MemoryStream = New MemoryStream
newImage.Save(m, ImageFormat.Jpeg)
Return m.GetBuffer
canvas.Dispose()
newImage.Dispose()
oldImage.Dispose()
mstr.Dispose()
End Function
Private Function CalculateDimensions(ByVal oldSize As Size, ByVal targetSize As Integer) As Size
Dim newSize As Size = New Size
If (oldSize.Height > oldSize.Width) Then
newSize.Height = targetSize
newSize.Width = CType((oldSize.Width * CType((targetSize / CType(oldSize.Height, Single)), Single)), Integer)
Else
newSize.Width = targetSize
newSize.Height = CType((oldSize.Height * CType((targetSize / CType(oldSize.Width, Single)), Single)), Integer)
End If
Return newSize
End Function
#End Region
End Class