;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; ;; AutoIt Version: 3.3.0.0 ;; ;; ;; ;; Template AutoIt script. ;; ;; ;; ;; AUTHOR: TheSaint ;; ;; ;; ;; SCRIPT FUNCTION: Interact with CDRTools and run specific elements ;; ;; ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; FUNCTIONS ; GetCDRToolsPath(), GetDefaultDriveName(), GetDriveLetters(), GetDriveNames(), ScanTheBus() ; SelectTheDrive() #region --- GuiBuilder code Start --- ; Script generated by AutoBuilder 0.7 Prototype #include #include #include #include #include #include Global $Button_i, $Button_scan, $Button_set, $Button_toc, $Button_x Global $Checkbox_scan, $Combo_cd, $Group_cd Global $begin, $c, $cdrtools, $cnt, $d, $def, $detail, $dev, $devices, $dif, $dr, $drive, $drvinfo Global $drvnam, $drvxml, $icofle, $icoI, $icoX, $id, $inifle, $line, $n, $name, $names, $nme, $pid Global $pth, $Runner, $s, $scan, $scanbus, $scanlog, $scsi, $sect, $sects, $shell $inifle = @ScriptDir & "\Settings.ini" $scanlog = @ScriptDir & "\scanbus.log" $drvinfo = @ScriptDir & '\Drives.xml' $Runner = GuiCreate("CDRTools Runner", 360, 130, -1, -1, $WS_OVERLAPPED + $WS_CAPTION _ + $WS_SYSMENU + $WS_VISIBLE + $WS_CLIPSIBLINGS + $WS_MINIMIZEBOX) ; ; CONTROLS $Group_cd = GuiCtrlCreateGroup("CD-Rom Drives", 10, 10, 340, 50) $Combo_cd = GuiCtrlCreateCombo("", 20, 30, 250, 21) GUICtrlSetTip($Combo_cd, "The available CD-Rom drives detected during a scan!") $Button_scan = GuiCtrlCreateButton("SCAN", 280, 30, 60, 20) GUICtrlSetFont($Button_scan, 7, 600, 0, "Small Fonts") GUICtrlSetTip($Button_scan, "Scan or Re-Scan for CD-Rom drives!") ; $Button_toc = GuiCtrlCreateButton("TOC", 10, 70, 70, 50) GUICtrlSetFont($Button_toc, 10, 600) GUICtrlSetTip($Button_toc, "Report the Table Of Contents for selected CD-Rom drive!") ; $Button_set = GuiCtrlCreateButton("Set current as default", 90, 70, 140, 27) GUICtrlSetTip($Button_set, "Set currently selected drive as default!") ; $Checkbox_scan = GUICtrlCreateCheckbox("Use previously scanned", 95, 103, 130, 20) GUICtrlSetTip($Checkbox_scan, "Use previously scanned drive details!") ; $Button_i = GuiCtrlCreateButton("Info", 240, 70, 50, 50, $BS_ICON) GUICtrlSetTip($Button_i, "Program Information!") ; $Button_x = GuiCtrlCreateButton("EXIT", 300, 70, 50, 50, $BS_ICON) GUICtrlSetTip($Button_x, "Exit / Quit / Close the program!") ; ; OS CHECK $shell = "shell32.dll" If @OSVersion = "WIN_ME" or StringLeft(@OSVersion, 5) = "WIN_9" Then ;~ $icofle = "User.exe" ;~ $icoX = 6 ;~ $icoI = 4 Else ; WIN_NT4, WIN_2000, WIN_XP, WIN_2003 $icofle = $shell $icoX = -28 $icoI = -222 EndIf GUICtrlSetImage($Button_i, $icofle, $icoI, 1) GUICtrlSetImage($Button_x, $icofle, $icoX, 1) ; ; SETTINGS $cdrtools = IniRead($inifle, "cdrtools", "path", "") If $cdrtools = "" Or Not FileExists($cdrtools) Then GetCDRToolsPath() EndIf If $cdrtools <> "" Then $scan = IniRead($inifle, "scsibus", "scan", "") If $scan = "" Then $scan = 4 IniWrite($inifle, "scsibus", "scan", $scan) EndIf If $scan = 4 Then ScanTheBus() Else GetDriveNames() GetDefaultDriveName() GUICtrlSetData($Combo_cd, $devices, $name) GUICtrlSetState($Checkbox_scan, $scan) EndIf Else #region --- Dialog Maker code Begin --- MsgBox(262192, "CDRTools Path Error", _ "This program cannot work unless the path" & @LF & _ "to the CDRTools folder has been set!", 0) #endregion --- Dialog Maker code End --- Exit EndIf GuiSetState() While 1 $msg = GuiGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Or $msg = $Button_x ; Exit / Quit / Close the program GUIDelete($Runner) ExitLoop Case $msg = $Button_toc ; Report the Table Of Contents for selected CD-Rom drive $dev = IniRead($inifle, "CD-Rom_" & $d, "device", "") If $dev <> "" Then SplashTextOn("", "Please Wait!", 200, 70, -1, -1, 33) $detail = "" $pid = Run('"' & $cdrtools & '\cdda2wav.exe"' & " dev=" & $dev & " -g -J -N -H -vtoc", $cdrtools, @SW_HIDE, 8) If @error Then MsgBox(262208, "Error", @error, 0) Local $read While 1 $read = StdoutRead($pid, True) If @error Then ;MsgBox(262208, "Error", @error, 0) ;ExitLoop ElseIf $read = "" And $detail <> "" Then ExitLoop ElseIf $read <> "" Then $detail = $read EndIf StderrRead($pid) If @error And $detail <> "" Then ExitLoop ;MsgBox(262208, "Program Information", $detail, 0) Sleep(1000) Wend ;Sleep(5000) If StringLen($detail) > 2500 Then $detail = StringLeft($detail, 2500) #region --- Dialog Maker code Begin --- MsgBox(262208, "Program Information", $detail, 0) #endregion --- Dialog Maker code End --- SplashOff() Else MsgBox(262208, "$dev", $dev, 0) EndIf Case $msg = $Button_set ; Set currently selected drive as default $name = GUICtrlRead($Combo_cd) IniWrite($inifle, "Drives", "default", $name) Case $msg = $Button_scan ; Scan or Re-Scan for CD-Rom drives GUICtrlSetData($Combo_cd, "", "") ScanTheBus() Case $msg = $Button_i ; Program Information #region --- Dialog Maker code Begin --- MsgBox(262208, "Program Information", _ "name = " & $name & @LF & _ "device = " & $dev & @LF & _ "CD-Rom = " & $d & @LF & _ "Scsi ID = " & $id & @LF & _ "Scsi Port = " & $scsi & @LF & _ "Drive Letter = " & $drive, 0) #endregion --- Dialog Maker code End --- Case $msg = $Checkbox_scan ; Use previously scanned drive details If GUICtrlRead($Checkbox_scan) = $GUI_CHECKED Then $scan = 1 Else $scan = 4 EndIf IniWrite($inifle, "scsibus", "scan", $scan) Case $msg = $Combo_cd ; The available CD-Rom drives detected during a scan $name = GUICtrlRead($Combo_cd) SelectTheDrive() Case Else ;;; EndSelect WEnd Exit #endregion --- GuiBuilder generated code End --- Func GetCDRToolsPath() $pth = FileSelectFolder("Set the path for the CDRTools folder.", @ProgramFilesDir, 6, @ProgramFilesDir & "\CDRTools") If Not @error And StringMid($pth, 2, 2) = ":\" Then $cdrtools = $pth If FileExists($cdrtools & "\readcd.exe") And FileExists($cdrtools & "\cdda2wav.exe") Then IniWrite($inifle, "cdrtools", "path", $cdrtools) Else #region --- Dialog Maker code Begin --- MsgBox(262192, "CDRTools Content Error", _ "This program cannot work with the specified folder path" & @LF & _ "because required elements are missing from that folder.", 0) #endregion --- Dialog Maker code End --- $cdrtools = "" EndIf EndIf EndFunc ;=> GetCDRToolsPath Func GetDefaultDriveName() $def = IniRead($inifle, "Drives", "default", "") If $def <> $name And $def <> "" Then If StringInStr($devices, $def) > 0 Then $name = $def SelectTheDrive() EndIf EndIf EndFunc ;=> GetDefaultDriveName Func GetDriveLetters() FileDelete($drvinfo) Run(@ComSpec & " /c " & 'wmic /RECORD:"' & $drvinfo &'" CDROM', "", @SW_HIDE) Sleep(3000) $begin = TimerInit() While 1 If FileExists($drvinfo) Then $cnt = _FileCountLines($drvinfo) $names = StringSplit($devices, "|") ;MsgBox(262208, "$cnt $drvinfo", $cnt & " " & $drvinfo) $devices = "" $drvxml = FileOpen($drvinfo, 0) For $c = 1 To $cnt For $n = 1 To $names[0] $nme = $names[$n] $drvnam = StringReplace($nme, "'", " ") $drvnam = StringStripWS($drvnam, 7) $line = FileReadLine($drvxml, $c) $line = StringSplit($line, "(Standard CD-ROM drives)", 1) $line = $line[1] $drvnam = StringSplit($drvnam, " ") For $dr = 1 To $drvnam[0] If StringInStr($line, $drvnam[$dr]) < 1 Then ExitLoop If $dr = $drvnam[0] Then $line = StringStripWS($line, 3) $drive = StringRight($line, 2) $name = "(" & $drive & ") " & $nme If $devices = "" Then $d = 1 IniWrite($inifle, "CD-Rom_" & $d, "name", $name) IniWrite($inifle, "CD-Rom_" & $d, "drive", $drive) IniWrite($inifle, "Drives", $d, $name) $devices = $name Else $d = $d + 1 IniWrite($inifle, "CD-Rom_" & $d, "name", $name) IniWrite($inifle, "CD-Rom_" & $d, "drive", $drive) IniWrite($inifle, "Drives", $d, $name) $devices = $devices & "|" & $name EndIf EndIf Next Next Next FileClose($drvxml) ExitLoop EndIf $dif = TimerDiff($begin) If $dif > 9000 Then ExitLoop WEnd ;MsgBox(262208, "$d $name", $d & " " & $name) EndFunc ;=> GetDriveLetters Func GetDriveNames() $names = IniReadSection($inifle, "Drives") If Not @error Then $devices = "" For $n = 1 To $names[0][0] If $names[$n][0] <> "default" Then $name = $names[$n][1] If $devices = "" Then $devices = $name Else $devices = $devices & "|" & $name EndIf EndIf Next EndIf EndFunc ;=> GetDriveLetters Func ScanTheBus() SplashTextOn("", "Please Wait!", 200, 70, -1, -1, 33) _RunDOS('"' & $cdrtools & '\readcd.exe"' & " -scanbus>scanbus.log") Sleep(2000) If FileExists($scanlog) Then $d = 0 $devices = "" $cnt = _FileCountLines($scanlog) $scanbus = FileOpen($scanlog, 0) For $c = 1 To $cnt $line = FileReadLine($scanbus, $c) If StringInStr($line, "Removable CD-ROM") > 0 Then $line = StringReplace($line, "Removable CD-ROM", "") $line = StringStripWS($line, 3) $dev = StringLeft($line, 5) $id = StringMid($dev, 3, 1) $name = StringStripWS(StringMid($line, 12), 3) $d = $d + 1 IniWrite($inifle, "CD-Rom_" & $d, "name", $name) IniWrite($inifle, "CD-Rom_" & $d, "device", $dev) IniWrite($inifle, "CD-Rom_" & $d, "id", $id) IniWrite($inifle, "CD-Rom_" & $d, "port", $scsi) If $devices = "" Then $devices = $name Else $devices = $devices & "|" & $name EndIf ElseIf StringInStr($line, "scsibus") > 0 Then $scsi = StringReplace($line, "scsibus", "") $scsi = StringReplace($scsi, ":", "") $scsi = StringStripWS($scsi, 3) EndIf Next FileClose($scanbus) GetDriveLetters() ; GetDefaultDriveName() ; GUICtrlSetData($Combo_cd, $devices, $name) EndIf SplashOff() EndFunc ;=> ScanTheBus Func SelectTheDrive() $sects = IniReadSectionNames($inifle) For $s = 1 To $sects[0] $d = $s $sect = IniRead($inifle, "CD-Rom_" & $d, "name", "") If $name = $sect Or $name = "'" & $sect & "'" Then $dev = IniRead($inifle, "CD-Rom_" & $d, "device", "") $id = IniRead($inifle, "CD-Rom_" & $d, "id", "") $scsi = IniRead($inifle, "CD-Rom_" & $d, "port", "") $drive = IniRead($inifle, "CD-Rom_" & $d, "drive", "") ;MsgBox(262208, "Program Information", "Found") ExitLoop EndIf Next EndFunc ;=> SelectTheDrive