Attribute VB_Name = "modMain"
' -------------------------------------------------------------------------------
'
'   AVStoDVD - by MrC
'   File: modMain.bas
'   Purpose: Main, startup
'
' -------------------------------------------------------------------------------


Option Explicit
Option Compare Binary
Option Base 0


Public Sub Main()

    Dim jj As Integer
    Dim CL() As String
    Dim Str As String
    Dim NumFile As Integer
    Dim bFlag As Boolean

    On Error Resume Next
    
    ' Detect Windows version, NT5 minimum
    If SysInfo.OSIsNT5 = False Then
        If MsgBox("Windows 2000 or higher is required in order to use AVStoDVD." & vbCrLf & vbCrLf & "Do you want to continue anyway?", vbQuestion + vbYesNo) = vbNo Then End
    End If
    
    ' Delete temporary AVStoDVD garbage
    If Dir(Preferences.TempPath & "\A2D*.cache") <> "" Then
        Kill Preferences.TempPath & "\A2D*.cache"
    End If
    modFS.DeleteIfExist Preferences.TempPath & "\AviSynthP.avs"
    modFS.DeleteIfExist Preferences.TempPath & "\AviSynthD.avs"
    
    ' Useful AVStoDVD Stuff (part 1)
    AVStoDVD_RegKey = "HKEY_CURRENT_USER\SOFTWARE\AVStoDVD"
    App.HelpFile = App.Path & "\Docs\AVStoDVD_Help.chm"
    SpecialChars = "\ / : * ? "" < > |"
    With SID
        .CurrentUser = modReg.SubKeysArray("HKEY_CURRENT_USER\Software\Microsoft\Protected Storage System Provider")
        .Users = "S-1-5-32-545"
        .Administrators = "S-1-5-32-544"
        .Guests = "S-1-5-32-546"
        .PowerUsers = "S-1-5-32-547"
        .TrustedInstaller = "S-1-5-80-956008885-3418522649-1831038044-1853292631-2271478464"
    End With
    
    ' Define Video/Audio standards
    With BitRates(AC3)
        .add 64
        .add 96
        .add 128
        .add 160
        .add 192
        .add 224
        .add 256
        .add 384
        .add 448
    End With
    With BitRates(MP2)
        .add 64
        .add 96
        .add 128
        .add 160
        .add 192
        .add 224
        .add 256
    End With
    With BitRates(WAV)
        .add 768
        .add 1536
    End With
    With BitRates(DTS)
        .add 754
        .add 1510
    End With
    
    ' Populate ISO Language Code collection
    With ISOLangCode
        If modFS.EsisteFile(App.Path & "\Docs\ISO639_Languages.txt") = True Then
            NumFile = FreeFile
            Open App.Path & "\Docs\ISO639_Languages.txt" For Input As #NumFile
                Do
                    Line Input #NumFile, Str
                    .add Str
                Loop Until EOF(NumFile) = True
            Close #NumFile
        Else
            .add "DE - German"
            .add "EN - English"
            .add "ES - Spanish"
            .add "FR - French"
            .add "IT - Italian"
            .add "JA - Japanese"
            .add "KO - Korean"
            .add "PT - Portuguese"
            .add "RU - Russian"
            .add "ZH - Chinese"
        End If
    End With
        
    ' Check if mscomctl.ocx is registered
    bFlag = False
    PathNames.MSComCtlOcx = modReg.EmiLeggiChiaveStringa("HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{0B314611-2C19-4AB4-8513-A6EEA569D3C4}\InprocServer32", "")
    If PathNames.MSComCtlOcx <> "" Then
        If Dir(PathNames.MSComCtlOcx) <> "" Then
            bFlag = True
        End If
    End If
    If bFlag = False Then
        MsgBox "Warning!" & vbCrLf & vbCrLf & _
               "Windows Common Controls 6.0 ActiveX Library (mscomctl.ocx) is not present or not correctly registered." & vbCrLf & vbCrLf & _
               "This file is mandatory for AVStoDVD." & vbCrLf & vbCrLf & _
               "You have 3 options:" & vbCrLf & vbCrLf & _
               "1. Download and install AVStoDVD Installer Package (it takes care to install mscomctl.ocx)" & vbCrLf & _
               "2. Download and install Visual Basic 6.0 Runtime Libraries Package (from Microsoft website)" & vbCrLf & _
               "3. (If you feel strong and admin) register it manually: regsvr32 """ & "..\AVStoDVD\Lib\mscomctl.ocx""", vbCritical, App.Title
        End
    End If
    
    ' Find Web Browser pathname
    Str = modReg.EmiLeggiChiaveStringa("HKEY_CURRENT_USER\Software\Classes\http\shell\open\command", "")
    If InStr(1, LCase(Str), ".exe") <> 0 Then
        Str = Left(Str, InStr(1, LCase(Str), ".exe")) & "exe"
        Str = modStr.RemoveCharBegEnd(Str, """")
    Else
        Str = modReg.EmiLeggiChiaveStringa("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.html\OpenWithList", "a")
        If Str = "" Then
            Str = modReg.EmiLeggiChiaveStringa("HKEY_CURRENT_USER\Software\Clients\StartmenuInternet", "", "IEXPLORE.EXE")
        End If
        Str = modReg.EmiLeggiChiaveStringa("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\" & Str, "")
    End If
    If modFS.EsisteFile(Str) = True And InStr(1, LCase(Str), ".exe") <> 0 Then
        PathNames.WebBrowser = Str
    End If
    
    ' Search for ImgBurn.exe
    PathNames.ImgBurn = modReg.EmiLeggiChiaveStringa("HKEY_CURRENT_USER\SOFTWARE\ImgBurn", "InstallDirectory", "") & "\ImgBurn.exe"
    If modFS.EsisteFile(PathNames.ImgBurn) = False Then
        PathNames.ImgBurn = SysInfo.PathPrograms & "\ImgBurn\ImgBurn.exe"
        If modFS.EsisteFile(PathNames.ImgBurn) = False Then
            PathNames.ImgBurn = ""
        End If
    End If
    
    ' Search for AviSynth
    With AviSynth
        .CLSID = ""
        .RegKey = "HKEY_LOCAL_MACHINE\SOFTWARE\AviSynth"
        .PathName = SysInfo.PathSystem & "\avisynth.dll"
        If modFS.EsisteFile(.PathName) = False Then
            .PathName = ""
        End If
        If .PathName <> "" Then
            .Version = modFileVersion.GetFileVersion(.PathName, , True)
        End If
    End With
    
    ' Search for ffdshow.ax
    With ffdshow
        .CLSID = "04FE9017-F873-410E-871E-AB91661A4EF7"
        .RegKey = "HKEY_CURRENT_USER\Software\GNU\ffdshow"
        .PathName = modReg.EmiLeggiChiaveStringa("HKEY_CLASSES_ROOT\CLSID\{" & .CLSID & "}\InprocServer32", "", "")
        If modFS.EsisteFile(.PathName) = False Then
            .PathName = SysInfo.PathPrograms & "\ffdshow\ffdshow.ax"
            If modFS.EsisteFile(.PathName) = False Then
                .PathName = ""
            End If
        End If
        If .PathName <> "" Then
            .Version = modFileVersion.GetFileVersion(.PathName, , True)
        End If
    End With
    
    ' Search for LAVVideo.ax
    With LAVFilters
        .CLSID = "EE30215D-164F-4A92-A4EB-9D4C13390F9F"
        .RegKey = "HKEY_CURRENT_USER\Software\LAV"
        .PathName = modReg.EmiLeggiChiaveStringa("HKEY_CLASSES_ROOT\CLSID\{" & .CLSID & "}\InprocServer32", "", "")
        If modFS.EsisteFile(.PathName) = False Then
            .PathName = SysInfo.PathPrograms & "\LAVFilters\LAVVideo.ax"
            If modFS.EsisteFile(.PathName) = False Then
                .PathName = ""
            End If
        End If
        If .PathName <> "" Then
            .Version = modFileVersion.GetFileVersion(.PathName, , True)
        End If
    End With
    
    ' Erase AVStoDVD registry key if current Release has different Major+Minor
    RegRelease = modStr.PadLeft(modReg.EmiLeggiChiaveStringa(AVStoDVD_RegKey, "ReleaseMajor", ""), "0", 2) & _
                 modStr.PadLeft(modReg.EmiLeggiChiaveStringa(AVStoDVD_RegKey, "ReleaseMinor", ""), "0", 2) & _
                 modStr.PadLeft(modReg.EmiLeggiChiaveStringa(AVStoDVD_RegKey, "ReleaseRevision", ""), "0", 2) & _
                 modStr.PadLeft(modReg.EmiLeggiChiaveStringa(AVStoDVD_RegKey, "ReleaseBuild", ""), "0", 6)
    CurRelease = modStr.PadLeft(App.Major, "0", 2) & _
                 modStr.PadLeft(App.Minor, "0", 2) & _
                 modStr.PadLeft(App.Revision, "0", 2) & _
                 Right(App.Comments, 6)
    If Val(RegRelease) < 20200090511# Or Val(CurRelease) - Val(RegRelease) > 100000000 Then
        modReg.CancellaChiave AVStoDVD_RegKey & "\DVDMenu"
        modReg.CancellaChiave AVStoDVD_RegKey
    End If
    
    ' Setup AVStoDVD registry key
    modReg.CreaChiave AVStoDVD_RegKey
    
    ' Define Default Preferences
    With PreferencesDefault
        .MultiThread = True
        
        Str = SysInfo.PathVideos
        If Len(Str) < 3 Then Str = SysInfo.PathDocuments
        .InputPath = Str
        .OutputPath = .InputPath
        .AssetsPath = .InputPath
        .ProjectsPath = SysInfo.PathDocuments
        .TempPath = Environ("TEMP")
        .MenuTemplatesPath = App.Path & "\Menu\Templates"
        .PreviewerPathName = ""
        
        .AVSVideoInput = "A2DSource"
        .AVSAudioInput = "A2DSource"
        .AVSUpSize = "Lanczos4Resize"
        .AVSDownSize = "Spline16Resize"
        .FrameAdjust = AddBordersLeftRight
        .FPSHardConversion = MotionProtectedFPS
        .PALSpeedUp = False
        .NTSCSlowDown = False
        
        .KeepOrigVideo = True
        .VideoStandard = PAL
        .VideoEncoder = SmartSelection
        .VideoProfileLevel1 = "6500"
        .VideoProfileLevel2 = "4500"
        .VideoResolution = Auto
        .VideoFFmpegHQ = False
        .VideoFFmpegHQCmd = "-bf 2 -mbd rd -cmp 2 -subcmp 2"
        .VideoMinAvgBitRate = "2500"
        .VideoMaxAvgBitRate = "8500"
        .VideoMaxBitRate = "9000"
        
        .KeepOrigAudio = True
        .AC3AudioEncoder = Wavi_Aften
        .ForceFFmpeg4GB = True
        .AudioFormat = AC3
        .AudioBitRate = "192"
        .AudioNormalize = False
        .AudioNormalizeVal = "1"
        .AudioDelayAuto = True
    
        .AudioLanguage = "EN - English"
        .AudioLanguage2 = .AudioLanguage
        .SubsLanguage = .AudioLanguage
        .SubsLanguage2 = .AudioLanguage
        With .SubsFont
            .Name = "Tahoma"
            .Height = 16
            .Bold = False
            .Italic = False
            .Color = RGB(255, 255, 255)
        End With
        With .SubsPos
            .Left = 80
            .Bottom = 100
            .Width = 560
        End With
        .ChaptersInterval = "5"
        .ChaptersUseSource = True
        For jj = 0 To Drives.driveCount - 1
            .DVDBurningDrive = Drives.driveLetter(jj) & ":\"
            If Drives.driveWriteDVD(jj) = True Then
                Exit For
            End If
        Next jj
        .DVDBurningSpeed = "4x"
        .DVDAutoErase = True
    
        .SplashScreenName = "Default"
        .EncodingPriority = Idle
        .EncodingWindowStyle = 1
        .ForceRunAsAdmin = False
        .UnloadDShow = True
        .DSFiltersRuntime = True
        .SaveSettings = False
        
        .Language = "English"
        .Skin = "Default"
        
        ' Debug
        .FFmpegDemuxMatroska = False
        .SlowSystemFlag = False
    End With
    
    ' Load General Preferences
    modMain.Reg_Preferences_Load
    
    ' Setup GUI Language
    Set Language = modMain.Load_Language(Preferences.Language)
    If Language.Count = 0 Then End
    
    ' Useful AVStoDVD stuff (part 2)
    AVStoDVD_Picture = App.Path & "\Graphics\AVStoDVD_Splash_" & Preferences.SplashScreenName & "_Large.jpg"
    If modFS.EsisteFile(AVStoDVD_Picture) = False Then
        AVStoDVD_Picture = App.Path & "\Graphics\AVStoDVD_Splash_Default_Large.jpg"
    End If
    With Msgs
        .FileExistsOverwrite = modStr.DefaultStr(Language("000100"), "File already existing. Overwrite?")
        .CreateSuccess = modStr.DefaultStr(Language("000110"), "File successfully created.")
        .FileNotFound = modStr.DefaultStr(Language("000150"), "Warning! File not found.")
        .InvalidValue = modStr.DefaultStr(Language("000200"), "Warning! Inserted value is invalid.")
    End With
    
    ' Load main forms and display release
    Load frmMain
    With frmMain
        .StatusBar.Panels("Release").Text = "AVStoDVD Release " & App.Major & "." & App.Minor & "." & App.Revision
        If InStr(1, LCase(App.Comments), "final") = 0 Then
            .StatusBar.Panels("Release").Text = .StatusBar.Panels("Release").Text & " " & App.Comments
        End If
    End With
    Load frmJobsList
    
    ' Load Quick StartUp Tutorial form
    If modReg.EmiLeggiChiaveNumero(AVStoDVD_RegKey, "TutorialExecuted", -1) = -1 Then
        Load frmTutorial
        frmTutorial.Show 1
    End If
    
    ' Display the splash screen while checking system files
    If LCase(Preferences.SplashScreenName) <> "none" Then
        Load frmSplash
        With frmSplash
            .Show
            .Refresh
            DoEvents
            .FadeIn
            modMain.Check_Software "frmSplash"
        End With
        Unload frmSplash
    Else
        modMain.Check_Software
    End If
    
    ' ffdshow settings check
    With ffdshow
        If Preferences.DSFiltersRuntime = True And .PathName <> "" Then
            .MixerEnabled = CBool(modReg.EmiLeggiChiaveNumero(.RegKey & "_audio\default", "isMixer", 0))
            .MixerBackup = modReg.EmiLeggiChiaveNumero(.RegKey & "_audio\default", "mixerOut", 1)
            .RawVideoBackup = modReg.EmiLeggiChiaveNumero(.RegKey, "rawv", 1)
            .RawAudioBackup = modReg.EmiLeggiChiaveNumero(.RegKey & "_audio", "rawa", 4)
        End If
    End With
    
    ' LAVFilters settings check
    With LAVFilters
        If Preferences.DSFiltersRuntime = True And .PathName <> "" Then
            .MixerEnabled = CBool(modReg.EmiLeggiChiaveNumero(.RegKey & "\Audio", "Mixing", 0))
            .MixerBackup = modReg.EmiLeggiChiaveNumero(.RegKey & "\Audio", "MixingLayout", 3)  ' 3: Stereo
            .PreferHighQualityAudioBackup = CBool(modReg.EmiLeggiChiaveNumero(.RegKey & "\Splitter", "PreferHighQualityAudio", 1))
            If .PreferHighQualityAudioBackup = True Then
                modReg.ScriviChiaveNumero .RegKey & "\Splitter", "PreferHighQualityAudio", 0
            End If
        End If
    End With
    
    ' Display Main form
    frmMain.Show
    
    ' Initialize AVStoDVD
    modMain.Reset_Project
    modMain.Save_Log_Video frmMain.StatusBar.Panels("Release").Text & " loaded!"
    
    ' Check AviSynth presence
    With AviSynth
        If InStr(1, modReg.EmiLeggiChiaveStringa(.RegKey, ""), "AviSynth") <> 0 Then
            modMain.Save_Log_Video "AviSynth " & .Version & " is installed (""" & .PathName & """)."
            ' Check version
            Str = Replace(.Version, ".", "")
            If Val(Str) < 260 Then
                modMain.Save_Log_Video "Warning! AviSynth release 2.6.0 or higher is required. Some encoding routines will not work.", , False
            End If
        Else
            modMain.Save_Log_Video "Warning! AviSynth is NOT installed. Most of encoding routines will not work.", , True
        End If
    End With
    
    ' Check ffdshow and LAVFilters presence
    With frmMain
        .Menu_Codecs_ffdshow_Video.Enabled = False
        .Menu_Codecs_LAVFilters_Video.Enabled = False
        If ffdshow.PathName = "" And LAVFilters.PathName = "" Then
            modMain.Save_Log_Video "Warning! ffdshow 32bit or LAV Filters are NOT installed. Some Video and Audio streams will not be decoded."
        Else
            If ffdshow.PathName <> "" Then
                modMain.Save_Log_Video "ffdshow " & modFileVersion.GetFileVersion(ffdshow.PathName, , True) & " 32bit is installed (""" & ffdshow.PathName & """)."
                .Menu_Codecs_ffdshow_Video.Enabled = True
            End If
            If LAVFilters.PathName <> "" Then
                modMain.Save_Log_Video "LAV Filters " & modFileVersion.GetFileVersion(LAVFilters.PathName, , True) & " is installed (""" & LAVFilters.PathName & """)."
                .Menu_Codecs_LAVFilters_Video.Enabled = True
            End If
            If ffdshow.PathName <> "" And LAVFilters.PathName <> "" Then
                modMain.Save_Log_Video "Warning! Having both ffdshow and LAV Filters installed may cause media decoding instability! Please consider removing one of them."
            End If
        End If
        .Menu_Codecs_ffdshow_Audio.Enabled = .Menu_Codecs_ffdshow_Video.Enabled
        .Menu_Codecs_LAVFilters_Audio.Enabled = .Menu_Codecs_LAVFilters_Video.Enabled
    End With
          
    ' Check ImgBurn presence
    If PathNames.ImgBurn <> "" Then
        Str = modFileVersion.GetFileVersion(PathNames.ImgBurn, , True)
        modMain.Save_Log_Video "ImgBurn " & Str & " is installed (""" & PathNames.ImgBurn & """)."
    Else
        modMain.Save_Log_Video "Warning! ImgBurn is NOT installed. ISO Image building and DVD burning disabled."
    End If
    With frmMain
        .Menu_Options_ISO.Enabled = CBool(Len(PathNames.ImgBurn))
        .Menu_Options_Burn_DVD.Enabled = .Menu_Options_ISO.Enabled
        With .Toolbar.Buttons("Output_Setup")
            .ButtonMenus("ISO").Enabled = CBool(Len(PathNames.ImgBurn))
            .ButtonMenus("Burn_DVD").Enabled = .ButtonMenus("ISO").Enabled
        End With
    End With
        
    ' Check Preferences Paths
    If modFS.EsisteDir(Preferences.OutputPath) = False Then
        modMain.Save_Log_Video "Warning! Cannot locate 'DVD Output Path'. Check 'Preferences'/'Paths'.", , True
    ElseIf modFS.EsisteDir(Preferences.AssetsPath) = False Then
        modMain.Save_Log_Video "Warning! Cannot locate 'DVD Asset Path'. Check 'Preferences'/'Paths'.", , True
    ElseIf modFS.EsisteDir(Preferences.ProjectsPath) = False Then
        modMain.Save_Log_Video "Warning! Cannot locate 'A2D Projects Path'. Check 'Preferences'/'Paths'.", , True
    ElseIf modFS.EsisteDir(Preferences.TempPath) = False Then
        modMain.Save_Log_Video "Warning! Cannot locate 'Temporary Files Path'. Check 'Preferences'/'Paths'.", , True
    ElseIf modFS.EsisteDir(Preferences.MenuTemplatesPath) = False Then
        modMain.Save_Log_Video "Warning! Cannot locate 'DVD Menu Templates Path'. Check 'Preferences'/'Paths'.", , True
    Else
        'modMain.Save_Log_Video "Preferences Paths check passed."
    End If
    
    ' Check if user is an Admin
    If SysInfo.IsAdmin = False Then
        modMain.Save_Log_Video "Warning! Current User does not have Administrator Rights. Some features may not work."
    End If
    
    ' Welcome
    modMain.Save_Log_Video "New AVStoDVD Project started!"
    
    ' Handle Command Line
    If Command <> "" Then
        CL = Split(modStr.RemoveCharBegEnd(Command, """"), """ """)
        For jj = LBound(CL) To UBound(CL)
            If modFS.EsisteFile(CL(jj)) = True Then
                If LCase(modFS.ExtOf(CL(jj))) = "a2d" Then
                    Call frmMain.Open_Project(CL(jj))
                    Exit Sub
                Else
                    If InStr(1, FilterList.VideoFiles, "." & LCase(modFS.ExtOf(CL(jj)))) <> 0 Then
                        Call frmMain.Add_Title(CL(jj))
                    Else
                        MsgBox "Warning! Unrecognized or unsupported file format for title:" & vbCrLf & vbCrLf & CL(jj) & vbCrLf & vbCrLf & _
                               "AVStoDVD supports following formats:" & vbCrLf & vbCrLf & FilterList.SupportedVideoFormats, vbExclamation, App.Title
                    End If
                End If
            End If
         Next jj
    End If
    
End Sub


Public Sub Quit(Shutdown As Boolean)
    
    Dim jj As Integer
    Dim frm As Form
    
    On Error GoTo Err_Handling
    
    ' Save general app properties into Registry
    modReg.ScriviChiaveStringa AVStoDVD_RegKey, "AppTitle", App.Title
    modReg.ScriviChiaveStringa AVStoDVD_RegKey, "Release", App.Major & "." & App.Minor & "." & App.Revision
    modReg.ScriviChiaveStringa AVStoDVD_RegKey, "ReleaseMajor", App.Major
    modReg.ScriviChiaveStringa AVStoDVD_RegKey, "ReleaseMinor", App.Minor
    modReg.ScriviChiaveStringa AVStoDVD_RegKey, "ReleaseRevision", App.Revision
    modReg.ScriviChiaveStringa AVStoDVD_RegKey, "ReleaseBuild", Right(App.Comments, 6)
    modReg.ScriviChiaveStringa AVStoDVD_RegKey, "AppPath", App.Path

    ' Unload Forms
    For Each frm In Forms
        Unload frm
    Next frm
    
    ' Restore ffdshow/LAVFilters mixer settings
    If Preferences.DSFiltersRuntime = True Then
        ' ffdshow
        With ffdshow
            If .PathName <> "" And .MixerEnabled = True Then
                modReg.ScriviChiaveNumero .RegKey & "_audio\default", "isMixer", 1
                modReg.ScriviChiaveNumero .RegKey & "_audio\default", "mixerOut", .MixerBackup
            End If
        End With
        ' LAVFilters
        With LAVFilters
            If .PathName <> "" Then
                If .MixerEnabled = True Then
                    modReg.ScriviChiaveNumero .RegKey & "\Audio", "Mixing", 1
                    modReg.ScriviChiaveNumero .RegKey & "\Audio", "MixingLayout", .MixerBackup
                End If
                If .PreferHighQualityAudioBackup = True Then
                    modReg.ScriviChiaveNumero .RegKey & "\Splitter", "PreferHighQualityAudio", 1
                End If
            End If
        End With
    End If
    
    ' Check Shutdown
    If Shutdown = True Then
        modExtSW.WinShutdown 60, "AVStoDVD has completed the job. Shutdown in progress..."
    End If
    
    ' Clear Variables
    For jj = AC3 To DTS
        Set BitRates(jj) = Nothing
    Next jj
    Set ISOLangCode = Nothing
    Set FilterList = Nothing
    Set Drives = Nothing
    Set SysInfo = Nothing
    Erase Title
    
    ' Delete junk files
    With Preferences
        modFS.DeleteIfExist Preferences.TempPath & "\AutoCrop001.bmp"
        If Dir(.TempPath & "\A2D*.cache") <> "" Then
            Kill .TempPath & "\A2D*.cache"
        End If
        If Dir(.TempPath & "\AviSynth*.avs") <> "" Then
            Kill .TempPath & "\AviSynth*.avs"
        End If
        If Dir(.TempPath & "\*.a2d.srt*") <> "" Then
            Kill .TempPath & "\*.a2d.srt*"
        End If
        If Dir(.TempPath & "\*.a2d.txt*") <> "" Then
            Kill .TempPath & "\*.a2d.txt*"
        End If
    End With
    
Err_Handling:
Screen.MousePointer = vbDefault
End
    
End Sub


Public Sub Reg_Preferences_Update()

    Dim sReg As String
    
    With Preferences
        modReg.ScriviChiaveNumero AVStoDVD_RegKey, "MultiThread", -CInt(.MultiThread)
        
        modReg.ScriviChiaveStringa AVStoDVD_RegKey, "InputPath", .InputPath
        modReg.ScriviChiaveStringa AVStoDVD_RegKey, "OutputPath", .OutputPath
        modReg.ScriviChiaveStringa AVStoDVD_RegKey, "AssetsPath", .AssetsPath
        modReg.ScriviChiaveStringa AVStoDVD_RegKey, "ProjectsPath", .ProjectsPath
        modReg.ScriviChiaveStringa AVStoDVD_RegKey, "TempPath", .TempPath
        modReg.ScriviChiaveStringa AVStoDVD_RegKey, "MenuTemplatesPath", .MenuTemplatesPath
        modReg.ScriviChiaveStringa AVStoDVD_RegKey, "PreviewerPathName", .PreviewerPathName
        
        modReg.ScriviChiaveStringa AVStoDVD_RegKey, "AVSVideoInput", .AVSVideoInput
        modReg.ScriviChiaveStringa AVStoDVD_RegKey, "AVSAudioInput", .AVSAudioInput
        modReg.ScriviChiaveStringa AVStoDVD_RegKey, "AVSUpSize", .AVSUpSize
        modReg.ScriviChiaveStringa AVStoDVD_RegKey, "AVSDownSize", .AVSDownSize
        modReg.ScriviChiaveNumero AVStoDVD_RegKey, "FrameAdjust", .FrameAdjust
        modReg.ScriviChiaveNumero AVStoDVD_RegKey, "FPSHardConversion", .FPSHardConversion
        modReg.ScriviChiaveNumero AVStoDVD_RegKey, "PALSpeedUp", .PALSpeedUp
        modReg.ScriviChiaveNumero AVStoDVD_RegKey, "NTSCSlowDown", .NTSCSlowDown
        
        modReg.ScriviChiaveNumero AVStoDVD_RegKey, "KeepOrigVideo", -CInt(.KeepOrigVideo)
        modReg.ScriviChiaveNumero AVStoDVD_RegKey, "VideoStandard", .VideoStandard
        modReg.ScriviChiaveNumero AVStoDVD_RegKey, "VideoResolution", .VideoResolution
        modReg.ScriviChiaveNumero AVStoDVD_RegKey, "VideoEncoder", .VideoEncoder
        modReg.ScriviChiaveStringa AVStoDVD_RegKey, "VideoProfileLevel1", .VideoProfileLevel1
        modReg.ScriviChiaveStringa AVStoDVD_RegKey, "VideoProfileLevel2", .VideoProfileLevel2
        modReg.ScriviChiaveNumero AVStoDVD_RegKey, "VideoFFmpegHQ", -CInt(.VideoFFmpegHQ)
        modReg.ScriviChiaveStringa AVStoDVD_RegKey, "VideoFFmpegHQCmd", .VideoFFmpegHQCmd
        modReg.ScriviChiaveStringa AVStoDVD_RegKey, "VideoMinAvgBitRate", .VideoMinAvgBitRate
        modReg.ScriviChiaveStringa AVStoDVD_RegKey, "VideoMaxAvgBitRate", .VideoMaxAvgBitRate
        modReg.ScriviChiaveStringa AVStoDVD_RegKey, "VideoMaxBitRate", .VideoMaxBitRate
        
        modReg.ScriviChiaveNumero AVStoDVD_RegKey, "KeepOrigAudio", -CInt(.KeepOrigAudio)
        modReg.ScriviChiaveNumero AVStoDVD_RegKey, "AC3AudioEncoder", .AC3AudioEncoder
        modReg.ScriviChiaveNumero AVStoDVD_RegKey, "ForceFFmpeg4GB", .ForceFFmpeg4GB
        modReg.ScriviChiaveNumero AVStoDVD_RegKey, "AudioFormat", .AudioFormat
        modReg.ScriviChiaveStringa AVStoDVD_RegKey, "AudioBitRate", .AudioBitRate
        modReg.ScriviChiaveNumero AVStoDVD_RegKey, "AudioNormalize", -CInt(.AudioNormalize)
        modReg.ScriviChiaveStringa AVStoDVD_RegKey, "AudioNormalizeVal", .AudioNormalizeVal
        modReg.ScriviChiaveNumero AVStoDVD_RegKey, "AudioDelayAuto", -CInt(.AudioDelayAuto)
        
        modReg.ScriviChiaveStringa AVStoDVD_RegKey, "AudioLanguage", .AudioLanguage
        modReg.ScriviChiaveStringa AVStoDVD_RegKey, "AudioLanguage2", .AudioLanguage2
        modReg.ScriviChiaveStringa AVStoDVD_RegKey, "SubsLanguage", .SubsLanguage
        modReg.ScriviChiaveStringa AVStoDVD_RegKey, "SubsLanguage2", .SubsLanguage2
        With .SubsFont
            modReg.ScriviChiaveStringa AVStoDVD_RegKey, "SubsFontName", .Name
            modReg.ScriviChiaveNumero AVStoDVD_RegKey, "SubsFontHeight", .Height
            modReg.ScriviChiaveNumero AVStoDVD_RegKey, "SubsFontBold", -CInt(.Bold)
            modReg.ScriviChiaveNumero AVStoDVD_RegKey, "SubsFontItalic", -CInt(.Italic)
            modReg.ScriviChiaveNumero AVStoDVD_RegKey, "SubsFontColor", .Color
        End With
        With .SubsPos
            modReg.ScriviChiaveNumero AVStoDVD_RegKey, "SubsPosLeft", .Left
            modReg.ScriviChiaveNumero AVStoDVD_RegKey, "SubsPosBottom", .Bottom
            modReg.ScriviChiaveNumero AVStoDVD_RegKey, "SubsPosWidth", .Width
        End With
        modReg.ScriviChiaveStringa AVStoDVD_RegKey, "ChaptersInterval", .ChaptersInterval
        modReg.ScriviChiaveNumero AVStoDVD_RegKey, "ChaptersUseSource", -CInt(.ChaptersUseSource)
        modReg.ScriviChiaveStringa AVStoDVD_RegKey, "DVDBurningDrive", .DVDBurningDrive
        modReg.ScriviChiaveStringa AVStoDVD_RegKey, "DVDBurningSpeed", .DVDBurningSpeed
        modReg.ScriviChiaveNumero AVStoDVD_RegKey, "DVDAutoErase", -CInt(.DVDAutoErase)
        
        modReg.ScriviChiaveStringa AVStoDVD_RegKey, "SplashScreenName", .SplashScreenName
        modReg.ScriviChiaveNumero AVStoDVD_RegKey, "EncodingPriority", .EncodingPriority
        modReg.ScriviChiaveNumero AVStoDVD_RegKey, "EncodingWindowStyle", .EncodingWindowStyle
        modReg.ScriviChiaveNumero AVStoDVD_RegKey, "ForceRunAsAdmin", -CInt(.ForceRunAsAdmin)
        modReg.ScriviChiaveNumero AVStoDVD_RegKey, "UnloadDShow", -CInt(.UnloadDShow)
        modReg.ScriviChiaveNumero AVStoDVD_RegKey, "DSFiltersRuntime", -CInt(.DSFiltersRuntime)
        modReg.ScriviChiaveNumero AVStoDVD_RegKey, "SaveSettings", -CInt(.SaveSettings)
        
        modReg.ScriviChiaveStringa AVStoDVD_RegKey, "Language", .Language
        modReg.ScriviChiaveStringa AVStoDVD_RegKey, "Skin", .Skin
    
        sReg = ""
        If .ForceRunAsAdmin = True Then
            sReg = "RUNASADMIN"
        End If
        modReg.ScriviChiaveStringa "HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers", App.Path & "\" & App.EXEName & ".exe", sReg
    
        'DefaultCustomDVDSize, RecentProject1-5 and RecentTitle1-5 are stored during their runtime sections and they do not have a Preferences user-type variable
    
    End With

End Sub


Public Sub Reg_Preferences_Load()

    Dim PD As GeneralPreferences
    
    On Error Resume Next
    
    PD = PreferencesDefault
    
    With Preferences
        .MultiThread = CBool(modReg.EmiLeggiChiaveNumero(AVStoDVD_RegKey, "MultiThread", PD.MultiThread))
        
        .InputPath = modReg.EmiLeggiChiaveStringa(AVStoDVD_RegKey, "InputPath", PD.InputPath)
            If modFS.EsisteDir(.InputPath) = False Then .InputPath = PD.InputPath
        .OutputPath = modReg.EmiLeggiChiaveStringa(AVStoDVD_RegKey, "OutputPath", PD.OutputPath)
            If modFS.EsisteDir(.OutputPath) = False Then .OutputPath = PD.OutputPath
        .AssetsPath = modReg.EmiLeggiChiaveStringa(AVStoDVD_RegKey, "AssetsPath", PD.AssetsPath)
            If modFS.EsisteDir(.AssetsPath) = False Then .AssetsPath = PD.AssetsPath
        .ProjectsPath = modReg.EmiLeggiChiaveStringa(AVStoDVD_RegKey, "ProjectsPath", PD.ProjectsPath)
            If modFS.EsisteDir(.ProjectsPath) = False Then .ProjectsPath = PD.ProjectsPath
        .TempPath = modReg.EmiLeggiChiaveStringa(AVStoDVD_RegKey, "TempPath", PD.TempPath)
            If modFS.EsisteDir(.TempPath) = False Then .TempPath = PD.TempPath
        .MenuTemplatesPath = modReg.EmiLeggiChiaveStringa(AVStoDVD_RegKey, "MenuTemplatesPath", PD.MenuTemplatesPath)
        .PreviewerPathName = modReg.EmiLeggiChiaveStringa(AVStoDVD_RegKey, "PreviewerPathName", PD.PreviewerPathName)
    
        .AVSVideoInput = modReg.EmiLeggiChiaveStringa(AVStoDVD_RegKey, "AVSVideoInput", PD.AVSVideoInput)
        .AVSAudioInput = modReg.EmiLeggiChiaveStringa(AVStoDVD_RegKey, "AVSAudioInput", PD.AVSAudioInput)
        .AVSUpSize = modReg.EmiLeggiChiaveStringa(AVStoDVD_RegKey, "AVSUpSize", PD.AVSUpSize)
        .AVSDownSize = modReg.EmiLeggiChiaveStringa(AVStoDVD_RegKey, "AVSDownSize", PD.AVSDownSize)
        .FrameAdjust = modReg.EmiLeggiChiaveNumero(AVStoDVD_RegKey, "FrameAdjust", PD.FrameAdjust)
        .FPSHardConversion = modReg.EmiLeggiChiaveNumero(AVStoDVD_RegKey, "FPSHardConversion", PD.FPSHardConversion)
        .PALSpeedUp = CBool(modReg.EmiLeggiChiaveNumero(AVStoDVD_RegKey, "PALSpeedUp", PD.PALSpeedUp))
        .NTSCSlowDown = CBool(modReg.EmiLeggiChiaveNumero(AVStoDVD_RegKey, "NTSCSlowDown", PD.NTSCSlowDown))
        
        .KeepOrigVideo = CBool(modReg.EmiLeggiChiaveNumero(AVStoDVD_RegKey, "KeepOrigVideo", PD.KeepOrigVideo))
        .VideoStandard = modReg.EmiLeggiChiaveNumero(AVStoDVD_RegKey, "VideoStandard", PD.VideoStandard)
        .VideoEncoder = modReg.EmiLeggiChiaveNumero(AVStoDVD_RegKey, "VideoEncoder", PD.VideoEncoder)
        .VideoProfileLevel1 = modReg.EmiLeggiChiaveStringa(AVStoDVD_RegKey, "VideoProfileLevel1", PD.VideoProfileLevel1)
            If .VideoProfileLevel1 = "" Then .VideoProfileLevel1 = PD.VideoProfileLevel1
        .VideoProfileLevel2 = modReg.EmiLeggiChiaveStringa(AVStoDVD_RegKey, "VideoProfileLevel2", PD.VideoProfileLevel2)
            If .VideoProfileLevel2 = "" Then .VideoProfileLevel1 = PD.VideoProfileLevel2
        .VideoResolution = modReg.EmiLeggiChiaveNumero(AVStoDVD_RegKey, "VideoResolution", PD.VideoResolution)
        .VideoFFmpegHQ = CBool(modReg.EmiLeggiChiaveNumero(AVStoDVD_RegKey, "VideoFFmpegHQ", PD.VideoFFmpegHQ))
        .VideoFFmpegHQCmd = modReg.EmiLeggiChiaveStringa(AVStoDVD_RegKey, "VideoFFmpegHQCmd", PD.VideoFFmpegHQCmd)
        .VideoMinAvgBitRate = modReg.EmiLeggiChiaveStringa(AVStoDVD_RegKey, "VideoMinAvgBitRate", PD.VideoMinAvgBitRate)
        .VideoMaxAvgBitRate = modReg.EmiLeggiChiaveStringa(AVStoDVD_RegKey, "VideoMaxAvgBitRate", PD.VideoMaxAvgBitRate)
        .VideoMaxBitRate = modReg.EmiLeggiChiaveStringa(AVStoDVD_RegKey, "VideoMaxBitRate", PD.VideoMaxBitRate)
        
        .KeepOrigAudio = CBool(Val(modReg.EmiLeggiChiaveNumero(AVStoDVD_RegKey, "KeepOrigAudio", PD.KeepOrigAudio)))
        .AC3AudioEncoder = modReg.EmiLeggiChiaveNumero(AVStoDVD_RegKey, "AC3AudioEncoder", PD.AC3AudioEncoder)
        .ForceFFmpeg4GB = CBool(modReg.EmiLeggiChiaveNumero(AVStoDVD_RegKey, "ForceFFmpeg4GB", PD.ForceFFmpeg4GB))
        .AudioFormat = modReg.EmiLeggiChiaveNumero(AVStoDVD_RegKey, "AudioFormat", PD.AudioFormat)
        .AudioBitRate = modReg.EmiLeggiChiaveStringa(AVStoDVD_RegKey, "AudioBitRate", PD.AudioBitRate)
        .AudioNormalize = CBool(modReg.EmiLeggiChiaveNumero(AVStoDVD_RegKey, "AudioNormalize", PD.AudioNormalize))
        .AudioNormalizeVal = modReg.EmiLeggiChiaveStringa(AVStoDVD_RegKey, "AudioNormalizeVal", PD.AudioNormalizeVal)
        .AudioDelayAuto = CBool(modReg.EmiLeggiChiaveNumero(AVStoDVD_RegKey, "AudioDelayAuto", PD.AudioDelayAuto))
    
        .AudioLanguage = modReg.EmiLeggiChiaveStringa(AVStoDVD_RegKey, "AudioLanguage", PD.AudioLanguage)
        .AudioLanguage2 = modReg.EmiLeggiChiaveStringa(AVStoDVD_RegKey, "AudioLanguage2", PD.AudioLanguage2)
        .SubsLanguage = modReg.EmiLeggiChiaveStringa(AVStoDVD_RegKey, "SubsLanguage", PD.SubsLanguage)
        .SubsLanguage2 = modReg.EmiLeggiChiaveStringa(AVStoDVD_RegKey, "SubsLanguage2", PD.SubsLanguage2)
        With .SubsFont
            .Name = modReg.EmiLeggiChiaveStringa(AVStoDVD_RegKey, "SubsFontName", PD.SubsFont.Name)
            .Height = modReg.EmiLeggiChiaveNumero(AVStoDVD_RegKey, "SubsFontHeight", PD.SubsFont.Height)
            .Bold = CBool(modReg.EmiLeggiChiaveNumero(AVStoDVD_RegKey, "SubsFontBold", PD.SubsFont.Bold))
            .Italic = CBool(modReg.EmiLeggiChiaveNumero(AVStoDVD_RegKey, "SubsFontItalic", PD.SubsFont.Italic))
            .Color = modReg.EmiLeggiChiaveNumero(AVStoDVD_RegKey, "SubsFontColor", PD.SubsFont.Color)
        End With
        With .SubsPos
            .Left = modReg.EmiLeggiChiaveNumero(AVStoDVD_RegKey, "SubsPosLeft", PD.SubsPos.Left)
            .Bottom = modReg.EmiLeggiChiaveNumero(AVStoDVD_RegKey, "SubsPosBottom", PD.SubsPos.Bottom)
            .Width = modReg.EmiLeggiChiaveNumero(AVStoDVD_RegKey, "SubsPosWidth", PD.SubsPos.Width)
        End With
        .ChaptersInterval = modReg.EmiLeggiChiaveStringa(AVStoDVD_RegKey, "ChaptersInterval", PD.ChaptersInterval)
        .ChaptersUseSource = CBool(modReg.EmiLeggiChiaveNumero(AVStoDVD_RegKey, "ChaptersUseSource", PD.ChaptersUseSource))
        .DVDBurningDrive = modReg.EmiLeggiChiaveStringa(AVStoDVD_RegKey, "DVDBurningDrive", PD.DVDBurningDrive)
        .DVDBurningSpeed = modReg.EmiLeggiChiaveStringa(AVStoDVD_RegKey, "DVDBurningSpeed", PD.DVDBurningSpeed)
        .DVDAutoErase = CBool(modReg.EmiLeggiChiaveNumero(AVStoDVD_RegKey, "DVDAutoErase", PD.DVDAutoErase))
    
        .SplashScreenName = modReg.EmiLeggiChiaveStringa(AVStoDVD_RegKey, "SplashScreenName", PD.SplashScreenName)
        .EncodingPriority = modReg.EmiLeggiChiaveNumero(AVStoDVD_RegKey, "EncodingPriority", PD.EncodingPriority)
        .EncodingWindowStyle = modReg.EmiLeggiChiaveNumero(AVStoDVD_RegKey, "EncodingWindowStyle", PD.EncodingWindowStyle)
        .ForceRunAsAdmin = CBool(modReg.EmiLeggiChiaveNumero(AVStoDVD_RegKey, "ForceRunAsAdmin", PD.ForceRunAsAdmin))
        .UnloadDShow = CBool(modReg.EmiLeggiChiaveNumero(AVStoDVD_RegKey, "UnloadDShow", PD.UnloadDShow))
        .DSFiltersRuntime = CBool(modReg.EmiLeggiChiaveNumero(AVStoDVD_RegKey, "ffdshowRuntime", PD.DSFiltersRuntime))    'for retro-compatibility (up to 2.7.5)
        .DSFiltersRuntime = CBool(modReg.EmiLeggiChiaveNumero(AVStoDVD_RegKey, "DSFiltersRuntime", PD.DSFiltersRuntime))
        .SaveSettings = CBool(modReg.EmiLeggiChiaveNumero(AVStoDVD_RegKey, "SaveSettings", PD.SaveSettings))
        
        .Language = modReg.EmiLeggiChiaveStringa(AVStoDVD_RegKey, "Language", PD.Language)
        .Skin = modReg.EmiLeggiChiaveStringa(AVStoDVD_RegKey, "Skin", PD.Skin)
        
        ' Debug
        .FFmpegDemuxMatroska = CBool(modReg.EmiLeggiChiaveNumero(AVStoDVD_RegKey & "\Debug", "FFmpegDemuxMatroska", PD.FFmpegDemuxMatroska))
        .SlowSystemFlag = CBool(modReg.EmiLeggiChiaveNumero(AVStoDVD_RegKey & "\Debug", "SlowSystemFlag", PD.SlowSystemFlag))
    End With

End Sub


Public Sub Reset_Project()

    Dim DVDMenuNull As MenuSettings
    Dim jj As Integer

    On Error Resume Next
    
    ' Initialize public variables
    VideoStandard = Preferences.VideoStandard
    DiscSize = modReg.EmiLeggiChiaveNumero(AVStoDVD_RegKey, "DefaultDVDSize", DVD5)
    OutputSetup = modReg.EmiLeggiChiaveNumero(AVStoDVD_RegKey, "DefaultOutputSetup", DVD_Folder)
    NumTitles = 0
    CurrentTitle = 0
    CurrentAudioTrack = 0
    Erase Title
    DVDMenu = DVDMenuNull
    
    ' Initialize frmMain
    With frmMain
        .Caption = "AVStoDVD"
        .Int_EditEncoderParams.value = modReg.EmiLeggiChiaveNumero(AVStoDVD_RegKey, "DefaultEditEncoderParams", 0)
        .Int_FrameServingCheck.value = modReg.EmiLeggiChiaveNumero(AVStoDVD_RegKey, "DefaultFrameServingCheck", 0)
        .intDeleteAssets.value = modReg.EmiLeggiChiaveNumero(AVStoDVD_RegKey, "DefaultDeleteAssets", 1)
        .intDeleteWorking.value = modReg.EmiLeggiChiaveNumero(AVStoDVD_RegKey, "DefaultDeleteWorking", 1)
        .Txt_DVD_Label.Text = "DVD"
        jj = modReg.EmiLeggiChiaveNumero(AVStoDVD_RegKey, "DefaultPostProcess", 0)
        If jj < 0 Or jj > .Cmb_PostProcess.ListCount - 1 Then
            .Cmb_PostProcess.ListIndex = 0
        Else
            .Cmb_PostProcess.ListIndex = jj
        End If
        .Txt_Estimated_Output_Size.Text = ""
        .Txt_Path_Output.Text = Preferences.OutputPath
        .lViewOper.Tag = ""
        .ProgressBar.value = 0
        With .StatusBar
            .Panels("Video_Standard").Text = IIf(VideoStandard = PAL, "PAL", "NTSC")
            .Panels("DVD_Time").Text = VisualTime(0)
        End With
    End With
    With frmJobsList
        .JobsList.Tag = ""
    End With
    modMain.Change_Titles
    modMain.Change_Settings
    
    ' Initialize remaining public variables
    ChangeFlag = False
    
End Sub


Public Sub Initialize_Title(Title As TitleSettings, Video As Boolean, Audio As Boolean, Subs As Boolean, AVS As Boolean, Chapters As Boolean)

    Dim jj As Integer
    Dim InputFPS As Single
    Dim bFlag As Boolean

    With Title
        
        .FPS = 25
        If VideoStandard = NTSC Then
            .FPS = 2997 / 100
        End If
        
        InputFPS = Val(.InputVideoInfo.FPS)
        If InputFPS = 0 Then
            InputFPS = .FPS
        End If
        If .TitleName = "" Then
            .TitleName = modFS.NameOf(.InputVideoPathName)
        End If
        
        If Video = True Then
            .VideoAutoSetup = True
            .VideoAutoBitRate = True
            ' Define Video Resolution and if Video is to be kept
            .VideoIsToBeKept = False
            If Preferences.VideoResolution = Auto Then
                .VideoResolution = Full_D1
                If Val(.InputVideoInfo.Width) <= 352 Then
                    .VideoResolution = Half_D1
                    If VideoStandard = PAL And Val(.InputVideoInfo.Height) <= 288 Then
                        .VideoResolution = VCD
                    ElseIf VideoStandard = NTSC And Val(.InputVideoInfo.Height) <= 240 Then
                        .VideoResolution = VCD
                    End If
                End If
            Else
                .VideoResolution = Preferences.VideoResolution
            End If
            If Preferences.KeepOrigVideo = True Then
                Select Case VideoStandard
                Case PAL
                    Select Case .InputVideoInfo.DVDCompliant
                    Case PAL_Full_D1
                        .VideoIsToBeKept = True
                        .VideoResolution = Full_D1
                    Case PAL_Half_D1
                        .VideoIsToBeKept = True
                        .VideoResolution = Half_D1
                    Case PAL_VCD
                        .VideoIsToBeKept = True
                        .VideoResolution = VCD
                    End Select
                Case NTSC
                    Select Case .InputVideoInfo.DVDCompliant
                    Case NTSC_Full_D1
                        .VideoIsToBeKept = True
                        .VideoResolution = Full_D1
                    Case NTSC_Half_D1
                        .VideoIsToBeKept = True
                        .VideoResolution = Half_D1
                    Case NTSC_VCD
                        .VideoIsToBeKept = True
                        .VideoResolution = VCD
                    End Select
                End Select
            End If
            ' Define Video Encoder
            'If .VideoAutoSetup = True Then
            '    Select Case Preferences.VideoEncoder
            '    Case SmartSelection
            '        Select Case Val(.VideoBitRate)
            '        Case Is <= Val(Preferences.VideoProfileLevel2)
            '            .VideoEncoder = HCencVBR2pass
            '        Case Is <= Val(Preferences.VideoProfileLevel1)
            '            .VideoEncoder = HCencVBR1pass
            '        Case Else
            '            .VideoEncoder = FFMpegCBR1pass
            '        End Select
            '    Case Else
            '        .VideoEncoder = Preferences.VideoEncoder
            '    End Select
            'End If
            ' Define Video Aspect Ratio
            .VideoAspectRatio = Standard
            ' Define Video Adv Options
            If Val(.InputVideoInfo.DAR) > 1.75 Then
                .VideoAspectRatio = Widescreen
            End If
            With .VideoHCenc
                .AQ = modReg.EmiLeggiChiaveStringa(AVStoDVD_RegKey, "DefaultHCencAQ", "1")
                .Lumgain = modReg.EmiLeggiChiaveStringa(AVStoDVD_RegKey, "DefaultHCencLumGain", "1")
                .Matrix = modReg.EmiLeggiChiaveStringa(AVStoDVD_RegKey, "DefaultHCencMatrix", "AUTO")
                .Profile = modReg.EmiLeggiChiaveStringa(AVStoDVD_RegKey, "DefaultHCencProfile", "BEST")
                .Bias = modReg.EmiLeggiChiaveStringa(AVStoDVD_RegKey, "DefaultHCencBias", "AUTO")
                .DCPrec = modReg.EmiLeggiChiaveStringa(AVStoDVD_RegKey, "DefaultHCencDCPrec", "AUTO")
                .Zone = ""
            End With
            ' Define DVSource, Interlaced encoding, Field order, GOPs
            .VideoDVSource = False
            If InStr(1, .InputVideoInfo.Compression, "DV") <> 0 And Val(.InputVideoInfo.AvgBitRate) / 1000 > 20000 Then
                Select Case VideoStandard
                Case PAL
                    If Val(.InputVideoInfo.FPS) = 25 And .InputVideoInfo.Width = "720" And .InputVideoInfo.Height = "576" Then
                        .VideoDVSource = True
                    End If
                Case NTSC
                    If Val(.InputVideoInfo.FPS) = 2997 / 100 And .InputVideoInfo.Width = "720" And .InputVideoInfo.Height = "480" Then
                        .VideoDVSource = True
                    End If
                End Select
            End If
            If .VideoDVSource = True Then
                .VideoInterlacedEncoding = True
                .VideoFieldOrder = "BFF"
            Else
                .VideoInterlacedEncoding = .InputVideoInfo.Interlaced
                If .AVSIVTC = True Then .VideoInterlacedEncoding = False
                .VideoFieldOrder = "TFF"
                If UCase(.InputVideoInfo.ScanOrder) = "BFF" Then
                    .VideoFieldOrder = "BFF"
                End If
            End If
            .VideoCloseAllGOPs = False
            
            ' Video bitrate is defined in dedicate bitrate routine
            
            ' Define FPSAdjust strategy
            .VideoFPSAdjust = HardConversion
            'If .InputVideoInfo.FrameRateMode <> "VFR" Then
                Select Case Round(InputFPS - .FPS, 3)
                Case Is > 0
                    If InputFPS = 2 * .FPS Then
                        .VideoFPSAdjust = SelectEven
                    End If
                Case Is < 0
                    If .InputVideoInfo.Interlaced = False Or .AVSDeInterlace = True Then
                        Select Case InputFPS
                        Case 23.976, 24, 25, 29.97, 30, 50, 59.94, 60    'only these fps are mpeg2 compliant (30, 50, 59.94, 60 will not be tested)
                            .VideoFPSAdjust = PullDown
                        End Select
                        If Preferences.PALSpeedUp = True And .FPS = 25 Then
                            If InputFPS = 24 Or InputFPS = 23.976 Then
                                .VideoFPSAdjust = PALSpeedUp
                            End If
                        End If
                        If Preferences.NTSCSlowDown = True And .FPS = 29.97 And InputFPS = 25 Then
                            .VideoFPSAdjust = NTSCSlowDown
                        End If
                    End If
                Case Else
                    .VideoFPSAdjust = NoConversion
                End Select
            'End If
            
        End If
        
        If Audio = True Then
            jj = 1
            Do Until .InputAudioPathName(jj) = ""
                .AudioAutoSetup(jj) = True
                ' Define if Audio is to be kept
                .AudioIsToBeKept(jj) = False
                If Preferences.KeepOrigAudio = True Then
                    .AudioIsToBeKept(jj) = CBool(.InputAudioInfo(jj).DVDCompliant)
                End If
                ' Force Audio re-encoding if PALSpeedUp/NTSCSlowDown is on
                bFlag = False
                If Preferences.PALSpeedUp = True And .FPS = 25 Then
                    If InputFPS = 24 Or InputFPS = 23.976 Then
                        bFlag = True
                    End If
                End If
                If Preferences.NTSCSlowDown = True And .FPS = 29.97 And InputFPS = 25 Then
                    bFlag = True
                End If
                If bFlag = True Then .AudioIsToBeKept(jj) = False
                ' Define AudioFormat
                If .AudioIsToBeKept(jj) = True Then
                    Select Case .InputAudioInfo(jj).DVDCompliant
                    Case AC3_Compl
                        .AudioFormat(jj) = AC3
                    Case MP2_Compl
                        .AudioFormat(jj) = MP2
                    Case WAV_Compl
                        .AudioFormat(jj) = WAV
                    Case DTS_Compl
                        .AudioFormat(jj) = DTS
                    End Select
                Else
                    If .AudioAutoSetup(jj) = True Then
                        .AudioFormat(jj) = Preferences.AudioFormat
                    End If
                End If
                With .AudioAften(jj)
                    .Pad = "0"
                    .DRC = "5"
                    .BWFilter = "0"
                End With
                .AudioChannelsMode(jj) = "2.0"
                If IsNumeric(.InputAudioInfo(jj).Channels) = True Then
                    Select Case Val(.InputAudioInfo(jj).Channels)
                    Case Is > 5
                        .AudioChannelsMode(jj) = "5.1"
                    Case 5
                        .AudioChannelsMode(jj) = "5.0"
                    Case 1
                        .AudioChannelsMode(jj) = "1.0"
                    End Select
                End If
                If jj = 1 Then
                    .AudioLanguage(jj) = Preferences.AudioLanguage
                Else
                    .AudioLanguage(jj) = Preferences.AudioLanguage2
                End If
                .AudioNormalize(jj) = Preferences.AudioNormalize
                .AudioDelayAuto(jj) = Preferences.AudioDelayAuto
                .AudioFixAC3(jj) = False
                If UCase(.InputAudioInfo(jj).Compression) = "AC3" Then
                    If .InputVideoPathName = .InputAudioPathName(jj) Then
                        .AudioFixAC3(jj) = True
                    End If
                End If
                jj = jj + 1
                If jj > MaxAudioTracks Then Exit Do
            Loop
            ' Audio bitrate is defined in dedicate bitrate routine
        End If
        
        If Subs = True Then
            jj = 1
            Do Until .InputSubsPathName(jj) = ""
                .SubsAutoSetup(jj) = True
                If jj = 1 Then
                    .SubsLanguage(jj) = Preferences.SubsLanguage
                Else
                    .SubsLanguage(jj) = Preferences.SubsLanguage2
                End If
                .SubsExtension(jj) = 1
                .SubsHardEncode(jj) = False
                .SubsFix(jj) = True
                jj = jj + 1
                If jj > MaxSubsTracks Then Exit Do
            Loop
        End If
        
        If AVS = True Then
            .AVSAutoSetup = True
            .AVSCrop = False
            .AVSVerticalResize = False
            .AVSDeInterlace = False
            .AVSTrim = False
            .AVSInfo = False
            .AVSTweak = False
            .AVSSharpen = False
            .AVSDelayAudio = False
            .AVSAmplifyAudio = False
            .AVSFadeIO = False
            .AVSColorMatrix = False
            If .InputVideoInfo.ColorCoefficients = "BT.709" Then
                .AVSColorMatrix = True
            End If
            .AVSMSharpen = False
            .AVSHQDN3D = False
            .AVSDeBlock = False
            .AVSIVTC = False
            .AVS.CropDx = 0
            .AVS.CropSx = 0
            .AVS.CropUp = 0
            .AVS.VResize = 100
            .AVS.DeIntThreshold = 10
            .AVS.FrameStart = 0
            Select Case .VideoFPSAdjust
            Case HardConversion, SelectEven
                If InStr(1, LCase(.InputVideoInfo.ScanOrder), "pulldown") = 0 Then
                    .AVS.FrameEnd = Int(Val(.InputVideoInfo.FrameCount) / InputFPS * .FPS)
                Else
                    .AVS.FrameEnd = Int(Val(.InputVideoInfo.FrameCount))
                End If
            Case Else
                .AVS.FrameEnd = Int(Val(.InputVideoInfo.FrameCount))
            End Select
            .AVS.Hue = 0
            .AVS.Saturation = 1
            .AVS.Brightness = 0
            .AVS.Contrast = 1
            .AVS.Sharpness = 0
            .AVS.AudioDelay = 0
            .AVS.AudioAmplify = 1
            .AVS.FadeIOFrames = 0
            .AVS.ColorMatrixSource = 0
            .AVS.ColorMatrixDest = 2
            .AVS.MSharpenThreshold = 10
            .AVS.MSharpenStrength = 100
            .AVS.HQDN3DStrength = 0
            .AVS.DeBlock = 25
            .AVSAutoScript = modAVS.Create_AVSScript(Title)
            .AVSScript = .AVSAutoScript
        End If
        
        ' Define FPSAVS, TimeTotal and TimeTrimmed
        .FPSAVS = .FPS
        .TimeTotal = Round(Val(.InputGeneralInfo.Time) / 1000)
        Select Case .VideoFPSAdjust
        Case PullDown
            Select Case LCase(.InputVideoInfo.ScanOrder)
            Case "2:2:2:2:2:2:2:2:2:2:2:3 pulldown"
                .FPSAVS = 25
            Case "2:3 pulldown"
                .FPSAVS = 29.97
            Case Else
                .FPSAVS = InputFPS   'can be only 23.976, 24, 25
            End Select
        Case PALSpeedUp
            .TimeTotal = Round(Val(.InputGeneralInfo.Time) / 1000 * 23.976 / 25)
        Case NTSCSlowDown
            .FPSAVS = 23.976
            .TimeTotal = Round(Val(.InputGeneralInfo.Time) / 1000 * 25 / 23.976)
        End Select
        If .AVSTrim = True Then
            .TimeTrimmed = (.AVS.FrameEnd - .AVS.FrameStart) / .FPSAVS
        Else
            .TimeTrimmed = .TimeTotal
        End If
        
        If Chapters = True Then
            .ChaptersAutoSetup = True
            .ChaptersList = modMain.Create_Chapters_List(Title)
        End If
        
    End With

End Sub


Public Sub Load_Skin()

    Dim jj As Integer
    Dim PathSkinIni As String
    Dim NumFile As Integer
    Dim StrSkinIni As String
    Dim IconFileName As Collection
    
    On Error GoTo Err_Handling
    
    Screen.MousePointer = vbHourglass
    
    Skin.Path = App.Path & "\Skins\" & Preferences.Skin
    If modFS.EsisteDir(Skin.Path) = False Then
        Skin.Path = App.Path & "\Skins\Default"
    End If

    With frmMain
        ' Load Text settings
        NumFile = FreeFile
        PathSkinIni = Skin.Path & "\Skin.ini"
        If modFS.EsisteFile(PathSkinIni) = False Then
            PathSkinIni = App.Path & "\Skins\Default\Skin.ini"
        End If
        Open PathSkinIni For Input As #NumFile
            Do
                StrSkinIni = StrSkinIni & Input(1, #NumFile)
            Loop Until UCase(Right(StrSkinIni, 7)) = "UPDATED" Or EOF(NumFile) = True
        Close #NumFile
        ' Set Foregroud settings
        Skin.ForeRed = Load_Str_Object(StrSkinIni, "Red", "0")
        Skin.ForeGreen = Load_Str_Object(StrSkinIni, "Green", "0")
        Skin.ForeBlue = Load_Str_Object(StrSkinIni, "Blue", "0")
        Skin.Font = Load_Str_Object(StrSkinIni, "Font", "Tahoma")
        Call modMain.Load_Skin_Font(frmMain)
        
        ' Initialize ImageList(s)
        Set .Toolbar.ImageList = Nothing
        Set .TitlesTreeView.ImageList = Nothing
        Set .lViewOper.SmallIcons = Nothing
        .ImageList60.ListImages.Clear
        .ImageList32.ListImages.Clear
        .ImageList16.ListImages.Clear
                
        ' Populate Imagelists
        If modFS.EsisteFile(Skin.Path & "\Icons.dll") = True Then
            modEnumResIcons.GetIconsFromLibrary Skin.Path & "\Icons.dll", .ImageList16, 16    '32 16x16 icons
            modEnumResIcons.GetIconsFromLibrary Skin.Path & "\Icons.dll", .ImageList32, 32    '43 32x32 icons
            modEnumResIcons.GetIconsFromLibrary Skin.Path & "\Icons.dll", .ImageList60, 60    '2  60x60 icons
        End If
        
        ' Backup with .ico
        If .ImageList16.ListImages.Count = 0 Or .ImageList32.ListImages.Count = 0 Or .ImageList60.ListImages.Count = 0 Then
            Set IconFileName = New Collection
            Set IconFileName = modFS.FileList(Skin.Path, "*.ico")
            If IconFileName.Count = 0 Then
                If MsgBox("Warning! Problems found during Skin Icons loading! AVStoDVD will try to extract the ico files." & vbCrLf & vbCrLf & "Do you want to continue?", vbQuestion + vbYesNo, App.Title) = vbYes Then
                    If modZip.UnZipFile(Skin.Path & "\Icons.zip", Skin.Path) = True Then
                        Set IconFileName = Nothing
                        Set IconFileName = modFS.FileList(Skin.Path, "*.ico")
                    End If
                End If
            End If
            If IconFileName.Count = 0 Then
                MsgBox "Warning! Errors found during Skin Icons loading!" & vbCrLf & vbCrLf & "Default AVStoDVD icon will be used." & vbCrLf & vbCrLf & "See Help/FAQ/GUI/Q2.6 for more details.", vbCritical, App.Title
                With .ImageList60.ListImages
                    .Clear
                    For jj = 1 To 2
                        .add .Count + 1, , modMain.Load_Skin_Icon(App.Path & "\AVStoDVD.ico")
                    Next jj
                End With
                With .ImageList32.ListImages
                    .Clear
                    For jj = 1 To 43
                        .add .Count + 1, , modMain.Load_Skin_Icon(App.Path & "\AVStoDVD.ico")
                    Next jj
                End With
                With .ImageList16.ListImages
                    .Clear
                    For jj = 1 To 32
                        .add .Count + 1, , modMain.Load_Skin_Icon(App.Path & "\AVStoDVD.ico")
                    Next jj
                End With
            Else
                For jj = 1 To IconFileName.Count
                    With .ImageList60.ListImages
                        If InStr(1, IconFileName.Item(jj), "A2D_60_") <> 0 Then
                            .add .Count + 1, IconFileName.Item(jj), modMain.Load_Skin_Icon(Skin.Path & "\" & IconFileName.Item(jj))
                        End If
                    End With
                    With .ImageList32.ListImages
                        If InStr(1, IconFileName.Item(jj), "A2D_32_") <> 0 Then
                            .add .Count + 1, IconFileName.Item(jj), modMain.Load_Skin_Icon(Skin.Path & "\" & IconFileName.Item(jj))
                        End If
                    End With
                    With .ImageList16.ListImages
                        If InStr(1, IconFileName.Item(jj), "A2D_16_") <> 0 Then
                            .add .Count + 1, IconFileName.Item(jj), modMain.Load_Skin_Icon(Skin.Path & "\" & IconFileName.Item(jj))
                        End If
                    End With
                Next jj
            End If
            Set IconFileName = Nothing
        End If
        
        ' Toolbar
        Set .Toolbar.ImageList = .ImageList32
        With .Toolbar
            .Buttons(2).Image = 1
            .Buttons(3).Image = 2
            .Buttons(4).Image = 3
            .Buttons(6).Image = 4
            .Buttons(7).Image = 5
            .Buttons(9).Image = 30
            .Buttons(11).Image = 36
            .Buttons(13).Image = 7
            .Buttons(15).Image = 6
            .Buttons(17).Image = 8
        End With
        
        ' TreeView
        Set .TitlesTreeView.ImageList = .ImageList16
        
        ' ListView
        Set .lViewOper.SmallIcons = .ImageList16
        modMain.Save_Log_Video "", True
            
        ' Statusbar
        With .StatusBar
            .Panels(1).Picture = frmMain.ImageList16.ListImages(1).Picture
            .Panels(2).Picture = frmMain.ImageList16.ListImages(2).Picture
            .Panels(3).Picture = frmMain.ImageList16.ListImages(3).Picture
            .Panels(4).Picture = frmMain.ImageList16.ListImages(4).Picture
            .Panels(5).Picture = frmMain.ImageList16.ListImages(26).Picture
            .Panels(6).Picture = frmMain.ImageList16.ListImages(5).Picture
        End With
        
        ' Main Form Buttons
        .Pls_Add_Title.Caption = ""
        .Pls_Add_Title.Picture = .ImageList32.ListImages(9).Picture
        .Img_Add_Title.Picture = .Pls_Add_Title.Picture
        .Pls_Edit_Title.Caption = ""
        .Pls_Edit_Title.Picture = .ImageList32.ListImages(10).Picture
        .Img_Edit_Title.Picture = .ImageList32.ListImages(11).Picture
        .Pls_Del_Title.Caption = ""
        .Pls_Del_Title.Picture = .ImageList32.ListImages(12).Picture
        .Img_Del_Title.Picture = .ImageList32.ListImages(13).Picture
        .Pls_Preview_Title.Caption = ""
        .Pls_Preview_Title.Picture = .ImageList32.ListImages(14).Picture
        .Img_Preview_Title.Picture = .ImageList32.ListImages(15).Picture
        .Pls_Path_Output.Caption = ""
        .Pls_Path_Output.Picture = .ImageList16.ListImages(11).Picture
        .Img_Path_Output.Picture = .Pls_Path_Output.Picture
        .Pls_Start.Caption = ""
        .Pls_Start.Picture = .ImageList60.ListImages(1).Picture
        .Img_Start.Picture = .ImageList60.ListImages(2).Picture
        
    End With
    
    ' JobsList Form Buttons
    With frmJobsList
        .Pls_Add_Job.Caption = ""
        .Pls_Add_Job.Picture = frmMain.ImageList16.ListImages(12).Picture
        .Img_Add_Job.Picture = .Pls_Add_Job.Picture
        .Pls_Remove_Job.Caption = ""
        .Pls_Remove_Job.Picture = frmMain.ImageList16.ListImages(14).Picture
        .Img_Remove_Job.Picture = .Pls_Remove_Job.Picture
        .Pls_Move_Up.Caption = ""
        .Pls_Move_Up.Picture = frmMain.ImageList16.ListImages(13).Picture
        .Img_Move_Up.Picture = .Pls_Move_Up.Picture
        .Pls_Erase_List.Caption = ""
        .Pls_Erase_List.Picture = frmMain.ImageList16.ListImages(15).Picture
        .Img_Erase_List.Picture = .Pls_Erase_List.Picture
        .Pls_Save_List.Caption = ""
        .Pls_Save_List.Picture = frmMain.ImageList16.ListImages(23).Picture
        .Img_Save_List.Picture = .Pls_Save_List.Picture
        .Pls_Load_List.Caption = ""
        .Pls_Load_List.Picture = frmMain.ImageList16.ListImages(24).Picture
        .Img_Load_List.Picture = .Pls_Load_List.Picture
        .Pls_Batch_Start.Caption = ""
        .Pls_Batch_Start.Picture = frmMain.ImageList16.ListImages(16).Picture
        .Img_Batch_Start.Picture = .Pls_Batch_Start.Picture
    End With
    
    GoTo Exit_Handling
    
Err_Handling:
Select Case Err.Number
Case 9999 'debug purpose
    Resume
End Select
Set IconFileName = Nothing

Exit_Handling:
Screen.MousePointer = vbDefault
    
End Sub


Public Sub Load_Skin_Font(frm As Form)

    Dim ctr As Control
    Dim jj As Integer
    Dim FC As Long
    
    On Error GoTo Err_Handling
    
    FC = RGB(CInt(Skin.ForeRed), CInt(Skin.ForeGreen), CInt(Skin.ForeBlue))
    With frm
        For Each ctr In .Controls
            Select Case UCase(Left(ctr.Name, 3))
            Case "PLS", "TXT", "CMB"
                .Controls(ctr.Name).Font.Name = Skin.Font
            Case "COR", "INT", "LBL"
                .Controls(ctr.Name).ForeColor = FC
                .Controls(ctr.Name).Font.Name = Skin.Font
            Case "OPT"
                For jj = .Controls(ctr.Name).LBound To .Controls(ctr.Name).UBound
                    .Controls(ctr.Name).Item(jj).ForeColor = FC
                    .Controls(ctr.Name).Item(jj).Font.Name = Skin.Font
                Next jj
            End Select
            If InStr(1, UCase(ctr.Name), "PROGRESSBAR") <> 0 Then
                modUtil.ProgBarForeColor ctr.hwnd, FC
            End If
        Next ctr
    End With
    
    Exit Sub

Err_Handling:
Select Case Err.Number
Case 438 'Proprietà o metodo non supportati dall'oggetto
    Resume Next
End Select

End Sub


Public Function Load_Skin_Icon(IconPathName As String) As Picture

    On Error GoTo Err_Handling
    
    If modFS.EsisteFile(IconPathName) = True Then
        Set Load_Skin_Icon = LoadPicture(IconPathName)
    ElseIf modFS.EsisteFile(App.Path & "\Skins\Default\" & modFS.NameOf(IconPathName) & "." & modFS.ExtOf(IconPathName)) = True Then
        Set Load_Skin_Icon = LoadPicture(App.Path & "\Skins\Default\" & modFS.NameOf(IconPathName) & "." & modFS.ExtOf(IconPathName))
    Else
        GoTo Err_Handling
    End If
    
    Exit Function
    
Err_Handling:
Set Load_Skin_Icon = LoadPicture(App.Path & "\AVStoDVD.ico")
    
End Function


Public Function Load_Picture_AVStoDVD(PathName As String, Optional OnErrorPathName As String, Optional IsVideo As Boolean) As Picture

    Dim StrAVS As String
    
    On Error GoTo Err_Handling
    
    If modUtil.IsPicture(PathName) = True Then
        Set Load_Picture_AVStoDVD = LoadPicture(PathName)
    ElseIf IsVideo = True Then
        StrAVS = "LoadCPlugin(""" & App.Path & "\Lib\ffms2.dll""" & ")" & vbCrLf & _
                 "Import(""" & App.Path & "\Lib\A2DSource.avsi""" & ")" & vbCrLf & vbCrLf & _
                 "A2DVideoSource(""" & PathName & """)" & vbCrLf & _
                 "ConvertToYV12" & vbCrLf & _
                 "Trim(1,1)" & vbCrLf
        modStr.STRtoANSIFile StrAVS, Preferences.TempPath & "\Picture.avs"
        modShellEx.Execute App.Path & "\FFmpeg\ffmpeg.exe", "-i """ & Preferences.TempPath & "\Picture.avs""" & " -f rawvideo -threads " & SysInfo.ProcessorNumber & " -c:v bmp -r 1 -y -an """ & Preferences.TempPath & "\Picture.bmp""", SW_HIDE, True
        Set Load_Picture_AVStoDVD = LoadPicture(Preferences.TempPath & "\Picture.bmp")
    Else
        GoTo Err_Handling
    End If
    
    Exit Function
    
Err_Handling:
If OnErrorPathName = "" Then
    MsgBox "Warning! Image '" & PathName & "' cannot be found or is invalid!" & vbCrLf & vbCrLf & "AVStoDVD default image will be loaded.", vbExclamation, App.Title
    OnErrorPathName = AVStoDVD_Picture
End If
Set Load_Picture_AVStoDVD = LoadPicture(OnErrorPathName)

End Function


'Update main form on changing Project Settings
Public Sub Change_Settings()

    Dim jj As Integer
    Dim ctr As Control
    
    On Error Resume Next
        
    With frmMain
        'Changing Disc Size
        .Menu_Options_DVD_5.Checked = False
        .Menu_Options_DVD_9.Checked = False
        .Menu_Options_Custom_Size.Checked = False
        With .Toolbar.Buttons("DVD_Size")
            .ButtonMenus("DVD_5").Text = frmMain.Menu_Options_DVD_5.Caption
            .ButtonMenus("DVD_9").Text = frmMain.Menu_Options_DVD_9.Caption
            .ButtonMenus("Custom").Text = frmMain.Menu_Options_Custom_Size.Caption
        End With
        Select Case DiscSize
        Case DVD5
            .Menu_Options_DVD_5.Checked = True
            .Toolbar.Buttons("DVD_Size").ButtonMenus("DVD_5").Text = Chr(149) & "  " & .Toolbar.Buttons("DVD_Size").ButtonMenus("DVD_5").Text
            .Txt_Output_Size.Text = 4450
            .StatusBar.Panels("DVD_Size").Text = modStr.DefaultStr(Language("170021"), "DVD-5")
        Case DVD9
            .Menu_Options_DVD_9.Checked = True
            .Toolbar.Buttons("DVD_Size").ButtonMenus("DVD_9").Text = Chr(149) & "  " & .Toolbar.Buttons("DVD_Size").ButtonMenus("DVD_9").Text
            .Txt_Output_Size.Text = 8100
            .StatusBar.Panels("DVD_Size").Text = modStr.DefaultStr(Language("170022"), "DVD-9")
        Case Custom
            .Menu_Options_Custom_Size.Checked = True
            .Toolbar.Buttons("DVD_Size").ButtonMenus("Custom").Text = Chr(149) & "  " & .Toolbar.Buttons("DVD_Size").ButtonMenus("Custom").Text
            .Txt_Output_Size.Text = modReg.EmiLeggiChiaveStringa(AVStoDVD_RegKey, "DefaultCustomDVDSize", "2200")
            .StatusBar.Panels("DVD_Size").Text = modStr.DefaultStr(Language("170023"), "Custom")
        End Select
        .ProgressBar.Max = .Txt_Output_Size.Text
        
        'Changing Output Setup
        .Menu_Options_MPEG2_2.Checked = False
        .Menu_Options_MPEG2_1.Checked = False
        .Menu_Options_DVD_Folder.Checked = False
        .Menu_Options_ISO.Checked = False
        .Menu_Options_Burn_DVD.Checked = False
        With .Toolbar.Buttons("Output_Setup")
            .ButtonMenus("MPEG2_2").Text = frmMain.Menu_Options_MPEG2_2.Caption
            .ButtonMenus("MPEG2_1").Text = frmMain.Menu_Options_MPEG2_1.Caption
            .ButtonMenus("DVD_Folder").Text = frmMain.Menu_Options_DVD_Folder.Caption
            .ButtonMenus("ISO").Text = frmMain.Menu_Options_ISO.Caption
            .ButtonMenus("Burn_DVD").Text = frmMain.Menu_Options_Burn_DVD.Caption
        End With
        Select Case OutputSetup
        Case MPEG2_Streams
            .Menu_Options_MPEG2_2.Checked = True
            .Toolbar.Buttons("Output_Setup").ButtonMenus("MPEG2_2").Text = Chr(149) & "  " & .Toolbar.Buttons("Output_Setup").ButtonMenus("MPEG2_2").Text
            .StatusBar.Panels("Output_Setup").Text = modStr.DefaultStr(Language("170031"), "MPEG2 Streams")
        Case MPEG2_File
            .Menu_Options_MPEG2_1.Checked = True
            .Toolbar.Buttons("Output_Setup").ButtonMenus("MPEG2_1").Text = Chr(149) & "  " & .Toolbar.Buttons("Output_Setup").ButtonMenus("MPEG2_1").Text
            .StatusBar.Panels("Output_Setup").Text = modStr.DefaultStr(Language("170032"), "MPEG2 File")
        Case DVD_Folder
            .Menu_Options_DVD_Folder.Checked = True
            .Toolbar.Buttons("Output_Setup").ButtonMenus("DVD_Folder").Text = Chr(149) & "  " & .Toolbar.Buttons("Output_Setup").ButtonMenus("DVD_Folder").Text
            .StatusBar.Panels("Output_Setup").Text = modStr.DefaultStr(Language("170033"), "DVD Folder")
        Case ISO_UDF_Image
            .Menu_Options_ISO.Checked = True
            .Toolbar.Buttons("Output_Setup").ButtonMenus("ISO").Text = Chr(149) & "  " & .Toolbar.Buttons("Output_Setup").ButtonMenus("ISO").Text
            .StatusBar.Panels("Output_Setup").Text = modStr.DefaultStr(Language("170034"), "ISO UDF Image")
        Case Burn_DVD
            .Menu_Options_Burn_DVD.Checked = True
            .Toolbar.Buttons("Output_Setup").ButtonMenus("Burn_DVD").Text = Chr(149) & "  " & .Toolbar.Buttons("Output_Setup").ButtonMenus("Burn_DVD").Text
            .StatusBar.Panels("Output_Setup").Text = modStr.DefaultStr(Language("170035"), "Burn DVD")
        End Select
        
        ' Changing DVD Menu
        With .Toolbar.Buttons("DVD_Menu")
            .ButtonMenus("Wizard").Text = frmMain.Menu_Options_DVDMenu_Wizard.Caption
            .ButtonMenus("Editor").Text = frmMain.Menu_Options_DVDMenu_Editor.Caption
            .ButtonMenus("Reset").Text = frmMain.Menu_Options_DVDMenu_Reset.Caption
        End With
        .Menu_Options_DVDMenu_Editor.Enabled = DVDMenu.IsInit
        .Toolbar.Buttons("DVD_Menu").ButtonMenus("Editor").Enabled = DVDMenu.IsInit
        .StatusBar.Panels("DVD_Menu").Text = modStr.DefaultStr(Language("170051"), "Menu Disabled")
        If DVDMenu.IsInit = True Then
            .StatusBar.Panels("DVD_Menu").Text = modStr.DefaultStr(Language("170052"), "Menu Enabled")
        End If
        .Menu_Options_DVDMenu.Enabled = Not (.Menu_Options_MPEG2_1.Checked Or .Menu_Options_MPEG2_2.Checked)
        .Toolbar.Buttons("DVD_Menu").Enabled = .Menu_Options_DVDMenu.Enabled
            
        ' Changing Language
        .Menu_View_Select_Language_English.Checked = False
        For jj = 1 To 9
            .Controls("Menu_View_Select_Language_" & jj).Checked = False
        Next jj
        If Preferences.Language = "English" Then
            .Menu_View_Select_Language_English.Checked = True
        Else
            For jj = 1 To 9
                If Preferences.Language = .Controls("Menu_View_Select_Language_" & jj).Caption Then
                    .Controls("Menu_View_Select_Language_" & jj).Checked = True
                End If
            Next jj
        End If
        If NumTitles > 0 Then
            For Each ctr In .Controls
                If InStr(1, ctr.Name, .Menu_Title_EditInfo.Name & "_Audio") <> 0 Then
                    ctr.Caption = ctr.Tag & " (Track " & CurrentAudioTrack & ")"
                End If
            Next ctr
        End If
        modReg.ScriviChiaveStringa AVStoDVD_RegKey, "Language", Preferences.Language
        
        ' Changing Skin
        .Menu_View_Select_Skin_Default.Checked = False
        For jj = 1 To 9
            .Controls("Menu_View_Select_Skin_" & jj).Checked = False
        Next jj
        If Preferences.Skin = "Default" Then
            .Menu_View_Select_Skin_Default.Checked = True
        Else
            For jj = 1 To 9
                If Preferences.Skin = .Controls("Menu_View_Select_Skin_" & jj).Caption Then
                    .Controls("Menu_View_Select_Skin_" & jj).Checked = True
                End If
            Next jj
        End If
        modReg.ScriviChiaveStringa AVStoDVD_RegKey, "Skin", Preferences.Skin
    End With

End Sub


Public Sub Change_Titles()

    Dim jj As Integer
    Dim kk As Integer
    Dim NodeExpandedFlag(1 To 99) As Boolean
    Dim Str As String
    
    On Error Resume Next
    
    With frmMain
        .Menu_File_Save.Enabled = CBool(NumTitles)
        .Menu_File_Save_as.Enabled = CBool(NumTitles)
        .Menu_File_Start.Enabled = CBool(NumTitles)
        .Img_Start.Enabled = CBool(NumTitles)
        .Img_Start.Picture = frmMain.ImageList60.ListImages(2 + CInt(CBool(NumTitles))).Picture
        .Menu_Title_Edit.Enabled = CBool(NumTitles)
        .Img_Edit_Title.Enabled = CBool(NumTitles)
        .Img_Edit_Title.Picture = frmMain.ImageList32.ListImages(11 + CInt(CBool(NumTitles))).Picture
        .Menu_Title_Remove.Enabled = CBool(NumTitles)
        .Img_Del_Title.Enabled = CBool(NumTitles)
        .Img_Del_Title.Picture = frmMain.ImageList32.ListImages(13 + CInt(CBool(NumTitles))).Picture
        .Menu_Title_Refresh.Enabled = CBool(NumTitles)
        .Menu_Title_Preview.Enabled = CBool(NumTitles)
        .Img_Preview_Title.Enabled = CBool(NumTitles)
        .Img_Preview_Title.Picture = frmMain.ImageList32.ListImages(15 + CInt(CBool(NumTitles))).Picture
        .Menu_Title_ViewInfo.Enabled = CBool(NumTitles)
        .Menu_Title_EditInfo.Enabled = CBool(NumTitles)
        .Menu_Title_Audio.Enabled = CBool(NumTitles)
        .Menu_Title_Subs.Enabled = CBool(NumTitles)
        .Menu_Options_DVDMenu_Wizard.Enabled = CBool(NumTitles)
        .Menu_Tools_Join_AVS.Enabled = CBool(NumTitles)
        .Menu_Codecs_AviSynth_FrameServing_Check.Enabled = CBool(NumTitles)
        .Menu_Codecs_Graph.Enabled = CBool(NumTitles)
    End With

    With frmMain.TitlesTreeView
        If .Nodes.Count > 0 Then
            For jj = 1 To .Nodes.Count
                If .Nodes.Item(jj).Children > 0 Then
                    kk = kk + 1
                End If
            Next jj
            For jj = 1 To kk
                NodeExpandedFlag(jj) = .Nodes.Item("Title " & jj).Expanded
            Next jj
        End If
        .Nodes.Clear
        For jj = 1 To NumTitles
            Str = "Title " & jj & " (" & Title(jj).InputVideoPathName
            Str = Str & ")"
            .Nodes.add , tvwFirst, "Title " & jj, Str, 1
            .Nodes.add "Title " & jj, tvwChild, "Video " & jj, Title(jj).InputVideoInfo.Summary, 8
            If Title(jj).InputAudioPathName(1) <> "" Then
                For kk = 1 To Val(Title(jj).AudioTracksCount)
                    Str = Title(jj).InputAudioInfo(kk).Summary
                    If Title(jj).InputAudioPathName(kk) = Title(jj).InputVideoPathName Then
                        Str = Str & " - Internal" & IIf(Val(Title(jj).InputGeneralInfo.AudioTracksCount) > 1, " (Track " & Title(jj).InputAudioInfo(kk).ID & ")", "")
                    Else
                        Str = Str & " - External"
                    End If
                    If kk = 1 Then
                        .Nodes.add "Video " & jj, tvwNext, "Audio 1 " & jj, Str, 9
                    Else
                        .Nodes.add "Audio " & kk - 1 & " " & jj, tvwNext, "Audio " & kk & " " & jj, Str, 9
                    End If
                Next kk
            End If
            If Title(jj).InputSubsPathName(1) <> "" Then
                For kk = 1 To Title(jj).SubsTracksCount
                    Str = Title(jj).InputSubsInfo(kk).Summary
                    If Title(jj).InputSubsPathName(kk) = Title(jj).InputVideoPathName Then
                        Str = Str & " - Internal" & IIf(Val(Title(jj).InputGeneralInfo.SubsTracksCount) > 1, " (Track " & Title(jj).InputSubsInfo(kk).ID & ")", "")
                    Else
                        Str = Str & " - External"
                    End If
                    If kk = 1 Then
                        If Val(Title(jj).AudioTracksCount) = 0 Then
                            .Nodes.add "Video " & jj, tvwNext, "Subs 1 " & jj, Str, 10
                        Else
                            .Nodes.add "Audio " & Title(jj).AudioTracksCount & " " & jj, tvwNext, "Subs 1 " & jj, Str, 10
                        End If
                    Else
                        .Nodes.add "Subs " & kk - 1 & " " & jj, tvwNext, "Subs " & kk & " " & jj, Str, 10
                    End If
                Next kk
            End If
        Next jj
        If NumTitles > 0 Then
            If CurrentTitle > NumTitles Then CurrentTitle = NumTitles
            For jj = 1 To NumTitles
                .Nodes.Item("Title " & jj).Expanded = NodeExpandedFlag(jj)
            Next jj
            .Nodes.Item("Title " & CurrentTitle).Expanded = True
            .Nodes.Item("Title " & CurrentTitle).Selected = True
            ChangeFlag = True
        End If
        If frmMain.Enabled = True And frmMain.Visible = True Then
            .SetFocus
        End If
        Call frmMain.TitlesTreeView_NodeClick(frmMain.TitlesTreeView.SelectedItem)
    End With
    
End Sub


Public Sub Define_BitRates_DVDSize()

    Dim jj As Integer
    Dim kk As Integer
    Dim LeftTime As Long
    Dim LeftVideoBitRate As Single
    Dim DVD_Time As Long
    Dim DVD_Size As Single
    Dim DVD_Size_Safe As Single
    Dim Output_Filesize As Single
    Dim KbpsToMB As Single  'still have to multiply for time
    Dim FileSystem As String
    Dim AudioBitRateMax As Integer
    Dim AudioBitRateTot As Integer
    Dim AudioBitRateStr As String
    Dim MInfo As New clsMediaInfo
    
    On Error GoTo Err_Handling
    
    ' Initialize variables
    KbpsToMB = 1000 / 8 / 1024 / 1024
    frmMain.Txt_Estimated_Output_Size.Text = ""
    frmMain.StatusBar.Panels("DVD_Time").Text = VisualTime(0)
    DVD_Size = Val(frmMain.Txt_Output_Size.Text)
    
    If NumTitles > 0 Then
        With DVDMenu
            If .IsInit = True Then
                If .Style = MotionMenu Then
                    Output_Filesize = (Val(.VideoBitRate) + 500) * KbpsToMB * Val(.MotionMenuDuration)
                Else
                    Output_Filesize = 1
                    If modFS.EsisteFile(.BackgroundAudioPath) = True Then
                        If MInfo.ReadMediaInfo(.BackgroundAudioPath, , False, False, True, False) = True Then
                            Output_Filesize = Int(192 * Val(MInfo.AudioTime(0)) / 1000 / 1024 / 8) + 1
                        End If
                        Set MInfo = Nothing
                    End If
                End If
                Output_Filesize = .NumMenuPages * Output_Filesize
            End If
        End With
        frmMain.Txt_Estimated_Output_Size.Tag = Output_Filesize
        
        ' Calculate DVD Time
        For jj = LBound(Title) To NumTitles
            DVD_Time = DVD_Time + Title(jj).TimeTrimmed
        Next jj
        If OutputSetup < DVD_Folder And DiscSize = Custom Then
            DVD_Size_Safe = DVD_Size
        Else
            'DVD_Size_Safe = Int((0.995 - 0.01 * DVD_Time / 3600) * DVD_Size)
            DVD_Size_Safe = Int((0.985 - 0.0045 * DVD_Time / 3600) * DVD_Size)
        End If
        LeftTime = DVD_Time
        ' Define Subs and Audio bitrates and initialize Video bitrate
        For jj = LBound(Title) To NumTitles
            With Title(jj)
                ' Add Subs bitrate
                For kk = 1 To Val(.SubsTracksCount)
                    If .SubsHardEncode(kk) = False Then
                        Output_Filesize = Output_Filesize + 15 * KbpsToMB * .TimeTrimmed
                    End If
                Next kk
                ' Define and add Audio bitrate (all Tracks)
                For kk = 1 To Val(.AudioTracksCount)
                    ' Define AudioBitRate
                    If .AudioIsToBeKept(kk) = True Then
                        .AudioBitRate(kk) = Val(.InputAudioInfo(kk).AvgBitRate) / 1000
                    Else
                        If .AudioAutoSetup(kk) = True Then .AudioBitRate(kk) = 0
                        If .AudioBitRate(kk) <> 0 Then
                            AudioBitRateStr = Round(.AudioBitRate(kk), 0) * 1000
                        Else
                            If .InputAudioPathName(kk) = .InputVideoPathName Then
                                AudioBitRateStr = .InputAudioInfo(kk).AvgBitRate
                            Else
                                AudioBitRateStr = .InputAudioInfo(1).AvgBitRate
                            End If
                            AudioBitRateMax = BitRates(.AudioFormat(kk)).Item(BitRates(.AudioFormat(kk)).Count)
                            If Val(AudioBitRateStr) / 1000 > Val(Preferences.AudioBitRate) Or AudioBitRateStr = "" Then
                                If Val(.InputAudioInfo(kk).Channels) > 2 Then
                                    .AudioBitRate(kk) = AudioBitRateMax
                                End If
                            End If
                        End If
                        If .AudioBitRate(kk) = 0 Then .AudioBitRate(kk) = Val(Preferences.AudioBitRate)
                    End If
                    Output_Filesize = Output_Filesize + .AudioBitRate(kk) * KbpsToMB * .TimeTrimmed
                Next kk
                ' Initialize VideoAutoBitRate option
                If IsEmpty(.VideoAutoBitRate) = True Then .VideoAutoBitRate = True
                ' Initialize VideoBitRate and VideoMaxBitrate
                If .VideoIsToBeKept = True Then
                    .VideoBitRate = Round(Val(.InputVideoInfo.AvgBitRate) / 1000)
                End If
                If .VideoBitRate = 0 Then .VideoBitRate = Preferences.VideoMaxAvgBitRate
                If .VideoBitRate > Preferences.VideoMaxAvgBitRate Then .VideoBitRate = Preferences.VideoMaxAvgBitRate
                .VideoMaxBitRate = Preferences.VideoMaxBitRate
                ' Reserve output space to special settings (direct stream copy and user-defined videobitrate)
                If .VideoIsToBeKept = True Or .VideoAutoBitRate = False Then
                    Output_Filesize = Output_Filesize + .VideoBitRate * KbpsToMB * .TimeTrimmed
                    LeftTime = LeftTime - .TimeTrimmed
                End If
            End With
        Next jj
        ' Finalize VideoBitrate
        'If LeftTime > 0 Then
        '    LeftVideoBitRate = Round((DVD_Size_Safe - Output_Filesize) / KbpsToMB / LeftTime, 0)
        If DVD_Time > 0 Then
            If LeftTime > 0 Then
                LeftVideoBitRate = Round((DVD_Size_Safe - Output_Filesize) / KbpsToMB / LeftTime, 0)
                If LeftVideoBitRate > Val(Preferences.VideoMaxAvgBitRate) Then LeftVideoBitRate = Val(Preferences.VideoMaxAvgBitRate)
                If LeftVideoBitRate < Val(Preferences.VideoMinAvgBitRate) Then LeftVideoBitRate = Val(Preferences.VideoMinAvgBitRate)
            End If
            For jj = LBound(Title) To NumTitles
                With Title(jj)
                    ' Define VideoBitRate and VideoMaxBitRate and Output Filesize
                    If .VideoIsToBeKept = False And .VideoAutoBitRate = True Then
                        .VideoBitRate = LeftVideoBitRate
                        AudioBitRateTot = 0
                        For kk = 1 To Val(.AudioTracksCount)
                            AudioBitRateTot = AudioBitRateTot + .AudioBitRate(kk)
                        Next kk
                        If .VideoBitRate + AudioBitRateTot > Preferences.VideoMaxBitRate Then
                            .VideoBitRate = Preferences.VideoMaxBitRate - AudioBitRateTot
                        End If
                        If .VideoMaxBitRate + AudioBitRateTot > 9500 Then
                            .VideoMaxBitRate = 9500 - AudioBitRateTot
                        End If
                        If .VideoBitRate > .VideoMaxBitRate Then .VideoMaxBitRate = .VideoBitRate
                        Output_Filesize = Output_Filesize + .VideoBitRate * KbpsToMB * .TimeTrimmed
                    End If
                    ' Define Video Encoder
                    If .VideoAutoSetup = True Or .VideoEncoder = DirectCopy Then
                        If .VideoIsToBeKept = True Then
                            .VideoEncoder = DirectCopy
                        Else
                            Select Case Preferences.VideoEncoder
                            Case SmartSelection
                                Select Case Val(.VideoBitRate)
                                Case Is <= Val(Preferences.VideoProfileLevel2)
                                    .VideoEncoder = HCencVBR2pass
                                Case Is <= Val(Preferences.VideoProfileLevel1)
                                    .VideoEncoder = HCencVBR1pass
                                Case Else
                                    .VideoEncoder = FFMpegCBR1pass
                                End Select
                            Case Else
                                .VideoEncoder = Preferences.VideoEncoder
                            End Select
                        End If
                    End If
                    ' Force Full D1 Video Resolution if FFmpeg is used with 6500+ kbps, to avoid padding
                    If .VideoBitRate > 6500 Then
                        If .VideoEncoder = FFMpegCBR1pass Or .VideoEncoder = FFMpegSafeMode Then
                            .VideoResolution = Full_D1
                        End If
                    End If
                End With
            Next jj
        End If
        With frmMain.StatusBar.Panels("DVD_Time")
            .Text = VisualTime(DVD_Time)
        End With
    
    End If

    ' Update Estimated Output Size and Progress Bar
    With frmMain
        .Txt_Estimated_Output_Size.Text = ""
        If Output_Filesize > 0 And DVD_Size_Safe > 0 Then
            .Txt_Estimated_Output_Size.Text = Int(Output_Filesize * Val(.Txt_Output_Size) / DVD_Size_Safe)
        End If
        .Txt_Estimated_Output_Size.ToolTipText = modStr.DefaultStr(Language("160021"), .Txt_Estimated_Output_Size.ToolTipText) & ": " & Round(Val(.Txt_Estimated_Output_Size.Tag)) & "/" & Round((Val(.Txt_Estimated_Output_Size.Text) - Val(.Txt_Estimated_Output_Size.Tag)) * (DVD_Size_Safe / .Txt_Output_Size.Text), 0) & "/" & Round((Val(.Txt_Estimated_Output_Size.Text) - Val(.Txt_Estimated_Output_Size.Tag)) * (1 - DVD_Size_Safe / .Txt_Output_Size.Text), 0) & " MB"
        If Val(.Txt_Estimated_Output_Size.Text) > Val(.Txt_Output_Size.Text) Then
            .Txt_Estimated_Output_Size.ForeColor = RGB(255, 0, 0)
            .ProgressBar.value = Val(.Txt_Output_Size.Text)
            modUtil.ProgBarForeColor .ProgressBar.hwnd, RGB(255, 0, 0)
            modMain.Save_Log_Video "Warning! Resulting DVD will be oversized (" & Format(Val(.Txt_Estimated_Output_Size.Text) / Val(.Txt_Output_Size.Text), "0%") & ")!"
        Else
            .Txt_Estimated_Output_Size.ForeColor = RGB(0, 0, 0)
            .ProgressBar.value = Val(.Txt_Estimated_Output_Size.Text)
            modUtil.ProgBarForeColor .ProgressBar.hwnd, RGB(Skin.ForeRed, Skin.ForeGreen, Skin.ForeBlue)
        End If
        FileSystem = modFS.atFATType(Left(Preferences.OutputPath, 2))
        If InStr(1, FileSystem, "FAT") <> 0 And Val(.Txt_Estimated_Output_Size.Text) > 3990 Then
            MsgBox "Warning! Output Folder FileSystem is " & UCase(FileSystem) & "." & vbCrLf & _
                   "DVD Size must be limited to 4 GB." & vbCrLf & vbCrLf & _
                   "Please set DVD Size to 'Custom'/'3990' MB", vbExclamation, App.Title
        End If
    End With

    Exit Sub
    
Err_Handling:
Select Case Err.Number
Case 9999
    Resume
Case Else
    MsgBox "Error " & Err.Number & vbCrLf & vbCrLf & Err.Description, vbCritical, App.Title
    modMain.Save_Log_Video "Warning! Failed to initialize Project and compute output DVD size! Verify source file and/or check project settings.", , True
    frmMain.Txt_Output_Size.Text = ""
    frmMain.ProgressBar.value = Val(frmMain.Txt_Output_Size.Text)
    Set MInfo = Nothing
End Select

End Sub


' Create chapters list (sequence of frames) to be saved as txt file and used by MuxMan
Public Function Create_Chapters_List(Title As TitleSettings, Optional Delimiter As String = " ") As String

    Dim jj As Integer
    Dim InputFPS As Single
    Dim FPS As Single
    Dim InputFrameChapter As Single
    Dim FrameChapter As Long
    Dim iChapters As Integer
    Dim aChapters
    Dim dConvFactor As Double
    Dim bFlag As Boolean
    Dim bSource As Boolean
    
    On Error GoTo Err_Handling
    
    With Title
        ' Setting the FPS as the AviSynth script
        InputFPS = Val(.InputVideoInfo.FPS)
        FPS = .FPS
        Select Case .VideoFPSAdjust
        Case PullDown, PALSpeedUp, NTSCSlowDown
            dConvFactor = 1
        'Case PALSpeedUp
        '    dConvFactor = InputFPS / 25
        'Case NTSCSlowDown
        '    dConvFactor = 25 / 23.976
        Case Else
            dConvFactor = FPS / InputFPS
        End Select
        
        If Preferences.ChaptersUseSource = True And .InputGeneralInfo.ChaptersList <> "" And InStr(1, LCase(.InputVideoInfo.Compression), "mpeg") = 0 Then
            bSource = True
        End If
        
        If bSource = True Then
            aChapters = Split(.InputGeneralInfo.ChaptersList, " ")
            For jj = LBound(aChapters) To UBound(aChapters)
                If aChapters(jj) <> "" Then
                    InputFrameChapter = (Val(Mid(aChapters(jj), 1, 2)) * 3600 + Val(Mid(aChapters(jj), 4, 2)) * 60 + Val(Mid(aChapters(jj), 7, 2)) + Val(Right(aChapters(jj), 4))) * InputFPS
                    If InputFrameChapter > 0 Then
                        FrameChapter = Int(InputFrameChapter * dConvFactor) - .AVS.FrameStart
                        If FrameChapter > 0 Then
                            iChapters = iChapters + 1
                            If iChapters > MaxChapters Then Exit For
                            Create_Chapters_List = Create_Chapters_List & FrameChapter & Delimiter
                        End If
                    End If
                    'FrameChapter = Int((Val(Mid(aChapters(jj), 1, 2)) * 3600 + Val(Mid(aChapters(jj), 4, 2)) * 60 + Val(Mid(aChapters(jj), 7, 2)) + Val(Right(aChapters(jj), 4))) * FPS)
                    'If FrameChapter > 0 Then
                    '    dConvFactor = 1
                    '    If .VideoFPSAdjust = PALSpeedUp Then
                    '        dConvFactor = Val(.InputVideoInfo.FPS) / 25
                    '    ElseIf .VideoFPSAdjust = NTSCSlowDown Then
                    '        dConvFactor = 25 / 23.976
                    '    End If
                    '    FrameChapter = Int(FrameChapter * dConvFactor)
                    '    If FrameChapter < .TimeTrimmed * FPS Then
                    '        iChapters = iChapters + 1
                    '        If iChapters > MaxChapters Then Exit For
                    '        Create_Chapters_List = Create_Chapters_List & FrameChapter & Delimiter
                    '    End If
                    'End If
                End If
            Next jj
        ElseIf Val(Preferences.ChaptersInterval) * 60 < .TimeTrimmed Then
            bFlag = False
            Do
                jj = jj + 1
                FrameChapter = Val(Preferences.ChaptersInterval) * jj * 60 * .FPSAVS
                If FrameChapter > 0 And FrameChapter < .TimeTrimmed * .FPSAVS Then
                    iChapters = iChapters + 1
                    If iChapters > MaxChapters Then
                        iChapters = iChapters - 1
                        Exit Do
                    Else
                        Create_Chapters_List = Create_Chapters_List & FrameChapter & Delimiter
                    End If
                Else
                    bFlag = True
                End If
            Loop Until bFlag = True
        End If
    End With
    If Right(Create_Chapters_List, 1) = Delimiter Then
        Create_Chapters_List = Left(Create_Chapters_List, Len(Create_Chapters_List) - Len(Delimiter))
    End If
    
    Exit Function
    
Err_Handling:
Create_Chapters_List = ""

End Function


Public Sub Save_Log(Str_File As String, Str_Log As String, Append_Flag As Boolean, Optional Video_Flag As Boolean)

    Dim NumFile As Integer
        
    ' Verify log file path
    If Append_Flag = False Then
        modFS.DeleteIfExist Str_File
    End If
    ' Append string 'Str_Log' to txt-based file 'Str_File'
    NumFile = FreeFile
    Open Str_File For Append As #NumFile
        Print #NumFile, "<" & Now() & ">" & vbCrLf & Str_Log & vbCrLf & "<>" & vbCrLf
    Close #NumFile
    If Video_Flag = True Then
        modMain.Save_Log_Video Str_Log
    End If

End Sub


Public Sub Save_Log_Video(StrLog As String, Optional Refresh As Boolean, Optional MessageBox As Boolean)

    Dim StrLogMod As String
    Dim IconNum As Integer
    Dim jj As Integer
    Dim Str
    Dim bFlag As Boolean
    
    ' Uses icons from ImageList16 control
    ' 6 -> InfoIcon
    ' 7 -> WarningIcon
    
    On Error Resume Next
    
    With frmMain.lViewOper
        If Refresh = True Then
            For jj = 1 To .ListItems.Count
                IconNum = 6
                With .ListItems(jj)
                    If InStr(1, UCase(.SubItems(2)), "WARNING") <> 0 Then IconNum = 7
                    If InStr(1, UCase(.SubItems(2)), "ABORT") <> 0 Then IconNum = 7
                    If InStr(1, UCase(.SubItems(2)), "ERROR") <> 0 Then IconNum = 7
                    .SmallIcon = IconNum
                End With
            Next jj
        End If
        If StrLog <> "" Then
            For jj = 1 To Len(StrLog)
                If Mid(StrLog, jj, 1) = """" Then
                    bFlag = Not bFlag
                Else
                    If bFlag = False Then
                        StrLogMod = StrLogMod & Mid(StrLog, jj, 1)
                    End If
                End If
            Next jj
            IconNum = 6
            If InStr(1, UCase(StrLogMod), "WARNING") <> 0 Then IconNum = 7
            If InStr(1, UCase(StrLogMod), "ABORT") <> 0 Then IconNum = 7
            If InStr(1, UCase(StrLogMod), "ERROR") <> 0 Then IconNum = 7
            Str = Split(StrLog, vbCrLf)
            For jj = LBound(Str) To UBound(Str)
                If Str(jj) <> "" Then
                    .ListItems.add .ListItems.Count + 1, , ""
                    With .ListItems(.ListItems.Count)
                        .SmallIcon = IconNum
                        .SubItems(1) = Format(Time, "hh:nn:ss")
                        .SubItems(2) = Str(jj)
                        .EnsureVisible
                    End With
                End If
            Next jj
            If MessageBox = True Then
                MsgBox StrLog, IIf(IconNum = 7, vbExclamation, vbInformation), App.Title
            End If
        End If
    End With
        
    modUtil.ListViewAutoSize frmMain.lViewOper, 1
    DoEvents

End Sub


Public Sub Save_History(frm As Form, MenuEntry As String, RegKeyEntry As String, PathName As String, Optional Counts As Integer = 5)

    Dim jj As Integer

    For jj = 1 To Counts
        If modReg.EmiLeggiChiaveStringa(AVStoDVD_RegKey, RegKeyEntry & jj, "") = PathName Then
            Exit Sub
        End If
    Next jj
    For jj = Counts To 2 Step -1
        With frm.Controls(MenuEntry & jj)
            .Caption = modReg.EmiLeggiChiaveStringa(AVStoDVD_RegKey, RegKeyEntry & jj - 1, "")
            If .Caption <> "" Then
                modReg.ScriviChiaveStringa AVStoDVD_RegKey, RegKeyEntry & jj, .Caption
            End If
        End With
    Next jj
    frm.Controls(MenuEntry & "1").Caption = PathName
    modReg.ScriviChiaveStringa AVStoDVD_RegKey, RegKeyEntry & "1", PathName
    For jj = 1 To Counts
        frm.Controls(MenuEntry & jj).Visible = CBool(Len(frm.Controls(MenuEntry & jj).Caption))
    Next jj

End Sub


Public Function Create_Job_Save_Str(Optional FileNameSave As String) As String

    ' Create string containing all current project settings
    
    Dim Titolo As String
    Dim jj As Integer
    Dim kk As Integer
    Dim hh As Integer
    Dim Str As String
    
    On Error GoTo Err_Handling
    
    Screen.MousePointer = vbHourglass
    Titolo = "** Project Settings **"
    Str = Str & String(Len(Titolo), "*") & vbCrLf
    Str = Str & Titolo & vbCrLf
    Str = Str & String(Len(Titolo), "*") & vbCrLf
    Str = Str & vbCrLf
    Str = Str & "Project_PathName: " & FileNameSave & vbCrLf
    With frmMain
        Str = Str & "Output_Folder: " & .Txt_Path_Output.Text & vbCrLf
        Str = Str & "EditEncoderParams: " & .Int_EditEncoderParams.value & vbCrLf
        Str = Str & "DeleteAssets: " & .intDeleteAssets.value & vbCrLf
        Str = Str & "DeleteWorking: " & .intDeleteWorking.value & vbCrLf
        Str = Str & "FrameServingCheck: " & .Int_FrameServingCheck.value & vbCrLf
        Str = Str & "DVD_Label: " & .Txt_DVD_Label.Text & vbCrLf
        Str = Str & "Post_Process: " & .Cmb_PostProcess.ListIndex & vbCrLf
        Str = Str & "Output_Size: " & .Txt_Output_Size.Text & vbCrLf
        Str = Str & "DVD_Size: " & DiscSize & vbCrLf
        Str = Str & "Output_Setup: " & OutputSetup & vbCrLf
        Str = Str & "Video_Standard: " & VideoStandard & vbCrLf
    End With
    With DVDMenu
        If .IsInit = True Then
            Str = Str & vbCrLf
            Str = Str & "[DVD Menu]" & vbCrLf
            ' Wizard settings
            Str = Str & "IsInit: " & -CInt(.IsInit) & vbCrLf
            Str = Str & "IsFinal: " & -CInt(.IsFinal) & vbCrLf
            Str = Str & "Style: " & .Style & vbCrLf
            Str = Str & "AR: " & .AR & vbCrLf
            Str = Str & "TitlesFormat: " & .TitlesFormat & vbCrLf
            Str = Str & "Template: " & .Template & vbCrLf
            Str = Str & "MaxTitlesPage: " & .MaxTitlesPage & vbCrLf
            Str = Str & "PlayAllButton: " & -CInt(.PlayAllButton) & vbCrLf
            Str = Str & "ForcePlayAllSelection: " & -CInt(.ForcePlayAllSelection) & vbCrLf
            Str = Str & "BackgroundAudio: " & -CInt(.BackgroundAudio) & vbCrLf
            Str = Str & "MotionMenuDuration: " & .MotionMenuDuration & vbCrLf
            Str = Str & "VideoBitRate: " & .VideoBitRate & vbCrLf
            Str = Str & "MaxThumbsRow: " & .MaxThumbsRow & vbCrLf
            Str = Str & "ThumbImageSource: " & .ThumbImageSource & vbCrLf
            Str = Str & "ThumbFramePos: " & .ThumbFramePos & vbCrLf
            Str = Str & "HLFormat: " & .HLFormat & vbCrLf
            Str = Str & "HLColorsPlay: " & .HLColorsPlay & vbCrLf
            Str = Str & "HLColorsSel: " & .HLColorsSel & vbCrLf
            Str = Str & "ThumbShadow: " & .ThumbShadow & vbCrLf
            Str = Str & "PlayAllShadow: " & .PlayAllShadow & vbCrLf
            Str = Str & "ArrowsShadow: " & .ArrowsShadow & vbCrLf
            ' Editor settings
            Str = Str & "NumMenuTitles: " & .NumMenuTitles & vbCrLf
            Str = Str & "NumMenuPages: " & .NumMenuPages & vbCrLf
            Str = Str & "BackgroundPicturePath: " & .BackgroundPicturePath & vbCrLf
            Str = Str & "BackgroundVideoPath: " & .BackgroundVideoPath & vbCrLf
            Str = Str & "BackgroundAudioPath: " & .BackgroundAudioPath & vbCrLf
            Str = Str & "TitleText: " & Replace(.TitleText, vbCrLf, "~§~") & vbCrLf   'replace CR+LF with ~§~
            Str = Str & "TitleFontName: " & .TitleFont.Name & vbCrLf
            Str = Str & "TitleFontHeight: " & .TitleFont.Height & vbCrLf
            Str = Str & "TitleFontBold: " & -CInt(.TitleFont.Bold) & vbCrLf
            Str = Str & "TitleFontItalic: " & -CInt(.TitleFont.Italic) & vbCrLf
            Str = Str & "TitleFontUnderline: " & -CInt(.TitleFont.Underline) & vbCrLf
            Str = Str & "TitleFontOutline: " & -CInt(.TitleFont.Outline) & vbCrLf
            Str = Str & "TitleFontShadow: " & -CInt(.TitleFont.Shadow) & vbCrLf
            Str = Str & "TitleFontColor: " & .TitleFont.Color & vbCrLf
            Str = Str & "TitleAlignment: " & .TitleAlignment & vbCrLf
            Str = Str & "TitleLeft: " & .TitleLeft & vbCrLf
            Str = Str & "TitleTop: " & .TitleTop & vbCrLf
            Str = Str & "TitleWidth: " & .TitleWidth & vbCrLf
            Str = Str & "TitleHeight: " & .TitleHeight & vbCrLf
            Str = Str & "PlayAllButtonPicturePath: " & .PlayAllButtonPicturePath & vbCrLf
            Str = Str & "PlayAllButtonLeft: " & .PlayAllButtonLeft & vbCrLf
            Str = Str & "PlayAllButtonTop: " & .PlayAllButtonTop & vbCrLf
            Str = Str & "PlayAllButtonWidth: " & .PlayAllButtonWidth & vbCrLf
            Str = Str & "PlayAllButtonHeight: " & .PlayAllButtonHeight & vbCrLf
            Str = Str & "ArrowLButtonPicturePath: " & .ArrowLButtonPicturePath & vbCrLf
            Str = Str & "ArrowLButtonLeft: " & .ArrowLButtonLeft & vbCrLf
            Str = Str & "ArrowLButtonTop: " & .ArrowLButtonTop & vbCrLf
            Str = Str & "ArrowLButtonWidth: " & .ArrowLButtonWidth & vbCrLf
            Str = Str & "ArrowLButtonHeight: " & .ArrowLButtonHeight & vbCrLf
            Str = Str & "ArrowRButtonPicturePath: " & .ArrowRButtonPicturePath & vbCrLf
            Str = Str & "ArrowRButtonLeft: " & .ArrowRButtonLeft & vbCrLf
            Str = Str & "ArrowRButtonTop: " & .ArrowRButtonTop & vbCrLf
            Str = Str & "ArrowRButtonWidth: " & .ArrowRButtonWidth & vbCrLf
            Str = Str & "ArrowRButtonHeight: " & .ArrowRButtonHeight & vbCrLf
        End If
    End With
    Str = Str & vbCrLf & vbCrLf
    For jj = 1 To NumTitles
        DoEvents
        With Title(jj)
            Titolo = "** Title " & jj & " **"
            Str = Str & String(Len(Titolo), "*") & vbCrLf
            Str = Str & Titolo & vbCrLf
            Str = Str & String(Len(Titolo), "*") & vbCrLf
            Str = Str & vbCrLf
            Str = Str & "[General]" & vbCrLf
            Str = Str & "TitleName: " & .TitleName & vbCrLf
            Str = Str & "FPS: " & .FPS & vbCrLf
            Str = Str & "FPSAVS: " & .FPSAVS & vbCrLf
            Str = Str & "TimeTotal: " & .TimeTotal & vbCrLf
            Str = Str & "TimeTrimmed: " & .TimeTrimmed & vbCrLf
            Str = Str & "InputVideoPathName: " & .InputVideoPathName & vbCrLf
            For kk = 1 To Val(.AudioTracksCount)
                Str = Str & "InputAudioPathName" & kk & ": " & .InputAudioPathName(kk) & vbCrLf
            Next kk
            For kk = 1 To Val(.SubsTracksCount)
                Str = Str & "InputSubsPathName" & kk & ": " & .InputSubsPathName(kk) & vbCrLf
            Next kk
            Str = Str & "AudioTracksCount: " & .AudioTracksCount & vbCrLf
            Str = Str & "SubsTracksCount: " & .SubsTracksCount & vbCrLf
            Str = Str & vbCrLf
            Str = Str & "[MediaInfo]" & vbCrLf
            With .InputGeneralInfo
                Str = Str & "MediaInfoVersion: " & .MediaInfoVersion & vbCrLf
                Str = Str & "Format: " & .Format & vbCrLf
                Str = Str & "AudioTracksCount: " & .AudioTracksCount & vbCrLf
                Str = Str & "SubsTracksCount: " & .SubsTracksCount & vbCrLf
                Str = Str & "Time: " & .Time & vbCrLf
                Str = Str & "ChaptersList: " & .ChaptersList & vbCrLf
            End With
            With .InputVideoInfo
                Str = Str & "VideoTime: " & .Time & vbCrLf
                Str = Str & "VideoCompression: " & .Compression & vbCrLf
                Str = Str & "VideoBitRateMode: " & .BitRateMode & vbCrLf
                Str = Str & "VideoAvgBitRate: " & .AvgBitRate & vbCrLf
                Str = Str & "VideoMinBitRate: " & .MinBitRate & vbCrLf
                Str = Str & "VideoMaxBitRate: " & .MaxBitRate & vbCrLf
                Str = Str & "VideoWidth: " & .Width & vbCrLf
                Str = Str & "VideoHeight: " & .Height & vbCrLf
                Str = Str & "VideoDAR: " & .DAR & vbCrLf
                Str = Str & "VideoPAR: " & .PAR & vbCrLf
                Str = Str & "VideoFAR: " & .FAR & vbCrLf
                Str = Str & "VideoFrameRateMode: " & .FrameRateMode & vbCrLf
                Str = Str & "VideoFPS: " & .FPS & vbCrLf
                Str = Str & "VideoFrameCount: " & .FrameCount & vbCrLf
                Str = Str & "VideoScanType: " & .ScanType & vbCrLf
                Str = Str & "VideoScanOrder: " & .ScanOrder & vbCrLf
                Str = Str & "VideoColorSpace: " & .ColorSpace & vbCrLf
                Str = Str & "VideoColorCoefficients: " & .ColorCoefficients & vbCrLf
            End With
            For hh = 1 To Val(.AudioTracksCount)
                With .InputAudioInfo(hh)
                    Str = Str & "AudioID(" & hh & "): " & .ID & vbCrLf
                    Str = Str & "AudioStreamOrder(" & hh & "): " & .StreamOrder & vbCrLf
                    Str = Str & "AudioTime(" & hh & "): " & .Time & vbCrLf
                    Str = Str & "AudioCompression(" & hh & "): " & .Compression & vbCrLf
                    Str = Str & "AudioAvgBitRate(" & hh & "): " & .AvgBitRate & vbCrLf
                    Str = Str & "AudioBitRateMode(" & hh & "): " & .BitRateMode & vbCrLf
                    Str = Str & "AudioChannels(" & hh & "): " & .Channels & vbCrLf
                    Str = Str & "AudioSampleRate(" & hh & "): " & .SampleRate & vbCrLf
                    Str = Str & "AudioResolution(" & hh & "): " & .Resolution & vbCrLf
                    Str = Str & "AudioLanguage(" & hh & "): " & .Language & vbCrLf
                    Str = Str & "AudioDelay(" & hh & "): " & .Delay & vbCrLf
                End With
            Next hh
            For hh = 1 To Val(.SubsTracksCount)
                With .InputSubsInfo(hh)
                    Str = Str & "TextID(" & hh & "): " & .ID & vbCrLf
                    Str = Str & "TextStreamOrder(" & hh & "): " & .StreamOrder & vbCrLf
                    Str = Str & "TextFormat(" & hh & "): " & .Format & vbCrLf
                    Str = Str & "TextTitle(" & hh & "): " & .Title & vbCrLf
                    Str = Str & "TextLanguage(" & hh & "): " & .Language & vbCrLf
                    Str = Str & "TextLinesNum(" & hh & "): " & .LinesNum & vbCrLf
                End With
            Next hh
            Str = Str & vbCrLf
            Str = Str & "[Video]" & vbCrLf
            Str = Str & "VideoAutoSetup: " & -CInt(.VideoAutoSetup) & vbCrLf
            Str = Str & "VideoIsToBeKept: " & -CInt(.VideoIsToBeKept) & vbCrLf
            Str = Str & "VideoEncoder: " & .VideoEncoder & vbCrLf
            Str = Str & "VideoHCencAQ: " & .VideoHCenc.AQ & vbCrLf
            Str = Str & "VideoHCencLumgain: " & .VideoHCenc.Lumgain & vbCrLf
            Str = Str & "VideoHCencMatrix: " & .VideoHCenc.Matrix & vbCrLf
            Str = Str & "VideoHCencProfile: " & .VideoHCenc.Profile & vbCrLf
            Str = Str & "VideoHCencBias: " & .VideoHCenc.Bias & vbCrLf
            Str = Str & "VideoHCencDCPrec: " & .VideoHCenc.DCPrec & vbCrLf
            Str = Str & "VideoHCencZone: " & .VideoHCenc.Zone & vbCrLf
            Str = Str & "VideoResolution: " & .VideoResolution & vbCrLf
            Str = Str & "VideoAspectRatio: " & .VideoAspectRatio & vbCrLf
            Str = Str & "VideoDVSource: " & -CInt(.VideoDVSource) & vbCrLf
            Str = Str & "VideoInterlacedEncoding: " & -CInt(.VideoInterlacedEncoding) & vbCrLf
            Str = Str & "VideoFieldOrder: " & .VideoFieldOrder & vbCrLf
            Str = Str & "VideoCloseAllGOPs: " & -CInt(.VideoCloseAllGOPs) & vbCrLf
            Str = Str & "VideoBitRate: " & .VideoBitRate & vbCrLf
            Str = Str & "VideoMaxBitRate: " & .VideoMaxBitRate & vbCrLf
            Str = Str & "VideoAutoBitRate: " & -CInt(.VideoAutoBitRate) & vbCrLf
            Str = Str & "VideoFPSAdjust: " & .VideoFPSAdjust & vbCrLf
            Str = Str & vbCrLf
            Str = Str & "[Audio]" & vbCrLf
            Str = Str & "AudioTracksCount: " & .AudioTracksCount & vbCrLf
            For kk = 1 To Val(.AudioTracksCount)
                Str = Str & "AudioAutoSetup" & kk & ": " & -CInt(.AudioAutoSetup(kk)) & vbCrLf
                Str = Str & "AudioIsToBeKept" & kk & ": " & -CInt(.AudioIsToBeKept(kk)) & vbCrLf
                Str = Str & "AudioFormat" & kk & ": " & .AudioFormat(kk) & vbCrLf
                Str = Str & "AudioChannelsMode" & kk & ": " & .AudioChannelsMode(kk) & vbCrLf
                Str = Str & "AudioLanguage" & kk & ": " & .AudioLanguage(kk) & vbCrLf
                Str = Str & "AudioBitRate" & kk & ": " & .AudioBitRate(kk) & vbCrLf
                Str = Str & "AudioNormalize" & kk & ": " & -CInt(.AudioNormalize(kk)) & vbCrLf
                Str = Str & "AudioDelayAuto" & kk & ": " & -CInt(.AudioDelayAuto(kk)) & vbCrLf
                Str = Str & "AudioFixAC3" & kk & ": " & -CInt(.AudioFixAC3(kk)) & vbCrLf
                Str = Str & "AudioAftenPad" & kk & ": " & .AudioAften(kk).Pad & vbCrLf
                Str = Str & "AudioAftenDRC" & kk & ": " & .AudioAften(kk).DRC & vbCrLf
                Str = Str & "AudioAftenBWFilter" & kk & ": " & .AudioAften(kk).BWFilter & vbCrLf
            Next kk
            Str = Str & vbCrLf
            Str = Str & "[Subs]" & vbCrLf
            Str = Str & "SubsTracksCount: " & .SubsTracksCount & vbCrLf
            For kk = 1 To Val(.SubsTracksCount)
                Str = Str & "SubsAutoSetup" & kk & ": " & -CInt(.SubsAutoSetup(kk)) & vbCrLf
                Str = Str & "SubsLanguage" & kk & ": " & .SubsLanguage(kk) & vbCrLf
                Str = Str & "SubsExtension" & kk & ": " & .SubsExtension(kk) & vbCrLf
                Str = Str & "SubsHardEncode" & kk & ": " & -CInt(.SubsHardEncode(kk)) & vbCrLf
                Str = Str & "SubsFix" & kk & ": " & -CInt(.SubsFix(kk)) & vbCrLf
            Next kk
            Str = Str & vbCrLf
            Str = Str & "[AVS]" & vbCrLf
            Str = Str & "AVSAutoSetup: " & -CInt(.AVSAutoSetup) & vbCrLf
            Str = Str & "AVSAutoScript: " & vbCrLf & .AVSAutoScript & vbCrLf
            Str = Str & "AVSScript: " & vbCrLf & .AVSScript & vbCrLf
            Str = Str & "AVSCrop: " & -CInt(.AVSCrop) & vbCrLf
            Str = Str & "CropDx: " & .AVS.CropDx & vbCrLf
            Str = Str & "CropSx: " & .AVS.CropSx & vbCrLf
            Str = Str & "CropUp: " & .AVS.CropUp & vbCrLf
            Str = Str & "CropDo: " & .AVS.CropDo & vbCrLf
            Str = Str & "AVSVerticalResize: " & -CInt(.AVSVerticalResize) & vbCrLf
            Str = Str & "VResize: " & .AVS.VResize & vbCrLf
            Str = Str & "AVSDeInterlace: " & -CInt(.AVSDeInterlace) & vbCrLf
            Str = Str & "DeIntThreshold: " & .AVS.DeIntThreshold & vbCrLf
            Str = Str & "AVSTrim: " & -CInt(.AVSTrim) & vbCrLf
            Str = Str & "FrameStart: " & .AVS.FrameStart & vbCrLf
            Str = Str & "FrameEnd: " & .AVS.FrameEnd & vbCrLf
            Str = Str & "AVSInfo: " & -CInt(.AVSInfo) & vbCrLf
            Str = Str & "AVSTweak: " & -CInt(.AVSTweak) & vbCrLf
            Str = Str & "Hue: " & .AVS.Hue & vbCrLf
            Str = Str & "Saturation: " & .AVS.Saturation & vbCrLf
            Str = Str & "Brightness: " & .AVS.Brightness & vbCrLf
            Str = Str & "Contrast: " & .AVS.Contrast & vbCrLf
            Str = Str & "AVSSharpen: " & -CInt(.AVSSharpen) & vbCrLf
            Str = Str & "Sharpness: " & .AVS.Sharpness & vbCrLf
            Str = Str & "AVSDelayAudio: " & -CInt(.AVSDelayAudio) & vbCrLf
            Str = Str & "AudioDelay: " & .AVS.AudioDelay & vbCrLf
            Str = Str & "AVSAmplifyAudio: " & -CInt(.AVSAmplifyAudio) & vbCrLf
            Str = Str & "AudioAmplify: " & .AVS.AudioAmplify & vbCrLf
            Str = Str & "AVSFadeIO: " & -CInt(.AVSFadeIO) & vbCrLf
            Str = Str & "FadeIOFrames: " & .AVS.FadeIOFrames & vbCrLf
            Str = Str & "AVSColorMatrix: " & -CInt(.AVSColorMatrix) & vbCrLf
            Str = Str & "ColorMatrixSource: " & .AVS.ColorMatrixSource & vbCrLf
            Str = Str & "ColorMatrixDest: " & .AVS.ColorMatrixDest & vbCrLf
            Str = Str & "AVSMSharpen: " & -CInt(.AVSMSharpen) & vbCrLf
            Str = Str & "MSharpenThreshold: " & .AVS.MSharpenThreshold & vbCrLf
            Str = Str & "MSharpenStrength: " & .AVS.MSharpenStrength & vbCrLf
            Str = Str & "AVSHQDN3D: " & -CInt(.AVSHQDN3D) & vbCrLf
            Str = Str & "HQDN3DStrength: " & .AVS.HQDN3DStrength & vbCrLf
            Str = Str & "AVSDeBlock: " & -CInt(.AVSDeBlock) & vbCrLf
            Str = Str & "DeBlock: " & .AVS.DeBlock & vbCrLf
            Str = Str & "IVTC: " & -CInt(.AVSIVTC) & vbCrLf
            Str = Str & vbCrLf
            Str = Str & "[Chapters]" & vbCrLf
            Str = Str & "ChaptersAutoSetup: " & -CInt(.ChaptersAutoSetup) & vbCrLf
            Str = Str & "ChaptersList: " & .ChaptersList & vbCrLf
            Str = Str & vbCrLf
        End With
        If DVDMenu.NumMenuTitles > 0 Then
            Str = Str & "[Title Menu]" & vbCrLf
            Str = Str & "ThumbLeft: " & DVDMenu.ThumbLeft(jj) & vbCrLf
            Str = Str & "ThumbTop: " & DVDMenu.ThumbTop(jj) & vbCrLf
            Str = Str & "ThumbWidth: " & DVDMenu.ThumbWidth(jj) & vbCrLf
            Str = Str & "ThumbHeight: " & DVDMenu.ThumbHeight(jj) & vbCrLf
            Str = Str & "ThumbFrameStart: " & DVDMenu.ThumbFrameStart(jj) & vbCrLf
            Str = Str & "ThumbFrameEnd: " & DVDMenu.ThumbFrameEnd(jj) & vbCrLf
            Str = Str & "ThumbLabelText: " & Replace(DVDMenu.ThumbLabelText(jj), vbCrLf, "~§~") & vbCrLf
            Str = Str & "ThumbLabelFontName: " & DVDMenu.ThumbLabelFont(jj).Name & vbCrLf
            Str = Str & "ThumbLabelFontHeight: " & DVDMenu.ThumbLabelFont(jj).Height & vbCrLf
            Str = Str & "ThumbLabelFontBold: " & -CInt(DVDMenu.ThumbLabelFont(jj).Bold) & vbCrLf
            Str = Str & "ThumbLabelFontItalic: " & -CInt(DVDMenu.ThumbLabelFont(jj).Italic) & vbCrLf
            Str = Str & "ThumbLabelFontUnderline: " & -CInt(DVDMenu.ThumbLabelFont(jj).Underline) & vbCrLf
            Str = Str & "ThumbLabelFontOutline: " & -CInt(DVDMenu.ThumbLabelFont(jj).Outline) & vbCrLf
            Str = Str & "ThumbLabelFontShadow: " & -CInt(DVDMenu.ThumbLabelFont(jj).Shadow) & vbCrLf
            Str = Str & "ThumbLabelFontColor: " & DVDMenu.ThumbLabelFont(jj).Color & vbCrLf
            Str = Str & "ThumbLabelAlignment: " & DVDMenu.ThumbLabelAlignment(jj) & vbCrLf
            Str = Str & "ThumbLabelLeft: " & DVDMenu.ThumbLabelLeft(jj) & vbCrLf
            Str = Str & "ThumbLabelTop: " & DVDMenu.ThumbLabelTop(jj) & vbCrLf
            Str = Str & "ThumbLabelWidth: " & DVDMenu.ThumbLabelWidth(jj) & vbCrLf
            Str = Str & "ThumbLabelHeight: " & DVDMenu.ThumbLabelHeight(jj) & vbCrLf
            Str = Str & "ThumbAVSSCript: " & vbCrLf & DVDMenu.ThumbAVSSCript(jj) & vbCrLf
            Str = Str & "ThumbPicturePath: " & vbCrLf & DVDMenu.ThumbPicturePath(jj) & vbCrLf
            Str = Str & "~§~" & vbCrLf
        End If
        Str = Str & vbCrLf & vbCrLf
    Next jj
    Do Until Right(Str, 2) <> vbCrLf
        Str = Left(Str, Len(Str) - 2)
    Loop
    Str = Str & vbCrLf & vbCrLf & _
          frmMain.StatusBar.Panels("Release").Text & " - by MrC" & vbCrLf & _
          "AVStoDVD Job <" & FileNameSave & "> created on date " & Now
    Create_Job_Save_Str = Str
    Screen.MousePointer = vbDefault
    
    Exit Function

Err_Handling:
Select Case Err.Number
Case 9999
    Resume
Case Else
    Create_Job_Save_Str = ""
    Screen.MousePointer = vbDefault
End Select

End Function


Public Sub Load_AVStoDVD_Job(StrOpen As String)

    ' Load Project Settings from <StrJob> string (I kwow, this part of the code is orrible...)
    
    Dim StrOpenTitle As String
    Dim Inizio As Integer
    Dim Fine As Integer
    Dim Flag As Boolean
    Dim jj As Integer
    Dim kk As Integer
    Dim hh As Integer
    
    On Error GoTo Err_Handling
    
    Screen.MousePointer = vbHourglass
    modMain.Reset_Project
    
    If InStr(1, StrOpen, "Project Settings") <> 0 Then
        With frmMain
            .Caption = "AVStoDVD" & IIf(modMain.Load_Str_Object(StrOpen, "Project_PathName") <> "", " - " & modMain.Load_Str_Object(StrOpen, "Project_PathName"), "")
            .Txt_Path_Output.Text = modMain.Load_Str_Object(StrOpen, "Output_Folder", frmMain.Txt_Path_Output.Text)
            .Int_EditEncoderParams.value = modMain.Load_Str_Object(StrOpen, "EditEncoderParams", 0)
            .Int_FrameServingCheck.value = modMain.Load_Str_Object(StrOpen, "FrameServingCheck", 1)
            .intDeleteAssets.value = modMain.Load_Str_Object(StrOpen, "DeleteAssets", 1)
            .intDeleteWorking.value = modMain.Load_Str_Object(StrOpen, "DeleteWorking", 1)
            .Txt_DVD_Label.Text = modMain.Load_Str_Object(StrOpen, "DVD_Label", "DVD")
            .Cmb_PostProcess.ListIndex = Int(Val(modMain.Load_Str_Object(StrOpen, "Post_Process", 0)))
            .Txt_Output_Size.Text = modMain.Load_Str_Object(StrOpen, "Output_Size", frmMain.Txt_Output_Size.Text)
            DiscSize = Int(Val(modMain.Load_Str_Object(StrOpen, "DVD_Size", DiscSize)))
            OutputSetup = Int(Val(modMain.Load_Str_Object(StrOpen, "Output_Setup", OutputSetup)))
            VideoStandard = Int(Val(modMain.Load_Str_Object(StrOpen, "Video_Standard", VideoStandard)))
        End With
    End If
    Do
        DoEvents
        jj = jj + 1
        If InStr(1, StrOpen, "Title " & jj) <> 0 Then
            StrOpenTitle = Mid(StrOpen, InStr(1, StrOpen, "Title " & jj), IIf(InStr(1, StrOpen, "Title " & jj + 1) <> 0, InStr(1, StrOpen, "Title " & jj + 1) - InStr(1, StrOpen, "Title " & jj), InStr(1, StrOpen, "AVStoDVD Release") - InStr(1, StrOpen, "Title " & jj)))
            With Title(jj)
                ' General
                .TitleName = modMain.Load_Str_Object(StrOpenTitle, "TitleName", .TitleName)
                .FPS = modMain.Load_Str_Object(StrOpenTitle, "FPS")
                .FPSAVS = modMain.Load_Str_Object(StrOpenTitle, "FPSAVS")
                .TimeTotal = CLng(Val(modMain.Load_Str_Object(StrOpenTitle, "TimeTotal")))
                .TimeTrimmed = CLng(Val(modMain.Load_Str_Object(StrOpenTitle, "TimeTrimmed")))
                .InputVideoPathName = modMain.Load_Str_Object(StrOpenTitle, "InputVideoPathName", .InputVideoPathName)
                For hh = 1 To MaxAudioTracks
                    .InputAudioPathName(hh) = modMain.Load_Str_Object(StrOpenTitle, "InputAudioPathName" & hh)
                Next hh
                For hh = 1 To MaxSubsTracks
                    .InputSubsPathName(hh) = modMain.Load_Str_Object(StrOpenTitle, "InputSubsPathName" & hh)
                Next hh
                .AudioTracksCount = CInt(Val(modMain.Load_Str_Object(StrOpenTitle, "AudioTracksCount")))
                .SubsTracksCount = CInt(Val(modMain.Load_Str_Object(StrOpenTitle, "SubsTracksCount")))
                ' MediaInfo
                StrOpenTitle = Mid(StrOpenTitle, InStr(1, StrOpenTitle, "[MediaInfo]"), Len(StrOpenTitle) - InStr(1, StrOpenTitle, "[MediaInfo]") + 1)
                With .InputGeneralInfo
                    .MediaInfoVersion = modMain.Load_Str_Object(StrOpenTitle, "MediaInfoVersion", .MediaInfoVersion)
                    .Format = modMain.Load_Str_Object(StrOpenTitle, "Format", .Format)
                    .AudioTracksCount = modMain.Load_Str_Object(StrOpenTitle, "AudioTracksCount", .AudioTracksCount)
                    .SubsTracksCount = modMain.Load_Str_Object(StrOpenTitle, "SubsTracksCount", .SubsTracksCount)
                    .Time = modMain.Load_Str_Object(StrOpenTitle, "Time", .Time)
                    .ChaptersList = modMain.Load_Str_Object(StrOpenTitle, "ChaptersList", .ChaptersList)
                End With
                With .InputVideoInfo
                    .Time = modMain.Load_Str_Object(StrOpenTitle, "VideoTime", .Time)
                    .Compression = modMain.Load_Str_Object(StrOpenTitle, "VideoCompression", .Compression)
                    .BitRateMode = modMain.Load_Str_Object(StrOpenTitle, "VideoBitRateMode", .BitRateMode)
                    .AvgBitRate = modMain.Load_Str_Object(StrOpenTitle, "VideoAvgBitRate", .AvgBitRate)
                    .MinBitRate = modMain.Load_Str_Object(StrOpenTitle, "VideoMinBitRate", .MinBitRate)
                    .MaxBitRate = modMain.Load_Str_Object(StrOpenTitle, "VideoMaxBitRate", .MaxBitRate)
                    .Width = modMain.Load_Str_Object(StrOpenTitle, "VideoWidth", .Width)
                    .Height = modMain.Load_Str_Object(StrOpenTitle, "VideoHeight", .Height)
                    .DAR = modMain.Load_Str_Object(StrOpenTitle, "VideoDAR", .DAR)
                    .PAR = modMain.Load_Str_Object(StrOpenTitle, "VideoPAR", .PAR)
                    .FAR = modMain.Load_Str_Object(StrOpenTitle, "VideoFAR", .FAR)
                    .FrameRateMode = modMain.Load_Str_Object(StrOpenTitle, "VideoFrameRateMode", .FrameRateMode)
                    .FPS = modMain.Load_Str_Object(StrOpenTitle, "VideoFPS", .FPS)
                    .FrameCount = modMain.Load_Str_Object(StrOpenTitle, "VideoFrameCount", .FrameCount)
                    .ScanType = modMain.Load_Str_Object(StrOpenTitle, "VideoScanType", .ScanType)
                    .ScanOrder = modMain.Load_Str_Object(StrOpenTitle, "VideoScanOrder", .ScanOrder)
                    .ColorSpace = modMain.Load_Str_Object(StrOpenTitle, "VideoColorSpace", .ColorSpace)
                    .ColorCoefficients = modMain.Load_Str_Object(StrOpenTitle, "VideoColorCoefficients", .ColorCoefficients)
                End With
                For hh = 1 To Val(.AudioTracksCount)
                    With .InputAudioInfo(hh)
                        .ID = modMain.Load_Str_Object(StrOpenTitle, "AudioID(" & hh & ")")
                        .StreamOrder = modMain.Load_Str_Object(StrOpenTitle, "AudioStreamOrder(" & hh & ")")
                        .Time = modMain.Load_Str_Object(StrOpenTitle, "AudioTime(" & hh & ")")
                        .Compression = modMain.Load_Str_Object(StrOpenTitle, "AudioCompression(" & hh & ")")
                        .AvgBitRate = modMain.Load_Str_Object(StrOpenTitle, "AudioAvgBitRate(" & hh & ")")
                        .BitRateMode = modMain.Load_Str_Object(StrOpenTitle, "AudioBitRateMode(" & hh & ")")
                        .Channels = modMain.Load_Str_Object(StrOpenTitle, "AudioChannels(" & hh & ")")
                        .SampleRate = modMain.Load_Str_Object(StrOpenTitle, "AudioSampleRate(" & hh & ")")
                        .Resolution = modMain.Load_Str_Object(StrOpenTitle, "AudioResolution(" & hh & ")")
                        .Language = modMain.Load_Str_Object(StrOpenTitle, "AudioLanguage(" & hh & ")")
                        .Delay = modMain.Load_Str_Object(StrOpenTitle, "AudioDelay(" & hh & ")")
                    End With
                Next hh
                For hh = 1 To Val(.SubsTracksCount)
                    With .InputSubsInfo(hh)
                        .ID = modMain.Load_Str_Object(StrOpenTitle, "TextID(" & hh & ")")
                        .StreamOrder = modMain.Load_Str_Object(StrOpenTitle, "TextStreamOrder(" & hh & ")")
                        .Format = modMain.Load_Str_Object(StrOpenTitle, "TextFormat(" & hh & ")")
                        .Title = modMain.Load_Str_Object(StrOpenTitle, "TextTitle(" & hh & ")")
                        .Language = modMain.Load_Str_Object(StrOpenTitle, "TextLanguage(" & hh & ")")
                        .LinesNum = modMain.Load_Str_Object(StrOpenTitle, "TextLinesNum(" & hh & ")")
                    End With
                Next hh
                ' Video
                StrOpenTitle = Mid(StrOpenTitle, InStr(1, StrOpenTitle, "[Video]"), Len(StrOpenTitle) - InStr(1, StrOpenTitle, "[Video]") + 1)
                .VideoAutoSetup = CBool(modMain.Load_Str_Object(StrOpenTitle, "VideoAutoSetup", "1"))
                .VideoIsToBeKept = CBool(modMain.Load_Str_Object(StrOpenTitle, "VideoIsToBeKept", "0"))
                .VideoEncoder = CInt(modMain.Load_Str_Object(StrOpenTitle, "VideoEncoder", "3"))
                With .VideoHCenc
                    .AQ = modMain.Load_Str_Object(StrOpenTitle, "VideoHCencAQ", .AQ)
                    .Lumgain = modMain.Load_Str_Object(StrOpenTitle, "VideoHCencLumgain", .Lumgain)
                    .Matrix = modMain.Load_Str_Object(StrOpenTitle, "VideoHCencMatrix", .Matrix)
                    .Profile = modMain.Load_Str_Object(StrOpenTitle, "VideoHCencProfile", .Profile)
                    .Bias = modMain.Load_Str_Object(StrOpenTitle, "VideoHCencBias", .Bias)
                    .DCPrec = modMain.Load_Str_Object(StrOpenTitle, "VideoHCencDCPrec", .DCPrec)
                    .Zone = modMain.Load_Str_Object(StrOpenTitle, "VideoHCencZone", .Zone)
                End With
                .VideoResolution = CInt(modMain.Load_Str_Object(StrOpenTitle, "VideoResolution", Preferences.VideoResolution))
                .VideoAspectRatio = CInt(modMain.Load_Str_Object(StrOpenTitle, "VideoAspectRatio", .VideoAspectRatio))
                .VideoDVSource = CBool(modMain.Load_Str_Object(StrOpenTitle, "VideoDVSource", "0"))
                .VideoInterlacedEncoding = CBool(modMain.Load_Str_Object(StrOpenTitle, "VideoInterlacedEncoding", "0"))
                .VideoFieldOrder = modMain.Load_Str_Object(StrOpenTitle, "VideoFieldOrder", .VideoFieldOrder)
                .VideoCloseAllGOPs = CBool(modMain.Load_Str_Object(StrOpenTitle, "VideoCloseAllGOPs", "0"))
                .VideoBitRate = Int(Val(modMain.Load_Str_Object(StrOpenTitle, "VideoBitRate", .VideoBitRate)))
                .VideoMaxBitRate = Int(Val(modMain.Load_Str_Object(StrOpenTitle, "VideoMaxBitRate", .VideoMaxBitRate)))
                .VideoAutoBitRate = CBool(modMain.Load_Str_Object(StrOpenTitle, "VideoAutoBitRate", "1"))
                .VideoFPSAdjust = Int(Val(modMain.Load_Str_Object(StrOpenTitle, "VideoFPSAdjust", .VideoFPSAdjust)))
                ' Audio
                StrOpenTitle = Mid(StrOpenTitle, InStr(1, StrOpenTitle, "[Audio]"), Len(StrOpenTitle) - InStr(1, StrOpenTitle, "[Audio]") + 1)
                .AudioTracksCount = Int(Val(modMain.Load_Str_Object(StrOpenTitle, "AudioTracksCount", .AudioTracksCount)))
                For kk = 1 To Val(.AudioTracksCount)
                    .AudioIsToBeKept(kk) = CBool(modMain.Load_Str_Object(StrOpenTitle, "AudioIsToBeKept" & kk, "0"))
                    .AudioAutoSetup(kk) = CBool(modMain.Load_Str_Object(StrOpenTitle, "AudioAutoSetup" & kk, "1"))
                    .AudioFormat(kk) = modMain.Load_Str_Object(StrOpenTitle, "AudioFormat" & kk, Preferences.AudioFormat)
                    .AudioChannelsMode(kk) = modMain.Load_Str_Object(StrOpenTitle, "AudioChannelsMode" & kk, .AudioChannelsMode(kk))
                    .AudioLanguage(kk) = modMain.Load_Str_Object(StrOpenTitle, "AudioLanguage" & kk, IIf(kk = 1, Preferences.AudioLanguage, Preferences.AudioLanguage2))
                    .AudioBitRate(kk) = Int(Val(modMain.Load_Str_Object(StrOpenTitle, "AudioBitRate" & kk, .AudioBitRate(kk))))
                    .AudioNormalize(kk) = CBool(modMain.Load_Str_Object(StrOpenTitle, "AudioNormalize" & kk, Preferences.AudioNormalize))
                    .AudioDelayAuto(kk) = CBool(modMain.Load_Str_Object(StrOpenTitle, "AudioDelayAuto" & kk, Preferences.AudioDelayAuto))
                    .AudioFixAC3(kk) = CBool(modMain.Load_Str_Object(StrOpenTitle, "AudioFixAC3" & kk, "1"))
                    With .AudioAften(kk)
                        .Pad = modMain.Load_Str_Object(StrOpenTitle, "AudioAftenPad" & kk, "0")
                        .DRC = modMain.Load_Str_Object(StrOpenTitle, "AudioAftenDRC" & kk, "5")
                        .BWFilter = modMain.Load_Str_Object(StrOpenTitle, "AudioAftenBWFilter" & kk, "0")
                    End With
                Next kk
                ' Subs
                StrOpenTitle = Mid(StrOpenTitle, InStr(1, StrOpenTitle, "[Subs]"), Len(StrOpenTitle) - InStr(1, StrOpenTitle, "[Subs]") + 1)
                .SubsTracksCount = Int(Val(modMain.Load_Str_Object(StrOpenTitle, "SubsTracksCount", .SubsTracksCount)))
                For kk = 1 To Val(.SubsTracksCount)
                    .SubsAutoSetup(kk) = CBool(modMain.Load_Str_Object(StrOpenTitle, "SubsAutoSetup" & kk, "1"))
                    .SubsLanguage(kk) = modMain.Load_Str_Object(StrOpenTitle, "SubsLanguage" & kk, IIf(kk = 1, Preferences.SubsLanguage, Preferences.SubsLanguage2))
                    .SubsExtension(kk) = Int(modMain.Load_Str_Object(StrOpenTitle, "SubsExtension" & kk, "1"))
                    .SubsHardEncode(kk) = CBool(modMain.Load_Str_Object(StrOpenTitle, "SubsHardEncode" & kk, "0"))
                    .SubsFix(kk) = CBool(modMain.Load_Str_Object(StrOpenTitle, "SubsFix" & kk, "1"))
                Next kk
                ' AVS
                StrOpenTitle = Mid(StrOpenTitle, InStr(1, StrOpenTitle, "[AVS]"), Len(StrOpenTitle) - InStr(1, StrOpenTitle, "[AVS]") + 1)
                .AVSAutoSetup = CBool(modMain.Load_Str_Object(StrOpenTitle, "AVSAutoSetup", "1"))
                If InStr(1, StrOpenTitle, "AVSAutoScript: ", vbTextCompare) <> 0 Then
                    Inizio = InStr(1, StrOpenTitle, "AVSAutoScript: ", vbTextCompare) + 15
                    Fine = InStr(Inizio, StrOpenTitle, "AVSScript: ", vbTextCompare)
                    .AVSAutoScript = Mid(StrOpenTitle, Inizio, Fine - Inizio - 1)
                    .AVSAutoScript = modStr.RemoveCharBegEnd(.AVSAutoScript, Chr(10), Chr(13))
                End If
                If InStr(1, StrOpenTitle, "AVSScript: ", vbTextCompare) <> 0 Then
                    Inizio = InStr(1, StrOpenTitle, "AVSScript: ", vbTextCompare) + 12
                    Fine = InStr(Inizio, StrOpenTitle, "AVSCrop: ", vbTextCompare)
                    .AVSScript = Mid(StrOpenTitle, Inizio, Fine - Inizio - 1)
                    .AVSScript = modStr.RemoveCharBegEnd(.AVSScript, Chr(10), Chr(13))
                End If
                .AVSCrop = CBool(modMain.Load_Str_Object(StrOpenTitle, "AVSCrop", "0"))
                .AVS.CropDx = Int(Val(modMain.Load_Str_Object(StrOpenTitle, "CropDx")))
                .AVS.CropSx = Int(Val(modMain.Load_Str_Object(StrOpenTitle, "CropSx")))
                .AVS.CropUp = Int(Val(modMain.Load_Str_Object(StrOpenTitle, "CropUp")))
                .AVS.CropDo = Int(Val(modMain.Load_Str_Object(StrOpenTitle, "CropDo")))
                .AVSVerticalResize = CBool(modMain.Load_Str_Object(StrOpenTitle, "AVSVerticalResize", "0"))
                .AVS.VResize = Int(Val(modMain.Load_Str_Object(StrOpenTitle, "VResize")))
                .AVSDeInterlace = CBool(modMain.Load_Str_Object(StrOpenTitle, "AVSDeInterlace", "0"))
                .AVS.DeIntThreshold = Int(Val(modMain.Load_Str_Object(StrOpenTitle, "DeIntThreshold", "10")))
                .AVSTrim = CBool(modMain.Load_Str_Object(StrOpenTitle, "AVSTrim", "0"))
                .AVS.FrameStart = Int(Val(modMain.Load_Str_Object(StrOpenTitle, "FrameStart")))
                .AVS.FrameEnd = Int(Val(modMain.Load_Str_Object(StrOpenTitle, "FrameEnd")))
                .AVSInfo = CBool(modMain.Load_Str_Object(StrOpenTitle, "AVSInfo", "0"))
                .AVSTweak = CBool(modMain.Load_Str_Object(StrOpenTitle, "AVSTweak", "0"))
                .AVS.Hue = Val(Replace(modMain.Load_Str_Object(StrOpenTitle, "Hue"), ",", "."))
                .AVS.Saturation = Val(Replace(modMain.Load_Str_Object(StrOpenTitle, "Saturation"), ",", "."))
                .AVS.Brightness = Val(Replace(modMain.Load_Str_Object(StrOpenTitle, "Brightness"), ",", "."))
                .AVS.Contrast = Val(Replace(modMain.Load_Str_Object(StrOpenTitle, "Contrast"), ",", "."))
                .AVSSharpen = CBool(modMain.Load_Str_Object(StrOpenTitle, "AVSSharpen", "0"))
                .AVS.Sharpness = Val(Replace(modMain.Load_Str_Object(StrOpenTitle, "Sharpness"), ",", "."))
                .AVSDelayAudio = CBool(modMain.Load_Str_Object(StrOpenTitle, "AVSDelayAudio", "0"))
                .AVS.AudioDelay = Val(Replace(modMain.Load_Str_Object(StrOpenTitle, "AudioDelay"), ",", "."))
                .AVSAmplifyAudio = CBool(modMain.Load_Str_Object(StrOpenTitle, "AVSAmplifyAudio", "0"))
                .AVS.AudioAmplify = Val(Replace(modMain.Load_Str_Object(StrOpenTitle, "AudioAmplify"), ",", "."))
                .AVSFadeIO = CBool(modMain.Load_Str_Object(StrOpenTitle, "AVSFadeIO", "0"))
                .AVS.FadeIOFrames = Int(Val(modMain.Load_Str_Object(StrOpenTitle, "FadeIOFrames")))
                .AVSColorMatrix = CBool(modMain.Load_Str_Object(StrOpenTitle, "AVSColorMatrix", "0"))
                .AVS.ColorMatrixSource = Int(Val(modMain.Load_Str_Object(StrOpenTitle, "ColorMatrixSource")))
                .AVS.ColorMatrixDest = Int(Val(modMain.Load_Str_Object(StrOpenTitle, "ColorMatrixDest")))
                .AVSMSharpen = CBool(modMain.Load_Str_Object(StrOpenTitle, "AVSMSharpen", "0"))
                .AVS.MSharpenThreshold = Int(Val(modMain.Load_Str_Object(StrOpenTitle, "MSharpenThreshold")))
                .AVS.MSharpenStrength = Int(Val(modMain.Load_Str_Object(StrOpenTitle, "MSharpenStrength")))
                .AVSHQDN3D = CBool(modMain.Load_Str_Object(StrOpenTitle, "AVSHQDN3D", "0"))
                .AVS.HQDN3DStrength = Int(Val(modMain.Load_Str_Object(StrOpenTitle, "HQDN3DStrength")))
                .AVSDeBlock = CBool(modMain.Load_Str_Object(StrOpenTitle, "AVSDeBlock", "0"))
                .AVS.DeBlock = Int(Val(modMain.Load_Str_Object(StrOpenTitle, "DeBlock")))
                .AVSIVTC = CBool(modMain.Load_Str_Object(StrOpenTitle, "AVSIVTC", "0"))
                ' Chapters
                StrOpenTitle = Mid(StrOpenTitle, InStr(1, StrOpenTitle, "[Chapters]"), Len(StrOpenTitle) - InStr(1, StrOpenTitle, "[Chapters]") + 1)
                .ChaptersAutoSetup = CBool(modMain.Load_Str_Object(StrOpenTitle, "ChaptersAutoSetup", "1"))
                .ChaptersList = modMain.Load_Str_Object(StrOpenTitle, "ChaptersList", .ChaptersList)
            End With
        Else
            Flag = True
        End If
    Loop Until Flag = True
    NumTitles = jj - 1
    modMain.Load_AVStoDVD_DVDMenu StrOpen
    CurrentTitle = NumTitles
    modMain.Change_Settings
    modMain.Define_BitRates_DVDSize
    modMain.Change_Titles
    Screen.MousePointer = vbDefault
    
    Exit Sub
    
Err_Handling:
Select Case Err.Number
Case 13   'Type mismatch
    Resume Next
Case Else
    Screen.MousePointer = vbDefault
    MsgBox "Error " & Err.Number & vbCrLf & vbCrLf & Err.Description, vbCritical, App.Title
    modMain.Save_Log_Video "Warning! Failed to load AVStoDVD Project!"
End Select

End Sub


Public Sub Load_AVStoDVD_DVDMenu(StrOpen As String)

    ' Load DVDMenu Project Settings from <StrJob> string
    
    Dim StrOpenTitle As String
    Dim StrOpenMenu As String
    Dim jj As Integer

    On Error GoTo Err_Handling

    If InStr(1, StrOpen, "[DVD Menu]") <> 0 Then
        StrOpenMenu = Mid(StrOpen, InStr(1, StrOpen, "[DVD Menu]"), InStr(1, StrOpen, "** Title 1 **") - InStr(1, StrOpen, "[DVD Menu]"))
        With DVDMenu
            ' DVD Menu General Settings
            .IsInit = CBool(modMain.Load_Str_Object(StrOpenMenu, "IsInit"))
            .IsFinal = CBool(modMain.Load_Str_Object(StrOpenMenu, "IsFinal"))
            .Style = modMain.Load_Str_Object(StrOpenMenu, "Style", .Style)
            .AR = modMain.Load_Str_Object(StrOpenMenu, "AR", .AR)
            .TitlesFormat = modMain.Load_Str_Object(StrOpenMenu, "TitlesFormat", .TitlesFormat)
            .Template = modMain.Load_Str_Object(StrOpenMenu, "Template", .Template)
            .MaxTitlesPage = modMain.Load_Str_Object(StrOpenMenu, "MaxTitlesPage", .MaxTitlesPage)
            .PlayAllButton = CBool(modMain.Load_Str_Object(StrOpenMenu, "PlayAllButton"))
            .ForcePlayAllSelection = CBool(modMain.Load_Str_Object(StrOpenMenu, "ForcePlayAllSelection", .ForcePlayAllSelection))
            .BackgroundAudio = CBool(modMain.Load_Str_Object(StrOpenMenu, "BackgroundAudio"))
            .MotionMenuDuration = modMain.Load_Str_Object(StrOpenMenu, "MotionMenuDuration", .MotionMenuDuration)
            .VideoBitRate = modMain.Load_Str_Object(StrOpenMenu, "VideoBitRate", .VideoBitRate)
            .MaxThumbsRow = modMain.Load_Str_Object(StrOpenMenu, "MaxThumbsRow", .MaxThumbsRow)
            .ThumbImageSource = modMain.Load_Str_Object(StrOpenMenu, "ThumbImageSource", .ThumbImageSource)
            .ThumbFramePos = modMain.Load_Str_Object(StrOpenMenu, "ThumbFramePos", .ThumbFramePos)
            .HLFormat = modMain.Load_Str_Object(StrOpenMenu, "HLFormat", .HLFormat)
            .HLColorsPlay = modMain.Load_Str_Object(StrOpenMenu, "HLColorsPlay", .HLColorsPlay)
            .HLColorsSel = modMain.Load_Str_Object(StrOpenMenu, "HLColorsSel", .HLColorsSel)
            .ThumbShadow = modMain.Load_Str_Object(StrOpenMenu, "ThumbShadow", .ThumbShadow)
            .PlayAllShadow = modMain.Load_Str_Object(StrOpenMenu, "PlayAllShadow", .PlayAllShadow)
            .ArrowsShadow = modMain.Load_Str_Object(StrOpenMenu, "ArrowsShadow", .ArrowsShadow)
            ' Editor settings
            .NumMenuTitles = CInt(modMain.Load_Str_Object(StrOpenMenu, "NumMenuTitles", "1"))
            .NumMenuPages = CInt(modMain.Load_Str_Object(StrOpenMenu, "NumMenuPages", "1"))
            .BackgroundPicturePath = modMain.Load_Str_Object(StrOpenMenu, "BackgroundPicturePath", .BackgroundPicturePath)
            .BackgroundVideoPath = modMain.Load_Str_Object(StrOpenMenu, "BackgroundVideoPath", .BackgroundVideoPath)
            .BackgroundAudioPath = modMain.Load_Str_Object(StrOpenMenu, "BackgroundAudioPath", .BackgroundAudioPath)
            .TitleText = Replace(modMain.Load_Str_Object(StrOpenMenu, "TitleText", .TitleText), "~§~", vbCrLf)
            With .TitleFont
                .Name = modMain.Load_Str_Object(StrOpenMenu, "TitleFontName", .Name)
                .Height = modMain.Load_Str_Object(StrOpenMenu, "TitleFontHeight", "18")
                .Bold = CBool(modMain.Load_Str_Object(StrOpenMenu, "TitleFontBold"))
                .Italic = CBool(modMain.Load_Str_Object(StrOpenMenu, "TitleFontItalic"))
                .Underline = CBool(modMain.Load_Str_Object(StrOpenMenu, "TitleFontUnderline"))
                .Outline = CBool(modMain.Load_Str_Object(StrOpenMenu, "TitleFontOutline"))
                .Shadow = CBool(modMain.Load_Str_Object(StrOpenMenu, "TitleFontShadow"))
                .Color = modMain.Load_Str_Object(StrOpenMenu, "TitleFontColor", CStr(RGB(255, 255, 255)))
            End With
            .TitleAlignment = modMain.Load_Str_Object(StrOpenMenu, "TitleAlignment", vbCenter)
            .TitleLeft = modMain.Load_Str_Object(StrOpenMenu, "TitleLeft")
            .TitleTop = modMain.Load_Str_Object(StrOpenMenu, "TitleTop")
            .TitleWidth = modMain.Load_Str_Object(StrOpenMenu, "TitleWidth")
            .TitleHeight = modMain.Load_Str_Object(StrOpenMenu, "TitleHeight")
            .PlayAllButtonPicturePath = modMain.Load_Str_Object(StrOpenMenu, "PlayAllButtonPicturePath", .PlayAllButtonPicturePath)
            .PlayAllButtonLeft = modMain.Load_Str_Object(StrOpenMenu, "PlayAllButtonLeft")
            .PlayAllButtonTop = modMain.Load_Str_Object(StrOpenMenu, "PlayAllButtonTop")
            .PlayAllButtonWidth = modMain.Load_Str_Object(StrOpenMenu, "PlayAllButtonWidth")
            .PlayAllButtonHeight = modMain.Load_Str_Object(StrOpenMenu, "PlayAllButtonHeight")
            .ArrowLButtonPicturePath = modMain.Load_Str_Object(StrOpenMenu, "ArrowLButtonPicturePath", .ArrowLButtonPicturePath)
            .ArrowLButtonLeft = modMain.Load_Str_Object(StrOpenMenu, "ArrowLButtonLeft")
            .ArrowLButtonTop = modMain.Load_Str_Object(StrOpenMenu, "ArrowLButtonTop")
            .ArrowLButtonWidth = modMain.Load_Str_Object(StrOpenMenu, "ArrowLButtonWidth")
            .ArrowLButtonHeight = modMain.Load_Str_Object(StrOpenMenu, "ArrowLButtonHeight")
            .ArrowRButtonPicturePath = modMain.Load_Str_Object(StrOpenMenu, "ArrowRButtonPicturePath", .ArrowRButtonPicturePath)
            .ArrowRButtonLeft = modMain.Load_Str_Object(StrOpenMenu, "ArrowRButtonLeft")
            .ArrowRButtonTop = modMain.Load_Str_Object(StrOpenMenu, "ArrowRButtonTop")
            .ArrowRButtonWidth = modMain.Load_Str_Object(StrOpenMenu, "ArrowRButtonWidth")
            .ArrowRButtonHeight = modMain.Load_Str_Object(StrOpenMenu, "ArrowRButtonHeight")
        End With
    End If
    For jj = 1 To NumTitles
        If InStr(1, StrOpen, "Title " & jj) <> 0 Then
            StrOpenTitle = Mid(StrOpen, InStr(1, StrOpen, "Title " & jj), IIf(InStr(1, StrOpen, "Title " & jj + 1) <> 0, InStr(1, StrOpen, "Title " & jj + 1) - InStr(1, StrOpen, "Title " & jj), InStr(1, StrOpen, "AVStoDVD Release") - InStr(1, StrOpen, "Title " & jj)))
            ' DVD Menu Titles Settings
            If InStr(1, StrOpenTitle, "[Title Menu]") <> 0 Then
                With DVDMenu
                    .ThumbLeft(jj) = modMain.Load_Str_Object(StrOpenTitle, "ThumbLeft")
                    .ThumbTop(jj) = modMain.Load_Str_Object(StrOpenTitle, "ThumbTop")
                    .ThumbWidth(jj) = modMain.Load_Str_Object(StrOpenTitle, "ThumbWidth")
                    .ThumbHeight(jj) = modMain.Load_Str_Object(StrOpenTitle, "ThumbHeight")
                    .ThumbFrameStart(jj) = modMain.Load_Str_Object(StrOpenTitle, "ThumbFrameStart")
                    .ThumbFrameEnd(jj) = modMain.Load_Str_Object(StrOpenTitle, "ThumbFrameEnd")
                    .ThumbLabelText(jj) = Replace(modMain.Load_Str_Object(StrOpenTitle, "ThumbLabelText"), "~§~", vbCrLf)
                    With .ThumbLabelFont(jj)
                        .Name = modMain.Load_Str_Object(StrOpenTitle, "ThumbLabelFontName", "Tahoma")
                        .Height = modMain.Load_Str_Object(StrOpenTitle, "ThumbLabelFontHeight", "9")
                        .Bold = CBool(modMain.Load_Str_Object(StrOpenTitle, "ThumbLabelFontBold"))
                        .Italic = CBool(modMain.Load_Str_Object(StrOpenTitle, "ThumbLabelFontItalic"))
                        .Underline = CBool(modMain.Load_Str_Object(StrOpenTitle, "ThumbLabelFontUnderline"))
                        .Outline = CBool(modMain.Load_Str_Object(StrOpenTitle, "ThumbLabelFontOutline"))
                        .Shadow = CBool(modMain.Load_Str_Object(StrOpenTitle, "ThumbLabelFontShadow"))
                        .Color = modMain.Load_Str_Object(StrOpenTitle, "ThumbLabelFontColor", CStr(RGB(255, 255, 255)))
                    End With
                    .ThumbLabelAlignment(jj) = modMain.Load_Str_Object(StrOpenTitle, "ThumbLabelAlignment", vbCenter)
                    .ThumbLabelLeft(jj) = modMain.Load_Str_Object(StrOpenTitle, "ThumbLabelLeft")
                    .ThumbLabelTop(jj) = modMain.Load_Str_Object(StrOpenTitle, "ThumbLabelTop")
                    .ThumbLabelWidth(jj) = modMain.Load_Str_Object(StrOpenTitle, "ThumbLabelWidth")
                    .ThumbLabelHeight(jj) = modMain.Load_Str_Object(StrOpenTitle, "ThumbLabelHeight")
                    .ThumbAVSSCript(jj) = modMain.Load_Str_Object(StrOpenTitle, "ThumbAVSSCript")
                    .ThumbPicturePath(jj) = modMain.Load_Str_Object(StrOpenTitle, "ThumbPicturePath", , ": " & vbCrLf, "~§~")
                End With
            End If
        End If
    Next jj

    Exit Sub
    
Err_Handling:
Select Case Err.Number
Case 13   'Type mismatch
    Resume Next
Case Else
    MsgBox "Error " & Err.Number & vbCrLf & vbCrLf & Err.Description, vbCritical, App.Title
    modMain.Save_Log_Video "Warning! Failed to load AVStoDVD Project!"
End Select

End Sub


Public Function Load_Str_Object(Str As String, Object As String, Optional ByVal Default As String = "", Optional ByVal Separator As String = ": ", Optional ByVal EndString As String = vbCrLf) As String

    ' Get string object (Object) from string (Str). If no Object is found, Default is returned
    
    Dim Inizio As Integer
    Dim Fine As Integer

    On Error GoTo Err_Handling
        
    If InStr(1, Str, Object & Separator, vbTextCompare) <> 0 Then
        Inizio = InStr(1, Str, Object & Separator, vbTextCompare) + Len(Object) + Len(Separator)
        Fine = InStr(Inizio, Str, EndString, vbTextCompare)
        Load_Str_Object = Mid(Str, Inizio, Fine - Inizio)
        Load_Str_Object = modStr.RemoveCharBegEnd(Load_Str_Object, Chr(10), Chr(13))
    End If
    If Load_Str_Object = "" Then
        Load_Str_Object = Default
    End If
    
    Exit Function

Err_Handling:
Load_Str_Object = Default

End Function


Public Sub Load_Preview_Clip(Title As TitleSettings, OwnerForm As Form, Optional AudioNum As Integer = 1, Optional AVSScript As String)

    Dim sAVS As String
    Dim Str As String
    Dim MBR As VbMsgBoxResult
    
    On Error GoTo Err_Handling
    
    With Title
        If AVSScript <> "" Then
            sAVS = AVSScript
        Else
            If AudioNum = 1 Then
                sAVS = .AVSScript
            Else
                sAVS = modAVS.Create_AVSScript(Title, AudioNum)
            End If
        End If
        ' Remove Normalize to speed up preview
        If InStr(1, sAVS, ".Normalize(") <> 0 Then
            MBR = MsgBox("Warning! A <.Normalize()> function has been found in your AVS script." & vbCrLf & vbCrLf & "Do you want to remove it (speed up preview opening)?", vbQuestion + vbYesNoCancel, App.Title)
            Select Case MBR
            Case vbYes
                Str = Mid(sAVS, InStr(1, sAVS, ".Normalize("), InStr(InStr(1, sAVS, ".Normalize("), sAVS, ")") - InStr(1, sAVS, ".Normalize(")) & ")"
                sAVS = modStr.RemoveStr(sAVS, Str)
            Case vbCancel
                Exit Sub
            End Select
        End If
        sAVS = modMain.Prepare_AviSynth_Script_Preview(Title, sAVS, True)
        
        modStr.STRtoANSIFile sAVS, Preferences.TempPath & "\AviSynthP.avs"
        If FileLen(Preferences.TempPath & "\AviSynthP.avs") > 0 Then
            If Preferences.PreviewerPathName <> "" Then
                modShellEx.Execute Preferences.PreviewerPathName, """" & Preferences.TempPath & "\AviSynthP.avs""", SW_DEFAULT, True
            Else
                Load frmPreview
                frmPreview.Caption = frmPreview.Caption & " [" & Preferences.TempPath & "\AviSynthP.avs" & "]"
                frmPreview.Show 1, OwnerForm
            End If
        End If
    End With

    Exit Sub
    
Err_Handling:
Select Case Err.Number
Case 9999
    Resume
Case Else
    MsgBox "Error " & Err.Number & vbCrLf & vbCrLf & Err.Description, vbCritical, App.Title
    modMain.Save_Log_Video "Warning! Problems encountered in previewing Title " & CurrentTitle & "."
End Select

End Sub


Public Function Prepare_AviSynth_Script_Preview(Title As TitleSettings, Optional sAVS As String, Optional bResize As Boolean) As String

    Dim sOut As String
    Dim sAdd As String
    
    If sAVS = "" Then
        sAVS = Title.AVSScript
    End If
    ' Handle Return Video statement
    If InStr(1, sAVS, "Return Video") <> 0 Then
        sOut = sAVS & "."
    Else
        sOut = sAVS & vbCrLf
    End If
    ' Resize to have PAR 1
    If bResize = True Then
        If Title.VideoAspectRatio = Widescreen Then
            sAdd = sAdd & "Lanczos4Resize(720,406)."
        Else
            sAdd = sAdd & "Lanczos4Resize(720,540)."
        End If
    End If
    ' Add ConvertToRGB for better compliance to Raw Video directshow display
    sAdd = sAdd & "ConvertToRGB()"
    sOut = sOut & sAdd
    
    Prepare_AviSynth_Script_Preview = sOut

End Function


Public Sub Check_Software(Optional LoadedForm As String)

    Dim jj As Integer
    Dim Str As String
    Dim StrA As String
    Dim StrB As String
    Dim Programs_Paths As Variant
    Dim Programs_Names As Variant
    Dim MediaInfo_Sys_Ver As String
    Dim MediaInfo_Lib_Ver As String
    Dim iDist As Integer
    
    On Error GoTo Err_Handling
        
    Programs_Paths = Array(App.Path & "\ac3fix\ac3fix.exe", _
                           App.Path & "\Aften\aften.exe", _
                           App.Path & "\AVSMeter\AVSMeter.exe", _
                           App.Path & "\BatchMux\BatchMux.exe", _
                           App.Path & "\DGIndex\DGIndex.exe", _
                           App.Path & "\DGPulldown\DGPulldown.exe", _
                           App.Path & "\FFmpeg\ffmpeg.exe", _
                           App.Path & "\GraphStudio\GraphStudio0320.exe", _
                           App.Path & "\HCenc\HCenc.exe", _
                           App.Path & "\MKVToolNix\mkvextract.exe", _
                           App.Path & "\Mplex\mplex.exe", _
                           App.Path & "\MuxMan\MuxMan.exe", _
                           App.Path & "\SetACL\SetACL.exe", _
                           App.Path & "\SubtitleCreator\SubtitleCreator.exe", _
                           App.Path & "\Wavi\wavi.exe", _
                           App.Path & "\VobSub\VSConv.exe", _
                           App.Path & "\VobSub\VobSub.dll", _
                           App.Path & "\VobSub\VSFilter.dll", _
                           App.Path & "\Lib\MediaInfo.dll", _
                           App.Path & "\Lib\AuthDVD.dll", _
                           App.Path & "\Lib\ffms2.dll", _
                           App.Path & "\Lib\GetSystemEnv.dll", _
                           SysInfo.PathSystem & "\quartz.dll", _
                           PathNames.MSComCtlOcx)
    Programs_Names = Array("AC3Fix", _
                           "Aften", _
                           "AVSMeter", _
                           "BatchMux", _
                           "DGIndex", _
                           "DGPulldown", _
                           "FFmpeg", _
                           "GraphStudio", _
                           "HCenc", _
                           "MKVextract", _
                           "Mplex", _
                           "MuxMan", _
                           "SetACL", _
                           "SubtitleCreator", _
                           "Wavi", _
                           "VSConv", _
                           "VobSub Lib", _
                           "VobSub Plugin", _
                           "MediaInfo Lib", _
                           "DVD Parsing Lib", _
                           "FFMS2 C Plugin", _
                           "GetSystemEnv Plugin", _
                           "DirectShow Lib", _
                           "Common Controls Lib")
        
    ' Check if mscomctl.ocx is located in Windows\System32
    'If Dir(SysInfo.PathSystem & "\mscomctl.ocx") = "" Then
    '    If MsgBox("Windows Common Controls 6.0 library (mscomctl.ocx) has not been found in your system." & vbCrLf & vbCrLf & _
    '              "This library is mandatory for AVStoDVD. Do you want to install it?", vbYesNo + vbQuestion, App.Title) = vbYes Then
    '        FileCopy App.Path & "\Lib\mscomctl.ocx", SysInfo.PathSystem & "\mscomctl.ocx"
    '        modShellEx.Execute "regsvr32.exe", SysInfo.PathSystem & "\mscomctl.ocx", SW_HIDE, True
    '    End If
    'End If
    
    ' Check if MediaInfo.dll is located in Windows\System32
    If Dir(SysInfo.PathSystem & "\MediaInfo.dll") <> "" Then
        MediaInfo_Lib_Ver = modFileVersion.GetFileVersion(App.Path & "\Lib\MediaInfo.dll")
        MediaInfo_Sys_Ver = modFileVersion.GetFileVersion(SysInfo.PathSystem & "\MediaInfo.dll")
        If Val(Replace(MediaInfo_Lib_Ver, ".", "")) > Val(Replace(MediaInfo_Sys_Ver, ".", "")) Then
            If MsgBox("An older release (" & MediaInfo_Sys_Ver & ") of MediaInfo has been found in your system." & vbCrLf & vbCrLf & _
                      "Since " & frmMain.StatusBar.Panels("Release").Text & " requires release " & MediaInfo_Lib_Ver & " or higher, do you want to update it?", vbYesNo + vbQuestion, App.Title) = vbYes Then
                FileCopy App.Path & "\Lib\MediaInfo.dll", SysInfo.PathSystem & "\MediaInfo.dll"
            End If
        End If
    End If
    
    ' Check programs paths
    If LoadedForm = "frmPreferences" Then
        With frmPreferences
            iDist = 25
            ' Check AviSynth
            StrA = "AviSynth"
            StrB = ""
            If AviSynth.PathName = "" Then
                StrB = "WARNING! " & StrA & " NOT found!"
            Else
                If Val(Replace(AviSynth.Version, ".", "")) < 257 Then
                    StrB = "WARNING! AviSynth release 2.5.7 or higher is required!"
                Else
                    StrA = StrA & " " & AviSynth.Version
                    StrB = AviSynth.PathName
                End If
            End If
            .Lst_SysInfo.AddItem StrA & String(iDist - Len(StrA), " ") & ": " & StrB
            ' Check ffdshow
            StrA = "ffdshow"
            StrB = ""
            If ffdshow.PathName = "" Then
                ' No warning: ffdshow is not mandatory
            Else
                StrA = StrA & " " & ffdshow.Version
                StrB = ffdshow.PathName
                .Lst_SysInfo.AddItem StrA & String(iDist - Len(StrA), " ") & ": " & StrB
            End If
            ' Check LAVFilters
            StrA = "LAV Filters"
            StrB = ""
            If LAVFilters.PathName = "" Then
                ' No warning: LAVFilters is not mandatory
            Else
                StrA = StrA & " " & LAVFilters.Version
                StrB = LAVFilters.PathName
                .Lst_SysInfo.AddItem StrA & String(iDist - Len(StrA), " ") & ": " & StrB
            End If
            ' Check ImgBurn
            StrA = "ImgBurn"
            StrB = ""
            If PathNames.ImgBurn = "" Then
                ' No warning: ImgBurn is not mandatory
            Else
                StrA = StrA & " " & modFileVersion.GetFileVersion(PathNames.ImgBurn, , True)
                StrB = PathNames.ImgBurn
                .Lst_SysInfo.AddItem StrA & String(iDist - Len(StrA), " ") & ": " & StrB
            End If
            For jj = LBound(Programs_Paths) To UBound(Programs_Paths)
                Str = Programs_Names(jj) & " " & modFileVersion.GetFileVersion(Programs_Paths(jj))
                If Len(Str) < 25 Then
                    Str = Str & String(iDist - Len(Str), " ")
                Else
                    Str = Str & String(iDist + 6 - Len(Str), " ")
                End If
                If EsisteFile(CStr(Programs_Paths(jj)), False, vbHidden + vbReadOnly + vbSystem) = True Then
                    .Lst_SysInfo.AddItem Str & ": " & Programs_Paths(jj)
                Else
                    .Lst_SysInfo.AddItem Str & ": WARNING! " & Programs_Names(jj) & " NOT found!"
                End If
            Next jj
        End With
    ElseIf LoadedForm = "frmSplash" Then
        With frmSplash
            '.Lbl_Check.Caption = "Checking AviSynth..."
            'If InStr(1, modReg.EmiLeggiChiaveStringa("HKEY_LOCAL_MACHINE\SOFTWARE\AviSynth", ""), "AviSynth") <> 0 Then
            '    .Lbl_Check.Caption = "AviSynth found"
            'Else
            '    MsgBox "Warning! AviSynth NOT found!" & vbCrLf & vbCrLf & "Most of encoding routines will not be available!", vbCritical, App.Title
            'End If
            '.Lbl_Check.Caption = "Checking ImgBurn..."
            'If PathNames.ImgBurn <> "" Then
            '    .Lbl_Check.Caption = "ImgBurn found"
            'Else
            '    MsgBox "Warning! ImgBurn NOT found!" & vbCrLf & vbCrLf & "ISO building and DVD burning are disabled!", vbCritical, App.Title
            'End If
            For jj = LBound(Programs_Paths) To UBound(Programs_Paths)
                .lblCheck.Caption = "Checking " & Programs_Names(jj) & "..."
                If EsisteFile(CStr(Programs_Paths(jj)), False, vbHidden + vbReadOnly + vbSystem) = True Then
                    .lblCheck.Caption = Programs_Names(jj) & "found"
                Else
                    MsgBox "Warning! " & Programs_Names(jj) & " not found!", vbCritical, App.Title
                End If
            Next jj
            .lblCheck.Caption = "Check completed."
        End With
    End If
    
    Exit Sub
    
Err_Handling:
MsgBox "Error " & Err.Number & vbCrLf & vbCrLf & Err.Description, vbCritical, App.Title
Select Case Err.Number
Case 70
    Resume Next
End Select

End Sub


Public Sub Save_Preferences_InputPath(PathName As String)

    Dim PathSave As String
    
    If Right(PathName, 1) = "\" Then PathName = Left(PathName, Len(PathName) - 1)
    If modFS.EsisteFile(PathName) = True Then
        PathSave = modFS.PathOf(PathName, False)
    ElseIf modFS.EsisteDir(PathName) = True Then
        PathSave = PathName
    End If
    If PathSave <> "" Then
        Preferences.InputPath = PathSave
        modReg.ScriviChiaveStringa AVStoDVD_RegKey, "InputPath", PathSave
    End If

End Sub


Public Function Load_Language(Optional sLanguage As String = "English") As Collection

    Dim LangPathname As String
    Dim NumFile As Integer
    Dim sLine As String
    Dim vLine
    
    On Error GoTo Err_Handling
    
    LangPathname = App.Path & "\Lang\" & sLanguage & ".lang.ini"
    If modFS.EsisteFile(LangPathname) = False Then
        GoTo Err_Handling
    Else
        Set Load_Language = New Collection
        NumFile = FreeFile
        Open App.Path & "\Lang\" & sLanguage & ".lang.ini" For Input As #NumFile
            Do Until EOF(NumFile) = True
                Line Input #NumFile, sLine
                If sLine <> "" Then
                    If Len(sLine) > 8 Then
                        vLine = Split(sLine, Chr(9))
                        If IsNumeric(vLine(0)) = True Then
                            Load_Language.add modStr.RemoveCharBegEnd(CStr(vLine(1)), " "), vLine(0)
                        End If
                    End If
                End If
            Loop
        Close #NumFile
    End If
    
    Exit Function
    
Err_Handling:
Select Case Err.Number
Case 9999
    Resume
Case Else
    MsgBox "Warning!" & vbCrLf & vbCrLf & "Cannot load '" & sLanguage & "' language." & vbCrLf & vbCrLf & _
           "Check pathname '" & LangPathname & "'.", vbCritical, App.Title
End Select

End Function

