home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 September / Chip_2002-09_cd1.bin / zkuste / vbasic / Data / Utils / XZipComp.exe / XceedEncoding.Cab / F112903_Manager.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  2001-04-27  |  60.9 KB  |  1,402 lines

  1. VERSION 5.00
  2. Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
  3. Object = "{BDC217C8-ED16-11CD-956C-0000C04E4C0A}#1.1#0"; "TABCTL32.OCX"
  4. Begin VB.Form frmManager 
  5.    BorderStyle     =   1  'Fixed Single
  6.    Caption         =   "Encoder / Decoder manager"
  7.    ClientHeight    =   5565
  8.    ClientLeft      =   150
  9.    ClientTop       =   720
  10.    ClientWidth     =   8565
  11.    LinkTopic       =   "Form1"
  12.    MaxButton       =   0   'False
  13.    OLEDropMode     =   1  'Manual
  14.    ScaleHeight     =   5565
  15.    ScaleWidth      =   8565
  16.    StartUpPosition =   3  'Windows Default
  17.    Begin TabDlg.SSTab tabManager 
  18.       Height          =   3840
  19.       Left            =   75
  20.       TabIndex        =   26
  21.       Top             =   75
  22.       Width           =   8415
  23.       _ExtentX        =   14843
  24.       _ExtentY        =   6773
  25.       _Version        =   393216
  26.       Style           =   1
  27.       Tabs            =   2
  28.       TabsPerRow      =   2
  29.       TabHeight       =   520
  30.       TabCaption(0)   =   "Encode"
  31.       TabPicture(0)   =   "Manager.frx":0000
  32.       Tab(0).ControlEnabled=   -1  'True
  33.       Tab(0).Control(0)=   "lbl(2)"
  34.       Tab(0).Control(0).Enabled=   0   'False
  35.       Tab(0).Control(1)=   "lbl(3)"
  36.       Tab(0).Control(1).Enabled=   0   'False
  37.       Tab(0).Control(2)=   "cmdSelectSourceFile"
  38.       Tab(0).Control(2).Enabled=   0   'False
  39.       Tab(0).Control(3)=   "fraEncodeMethod"
  40.       Tab(0).Control(3).Enabled=   0   'False
  41.       Tab(0).Control(4)=   "cmdEncode"
  42.       Tab(0).Control(4).Enabled=   0   'False
  43.       Tab(0).Control(5)=   "txtSourceFile"
  44.       Tab(0).Control(5).Enabled=   0   'False
  45.       Tab(0).Control(6)=   "txtDestinationFile"
  46.       Tab(0).Control(6).Enabled=   0   'False
  47.       Tab(0).Control(7)=   "cmdSelectDestinationFile"
  48.       Tab(0).Control(7).Enabled=   0   'False
  49.       Tab(0).ControlCount=   8
  50.       TabCaption(1)   =   "Decode"
  51.       TabPicture(1)   =   "Manager.frx":001C
  52.       Tab(1).ControlEnabled=   0   'False
  53.       Tab(1).Control(0)=   "txtDecodedFileName"
  54.       Tab(1).Control(1)=   "cmdSelectDecodeFolder"
  55.       Tab(1).Control(2)=   "txtDecodeFolder"
  56.       Tab(1).Control(3)=   "fraEncoded"
  57.       Tab(1).Control(4)=   "cmdDecode"
  58.       Tab(1).Control(5)=   "fraDecodeMethod"
  59.       Tab(1).Control(6)=   "lbl(1)"
  60.       Tab(1).Control(7)=   "lbl(0)"
  61.       Tab(1).ControlCount=   8
  62.       Begin VB.CommandButton cmdSelectDestinationFile 
  63.          Caption         =   "..."
  64.          Height          =   285
  65.          Left            =   6075
  66.          TabIndex        =   3
  67.          Top             =   900
  68.          Width           =   285
  69.       End
  70.       Begin VB.TextBox txtDestinationFile 
  71.          Height          =   285
  72.          Left            =   1500
  73.          OLEDropMode     =   2  'Automatic
  74.          TabIndex        =   2
  75.          Top             =   900
  76.          Width           =   4515
  77.       End
  78.       Begin VB.TextBox txtDecodedFileName 
  79.          Height          =   285
  80.          Left            =   -73350
  81.          OLEDropMode     =   2  'Automatic
  82.          TabIndex        =   17
  83.          Top             =   3375
  84.          Width           =   4590
  85.       End
  86.       Begin VB.CommandButton cmdSelectDecodeFolder 
  87.          Caption         =   "..."
  88.          Height          =   285
  89.          Left            =   -68700
  90.          TabIndex        =   16
  91.          Top             =   3000
  92.          Width           =   285
  93.       End
  94.       Begin VB.TextBox txtDecodeFolder 
  95.          Height          =   285
  96.          Left            =   -73350
  97.          OLEDropMode     =   2  'Automatic
  98.          TabIndex        =   15
  99.          Top             =   3000
  100.          Width           =   4590
  101.       End
  102.       Begin VB.Frame fraEncoded 
  103.          Caption         =   "Encoded file(s)"
  104.          Height          =   2415
  105.          Left            =   -74850
  106.          TabIndex        =   31
  107.          Top             =   450
  108.          Width           =   6240
  109.          Begin VB.ListBox lstEncodedFile 
  110.             Height          =   1620
  111.             Left            =   150
  112.             MultiSelect     =   2  'Extended
  113.             OLEDropMode     =   1  'Manual
  114.             Sorted          =   -1  'True
  115.             TabIndex        =   11
  116.             Top             =   675
  117.             Width           =   5940
  118.          End
  119.          Begin VB.CommandButton cmdAddEncodedFile 
  120.             Caption         =   "Add file"
  121.             Height          =   315
  122.             Left            =   150
  123.             OLEDropMode     =   1  'Manual
  124.             TabIndex        =   12
  125.             Top             =   300
  126.             Width           =   1140
  127.          End
  128.          Begin VB.CommandButton cmdRemoveEncodedFile 
  129.             Caption         =   "Remove file"
  130.             Height          =   315
  131.             Left            =   1350
  132.             TabIndex        =   13
  133.             Top             =   300
  134.             Width           =   1140
  135.          End
  136.          Begin VB.CommandButton cmdClearEncodedFile 
  137.             Caption         =   "Clear"
  138.             Height          =   315
  139.             Left            =   4950
  140.             TabIndex        =   14
  141.             Top             =   300
  142.             Width           =   1140
  143.          End
  144.       End
  145.       Begin VB.TextBox txtSourceFile 
  146.          Height          =   285
  147.          Left            =   1500
  148.          OLEDropMode     =   1  'Manual
  149.          TabIndex        =   0
  150.          Top             =   525
  151.          Width           =   4515
  152.       End
  153.       Begin VB.CommandButton cmdEncode 
  154.          Caption         =   "Encode"
  155.          Height          =   675
  156.          Left            =   6750
  157.          TabIndex        =   10
  158.          Top             =   3000
  159.          Width           =   1515
  160.       End
  161.       Begin VB.Frame fraEncodeMethod 
  162.          Caption         =   "Method"
  163.          Height          =   2190
  164.          Left            =   6450
  165.          TabIndex        =   30
  166.          Top             =   450
  167.          Width           =   1815
  168.          Begin VB.OptionButton optEncodeMethod 
  169.             Caption         =   "BinHex"
  170.             Height          =   240
  171.             Index           =   5
  172.             Left            =   150
  173.             TabIndex        =   9
  174.             Top             =   1800
  175.             Width           =   1515
  176.          End
  177.          Begin VB.OptionButton optEncodeMethod 
  178.             Caption         =   "Quoted printable"
  179.             Height          =   240
  180.             Index           =   4
  181.             Left            =   150
  182.             TabIndex        =   8
  183.             Top             =   1500
  184.             Width           =   1515
  185.          End
  186.          Begin VB.OptionButton optEncodeMethod 
  187.             Caption         =   "Base64"
  188.             Height          =   240
  189.             Index           =   2
  190.             Left            =   150
  191.             TabIndex        =   6
  192.             Top             =   900
  193.             Width           =   1515
  194.          End
  195.          Begin VB.OptionButton optEncodeMethod 
  196.             Caption         =   "UUEncode"
  197.             Height          =   240
  198.             Index           =   0
  199.             Left            =   150
  200.             TabIndex        =   4
  201.             Top             =   300
  202.             Value           =   -1  'True
  203.             Width           =   1515
  204.          End
  205.          Begin VB.OptionButton optEncodeMethod 
  206.             Caption         =   "Hexadecimal"
  207.             Height          =   240
  208.             Index           =   3
  209.             Left            =   150
  210.             TabIndex        =   7
  211.             Top             =   1200
  212.             Width           =   1515
  213.          End
  214.          Begin VB.OptionButton optEncodeMethod 
  215.             Caption         =   "XXEncode"
  216.             Height          =   240
  217.             Index           =   1
  218.             Left            =   150
  219.             TabIndex        =   5
  220.             Top             =   600
  221.             Width           =   1515
  222.          End
  223.       End
  224.       Begin VB.CommandButton cmdSelectSourceFile 
  225.          Caption         =   "..."
  226.          Height          =   285
  227.          Left            =   6075
  228.          TabIndex        =   1
  229.          Top             =   525
  230.          Width           =   285
  231.       End
  232.       Begin VB.CommandButton cmdDecode 
  233.          Caption         =   "Decode"
  234.          Height          =   675
  235.          Left            =   -68250
  236.          TabIndex        =   24
  237.          Top             =   3000
  238.          Width           =   1515
  239.       End
  240.       Begin VB.Frame fraDecodeMethod 
  241.          Caption         =   "Method"
  242.          Height          =   2190
  243.          Left            =   -68550
  244.          TabIndex        =   29
  245.          Top             =   450
  246.          Width           =   1815
  247.          Begin VB.OptionButton optDecodeMethod 
  248.             Caption         =   "BinHex"
  249.             Height          =   240
  250.             Index           =   5
  251.             Left            =   150
  252.             TabIndex        =   23
  253.             Top             =   1800
  254.             Width           =   1515
  255.          End
  256.          Begin VB.OptionButton optDecodeMethod 
  257.             Caption         =   "Quoted printable"
  258.             Height          =   240
  259.             Index           =   4
  260.             Left            =   150
  261.             TabIndex        =   22
  262.             Top             =   1500
  263.             Width           =   1515
  264.          End
  265.          Begin VB.OptionButton optDecodeMethod 
  266.             Caption         =   "XXEncode"
  267.             Height          =   240
  268.             Index           =   1
  269.             Left            =   150
  270.             TabIndex        =   19
  271.             Top             =   600
  272.             Width           =   1515
  273.          End
  274.          Begin VB.OptionButton optDecodeMethod 
  275.             Caption         =   "Hexadecimal"
  276.             Height          =   240
  277.             Index           =   3
  278.             Left            =   150
  279.             TabIndex        =   21
  280.             Top             =   1200
  281.             Width           =   1515
  282.          End
  283.          Begin VB.OptionButton optDecodeMethod 
  284.             Caption         =   "UUEncode"
  285.             Height          =   240
  286.             Index           =   0
  287.             Left            =   150
  288.             TabIndex        =   18
  289.             Top             =   300
  290.             Value           =   -1  'True
  291.             Width           =   1515
  292.          End
  293.          Begin VB.OptionButton optDecodeMethod 
  294.             Caption         =   "Base64"
  295.             Height          =   240
  296.             Index           =   2
  297.             Left            =   150
  298.             TabIndex        =   20
  299.             Top             =   900
  300.             Width           =   1515
  301.          End
  302.       End
  303.       Begin VB.Label lbl 
  304.          Caption         =   "Destination file"
  305.          Height          =   240
  306.          Index           =   3
  307.          Left            =   150
  308.          TabIndex        =   35
  309.          Top             =   900
  310.          Width           =   1215
  311.       End
  312.       Begin VB.Label lbl 
  313.          Caption         =   "Source file"
  314.          Height          =   240
  315.          Index           =   2
  316.          Left            =   150
  317.          TabIndex        =   34
  318.          Top             =   525
  319.          Width           =   915
  320.       End
  321.       Begin VB.Label lbl 
  322.          Caption         =   "Decoded file name"
  323.          Height          =   240
  324.          Index           =   1
  325.          Left            =   -74850
  326.          TabIndex        =   33
  327.          Top             =   3375
  328.          Width           =   1365
  329.       End
  330.       Begin VB.Label lbl 
  331.          Caption         =   "Decode in"
  332.          Height          =   240
  333.          Index           =   0
  334.          Left            =   -74850
  335.          TabIndex        =   32
  336.          Top             =   3000
  337.          Width           =   915
  338.       End
  339.    End
  340.    Begin MSComDlg.CommonDialog dlgCommon 
  341.       Left            =   7950
  342.       Top             =   3975
  343.       _ExtentX        =   847
  344.       _ExtentY        =   847
  345.       _Version        =   393216
  346.    End
  347.    Begin VB.Frame Frame3 
  348.       Height          =   90
  349.       Left            =   0
  350.       TabIndex        =   28
  351.       Top             =   4050
  352.       Width           =   8565
  353.    End
  354.    Begin VB.TextBox txtMessage 
  355.       Height          =   990
  356.       Left            =   75
  357.       Locked          =   -1  'True
  358.       MultiLine       =   -1  'True
  359.       ScrollBars      =   2  'Vertical
  360.       TabIndex        =   25
  361.       Top             =   4500
  362.       Width           =   8415
  363.    End
  364.    Begin VB.Label lbl 
  365.       Caption         =   "Error / Warning message"
  366.       Height          =   240
  367.       Index           =   4
  368.       Left            =   75
  369.       TabIndex        =   27
  370.       Top             =   4275
  371.       Width           =   2565
  372.    End
  373.    Begin VB.Menu mnuFile 
  374.       Caption         =   "File"
  375.       Begin VB.Menu mnuQuit 
  376.          Caption         =   "Quit"
  377.       End
  378.    End
  379.    Begin VB.Menu mnuOption 
  380.       Caption         =   "Option"
  381.    End
  382. Attribute VB_Name = "frmManager"
  383. Attribute VB_GlobalNameSpace = False
  384. Attribute VB_Creatable = False
  385. Attribute VB_PredeclaredId = True
  386. Attribute VB_Exposed = False
  387. ' Xceed Binary Encoding Library - Encoding Manager sample
  388. ' Copyright (c) 2001 Xceed Software Inc.
  389. ' [Manager.frm]
  390. ' This form module contains the main form's code. It demonstrates how to
  391. ' encode a file using different kinds of encoding methods, and decode an
  392. ' encoded file. It specifically uses:
  393. '  - The ProcessFile method.
  394. '  - The EndOfLineType, MaxLineLength, ContinueOnInvalidData,
  395. '    HeaderDataForkLength, HeaderResourceForkLength, HeaderFilename, EncodingFormat
  396. '    and IncludeHeaderFooter propeties.
  397. ' This file is part of the Xceed Binary Encoding Library sample applications.
  398. ' The source code in this file is only intended as a supplement to Xceed
  399. ' Binary Encoding Library's documentation, and is provided "as is", without
  400. ' warranty of any kind, either expressed or implied.
  401. Option Explicit
  402. 'The tabs from the SSTab control
  403. Private Enum enuTabManager
  404.     tmEncode = 0
  405.     tmDecode = 1
  406. End Enum
  407. 'The different encoding methods corresponding to the option buttons (the same
  408. 'for the Decode and Encode tabs)
  409. Private Enum enuEncodingMethod
  410.     emUUEncode = 0
  411.     emXXEncode = 1
  412.     emBase64 = 2
  413.     emHexadecimal = 3
  414.     emQuotedPrintable = 4
  415.     emBinHex = 5
  416. End Enum
  417. 'The values chosen by the user in the Option form
  418. Private m_lMaxLineLength As Long
  419. Private m_eEndOfLineType As EXBEndOfLineType
  420. Private m_bContinueOnInvalidData As Boolean
  421. 'The Encoding and Decoding method chosen by the user from the option buttons
  422. Private m_eEncodingMethod As enuEncodingMethod
  423. Private m_eDecodingMethod As enuEncodingMethod
  424. '====================================================================================
  425. ' EVENTS - triggered by the form and its controls
  426. '====================================================================================
  427. '====================================================================================
  428. 'Events relative to the encode process
  429. '====================================================================================
  430. '------------------------------------------------------------------------------------
  431. 'Select the source folder and file name that will be encoded by the
  432. 'encode action
  433. '------------------------------------------------------------------------------------
  434. Private Sub cmdSelectSourceFile_Click()
  435.     With dlgCommon
  436.         .FileName = ""
  437.         .DialogTitle = "Source file"
  438.         .Filter = "All type (*.*)|*.*"
  439.         .FilterIndex = 0
  440.         .Flags = cdlOFNExplorer
  441.         On Error Resume Next
  442.             'Show an Open common dialog to let the user select a file
  443.             Call .ShowOpen
  444.             If Err.Number = 0 Then
  445.                 txtSourceFile.Text = .FileName
  446.                 Call SetDestinationFileName
  447.             End If
  448.         On Error GoTo 0
  449.     End With
  450. End Sub
  451. '------------------------------------------------------------------------------------
  452. 'Select the destination and name of the file that will be created by the
  453. 'encode action
  454. '------------------------------------------------------------------------------------
  455. Private Sub cmdSelectDestinationFile_Click()
  456.     With dlgCommon
  457.         .FileName = ""
  458.         .DialogTitle = "Destination file"
  459.         .Filter = "Encoded (*.uue;*.xxe;*.b64;*.hex;*.hqx;*.qpr)|*.uue;*.xxe;*.b64;*.hex;*.hqx;*.qpr|UU encoded (*.uue)|*.uue|XX Encoded (*.xxe)|*.xxe|Base 64 (*.b64)|*.b64|Hexadecimal (*.hex)|*.hex|BinHex (*.hqx)|*.hqx|Quoted printable (*.qpr)|*.qpr|All type (*.*)|*.*"
  460.         .FilterIndex = 0
  461.         .Flags = cdlOFNExplorer
  462.         On Error Resume Next
  463.             'Show an Open common dialog to let the user select the destination
  464.             'file name
  465.             Call .ShowOpen
  466.             If Err.Number = 0 Then
  467.                 txtDestinationFile.Text = .FileName
  468.             End If
  469.         On Error GoTo 0
  470.     End With
  471. End Sub
  472. '------------------------------------------------------------------------------------
  473. 'The user changed the selected Encoding method
  474. '------------------------------------------------------------------------------------
  475. Private Sub optEncodeMethod_Click(Index As Integer)
  476.     'Change the extension of the destination (encoded) file name to be
  477.     'consistent with the newly selected encoding method
  478.     Call SetDestinationFileExtension(m_eEncodingMethod, Index)
  479.     m_eEncodingMethod = Index
  480. End Sub
  481. '------------------------------------------------------------------------------------
  482. 'Fill the destination file name to a default value if its empty
  483. '------------------------------------------------------------------------------------
  484. Private Sub txtSourceFile_LostFocus()
  485.     Call SetDestinationFileName
  486. End Sub
  487. '------------------------------------------------------------------------------------
  488. 'The mouse cursor dropped something in the source file text box
  489. '------------------------------------------------------------------------------------
  490. Private Sub txtSourceFile_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
  491.     Call EncodeDragDrop(Data, Effect)
  492. End Sub
  493. '------------------------------------------------------------------------------------
  494. 'The mouse cursor is moved over the source file text box
  495. '------------------------------------------------------------------------------------
  496. Private Sub txtSourceFile_OLEDragOver(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single, State As Integer)
  497.     Call EncodeDragOver(Data, Effect)
  498. End Sub
  499. '------------------------------------------------------------------------------------
  500. 'Do the encoding of the selected source file name to the destination file
  501. '------------------------------------------------------------------------------------
  502. Private Sub cmdEncode_Click()
  503.     'We do this SetFocus and DoEvents to make sure that, if the user did not used
  504.     'the mouse but rather a shortcut to the Encode button, the LostFocus event
  505.     'for the current active control and its handling are triggered.
  506.     cmdEncode.SetFocus
  507.     DoEvents
  508.     If Len(Trim(txtSourceFile.Text)) <> 0 Then
  509.         'There is something to Encode! Do the encoding
  510.         If EncodeFile(txtSourceFile.Text, m_eEncodingMethod, m_eEndOfLineType, m_lMaxLineLength, txtDestinationFile.Text) Then
  511.             'The encoding was successful, we clear the source and destination
  512.             'text boxes.
  513.             txtSourceFile.Text = ""
  514.             txtDestinationFile.Text = ""
  515.         End If
  516.     End If
  517. End Sub
  518. '====================================================================================
  519. 'Events relative to the decode process
  520. '====================================================================================
  521. '------------------------------------------------------------------------------------
  522. 'Add file(s) to the list of files to Decode
  523. '------------------------------------------------------------------------------------
  524. Private Sub cmdAddEncodedFile_Click()
  525.     Dim sFilenames As String
  526.     Dim sFilename As String
  527.     Dim sFolder As String
  528.     Dim nPos As Integer
  529.     Dim nOldPos As Integer
  530.         
  531.     With dlgCommon
  532.         .FileName = ""
  533.         .DialogTitle = "Encoded file"
  534.         .Filter = "Encoded (*.uue;*.xxe;*.b64;*.hex;*.hqx;*.qpr)|*.uue;*.xxe;*.b64;*.hex;*.hqx;*.qpr|UU encoded (*.uue)|*.uue|XX Encoded (*.xxe)|*.xxe|Base 64 (*.b64)|*.b64|Hexadecimal (*.hex)|*.hex|BinHex (*.hqx)|*.hqx|Quoted printable (*.qpr)|*.qpr|All type (*.*)|*.*"
  535.         .FilterIndex = 0
  536.         .Flags = cdlOFNExplorer Or cdlOFNAllowMultiselect
  537.         On Error Resume Next
  538.             'Show an Open common dialog to let the user select file(s)
  539.             Call .ShowOpen
  540.             If Err.Number = 0 Then
  541.                 sFilenames = .FileName
  542.                 
  543.                 nOldPos = 0
  544.                 'Extract each chosen files which are separated by a binary 0
  545.                 nPos = InStr(sFilenames, Chr(0))
  546.                 If nPos > 0 Then
  547.                     'More than one files were selected. The first 0 delimited string
  548.                     'contains the folder name of all the following file name.
  549.                     sFolder = Left$(sFilenames, nPos - 1)
  550.                     
  551.                     'We add a binary 0 to the user selected file names so that the
  552.                     'last file name of the string while also end by a 0 (the following
  553.                     'algorithm assume that a file name is always between two binary 0).
  554.                     sFilenames = sFilenames & Chr(0)
  555.                     
  556.                     nOldPos = nPos
  557.                     'Find the ending position of the file name string
  558.                     nPos = InStr(nOldPos + 1, sFilenames, Chr(0))
  559.                     While nPos > 0
  560.                         sFilename = Trim$(Mid$(sFilenames, nOldPos + 1, nPos - nOldPos - 1))
  561.                         If Len(sFilename) <> 0 Then
  562.                             'Add the extracted file name to the list box of file names
  563.                             Call AddEncodedFileToList(sFolder & "\" & sFilename)
  564.                         End If
  565.                         
  566.                         'Set the beginning position of the next file name (the end
  567.                         'of the previous one).
  568.                         nOldPos = nPos
  569.                         'Find the end position of the file name string
  570.                         nPos = InStr(nOldPos + 1, sFilenames, Chr(0))
  571.                     Wend
  572.                 Else
  573.                     'Only one file was selected by the user. Add it to the list box
  574.                     Call AddEncodedFileToList(sFilenames)
  575.                 End If
  576.             End If
  577.         On Error GoTo 0
  578.     End With
  579. End Sub
  580. '------------------------------------------------------------------------------------
  581. 'The mouse cursor dropped something on the Add File button of the Decode tab
  582. '------------------------------------------------------------------------------------
  583. Private Sub cmdAddEncodedFile_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
  584.     Call DecodeDragDrop(Data, Effect)
  585. End Sub
  586. '------------------------------------------------------------------------------------
  587. 'The mouse cursor is moved over the Add File button of the Decode tab
  588. '------------------------------------------------------------------------------------
  589. Private Sub cmdAddEncodedFile_OLEDragOver(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single, State As Integer)
  590.     Call DecodeDragOver(Data, Effect)
  591. End Sub
  592. '------------------------------------------------------------------------------------
  593. 'Remove the selected file from the "files to decode" list box
  594. '------------------------------------------------------------------------------------
  595. Private Sub cmdRemoveEncodedFile_Click()
  596.     Dim nFirstItem As Integer
  597.     Dim nNbItemRemoved As Integer
  598.     Dim nNbItemToRemove As Integer
  599.     Dim nNbItem As Integer
  600.     Dim i As Integer
  601.     With lstEncodedFile
  602.         nNbItemToRemove = .SelCount
  603.         If nNbItemToRemove <> 0 Then
  604.             'Check each file in the files to decode list box and, if it is
  605.             'selected, remove it from the list
  606.             nNbItem = .ListCount
  607.             For i = nNbItem - 1 To 0 Step -1
  608.                 If .Selected(i) Then
  609.                     Call .RemoveItem(i)
  610.                     nNbItemRemoved = nNbItemRemoved + 1
  611.                     nNbItem = nNbItem - 1
  612.                     If nNbItemRemoved = nNbItemToRemove Then
  613.                         'We removed the original number of files selected. We set
  614.                         'the new item to select in the file list (the file that
  615.                         'follows the last selected item) and exit the loop.
  616.                         nFirstItem = i
  617.                         Exit For
  618.                     End If
  619.                 End If
  620.             Next
  621.             
  622.             If nNbItem <> 0 Then
  623.                 'There is at least one file left in the list
  624.                 If nFirstItem >= nNbItem Then
  625.                     'There was no file after the last removed. We select the last
  626.                     'file of the list
  627.                     .Selected(nNbItem - 1) = True
  628.                 Else
  629.                     .Selected(nFirstItem) = True
  630.                 End If
  631.             End If
  632.         End If
  633.     End With
  634. End Sub
  635. '------------------------------------------------------------------------------------
  636. 'Remove all item from the Encoded file(s) list box
  637. '------------------------------------------------------------------------------------
  638. Private Sub cmdClearEncodedFile_Click()
  639.     lstEncodedFile.Clear
  640. End Sub
  641. '------------------------------------------------------------------------------------
  642. 'The user pressed a key while in the encoded file(s) list box.
  643. '------------------------------------------------------------------------------------
  644. Private Sub lstEncodedFile_KeyDown(KeyCode As Integer, Shift As Integer)
  645.     Select Case KeyCode
  646.         Case vbKeyDelete
  647.             Call cmdRemoveEncodedFile_Click
  648.             
  649.         Case vbKeyInsert
  650.             Call cmdAddEncodedFile_Click
  651.             
  652.     End Select
  653. End Sub
  654. '------------------------------------------------------------------------------------
  655. 'The mouse cursor dropped something in the encoded file(s) list box
  656. '------------------------------------------------------------------------------------
  657. Private Sub lstEncodedFile_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
  658.     Call DecodeDragDrop(Data, Effect)
  659. End Sub
  660. '------------------------------------------------------------------------------------
  661. 'The mouse cursor is moved over the encoded file(s) list box
  662. '------------------------------------------------------------------------------------
  663. Private Sub lstEncodedFile_OLEDragOver(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single, State As Integer)
  664.     Call DecodeDragOver(Data, Effect)
  665. End Sub
  666. '------------------------------------------------------------------------------------
  667. 'Select a folder that will contain the decoded files
  668. '------------------------------------------------------------------------------------
  669. Private Sub cmdSelectDecodeFolder_Click()
  670.     Dim sFolder As String
  671.     'By default the browse folder window will be positionned in the currently
  672.     'selected Decode folder
  673.     sFolder = txtDecodeFolder.Text
  674.     If BrowseFolder(Me.hwnd, "Decode folder", sFolder) Then
  675.         txtDecodeFolder.Text = sFolder
  676.     End If
  677. End Sub
  678. '------------------------------------------------------------------------------------
  679. 'The user changed the selected Decoding method
  680. '------------------------------------------------------------------------------------
  681. Private Sub optDecodeMethod_Click(Index As Integer)
  682.     m_eDecodingMethod = Index
  683. End Sub
  684. '------------------------------------------------------------------------------------
  685. 'Do the decoding of the selected source file(s) to the selected destination
  686. '------------------------------------------------------------------------------------
  687. Private Sub cmdDecode_Click()
  688.     Dim sDecodedFileName As String
  689.     Dim matsEncodedFile() As String
  690.     Dim nNbEncodedFile As Integer
  691.     Dim i As Integer
  692.     sDecodedFileName = txtDecodedFileName.Text
  693.     If Len(sDecodedFileName) = 0 And m_eDecodingMethod <> emUUEncode And m_eDecodingMethod <> emXXEncode Then
  694.         'No decode file name was entered by the user. Use the file name of the
  695.         'first item in the "Encoded file(s)" list box
  696.         sDecodedFileName = RemoveFileExtension(ExtractFileName(lstEncodedFile.List(0))) & ".bin"
  697.         If Len(sDecodedFileName) <> 0 Then
  698.             txtDecodedFileName.Text = sDecodedFileName
  699.         End If
  700.     End If
  701.     nNbEncodedFile = lstEncodedFile.ListCount
  702.     If nNbEncodedFile <> 0 Then
  703.         'Fill a string array with all the encoded file names of the list box
  704.         ReDim matsEncodedFile(nNbEncodedFile)
  705.         For i = 0 To nNbEncodedFile - 1
  706.             matsEncodedFile(i) = lstEncodedFile.List(i)
  707.         Next
  708.         
  709.         'Do the decoding
  710.         If DecodeFile(matsEncodedFile, nNbEncodedFile, m_eDecodingMethod, m_bContinueOnInvalidData, txtDecodeFolder.Text, sDecodedFileName) Then
  711.             'The decoding was successful. We clear the file source list box and the
  712.             'destination text box.
  713.             txtDecodeFolder = ""
  714.             txtDecodedFileName = ""
  715.             lstEncodedFile.Clear
  716.         End If
  717.     End If
  718. End Sub
  719. '====================================================================================
  720. 'Events - others
  721. '====================================================================================
  722. '------------------------------------------------------------------------------------
  723. 'Prepare the main window by assigning default values and last saved options
  724. '------------------------------------------------------------------------------------
  725. Private Sub Form_Load()
  726.     m_eEncodingMethod = emUUEncode
  727.     m_eDecodingMethod = emUUEncode
  728.     optEncodeMethod(m_eEncodingMethod).Value = True
  729.     optDecodeMethod(m_eDecodingMethod).Value = True
  730.     lstEncodedFile.Clear
  731.     Call LoadOption
  732.     Call tabManager_Click(0)
  733. End Sub
  734. '------------------------------------------------------------------------------------
  735. 'The mouse cursor dropped something on the form. Do something according to
  736. 'the selected tab.
  737. '------------------------------------------------------------------------------------
  738. Private Sub Form_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
  739.     Select Case tabManager.Tab
  740.         Case tmEncode ' Encode
  741.             Call EncodeDragDrop(Data, Effect)
  742.         
  743.         Case tmDecode ' Decode
  744.             Call DecodeDragDrop(Data, Effect)
  745.         
  746.     End Select
  747. End Sub
  748. '------------------------------------------------------------------------------------
  749. 'The mouse cursor is moved over the form
  750. '------------------------------------------------------------------------------------
  751. Private Sub Form_OLEDragOver(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single, State As Integer)
  752.     Select Case tabManager.Tab
  753.         Case tmEncode ' Encode
  754.             Call EncodeDragOver(Data, Effect)
  755.         
  756.         Case tmDecode ' Decode
  757.             Call DecodeDragOver(Data, Effect)
  758.         
  759.     End Select
  760. End Sub
  761. '------------------------------------------------------------------------------------
  762. 'The user selected the Option menu
  763. '------------------------------------------------------------------------------------
  764. Private Sub mnuOption_Click()
  765.     Dim xFrmOption As frmOption
  766.     'Show the options form
  767.     Set xFrmOption = New frmOption
  768.     If xFrmOption.ShowForm(m_lMaxLineLength, m_eEndOfLineType, m_bContinueOnInvalidData) Then
  769.         'The user clicked OK. Save the options in the registry
  770.         Call SaveOption
  771.     End If
  772.     Set xFrmOption = Nothing
  773. End Sub
  774. '------------------------------------------------------------------------------------
  775. 'The user selected the Quit option in the menu
  776. '------------------------------------------------------------------------------------
  777. Private Sub mnuQuit_Click()
  778.     End
  779. End Sub
  780. '------------------------------------------------------------------------------------
  781. 'The user changed the selected tab.
  782. '------------------------------------------------------------------------------------
  783. Private Sub tabManager_Click(PreviousTab As Integer)
  784.     'Change the default button according to the selected tab
  785.     Select Case tabManager.Tab
  786.         Case tmEncode ' Encode
  787.             cmdEncode.Default = True
  788.         
  789.         Case tmDecode ' Decode
  790.             cmdDecode.Default = True
  791.     End Select
  792. End Sub
  793. '====================================================================================
  794. ' FUNCTIONS
  795. '====================================================================================
  796. '====================================================================================
  797. 'Functions relative to the encode process
  798. '====================================================================================
  799. '------------------------------------------------------------------------------------
  800. 'The mouse cursor dropped something in the encode part of the form.
  801. 'If it's a file, we set the source file to encode to the first item (file) of the
  802. 'object. Hence, in a multiple files dropping, only the first is considered.
  803. '------------------------------------------------------------------------------------
  804. Private Sub EncodeDragDrop(ByRef xData As DataObject, _
  805.                            ByRef lEffect As Long)
  806.     Dim sFile As Variant
  807.     If xData.GetFormat(vbCFFiles) Then
  808.         txtSourceFile.Text = xData.Files(1)
  809.     End If
  810.     lEffect = vbDropEffectNone
  811. End Sub
  812. '------------------------------------------------------------------------------------
  813. 'The mouse cursor is moved over the encode part of the form.
  814. 'If it's a file, we show an icon telling the user (s)he can drop it.
  815. 'Otherwise, we show a no-drop icon.
  816. '------------------------------------------------------------------------------------
  817. Private Sub EncodeDragOver(ByRef xData As DataObject, _
  818.                            ByRef lEffect As Long)
  819.     If xData.GetFormat(vbCFFiles) Then
  820.         lEffect = vbDropEffectCopy
  821.     Else
  822.         lEffect = vbDropEffectNone
  823.     End If
  824. End Sub
  825. '------------------------------------------------------------------------------------
  826. 'If a destination file name already exist for encoding, change its extension for
  827. 'a new one appropriate to the new encoding method
  828. '------------------------------------------------------------------------------------
  829. Private Sub SetDestinationFileExtension(ByVal eOldEncodingMethod As enuEncodingMethod, _
  830.                                         ByVal eNewEncodingMethod As enuEncodingMethod)
  831.     Dim sDestinationFile As String
  832.     Dim sDestinationFileExtension As String
  833.     Dim bChangeExtension As Boolean
  834.     bChangeExtension = False
  835.     sDestinationFile = txtDestinationFile.Text
  836.     sDestinationFileExtension = UCase(ExtractFileExtension(sDestinationFile))
  837.     'If there is a destination file, we verify if its extension correspond to the
  838.     'old encoding method. If it correspond or if there is no extension, we set
  839.     'the flag that will do the change of extension below
  840.     If Len(sDestinationFile) <> 0 Then
  841.         Select Case eOldEncodingMethod
  842.             Case emUUEncode
  843.                 If sDestinationFileExtension = "UUE" Or _
  844.                    Len(sDestinationFileExtension) = 0 Then
  845.                     bChangeExtension = True
  846.                 End If
  847.                 
  848.             Case emXXEncode
  849.                 If sDestinationFileExtension = "XXE" Or _
  850.                    Len(sDestinationFileExtension) = 0 Then
  851.                     bChangeExtension = True
  852.                 End If
  853.                 
  854.             Case emBase64
  855.                 If sDestinationFileExtension = "B64" Or _
  856.                    Len(sDestinationFileExtension) = 0 Then
  857.                     bChangeExtension = True
  858.                 End If
  859.                 
  860.             Case emHexadecimal
  861.                 If sDestinationFileExtension = "HEX" Or _
  862.                    Len(sDestinationFileExtension) = 0 Then
  863.                     bChangeExtension = True
  864.                 End If
  865.                 
  866.             Case emQuotedPrintable
  867.                 If sDestinationFileExtension = "QPR" Or _
  868.                    Len(sDestinationFileExtension) = 0 Then
  869.                     bChangeExtension = True
  870.                 End If
  871.                 
  872.             Case emBinHex
  873.                 If sDestinationFileExtension = "HQX" Or _
  874.                    Len(sDestinationFileExtension) = 0 Then
  875.                     bChangeExtension = True
  876.                 End If
  877.                 
  878.         End Select
  879.     End If
  880.     'If we determined above that a change of extension is in order. Do it
  881.     If bChangeExtension Then
  882.         sDestinationFile = RemoveFileExtension(sDestinationFile) & StdFileExtension(eNewEncodingMethod)
  883.         txtDestinationFile.Text = sDestinationFile
  884.     End If
  885. End Sub
  886. '------------------------------------------------------------------------------------
  887. 'Set a default destination file name used for the encoding process. This file name
  888. 'is derived from the source file name.
  889. 'If a destination file name is already specified, do nothing.
  890. '------------------------------------------------------------------------------------
  891. Private Sub SetDestinationFileName()
  892.     Dim sEncodedFileName As String
  893.     sEncodedFileName = txtDestinationFile.Text
  894.     If Len(sEncodedFileName) = 0 Then
  895.         sEncodedFileName = RemoveFileExtension(txtSourceFile)
  896.         If Len(sEncodedFileName) <> 0 Then
  897.             txtDestinationFile.Text = sEncodedFileName
  898.             Call SetDestinationFileExtension(m_eEncodingMethod, m_eEncodingMethod)
  899.         End If
  900.     End If
  901. End Sub
  902. '------------------------------------------------------------------------------------
  903. 'Encode a file!
  904. '------------------------------------------------------------------------------------
  905. Private Function EncodeFile(ByVal sSourceFileName As String, _
  906.                             ByVal eMethod As enuEncodingMethod, _
  907.                             ByVal eEndOfLineType As EXBEndOfLineType, _
  908.                             ByVal lMaxLineLength As Long, _
  909.                             ByVal sEncodedFileName As String) As Boolean
  910.     Dim xEncoder As XceedBinaryEncoding
  911.     Dim lErrNumber As Long
  912.     Dim sErrDesc As String
  913.     Dim lBytesWritten As Long
  914.     Dim lBytesRead As Long
  915.     EncodeFile = False
  916.     Me.MousePointer = vbHourglass
  917.     'Create an instance of the Xceed binary encoding
  918.     Set xEncoder = New XceedBinaryEncoding
  919.     'Create and prepare the encoding format (XX, UU, BinHex, ...)
  920.     If CreateEncodingFormat(eMethod, xEncoder) Then
  921.         'Set the End of line type and the Maximum line length of the chosen
  922.         'encoding format
  923.         xEncoder.EncodingFormat.EndOfLineType = eEndOfLineType
  924.         xEncoder.EncodingFormat.MaxLineLength = lMaxLineLength
  925.         
  926.         If eMethod = emBinHex Then
  927.             'For the BinHex format, we must specify the data fork length and the
  928.             'resource fork length
  929.             xEncoder.EncodingFormat.HeaderDataForkLength = FileLen(sSourceFileName)
  930.             xEncoder.EncodingFormat.HeaderResourceForkLength = 0
  931.         End If
  932.         
  933.         'If no extension for the destination file name was provided by the user,
  934.         'we set a default one (according the the encoding method)
  935.         If Len(ExtractFileExtension(sEncodedFileName)) = 0 Then
  936.             sEncodedFileName = sEncodedFileName & StdFileExtension(eMethod)
  937.         End If
  938.         
  939.         'Clear the error message and status
  940.         txtMessage.Text = ""
  941.         lErrNumber = 0
  942.         If lErrNumber = 0 Then
  943.             On Error Resume Next
  944.                 'Encode the file, specifying that :
  945.                 '  We want to encode all the source file name (0,0 parameters)
  946.                 '  This is the end of data, no more file to encode will follow (True parameter)
  947.                 '  We want to overwrite a possibly existing destination file (False parameter)
  948.                 lBytesWritten = xEncoder.ProcessFile(sSourceFileName, 0, 0, bfpEncode, True, sEncodedFileName, False, lBytesRead)
  949.                 
  950.                 'Keep the eventual error code and description as it is reset by the
  951.                 'On error goto 0
  952.                 lErrNumber = Err.Number
  953.                 sErrDesc = Err.Description
  954.             On Error GoTo 0
  955.         End If
  956.         
  957.         If lErrNumber <> 0 Then
  958.             'Display the error that occured
  959.             txtMessage.Text = sSourceFileName & " fail to encode" & vbCrLf & vbCrLf & _
  960.                               sErrDesc & " (" & Hex(lErrNumber) & ")"
  961.         Else
  962.             'Display a message of success
  963.             EncodeFile = True
  964.             txtMessage = sSourceFileName & " successfully encoded in " & sEncodedFileName
  965.         End If
  966.     End If
  967.     'Deallocate the Encoding object. The encoding object will free
  968.     'the EncodingFormat object.
  969.     Set xEncoder = Nothing
  970.     Me.MousePointer = vbDefault
  971. End Function
  972. '====================================================================================
  973. 'Functions relative to the decode process
  974. '====================================================================================
  975. '------------------------------------------------------------------------------------
  976. 'The mouse cursor dropped something in the decode part of the form.
  977. 'If it's a file, we add it to the list of files to decode.
  978. 'The object dropped can contain more than one file.
  979. '------------------------------------------------------------------------------------
  980. Private Sub DecodeDragDrop(ByRef xData As DataObject, _
  981.                            ByRef lEffect As Long)
  982.     Dim sFile As Variant
  983.     If xData.GetFormat(vbCFFiles) Then
  984.         For Each sFile In xData.Files
  985.             Call AddEncodedFileToList(sFile)
  986.         Next
  987.     End If
  988.     lEffect = vbDropEffectNone
  989. End Sub
  990. '------------------------------------------------------------------------------------
  991. 'The mouse cursor is moved over the decode part of the form.
  992. 'If it's a file, we show an icon telling the user (s)he can drop it.
  993. 'Otherwise, we show a no-drop icon.
  994. '------------------------------------------------------------------------------------
  995. Private Sub DecodeDragOver(ByRef xData As DataObject, _
  996.                            ByRef lEffect As Long)
  997.     If xData.GetFormat(vbCFFiles) Then
  998.         lEffect = vbDropEffectCopy
  999.     Else
  1000.         lEffect = vbDropEffectNone
  1001.     End If
  1002. End Sub
  1003. '------------------------------------------------------------------------------------
  1004. 'Add the specified file name to the list box of file names to decode
  1005. '------------------------------------------------------------------------------------
  1006. Private Sub AddEncodedFileToList(ByVal sFilename As String)
  1007.     Dim i As Integer
  1008.     Dim bFound As Boolean
  1009.     Dim nNbItem As Integer
  1010.     Dim sDecodeFolder As String
  1011.     nNbItem = lstEncodedFile.ListCount
  1012.     'Do not allow more than 1000 files to be decoded in a one-shot decode
  1013.     If nNbItem < 1000 Then
  1014.         'Check if the file name is already in the list of files
  1015.         For i = 0 To nNbItem
  1016.             If lstEncodedFile.List(i) = sFilename Then
  1017.                 bFound = True
  1018.                 Exit For
  1019.             End If
  1020.         Next
  1021.         If Not bFound Then
  1022.             'Add the file name to the list
  1023.             Call lstEncodedFile.AddItem(sFilename)
  1024.             'If no decode folder is specified, set one to the folder name of the
  1025.             'added file name.
  1026.             sDecodeFolder = txtDecodeFolder.Text
  1027.             If Len(sDecodeFolder) = 0 Then
  1028.                 sDecodeFolder = ExtractFolder(sFilename)
  1029.                 If Len(sDecodeFolder) <> 0 Then
  1030.                     txtDecodeFolder.Text = sDecodeFolder
  1031.                 End If
  1032.             End If
  1033.             'If it's the first file added to the list, select it in the list
  1034.             If nNbItem = 0 Then
  1035.                 lstEncodedFile.Selected(0) = True
  1036.             End If
  1037.             
  1038.             'Set the decoding method according to the file name extension
  1039.             Select Case UCase(Right(sFilename, 4))
  1040.                 Case ".UUE"
  1041.                     m_eDecodingMethod = emUUEncode
  1042.                     optDecodeMethod(m_eDecodingMethod).Value = True
  1043.                     
  1044.                 Case ".XXE"
  1045.                     m_eDecodingMethod = emXXEncode
  1046.                     optDecodeMethod(m_eDecodingMethod).Value = True
  1047.                     
  1048.                 Case ".B64"
  1049.                     m_eDecodingMethod = emBase64
  1050.                     optDecodeMethod(m_eDecodingMethod).Value = True
  1051.                     
  1052.                 Case ".HEX"
  1053.                     m_eDecodingMethod = emHexadecimal
  1054.                     optDecodeMethod(m_eDecodingMethod).Value = True
  1055.                     
  1056.                 Case ".QPR"
  1057.                     m_eDecodingMethod = emQuotedPrintable
  1058.                     optDecodeMethod(m_eDecodingMethod).Value = True
  1059.                     
  1060.                 Case ".HQX"
  1061.                     m_eDecodingMethod = emBinHex
  1062.                     optDecodeMethod(m_eDecodingMethod).Value = True
  1063.                     
  1064.             End Select
  1065.         End If
  1066.     End If
  1067. End Sub
  1068. '------------------------------------------------------------------------------------
  1069. 'Decode file(s)!
  1070. 'If more than one source file was specified by the user; they will be decoded
  1071. 'in the same destination file (showing an example of the bAppend paramater).
  1072. '------------------------------------------------------------------------------------
  1073. Private Function DecodeFile(sEncodedFile() As String, _
  1074.                             ByVal nNbEncodedFile As String, _
  1075.                             ByVal eMethod As enuEncodingMethod, _
  1076.                             ByVal bContinueOnInvalidData As Boolean, _
  1077.                             ByVal sDecodeFolder As String, _
  1078.                             ByRef sDecodedFileName As String) As Boolean
  1079.     Dim xEncoder As XceedBinaryEncoding
  1080.     Dim lErrNumber As Long
  1081.     Dim sErrDesc As String
  1082.     Dim i As Integer
  1083.     Dim lBytesRead As Long
  1084.     DecodeFile = False
  1085.     Me.MousePointer = vbHourglass
  1086.     If Right(sDecodeFolder, 1) <> "\" Then
  1087.         'The Decode folder must end with a \
  1088.         sDecodeFolder = sDecodeFolder & "\"
  1089.     End If
  1090.         
  1091.     'Create an instance of the Xceed binary encoding
  1092.     Set xEncoder = New XceedBinaryEncoding
  1093.     'Create and prepare the encoding format (XX, UU, BinHex, ...)
  1094.     If CreateEncodingFormat(eMethod, xEncoder) Then
  1095.         'Tell whether or not we want to ignore invalid character in the file(s)
  1096.         'to decode
  1097.         xEncoder.EncodingFormat.ContinueOnInvalidData = bContinueOnInvalidData
  1098.         
  1099.         'Clear the error message and status
  1100.         txtMessage.Text = ""
  1101.         lErrNumber = 0
  1102.         
  1103.         If lErrNumber = 0 Then
  1104.             'Assume all will succeed.
  1105.             DecodeFile = True
  1106.             
  1107.             For i = 0 To nNbEncodedFile - 1
  1108.                 On Error Resume Next
  1109.                     'Decode a source file, specifying:
  1110.                     '  We want to decode all the source file name (0,0 parameters)
  1111.                     '  This is the end of data only for the last source file of the
  1112.                     '     EncodedFile array [(i = nbEncodedFile -1) parameter]
  1113.                     '  We know the destination folder. For the first call, sDecodedFileName
  1114.                     '     may be empty for 3 encoding method (BinHex, XX or UU). In that
  1115.                     '     case, the EncodingFormat object will have the Filename set
  1116.                     '     at the first call. (sDecodeFolder & sDecodedFileName parameter)
  1117.                     '  We want to overwrite a possibly existing destination file only
  1118.                     '     at the first call. For the other calls, we tell that we want
  1119.                     '     to append ( (i <> 0) parameter ).
  1120.                     Call xEncoder.ProcessFile(sEncodedFile(i), 0, 0, bfpDecode, (i = nNbEncodedFile - 1), sDecodeFolder & sDecodedFileName, (i <> 0), lBytesRead)
  1121.                     
  1122.                     If Len(sDecodedFileName) = 0 Then
  1123.                         'No file name was specified by the user. Read the one used by default
  1124.                         'by the encoding library (set at the first call).
  1125.                         sDecodedFileName = xEncoder.EncodingFormat.HeaderFilename
  1126.                     End If
  1127.                     
  1128.                     'Keep the eventual error code and description as it is reset by the
  1129.                     'On error goto 0
  1130.                     lErrNumber = Err.Number
  1131.                     sErrDesc = Err.Description
  1132.                 On Error GoTo 0
  1133.                 
  1134.                 If lErrNumber <> 0 Then
  1135.                     'Display the error that occured
  1136.                     DecodeFile = False
  1137.                     txtMessage = txtMessage & sEncodedFile(i) & " fail to decode" & vbCrLf & vbCrLf & _
  1138.                                  sErrDesc & " (" & Hex(lErrNumber) & ")" & vbCrLf
  1139.                     Exit For
  1140.                 Else
  1141.                     'Display a message of success
  1142.                     txtMessage = txtMessage & sEncodedFile(i) & " successfully decoded in " & sDecodeFolder & sDecodedFileName & vbCrLf
  1143.                 End If
  1144.             Next
  1145.         End If
  1146.     End If
  1147.     'Deallocate the Encoding object. The encoding object will free
  1148.     'the EncodingFormat object.
  1149.     Set xEncoder = Nothing
  1150.     Me.MousePointer = vbDefault
  1151. End Function
  1152. '====================================================================================
  1153. 'Functions - others
  1154. '====================================================================================
  1155. '------------------------------------------------------------------------------------
  1156. 'Create a new instance of an encoding format according to the specified
  1157. 'encoding method.
  1158. 'Set some properties to the encoding format object appropriate for the selected
  1159. 'encoding method.
  1160. '------------------------------------------------------------------------------------
  1161. Private Function CreateEncodingFormat(ByVal eMethod As enuEncodingMethod, _
  1162.                                       ByRef xEncoder As XceedBinaryEncoding) As Boolean
  1163.     Dim bCreateOK As Boolean
  1164.     bCreateOK = True
  1165.     'We instanciate a new encoding format, assigning it directly to the
  1166.     'EncodingFormat property of the XceedBinaryEncoding object.
  1167.     'The drawbacks to this programming method are :
  1168.     '   - we don't have access to the code completion for the EncodingFormat
  1169.     '   - setting a property of the EncodingFormat (a VB Object, or COM
  1170.     '     IDispatch) will use the QueryInterface COM scheme which is less
  1171.     '     efficient than calling a property from a object of type
  1172.     '     XceedBase64EncodingFormat for instance.
  1173.     'To see an example of how it could be done more efficiently and with the
  1174.     'help of code completion, consult the MemoryEncode sample application.
  1175.     On Error Resume Next
  1176.         Select Case eMethod
  1177.             Case emBase64
  1178.                 Set xEncoder.EncodingFormat = New XceedBase64EncodingFormat
  1179.             
  1180.             Case emBinHex
  1181.                 Set xEncoder.EncodingFormat = New XceedBinHexEncodingFormat
  1182.                 'When encoding, we want the output file to have BinHex formating.
  1183.                 'When decoding, we tell to the Encoder that the input file have
  1184.                 'BinHex formating
  1185.                 xEncoder.EncodingFormat.IncludeHeaderFooter = True
  1186.             
  1187.             Case emHexadecimal
  1188.                 Set xEncoder.EncodingFormat = New XceedHexaEncodingFormat
  1189.             
  1190.             Case emQuotedPrintable
  1191.                 Set xEncoder.EncodingFormat = New XceedQuotedPrintableEncodingFormat
  1192.             
  1193.             Case emUUEncode
  1194.                 Set xEncoder.EncodingFormat = New XceedUUEncodingFormat
  1195.                 'When encoding, we want the output file to have a header/footer.
  1196.                 'When decoding, we tell to the Encoder that the input file have
  1197.                 'a header/footer
  1198.                 xEncoder.EncodingFormat.IncludeHeaderFooter = True
  1199.             
  1200.             Case emXXEncode
  1201.                 Set xEncoder.EncodingFormat = New XceedXXEncodingFormat
  1202.                 'When encoding, we want the output file to have a header/footer.
  1203.                 'When decoding, we tell to the Encoder that the input file have
  1204.                 'a header/footer
  1205.                 xEncoder.EncodingFormat.IncludeHeaderFooter = True
  1206.         End Select
  1207.         
  1208.         If Err.Number <> 0 Then
  1209.             txtMessage = txtMessage & " error initializing the encoding format" & vbCrLf & vbCrLf & _
  1210.                          Err.Description & " (" & Hex(Err.Number) & ")" & vbCrLf
  1211.             bCreateOK = False
  1212.         End If
  1213.     On Error GoTo 0
  1214.     CreateEncodingFormat = bCreateOK
  1215. End Function
  1216. '------------------------------------------------------------------------------------
  1217. 'Return the file name part from a "path and file name" string
  1218. '------------------------------------------------------------------------------------
  1219. Private Function ExtractFileName(ByVal sFilename As String) As String
  1220.     Dim i As Integer
  1221.     Dim nFileNameLen As Integer
  1222.     Dim nLenToTake As Integer
  1223.     nFileNameLen = Len(sFilename)
  1224.     i = nFileNameLen
  1225.     nLenToTake = -1
  1226.     'Starting from the end of the string, we check each character and stop
  1227.     'at the first occurence of \ or :
  1228.     While i > 0 And nLenToTake = -1
  1229.         Select Case Mid(sFilename, i, 1)
  1230.             Case "\", ":"
  1231.                 'The length of the file name part is the length of the string
  1232.                 'minus the position of the \ or :
  1233.                 nLenToTake = nFileNameLen - i
  1234.         End Select
  1235.         i = i - 1
  1236.     Wend
  1237.     If nLenToTake = -1 Then
  1238.         'No \ or : were present. We assume that the string was a file name and
  1239.         'we return it
  1240.         ExtractFileName = sFilename
  1241.     Else
  1242.         'We return the right part of the string corresponding to the file name
  1243.         ExtractFileName = Right(sFilename, nLenToTake)
  1244.     End If
  1245. End Function
  1246. '------------------------------------------------------------------------------------
  1247. 'Return the folder part from a "path and file name" string excluding any
  1248. 'terminating \
  1249. '------------------------------------------------------------------------------------
  1250. Private Function ExtractFolder(ByVal sFilename As String) As String
  1251.     Dim i As Integer
  1252.     Dim nFileNameLen As Integer
  1253.     Dim nLenToTake As Integer
  1254.     nFileNameLen = Len(sFilename)
  1255.     i = nFileNameLen
  1256.     nLenToTake = -1
  1257.     'Starting from the end of the string, we check each character and stop
  1258.     'at the first occurence of \ or :
  1259.     While i > 0 And nLenToTake = -1
  1260.         Select Case Mid(sFilename, i, 1)
  1261.             Case "\"
  1262.                 'The length of the folder name part is the position of the \ minus 1
  1263.                 '(to exclude the \)
  1264.                 nLenToTake = i - 1
  1265.             Case ":"
  1266.                 'The length of the folder name part is the same as the position of the :
  1267.                 nLenToTake = i
  1268.         End Select
  1269.         i = i - 1
  1270.     Wend
  1271.     If nLenToTake = -1 Then
  1272.         'The string contains no folder. We return an empty string
  1273.         ExtractFolder = ""
  1274.     Else
  1275.         'Return the left part of the string corresponding to the folder name
  1276.         ExtractFolder = Left(sFilename, nLenToTake)
  1277.     End If
  1278. End Function
  1279. '------------------------------------------------------------------------------------
  1280. 'Return the specified file name WITHOUT its extension, if any.
  1281. '------------------------------------------------------------------------------------
  1282. Private Function RemoveFileExtension(ByVal sFilename As String) As String
  1283.     Dim i As Integer
  1284.     Dim nFileNameLen As Integer
  1285.     Dim nLenToTake As Integer
  1286.     nFileNameLen = Len(sFilename)
  1287.     i = nFileNameLen
  1288.     nLenToTake = -1
  1289.     'Starting from the end of the string, we check each character and stop
  1290.     'at the first occurence of . or \
  1291.     While i > 0 And nLenToTake = -1
  1292.         Select Case Mid(sFilename, i, 1)
  1293.             Case "."
  1294.                 'The length of the filename name part is the position of the . minus 1
  1295.                 '(to exclude the .)
  1296.                 nLenToTake = i - 1
  1297.             Case "\"
  1298.                 'The file name contains a path. Returns all the string
  1299.                 nLenToTake = nFileNameLen
  1300.         End Select
  1301.         i = i - 1
  1302.     Wend
  1303.     If nLenToTake = -1 Then
  1304.         'No extension was found return an empty string
  1305.         RemoveFileExtension = ""
  1306.     Else
  1307.         RemoveFileExtension = Left(sFilename, nLenToTake)
  1308.     End If
  1309. End Function
  1310. '------------------------------------------------------------------------------------
  1311. 'Return the extension part of the specified file name
  1312. '------------------------------------------------------------------------------------
  1313. Private Function ExtractFileExtension(ByVal sFilename As String) As String
  1314.     Dim i As Integer
  1315.     Dim nFileNameLen As Integer
  1316.     Dim nLenToTake As Integer
  1317.     nFileNameLen = Len(sFilename)
  1318.     i = nFileNameLen
  1319.     nLenToTake = -1
  1320.     'Starting from the end of the string, we check each character and stop
  1321.     'at the first occurence of . or \
  1322.     While i > 0 And nLenToTake = -1
  1323.         Select Case Mid(sFilename, i, 1)
  1324.             Case "."
  1325.                 'The length of the extension part is the length of the string
  1326.                 'minus the position of the .
  1327.                 nLenToTake = nFileNameLen - i
  1328.             Case "\"
  1329.                 'No extension was found. We will return an empty string
  1330.                 nLenToTake = 0
  1331.         End Select
  1332.         i = i - 1
  1333.     Wend
  1334.     If nLenToTake = -1 Then
  1335.         'No extension was found. We return an empty string
  1336.         ExtractFileExtension = ""
  1337.     Else
  1338.         ExtractFileExtension = Right(sFilename, nLenToTake)
  1339.     End If
  1340. End Function
  1341. '------------------------------------------------------------------------------------
  1342. 'Return the extension associated with the specified encoding method
  1343. '------------------------------------------------------------------------------------
  1344. Private Function StdFileExtension(eMethod As enuEncodingMethod) As String
  1345.     StdFileExtension = ""
  1346.     Select Case eMethod
  1347.         Case emUUEncode
  1348.             StdFileExtension = ".uue"
  1349.             
  1350.         Case emXXEncode
  1351.             StdFileExtension = ".xxe"
  1352.             
  1353.         Case emBase64
  1354.             StdFileExtension = ".b64"
  1355.             
  1356.         Case emHexadecimal
  1357.             StdFileExtension = ".hex"
  1358.             
  1359.         Case emQuotedPrintable
  1360.             StdFileExtension = ".qpr"
  1361.             
  1362.         Case emBinHex
  1363.             StdFileExtension = ".hqx"
  1364.             
  1365.     End Select
  1366. End Function
  1367. '------------------------------------------------------------------------------------
  1368. 'Read the last saved options kept in the registry
  1369. '------------------------------------------------------------------------------------
  1370. Private Sub LoadOption()
  1371.     ' Encoding option
  1372.     m_lMaxLineLength = Val(GetSetting("XceedEncodingManager", "Encoding", "MaxLineLen", "78"))
  1373.     If UCase(GetSetting("XceedEncodingManager", "Encoding", "EOLType", "CRLF")) = "LF" Then
  1374.         m_eEndOfLineType = bltLf
  1375.     Else
  1376.         m_eEndOfLineType = bltCrLf
  1377.     End If
  1378.     ' Decoding option
  1379.     m_bContinueOnInvalidData = CBool(Val(GetSetting("XceedEncodingManager", "Decoding", "ContinueOnInvalidData", "-1")))
  1380. End Sub
  1381. '------------------------------------------------------------------------------------
  1382. 'Save the current options in the registry
  1383. '------------------------------------------------------------------------------------
  1384. Private Sub SaveOption()
  1385.     Dim sTemp As String
  1386.     ' Encoding option
  1387.     Call SaveSetting("XceedEncodingManager", "Encoding", "MaxLineLen", Str(m_lMaxLineLength))
  1388.     If m_eEndOfLineType = bltLf Then
  1389.         sTemp = "LF"
  1390.     Else
  1391.         sTemp = "CRLF"
  1392.     End If
  1393.     Call SaveSetting("XceedEncodingManager", "Encoding", "EOLType", sTemp)
  1394.     ' Decoding option
  1395.     If m_bContinueOnInvalidData Then
  1396.         sTemp = "-1"
  1397.     Else
  1398.         sTemp = "0"
  1399.     End If
  1400.     Call SaveSetting("XceedEncodingManager", "Decoding", "ContinueOnInvalidData", sTemp)
  1401. End Sub
  1402.