PageRenderTime 320ms CodeModel.GetById 238ms app.highlight 52ms RepoModel.GetById 1ms app.codeStats 3ms

/Forms/Form1/Form1.vb

#
Visual Basic | 10353 lines | 9774 code | 456 blank | 123 comment | 15 complexity | 40a1bfda00cc6a098c9293f61b2d26d8 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1Option Explicit On
   2
   3Imports System.Net
   4Imports System.IO
   5Imports System.Text
   6Imports System.Text.RegularExpressions
   7Imports System.Threading
   8Imports System.Runtime.InteropServices
   9Imports System.Globalization
  10Imports Microsoft.Win32
  11Imports Media_Companion.Pref
  12Imports System.Xml
  13Imports System.Reflection
  14Imports System.Windows.Forms
  15Imports System.ComponentModel
  16Imports System.Linq
  17Imports XBMC.JsonRpc
  18
  19#Const SilentErrorScream = False
  20#Const Refocus = False
  21
  22
  23Public Class Form1
  24
  25    Const HOME_PAGE            = "http://mediacompanion.codeplex.com"
  26    Const TMDB_SITE            = "www.themoviedb.org/"
  27    Const TMDB_SET_URL         = TMDB_SITE & "collection/"
  28    Const TMDB_MOVIE_URL       = TMDB_SITE & "movie/"           
  29    Const NFO_INDEX As Integer = 7
  30    Public Const XBMC_Controller_full_log_file  As String = "XBMC-Controller-full-log-file.txt" 
  31    Public Const XBMC_Controller_brief_log_file As String = "XBMC-Controller-brief-log-file.txt" 
  32    Public Const MCToolsCommands As Integer = 5          ' increment when adding MC functions to ToolsToolStripMenuItem
  33
  34    Public Dim WithEvents  BckWrkScnMovies       As BackgroundWorker = New BackgroundWorker
  35    Public Dim WithEvents  BckWrkCheckNewVersion As BackgroundWorker = New BackgroundWorker
  36    Public Dim WithEvents  BckWrkXbmcController  As BackgroundWorker = New BackgroundWorker
  37    Public Dim WithEvents  Bw                    As BackgroundWorker = New BackgroundWorker
  38    Public Dim WithEvents  ImgBw                 As BackgroundWorker = New BackgroundWorker
  39    Property               BWs                   As New List(Of BackgroundWorker)
  40    Property                NumActiveThreads     As Integer
  41    Shared Public          XbmcControllerQ       As PriorityQueue    = New PriorityQueue
  42    Shared Public          XbmcControllerBufferQ As PriorityQueue    = New PriorityQueue
  43    Shared Public Property MC_Only_Movies        As List(Of ComboList)
  44    Public Shared Property MaxXbmcMovies As List(Of MaxXbmcMovie)
  45    Shared Public MyCulture As New System.Globalization.CultureInfo("en-US")
  46    Private Declare Function GetActiveWindow Lib "user32" Alias "GetActiveWindow" () As IntPtr
  47
  48    Public Property        XBMC_Controller_LogLastShownDt  As Date = Now
  49    Private                XBMC_Link_ErrorLog_Timer As Timers.Timer = New Timers.Timer()
  50    Private                XBMC_Link_Idle_Timer     As Timers.Timer = New Timers.Timer()
  51    Private                XBMC_Link_Check_Timer    As Timers.Timer = New Timers.Timer()
  52
  53    Declare Function AttachConsole Lib "kernel32.dll" (ByVal dwProcessId As Int32) As Boolean
  54
  55    Private WithEvents Tmr As New Windows.Forms.Timer With {.Interval = 200}
  56    Private fb As New FolderBrowserDialog
  57    Private Const WM_USER As Integer = &H400
  58    Private Const BFFM_SETEXPANDED As Integer = WM_USER + 106
  59
  60    <DllImport("user32.dll", EntryPoint:="SendMessageW")> _
  61    Private Shared Function SendMessageW(ByVal hWnd As IntPtr, ByVal msg As UInteger, ByVal wParam As Integer, <MarshalAs(UnmanagedType.LPWStr)> ByVal lParam As String) As IntPtr
  62    End Function
  63
  64    <DllImport("user32.dll", EntryPoint:="FindWindowW")> _
  65    Private Shared Function FindWindowW(<MarshalAs(UnmanagedType.LPWStr)> ByVal lpClassName As String, <MarshalAs(UnmanagedType.LPWStr)> ByVal lpWindowName As String) As IntPtr
  66    End Function
  67
  68    Shared ReadOnly Property Link_TotalQCount
  69        Get
  70            Return XbmcControllerQ.Count + XbmcControllerBufferQ.Count
  71        End Get
  72    End Property
  73
  74    Shared ReadOnly Property MC_Only_Movies_Nfos As List(Of String)
  75        Get
  76            If IsNothing(MC_Only_Movies) Then Return New List(Of String)
  77
  78            Return (From M In MC_Only_Movies Select M.fullpathandfilename).ToList
  79        End Get
  80    End Property
  81
  82    ReadOnly Shared Property NumOfScreens As Integer
  83        Get
  84            Return System.Windows.Forms.Screen.AllScreens.GetUpperBound(0)
  85        End Get
  86    End Property
  87
  88    ReadOnly Shared Property CurrentScreen As Integer
  89        Get
  90            Try
  91                Dim display As String = System.Windows.Forms.Screen.FromControl(Form1).DeviceName
  92                Dim m As String = Regex.Match(display, "DISPLAY[0-9]").Value
  93                Return ToInt(m.Substring(m.Length - 1)) - 1
  94            Catch
  95                Return 0
  96            End Try 
  97        End Get
  98    End Property
  99
 100    Property frmXBMC_Progress As frmXBMC_Progress = New frmXBMC_Progress
 101    
 102    #Region "Movie scraping related objects"
 103            Public WithEvents oMovies As New Movies
 104
 105            Public filteredList As New List(Of ComboList)
 106            Public rescrapeList As New RescrapeList
 107            Public workingMovieDetails As FullMovieDetails
 108            Public _rescrapeList As New RescrapeSpecificParams
 109            Public ChangeMovieId = ""
 110            Public droppedItems As New List(Of String)
 111            Public ControlsToDisableDuringMovieScrape As IEnumerable(Of Control)
 112
 113            Public Shared blnAbortFileDownload As Boolean
 114            Public Shared ReadOnly countLock = New Object
 115            Public ScraperErrorDetected As Boolean
 116
 117    #End Region 'Movie scraping objects
 118
 119
 120    Enum ProgramState
 121        ResettingFilters
 122	    UpdatingFilteredList
 123        ResizingSplitterPanel
 124        MovieControlsDisabled
 125	    Other
 126    End Enum
 127
 128    Shared Public ProgState As ProgramState=ProgramState.Other
 129    Public StateBefore As ProgramState=ProgramState.Other
 130
 131    Public DataDirty As Boolean
 132    Public _yield               As Boolean
 133    Public LastMovieDisplayed   As String=""
 134    Public MainFormLoadedStatus As Boolean = False
 135    Public tvRefreshNeeded As Boolean = True
 136    Public messbox As New frmMessageBox("blank", "", "")
 137    Public startup As Boolean = True
 138    Public SeriesXmlPath As String
 139    Public scraperFunction2 As New ScraperFunctions
 140    Public globalThreadStop As Boolean = False
 141    Public nfoFunction As New WorkingWithNfoFiles
 142    Public mediaInfoExp As New MediaInfoExport
 143    Shared Public langarray(300, 3) As String
 144    Public screen As Screen
 145    Public Shared genrelist As New List(Of String)
 146    
 147    Public Data_GridViewMovie As Data_GridViewMovie
 148    Public DataGridViewBindingSource As New BindingSource
 149
 150    Public homemovielist As New List(Of str_BasicHomeMovie)
 151    Public WorkingHomeMovie As New HomeMovieDetails
 152    Public workingMovie As New ComboList
 153    Public tvBatchList As New str_TvShowBatchWizard(SetDefaults)
 154    
 155    Public moviefolderschanged As Boolean = False
 156    Public tvfolderschanged As Boolean = False
 157    Public hmfolderschanged As Boolean = False
 158    Public customTvfolderschanged As Boolean = False
 159    Public scraperLog As String = ""
 160    Public NewTagList As New List(Of String)
 161    Public MovieSearchEngine As String = "imdb"
 162    Dim mov_TableColumnName As String = ""
 163    Dim mov_TableRowNum As Integer = -1
 164    Dim MovFanartToggle As Boolean = False
 165    Dim MovPosterToggle As Boolean = False
 166    Private keypresstimer As Timers.Timer = New Timers.Timer()
 167    Private statusstripclear As Timers.Timer = New Timers.Timer()
 168    Private MovieKeyPress As String = ""
 169    Public cropMode As String = "movieposter"
 170    
 171    Dim WithEvents bigPictureBox As PictureBox
 172    Dim WithEvents fanartBoxes As PictureBox
 173    Dim WithEvents fanartCheckBoxes As RadioButton
 174    Dim WithEvents posterPicBoxes As PictureBox
 175    Dim WithEvents posterCheckBoxes As RadioButton
 176    Dim WithEvents posterLabels As Label
 177    Dim WithEvents resLabel As Label
 178    Dim WithEvents tvFanartBoxes As PictureBox
 179    Dim WithEvents tvFanartCheckBoxes As RadioButton
 180    Dim WithEvents resolutionLabels As Label
 181    Dim newTvFolders As New List(Of String)
 182    Dim tvprogresstxt As String = ""
 183    Dim maximised As Boolean = False
 184    Dim tootip5 As New ToolTip
 185    Dim MovpictureList As New List(Of PictureBox)
 186    Dim tvpictureList As New List(Of PictureBox)
 187    Dim screenshotTab As TabPage
 188    Dim filterOverride As Boolean = False
 189    Dim bigPanel As Panel
 190    Dim realTvPaths As New List(Of String)
 191    Public Shared profileStruct As New Profiles
 192    Dim frmSplash As New frmSplashscreen
 193    Dim frmSplash2 As New frmProgressScreen
 194    Public Shared multimonitor As Boolean = False
 195    Dim progressmode As Boolean
 196    Dim scrapeAndQuit  As Boolean = False
 197    Dim refreshAndQuit As Boolean = False
 198    Dim sandq As Integer = 0
 199    Dim mouseDelta As Integer = 0
 200    Dim resLabels As Label
 201    Dim votelabels As Label
 202    Dim fanartArray As New List(Of McImage)
 203    Dim cropString As String
 204    Dim thumbedItsMade As Boolean = False
 205    Dim posterArray As New List(Of McImage)
 206    Dim pageCount As Integer = 0
 207    Dim currentPage As Integer = 0
 208    Dim actorflag As Boolean = False
 209    Dim listOfTvFanarts As New List(Of str_FanartList)
 210    Dim tableSets As New List(Of str_TableItems)
 211    Dim relativeFolderList As New List(Of str_RelativeFileList)
 212    Dim templanguage As String
 213    Dim WithEvents tvposterpicboxes As PictureBox
 214    Dim WithEvents tvpostercheckboxes As RadioButton
 215    Dim WithEvents tvposterlabels As Label
 216    Dim WithEvents tvreslabel As Label
 217    Dim tvposterpage As Integer = 1
 218    Public Shared WallPicWidth As Integer = 165
 219    Public Shared WallPicHeight As Integer = Math.Floor((WallPicWidth/3)*4)
 220    Dim MovMaxWallCount As Integer = 0
 221    Dim tvMaxWallCount As Integer = 0
 222    Dim moviecount_bak As Integer = 0
 223    Dim tvCount_bak As Integer = 0
 224    Dim lastSort As String = ""
 225    Dim lastinvert As String = ""
 226    Public displayRuntimeScraper As Boolean = True
 227    Dim tv_IMDbID_detected As Boolean = False
 228    Dim tv_IMDbID_warned As Boolean = False
 229    Dim tv_IMDbID_detectedMsg As String = String.Format("Media Companion has detected one or more TV Shows has an incorrect ID.{0}", vbCrLf) & _
 230                            String.Format("To rectify, please select the following:{0}", vbCrLf) & _
 231                            String.Format("  1. TV Preferences -> Fix NFO id during cache refresh{0}", vbCrLf) & _
 232                            String.Format("  2. TV Shows -> Refresh Shows{0}", vbCrLf) & _
 233                            String.Format("(This will only be reported once per session)", vbCrLf)
 234    Dim TVSearchALL As Boolean = False
 235    Private ClickedControl As String
 236    Private tvCurrentTabIndex As Integer = 0
 237    Private currentTabIndex As Integer = 0
 238    Private homeTabIndex As Integer = 0
 239    Private CustTvIndex As Integer = 0
 240    Public totalfilesize As Long = 0
 241    Public listoffilestomove As New List(Of String)
 242    Dim currenttitle As String
 243    Public singleshow As Boolean = False
 244    Public showslist As Object
 245    Public DGVMoviesColName As String = ""
 246    Dim CloseMC As Boolean = False
 247    Public Imageloading As Boolean = False
 248    Dim MoviesFiltersResizeCalled As Boolean = False
 249    Private tb_tagtxt_changed As Boolean = False
 250
 251    'TODO: (Form1_Load) Need to refactor
 252#Region "Form1 Events"
 253    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 254        PictureBoxAssignedMoviePoster.AllowDrop = True
 255        Try
 256            Pref.movie_filters.FilterPanel = SplitContainer5.Panel2
 257            Label73.Text = ""
 258
 259            BckWrkScnMovies.WorkerReportsProgress = True
 260            BckWrkScnMovies.WorkerSupportsCancellation = True
 261            ImgBw.WorkerReportsProgress = True
 262            ImgBw.WorkerSupportsCancellation = True
 263            oMovies.Bw = BckWrkScnMovies
 264
 265            For I = 0 To 20
 266                Common.Tasks.Add(New Tasks.BlankTask())
 267            Next
 268
 269            Pref.applicationPath = Application.StartupPath
 270            Utilities.applicationPath = Application.StartupPath
 271            SeriesXmlPath = IO.Path.Combine(Utilities.applicationPath, "SeriesXml\")
 272            Utilities.EnsureFolderExists(Utilities.PosterCachePath)
 273            Utilities.EnsureFolderExists(Utilities.MissingPath)
 274            Utilities.EnsureFolderExists(Utilities.CacheFolderPath)
 275            If Not Utilities.GetFrameworkVersions().IndexOf("4.0") Then
 276                Dim RequiredNetURL As String = "http://www.microsoft.com/download/en/details.aspx?id=17718"
 277                If MsgBox("The Client version is available through Windows Updates." & vbCrLf & _
 278                          "The Full version, while not required, is available from:" & vbCrLf & _
 279                          RequiredNetURL & vbCrLf & vbCrLf & _
 280                          "Do you wish to download the Full version?", _
 281                          MsgBoxStyle.YesNo, "MC Requires .Net 4.0.") = MsgBoxResult.Yes Then
 282                    OpenUrl(RequiredNetURL)
 283                    End
 284                End If
 285            End If
 286            
 287            ForegroundWorkTimer.Interval = 500
 288#If Not Debug Then
 289           AddHandler ForegroundWorkTimer.Tick, AddressOf ForegroundWorkPumper
 290#End If
 291
 292            Dim asm As Assembly = Assembly.GetExecutingAssembly
 293            Dim InternalResourceNames() As String = asm.GetManifestResourceNames
 294
 295            For Each Temp In InternalResourceNames
 296                Dim Temp1 As ManifestResourceInfo = asm.GetManifestResourceInfo(Temp)
 297            Next
 298
 299            TvTreeview.Sort()
 300
 301            For Each arg As String In Environment.GetCommandLineArgs().Skip(1)
 302                Select Case arg.ToLower
 303                    Case "sq"
 304                        scrapeAndQuit = True
 305                        sandq = 3
 306                    Case "st"
 307                        scrapeAndQuit = True
 308                        sandq = 1
 309                    Case "sm"
 310                        scrapeAndQuit = True
 311                        sandq = 2
 312                    Case "r"
 313                        refreshAndQuit = True
 314                    Case "?"
 315                        AttachConsole(-1)
 316                        Console.WriteLine("")
 317                        Console.WriteLine("")
 318                        Console.WriteLine("Commandline options")
 319                        Console.WriteLine("-------------------")
 320                        Console.WriteLine("sq - Search for & scrape new movies & tv shows")
 321                        Console.WriteLine("st - Search for & scrape newtv shows")
 322                        Console.WriteLine("sm - Search for & scrape new movies")
 323                        Console.WriteLine("r  - Refresh movie & tv caches")
 324                        Console.WriteLine("?  - Show this page")
 325                        Console.WriteLine("")
 326                        Environment.Exit(1)
 327                        'Me.Close()
 328                    Case Else
 329                        AttachConsole(-1)
 330                        Console.WriteLine("")
 331                        Console.WriteLine("")
 332                        Console.WriteLine("Unrecognised commandline option : [" & arg & "]. Type ? for help")
 333                        Console.WriteLine("")
 334                        Environment.Exit(1)
 335                        'Me.Close()
 336                End Select
 337            Next
 338
 339            If scrapeAndQuit Or refreshAndQuit Then
 340                Me.WindowState = FormWindowState.Minimized
 341            Else
 342                Dim scrn As Integer = splashscreenread()
 343                If multimonitor Then
 344                    frmSplash.Bounds = screen.AllScreens(scrn).Bounds
 345                    frmSplash.StartPosition = FormStartPosition.Manual
 346                    Dim x As Integer = screen.AllScreens(scrn).Bounds.X
 347                    frmSplash.Location = New Point(x + 250, 250)
 348                    frmSplash.TopMost = True
 349                End If
 350                frmSplash.Show()
 351                frmSplash.Label3.Text = "Status :- Initialising Program"
 352                frmSplash.Label3.Refresh()
 353            End If
 354            Me.Visible = False
 355
 356            Me.Refresh()
 357            Application.DoEvents()
 358            Dim tempstring As String
 359            tempstring = applicationPath & "\enablemultiple.set"
 360            If Not File.Exists(tempstring) Then
 361                Dim tej As Integer = 0
 362                Dim processes() As Process
 363                Dim instance As Process
 364                Dim process As New Process()
 365                processes = process.GetProcesses
 366                For Each instance In processes
 367                    If instance.ProcessName = "Media Companion" Then
 368                        tej = tej + 1
 369                        If tej >= 2 Then
 370                            MsgBox("Media Companion is already running")
 371                            End                         'Close MC since another version of the program is running.
 372                        End If
 373                    End If
 374                Next
 375            End If
 376            CheckForIllegalCrossThreadCalls = False
 377
 378            Pref.maximised = False
 379            Pref.SetUpPreferences()  'Set defaults to all userpreferences. We then load the preferences from config.xml this way any missing ones have a default already set
 380
 381            GenreMasterLoad()
 382
 383            tempstring = applicationPath & "\Settings\" 'read in the config.xml to set the stored preferences (if it exists)
 384            Dim hg As New IO.DirectoryInfo(tempstring)
 385            If hg.Exists Then
 386                Pref.configpath = tempstring & "config.xml"
 387                If Not IO.File.Exists(Pref.configpath) Then Pref.ConfigSave()
 388            Else
 389                IO.Directory.CreateDirectory(tempstring)
 390                workingProfile.Config = applicationPath & "\Settings\config.xml"
 391                Pref.ConfigSave()
 392            End If
 393
 394            If Not IO.File.Exists(applicationPath & "\Settings\profile.xml") Then
 395                profileStruct.WorkingProfileName = "Default"
 396                profileStruct.DefaultProfile = "Default"
 397                profileStruct.StartupProfile = "Default"
 398                Dim currentprofile As New ListOfProfiles
 399                tempstring = applicationPath & "\Settings\"
 400                currentprofile.ActorCache = tempstring & "actorcache.xml"
 401                currentprofile.DirectorCache = tempstring & "directorcache.xml"
 402                currentprofile.Config = tempstring & "config.xml"
 403                currentprofile.RegExList = tempstring & "regex.xml"
 404                currentprofile.TvCache = tempstring & "tvcache.xml"
 405                currentprofile.MusicVideoCache = tempstring & "musicvideocache.xml"
 406                currentprofile.Genres = tempstring & "genres.txt"
 407                currentprofile.MovieCache = tempstring & "moviecache.xml"
 408                currentprofile.MovieSetCache = tempstring & "moviesetcache.xml"
 409                currentprofile.CustomTvCache = tempstring & "customtvcache.xml"
 410                currentprofile.ProfileName = "Default"
 411                profileStruct.ProfileList.Add(currentprofile)
 412                profileStruct.WorkingProfileName = "Default"
 413                Call util_ProfileSave()
 414            End If
 415            
 416            'hide debug xml view tabs - unhiden (i.e. added) via debug tab
 417            TabLevel1.TabPages.Remove(Me.TabConfigXML)
 418            TabLevel1.TabPages.Remove(Me.TabMovieCacheXML)
 419            TabLevel1.TabPages.Remove(Me.TabTVCacheXML)
 420            TabLevel1.TabPages.Remove(Me.TabProfile)
 421            TabLevel1.TabPages.Remove(Me.TabActorCache)
 422            TabLevel1.TabPages.Remove(Me.TabRegex)
 423            TabLevel1.TabPages.Remove(Me.TabCustTv)     'Hide customtv tab while Work-In-Progress
 424            'TabControl2.TabPages.Remove(Me.tpMovSets)
 425            TabControl2.TabPages.Remove(Me.tpMovTags)
 426            
 427            Call util_ProfilesLoad()
 428            For Each prof In profileStruct.ProfileList
 429                If prof.ProfileName = profileStruct.StartupProfile Then
 430                    workingProfile.ActorCache = prof.ActorCache
 431                    workingProfile.DirectorCache = prof.DirectorCache
 432                    workingProfile.Config = prof.Config
 433                    workingProfile.MovieCache = prof.MovieCache
 434                    workingProfile.ProfileName = prof.ProfileName
 435                    workingProfile.RegExList = prof.RegExList
 436                    workingProfile.Genres = prof.Genres 
 437                    workingProfile.TvCache = prof.TvCache
 438                    workingProfile.CustomTvCache = prof.CustomTvCache 
 439                    workingProfile.ProfileName = prof.ProfileName
 440                    workingProfile.MusicVideoCache = prof.MusicVideoCache
 441                    workingProfile.MovieSetCache = prof.MovieSetCache 
 442                    For Each item In ProfilesToolStripMenuItem.DropDownItems
 443                        If item.text = workingProfile.ProfileName Then
 444                            With item
 445                                item.checked = True
 446                            End With
 447                        Else
 448                            item.checked = False
 449                        End If
 450                    Next
 451                End If
 452            Next
 453
 454            'add musicvideocache to profile if it doesnt exist
 455            Dim counter As Int16 = 0
 456            tempstring = applicationPath & "\Settings\"
 457            For Each prof In profileStruct.ProfileList
 458                If counter = 0 Then
 459                    If prof.MusicVideoCache = "" Then
 460                        prof.MusicVideoCache = tempstring & "musicvideocache.xml"
 461                        If prof.ProfileName = workingProfile.ProfileName Then
 462                            workingProfile.MusicVideoCache = tempstring & "musicvideocache.xml"
 463                        End If
 464                    End If
 465                    If prof.MovieSetCache = "" Then
 466                        prof.MovieSetCache = tempstring & "moviesetcache.xml"
 467                        If prof.ProfileName = workingProfile.ProfileName Then
 468                            workingProfile.MovieSetCache = tempstring & "moviesetcache.xml"
 469                        End If
 470                    End If
 471                    If prof.CustomTvCache = "" Then
 472                        prof.CustomTvCache = tempstring & "customtvcache.xml"
 473                        If prof.ProfileName = workingProfile.ProfileName Then
 474                            workingProfile.CustomTvCache = tempstring & "customtvcache.xml"
 475                        End If
 476                    End If
 477                Else
 478                    If prof.MusicVideoCache = "" Then
 479                        prof.MusicVideoCache = tempstring & "musicvideocache" & counter.ToString & ".xml"
 480                    End If
 481                    If prof.ProfileName = workingProfile.ProfileName Then
 482                        workingProfile.MusicVideoCache = tempstring & "musicvideocache" & counter.ToString & ".xml"
 483                    End If
 484                    If prof.MovieSetCache = "" Then
 485                        prof.MovieSetCache = tempstring & "moviesetcache" & counter.ToString & ".xml"
 486                    End If
 487                    If prof.ProfileName = workingProfile.ProfileName Then
 488                        workingProfile.MovieSetCache = tempstring & "moviesetcache" & counter.ToString & ".xml"
 489                    End If
 490                    If prof.CustomTvCache = "" Then
 491                        prof.CustomTvCache = tempstring & "customtvcache" & counter.ToString & ".xml"
 492                    End If
 493                    If prof.ProfileName = workingProfile.ProfileName Then
 494                        workingProfile.CustomTvCache = tempstring & "customtvcache" & counter.ToString & ".xml"
 495                    End If
 496                End If
 497                counter += 1
 498            Next
 499
 500            If workingProfile.HomeMovieCache = "" Then workingProfile.HomeMovieCache = tempstring & "homemoviecache.xml"
 501            'Update Main Form Window Title to show Currrent Version - displays current profile so has to be done after profile is loaded
 502            util_MainFormTitleUpdate()
 503
 504
 505            Dim g As New IO.DirectoryInfo(Utilities.PosterCachePath)
 506            If Not g.Exists Then
 507                Try
 508                    Directory.CreateDirectory(Utilities.PosterCachePath)
 509                Catch ex As Exception
 510                    MsgBox(ex.Message.ToString)
 511                    End
 512                End Try
 513            End If
 514
 515            CheckForIllegalCrossThreadCalls = False
 516            
 517            Try
 518                If IO.File.Exists(IO.Path.Combine(applicationPath, "\error.log")) Then IO.File.Delete(IO.Path.Combine(applicationPath, "\error.log"))
 519            Catch ex As Exception
 520#If SilentErrorScream Then
 521                Throw ex
 522#End If
 523            End Try
 524
 525            tempstring = applicationDatapath & "error.log"
 526            If IO.File.Exists(tempstring) = True Then IO.File.Delete(tempstring)
 527
 528            Call util_RegexLoad()
 529
 530            Call util_PrefsLoad()
 531            Statusstrip_Enable(False)
 532
 533            'These lines fixed the associated panel so that they don't automove when the Form1 is resized
 534            SplitContainer1.FixedPanel = System.Windows.Forms.FixedPanel.Panel1 'Left Panel on Movie tab - Movie Listing 
 535            SplitContainer5.FixedPanel = System.Windows.Forms.FixedPanel.Panel2 'Bottom Left Panel on Movie Tab - Filters
 536            SplitContainer3.FixedPanel = System.Windows.Forms.FixedPanel.Panel1 'Left Panel on TV Tab
 537
 538            Movies.SpinUpDrives()
 539
 540            If Not (scrapeAndQuit Or refreshAndQuit) Then
 541                Me.Visible = True
 542                Dim intX As Integer
 543                Dim intY As Integer
 544                If Pref.MultiMonitoEnabled Then
 545                    Dim scrn As Integer = If(NumOfScreens > 0, Pref.preferredscreen, 0)
 546                    intX = screen.AllScreens(scrn).Bounds.X ' + screen.AllScreens(scrn).Bounds.Width
 547                    intY = screen.AllScreens(scrn).Bounds.Height
 548                Else
 549                    intX = Screen.PrimaryScreen.Bounds.Width
 550                    intY = Screen.PrimaryScreen.Bounds.Height
 551                End If
 552                SplitContainer1.IsSplitterFixed = True
 553                SplitContainer2.IsSplitterFixed = True
 554                SplitContainer3.IsSplitterFixed = True
 555                SplitContainer4.IsSplitterFixed = True
 556                SplitContainer5.IsSplitterFixed = True
 557
 558                If intX >= 0 Then  'First check if screen is Centre or to the right of main screen.
 559                    If Pref.locx < 0 Then Pref.locx = 0
 560                    If Pref.locy < 0 Then Pref.locy = 0
 561                    If Pref.formheight > intY Then Pref.formheight = intY
 562                    If Pref.formwidth > intX Then Pref.formwidth = intX
 563                    If Pref.locx >= intX Then Pref.locx = intX - Pref.formwidth
 564                    If Pref.locy >= intY Then Pref.locy = intY - Pref.formheight
 565                Else    'Else screen could be to the left of Centre/Main screen so intX is a negative number.
 566                    'If Pref.locx < 0 Then Pref.locx = 0
 567                    If Pref.locy < 0 Then Pref.locy = 0
 568                    If Pref.formheight > intY Then Pref.formheight = intY
 569                    If Pref.formwidth > Math.Abs(intX) Then Pref.formwidth = intX
 570                    If Pref.locx <= intX Then Pref.locx = intX ' - Pref.formwidth
 571                    If Pref.locy >= intY Then Pref.locy = intY - Pref.formheight
 572                End If
 573                If Pref.formheight <> 0 And Pref.formwidth <> 0 Then
 574                    Me.Width = Pref.formwidth
 575                    Me.Height = Pref.formheight
 576                    Me.Location = New Point(Pref.locx, Pref.locy)
 577                End If
 578                If Pref.maximised Then Me.WindowState = FormWindowState.Maximized
 579
 580                Dim dpi As Graphics = Me.CreateGraphics
 581
 582                'MessageBox.Show(String.Format("X={0}, Y={1}", dpi.DpiX, dpi.DpiY),
 583                '"DPI Settings", MessageBoxButtons.OK, MessageBoxIcon.Information)
 584
 585                DebugSytemDPITextBox.Text = dpi.DpiX
 586
 587                Me.Refresh()
 588                Application.DoEvents()
 589
 590                Me.Refresh()
 591                Application.DoEvents()
 592
 593                Application.DoEvents()
 594
 595                screenshotTab = TabControl3.TabPages(1)
 596
 597                TabControl3.TabPages.RemoveAt(1)
 598
 599                If Pref.splt5 = 0 Then
 600                    Dim tempint As Integer = SplitContainer1.Height
 601                    tempint = tempint / 4
 602                    tempint = tempint * 3
 603                    If tempint > 275 Then
 604                        Pref.splt5 = tempint
 605                    Else
 606                        Pref.splt5 = 275
 607                    End If
 608                End If
 609
 610                SplitContainer1.SplitterDistance = Pref.splt1
 611                SplitContainer2.SplitterDistance = Pref.splt2
 612                SplitContainer5.SplitterDistance = Pref.splt5
 613                SplitContainer3.SplitterDistance = Pref.splt3
 614                SplitContainer4.SplitterDistance = Pref.splt4
 615                TabLevel1.SelectedIndex = Pref.startuptab
 616
 617                If Pref.startuptab = 0 Then
 618                    If Not MoviesFiltersResizeCalled Then
 619                        MoviesFiltersResizeCalled = True
 620                        Pref.movie_filters.RemoveInvalidMovieFilters
 621                        Pref.movie_filters.SetMovieFiltersVisibility
 622                        UpdateMovieFiltersPanel
 623                    End If
 624                End If
 625                btn_MPDB_posters.Enabled = False        'Disable MoviePoster button on Movie Poster Tab as now not available to us.
 626
 627                SplitContainer1.IsSplitterFixed = False
 628                SplitContainer2.IsSplitterFixed = False
 629                SplitContainer3.IsSplitterFixed = False
 630                SplitContainer4.IsSplitterFixed = False
 631                SplitContainer5.IsSplitterFixed = False
 632            End If
 633
 634            If scrapeAndQuit Or refreshAndQuit Then
 635                Do_ScrapeAndQuit()
 636                Me.Close()
 637            Else
 638                Try
 639                    If cbMovieDisplay_MovieSet.Items.Count <> Pref.moviesets.Count Then
 640                        cbMovieDisplay_MovieSet.Items.Clear()
 641                        For Each mset In Pref.moviesets
 642                            cbMovieDisplay_MovieSet.Items.Add(If(Pref.MovSetTitleIgnArticle, Pref.RemoveIgnoredArticles(mset), mset))
 643                        Next
 644                    End If
 645                    If Not IsNothing(workingMovieDetails) AndAlso workingMovieDetails.fullmoviebody.MovieSet.MovieSetName <> "-None-" Then
 646                        For Each mset In Pref.moviesets
 647                            cbMovieDisplay_MovieSet.Items.Add(If(Pref.MovSetTitleIgnArticle, Pref.RemoveIgnoredArticles(mset), mset))
 648                        Next
 649                        For te = 0 To cbMovieDisplay_MovieSet.Items.Count - 1
 650                            If cbMovieDisplay_MovieSet.Items(te) = workingMovieDetails.fullmoviebody.MovieSet.MovieSetDisplayName Then
 651                                cbMovieDisplay_MovieSet.SelectedIndex = te
 652                                Exit For
 653                            End If
 654                        Next
 655                    End If
 656
 657                Catch ex As Exception
 658#If SilentErrorScream Then
 659                    Throw ex
 660#End If
 661                End Try
 662                mov_VideoSourcePopulate()
 663                ep_VideoSourcePopulate()
 664                Call util_FontSetup()
 665                Call langarrsetup()
 666                Dim mediaDropdown As New SortedList(Of String, String)
 667                mediaInfoExp.addTemplates(mediaDropdown)
 668                For Each item In mediaDropdown
 669                    If item.Value = MediaInfoExport.mediaType.Movie Then
 670                        ExportMovieListInfoToolStripMenuItem.DropDownItems.Add(item.Key)
 671                    ElseIf item.Value = MediaInfoExport.mediaType.TV Then
 672                        ExportTVShowInfoToolStripMenuItem.DropDownItems.Add(item.Key)
 673                    End If
 674                Next
 675
 676                Call util_CommandListLoad()
 677                startup = False
 678
 679                frmSplash.Label3.Text = "Status :- Cleaning Cache folder."
 680                frmSplash.Label3.Refresh()
 681                
 682                frmSplash.Close()
 683                
 684                mov_SplitContainerAutoPosition()
 685                tv_ShowSelectedCurrently(TvTreeview)
 686                tv_SplitContainerAutoPosition()
 687            End If
 688
 689            'Parameters to display the movie grid at startup
 690            Select Case Pref.moviedefaultlist
 691                Case 0
 692                    rbTitleAndYear.Checked = True
 693                Case 1
 694                    rbFileName.Checked = True
 695                Case 2
 696                    rbFolder.Checked = True
 697            End Select
 698
 699            Try
 700                cbSort.SelectedIndex = Pref.moviesortorder
 701            Catch
 702                cbSort.SelectedIndex = 0
 703            End Try
 704            btnreverse.Checked = Pref.movieinvertorder
 705            If btnreverse.Checked Then
 706                Mc.clsGridViewMovie.GridSort = "Desc"
 707            Else
 708                Mc.clsGridViewMovie.GridSort = "Asc"
 709            End If
 710
 711            Read_XBMC_TMDB_Scraper_Config()
 712            Read_XBMC_TVDB_Scraper_Config()
 713            MainFormLoadedStatus = True
 714            UcFanartTv1.Form1MainFormLoadedStatus = True
 715            UcFanartTvTv1.Form1MainFormLoadedStatus = True
 716            ReloadMovieCacheToolStripMenuItem.Visible = False
 717            ToolStripSeparator9.Visible = False
 718
 719            ResetFilters()
 720
 721            UpdateFilteredList()
 722
 723            If Not IsNothing(Pref.MovFiltLastSize) Then ResizeBottomLHSPanel(Pref.MovFiltLastSize, MovieFiltersPanelMaxHeight)
 724
 725            Common.Tasks.StartTaskEngine()
 726            ForegroundWorkTimer.Start()
 727            
 728            BckWrkXbmcController.WorkerReportsProgress = True
 729            ' BckWrkXbmcController.WorkerSupportsCancellation = true
 730
 731            oMovies.Bw = BckWrkScnMovies
 732            
 733            AddHandler XBMC_Link_ErrorLog_Timer.Elapsed, AddressOf XBMC_Controller_Log_TO_Timer_Elapsed
 734            Ini_Timer(XBMC_Link_ErrorLog_Timer, 3000)
 735
 736            AddHandler XBMC_Link_Idle_Timer.Elapsed, AddressOf XBMC_Link_Idle_Timer_Elapsed
 737            Ini_Timer(XBMC_Link_Idle_Timer, 3000)
 738
 739            AddHandler XBMC_Link_Check_Timer.Elapsed, AddressOf XBMC_Link_Check_Timer_Elapsed
 740            Ini_Timer(XBMC_Link_Check_Timer, 2000, True)
 741            'XBMC_Link_Check_Timer.Start
 742
 743            AddHandler keypresstimer.Elapsed, AddressOf keypresstimer_Elapsed
 744            Ini_Timer(keypresstimer, 1000)
 745
 746            AddHandler statusstripclear.Elapsed, AddressOf statusstripclear_Elapsed
 747            Ini_Timer(statusstripclear, 2000)
 748
 749
 750            AddHandler BckWrkXbmcController.ProgressChanged, AddressOf BckWrkXbmcController_ReportProgress
 751            AddHandler BckWrkXbmcController.DoWork, AddressOf BckWrkXbmcController_DoWork
 752
 753            BckWrkXbmcController.RunWorkerAsync(Me)
 754
 755            For each pb As Control In TableLayoutPanel6.Controls
 756                If pb.Name.Contains("pbEpScrSht") Then
 757                    AddHandler pb.Click, AddressOf pbepscrsht_click
 758                End If
 759            Next
 760
 761            For each pb As Control In TableLayoutPanel27.Controls
 762                If pb.Name.Contains("pbHmScrSht") Then
 763                    AddHandler pb.Click, AddressOf pbHmScrSht_click
 764                End If
 765            Next 
 766        Catch ex As Exception
 767            ExceptionHandler.LogError(ex)
 768        End Try
 769    End Sub
 770
 771#If Refocus Then
 772    Private Sub Form1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Activated
 773        Try
 774            If messbox.Visible = True Then
 775                messbox.Activate()
 776                messbox.BringToFront()
 777                messbox.Focus()
 778            End If
 779        Catch ex As Exception
 780            ExceptionHandler.LogError(ex)
 781        End Try
 782
 783    End Sub
 784#End If
 785
 786    Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed
 787        Try
 788            Me.Dispose()
 789            Me.Finalize()
 790            CleanCacheFolder(, cbClearCache.Checked)  'Limit cachefolder to max 300 files.  Cleaned on startup and shutdown.
 791            'If cbClearCache checked then completely empty
 792            If cbClearMissingFolder.Checked = True Then ClearMissingFolder() ' delete missing folder if option selected.
 793            End
 794        Catch ex As Exception
 795            ExceptionHandler.LogError(ex)
 796        End Try
 797
 798    End Sub
 799
 800    Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
 801
 802        BckWrkScnMovies_Cancel()
 803        While BckWrkScnMovies.IsBusy
 804            Application.DoEvents()
 805        End While
 806        
 807        Try
 808            oMovies.SaveCaches()
 809
 810            If Tv_CacheSave() Then
 811                e.Cancel = True
 812                Exit Sub
 813            End If
 814            Call HomeMovieCacheSave()
 815
 816            Call UcMusicVideo1.MVCacheSave()
 817
 818            'if we say cancel to save nfo's & exit then we don't want to exit MC if e.cancel= true we abort the closing....
 819
 820            'Todo: Code a better way to serialize the data
 821            
 822            Pref.splt1 = SplitContainer1.SplitterDistance
 823            Pref.splt2 = SplitContainer2.SplitterDistance
 824            Pref.splt3 = SplitContainer3.SplitterDistance
 825            Pref.splt4 = SplitContainer4.SplitterDistance
 826            Pref.splt5 = SplitContainer5.SplitterDistance
 827            Pref.splt6 = _tv_SplitContainer.SplitterDistance
 828            Pref.tvbannersplit = Math.Round(_tv_SplitContainer.SplitterDistance / _tv_SplitContainer.Height, 2)
 829            Pref.MovFiltLastSize = SplitContainer5.Height - SplitContainer5.SplitterDistance
 830            Pref.preferredscreen = CurrentScreen
 831
 832
 833            If Me.WindowState = FormWindowState.Minimized Then
 834                Me.WindowState = FormWindowState.Normal
 835                Pref.formwidth = Me.Width
 836                Pref.formheight = Me.Height
 837                Pref.locx = Me.Location.X
 838                Pref.locy = Me.Location.Y
 839                Pref.maximised = False
 840            End If
 841
 842            If Me.WindowState = FormWindowState.Normal Then
 843                Pref.formwidth = Me.Width
 844                Pref.formheight = Me.Height
 845                Pref.locx = Me.Location.X
 846                Pref.locy = Me.Location.Y
 847                Pref.maximised = False
 848            End If
 849
 850            If Me.WindowState = FormWindowState.Maximized Then
 851                Me.WindowState = FormWindowState.Normal
 852                Pref.maximised = True
 853            End If
 854
 855            If DataGridView1.Columns.Count > 0 Then
 856                Pref.tableview.Clear()
 857                For Each column In DataGridView1.Columns
 858                    Dim tempstring As String = String.Format("{0}|{1}|{2}|{3}", column.name, column.width, column.displayindex, column.visible)
 859                    Pref.tableview.Add(tempstring)
 860                Next
 861            End If
 862
 863            Pref.startuptab = TabLevel1.SelectedIndex
 864
 865            Pref.ConfigSave()
 866            SplashscreenWrite()
 867            Call util_ProfileSave()
 868            Dim errpath As String = IO.Path.Combine(applicationPath, "tvrefresh.log")
 869        Catch ex As Exception
 870            MessageBox.Show(ex.ToString, "Exception")
 871            Environment.Exit(1)
 872            'ExceptionHandler.LogError(ex)
 873        End Try
 874
 875    End Sub
 876
 877    Private Sub Form1_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.GotFocus
 878        Try
 879            If messbox.Visible = True Then
 880                messbox.Activate()
 881            End If
 882        Catch ex As Exception
 883            ExceptionHandler.LogError(ex)
 884        End Try
 885
 886    End Sub
 887
 888    Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize
 889        Try
 890            If Me.WindowState = FormWindowState.Maximized Then
 891                mov_SplitContainerAutoPosition()
 892                tv_SplitContainerAutoPosition()
 893            End If
 894            If Not Me.WindowState = FormWindowState.Minimized Then
 895                tv_SplitContainerAutoPosition()
 896            End If
 897            If startup = False Then
 898                Pref.locx = Me.Location.X
 899                Pref.locy = Me.Location.Y
 900            End If
 901            If MainFormLoadedStatus = True Then
 902                doResizeRefresh()
 903            End If
 904        Catch ex As Exception
 905            Dim paramInfo As String = ""
 906            Try
 907                paramInfo = "PbMovieFanArt.Width:" & PbMovieFanArt.Width.ToString & " PbMovieFanArt.Height: " & PbMovieFanArt.Height.ToString & " Rating:" & ratingtxt.Text
 908            Catch ex2 As Exception
 909                ExceptionHandler.LogError(ex2)
 910            End Try
 911            ExceptionHandler.LogError(ex, paramInfo)
 912        End Try
 913    End Sub
 914
 915    Private Sub Form1_ResizeEnd(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.ResizeEnd
 916        Try
 917            If Pref.formwidth <> Me.Width Or Pref.formheight <> Me.Height Then
 918                Pref.formwidth = Me.Width
 919                Pref.formheight = Me.Height
 920            End If
 921            mov_SplitContainerAutoPosition()
 922            tv_SplitContainerAutoPosition()
 923
 924        Catch ex As Exception
 925            ExceptionHandler.LogError(ex)
 926        End Try
 927
 928    End Sub
 929    
 930    Private Sub Form1_KeyDown(sender As System.Object, e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
 931
 932        If e.KeyCode = Keys.Escape Then bckgrndcancel()
 933        If e.KeyCode = Keys.F5 Then doRefresh()
 934        If e.KeyCode = Keys.F3 Then doSearchNew()
 935        If e.Control And e.KeyCode = Keys.C Then AbortFileDownload()
 936    End Sub
 937
 938#End Region
 939
 940    Sub Ini_Timer(t As Timers.Timer, Optional Interval As Integer = 1000, Optional Repeating As Boolean = False)
 941        t.Stop()
 942        t.Interval = Interval
 943        t.AutoReset = Repeating
 944    End Sub
 945    
 946
 947#Region "XBMC Link"
 948    Private Sub BckWrkXbmcController_DoWork(ByVal sender As Object, ByVal e As DoWorkEventArgs)
 949        Dim bw As BackgroundWorker = CType(sender, BackgroundWorker)
 950        Dim sm As New XbmcController(e.Argument, bw)
 951        sm.Go()
 952    End Sub
 953
 954    Private Sub XBMC_Controller_Log_TO_Timer_Elapsed()
 955        If Not BckWrkScnMovies.IsBusy And XbmcControllerBufferQ.Count = 0 Then
 956            If DateDiff(DateInterval.Second, XBMC_Controller_LogLastShownDt, Now) > 30 Then
 957
 958                Pref.OpenFileInAppPath(Form1.XBMC_Controller_full_log_file)
 959                Pref.OpenFileInAppPath(Form1.XBMC_Controller_brief_log_file)
 960
 961                frmXBMC_Progress.Reset()
 962                Dim ce As New BaseEvent(XbmcController.E.ResetErrorCount, New BaseEventArgs())
 963                XbmcControllerQ.Write(ce)
 964            End If
 965            XBMC_Controller_LogLastShownDt = Now
 966            XBMC_Link_ErrorLog_Timer.Stop()
 967        End If
 968    End Sub
 969
 970    Private Sub XBMC_Link_Idle_Timer_Elapsed()
 971        If Not BckWrkScnMovies.IsBusy And XbmcControllerBufferQ.Count = 0 Then
 972            frmXBMC_Progress.Visible = False
 973            XBMC_Link_ErrorLog_Timer.Stop()
 974        End If
 975    End Sub
 976
 977    Sub Restart(tmr As Timers.Timer)
 978        tmr.Stop()
 979        tmr.Start()
 980    End Sub
 981
 982    Private Sub BckWrkXbmcController_ReportProgress(ByVal sender As Object, ByVal e As ProgressChangedEventArgs)
 983        Dim oProgress As XBMC_Controller_Progress = CType(e.UserState, XBMC_Controller_Progress)
 984
 985        If XBMC_Link_ErrorLog_Timer.Enabled Then
 986            Restart(XBMC_Link_ErrorLog_Timer)
 987        End If
 988
 989        Restart(XBMC_Link_Idle_Timer)
 990        Restart(XBMC_Link_Check_Timer)
 991
 992        frmXBMC_Progress.Visible = True
 993        If HandleEvents(oProgress) Then Return
 994        If oProgress.ErrorCount > 0 Then
 995            If Pref.ShowLogOnError Then
 996                XBMC_Link_ErrorLog_Timer.Start()
 997            End If      
 998        End If
 999
1000        frmXBMC_Progress.UpdateDetails(oProgress)
1001    End Sub
1002
1003    Function HandleEvents(oProgress As XBMC_Controller_Progress) As Boolean
1004
1005        Select Case oProgress.Evt
1006
1007            Case XbmcController.E.MC_Only_Movies
1008                MC_Only_Movies = CType(oProgress.Args, ComboList_EventArgs).XbmcMovies
1009                Assign_FilterGeneral()
1010                Return True
1011
1012            Case XbmcController.E.MC_XbmcMcMovies
1013                oMovies.XbmcMcMovies = CType(oProgress.Args, XBMC_MC_Movies_EventArgs).XbmcMcMovies
1014                Assign_FilterGeneral()
1015                Return True
1016
1017            Case XbmcController.E.MC_XbmcOnlyMovies
1018                oMovies.XbmcOnlyMovies = CType(oProgress.Args, XBMC_Only_Movies_EventArgs).XbmcOnlyMovies
1019                Return True
1020
1021            Case XbmcController.E.MC_XbmcQuit
1022                SetcbBtnLink()
1023                Return True
1024                
1025        End Select
1026        Return False
1027    End Function
1028
1029    Const MaxConseqFailures As Integer = 3
1030
1031    Dim ConnectSent As Boolean
1032    Dim XbmcLastLinkState As Boolean
1033    Dim ConseqFailures As Integer = 0
1034
1035    Sub SetcbBtnLink(Optional sender As Object = Nothing)
1036        XBMC_Link_Check_Timer.Stop()
1037
1038        'Only check when link is idle
1039        If Not BckWrkScnMovies.IsBusy And XbmcControllerBufferQ.Count = 0 Then
1040            Dim passed As Boolean = XBMC_TestsPassed
1041
1042            '
1043            ' Sometimes the link test fails. Don't know why yet, maybe XBMC is busy...but anyway this should reduce the number of phantom 
1044            ' link disablings...
1045            ' 
1046            If Not IsNothing(sender) Then
1047                If cbBtnLink.Enabled And Not passed Then
1048                    ConseqFailures += 1
1049                Else
1050                    ConseqFailures = 0
1051                End If
1052            Else
1053                ConseqFailures = 0
1054            End If
1055
1056            If IsNothing(sender) Or ConseqFailures <= MaxConseqFailures Then
1057                cbBtnLink.Enabled = passed
1058                If cbBtnLink.Enabled Then
1059                    cbBtnLink.BackColor = IIf(cbBtnLink.Checked, Color.LightGreen, Color.Transparent)
1060                    If Pref.XBMC_Link <> cbBtnLink.Checked Then
1061                        Pref.XBMC_Link = cbBtnLink.Checked
1062                        If Pref.XbmcLinkReady Then
1063                            XbmcControllerQ.Write(XbmcController.E.ConnectReq, PriorityQueue.Priorities.low)
1064                        End If
1065                        Pref.ConfigSave()
1066                    End If
1067                Else
1068                    cbBtnLink.Checked = False
1069                    cbBtnLink.BackColor = Color.Transparent
1070                End If
1071                tsmiMov_SyncToXBMC.Enabled = cbBtnLink.Enabled And cbBtnLink.Checked
1072            End If
1073        End If
1074        XBMC_Link_Check_Timer.Start()
1075    End Sub
1076
1077    Private Sub XBMC_Link_Check_Timer_Elapsed()
1078        If ProgState = ProgramState.MovieControlsDisabled Then Return
1079        SetcbBtnLink(XBMC_Link_Check_Timer)
1080    End Sub
1081
1082    Private Sub keypresstimer_Elapsed()
1083        MovieKeyPress = ""
1084    End Sub
1085
1086    Private Sub statusstripclear_Elapsed()
1087        ToolStripStatusLabel2.Visible = False
1088        Statusstrip_Enable(False)
1089        ToolStripStatusLabel2.Text = "TV Show Episode Scan In Progress"
1090    End Sub
1091
1092    Sub XbmcLink_UpdateArtwork()
1093        If Pref.XBMC_Delete_Cached_Images AndAlso Pref.XbmcLinkReady Then
1094            Dim m As Movie = oMovies.LoadMovie(workingMovieDetails.fileinfo.fullpathandfilename)
1095            m.SaveNFO()
1096        End If
1097    End Sub
1098#End Region
1099
1100    Private Sub BlinkTaskBar()
1101        If GetActiveWindow <> Me.Handle Then
1102            Dim res = WindowsApi.FlashWindow(Process.GetCurrentProcess().MainWindowHandle, True, True, 5)
1103        End If
1104    End Sub
1105
1106    Private Function splashscreenread() As Integer
1107        Dim scrn As Integer = 0
1108        Dim checkpath As String = Pref.applicationPath & "\Settings\screen.xml"
1109        If File.Exists(checkpath) Then
1110            Try
1111                Dim document As XDocument = XDocument.Load(checkpath)
1112                Dim sc = From t In document.Descendants("screen") Select t.Value
1113                Dim mten = From t In document.Descendants("MultiEnabled") Select t.Value
1114                multimonitor = Convert.ToBoolean(mten.First())
1115                scrn = sc.First().ToInt
1116                If scrn > NumOfScreens Then scrn = 0
1117            Catch
1118                scrn = 0
1119                multimonitor = False
1120            End Try
1121        End If
1122        Return scrn
1123    End Function
1124
1125    Private Sub SplashscreenWrite()
1126        Dim doc As New XmlDocument
1127        Dim thispref As XmlNode = Nothing
1128        Dim xmlproc As XmlDeclaration
1129        Dim root As XmlElement = Nothing
1130        Dim child As XmlElement = Nothing
1131        xmlproc = doc.CreateXmlDeclaration("1.0", "UTF-8", "yes")
1132        doc.AppendChild(xmlproc)
1133        root = doc.CreateElement("root")
1134        child = doc.CreateElement("MultiEnabled")
1135        child.InnerXml = Pref.MultiMonitoEnabled
1136        root.AppendChild(chi

Large files files are truncated, but you can click here to view the full file