Thanks to the comments of your code, I decided to start the programming.
The last time I wrote a program was 22 years ago in C or Fortran and I've never used object programming language.
But after 3 weeks of heavy documentation reading I've obtained all that I wanted.
I guess it could be written better (I have myself rewrite lot of lines that I wrote the first week)
So, let me introduce you
Comic Book CBx-To-CBx Convert & Resize v2 !!!
FEATURES
+all of V1.4
- option for a custom ratio transformation (instead of standard height and weight) and quality
- option to create a backup file (with choice of a prefix and/or suffix)
- option to check if extension is in keeping with the inside format of the archive and rename it (I had lot of cbz that were rar file or cbr that were zip file, and dopus was not handling correctly their bad name)
- option to make compression only if the average image size in the archive is over a custom size (I've got 300 Mo cbr with only 50 pages...)
- Selected files can be selected with "Flat view" activated. The compressed file will be on the same directory as original (if destination "source" is chosen)
- Configuration saved between 2 sessions
- Changed the way that conversion is called : before, if the original file contains subfolder the result have only the last alphabetic folder converted. Now, they are all converted.
- Lots of logs added
- bug fix on custom widht and height
- minor bug fix when the output format was cb7
NB: If you choose cbr as destination format, you MUST have winrar installed on your platform and you must have activated the rar plugin in Dopus (Preferences / Zip & Other Archives / Archive and VFS Plugins)
I've been heavily using it for one month, and I've not found anymore bugs.
I hope you will find this dialogbox useful.
INSTALLATION
Use either provided button (.dcf) or attached VBScript code with dialog resource (please scroll down).
CBx to CBX V2.1.1.dcf (59.3 KB)
I've made a beautiful icon :
The script:
@script VBScript
'--------------------------------------------------------------------------------
' CBx to CBx
' This script converts and resizes comic book files
' Includes versatile dialog for maximal user friendlines
' Date: 2017-01-31
' Author: Dalibor Puljiz, Croatia
' ' Thanks:
' - Directory Opus developers for the greatest software
' - @Playful for providing great insight on DOpus object
' through his first conversion script: 'cbr to cbz'
' http://resource.dopus.com/viewtopic.php?f=35&t=27206
'Forum support:
' https://resource.dopus.com/t/button-comic-book-cbx-to-cbx-convert-resize/24719
'History:
' v1.0: 2017-01-28 Initial Release
' v1.1: 2017-01-29 Ability to set custom temp folder such as RAM disk
' v1.2: 2017-01-31 Ability to save TEMP folder for next script call (first official release)
' v1.3: 2017-02-13
' New user options:
' (1) Do Not Resize
' (2) Deselect file after conversion
' Enforced error prevention:
' (1) Make sure no protected files from deletion dialog pops-out
' (2) Removes spaces before extension to prevent errors
' v1.4: 2017-02-14
' Added quality change option, Auto mode as default
' v2.0: 2019-01-18
' Evolution by Olivier Evesque, France
' Added option for a custom ratio transformation (instead of standard height and weight) and quality
' Added option to create a backup file (with choice of a prefix and/or suffix)
' Added option to check if extension is in keeping with the inside format of the archive and rename it
' Added option to make compression only if the average image size in the archive is over a custom size
' Selected files can be selected with "Flat view" activated. The compressed file will be on the same directory as original (if destination "source" is chosen)
' Changed the way that conversion is called : before, if the original file contains subfolder the result have only the last alphabetic folder converted. Now, they are all converted.
' Lots of log added
' bug fix on custom widht and height
' minor bug fix when the output format was cb7
' If you choose cbr as destination format, you MUST have winrar installed on your platform and you must have activated the rar plugin in Dopus (Preferences / Zip & Other Archives / Archive and VFS Plugins)
'--------------------------------------------------------------------------------
Option Explicit
Const WindowsFolder = 0
Const SystemFolder = 1
Const TemporaryFolder = 2
Function OnClick(ClickData)
Dim dlgO: Dim msgD
Dim ixList: Dim ixLabel: Dim ixXPos: Dim ixWPos: Dim ixHPos
Dim lngNewWidth: Dim lngNewHeight: Dim strResizeMode
Dim blnUseTempFolder: Dim strTmpF
Dim blnDeselectAfterConversion
Dim strUseSD
Dim fsT: Dim strOutFormat
Dim strTgtLst: Dim strDirTgt
Dim currentFile: Dim retF
Dim cmdDS
Dim strRatio: Dim StrQuality
Dim StrPrefix: Dim StrSuffix
Dim fso, f
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim header
Dim CountedRenamedFiles
dim backup
CountedRenamedFiles=0
'Initialize dialog box using resource template
Set dlgO = ClickData.Func.Dlg
dlgO.template = "dlgSetFileSize"
dlgO.detach = True
dlgO.Show
'typable field will be saved only after cliking OK
DOpus.vars("CBxToCBxCustomRatio").Persist = False
DOpus.vars("CBxToCBxCustomQuality").Persist = False
DOpus.vars("CBxToCBxCustomPrefix").Persist = False
DOpus.vars("CBxToCBxCustomSuffix").Persist = False
DOpus.vars("CBxToCBxCustomAvgSize").Persist = False
'Set defaults
'Resolution: Custom Ratio
dlgO.Control("lstResolution").Value = 22 'Custom Ratio
lngNewHeight = 1280
lngNewWidth = 800
strResizeMode = "Auto"
dlgO.Control("chkOrientationMode").Value = 2 'Auto
dlgO.Control("chkOrientationMode").Label = "Auto per image"
'Outptut format: cbz and Auto dimension
dlgO.Control("cbxOutputFormat").Value = 1 ' .cbz (cbz)
strOutFormat = ".cbz"
'Lister: Destination
strUseSD = "source"
dlgO.Control("radUseSource").Value = True
dlgO.Control("radUseDestination").Value = False
'Temp section
dlgO.Control("btnSelectFolder").Enabled = Not blnUseTempFolder
dlgO.Control("tbxCustomTempFolder").Value = strTmpF
dlgO.Control("radWindowsTemp").Value = blnUseTempFolder
dlgO.Control("radCustomTempFolder").Value = Not blnUseTempFolder
blnDeselectAfterConversion = False
'Pickup where you left off
'Temp folder: Windows %Temp% folder recommended, most likely SSD disk anyway)
'However if you use some RAM disk (such as AMD RAM Disk), you may wish to keep it on
Set fsT = CreateObject("Scripting.FileSystemObject")
If DOpus.vars("CBxToCBxTempFolder").Exists Then
strTmpF = DOpus.vars.get("CBxToCBxTempFolder")
Else
strTmpF = CStr(fsT.GetSpecialFolder(TemporaryFolder))
DOpus.vars.set("CBxToCBxTempFolder")= strTmpF
DOpus.vars("CBxToCBxTempFolder").Persist = True
End If
If DOpus.vars("CBxToCBxUseWindowsTemp").Exists Then
blnUseTempFolder = CBool(DOpus.vars.get("CBxToCBxUseWindowsTemp"))
Else
blnUseTempFolder = True
DOpus.vars.set("CBxToCBxUseWindowsTemp") = blnUseTempFolder
DOpus.vars("CBxToCBxUseWindowsTemp").Persist = True
End If
If DOpus.vars("CBxToCBxCustomRatio").Exists Then
dlgO.Control("tbxRatio").value=DOpus.vars("CBxToCBxCustomRatio")
end if
If DOpus.vars("CBxToCBxCustomQuality").Exists Then
dlgO.Control("tbxQuality").value=DOpus.vars("CBxToCBxCustomQuality")
end if
If DOpus.vars("CBxToCBxCustomPrefix").Exists Then
dlgO.Control("tbxPrefix").value=DOpus.vars("CBxToCBxCustomPrefix")
end if
If DOpus.vars("CBxToCBxCustomSuffix").Exists Then
dlgO.Control("tbxSuffix").value=DOpus.vars("CBxToCBxCustomSuffix")
end if
If DOpus.vars("CBxToCBxCustomAvgSize").Exists Then
dlgO.Control("TbxMaxAvgSize").value=DOpus.vars("CBxToCBxCustomAvgSize")
end if
'Keep running in detached mode so we can run events asynchronously
Do
Set msgD = dlgO.GetMsg()
'Preliminary pre-setup orientation modes, so later change may run smoothly
If msgD.Control = "chkOrientationMode" Then
Select Case dlgO.Control("chkOrientationMode").Value
Case 0
strResizeMode = "Landscape"
dlgO.Control("chkOrientationMode").Label = "Force Landscape"
Case 1
strResizeMode = "Portrait"
dlgO.Control("chkOrientationMode").Label = "Force Portrait"
Case 2
strResizeMode = "Auto"
dlgO.Control("chkOrientationMode").Label = "Auto per image"
End Select
End If
'Check everything
Select Case msgD.Control
Case "chkDoNotResize"
dlgO.Control("chkOrientationMode").Enabled = Not (dlgO.Control("chkDoNotResize").Value)
dlgO.Control("ChkAutoCompress").value = Not (dlgO.Control("chkDoNotResize").Value)
If dlgO.Control("chkDoNotResize").Value Then strResizeMode = "Do Not Resize"
Case "lstResolution", "chkOrientationMode", "imgRWidth", "imgRHeight"
'Get actual content label so to skip hard translate side-side coding
ixList = dlgO.Control("lstResolution").Value
ixLabel = dlgO.Control("lstResolution").GetItemAt(ixList).name 'ie: Android Tablet: 2560 × 1440
If InStr(1,ixLabel,"Custom",1) = 0 Then
dlgO.Control("imgRWidth").Enabled = False
dlgO.Control("imgRHeight").Enabled = False
dlgO.Control("tbxRatio").Enabled = False
dlgO.Control("tbxQuality").Enabled = False
strRatio=0
ixXPos = InStr(1,ixLabel,"×") 'W×H separated by ×
ixWPos = InStrRev(ixLabel," ",ixXPos-2) 'find first space backwards
ixHPos = InStr(ixXPos+2,ixLabel," ") 'find next space forward
If ixHPos = 0 Then ixHPos = Len(ixLabel) 'if not found assume max string length
Select Case strResizeMode
Case "Portrait", "Auto"
lngNewHeight = Mid(ixLabel,ixWPos+1,(ixXPos-ixWPos-2))
lngNewWidth = Mid(ixLabel,ixXPos+2,(ixHPos-ixXPos-1))
Case "Landscape"
lngNewWidth = Mid(ixLabel,ixWPos+1,(ixXPos-ixWPos-2))
lngNewHeight = Mid(ixLabel,ixXPos+2,(ixHPos-ixXPos-1))
End Select
dlgO.Control("tbxNotifySelected").Value = "Exporting to WH " & lngNewWidth & "×" & lngNewHeight & " (" & strResizeMode & ")"
Elseif InStr(1,ixLabel,"Custom ratio",1) <> 0 Then
dlgO.Control("imgRWidth").Enabled = False
dlgO.Control("imgRHeight").Enabled = False
dlgO.Control("tbxRatio").Enabled = True
dlgO.Control("tbxQuality").Enabled = True
strRatio = dlgO.Control("tbxRatio").Value
StrQuality= dlgO.Control("tbxQuality").Value
dlgO.Control("tbxNotifySelected").Value = "Exporting to ratio " & strRatio & " and quality " & StrQuality
Else 'this test is for custom Width and Height
dlgO.Control("imgRWidth").Enabled = True
dlgO.Control("imgRHeight").Enabled = True
dlgO.Control("tbxRatio").Enabled = False
dlgO.Control("tbxQuality").Enabled = False
strRatio=0
StrQuality=90
Select Case strResizeMode
Case "Portrait", "Auto"
lngNewHeight = dlgO.Control("imgRWidth").Value
lngNewWidth = dlgO.Control("imgRHeight").Value
Case "Landscape"
lngNewWidth = dlgO.Control("imgRWidth").Value
lngNewHeight = dlgO.Control("imgRHeight").Value
End Select
dlgO.Control("tbxNotifySelected").Value = "Exporting to WH " & lngNewWidth & "×" & lngNewHeight & " (" & strResizeMode & ")"
End if
'Get other dialog options
Case "radUseSource", "radUseDestination"
Select Case msgD.Control
Case "radUseSource": strUseSD = "source"
Case "radUseDestination": strUseSD = "destin"
End Select
Case "cbxOutputFormat"
Select Case dlgO.Control("cbxOutputFormat").Value
Case 0: strOutFormat = ".cb7"
Case 1: strOutFormat = ".cbz"
Case 2: strOutFormat = ".cbr"
End Select
Case "radWindowsTemp", "radCustomTempFolder"
blnUseTempFolder = (msgD.Control = "radWindowsTemp")
dlgO.Control("btnSelectFolder").Enabled = Not blnUseTempFolder
Case "btnSelectFolder"
Set retF = dlgO.folder("Select TEMP folder", strTmpF, True)
If retF.result = True Then
strTmpF = retF
dlgO.Control("tbxCustomTempFolder").Value = retF
End If
Case "chkDeselectAsYouProgress"
blnDeselectAfterConversion = dlgO.Control("chkDeselectAsYouProgress").Value
'get info on typable fields
case "tbxRatio", "tbxQuality"
StrRatio = dlgO.Control("tbxRatio").Value
StrQuality= dlgO.Control("tbxQuality").Value
dlgO.Control("tbxNotifySelected").Value = "Exporting to ratio " & strRatio & " and quality " & StrQuality
case "tbxPrefix", "tbxSuffix"
StrPrefix= dlgO.Control("tbxPrefix").Value
StrSuffix= dlgO.Control("tbxSuffix").Value
case "TbxMaxAvgSize"
DOpus.vars.set("CBxToCBxCustomAvgSize")= dlgO.Control("TbxMaxAvgSize").Value 'I should have used a variable :-(
end select
if Msgd.control="ChkAutoCompress" then 'Click on Checkbox Compress only if ...
dlgO.Control("TbxMaxAvgSize").Enabled = not dlgO.Control("TbxMaxAvgSize").Enabled
End if
if Msgd.control="chkBackup" then 'Click on backup file Compress only if ...
dlgO.Control("tbxSuffix").Enabled = not dlgO.Control("tbxSuffix").Enabled
dlgO.Control("tbxPrefix").Enabled = not dlgO.Control("tbxPrefix").Enabled
end if
Loop While msgD
'If user set Cancel exit function
If dlgO.Result = 0 Then
Exit Function
Else
'Saving for next session the typable field.
DOpus.vars.set("CBxToCBxCustomRatio")= strRatio
DOpus.vars.set("CBxToCBxCustomQuality")= strQuality
DOpus.vars.set("CBxToCBxCustomPrefix")= StrPrefix
DOpus.vars.set("CBxToCBxCustomSuffix")= StrSuffix
DOpus.vars("CBxToCBxCustomRatio").Persist = True
DOpus.vars("CBxToCBxCustomQuality").Persist = True
DOpus.vars("CBxToCBxCustomPrefix").Persist = True
DOpus.vars("CBxToCBxCustomSuffix").Persist = True
DOpus.vars("CBxToCBxCustomAvgSize").Persist = True
End if
'Proceed otherwise
Select Case strUseSD
Case "source"
strTgtLst = CStr(ClickData.Func.sourcetab.path)
Case "destin"
strTgtLst = Cstr(ClickData.Func.desttab.path)
End Select
If blnUseTempFolder Then strTmpF = CStr(fsT.GetSpecialFolder(TemporaryFolder))
DOpus.vars.set("CBxToCBxUseWindowsTemp") = blnUseTempFolder
If Not blnUseTempFolder Then DOpus.vars.set("CBxToCBxTempFolder")= strTmpF
Set cmdDS = DOpus.Create.Command()
'cmdDS.deselect = True
'Log actions
Dopus.output ("***************************************")
DOpus.Output("Target folder: " & strTgtLst)
DOpus.Output("Export format: " & strOutFormat)
If strRatio = 0 then
DOpus.Output("Export Resolution WH: " & lngNewWidth & "×" & lngNewHeight & " mode: " & strResizeMode)
else
DOpus.Output("Export with Ratio: " & StrRatio & " and quality " & StrQuality)
End if
If dlgO.control("chkBackup").value then
Dopus.output ("Make a Backup of converted file")
backup=true
Else
Dopus.output ("Overwriting existing file")
backup=false
End if
If dlgO.control("ChkAutoCompress").value then
Dopus.output ("Convert file only if Avg size is bigger than " & dlgO.Control("TbxMaxAvgSize").Value & " Mo" )
Else
Dopus.output ("Convert all files")
End if
'Loop files
For Each currentFile In clickData.func.sourcetab.selected_files
'we're checking if the extension is compatible with the internal compress algorithm, If not, we are renaming file
If dlgO.control("chkCheckName").value then
If clickData.func.sourcetab.selected.count = 0 Then
DOpus.Output " Aucune selection"
Else
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(currentFile.RealPath, ForReading)
header=lcase(f.Read(2))
f.close
if (lcase(currentfile.ext)=".cbz" and header="pk") or (lcase(currentfile.ext)=".cbr" and header="ra") or (lcase(currentfile.ext)=".cb7" and header="7z") then
'Dopus.output "File " & currentFile.RealPath & " have a correct extension"
else
Dopus.output " File " & currentFile.RealPath & " have NOT a correct extension"
CountedRenamedFiles= CountedRenamedFiles +1
select case header
case "pk"
' cmdDS.RunCommand("Rename PATTERN=* FROM " & currentFile.name & " TO " & currentFile.name_stem & ".cbz" )
Dopus.output " -->Rename """ & currentfile.path & "\" & currentFile.name & """ TO """ & currentfile.path & "\" & currentFile.name_stem & ".cbz"
cmdDS.RunCommand("Rename """ & currentfile.path & "\" & currentFile.name & """ TO """ & currentfile.path & "\" & currentFile.name_stem & ".cbz" )
case "ra"
Dopus.output " -->Rename """ & currentfile.path & "\" & currentFile.name & """ TO """ & currentfile.path & "\" & currentFile.name_stem & ".cbr"
cmdDS.RunCommand("Rename """ & currentfile.path & "\" & currentFile.name & """ TO """ & currentfile.path & "\" & currentFile.name_stem & ".cbr" )
case "7z"
Dopus.output " -->Rename """ & currentfile.path & "\" & currentFile.name & """ TO """ & currentfile.path & "\" & currentFile.name_stem & ".cb7"
cmdDS.RunCommand("Rename """ & currentfile.path & "\" & currentFile.name & """ TO """ & currentfile.path & "\" & currentFile.name_stem & ".cb7" )
case else
Dopus.output (" -->" & currentfile.name & " is not recognized as a comic book")
end Select
End If
End If
Else
cmdDS.Clear()
cmdDS.ClearFiles()
If ((LCase(currentFile.ext) = ".cbr") Or (LCase(currentFile.ext) = ".cbz") Or (LCase(currentFile.ext) = ".cb7")) Then
DOpus.Output(" Processing: " & currentFile.name_stem)
Select Case strUseSD
Case "source"
strTgtLst = CStr(currentfile.path) ' source path have been previously initialized wut it can change if you have selected files on different subdirectory on a lister with "Flatview"
Case "destin"
strTgtLst = Cstr(ClickData.Func.desttab.path)
End Select
If dlgO.control("ChkAutoCompress").value then 'we are checking if the size of the file divided by then number of files is greater than the wanted value.
'on va compter les fichiers
If cdbl((currentFile.size.cy*10000/(1024^2))/FileCountRecursive(currentFile)) >= cdbl(replace(dlgO.Control("TbxMaxAvgSize").Value,".",",")) Then 'Cdbl is for convertit txt to number, and the replace is to accept different number format (1,2 ou 1.2)
dopus.output " File " & currentFile & " have a size of " & currentFile.size.cy*10000/(1024^2) & "and have "& FileCountRecursive(currentFile) & " files so " & (currentFile.size.cy*10000/(1024^2))/FileCountRecursive(currentFile) & " Mo on average"
Call CBR2CB7(currentFile, strTgtLst, strOutFormat, lngNewWidth, lngNewHeight, strResizeMode, strTmpF, strRatio, strQuality, StrPrefix, strSuffix, backup)
If Right(currentFile.name_stem,1) = " " Then
cmdDS.RunCommand("Rename FROM """ & currentFile.name & """ TO """ & Trim(currentFile.name_stem) & currentFile.ext)
currentFile.Update
end If
If blnDeselectAfterConversion Then
cmdDS.RunCommand("Select """ & currentFile.name & """ DESELECT")
End If
Else
dopus.output " File " & currentFile & " have " & FileCountRecursive(currentFile) & " file and it size is " & currentFile.size.cy*10000/(1024^2) & " so " & (currentFile.size.cy*10000/(1024^2))/FileCountRecursive(currentFile) & " Mo on average -->No convertion needed"
End if
Else
Call CBR2CB7(currentFile, strTgtLst, strOutFormat, lngNewWidth, lngNewHeight, strResizeMode, strTmpF, strRatio, strQuality, StrPrefix, strSuffix, backup)
If Right(currentFile.name_stem,1) = " " Then
cmdDS.RunCommand("Rename FROM """ & currentFile.name & """ TO """ & Trim(currentFile.name_stem) & currentFile.ext)
currentFile.Update
end If
If blnDeselectAfterConversion Then
cmdDS.RunCommand("Select """ & currentFile.name & """ DESELECT")
Dopus.output "on compresse dans tout les cas"
End if
End if
Else
Set dlgO = clickData.func.Dlg
dlgO.buttons = "OK"
dlgO.message = "Comic book file extension not recognized (" + currentFile.name + ")"
dlgO.Show()
End If
End If
Next
If dlgO.control("chkCheckName").value then
Dopus.output CountedRenamedFiles & " files have been renamed"
End if
End Function
Function CBR2CB7(cFile, cFolder, expFmt, nWidth, nHeight, sRMode, sTempFolder, sRatio, sQuality, sPrefix, sSuffix, backup)
Dim cmdR7
Dim strLastFoundFolder: Dim strDestination: Dim dirHoldsFiles
Dim itmInspectFolder
Dim fso
Dim strT: Dim strTNmStm
'Extract files to temp folder
Set cmdR7 = DOpus.Create.Command()
cmdR7.Clear()
strTNmStm = Trim(cFile.name_stem)
strDestination = sTempFolder & "\" & strTNmStm
cmdR7.RunCommand("CreateFolder """ & strDestination & """ NOSEL")
cmdR7.SetDest(strDestination)
cmdR7.AddFile(cFile)
cmdR7.AddLine("Copy CLEARREADONLY=yes EXTRACT")
cmdR7.Run()
cmdR7.Clear()
'Make a Backup of the original file, with suffix and/or prefix
If backup then
DOpus.Output(" Renaming """ & cFile.path & "\" & cFile.name & """ TO """ & cFile.path & "\" & sPrefix & strTNmStm & sSuffix & cfile.ext & """" )
cmdR7.RunCommand("Rename """ & cFile.path & "\" & cFile.name & """ TO """ & cFile.path & "\" & sPrefix & strTNmStm & sSuffix & cfile.ext & """")
End if
'Find last folder that supposedly holds all the files
Set dirHoldsFiles = DOpus.FSUtil.ReadDir(strDestination,"rl")
strLastFoundFolder = strDestination
'first convert image in the principal temp directory
ConvertFileInDirectory strDestination, nHeight, nWidth,sRMode, sQuality, sRatio
Do While (Not dirHoldsFiles.complete) 'then convert image inside each subfolder
Set itmInspectFolder = dirHoldsFiles.Next
If itmInspectFolder.is_dir Then
strLastFoundFolder = itmInspectFolder.realpath
ConvertFileInDirectory strLastFoundFolder, nHeight, nWidth, sRMode, sQuality, sRatio
End If ' end condition if this a folder
Loop
'DOpus.Output(strLastFoundFolder)
'Compress
cmdR7.Clear()
cmdR7.ClearFiles()
cmdR7.SetDest(cFolder)
' cmdR7.AddFilesFromFolder(strLastFoundFolder)
cmdR7.AddFilesFromFolder(strDestination)
Select Case expFmt
Case ".cb7": cmdR7.AddLine("Copy ARCHIVE=.7z CREATEFOLDER=""" & strTNmStm + ".cb7""")
Case ".cbz": cmdR7.AddLine("Copy ARCHIVE CREATEFOLDER=""" & strTNmStm + ".cbz""")
Case ".cbr": cmdR7.AddLine("Copy ARCHIVE=.rar CREATEFOLDER=""" & strTNmStm + ".cbr""")
End Select
cmdR7.Run()
'Delete temp dir
cmdR7.Clear()
cmdR7.ClearFiles()
cmdR7.AddFile(strDestination)
cmdR7.AddLine("Delete NORECYCLE QUIET FORCE ")
cmdR7.Run()
'Final cleanup
dirHoldsFiles.Close()
End Function
Function ConvertFileInDirectory (folder, Height, Width, srMode, sQuality, sRatio)
dim cmdConvert
dim strT
'Resize
Set cmdConvert = DOpus.Create.Command()
cmdConvert.Clear()
cmdConvert.ClearFiles()
cmdConvert.AddFilesFromFolder(folder)
Select Case sRMode
Case "Portrait"
strT = "Image HEIGHT=" & Height
Case "Landscape"
strT = "Image WIDTH=" & Width
Case "Do Not Resize"
strT = "Image "
Case Else
strT = "Image HEIGHT=" & Height & " WIDTH=" & Width
End Select
If sRMode <> "Do Not Resize" Then
cmdConvert.AddLine(strT & " QUALITY=90 PRESERVEASPECTRATIO NOENLARGE REPLACE HERE")
if sRatio<>0 then
cmdConvert.Clear()
cmdConvert.Addline ("Image CONVERT QUALITY=" & sQuality & " PERCENT="& sRatio & " REPLACE HERE" )
end if
cmdConvert.Run()
End If
End function
function FileCountRecursive(filePath)
dim filecount: dim folderEnum: dim folderItem
Set folderEnum = DOpus.FSUtil.ReadDir(filePath,"r")
Do while (not folderEnum.complete)
set folderItem = folderEnum.Next
if not(folderItem.is_dir) then
fileCount=filecount+1
end if
loop
FileCountRecursive= fileCount
End function
The ressource:
<resources>
<resource name="dlgSetFileSize" type="dialog">
<dialog fontsize="8" height="286" lang="english" standard_buttons="ok,cancel" title="CBx-To-CBx Convert & Resize" width="445">
<control ellipsis="word" halign="left" height="8" name="static1" title="Set comic &book downsampling resolution" type="static" width="149" x="9" y="7" />
<control height="191" name="lstResolution" type="listbox" width="160" x="12" y="19">
<contents>
<item text="Android Tablet: 1024 × 600" />
<item text="Android Tablet: 1280 × 800" />
<item text="Android Tablet: 1920 × 1080 (Full HD)" />
<item text="Android Tablet: 2048 × 1536" />
<item text="Android Tablet: 2560 × 1440" />
<item text="Android Tablet: 2560 × 1600" />
<item text="Android Tablet: 3840 × 2160 (4k Ultra HD)" />
<item text="Android Tablet: 7680 × 4320 (8k)" />
<item text="Android Phone: 320 × 480" />
<item text="Android Phone: 480 × 800" />
<item text="Android Phone: 480 × 854" />
<item text="Android Phone: 540 × 960" />
<item text="Android Phone: 1280 × 720 (HD 720p)" />
<item text="Android Phone: 1920 × 1080 (Full HD 1080p)" />
<item text="Android Phone: 3840 × 2160 (4k Ultra HD)" />
<item text="iPhone5: 640 × 1136" />
<item text="iPhone7: 750 × 1334" />
<item text="iPhone7+: 1242 × 2208" />
<item text="iPad Mini: 1536 × 2048" />
<item text="iPad Air: 1536 × 2048" />
<item text="iPad Pro: 2048 × 2732" />
<item text="Use custom width and height" />
<item text="Use custom ratio" />
</contents>
</control>
<control halign="left" height="12" name="tbxNotifySelected" readonly="yes" title="Please select export resolution" type="edit" width="160" x="12" y="211" />
<control halign="left" height="8" name="static9" title="Resize orientation mode" type="static" width="84" x="183" y="16" />
<control height="10" name="chkDoNotResize" title="Do not resize, only repack" type="check" width="103" x="184" y="29" />
<control height="10" indeterminate="yes" name="chkOrientationMode" title="Orientation Mode" tristate="yes" type="check" width="100" x="184" y="41" />
<control halign="left" height="40" name="static5" title="Makes sure better size is\n preserved with aspect ratio\n kept intact (options: Auto,\n Portrait: keep height,\n Landscape: keep width)." type="static" width="100" x="198" y="54" />
<control halign="left" height="8" name="static6" title="Export comic book to:" type="static" width="79" x="325" y="16" />
<control height="10" name="radUseSource" title="Source lister" type="radio" width="55" x="331" y="28" />
<control checked="yes" height="10" name="radUseDestination" title="Destination lister" type="radio" width="74" x="331" y="40" />
<control halign="left" height="10" name="static4" title="Select custom size" type="static" width="69" x="191" y="103" />
<control halign="center" height="8" name="static2" title="Wi&dth" type="static" width="26" x="190" y="117" />
<control enable="no" halign="center" height="12" name="imgRWidth" title="1280" type="edit" width="28" x="222" y="115" />
<control halign="center" height="8" name="static3" title="Hei&ght" type="static" width="26" x="190" y="130" />
<control enable="no" halign="center" height="12" name="imgRHeight" title="800" type="edit" width="28" x="222" y="128" />
<control halign="left" height="8" name="static7" title="Output format" type="static" width="51" x="325" y="66" />
<control height="40" name="cbxOutputFormat" type="combo" width="51" x="329" y="76">
<contents>
<item text="7Z (.cb7)" />
<item text="ZIP (.cbz)" />
<item text="RAR (.cbr)" />
</contents>
</control>
<control halign="left" height="8" name="static9" title="Temporary folder" type="static" width="58" x="184" y="167" />
<control checked="yes" group="yes" height="10" name="radWindowsTemp" title="Windows TEMP folder" type="radio" width="86" x="190" y="178" />
<control height="10" name="radCustomTempFolder" type="radio" width="13" x="190" y="190" />
<control halign="left" height="12" name="tbxCustomTempFolder" readonly="yes" title="Select Your Temp Folder" type="edit" width="213" x="203" y="189" />
<control enable="no" height="14" name="btnSelectFolder" title="..." type="button" width="16" x="420" y="179" />
<control height="10" name="chkDeselectAsYouProgress" title="Progressively deselect file after conversion" type="check" width="158" x="190" y="209" />
<control halign="center" height="12" name="tbxQuality" readonly="yes" title="75" type="edit" width="21" x="399" y="122" />
<control halign="left" height="8" name="static10" title="Quality %" type="static" width="38" x="325" y="111" />
<control height="10" name="chkEnforceQuality" title="Change to max" type="check" width="65" x="330" y="123" />
<control halign="left" height="8" name="static11" title="%" type="static" width="7" x="424" y="124" />
<control halign="left" height="10" name="static8" title="Custom ratio (%)" type="static" width="56" x="190" y="144" />
<control enable="no" halign="center" height="12" name="tbxRatio" title="75" type="edit" width="16" x="253" y="142" />
<control halign="left" height="10" name="static12" title="with quality " type="static" width="42" x="275" y="144" />
<control enable="no" halign="center" height="12" name="tbxQuality" title="90" type="edit" width="16" x="322" y="143" />
<control checked="yes" height="10" name="chkBackup" title="Backup Converted File" type="check" width="92" x="190" y="224" />
<control halign="left" height="10" name="static13" title="Prefix" type="static" width="23" x="214" y="235" />
<control halign="left" height="10" name="static14" title="Suffix" type="static" width="23" x="312" y="235" />
<control halign="center" height="12" name="tbxPrefix" type="edit" width="62" x="241" y="234" />
<control halign="center" height="12" name="tbxSuffix" title="_old" type="edit" width="62" x="341" y="234" />
<control height="25" name="chkCheckName" type="check" width="15" x="189" y="248" />
<control halign="left" height="29" name="static16" title="Don't convert, just rename if extension is incorrect (cbr for Rar File, cbz for Zip, cb7 for 7z)" type="static" width="118" x="208" y="254" />
<control checked="yes" height="10" name="ChkAutoCompress" title="Compress only if average size is bigger than" type="check" width="163" x="204" y="156" />
<control halign="left" height="12" name="TbxMaxAvgSize" title="1,2" type="edit" width="32" x="369" y="155" />
<control halign="left" height="10" name="static17" title="Mo" type="static" width="12" x="406" y="156" />
</dialog>
</resource>
</resources>