/Forms/Form1/Form1.vb
Visual Basic | 10353 lines | 9774 code | 456 blank | 123 comment | 15 complexity | 40a1bfda00cc6a098c9293f61b2d26d8 MD5 | raw file
Possible License(s): GPL-2.0
Large files files are truncated, but you can click here to view the full file
- Option Explicit On
-
- Imports System.Net
- Imports System.IO
- Imports System.Text
- Imports System.Text.RegularExpressions
- Imports System.Threading
- Imports System.Runtime.InteropServices
- Imports System.Globalization
- Imports Microsoft.Win32
- Imports Media_Companion.Pref
- Imports System.Xml
- Imports System.Reflection
- Imports System.Windows.Forms
- Imports System.ComponentModel
- Imports System.Linq
- Imports XBMC.JsonRpc
-
- #Const SilentErrorScream = False
- #Const Refocus = False
-
-
- Public Class Form1
-
- Const HOME_PAGE = "http://mediacompanion.codeplex.com"
- Const TMDB_SITE = "www.themoviedb.org/"
- Const TMDB_SET_URL = TMDB_SITE & "collection/"
- Const TMDB_MOVIE_URL = TMDB_SITE & "movie/"
- Const NFO_INDEX As Integer = 7
- Public Const XBMC_Controller_full_log_file As String = "XBMC-Controller-full-log-file.txt"
- Public Const XBMC_Controller_brief_log_file As String = "XBMC-Controller-brief-log-file.txt"
- Public Const MCToolsCommands As Integer = 5 ' increment when adding MC functions to ToolsToolStripMenuItem
-
- Public Dim WithEvents BckWrkScnMovies As BackgroundWorker = New BackgroundWorker
- Public Dim WithEvents BckWrkCheckNewVersion As BackgroundWorker = New BackgroundWorker
- Public Dim WithEvents BckWrkXbmcController As BackgroundWorker = New BackgroundWorker
- Public Dim WithEvents Bw As BackgroundWorker = New BackgroundWorker
- Public Dim WithEvents ImgBw As BackgroundWorker = New BackgroundWorker
- Property BWs As New List(Of BackgroundWorker)
- Property NumActiveThreads As Integer
- Shared Public XbmcControllerQ As PriorityQueue = New PriorityQueue
- Shared Public XbmcControllerBufferQ As PriorityQueue = New PriorityQueue
- Shared Public Property MC_Only_Movies As List(Of ComboList)
- Public Shared Property MaxXbmcMovies As List(Of MaxXbmcMovie)
- Shared Public MyCulture As New System.Globalization.CultureInfo("en-US")
- Private Declare Function GetActiveWindow Lib "user32" Alias "GetActiveWindow" () As IntPtr
-
- Public Property XBMC_Controller_LogLastShownDt As Date = Now
- Private XBMC_Link_ErrorLog_Timer As Timers.Timer = New Timers.Timer()
- Private XBMC_Link_Idle_Timer As Timers.Timer = New Timers.Timer()
- Private XBMC_Link_Check_Timer As Timers.Timer = New Timers.Timer()
-
- Declare Function AttachConsole Lib "kernel32.dll" (ByVal dwProcessId As Int32) As Boolean
-
- Private WithEvents Tmr As New Windows.Forms.Timer With {.Interval = 200}
- Private fb As New FolderBrowserDialog
- Private Const WM_USER As Integer = &H400
- Private Const BFFM_SETEXPANDED As Integer = WM_USER + 106
-
- <DllImport("user32.dll", EntryPoint:="SendMessageW")> _
- 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
- End Function
-
- <DllImport("user32.dll", EntryPoint:="FindWindowW")> _
- Private Shared Function FindWindowW(<MarshalAs(UnmanagedType.LPWStr)> ByVal lpClassName As String, <MarshalAs(UnmanagedType.LPWStr)> ByVal lpWindowName As String) As IntPtr
- End Function
-
- Shared ReadOnly Property Link_TotalQCount
- Get
- Return XbmcControllerQ.Count + XbmcControllerBufferQ.Count
- End Get
- End Property
-
- Shared ReadOnly Property MC_Only_Movies_Nfos As List(Of String)
- Get
- If IsNothing(MC_Only_Movies) Then Return New List(Of String)
-
- Return (From M In MC_Only_Movies Select M.fullpathandfilename).ToList
- End Get
- End Property
-
- ReadOnly Shared Property NumOfScreens As Integer
- Get
- Return System.Windows.Forms.Screen.AllScreens.GetUpperBound(0)
- End Get
- End Property
-
- ReadOnly Shared Property CurrentScreen As Integer
- Get
- Try
- Dim display As String = System.Windows.Forms.Screen.FromControl(Form1).DeviceName
- Dim m As String = Regex.Match(display, "DISPLAY[0-9]").Value
- Return ToInt(m.Substring(m.Length - 1)) - 1
- Catch
- Return 0
- End Try
- End Get
- End Property
-
- Property frmXBMC_Progress As frmXBMC_Progress = New frmXBMC_Progress
-
- #Region "Movie scraping related objects"
- Public WithEvents oMovies As New Movies
-
- Public filteredList As New List(Of ComboList)
- Public rescrapeList As New RescrapeList
- Public workingMovieDetails As FullMovieDetails
- Public _rescrapeList As New RescrapeSpecificParams
- Public ChangeMovieId = ""
- Public droppedItems As New List(Of String)
- Public ControlsToDisableDuringMovieScrape As IEnumerable(Of Control)
-
- Public Shared blnAbortFileDownload As Boolean
- Public Shared ReadOnly countLock = New Object
- Public ScraperErrorDetected As Boolean
-
- #End Region 'Movie scraping objects
-
-
- Enum ProgramState
- ResettingFilters
- UpdatingFilteredList
- ResizingSplitterPanel
- MovieControlsDisabled
- Other
- End Enum
-
- Shared Public ProgState As ProgramState=ProgramState.Other
- Public StateBefore As ProgramState=ProgramState.Other
-
- Public DataDirty As Boolean
- Public _yield As Boolean
- Public LastMovieDisplayed As String=""
- Public MainFormLoadedStatus As Boolean = False
- Public tvRefreshNeeded As Boolean = True
- Public messbox As New frmMessageBox("blank", "", "")
- Public startup As Boolean = True
- Public SeriesXmlPath As String
- Public scraperFunction2 As New ScraperFunctions
- Public globalThreadStop As Boolean = False
- Public nfoFunction As New WorkingWithNfoFiles
- Public mediaInfoExp As New MediaInfoExport
- Shared Public langarray(300, 3) As String
- Public screen As Screen
- Public Shared genrelist As New List(Of String)
-
- Public Data_GridViewMovie As Data_GridViewMovie
- Public DataGridViewBindingSource As New BindingSource
-
- Public homemovielist As New List(Of str_BasicHomeMovie)
- Public WorkingHomeMovie As New HomeMovieDetails
- Public workingMovie As New ComboList
- Public tvBatchList As New str_TvShowBatchWizard(SetDefaults)
-
- Public moviefolderschanged As Boolean = False
- Public tvfolderschanged As Boolean = False
- Public hmfolderschanged As Boolean = False
- Public customTvfolderschanged As Boolean = False
- Public scraperLog As String = ""
- Public NewTagList As New List(Of String)
- Public MovieSearchEngine As String = "imdb"
- Dim mov_TableColumnName As String = ""
- Dim mov_TableRowNum As Integer = -1
- Dim MovFanartToggle As Boolean = False
- Dim MovPosterToggle As Boolean = False
- Private keypresstimer As Timers.Timer = New Timers.Timer()
- Private statusstripclear As Timers.Timer = New Timers.Timer()
- Private MovieKeyPress As String = ""
- Public cropMode As String = "movieposter"
-
- Dim WithEvents bigPictureBox As PictureBox
- Dim WithEvents fanartBoxes As PictureBox
- Dim WithEvents fanartCheckBoxes As RadioButton
- Dim WithEvents posterPicBoxes As PictureBox
- Dim WithEvents posterCheckBoxes As RadioButton
- Dim WithEvents posterLabels As Label
- Dim WithEvents resLabel As Label
- Dim WithEvents tvFanartBoxes As PictureBox
- Dim WithEvents tvFanartCheckBoxes As RadioButton
- Dim WithEvents resolutionLabels As Label
- Dim newTvFolders As New List(Of String)
- Dim tvprogresstxt As String = ""
- Dim maximised As Boolean = False
- Dim tootip5 As New ToolTip
- Dim MovpictureList As New List(Of PictureBox)
- Dim tvpictureList As New List(Of PictureBox)
- Dim screenshotTab As TabPage
- Dim filterOverride As Boolean = False
- Dim bigPanel As Panel
- Dim realTvPaths As New List(Of String)
- Public Shared profileStruct As New Profiles
- Dim frmSplash As New frmSplashscreen
- Dim frmSplash2 As New frmProgressScreen
- Public Shared multimonitor As Boolean = False
- Dim progressmode As Boolean
- Dim scrapeAndQuit As Boolean = False
- Dim refreshAndQuit As Boolean = False
- Dim sandq As Integer = 0
- Dim mouseDelta As Integer = 0
- Dim resLabels As Label
- Dim votelabels As Label
- Dim fanartArray As New List(Of McImage)
- Dim cropString As String
- Dim thumbedItsMade As Boolean = False
- Dim posterArray As New List(Of McImage)
- Dim pageCount As Integer = 0
- Dim currentPage As Integer = 0
- Dim actorflag As Boolean = False
- Dim listOfTvFanarts As New List(Of str_FanartList)
- Dim tableSets As New List(Of str_TableItems)
- Dim relativeFolderList As New List(Of str_RelativeFileList)
- Dim templanguage As String
- Dim WithEvents tvposterpicboxes As PictureBox
- Dim WithEvents tvpostercheckboxes As RadioButton
- Dim WithEvents tvposterlabels As Label
- Dim WithEvents tvreslabel As Label
- Dim tvposterpage As Integer = 1
- Public Shared WallPicWidth As Integer = 165
- Public Shared WallPicHeight As Integer = Math.Floor((WallPicWidth/3)*4)
- Dim MovMaxWallCount As Integer = 0
- Dim tvMaxWallCount As Integer = 0
- Dim moviecount_bak As Integer = 0
- Dim tvCount_bak As Integer = 0
- Dim lastSort As String = ""
- Dim lastinvert As String = ""
- Public displayRuntimeScraper As Boolean = True
- Dim tv_IMDbID_detected As Boolean = False
- Dim tv_IMDbID_warned As Boolean = False
- Dim tv_IMDbID_detectedMsg As String = String.Format("Media Companion has detected one or more TV Shows has an incorrect ID.{0}", vbCrLf) & _
- String.Format("To rectify, please select the following:{0}", vbCrLf) & _
- String.Format(" 1. TV Preferences -> Fix NFO id during cache refresh{0}", vbCrLf) & _
- String.Format(" 2. TV Shows -> Refresh Shows{0}", vbCrLf) & _
- String.Format("(This will only be reported once per session)", vbCrLf)
- Dim TVSearchALL As Boolean = False
- Private ClickedControl As String
- Private tvCurrentTabIndex As Integer = 0
- Private currentTabIndex As Integer = 0
- Private homeTabIndex As Integer = 0
- Private CustTvIndex As Integer = 0
- Public totalfilesize As Long = 0
- Public listoffilestomove As New List(Of String)
- Dim currenttitle As String
- Public singleshow As Boolean = False
- Public showslist As Object
- Public DGVMoviesColName As String = ""
- Dim CloseMC As Boolean = False
- Public Imageloading As Boolean = False
- Dim MoviesFiltersResizeCalled As Boolean = False
- Private tb_tagtxt_changed As Boolean = False
-
- 'TODO: (Form1_Load) Need to refactor
- #Region "Form1 Events"
- Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- PictureBoxAssignedMoviePoster.AllowDrop = True
- Try
- Pref.movie_filters.FilterPanel = SplitContainer5.Panel2
- Label73.Text = ""
-
- BckWrkScnMovies.WorkerReportsProgress = True
- BckWrkScnMovies.WorkerSupportsCancellation = True
- ImgBw.WorkerReportsProgress = True
- ImgBw.WorkerSupportsCancellation = True
- oMovies.Bw = BckWrkScnMovies
-
- For I = 0 To 20
- Common.Tasks.Add(New Tasks.BlankTask())
- Next
-
- Pref.applicationPath = Application.StartupPath
- Utilities.applicationPath = Application.StartupPath
- SeriesXmlPath = IO.Path.Combine(Utilities.applicationPath, "SeriesXml\")
- Utilities.EnsureFolderExists(Utilities.PosterCachePath)
- Utilities.EnsureFolderExists(Utilities.MissingPath)
- Utilities.EnsureFolderExists(Utilities.CacheFolderPath)
- If Not Utilities.GetFrameworkVersions().IndexOf("4.0") Then
- Dim RequiredNetURL As String = "http://www.microsoft.com/download/en/details.aspx?id=17718"
- If MsgBox("The Client version is available through Windows Updates." & vbCrLf & _
- "The Full version, while not required, is available from:" & vbCrLf & _
- RequiredNetURL & vbCrLf & vbCrLf & _
- "Do you wish to download the Full version?", _
- MsgBoxStyle.YesNo, "MC Requires .Net 4.0.") = MsgBoxResult.Yes Then
- OpenUrl(RequiredNetURL)
- End
- End If
- End If
-
- ForegroundWorkTimer.Interval = 500
- #If Not Debug Then
- AddHandler ForegroundWorkTimer.Tick, AddressOf ForegroundWorkPumper
- #End If
-
- Dim asm As Assembly = Assembly.GetExecutingAssembly
- Dim InternalResourceNames() As String = asm.GetManifestResourceNames
-
- For Each Temp In InternalResourceNames
- Dim Temp1 As ManifestResourceInfo = asm.GetManifestResourceInfo(Temp)
- Next
-
- TvTreeview.Sort()
-
- For Each arg As String In Environment.GetCommandLineArgs().Skip(1)
- Select Case arg.ToLower
- Case "sq"
- scrapeAndQuit = True
- sandq = 3
- Case "st"
- scrapeAndQuit = True
- sandq = 1
- Case "sm"
- scrapeAndQuit = True
- sandq = 2
- Case "r"
- refreshAndQuit = True
- Case "?"
- AttachConsole(-1)
- Console.WriteLine("")
- Console.WriteLine("")
- Console.WriteLine("Commandline options")
- Console.WriteLine("-------------------")
- Console.WriteLine("sq - Search for & scrape new movies & tv shows")
- Console.WriteLine("st - Search for & scrape newtv shows")
- Console.WriteLine("sm - Search for & scrape new movies")
- Console.WriteLine("r - Refresh movie & tv caches")
- Console.WriteLine("? - Show this page")
- Console.WriteLine("")
- Environment.Exit(1)
- 'Me.Close()
- Case Else
- AttachConsole(-1)
- Console.WriteLine("")
- Console.WriteLine("")
- Console.WriteLine("Unrecognised commandline option : [" & arg & "]. Type ? for help")
- Console.WriteLine("")
- Environment.Exit(1)
- 'Me.Close()
- End Select
- Next
-
- If scrapeAndQuit Or refreshAndQuit Then
- Me.WindowState = FormWindowState.Minimized
- Else
- Dim scrn As Integer = splashscreenread()
- If multimonitor Then
- frmSplash.Bounds = screen.AllScreens(scrn).Bounds
- frmSplash.StartPosition = FormStartPosition.Manual
- Dim x As Integer = screen.AllScreens(scrn).Bounds.X
- frmSplash.Location = New Point(x + 250, 250)
- frmSplash.TopMost = True
- End If
- frmSplash.Show()
- frmSplash.Label3.Text = "Status :- Initialising Program"
- frmSplash.Label3.Refresh()
- End If
- Me.Visible = False
-
- Me.Refresh()
- Application.DoEvents()
- Dim tempstring As String
- tempstring = applicationPath & "\enablemultiple.set"
- If Not File.Exists(tempstring) Then
- Dim tej As Integer = 0
- Dim processes() As Process
- Dim instance As Process
- Dim process As New Process()
- processes = process.GetProcesses
- For Each instance In processes
- If instance.ProcessName = "Media Companion" Then
- tej = tej + 1
- If tej >= 2 Then
- MsgBox("Media Companion is already running")
- End 'Close MC since another version of the program is running.
- End If
- End If
- Next
- End If
- CheckForIllegalCrossThreadCalls = False
-
- Pref.maximised = False
- 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
-
- GenreMasterLoad()
-
- tempstring = applicationPath & "\Settings\" 'read in the config.xml to set the stored preferences (if it exists)
- Dim hg As New IO.DirectoryInfo(tempstring)
- If hg.Exists Then
- Pref.configpath = tempstring & "config.xml"
- If Not IO.File.Exists(Pref.configpath) Then Pref.ConfigSave()
- Else
- IO.Directory.CreateDirectory(tempstring)
- workingProfile.Config = applicationPath & "\Settings\config.xml"
- Pref.ConfigSave()
- End If
-
- If Not IO.File.Exists(applicationPath & "\Settings\profile.xml") Then
- profileStruct.WorkingProfileName = "Default"
- profileStruct.DefaultProfile = "Default"
- profileStruct.StartupProfile = "Default"
- Dim currentprofile As New ListOfProfiles
- tempstring = applicationPath & "\Settings\"
- currentprofile.ActorCache = tempstring & "actorcache.xml"
- currentprofile.DirectorCache = tempstring & "directorcache.xml"
- currentprofile.Config = tempstring & "config.xml"
- currentprofile.RegExList = tempstring & "regex.xml"
- currentprofile.TvCache = tempstring & "tvcache.xml"
- currentprofile.MusicVideoCache = tempstring & "musicvideocache.xml"
- currentprofile.Genres = tempstring & "genres.txt"
- currentprofile.MovieCache = tempstring & "moviecache.xml"
- currentprofile.MovieSetCache = tempstring & "moviesetcache.xml"
- currentprofile.CustomTvCache = tempstring & "customtvcache.xml"
- currentprofile.ProfileName = "Default"
- profileStruct.ProfileList.Add(currentprofile)
- profileStruct.WorkingProfileName = "Default"
- Call util_ProfileSave()
- End If
-
- 'hide debug xml view tabs - unhiden (i.e. added) via debug tab
- TabLevel1.TabPages.Remove(Me.TabConfigXML)
- TabLevel1.TabPages.Remove(Me.TabMovieCacheXML)
- TabLevel1.TabPages.Remove(Me.TabTVCacheXML)
- TabLevel1.TabPages.Remove(Me.TabProfile)
- TabLevel1.TabPages.Remove(Me.TabActorCache)
- TabLevel1.TabPages.Remove(Me.TabRegex)
- TabLevel1.TabPages.Remove(Me.TabCustTv) 'Hide customtv tab while Work-In-Progress
- 'TabControl2.TabPages.Remove(Me.tpMovSets)
- TabControl2.TabPages.Remove(Me.tpMovTags)
-
- Call util_ProfilesLoad()
- For Each prof In profileStruct.ProfileList
- If prof.ProfileName = profileStruct.StartupProfile Then
- workingProfile.ActorCache = prof.ActorCache
- workingProfile.DirectorCache = prof.DirectorCache
- workingProfile.Config = prof.Config
- workingProfile.MovieCache = prof.MovieCache
- workingProfile.ProfileName = prof.ProfileName
- workingProfile.RegExList = prof.RegExList
- workingProfile.Genres = prof.Genres
- workingProfile.TvCache = prof.TvCache
- workingProfile.CustomTvCache = prof.CustomTvCache
- workingProfile.ProfileName = prof.ProfileName
- workingProfile.MusicVideoCache = prof.MusicVideoCache
- workingProfile.MovieSetCache = prof.MovieSetCache
- For Each item In ProfilesToolStripMenuItem.DropDownItems
- If item.text = workingProfile.ProfileName Then
- With item
- item.checked = True
- End With
- Else
- item.checked = False
- End If
- Next
- End If
- Next
-
- 'add musicvideocache to profile if it doesnt exist
- Dim counter As Int16 = 0
- tempstring = applicationPath & "\Settings\"
- For Each prof In profileStruct.ProfileList
- If counter = 0 Then
- If prof.MusicVideoCache = "" Then
- prof.MusicVideoCache = tempstring & "musicvideocache.xml"
- If prof.ProfileName = workingProfile.ProfileName Then
- workingProfile.MusicVideoCache = tempstring & "musicvideocache.xml"
- End If
- End If
- If prof.MovieSetCache = "" Then
- prof.MovieSetCache = tempstring & "moviesetcache.xml"
- If prof.ProfileName = workingProfile.ProfileName Then
- workingProfile.MovieSetCache = tempstring & "moviesetcache.xml"
- End If
- End If
- If prof.CustomTvCache = "" Then
- prof.CustomTvCache = tempstring & "customtvcache.xml"
- If prof.ProfileName = workingProfile.ProfileName Then
- workingProfile.CustomTvCache = tempstring & "customtvcache.xml"
- End If
- End If
- Else
- If prof.MusicVideoCache = "" Then
- prof.MusicVideoCache = tempstring & "musicvideocache" & counter.ToString & ".xml"
- End If
- If prof.ProfileName = workingProfile.ProfileName Then
- workingProfile.MusicVideoCache = tempstring & "musicvideocache" & counter.ToString & ".xml"
- End If
- If prof.MovieSetCache = "" Then
- prof.MovieSetCache = tempstring & "moviesetcache" & counter.ToString & ".xml"
- End If
- If prof.ProfileName = workingProfile.ProfileName Then
- workingProfile.MovieSetCache = tempstring & "moviesetcache" & counter.ToString & ".xml"
- End If
- If prof.CustomTvCache = "" Then
- prof.CustomTvCache = tempstring & "customtvcache" & counter.ToString & ".xml"
- End If
- If prof.ProfileName = workingProfile.ProfileName Then
- workingProfile.CustomTvCache = tempstring & "customtvcache" & counter.ToString & ".xml"
- End If
- End If
- counter += 1
- Next
-
- If workingProfile.HomeMovieCache = "" Then workingProfile.HomeMovieCache = tempstring & "homemoviecache.xml"
- 'Update Main Form Window Title to show Currrent Version - displays current profile so has to be done after profile is loaded
- util_MainFormTitleUpdate()
-
-
- Dim g As New IO.DirectoryInfo(Utilities.PosterCachePath)
- If Not g.Exists Then
- Try
- Directory.CreateDirectory(Utilities.PosterCachePath)
- Catch ex As Exception
- MsgBox(ex.Message.ToString)
- End
- End Try
- End If
-
- CheckForIllegalCrossThreadCalls = False
-
- Try
- If IO.File.Exists(IO.Path.Combine(applicationPath, "\error.log")) Then IO.File.Delete(IO.Path.Combine(applicationPath, "\error.log"))
- Catch ex As Exception
- #If SilentErrorScream Then
- Throw ex
- #End If
- End Try
-
- tempstring = applicationDatapath & "error.log"
- If IO.File.Exists(tempstring) = True Then IO.File.Delete(tempstring)
-
- Call util_RegexLoad()
-
- Call util_PrefsLoad()
- Statusstrip_Enable(False)
-
- 'These lines fixed the associated panel so that they don't automove when the Form1 is resized
- SplitContainer1.FixedPanel = System.Windows.Forms.FixedPanel.Panel1 'Left Panel on Movie tab - Movie Listing
- SplitContainer5.FixedPanel = System.Windows.Forms.FixedPanel.Panel2 'Bottom Left Panel on Movie Tab - Filters
- SplitContainer3.FixedPanel = System.Windows.Forms.FixedPanel.Panel1 'Left Panel on TV Tab
-
- Movies.SpinUpDrives()
-
- If Not (scrapeAndQuit Or refreshAndQuit) Then
- Me.Visible = True
- Dim intX As Integer
- Dim intY As Integer
- If Pref.MultiMonitoEnabled Then
- Dim scrn As Integer = If(NumOfScreens > 0, Pref.preferredscreen, 0)
- intX = screen.AllScreens(scrn).Bounds.X ' + screen.AllScreens(scrn).Bounds.Width
- intY = screen.AllScreens(scrn).Bounds.Height
- Else
- intX = Screen.PrimaryScreen.Bounds.Width
- intY = Screen.PrimaryScreen.Bounds.Height
- End If
- SplitContainer1.IsSplitterFixed = True
- SplitContainer2.IsSplitterFixed = True
- SplitContainer3.IsSplitterFixed = True
- SplitContainer4.IsSplitterFixed = True
- SplitContainer5.IsSplitterFixed = True
-
- If intX >= 0 Then 'First check if screen is Centre or to the right of main screen.
- If Pref.locx < 0 Then Pref.locx = 0
- If Pref.locy < 0 Then Pref.locy = 0
- If Pref.formheight > intY Then Pref.formheight = intY
- If Pref.formwidth > intX Then Pref.formwidth = intX
- If Pref.locx >= intX Then Pref.locx = intX - Pref.formwidth
- If Pref.locy >= intY Then Pref.locy = intY - Pref.formheight
- Else 'Else screen could be to the left of Centre/Main screen so intX is a negative number.
- 'If Pref.locx < 0 Then Pref.locx = 0
- If Pref.locy < 0 Then Pref.locy = 0
- If Pref.formheight > intY Then Pref.formheight = intY
- If Pref.formwidth > Math.Abs(intX) Then Pref.formwidth = intX
- If Pref.locx <= intX Then Pref.locx = intX ' - Pref.formwidth
- If Pref.locy >= intY Then Pref.locy = intY - Pref.formheight
- End If
- If Pref.formheight <> 0 And Pref.formwidth <> 0 Then
- Me.Width = Pref.formwidth
- Me.Height = Pref.formheight
- Me.Location = New Point(Pref.locx, Pref.locy)
- End If
- If Pref.maximised Then Me.WindowState = FormWindowState.Maximized
-
- Dim dpi As Graphics = Me.CreateGraphics
-
- 'MessageBox.Show(String.Format("X={0}, Y={1}", dpi.DpiX, dpi.DpiY),
- '"DPI Settings", MessageBoxButtons.OK, MessageBoxIcon.Information)
-
- DebugSytemDPITextBox.Text = dpi.DpiX
-
- Me.Refresh()
- Application.DoEvents()
-
- Me.Refresh()
- Application.DoEvents()
-
- Application.DoEvents()
-
- screenshotTab = TabControl3.TabPages(1)
-
- TabControl3.TabPages.RemoveAt(1)
-
- If Pref.splt5 = 0 Then
- Dim tempint As Integer = SplitContainer1.Height
- tempint = tempint / 4
- tempint = tempint * 3
- If tempint > 275 Then
- Pref.splt5 = tempint
- Else
- Pref.splt5 = 275
- End If
- End If
-
- SplitContainer1.SplitterDistance = Pref.splt1
- SplitContainer2.SplitterDistance = Pref.splt2
- SplitContainer5.SplitterDistance = Pref.splt5
- SplitContainer3.SplitterDistance = Pref.splt3
- SplitContainer4.SplitterDistance = Pref.splt4
- TabLevel1.SelectedIndex = Pref.startuptab
-
- If Pref.startuptab = 0 Then
- If Not MoviesFiltersResizeCalled Then
- MoviesFiltersResizeCalled = True
- Pref.movie_filters.RemoveInvalidMovieFilters
- Pref.movie_filters.SetMovieFiltersVisibility
- UpdateMovieFiltersPanel
- End If
- End If
- btn_MPDB_posters.Enabled = False 'Disable MoviePoster button on Movie Poster Tab as now not available to us.
-
- SplitContainer1.IsSplitterFixed = False
- SplitContainer2.IsSplitterFixed = False
- SplitContainer3.IsSplitterFixed = False
- SplitContainer4.IsSplitterFixed = False
- SplitContainer5.IsSplitterFixed = False
- End If
-
- If scrapeAndQuit Or refreshAndQuit Then
- Do_ScrapeAndQuit()
- Me.Close()
- Else
- Try
- If cbMovieDisplay_MovieSet.Items.Count <> Pref.moviesets.Count Then
- cbMovieDisplay_MovieSet.Items.Clear()
- For Each mset In Pref.moviesets
- cbMovieDisplay_MovieSet.Items.Add(If(Pref.MovSetTitleIgnArticle, Pref.RemoveIgnoredArticles(mset), mset))
- Next
- End If
- If Not IsNothing(workingMovieDetails) AndAlso workingMovieDetails.fullmoviebody.MovieSet.MovieSetName <> "-None-" Then
- For Each mset In Pref.moviesets
- cbMovieDisplay_MovieSet.Items.Add(If(Pref.MovSetTitleIgnArticle, Pref.RemoveIgnoredArticles(mset), mset))
- Next
- For te = 0 To cbMovieDisplay_MovieSet.Items.Count - 1
- If cbMovieDisplay_MovieSet.Items(te) = workingMovieDetails.fullmoviebody.MovieSet.MovieSetDisplayName Then
- cbMovieDisplay_MovieSet.SelectedIndex = te
- Exit For
- End If
- Next
- End If
-
- Catch ex As Exception
- #If SilentErrorScream Then
- Throw ex
- #End If
- End Try
- mov_VideoSourcePopulate()
- ep_VideoSourcePopulate()
- Call util_FontSetup()
- Call langarrsetup()
- Dim mediaDropdown As New SortedList(Of String, String)
- mediaInfoExp.addTemplates(mediaDropdown)
- For Each item In mediaDropdown
- If item.Value = MediaInfoExport.mediaType.Movie Then
- ExportMovieListInfoToolStripMenuItem.DropDownItems.Add(item.Key)
- ElseIf item.Value = MediaInfoExport.mediaType.TV Then
- ExportTVShowInfoToolStripMenuItem.DropDownItems.Add(item.Key)
- End If
- Next
-
- Call util_CommandListLoad()
- startup = False
-
- frmSplash.Label3.Text = "Status :- Cleaning Cache folder."
- frmSplash.Label3.Refresh()
-
- frmSplash.Close()
-
- mov_SplitContainerAutoPosition()
- tv_ShowSelectedCurrently(TvTreeview)
- tv_SplitContainerAutoPosition()
- End If
-
- 'Parameters to display the movie grid at startup
- Select Case Pref.moviedefaultlist
- Case 0
- rbTitleAndYear.Checked = True
- Case 1
- rbFileName.Checked = True
- Case 2
- rbFolder.Checked = True
- End Select
-
- Try
- cbSort.SelectedIndex = Pref.moviesortorder
- Catch
- cbSort.SelectedIndex = 0
- End Try
- btnreverse.Checked = Pref.movieinvertorder
- If btnreverse.Checked Then
- Mc.clsGridViewMovie.GridSort = "Desc"
- Else
- Mc.clsGridViewMovie.GridSort = "Asc"
- End If
-
- Read_XBMC_TMDB_Scraper_Config()
- Read_XBMC_TVDB_Scraper_Config()
- MainFormLoadedStatus = True
- UcFanartTv1.Form1MainFormLoadedStatus = True
- UcFanartTvTv1.Form1MainFormLoadedStatus = True
- ReloadMovieCacheToolStripMenuItem.Visible = False
- ToolStripSeparator9.Visible = False
-
- ResetFilters()
-
- UpdateFilteredList()
-
- If Not IsNothing(Pref.MovFiltLastSize) Then ResizeBottomLHSPanel(Pref.MovFiltLastSize, MovieFiltersPanelMaxHeight)
-
- Common.Tasks.StartTaskEngine()
- ForegroundWorkTimer.Start()
-
- BckWrkXbmcController.WorkerReportsProgress = True
- ' BckWrkXbmcController.WorkerSupportsCancellation = true
-
- oMovies.Bw = BckWrkScnMovies
-
- AddHandler XBMC_Link_ErrorLog_Timer.Elapsed, AddressOf XBMC_Controller_Log_TO_Timer_Elapsed
- Ini_Timer(XBMC_Link_ErrorLog_Timer, 3000)
-
- AddHandler XBMC_Link_Idle_Timer.Elapsed, AddressOf XBMC_Link_Idle_Timer_Elapsed
- Ini_Timer(XBMC_Link_Idle_Timer, 3000)
-
- AddHandler XBMC_Link_Check_Timer.Elapsed, AddressOf XBMC_Link_Check_Timer_Elapsed
- Ini_Timer(XBMC_Link_Check_Timer, 2000, True)
- 'XBMC_Link_Check_Timer.Start
-
- AddHandler keypresstimer.Elapsed, AddressOf keypresstimer_Elapsed
- Ini_Timer(keypresstimer, 1000)
-
- AddHandler statusstripclear.Elapsed, AddressOf statusstripclear_Elapsed
- Ini_Timer(statusstripclear, 2000)
-
-
- AddHandler BckWrkXbmcController.ProgressChanged, AddressOf BckWrkXbmcController_ReportProgress
- AddHandler BckWrkXbmcController.DoWork, AddressOf BckWrkXbmcController_DoWork
-
- BckWrkXbmcController.RunWorkerAsync(Me)
-
- For each pb As Control In TableLayoutPanel6.Controls
- If pb.Name.Contains("pbEpScrSht") Then
- AddHandler pb.Click, AddressOf pbepscrsht_click
- End If
- Next
-
- For each pb As Control In TableLayoutPanel27.Controls
- If pb.Name.Contains("pbHmScrSht") Then
- AddHandler pb.Click, AddressOf pbHmScrSht_click
- End If
- Next
- Catch ex As Exception
- ExceptionHandler.LogError(ex)
- End Try
- End Sub
-
- #If Refocus Then
- Private Sub Form1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Activated
- Try
- If messbox.Visible = True Then
- messbox.Activate()
- messbox.BringToFront()
- messbox.Focus()
- End If
- Catch ex As Exception
- ExceptionHandler.LogError(ex)
- End Try
-
- End Sub
- #End If
-
- Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed
- Try
- Me.Dispose()
- Me.Finalize()
- CleanCacheFolder(, cbClearCache.Checked) 'Limit cachefolder to max 300 files. Cleaned on startup and shutdown.
- 'If cbClearCache checked then completely empty
- If cbClearMissingFolder.Checked = True Then ClearMissingFolder() ' delete missing folder if option selected.
- End
- Catch ex As Exception
- ExceptionHandler.LogError(ex)
- End Try
-
- End Sub
-
- Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
-
- BckWrkScnMovies_Cancel()
- While BckWrkScnMovies.IsBusy
- Application.DoEvents()
- End While
-
- Try
- oMovies.SaveCaches()
-
- If Tv_CacheSave() Then
- e.Cancel = True
- Exit Sub
- End If
- Call HomeMovieCacheSave()
-
- Call UcMusicVideo1.MVCacheSave()
-
- '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....
-
- 'Todo: Code a better way to serialize the data
-
- Pref.splt1 = SplitContainer1.SplitterDistance
- Pref.splt2 = SplitContainer2.SplitterDistance
- Pref.splt3 = SplitContainer3.SplitterDistance
- Pref.splt4 = SplitContainer4.SplitterDistance
- Pref.splt5 = SplitContainer5.SplitterDistance
- Pref.splt6 = _tv_SplitContainer.SplitterDistance
- Pref.tvbannersplit = Math.Round(_tv_SplitContainer.SplitterDistance / _tv_SplitContainer.Height, 2)
- Pref.MovFiltLastSize = SplitContainer5.Height - SplitContainer5.SplitterDistance
- Pref.preferredscreen = CurrentScreen
-
-
- If Me.WindowState = FormWindowState.Minimized Then
- Me.WindowState = FormWindowState.Normal
- Pref.formwidth = Me.Width
- Pref.formheight = Me.Height
- Pref.locx = Me.Location.X
- Pref.locy = Me.Location.Y
- Pref.maximised = False
- End If
-
- If Me.WindowState = FormWindowState.Normal Then
- Pref.formwidth = Me.Width
- Pref.formheight = Me.Height
- Pref.locx = Me.Location.X
- Pref.locy = Me.Location.Y
- Pref.maximised = False
- End If
-
- If Me.WindowState = FormWindowState.Maximized Then
- Me.WindowState = FormWindowState.Normal
- Pref.maximised = True
- End If
-
- If DataGridView1.Columns.Count > 0 Then
- Pref.tableview.Clear()
- For Each column In DataGridView1.Columns
- Dim tempstring As String = String.Format("{0}|{1}|{2}|{3}", column.name, column.width, column.displayindex, column.visible)
- Pref.tableview.Add(tempstring)
- Next
- End If
-
- Pref.startuptab = TabLevel1.SelectedIndex
-
- Pref.ConfigSave()
- SplashscreenWrite()
- Call util_ProfileSave()
- Dim errpath As String = IO.Path.Combine(applicationPath, "tvrefresh.log")
- Catch ex As Exception
- MessageBox.Show(ex.ToString, "Exception")
- Environment.Exit(1)
- 'ExceptionHandler.LogError(ex)
- End Try
-
- End Sub
-
- Private Sub Form1_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.GotFocus
- Try
- If messbox.Visible = True Then
- messbox.Activate()
- End If
- Catch ex As Exception
- ExceptionHandler.LogError(ex)
- End Try
-
- End Sub
-
- Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize
- Try
- If Me.WindowState = FormWindowState.Maximized Then
- mov_SplitContainerAutoPosition()
- tv_SplitContainerAutoPosition()
- End If
- If Not Me.WindowState = FormWindowState.Minimized Then
- tv_SplitContainerAutoPosition()
- End If
- If startup = False Then
- Pref.locx = Me.Location.X
- Pref.locy = Me.Location.Y
- End If
- If MainFormLoadedStatus = True Then
- doResizeRefresh()
- End If
- Catch ex As Exception
- Dim paramInfo As String = ""
- Try
- paramInfo = "PbMovieFanArt.Width:" & PbMovieFanArt.Width.ToString & " PbMovieFanArt.Height: " & PbMovieFanArt.Height.ToString & " Rating:" & ratingtxt.Text
- Catch ex2 As Exception
- ExceptionHandler.LogError(ex2)
- End Try
- ExceptionHandler.LogError(ex, paramInfo)
- End Try
- End Sub
-
- Private Sub Form1_ResizeEnd(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.ResizeEnd
- Try
- If Pref.formwidth <> Me.Width Or Pref.formheight <> Me.Height Then
- Pref.formwidth = Me.Width
- Pref.formheight = Me.Height
- End If
- mov_SplitContainerAutoPosition()
- tv_SplitContainerAutoPosition()
-
- Catch ex As Exception
- ExceptionHandler.LogError(ex)
- End Try
-
- End Sub
-
- Private Sub Form1_KeyDown(sender As System.Object, e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
-
- If e.KeyCode = Keys.Escape Then bckgrndcancel()
- If e.KeyCode = Keys.F5 Then doRefresh()
- If e.KeyCode = Keys.F3 Then doSearchNew()
- If e.Control And e.KeyCode = Keys.C Then AbortFileDownload()
- End Sub
-
- #End Region
-
- Sub Ini_Timer(t As Timers.Timer, Optional Interval As Integer = 1000, Optional Repeating As Boolean = False)
- t.Stop()
- t.Interval = Interval
- t.AutoReset = Repeating
- End Sub
-
-
- #Region "XBMC Link"
- Private Sub BckWrkXbmcController_DoWork(ByVal sender As Object, ByVal e As DoWorkEventArgs)
- Dim bw As BackgroundWorker = CType(sender, BackgroundWorker)
- Dim sm As New XbmcController(e.Argument, bw)
- sm.Go()
- End Sub
-
- Private Sub XBMC_Controller_Log_TO_Timer_Elapsed()
- If Not BckWrkScnMovies.IsBusy And XbmcControllerBufferQ.Count = 0 Then
- If DateDiff(DateInterval.Second, XBMC_Controller_LogLastShownDt, Now) > 30 Then
-
- Pref.OpenFileInAppPath(Form1.XBMC_Controller_full_log_file)
- Pref.OpenFileInAppPath(Form1.XBMC_Controller_brief_log_file)
-
- frmXBMC_Progress.Reset()
- Dim ce As New BaseEvent(XbmcController.E.ResetErrorCount, New BaseEventArgs())
- XbmcControllerQ.Write(ce)
- End If
- XBMC_Controller_LogLastShownDt = Now
- XBMC_Link_ErrorLog_Timer.Stop()
- End If
- End Sub
-
- Private Sub XBMC_Link_Idle_Timer_Elapsed()
- If Not BckWrkScnMovies.IsBusy And XbmcControllerBufferQ.Count = 0 Then
- frmXBMC_Progress.Visible = False
- XBMC_Link_ErrorLog_Timer.Stop()
- End If
- End Sub
-
- Sub Restart(tmr As Timers.Timer)
- tmr.Stop()
- tmr.Start()
- End Sub
-
- Private Sub BckWrkXbmcController_ReportProgress(ByVal sender As Object, ByVal e As ProgressChangedEventArgs)
- Dim oProgress As XBMC_Controller_Progress = CType(e.UserState, XBMC_Controller_Progress)
-
- If XBMC_Link_ErrorLog_Timer.Enabled Then
- Restart(XBMC_Link_ErrorLog_Timer)
- End If
-
- Restart(XBMC_Link_Idle_Timer)
- Restart(XBMC_Link_Check_Timer)
-
- frmXBMC_Progress.Visible = True
- If HandleEvents(oProgress) Then Return
- If oProgress.ErrorCount > 0 Then
- If Pref.ShowLogOnError Then
- XBMC_Link_ErrorLog_Timer.Start()
- End If
- End If
-
- frmXBMC_Progress.UpdateDetails(oProgress)
- End Sub
-
- Function HandleEvents(oProgress As XBMC_Controller_Progress) As Boolean
-
- Select Case oProgress.Evt
-
- Case XbmcController.E.MC_Only_Movies
- MC_Only_Movies = CType(oProgress.Args, ComboList_EventArgs).XbmcMovies
- Assign_FilterGeneral()
- Return True
-
- Case XbmcController.E.MC_XbmcMcMovies
- oMovies.XbmcMcMovies = CType(oProgress.Args, XBMC_MC_Movies_EventArgs).XbmcMcMovies
- Assign_FilterGeneral()
- Return True
-
- Case XbmcController.E.MC_XbmcOnlyMovies
- oMovies.XbmcOnlyMovies = CType(oProgress.Args, XBMC_Only_Movies_EventArgs).XbmcOnlyMovies
- Return True
-
- Case XbmcController.E.MC_XbmcQuit
- SetcbBtnLink()
- Return True
-
- End Select
- Return False
- End Function
-
- Const MaxConseqFailures As Integer = 3
-
- Dim ConnectSent As Boolean
- Dim XbmcLastLinkState As Boolean
- Dim ConseqFailures As Integer = 0
-
- Sub SetcbBtnLink(Optional sender As Object = Nothing)
- XBMC_Link_Check_Timer.Stop()
-
- 'Only check when link is idle
- If Not BckWrkScnMovies.IsBusy And XbmcControllerBufferQ.Count = 0 Then
- Dim passed As Boolean = XBMC_TestsPassed
-
- '
- ' Sometimes the link test fails. Don't know why yet, maybe XBMC is busy...but anyway this should reduce the number of phantom
- ' link disablings...
- '
- If Not IsNothing(sender) Then
- If cbBtnLink.Enabled And Not passed Then
- ConseqFailures += 1
- Else
- ConseqFailures = 0
- End If
- Else
- ConseqFailures = 0
- End If
-
- If IsNothing(sender) Or ConseqFailures <= MaxConseqFailures Then
- cbBtnLink.Enabled = passed
- If cbBtnLink.Enabled Then
- cbBtnLink.BackColor = IIf(cbBtnLink.Checked, Color.LightGreen, Color.Transparent)
- If Pref.XBMC_Link <> cbBtnLink.Checked Then
- Pref.XBMC_Link = cbBtnLink.Checked
- If Pref.XbmcLinkReady Then
- XbmcControllerQ.Write(XbmcController.E.ConnectReq, PriorityQueue.Priorities.low)
- End If
- Pref.ConfigSave()
- End If
- Else
- cbBtnLink.Checked = False
- cbBtnLink.BackColor = Color.Transparent
- End If
- tsmiMov_SyncToXBMC.Enabled = cbBtnLink.Enabled And cbBtnLink.Checked
- End If
- End If
- XBMC_Link_Check_Timer.Start()
- End Sub
-
- Private Sub XBMC_Link_Check_Timer_Elapsed()
- If ProgState = ProgramState.MovieControlsDisabled Then Return
- SetcbBtnLink(XBMC_Link_Check_Timer)
- End Sub
-
- Private Sub keypresstimer_Elapsed()
- MovieKeyPress = ""
- End Sub
-
- Private Sub statusstripclear_Elapsed()
- ToolStripStatusLabel2.Visible = False
- Statusstrip_Enable(False)
- ToolStripStatusLabel2.Text = "TV Show Episode Scan In Progress"
- End Sub
-
- Sub XbmcLink_UpdateArtwork()
- If Pref.XBMC_Delete_Cached_Images AndAlso Pref.XbmcLinkReady Then
- Dim m As Movie = oMovies.LoadMovie(workingMovieDetails.fileinfo.fullpathandfilename)
- m.SaveNFO()
- End If
- End Sub
- #End Region
-
- Private Sub BlinkTaskBar()
- If GetActiveWindow <> Me.Handle Then
- Dim res = WindowsApi.FlashWindow(Process.GetCurrentProcess().MainWindowHandle, True, True, 5)
- End If
- End Sub
-
- Private Function splashscreenread() As Integer
- Dim scrn As Integer = 0
- Dim checkpath As String = Pref.applicationPath & "\Settings\screen.xml"
- If File.Exists(checkpath) Then
- Try
- Dim document As XDocument = XDocument.Load(checkpath)
- Dim sc = From t In document.Descendants("screen") Select t.Value
- Dim mten = From t In document.Descendants("MultiEnabled") Select t.Value
- multimonitor = Convert.ToBoolean(mten.First())
- scrn = sc.First().ToInt
- If scrn > NumOfScreens Then scrn = 0
- Catch
- scrn = 0
- multimonitor = False
- End Try
- End If
- Return scrn
- End Function
-
- Private Sub SplashscreenWrite()
- Dim doc As New XmlDocument
- Dim thispref As XmlNode = Nothing
- Dim xmlproc As XmlDeclaration
- Dim root As XmlElement = Nothing
- Dim child As XmlElement = Nothing
- xmlproc = doc.CreateXmlDeclaration("1.0", "UTF-8", "yes")
- doc.AppendChild(xmlproc)
- root = doc.CreateElement("root")
- child = doc.CreateElement("MultiEnabled")
- child.InnerXml = Pref.MultiMonitoEnabled
- root.AppendChild(chi…
Large files files are truncated, but you can click here to view the full file