-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainForm.cs
2733 lines (2367 loc) · 93.1 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
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
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// ------------------------------------------------------------------
// DrunkenBakery Zune Tag
// ZuneTag.ZuneTag
//
// <copyright file="MainForm.cs" company="The Drunken Bakery">
// Copyright (c) 2009-2012 The Drunken Bakery. All rights reserved.
// </copyright>
//
// Author: IRS
// ------------------------------------------------------------------
namespace DrunkenBakery.ZuneTag
{
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
using System.Net;
using System.Reflection;
using System.Runtime.InteropServices;
using System.ServiceModel;
using System.Threading;
using System.Windows.Forms;
using DrunkenBakery.ZuneTag.Amazon.ECS;
using DrunkenBakery.ZuneTag.Properties;
using JockerSoft.Media;
using WMFSDKWrapper;
using Image = System.Drawing.Image;
using Timer = System.Threading.Timer;
/// <summary>
/// Main application form which drives all functionality.
/// </summary>
public partial class MainForm : Form
{
#region Constants and Fields
/// <summary>
/// The amazon id.
/// </summary>
private const string AmazonID = "AKIAI344DCI3P6HJXGOA";
/// <summary>
/// The amazon key.
/// </summary>
private const string AmazonKey = "dM23mxiQzaMEy0O2I1qIacqJijV/JyqIlFRgTP+Y";
/// <summary>
/// The language.
/// </summary>
private const ushort Language = 0;
/// <summary>
/// The screen lines.
/// </summary>
private const int ScreenLines = 1000;
/// <summary>
/// The screen refresh.
/// </summary>
private const int ScreenRefresh = 1;
/// <summary>
/// The stream.
/// </summary>
private const ushort Stream = 65535;
/// <summary>
/// The this app.
/// </summary>
private const string ThisApp = "Zune Tag Editor";
/// <summary>
/// The this publisher.
/// </summary>
private const string ThisPublisher = "The Drunken Bakery";
/// <summary>
/// The type movie.
/// </summary>
private const string TypeMovie = "C9-7F-B8-A9-47-BD-F0-4B-AC-4F-65-5B-89-F7-D8-68";
/// <summary>
/// The type music.
/// </summary>
private const string TypeMusic = "E2-89-E6-E3-8C-BA-30-43-96-DF-A0-EE-EF-FA-68-76";
/// <summary>
/// The type tv.
/// </summary>
private const string TypeTV = "8A-25-7F-BA-F7-62-A9-47-B2-1F-46-51-C4-2A-00-0E";
/// <summary>
/// The type video.
/// </summary>
private const string TypeVideo = "BD-30-98-DB-B3-3A-AB-4F-8A-37-1A-99-5F-7F-F7-4B";
/// <summary>
/// The new stream.
/// </summary>
private const ushort newStream = 0;
/// <summary>
/// The _ screen log timer.
/// </summary>
private readonly Timer _ScreenLogTimer;
/// <summary>
/// The _ screen log timer callback.
/// </summary>
private readonly TimerCallback _ScreenLogTimerCallback;
/// <summary>
/// The _attributes.
/// </summary>
private readonly List<Attribute> _attributes = new List<Attribute>();
/// <summary>
/// The lvitems.
/// </summary>
private readonly List<ListViewItem> lvitems = new List<ListViewItem>();
/// <summary>
/// The frm about.
/// </summary>
private Form frmAbout;
/// <summary>
/// The index primary video.
/// </summary>
private ushort indexPrimaryVideo;
/// <summary>
/// The index secondary video.
/// </summary>
private ushort indexSecondaryVideo;
/// <summary>
/// The page number.
/// </summary>
private int pageNumber;
/// <summary>
/// The safe page number.
/// </summary>
private int safePageNumber;
#endregion
#region Constructors and Destructors
/// <summary>
/// Initializes a new instance of the <see cref="MainForm" /> class.
/// </summary>
public MainForm()
{
this.InitializeComponent();
// Upgrade settings from older version
Assembly a = Assembly.GetExecutingAssembly();
Version appVersion = a.GetName().Version;
string appVersionString = appVersion.ToString();
if (Settings.Default.ApplicationVersion != appVersion.ToString())
{
Settings.Default.Upgrade();
Settings.Default.ApplicationVersion = appVersionString;
}
// Form title bar
this.Text = ThisApp + " freshly baked at " + ThisPublisher;
// Tooltips
this.toolTip1.SetToolTip(this.cmdSave, "Change video type");
this.toolTip2.SetToolTip(this.cmdModify, "Save this attribute back to the file");
this.toolTip3.SetToolTip(this.cmdMovieSave, "Update Movie with these tags");
this.toolTip4.SetToolTip(this.cmdMusicSave, "Update Music Video with these tags");
this.toolTip5.SetToolTip(this.cmdTVSave, "Update TV Show with these tags");
this.toolTip6.SetToolTip(this.cmdVideoSave, "Update Video with these tags");
this.toolTip7.SetToolTip(this.cmdReset, "Hard reset the video type attributes");
this.toolTip8.SetToolTip(this.cmdCopyAz, "Copy the tags back ready for saving");
this.toolTip9.SetToolTip(this.cmdAmazonSearch, "Search Amazon for videos that match");
this.toolTip10.SetToolTip(this.cmdBrowse, "Open a WMV media file");
// Initialise Event Views
this.InitEventView(this.lvStatus);
// Initialise Media Types
this.InitMediaTypes();
// Logging
this.AddLogEntry("--------------------------------------------------", LogType.Info);
this.AddLogEntry("Welcome to the " + ThisApp + " v" + appVersionString, LogType.Info);
this.AddLogEntry("Ready.");
// Start Timers
this._ScreenLogTimerCallback = this._ScreenLogTimer_Elapsed;
this._ScreenLogTimer = new Timer(
this._ScreenLogTimerCallback, null, Convert.ToInt32(ScreenRefresh) * 1000, Timeout.Infinite);
}
#endregion
#region Delegates
/// <summary>
/// The flush output delegate.
/// </summary>
/// <param name="lv">
/// The lv.
/// </param>
private delegate void FlushOutputDelegate(ListView lv);
/// <summary>
/// The pause output delegate.
/// </summary>
/// <param name="lv">
/// The lv.
/// </param>
private delegate void PauseOutputDelegate(ListView lv);
/// <summary>
/// The resume output delegate.
/// </summary>
/// <param name="lv">
/// The lv.
/// </param>
private delegate void ResumeOutputDelegate(ListView lv);
#endregion
#region Enums
/// <summary>
/// Severity of logging entry
/// </summary>
private enum LogType
{
/// <summary>
/// The success.
/// </summary>
Success,
/// <summary>
/// The fail.
/// </summary>
Fail,
/// <summary>
/// The info.
/// </summary>
Info
}
/// <summary>
/// The media type.
/// </summary>
private enum MediaType
{
/// <summary>
/// The unknown.
/// </summary>
Unknown,
/// <summary>
/// The video.
/// </summary>
Video,
/// <summary>
/// The movie.
/// </summary>
Movie,
/// <summary>
/// The music.
/// </summary>
Music,
/// <summary>
/// The tv.
/// </summary>
TV
}
#endregion
#region Public Methods and Operators
/// <summary>
/// Add an attribute with the specifed language index.
/// </summary>
/// <param name="pwszFileName">
/// Name of the PWSZ file.
/// </param>
/// <param name="wStreamNum">
/// The w stream num.
/// </param>
/// <param name="pwszAttribName">
/// Name of the PWSZ attrib.
/// </param>
/// <param name="wAttribType">
/// Type of the w attrib.
/// </param>
/// <param name="pwszAttribValue">
/// The PWSZ attrib value.
/// </param>
/// <param name="wLangIndex">
/// Index of the w lang.
/// </param>
/// <returns>
/// The <see cref="bool"/>.
/// </returns>
public bool AddAttrib(
string pwszFileName,
ushort wStreamNum,
string pwszAttribName,
ushort wAttribType,
string pwszAttribValue,
ushort wLangIndex)
{
IWMMetadataEditor MetadataEditor = null;
IWMHeaderInfo3 HeaderInfo3;
byte[] pbAttribValue;
int nAttribValueLen;
var AttribDataType = (WMT_ATTR_DATATYPE)wAttribType;
ushort wAttribIndex = 0;
try
{
if (!this.TranslateAttrib(AttribDataType, pwszAttribValue, out pbAttribValue, out nAttribValueLen))
{
return false;
}
WMFSDKFunctions.WMCreateEditor(out MetadataEditor);
MetadataEditor.Open(pwszFileName);
HeaderInfo3 = (IWMHeaderInfo3)MetadataEditor;
HeaderInfo3.AddAttribute(
wStreamNum,
pwszAttribName,
out wAttribIndex,
AttribDataType,
wLangIndex,
pbAttribValue,
(uint)nAttribValueLen);
}
catch (Exception)
{
// AddLogEntry(e.Message, LogType.Fail);
return false;
}
finally
{
MetadataEditor.Flush();
MetadataEditor.Close();
}
return true;
}
/// <summary>
/// Attribs the exists.
/// </summary>
/// <param name="pwszFileName">
/// Name of the PWSZ file.
/// </param>
/// <param name="wStreamNum">
/// The w stream num.
/// </param>
/// <param name="searchAttrib">
/// The search attrib.
/// </param>
/// <returns>
/// The <see cref="bool"/>.
/// </returns>
public bool AttribExists(string pwszFileName, ushort wStreamNum, string searchAttrib)
{
bool isFound = false;
try
{
IWMMetadataEditor MetadataEditor;
IWMHeaderInfo3 HeaderInfo3;
ushort wAttributeCount = 0;
WMFSDKFunctions.WMCreateEditor(out MetadataEditor);
MetadataEditor.Open(pwszFileName);
HeaderInfo3 = (IWMHeaderInfo3)MetadataEditor;
HeaderInfo3.GetAttributeCountEx(wStreamNum, out wAttributeCount);
for (ushort wAttribIndex = 0; (wAttribIndex < wAttributeCount) && !isFound; wAttribIndex++)
{
WMT_ATTR_DATATYPE wAttribType;
ushort wLangIndex = 0;
string pwszAttribName = null;
byte[] pbAttribValue = null;
ushort wAttribNameLen = 0;
uint dwAttribValueLen = 0;
HeaderInfo3.GetAttributeByIndexEx(
wStreamNum,
wAttribIndex,
pwszAttribName,
ref wAttribNameLen,
out wAttribType,
out wLangIndex,
pbAttribValue,
ref dwAttribValueLen);
pwszAttribName = new String((char)0, wAttribNameLen);
pbAttribValue = new byte[dwAttribValueLen];
HeaderInfo3.GetAttributeByIndexEx(
wStreamNum,
wAttribIndex,
pwszAttribName,
ref wAttribNameLen,
out wAttribType,
out wLangIndex,
pbAttribValue,
ref dwAttribValueLen);
if (pwszAttribName.Substring(0, pwszAttribName.Length - 1) == searchAttrib)
{
isFound = true;
}
}
// Close file
MetadataEditor.Close();
}
catch (Exception e)
{
this.AddLogEntry(e.Message, LogType.Fail);
return false;
}
return isFound;
}
/// <summary>
/// Delete the attribute at the specified index.
/// </summary>
/// <param name="pwszFileName">
/// Name of the PWSZ file.
/// </param>
/// <param name="wStreamNum">
/// The w stream num.
/// </param>
/// <param name="wAttribIndex">
/// Index of the w attrib.
/// </param>
/// <returns>
/// The <see cref="bool"/>.
/// </returns>
public bool DeleteAttrib(string pwszFileName, ushort wStreamNum, ushort wAttribIndex)
{
try
{
IWMMetadataEditor MetadataEditor;
IWMHeaderInfo3 HeaderInfo3;
WMFSDKFunctions.WMCreateEditor(out MetadataEditor);
MetadataEditor.Open(pwszFileName);
HeaderInfo3 = (IWMHeaderInfo3)MetadataEditor;
HeaderInfo3.DeleteAttribute(wStreamNum, wAttribIndex);
MetadataEditor.Flush();
MetadataEditor.Close();
}
catch (Exception e)
{
this.AddLogEntry(e.Message, LogType.Fail);
return false;
}
return true;
}
/// <summary>
/// Creates a metadata editor and opens the file.
/// </summary>
/// <param name="pwszInFile">
/// The PWSZ in file.
/// </param>
/// <param name="ppEditor">
/// The pp editor.
/// </param>
/// <returns>
/// The <see cref="bool"/>.
/// </returns>
public bool EditorOpenFile(string pwszInFile, out IWMMetadataEditor ppEditor)
{
ppEditor = null;
try
{
WMFSDKFunctions.WMCreateEditor(out ppEditor);
ppEditor.Open(pwszInFile);
}
catch (COMException e)
{
this.AddLogEntry(e.Message, LogType.Fail);
return false;
}
return true;
}
/// <summary>
/// Generates the image dimensions.
/// </summary>
/// <param name="currW">
/// The curr W.
/// </param>
/// <param name="currH">
/// The curr H.
/// </param>
/// <param name="destW">
/// The dest W.
/// </param>
/// <param name="destH">
/// The dest H.
/// </param>
/// <returns>
/// The <see cref="Size"/>.
/// </returns>
public Size GenerateImageDimensions(int currW, int currH, int destW, int destH)
{
// double to hold the final multiplier to use when scaling the image
double multiplier = 0;
// string for holding layout
string layout;
// determine if it's Portrait or Landscape
if (currH > currW)
{
layout = "portrait";
}
else
{
layout = "landscape";
}
switch (layout.ToLower())
{
case "portrait":
// calculate multiplier on heights
if (destH > destW)
{
multiplier = destW / (double)currW;
}
else
{
multiplier = destH / (double)currH;
}
break;
case "landscape":
// calculate multiplier on widths
if (destH > destW)
{
multiplier = destW / (double)currW;
}
else
{
multiplier = destH / (double)currH;
}
break;
}
// return the new image dimensions
return new Size((int)(currW * multiplier), (int)(currH * multiplier));
}
/// <summary>
/// Modifies the value of the specified attribute.
/// </summary>
/// <param name="pwszFileName">
/// Name of the PWSZ file.
/// </param>
/// <param name="wStreamNum">
/// The w stream num.
/// </param>
/// <param name="wAttribIndex">
/// Index of the w attrib.
/// </param>
/// <param name="wAttribType">
/// Type of the w attrib.
/// </param>
/// <param name="pwszAttribValue">
/// The PWSZ attrib value.
/// </param>
/// <param name="wLangIndex">
/// Index of the w lang.
/// </param>
/// <returns>
/// The <see cref="bool"/>.
/// </returns>
public bool ModifyAttrib(
string pwszFileName,
ushort wStreamNum,
ushort wAttribIndex,
ushort wAttribType,
string pwszAttribValue,
ushort wLangIndex)
{
IWMMetadataEditor MetadataEditor = null;
IWMHeaderInfo3 HeaderInfo3;
byte[] pbAttribValue;
int nAttribValueLen;
var AttribDataType = (WMT_ATTR_DATATYPE)wAttribType;
try
{
if (!this.TranslateAttrib(AttribDataType, pwszAttribValue, out pbAttribValue, out nAttribValueLen))
{
return false;
}
WMFSDKFunctions.WMCreateEditor(out MetadataEditor);
MetadataEditor.Open(pwszFileName);
HeaderInfo3 = (IWMHeaderInfo3)MetadataEditor;
HeaderInfo3.ModifyAttribute(
wStreamNum, wAttribIndex, AttribDataType, wLangIndex, pbAttribValue, (uint)nAttribValueLen);
}
catch (Exception e)
{
this.AddLogEntry(e.Message, LogType.Fail);
return false;
}
finally
{
MetadataEditor.Flush();
MetadataEditor.Close();
}
return true;
}
/// <summary>
/// Displays the specified attribute.
/// </summary>
/// <param name="wIndex">
/// Index of the w.
/// </param>
/// <param name="wStream">
/// The w stream.
/// </param>
/// <param name="pwszName">
/// Name of the PWSZ.
/// </param>
/// <param name="AttribDataType">
/// Type of the attrib data.
/// </param>
/// <param name="wLangID">
/// The w lang ID.
/// </param>
/// <param name="pbValue">
/// The pb value.
/// </param>
/// <param name="dwValueLen">
/// The dw value len.
/// </param>
public void PrintAttribute(
ushort wIndex,
ushort wStream,
string pwszName,
WMT_ATTR_DATATYPE AttribDataType,
ushort wLangID,
byte[] pbValue,
uint dwValueLen)
{
string pwszValue = string.Empty;
//
// Make the data type string
//
string pwszType = "Unknown";
string[] pTypes = { "DWORD", "STRING", "BINARY", "BOOL", "QWORD", "WORD", "GUID" };
if (pTypes.Length > Convert.ToInt32(AttribDataType))
{
pwszType = pTypes[Convert.ToInt32(AttribDataType)];
}
//
// The attribute value.
//
switch (AttribDataType)
{
// String
case WMT_ATTR_DATATYPE.WMT_TYPE_STRING:
if (0 == dwValueLen)
{
pwszValue = "***** NULL *****";
}
else
{
if ((0xFE == Convert.ToInt16(pbValue[0])) && (0xFF == Convert.ToInt16(pbValue[1])))
{
pwszValue = "\"UTF-16LE BOM+\"";
if (4 <= dwValueLen)
{
for (int i = 0; i < pbValue.Length - 2; i += 2)
{
pwszValue += Convert.ToString(BitConverter.ToChar(pbValue, i));
}
}
pwszValue = pwszValue + "\"";
}
else if ((0xFF == Convert.ToInt16(pbValue[0])) && (0xFE == Convert.ToInt16(pbValue[1])))
{
pwszValue = "\"UTF-16BE BOM+\"";
if (4 <= dwValueLen)
{
for (int i = 0; i < pbValue.Length - 2; i += 2)
{
pwszValue += Convert.ToString(BitConverter.ToChar(pbValue, i));
}
}
pwszValue = pwszValue + "\"";
}
else
{
pwszValue = "\"";
if (2 <= dwValueLen)
{
for (int i = 0; i < pbValue.Length - 2; i += 2)
{
pwszValue += Convert.ToString(BitConverter.ToChar(pbValue, i));
}
}
pwszValue += "\"";
}
}
break;
// Binary
case WMT_ATTR_DATATYPE.WMT_TYPE_BINARY:
pwszValue = "[" + dwValueLen.ToString() + " bytes]";
break;
// Boolean
case WMT_ATTR_DATATYPE.WMT_TYPE_BOOL:
if (BitConverter.ToBoolean(pbValue, 0))
{
pwszValue = "True";
}
else
{
pwszValue = "False";
}
break;
// DWORD
case WMT_ATTR_DATATYPE.WMT_TYPE_DWORD:
uint dwValue = BitConverter.ToUInt32(pbValue, 0);
pwszValue = dwValue.ToString();
break;
// QWORD
case WMT_ATTR_DATATYPE.WMT_TYPE_QWORD:
ulong qwValue = BitConverter.ToUInt64(pbValue, 0);
pwszValue = qwValue.ToString();
break;
// WORD
case WMT_ATTR_DATATYPE.WMT_TYPE_WORD:
uint wValue = BitConverter.ToUInt16(pbValue, 0);
pwszValue = wValue.ToString();
break;
// GUID
case WMT_ATTR_DATATYPE.WMT_TYPE_GUID:
pwszValue = BitConverter.ToString(pbValue, 0, pbValue.Length);
break;
default:
break;
}
// Add to attribute list
var _attribute = new Attribute(
wIndex, pwszName.Substring(0, pwszName.Length - 1), pwszValue, AttribDataType);
// Add to list
this._attributes.Add(_attribute);
}
/// <summary>
/// Set the specified attribute.
/// </summary>
/// <param name="pwszFileName">
/// Name of the PWSZ file.
/// </param>
/// <param name="wStreamNum">
/// The w stream num.
/// </param>
/// <param name="pwszAttribName">
/// Name of the PWSZ attrib.
/// </param>
/// <param name="wAttribType">
/// Type of the w attrib.
/// </param>
/// <param name="pwszAttribValue">
/// The PWSZ attrib value.
/// </param>
/// <returns>
/// The <see cref="bool"/>.
/// </returns>
public bool SetAttrib(
string pwszFileName, ushort wStreamNum, string pwszAttribName, ushort wAttribType, string pwszAttribValue)
{
try
{
IWMMetadataEditor MetadataEditor;
IWMHeaderInfo3 HeaderInfo3;
byte[] pbAttribValue;
int nAttribValueLen;
var AttribDataType = (WMT_ATTR_DATATYPE)wAttribType;
if (!this.TranslateAttrib(AttribDataType, pwszAttribValue, out pbAttribValue, out nAttribValueLen))
{
return false;
}
WMFSDKFunctions.WMCreateEditor(out MetadataEditor);
MetadataEditor.Open(pwszFileName);
HeaderInfo3 = (IWMHeaderInfo3)MetadataEditor;
HeaderInfo3.SetAttribute(
wStreamNum, pwszAttribName, AttribDataType, pbAttribValue, (ushort)nAttribValueLen);
MetadataEditor.Flush();
MetadataEditor.Close();
}
catch (Exception e)
{
this.AddLogEntry(e.Message, LogType.Fail);
return false;
}
return true;
}
/// <summary>
/// Displays all attributes for the specified stream.
/// </summary>
/// <param name="pwszFileName">
/// Name of the PWSZ file.
/// </param>
/// <param name="wStreamNum">
/// The w stream num.
/// </param>
/// <returns>
/// The <see cref="bool"/>.
/// </returns>
public bool ShowAttributes(string pwszFileName, ushort wStreamNum)
{
try
{
IWMMetadataEditor MetadataEditor;
IWMHeaderInfo3 HeaderInfo3;
ushort wAttributeCount;
WMFSDKFunctions.WMCreateEditor(out MetadataEditor);
MetadataEditor.Open(pwszFileName);
HeaderInfo3 = (IWMHeaderInfo3)MetadataEditor;
HeaderInfo3.GetAttributeCount(wStreamNum, out wAttributeCount);
for (ushort wAttribIndex = 0; wAttribIndex < wAttributeCount; wAttribIndex++)
{
WMT_ATTR_DATATYPE wAttribType;
string pwszAttribName = null;
byte[] pbAttribValue = null;
ushort wAttribNameLen = 0;
ushort wAttribValueLen = 0;
HeaderInfo3.GetAttributeByIndex(
wAttribIndex,
ref wStreamNum,
pwszAttribName,
ref wAttribNameLen,
out wAttribType,
pbAttribValue,
ref wAttribValueLen);
pbAttribValue = new byte[wAttribValueLen];
pwszAttribName = new String((char)0, wAttribNameLen);
HeaderInfo3.GetAttributeByIndex(
wAttribIndex,
ref wStreamNum,
pwszAttribName,
ref wAttribNameLen,
out wAttribType,
pbAttribValue,
ref wAttribValueLen);
this.PrintAttribute(
wAttribIndex, wStreamNum, pwszAttribName, wAttribType, 0, pbAttribValue, wAttribValueLen);
}
}
catch (Exception e)
{
this.AddLogEntry(e.Message, LogType.Fail);
return false;
}
return true;
}
/// <summary>
/// Displays all attributes for the specified stream, with support for GetAttributeByIndexEx.
/// </summary>
/// <param name="pwszFileName">
/// Name of the PWSZ file.
/// </param>
/// <param name="wStreamNum">
/// The w stream num.
/// </param>
/// <returns>
/// The <see cref="bool"/>.
/// </returns>
public bool ShowAttributes3(string pwszFileName, ushort wStreamNum)
{
try
{
IWMMetadataEditor MetadataEditor;
IWMHeaderInfo3 HeaderInfo3;
ushort wAttributeCount = 0;
WMFSDKFunctions.WMCreateEditor(out MetadataEditor);
MetadataEditor.Open(pwszFileName);
HeaderInfo3 = (IWMHeaderInfo3)MetadataEditor;
HeaderInfo3.GetAttributeCountEx(wStreamNum, out wAttributeCount);
for (ushort wAttribIndex = 0; wAttribIndex < wAttributeCount; wAttribIndex++)
{
WMT_ATTR_DATATYPE wAttribType;
ushort wLangIndex = 0;
string pwszAttribName = null;
byte[] pbAttribValue = null;
ushort wAttribNameLen = 0;
uint dwAttribValueLen = 0;
HeaderInfo3.GetAttributeByIndexEx(
wStreamNum,
wAttribIndex,
pwszAttribName,
ref wAttribNameLen,