-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.xaml.cs
3800 lines (3198 loc) · 122 KB
/
MainWindow.xaml.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
using NLog;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.Eventing.Reader;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Linq;
using JetBrains.Annotations;
using TVRename.Ipc;
using Directory = Alphaleonis.Win32.Filesystem.Directory;
using File = Alphaleonis.Win32.Filesystem.File;
using FileInfo = Alphaleonis.Win32.Filesystem.FileInfo;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Threading;
using TVRename.View.Supporting;
using TVRename.ViewModel;
using MessageBox = System.Windows.MessageBox;
using DataGrid = System.Windows.Controls.DataGrid;
namespace TVRename
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
MyShowsViewModel viewMyShowsViewModel;
MainWindowViewModel mainViewModel;
WhenToWatchViewModel wtwViewModel;
public MainWindow(TVDoc doc, [NotNull] SplashViewModel splash,Dispatcher dispy, bool showUi)
{
mDoc = doc;
busy = 0;
mLastEpClicked = null;
mLastFolderClicked = null;
mLastSeasonClicked = null;
mLastShowsClicked = null;
mLastActionsClicked = null;
mInternalChange = 0;
mFoldersToOpen = new List<string>();
internalCheckChange = false;
InitializeComponent();
SetupIpc();
try
{
bool layoutLoadSuccess = LoadLayoutXml();
if (!layoutLoadSuccess)
{
Logger.Info("Error loading layout XML, but no error raised");
}
}
catch (Exception e)
{
// silently fail, doesn't matter too much
Logger.Info(e, "Error loading layout XML");
}
//lvWhenToWatch.ListViewItemSorter = new DateSorterWtw(0);
if (mDoc.Args.Hide || !showUi)
{
WindowState = WindowState.Minimized;
Visibility = Visibility.Hidden;
Hide();
}
//tmrPeriodicScan.Enabled = false;
UpdateSplashStatus(splash,dispy, "Filling Shows");
FillMyShows();
UpdateSearchButtons();
//ClearInfoWindows();
UpdateSplashPercent(splash, dispy, 10);
UpdateSplashStatus(splash, dispy, "Updating WTW");
mDoc.DoWhenToWatch(true, true, WindowState == WindowState.Minimized);
UpdateSplashPercent(splash, dispy, 40);
//FillWhenToWatchList();
UpdateSplashPercent(splash, dispy, 60);
UpdateSplashStatus(splash, dispy, "Write Upcoming");
mDoc.WriteUpcoming();
UpdateSplashStatus(splash, dispy, "Write Recent");
mDoc.WriteRecent();
UpdateSplashStatus(splash, dispy, "Setting Notifications");
ShowHideNotificationIcon();
viewMyShowsViewModel = new MyShowsViewModel(mDoc.Library);
wtwViewModel = new WhenToWatchViewModel(mDoc.Library);
mainViewModel = new MainWindowViewModel() {Airing = "Next", Downloading = "Idle", Status = 50};
viewMyShowsViewModel.Filter = TVSettings.Instance.Filter;
this.tbMyShows.DataContext = viewMyShowsViewModel;
this.sbBottomStatusBar.DataContext = mainViewModel;
this.tbWTW.DataContext = wtwViewModel;
//this.MyShowTree.DataContext = viewMyShowsViewModel.VisibleShows;
int t = TVSettings.Instance.StartupTab;
if (t < tabControl1.Items.Count)
{
tabControl1.SelectedIndex = TVSettings.Instance.StartupTab;
}
tabControl1_SelectedIndexChanged(null, null);
UpdateSplashStatus(splash, dispy, "Creating Monitors");
mAutoFolderMonitor = new AutoFolderMonitor(mDoc, this);
//TODO tmrPeriodicScan.Interval = TVSettings.Instance.PeriodicCheckPeriod();
UpdateSplashStatus(splash, dispy, "Starting Monitor");
if (TVSettings.Instance.MonitorFolders)
{
mAutoFolderMonitor.Start();
}
//TODO tmrPeriodicScan.Enabled = TVSettings.Instance.RunPeriodicCheck();
UpdateSplashStatus(splash, dispy, "Running autoscan");
}
public static string EXPLORE_PROXY => "http://www.tvrename.com/EXPLOREPROXY";
public static string WATCH_PROXY => "http://www.tvrename.com/WATCHPROXY";
public void Invoke(object afmDoAll)
{
throw new System.NotImplementedException();
}
// right click commands
public enum RightClickCommands
{
kEpisodeGuideForShow = 1,
kVisitTvdbEpisode,
kVisitTvdbSeason,
kVisitTvdbSeries,
kScanSpecificSeries,
kWhenToWatchSeries,
kForceRefreshSeries,
kBtSearchFor,
kActionIgnore,
kActionBrowseForFile,
kActionAction,
kActionDelete,
kActionIgnoreSeason,
kEditShow,
kEditSeason,
kDeleteShow,
kUpdateImages,
kActionRevert,
kWatchBase = 1000,
kOpenFolderBase = 2000,
kSearchForBase = 3000
}
#region Delegates
public delegate void AutoFolderMonitorDelegate();
#endregion
private int busy;
private TVDoc mDoc;
private bool internalCheckChange;
private int lastDlRemaining;
public AutoFolderMonitorDelegate AfmFullScan;
public AutoFolderMonitorDelegate AfmRecentScan;
public AutoFolderMonitorDelegate AfmQuickScan;
public AutoFolderMonitorDelegate AfmDoAll;
private List<string> mFoldersToOpen;
private int mInternalChange;
private List<FileInfo> mLastFl;
private Point mLastNonMaximizedLocation;
private Size mLastNonMaximizedSize;
private readonly AutoFolderMonitor mAutoFolderMonitor;
private bool treeExpandCollapseToggle = true;
private ItemList mLastActionsClicked;
private ProcessedEpisode mLastEpClicked;
private readonly string mLastFolderClicked;
private Season mLastSeasonClicked;
private List<ShowItem> mLastShowsClicked;
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
private static void UpdateSplashStatus([NotNull] SplashViewModel splashScreen, Dispatcher dispy, string text)
{
Logger.Info($"Splash Screen Updated with: {text}");
dispy.Invoke(()=>splashScreen.Status = text);
}
private static void UpdateSplashPercent([NotNull] SplashViewModel splashScreen, Dispatcher dispy, int num)
{
dispy.Invoke(() => splashScreen.Progress = num);
}
private static int BgdlLongInterval() => 1000 * 60 * 60; // one hour
private void MoreBusy() => Interlocked.Increment(ref busy);
private void LessBusy() => Interlocked.Decrement(ref busy);
private void SetupIpc()
{
AfmFullScan += Scan;
AfmQuickScan += QuickScan;
AfmRecentScan += RecentScan;
AfmDoAll += ProcessAll;
}
private void ProcessArgs()
{
// TODO: Unify command line handling between here and in Program.cs
if (mDoc.Args.Scan)
{
UiScan(null, true, TVSettings.ScanType.Full);
}
if (mDoc.Args.QuickScan)
{
UiScan(null, true, TVSettings.ScanType.Quick);
}
if (mDoc.Args.RecentScan)
{
UiScan(null, true, TVSettings.ScanType.Recent);
}
if (mDoc.Args.DoAll)
{
ProcessAll();
}
if (mDoc.Args.Quit || mDoc.Args.Hide)
{
Close();
}
}
private void UpdateSearchButtons()
{
string name = TVDoc.GetSearchers().Name(TVSettings.Instance.TheSearchers.CurrentSearchNum());
//bnWTWBTSearch.Enabled = !string.IsNullOrWhiteSpace(name);
//bnActionBTSearch.Enabled = !string.IsNullOrWhiteSpace(name);
//bnWTWBTSearch.Text = UseCustom(lvWhenToWatch) ? "Search" : name;
//bnActionBTSearch.Text = UseCustom(lvAction) ? "Search" : name;
//FillEpGuideHtml();
}
private void visitWebsiteToolStripMenuItem_Click(object sender, EventArgs eventArgs) =>
Helpers.SysOpen("http://tvrename.com");
private void exitToolStripMenuItem_Click(object sender, EventArgs e) => Close();
/* private static bool UseCustom([NotNull] ListView view)
{
foreach (ListViewItem lvi in view.SelectedItems)
{
if (!(lvi.Tag is ProcessedEpisode pe))
{
continue;
}
if (!pe.Show.UseCustomSearchUrl)
{
continue;
}
if (string.IsNullOrWhiteSpace(pe.Show.CustomSearchUrl))
{
continue;
}
return true;
}
return false;
}*/
private void UI_Load(object sender, EventArgs e)
{
ShowInTaskbar = TVSettings.Instance.ShowInTaskbar && !mDoc.Args.Hide;
/*
foreach (TabPage tp in tabControl1.TabPages) // grr! TODO: why does it go white?
{
tp.BackColor = SystemColors.Control;
}
// MAH: Create a "Clear" button in the Filter Text Box
Button filterButton = new Button
{
Size = new Size(16, 16),
Cursor = Cursors.Default,
Image = Properties.Resources.DeleteSmall,
Name = "Clear"
};
filterButton.Location = new Point(filterTextBox.ClientSize.Width - filterButton.Width,
((filterTextBox.ClientSize.Height - 16) / 2) + 1);
filterButton.Click += filterButton_Click;
filterTextBox.Controls.Add(filterButton);
// Send EM_SETMARGINS to prevent text from disappearing underneath the button
NativeMethods.SendMessage(filterTextBox.Handle, 0xd3, (IntPtr)2, (IntPtr)(filterButton.Width << 16));
betaToolsToolStripMenuItem.Visible = TVSettings.Instance.IncludeBetaUpdates();
*/
Show();
UI_LocationChanged(null, null);
UI_SizeChanged(null, null);
/* ToolTip tt = new ToolTip();
tt.SetToolTip(btnActionQuickScan,
"Scan shows with missing recent aired episodes and and shows that match files in the search folders");
tt.SetToolTip(bnActionRecentCheck, "Scan shows with recent aired episodes");
tt.SetToolTip(bnActionCheck, "Scan all shows");
backgroundDownloadToolStripMenuItem.Checked = TVSettings.Instance.BGDownload;
offlineOperationToolStripMenuItem.Checked = TVSettings.Instance.OfflineMode;
BGDownloadTimer.Interval = 10000; // first time
if (TVSettings.Instance.BGDownload)
{
BGDownloadTimer.Start();
}
UpdateTimer.Start();
quickTimer.Start();*/
if (TVSettings.Instance.RunOnStartUp())
{
RunAutoScan("Startup Scan");
}
}
// MAH: Added in support of the Filter TextBox Button
private void filterButton_Click(object sender, EventArgs e) => filterTextBox.Clear();
private DataGrid ListViewByName([NotNull] string name)
{
switch (name)
{
case "WhenToWatch":
return lvWhenToWatch;
case "AllInOne":
return lvAction;
default:
throw new ArgumentException("Inappropriate ListViewParameter " + name);
}
}
private void flushCacheToolStripMenuItem_Click(object sender, EventArgs e)
{
if (busy != 0)
{
MessageBox.Show("Can't refresh until background download is complete");
return;
}
MessageBoxResult res = MessageBox.Show(
"Are you sure you want to remove all " +
"locally stored TheTVDB information? This information will have to be downloaded again. You " +
"can force the refresh of a single show by holding down the \"Control\" key while clicking on " +
"the \"Refresh\" button in the \"My Shows\" tab.",
"Force Refresh All", MessageBoxButton.YesNo, MessageBoxImage.Warning);
if (res == MessageBoxResult.Yes)
{
TheTVDB.Instance.ForgetEverything();
FillMyShows();
//FillEpGuideHtml();
//FillWhenToWatchList();
BGDownloadTimer_QuickFire();
}
}
private bool LoadWidths([NotNull] XElement xml)
{
string forwho = xml.Attribute("For")?.Value;
if (forwho is null)
{
return false;
}
/*
ListView lv = ListViewByName(forwho);
if (lv is null)
{
return true;
}
int c = 0;
foreach (XElement w in xml.Descendants("Width"))
{
if (c >= lv.Columns.Count)
{
return false;
}
lv.Columns[c++].Width = XmlConvert.ToInt32(w.Value);
}
*/
return true;
}
private bool LoadLayoutXml()
{
if (mDoc.Args.Hide)
{
return true;
}
bool ok = true;
string fn = PathManager.UILayoutFile.FullName;
if (!File.Exists(fn))
{
return true;
}
XElement x = XElement.Load(fn);
if (x.Name.LocalName != "TVRename")
{
return false;
}
if (x.Attribute("Version")?.Value != "2.1")
{
return false;
}
if (!x.Descendants("Layout").Any())
{
return false;
}
SetWindowSize(x.Descendants("Layout").Descendants("Window").First());
foreach (XElement widthXmlElement in x.Descendants("Layout").Descendants("ColumnWidths"))
{
ok = LoadWidths(widthXmlElement) && ok;
}
SetSplitter(x.Descendants("Layout").Descendants("Splitter").First());
return ok;
}
private void SetSplitter([NotNull] XElement x)
{
// splitContainer1.SplitterDistance = int.Parse(x.Attribute("Distance")?.Value ?? "100");
// splitContainer1.Panel2Collapsed = bool.Parse(x.Attribute("HTMLCollapsed")?.Value ?? "false");
// if (splitContainer1.Panel2Collapsed)
// {
// bnHideHTMLPanel.ImageKey = "FillLeft.bmp";
// }
}
private void SetWindowSize([NotNull] XElement x)
{
SetSize(x.Descendants("Size").First());
SetLocation(x.Descendants("Location").First());
WindowState = (x.ExtractBool("Maximized", false))
? WindowState.Maximized
: WindowState.Normal;
}
private void SetLocation([NotNull] XElement x)
{
XAttribute valueX = x.Attribute("X");
XAttribute valueY = x.Attribute("Y");
if (valueX is null)
{
Logger.Error($"Missing X from {x}");
}
if (valueY == null)
{
Logger.Error($"Missing Y from {x}");
}
int xloc = (valueX == null) ? 100 : int.Parse(valueX.Value);
int yloc = (valueY is null) ? 100 : int.Parse(valueY.Value);
//Position = new Point(xloc, yloc);
}
private void SetSize([NotNull] XElement x)
{
XAttribute valueX = x.Attribute("Width");
XAttribute valueY = x.Attribute("Height");
if (valueX is null)
{
Logger.Error($"Missing Width from {x}");
}
if (valueY is null)
{
Logger.Error($"Missing Height from {x}");
}
int xsize = (valueX is null) ? 100 : int.Parse(valueX.Value);
int ysize = (valueY is null) ? 100 : int.Parse(valueY.Value);
//Size = new Size(xsize, ysize);
}
private bool SaveLayoutXml()
{
if (mDoc.Args.Hide)
{
return true;
}
XmlWriterSettings settings = new XmlWriterSettings
{
Indent = true,
NewLineOnAttributes = true
};
using (XmlWriter writer = XmlWriter.Create(PathManager.UILayoutFile.FullName, settings))
{
writer.WriteStartDocument();
writer.WriteStartElement("TVRename");
writer.WriteAttributeToXml("Version", "2.1");
writer.WriteStartElement("Layout");
writer.WriteStartElement("Window");
writer.WriteStartElement("Size");
writer.WriteAttributeToXml("Width", mLastNonMaximizedSize.Width);
writer.WriteAttributeToXml("Height", mLastNonMaximizedSize.Height);
writer.WriteEndElement(); // size
writer.WriteStartElement("Location");
writer.WriteAttributeToXml("X", mLastNonMaximizedLocation.X);
writer.WriteAttributeToXml("Y", mLastNonMaximizedLocation.Y);
writer.WriteEndElement(); // Location
writer.WriteElement("Maximized", WindowState == WindowState.Maximized);
writer.WriteEndElement(); // window
WriteColWidthsXml("WhenToWatch", writer);
WriteColWidthsXml("AllInOne", writer);
writer.WriteStartElement("Splitter");
//writer.WriteAttributeToXml("Distance", splitContainer1.SplitterDistance);
//writer.WriteAttributeToXml("HTMLCollapsed", splitContainer1.Panel2Collapsed);
writer.WriteEndElement(); // splitter
writer.WriteEndElement(); // Layout
writer.WriteEndElement(); // tvrename
writer.WriteEndDocument();
}
return true;
}
private void WriteColWidthsXml([NotNull] string thingName, XmlWriter writer)
{
DataGrid lv = ListViewByName(thingName);
if (lv is null)
{
return;
}
writer.WriteStartElement("ColumnWidths");
writer.WriteAttributeToXml("For", thingName);
foreach (DataGridColumn lvc in lv.Columns)
{
writer.WriteElement("Width", lvc.Width.Value);
}
// ReSharper disable once CommentTypo
writer.WriteEndElement(); // columnwidths
}
private void UI_Closing(object sender, CancelEventArgs e)
{
try
{
if (mDoc.Dirty())
{
MessageBoxResult res = MessageBox.Show(
"Your changes have not been saved. Do you wish to save before quitting?", "Unsaved data",
MessageBoxButton.YesNoCancel, MessageBoxImage.Warning);
switch (res)
{
case MessageBoxResult.Yes:
mDoc.WriteXMLSettings();
break;
case MessageBoxResult.Cancel:
e.Cancel = true;
break;
case MessageBoxResult.No:
break;
default:
throw new ArgumentOutOfRangeException();
}
}
if (!e.Cancel)
{
SaveLayoutXml();
mDoc.TidyTvdb();
mDoc.Closing();
}
}
catch (Exception ex)
{
MessageBox.Show(this, ex.Message + "\r\n\r\n" + ex.StackTrace, "Form Closing Error",
MessageBoxButton.OK, MessageBoxImage.Error);
}
}
[NotNull]
//private ContextMenuStrip BuildSearchMenu()
//{
/* menuSearchSites.Items.Clear();
for (int i = 0; i < TVDoc.GetSearchers().Count(); i++)
{
string name = TVDoc.GetSearchers().Name(i);
if (!string.IsNullOrWhiteSpace(name))
{
ToolStripMenuItem tsi = new ToolStripMenuItem(name) { Tag = i };
menuSearchSites.Items.Add(tsi);
}
}
return menuSearchSites;*/
//}
private void ChooseSiteMenu(int n)
{
/* ContextMenuStrip sm = BuildSearchMenu();
if (n == 1)
{
sm.Show(bnWTWChooseSite, new Point(0, 0));
}
else if (n == 0)
{
sm.Show(bnActionWhichSearch, new Point(0, 0));
}
else
{
throw new ArgumentOutOfRangeException();
}*/
}
// private void bnWTWChooseSite_Click(object sender, EventArgs e) => ChooseSiteMenu(1);
private void FillMyShows()
{
//MyShowTree.Sort();
/*Season currentSeas = TreeViewItemToSeason((TreeViewItem)MyShowTree.SelectedItem );
ShowItem currentSi = TreeViewItemToShowItem((TreeViewItem)MyShowTree.SelectedItem);
List<ShowItem> expanded =
MyShowTree.Items.Cast<TreeViewItem>()
.Where(n => n.IsExpanded)
.Select(TreeViewItemToShowItem).ToList();
//MyShowTree.BeginUpdate();
MyShowTree.Items.Clear();
List<ShowItem> sil = mDoc.Library.GetShowItems();
lock (TheTVDB.SERIES_LOCK)
{
sil.Sort((a, b) =>
{
SeriesInfo serA = TheTVDB.Instance.GetSeries(a.TvdbCode);
SeriesInfo serB = TheTVDB.Instance.GetSeries(b.TvdbCode);
return string.Compare(GenerateShowUIName(serA, a), GenerateShowUIName(serB, b), StringComparison.OrdinalIgnoreCase);
});
}
ShowFilter filter = TVSettings.Instance.Filter;
foreach (ShowItem si in sil)
{
if (filter.Filter(si)
& (string.IsNullOrEmpty(filterTextBox.Text) || si.NameMatchFilters(filterTextBox.Text)))
{
TreeViewItem tvn = AddShowItemToTree(si);
if (expanded.Contains(si))
{
tvn.IsExpanded = true;
}
}
}
foreach (ShowItem si in expanded)
{
foreach (TreeViewItem n in MyShowTree.Items)
{
if (TreeViewItemToShowItem(n) == si)
{
n.IsExpanded = true;
}
}
}
if (currentSeas != null)
{
SelectSeason(currentSeas);
}
else if (currentSi != null)
{
SelectShow(currentSi);
}
//MyShowTree.EndUpdate();
*/
}
[NotNull]
private static string QuickStartGuide() => "https://www.tvrename.com/manual/quickstart/";
private void ShowQuickStartGuide()
{
tabControl1.SelectedItem =tbMyShows;
webInformation.Navigate(QuickStartGuide());
webImages.Navigate(QuickStartGuide());
}
private ShowItem TreeViewItemToShowItem([CanBeNull] TreeViewItem n)
{
if (n is null)
{
return null;
}
if (n.Tag is ShowItem si)
{
return si;
}
if (n.Tag is ProcessedEpisode pe)
{
return pe.Show;
}
if (n.Tag is Season seas)
{
if (seas.Episodes.Count == 0)
{
return null;
}
return mDoc.Library.ShowItem(seas.TheSeries.TvdbCode);
}
return null;
}
[CanBeNull]
private static Season TreeViewItemToSeason([CanBeNull] TreeViewItem n)
{
Season seas = n?.Tag as Season;
return seas;
}
private static void TvdbFor([CanBeNull] ProcessedEpisode e)
{
if (e != null)
{
Helpers.SysOpen(TheTVDB.Instance.WebsiteUrl(e.Show.TvdbCode, e.SeasonId, false));
}
}
private static void TvdbFor([CanBeNull] Season seas)
{
if (seas != null)
{
Helpers.SysOpen(TheTVDB.Instance.WebsiteUrl(seas.TheSeries.TvdbCode, -1, false));
}
}
private static void TvdbFor([CanBeNull] ShowItem si)
{
if (si != null)
{
Helpers.SysOpen(TheTVDB.Instance.WebsiteUrl(si.TvdbCode, -1, false));
}
}
/*
private void menuSearchSites_ItemClicked(object sender, [NotNull] ToolStripItemClickedEventArgs e)
{
mDoc.SetSearcher((int)e.ClickedItem.Tag);
UpdateSearchButtons();
}
*/
private void bnWhenToWatchCheck_Click(object sender, EventArgs e) => RefreshWTW(true, false);
/*
private void lvWhenToWatch_ColumnClick(object sender, [NotNull] ColumnClickEventArgs e)
{
int col = e.Column;
// 3 - 6 = do date sort on 3
// 1 or 2 = number sort
// all others, text sort
lvWhenToWatch.ShowGroups = false;
switch (col)
{
case 3:
case 4:
case 5:
case 6:
lvWhenToWatch.ShowGroups = true;
lvWhenToWatch.ListViewItemSorter = new DateSorterWtw(col);
break;
case 1:
case 2:
lvWhenToWatch.ListViewItemSorter = new NumberAsTextSorter(col);
break;
default:
lvWhenToWatch.ListViewItemSorter = new TextSorter(col);
break;
}
lvWhenToWatch.Sort();
lvWhenToWatch.Refresh();
}
*/
/*
private void lvWhenToWatch_Click(object sender, EventArgs e)
{
UpdateSearchButtons();
if (lvWhenToWatch.SelectedIndices.Count == 0)
{
txtWhenToWatchSynopsis.Text = "";
return;
}
int n = lvWhenToWatch.SelectedIndices[0];
ProcessedEpisode ei = (ProcessedEpisode)lvWhenToWatch.Items[n].Tag;
if (TVSettings.Instance.HideWtWSpoilers &&
(ei.HowLong() != "Aired" || lvWhenToWatch.Items[n].ImageIndex == 1))
{
txtWhenToWatchSynopsis.Text = "[Spoilers Hidden]";
}
else
{
txtWhenToWatchSynopsis.Text = ei.Overview;
}
mInternalChange++;
DateTime? dt = ei.GetAirDateDt(true);
if (dt != null)
{
calCalendar.SelectionStart = (DateTime)dt;
calCalendar.SelectionEnd = (DateTime)dt;
}
mInternalChange--;
if (TVSettings.Instance.AutoSelectShowInMyShows)
{
GotoEpguideFor(ei, false);
}
}
*/
/*
private void lvWhenToWatch_DoubleClick(object sender, EventArgs e)
{
if (lvWhenToWatch.SelectedItems.Count == 0)
{
return;
}
ProcessedEpisode ei = (ProcessedEpisode)lvWhenToWatch.SelectedItems[0].Tag;
List<FileInfo> fl = FinderHelper.FindEpOnDisk(null, ei);
if (fl.Count > 0)
{
Helpers.SysOpen(fl[0].FullName);
return;
}
// Don't have the episode. Scan or search?
switch (TVSettings.Instance.WTWDoubleClick)
{
default:
case TVSettings.WTWDoubleClickAction.Search:
bnWTWBTSearch_Click(null, null);
break;
case TVSettings.WTWDoubleClickAction.Scan:
UiScan(new List<ShowItem> { ei.Show }, false, TVSettings.ScanType.SingleShow);
tabControl1.SelectTab(tbAllInOne);
break;
}
}
*/
/*
private void calCalendar_DateSelected(object sender, DateRangeEventArgs e)
{
if (mInternalChange != 0)
{
return;
}
DateTime dt = calCalendar.SelectionStart;
bool first = true;
foreach (ListViewItem lvi in lvWhenToWatch.Items)
{
lvi.Selected = false;
ProcessedEpisode ei = (ProcessedEpisode)lvi.Tag;
DateTime? dt2 = ei.GetAirDateDt(true);
if (dt2 != null)
{
double h = dt2.Value.Subtract(dt).TotalHours;
if (h >= 0 && h < 24.0)
{
lvi.Selected = true;
if (first)
{
lvi.EnsureVisible();
first = false;
}
}
}
}
lvWhenToWatch.Focus();
}
*/
// ReSharper disable once InconsistentNaming
private void RefreshWTW(bool doDownloads, bool unattended)
{
if (doDownloads)
{
if (!mDoc.DoDownloadsFG(unattended, WindowState == WindowState.Minimized))
{
return;
}
}
mInternalChange++;
mDoc.DoWhenToWatch(true, unattended, WindowState == WindowState.Minimized);
FillMyShows();
//FillWhenToWatchList();
mInternalChange--;
mDoc.WriteUpcoming();
mDoc.WriteRecent();
}