home *** CD-ROM | disk | FTP | other *** search
/ PC World 2003 May / PCWorld_2003-05_cd.bin / Software / Vyzkuste / divfix / Source / DivX.pas < prev    next >
Pascal/Delphi Source File  |  2002-09-21  |  36KB  |  1,229 lines

  1. {DivFix is a utility for reindexing partial DivX AVI movies
  2. Copyright (C) 2000-2002  Csaba Budai
  3.  
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8.  
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. GNU General Public License for more details.
  13.  
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA}
  17.  
  18. unit DivX;
  19.  
  20. interface
  21.  
  22. uses
  23.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  24.   StdCtrls, Mask, Menus, ExtCtrls, Buttons, DropSource, DropTarget,
  25.   ComCtrls, OleCtnrs, ShellApi, FileCtrl;
  26.  
  27. type
  28.   TForm1 = class(TForm)
  29.     Button1: TButton;
  30.     Button2: TButton;
  31.     Button3: TButton;
  32.     Button4: TButton;
  33.     SpeedButton2: TSpeedButton;
  34.     SpeedButton3: TSpeedButton;
  35.     CheckBox1: TCheckBox;
  36.     CheckBox2: TCheckBox;
  37.     CheckBox3: TCheckBox;
  38.     MaskEdit2: TMaskEdit;
  39.     MaskEdit3: TMaskEdit;
  40.     MainMenu1: TMainMenu;
  41.     File1: TMenuItem;
  42.     Open1: TMenuItem;
  43.     Rebuild1: TMenuItem;
  44.     Strip1: TMenuItem;
  45.     Check1: TMenuItem;
  46.     Exit1: TMenuItem;
  47.     Settings1: TMenuItem;
  48.     Stayontop1: TMenuItem;
  49.     Help1: TMenuItem;
  50.     About1: TMenuItem;
  51.     OpenDialog1: TOpenDialog;
  52.     OpenDialog2: TOpenDialog;
  53.     DropFileTarget1: TDropFileTarget;
  54.     ProgressBar1: TProgressBar;
  55.     Image1: TImage;
  56.     Bevel1: TBevel;
  57.     Button5: TButton;
  58.     Button6: TButton;
  59.     ListBox1: TListBox;
  60.     Bevel2: TBevel;
  61.     Button7: TButton;
  62.     RichEdit1: TRichEdit;
  63.     PopupMenu1: TPopupMenu;
  64.     Clear1: TMenuItem;
  65.     Autoclear1: TMenuItem;
  66.     procedure SpeedButton2Click(Sender: TObject);
  67.     procedure SpeedButton3Click(Sender: TObject);
  68.     procedure Button1Click(Sender: TObject);
  69.     procedure Button2Click(Sender: TObject);
  70.     procedure Exit1Click(Sender: TObject);
  71.     procedure About1Click(Sender: TObject);
  72.     procedure StayTop(Sender: TObject);
  73.     procedure FormCreate(Sender: TObject);
  74.     procedure FormDestroy(Sender: TObject);
  75.     procedure DropFileTarget1Drop(Sender: TObject; ShiftState: TShiftState;
  76.       Point: TPoint; var Effect: Integer);
  77.     procedure Button3Click(Sender: TObject);
  78.     procedure Button4Click(Sender: TObject);
  79.     procedure CheckBox1Click(Sender: TObject);
  80.     procedure CheckBox3Click(Sender: TObject);
  81.     procedure ShowWebPage(Sender: TObject);
  82.     procedure Button5Click(Sender: TObject);
  83.     procedure Button6Click(Sender: TObject);
  84.     procedure Button7Click(Sender: TObject);
  85.     procedure Clear1Click(Sender: TObject);
  86.     procedure FormKeyDown(Sender: TObject; var Key: Word;
  87.       Shift: TShiftState);
  88.  
  89.   private
  90.     { Private declarations }
  91.   public
  92.       Input,Output                : File;
  93.     Backup                            :    File;
  94.     Log                                    :    Text;
  95.     Config                            :    Text;
  96.         i,j                                    :    Cardinal;
  97.         Size,Position                :    Cardinal;
  98.         StreamStart                    :    Cardinal;
  99.     StreamSize                    :    Cardinal;
  100.     Difference                    :    Cardinal;
  101.     Frame                                :    Cardinal;
  102.     LastInputPosition        :    Cardinal;
  103.         LastIndexPosition        :    Cardinal;
  104.     LastBackupPosition    :    Cardinal;
  105.     Item                                :    Cardinal;
  106.     Interleaved                : Boolean;
  107.     OnTop                                :    Boolean;
  108.     StopButton                    :    Boolean;
  109.     Logging                            :    Boolean;
  110.     CommandLine                    :    Boolean;
  111.     CfgStay                            :    Boolean;
  112.     CfgClear                        :    Boolean;
  113.     CfgKeep                            :    Boolean;
  114.     CfgCut                            :    Boolean;
  115.     CfgLog                            :    Boolean;
  116.         CfgDir                            :    String;
  117.     CfgDest                            :    String;
  118.     ConfigDir                        :    String;
  119.     Text                                : String;
  120.     Text2                                :    String[2];
  121.         Chunkname                        :    String[8];
  122.         Temp                                : integer;
  123.         FrameType                        :    Cardinal;
  124.     KeyType                            :    Cardinal;
  125.         Buffer                            :    Array [0..32800] Of Byte;
  126.   end;
  127.  
  128.   Const
  129.       KeyFrame  :    Longint = 16;
  130.     NormFrame    :    Longint = 0;
  131.     Number        :    Set of char =['0'..'9'];
  132.  
  133. var
  134.   Form1: TForm1;
  135.  
  136. implementation
  137.  
  138. uses About, DirRequester;
  139.  
  140. {$R *.DFM}
  141.  
  142. procedure DisableButtons;
  143. begin
  144.     Form1.ListBox1.Enabled:=False;
  145.      Form1.SpeedButton2.Enabled:=False;
  146.      Form1.SpeedButton3.Enabled:=False;
  147.     Form1.MaskEdit2.Enabled:=False;
  148.     Form1.MaskEdit3.Enabled:=False;
  149.     Form1.Button1.Enabled:=False;
  150.   Form1.Button2.Enabled:=False;
  151.   Form1.Button3.Enabled:=False;
  152.     Form1.Button5.Enabled:=False;
  153.   Form1.Button6.Enabled:=False;
  154.   Form1.Button7.Enabled:=False;
  155.   Form1.CheckBox1.Enabled:=False;
  156.   Form1.CheckBox2.Enabled:=False;
  157.   Form1.CheckBox3.Enabled:=False;
  158. end;
  159.  
  160. procedure EnableButtons;
  161. begin
  162.     Form1.ListBox1.Enabled:=True;
  163.     If Form1.CheckBox1.Checked Then
  164.   Begin
  165.       Form1.SpeedButton2.Enabled:=True;
  166.       Form1.MaskEdit2.Enabled:=True;
  167.   End;
  168.     If Form1.CheckBox3.Checked Then
  169.   Begin
  170.       Form1.SpeedButton3.Enabled:=True;
  171.       Form1.MaskEdit3.Enabled:=True;
  172.   End;
  173.      Form1.Button1.Enabled:=True;
  174.   Form1.Button2.Enabled:=True;
  175.   Form1.Button3.Enabled:=True;
  176.      Form1.Button5.Enabled:=True;
  177.   Form1.Button6.Enabled:=True;
  178.   Form1.Button7.Enabled:=True;
  179.   Form1.CheckBox1.Enabled:=True;
  180.   If Form1.CheckBox1.Checked Then Form1.CheckBox2.Enabled:=True;
  181.   Form1.CheckBox3.Enabled:=True;
  182. end;
  183.  
  184. procedure WriteOut(Text : String);
  185. begin
  186.     If Form1.Logging Then Writeln(Form1.Log,Text)
  187.   Else
  188.   Begin
  189.       Form1.RichEdit1.Lines.Append(Text);
  190.     Form1.RichEdit1.Perform(EM_SCROLLCARET,0,0);
  191.   End;
  192. end;
  193.  
  194. function CheckOtherIndex(Var Input : File) : Cardinal;
  195. Var    Position,i    :    Cardinal;
  196.         OldPosition    :    Cardinal;
  197.     Buffer            :    Array [0..32800] of Byte;
  198.     Idx                    :    String[4];
  199.     Temp                :    Integer;
  200.  
  201. begin
  202.     OldPosition:=FilePos(Input);
  203.   Position:=FileSize(Input);
  204.   i:=32768;
  205.   Idx:='    ';
  206.   If Position>32768 Then
  207.   Repeat
  208.         Dec(Position,32764);
  209.     Seek(Input,Position);
  210.     BlockRead(Input,Buffer,32768,Temp);
  211.     i:=Temp;
  212.     Repeat
  213.             Dec(i);
  214.       Move(Buffer[i],Idx[1],4);
  215.     Until (i<0) Or (Idx='idx1');
  216.     Until (Position<32768) Or (Idx='idx1');
  217.   If (Position<32768) And (Idx<>'idx1') Then
  218.   Begin
  219.       i:=Position;
  220.     Position:=0;
  221.     Seek(Input,0);
  222.     Repeat
  223.             Dec(i);
  224.       Move(Buffer[i],Idx[1],4);
  225.     Until (i<0) Or (Idx='idx1');
  226.   End;
  227.   Seek(Input,OldPosition);
  228.   If Idx='idx1' Then Result:=Position+i
  229.   Else Result:=0;
  230. end;
  231.  
  232. procedure TForm1.SpeedButton2Click(Sender: TObject);
  233. begin
  234.     Form4.Left:=Form1.Left+70;
  235.   Form4.Top:=Form1.Top-28;
  236.   Form1.Enabled:=False;
  237.   Application.NormalizeTopMosts;
  238.     Form4.ShowModal;
  239.   Application.RestoreTopMosts;
  240.     If Stayontop1.Checked Then
  241.     SetWindowPos(TForm1(Self).Handle,HWND_TOPMOST,0,0,0,0,SWP_NOSIZE+SWP_NOMOVE);
  242. end;
  243.  
  244. procedure TForm1.SpeedButton3Click(Sender: TObject);
  245. begin
  246.     If OpenDialog2.Execute Then MaskEdit3.Text:=OpenDialog2.FileName;
  247. end;
  248.  
  249. procedure TForm1.Button1Click(Sender: TObject);
  250. Var k    :    Cardinal;
  251.  
  252. Label BError;
  253. Label BStartRead;
  254.  
  255. begin
  256.     If Autoclear1.Checked Then RichEdit1.Clear;
  257.     Logging:=False;
  258.     DisableButtons;
  259.     If ListBox1.Items.Count=0 Then
  260.   Begin
  261.         WriteOut(' No file selected.');
  262.     EnableButtons;
  263.       Exit;
  264.   End
  265.   Else
  266.   Begin
  267.        i:=0;
  268.       While i<=ListBox1.Items.Count-1 Do
  269.     Begin
  270.             ListBox1.Perform(LB_SETSEL,0,i);
  271.       Inc(i);
  272.     End;
  273.   End;
  274.   Item:=0;
  275.   Repeat
  276.       If Item>0 Then ListBox1.Perform(LB_SETSEL,0,Item-1);
  277.       ListBox1.Perform(LB_SETSEL,1,Item);
  278.         AssignFile(Input,ListBox1.Items.Strings[Item]);
  279.         AssignFile(Output,'$TEMP.IDX');
  280.       AssignFile(Log,MaskEdit3.Text);
  281.         If CheckBox1.Checked Then
  282.       Begin
  283.           {$I-}
  284.           FileMode:=0;
  285.             Reset(Input,1);
  286.           FileMode:=2;
  287.             {$I+}
  288.       End
  289.       Else
  290.       Begin
  291.              {$I-}
  292.           Reset(Input,1);
  293.           {$I+}
  294.       End;
  295.       If IOResult<>0 Then
  296.         Begin
  297.             WriteOut(' Can not open the file.');
  298.             EnableButtons;
  299.         Exit;
  300.       End;
  301.       Seek(Input,8);
  302.       BlockRead(Input,ChunkName[1],8,Temp);
  303.       ChunkName[0]:=#8;
  304.       If ChunkName<>'AVI LIST' Then
  305.       Begin
  306.           WriteOut(' This is not an AVI file.');
  307.         CloseFile(Input);
  308.         EnableButtons;
  309.         Exit;
  310.       End;
  311.         {$I-}
  312.         Rewrite(Output,1);
  313.         {$I+}
  314.         If IOResult<>0 Then
  315.         Begin
  316.             WriteOut(' Cannot create temporary index file.');
  317.         CloseFile(Input);
  318.         EnableButtons;
  319.         Exit;
  320.       End;
  321.         If CheckBox3.Checked Then
  322.       Begin
  323.             {$I-}
  324.             Reset(Log);
  325.             {$I+}
  326.             If IOResult<>0 Then
  327.         Begin
  328.                 {$I-}
  329.                 Rewrite(Log);
  330.                 {$I+}
  331.                 If IOResult<>0 Then
  332.             Begin
  333.                     WriteOut(' Cannot create log file.');
  334.                 CloseFile(Input);
  335.                  CloseFile(Output);
  336.                 EnableButtons;
  337.                 Exit;
  338.               End
  339.           Else
  340.             Begin
  341.                     CloseFile(Log);
  342.                  Append(Log);
  343.             End;
  344.         End
  345.            Else
  346.         Begin
  347.                 CloseFile(Log);
  348.              Append(Log);
  349.         End;
  350.       End;
  351.         If CheckBox1.Checked Then
  352.       Begin
  353.       AssignFile(Backup,ExtractFilePath(MaskEdit2.Text)+'DivFix.'+
  354.                                        ExtractFileName(ListBox1.Items.Strings[Item]));
  355.             {$I-}
  356.             Rewrite(Backup,1);
  357.             {$I+}
  358.             If IOResult<>0 Then
  359.             Begin
  360.                 WriteOut(' Cannot create backup file.');
  361.             CloseFile(Input);
  362.             CloseFile(Output);
  363.                 If CheckBox3.Checked Then CloseFile(Log);
  364.             Erase(Output);
  365.             EnableButtons;
  366.             Exit;
  367.           End;
  368.       End;
  369.         If CheckBox3.Checked Then
  370.       Begin
  371.           Logging:=True;
  372.             WriteOut(' Index rebuilding for file: '+ListBox1.Items.Strings[Item]);
  373.       End
  374.       Else WriteOut(' Index rebuilding for file: '+ListBox1.Items.Strings[Item]);
  375.          Position:=16;
  376.       Size:=0;
  377.          Chunkname[0]:=#4;
  378.       Repeat
  379.              Position:=Position+Size;
  380.           Seek(Input,Position);
  381.         BlockRead(Input,Size,4);
  382.            BlockRead(Input,Chunkname[1],4);
  383.            Inc(Position,8);
  384.       Until Chunkname='movi';
  385.          StreamStart:=Position-4;
  386.       StreamSize:=Size;
  387.          Chunkname:='idx1';
  388.       BlockWrite(Output,Chunkname[1],4);
  389.          BlockWrite(Output,Size,4);
  390.          LastIndexPosition:=FilePos(Output);
  391.       Position:=4;
  392.          i:=0;
  393.       Frame:=0;
  394.       Difference:=0;
  395.       Interleaved:=False;
  396.       StopButton:=False;
  397.       Seek(Input,0);
  398.       If CheckBox1.Checked Then
  399.       Begin
  400.              For k:=1 To (StreamStart+4) Div 32768 Do
  401.             Begin
  402.                 BlockRead(Input,Buffer,32768,Temp);
  403.                 BlockWrite(Backup,Buffer,Temp);
  404.             End;
  405.             BlockRead(Input,Buffer,((StreamStart+4) Mod 32768),Temp);
  406.             BlockWrite(Backup,Buffer,Temp);
  407.       End;
  408.       Repeat
  409.         ProgressBar1.Position:=Position Div ((FileSize(Input)-StreamStart) Div 100);
  410.              Seek(Input,StreamStart+Position);
  411.             BStartRead:
  412.            If Not Eof(Input) Then
  413.         Begin
  414.               BlockRead(Input,Chunkname[1],4,Temp);
  415.           If ChunkName='LIST' Then
  416.           Begin
  417.               Seek(Input,FilePos(Input)+8);
  418.             Inc(Position,12);
  419.             Goto BStartRead;
  420.                 End;
  421.           If ChunkName='JUNK' Then
  422.           Begin
  423.               BlockRead(Input,Size,4);
  424.             Position:=Position+Size+8;
  425.               Seek(Input,StreamStart+Position);
  426.                     Goto BStartRead;
  427.                 End;
  428.           Text2:=Copy(ChunkName,3,2);
  429.           If (Copy(ChunkName,1,2)='ix') Or (Text2='ix') Then
  430.           Begin
  431.             Inc(Position,16);
  432.               Seek(Input,StreamStart+Position);
  433.             Interleaved:=True;
  434.             Goto BStartRead;
  435.                 End;
  436.           If Not Eof(Input) Then
  437.           Begin
  438.               If ((ChunkName[1] In Number) And (ChunkName[2] In Number)) And
  439.                ((Text2='dc') Or (Text2='db') Or (Text2='wb')) Then
  440.             Begin
  441.                 If (Text2='dc') Or (Text2='db') Then
  442.             Begin
  443.                 If Frame=0 Then
  444.               Begin
  445.                   BlockRead(Input,Size,4);
  446.                    BlockRead(Input,KeyType,4);
  447.                 Seek(Input,FilePos(Input)-8);
  448.               End;
  449.                 Inc(Frame);
  450.             End;
  451.               If Interleaved Then
  452.               Begin
  453.                   Seek(Input,FilePos(Input)-16);
  454.                 Dec(Position,16);
  455.                 Interleaved:=False;
  456.               End;
  457.                       BlockRead(Input,Size,4,Temp);
  458.               If (Size<0) And (Temp=4) Then
  459.               Begin
  460.                   Inc(Position,4);
  461.                 Seek(Input,StreamStart+Position);
  462.                 BlockRead(Input,Chunkname[1],4,Temp);
  463.                 If ChunkName='LIST' Then
  464.                       Begin
  465.                           Seek(Input,FilePos(Input)+8);
  466.                   Inc(Position,12);
  467.                                 Goto BStartRead;
  468.                             End;
  469.                 If ChunkName='JUNK' Then
  470.                       Begin
  471.                           BlockRead(Input,Size,4);
  472.                         Position:=Position+Size+8;
  473.                           Seek(Input,StreamStart+Position);
  474.                         Goto BStartRead;
  475.                             End;
  476.                 Seek(Input,StreamStart+Position);
  477.                 Goto BError;
  478.                         End;
  479.                   If Not Eof(Input) Then
  480.                   Begin
  481.                   LastInputPosition:=Filepos(Input)-4;
  482.                           BlockRead(Input,FrameType,4);
  483.                       j:=(((Position+Size) Div 2)+((Position+Size) Mod 2))*2+8;
  484.                          Seek(Input,StreamStart+j-1);
  485.                          If Not Eof(Input) Then
  486.                       Begin
  487.                     LastIndexPosition:=FilePos(Output);
  488.                               BlockWrite(Output,Chunkname[1],4);
  489.                   Text2:=Copy(ChunkName,3,2);
  490.                               If ((Text2='dc') Or (Text2='db') Or (Text2='wb')) And
  491.                        ((Chunkname[1]In Number) And (ChunkName[2] In Number)) Then
  492.                       If (Text2='wb') Or  ((((KeyType<>65536) And (FrameType And 64=0)) Or
  493.                        ((KeyType=65536) And (FrameType=65536))) And (Size>0)) Then
  494.                           BlockWrite(Output,KeyFrame,4)
  495.                                   Else
  496.                           BlockWrite(Output,NormFrame,4);
  497.                               If CheckBox2.Checked Then
  498.                   Begin
  499.                       j:=Position-Difference;
  500.                       BlockWrite(Output,j,4)
  501.                   End
  502.                   Else BlockWrite(Output,Position,4);
  503.                               BlockWrite(Output,Size,4);
  504.                   j:=Position;
  505.                                Position:=(((Position+Size) Div 2)+((Position+Size) Mod 2))*2+8;
  506.                   Seek(Input,StreamStart+j);
  507.                   If CheckBox1.Checked Then
  508.                   Begin
  509.                       LastBackupPosition:=FilePos(Backup);
  510.                       If Position-j>32768 Then
  511.                       Begin
  512.                           For k:=1 To (Position-j) Div 32768 Do
  513.                         Begin
  514.                                             BlockRead(Input,Buffer,32768,Temp);
  515.                               BlockWrite(Backup,Buffer,Temp);
  516.                           End;
  517.                         BlockRead(Input,Buffer,((Position-j) Mod 32768),Temp);
  518.                              BlockWrite(Backup,Buffer,Temp);
  519.                       End
  520.                       Else
  521.                       Begin
  522.                           BlockRead(Input,Buffer,Position-j,Temp);
  523.                           BlockWrite(Backup,Buffer,Temp);
  524.                       End;
  525.                   End;
  526.                             Inc(i);
  527.                          End;
  528.                        End;
  529.             End
  530.             Else
  531.             Begin
  532.                 BError:
  533.               If Chunkname<>'idx1' Then
  534.               Begin
  535.                   Str(Frame,Text);
  536.                     Text:=' Corrupted data detected at frame '+Text;
  537.                   If FilePos(Output)>16 Then Seek(Output,FilePos(Output)-16);
  538.                             WriteOut(Text);
  539.                 Str(StreamStart+Position,Text);
  540.                 Text:=' Error offset: '+Text+' ($'+IntToHex(StreamStart+Position,8)+')';
  541.                 WriteOut(Text);
  542.                 Seek(Output,LastIndexPosition);
  543.                 If CheckBox1.Checked Then Seek(Backup,LastBackupPosition);
  544.                 j:=Position;
  545.                   Repeat
  546.                       Seek(Input,StreamStart+Position);
  547.                     If Not Eof(Input) Then
  548.                     Begin
  549.                             BlockRead(Input,Buffer[1],32768,Temp);
  550.                     k:=1;
  551.                       Repeat
  552.                               If ((Chr(Buffer[k])='d') Or (Chr(Buffer[k])='w')) Then
  553.                             Begin
  554.                                    If ((Chr(Buffer[k+1])='c') Or (Chr(Buffer[k+1])='b')) Then
  555.                              Begin
  556.                                 Seek(Input,StreamStart+Position+k-3);
  557.                                  If Not Eof(Input) Then BlockRead(Input,ChunkName[1],4);
  558.                                End;
  559.                              End;
  560.                             Inc(k);
  561.                       Text2:=Copy(ChunkName,3,2);
  562.                                     Until (((Text2='dc') Or (Text2='db') Or (Text2='wb')) And
  563.                               ((ChunkName[1] In Number) And (ChunkName[2] In Number))) Or
  564.                           (Chunkname='idx1') Or (k>32768);
  565.                     Inc(Position,k-3);
  566.                       End;
  567.                               Application.ProcessMessages;
  568.                               If StopButton Then
  569.                               Begin
  570.                                   WriteOut(' Index rebuilding aborted...');
  571.                                 ProgressBar1.Position:=0;
  572.                                 StopButton:=False;
  573.                                     CloseFile(Input);
  574.                                     CloseFile(Output);
  575.                     If CheckBox1.Checked Then CloseFile(Backup);
  576.                     If CheckBox3.Checked Then CloseFile(Log);
  577.                                      Erase(Output);
  578.                     EnableButtons;
  579.                                    Exit;
  580.                               End;
  581.                   Text2:=Copy(ChunkName,3,2);
  582.                   Until (((Text2='dc') Or (Text2='db') Or (Text2='wb')) And
  583.                           ((ChunkName[1] In Number) And (ChunkName[2] In Number))) Or
  584.                       (Chunkname='idx1') Or Eof(Input);
  585.                      If Not Eof(Input) Then Dec(Position);
  586.                             If CheckBox1.Checked Then
  587.                 Begin
  588.                     If Not(CheckBox2.Checked) Then
  589.                   Begin
  590.                         Seek(Input,StreamStart+j);
  591.                         If Position-j>32768 Then
  592.                         Begin
  593.                           For k:=1 To (Position-j) Div 32768 Do
  594.                            Begin
  595.                                             BlockRead(Input,Buffer,32768,Temp);
  596.                               BlockWrite(Backup,Buffer,Temp);
  597.                              End;
  598.                            BlockRead(Input,Buffer,((Position-j) Mod 32768),Temp);
  599.                                 BlockWrite(Backup,Buffer,Temp);
  600.                       End
  601.                         Else
  602.                         Begin
  603.                             BlockRead(Input,Buffer,Position-j,Temp);
  604.                             BlockWrite(Backup,Buffer,Temp);
  605.                         End;
  606.                   End
  607.                   Else Difference:=Difference+LastInputPosition-FilePos(Input);
  608.                 End;
  609.               End
  610.               Else
  611.               Begin
  612.                   Seek(Input,FilePos(Input)+6);
  613.                 ChunkName[0]:=#2;
  614.                 BlockRead(Input,ChunkName[1],2);
  615.                 Seek(Input,FilePos(Input)-8);
  616.                 If (ChunkName='dc') Or (ChunkName='wb') Or (ChunkName='db') Then
  617.                 Begin
  618.                     ChunkName[0]:=#4;
  619.                   ChunkName:='idx1';
  620.                 End
  621.                 Else
  622.                 Begin
  623.                     ChunkName[0]:=#4;
  624.                   ChunkName:='0000';
  625.                   Goto BError;
  626.                 End;
  627.               End;
  628.                End;
  629.           End;
  630.         End;
  631.         Application.ProcessMessages;
  632.         If StopButton Then
  633.         Begin
  634.             WriteOut(' Index rebuilding aborted...');
  635.           ProgressBar1.Position:=0;
  636.           StopButton:=False;
  637.               CloseFile(Input);
  638.                  CloseFile(Output);
  639.           If CheckBox1.Checked Then CloseFile(Backup);
  640.           If CheckBox3.Checked Then CloseFile(Log);
  641.               Erase(Output);
  642.           EnableButtons;
  643.             Exit;
  644.         End;
  645.         Until (Eof(Input)) Or (ChunkName='idx1');
  646.          Size:=i*16;
  647.       Seek(Output,4);
  648.          BlockWrite(Output,Size,4);
  649.         If CheckBox1.Checked Then
  650.       Begin
  651.           If ChunkName='idx1' Then StreamSize:=FilePos(Backup)-StreamStart-4
  652.         Else StreamSize:=Filesize(Backup)-StreamStart;
  653.           Seek(Backup,StreamStart-4);
  654.       Inc(StreamSize,4);
  655.              BlockWrite(Backup,StreamSize,4);
  656.           Seek(Backup,StreamStart+StreamSize);
  657.         If (StreamStart+StreamSize) MOD 2=1 Then
  658.         Begin
  659.             Buffer[0]:=0;
  660.             BlockWrite(Backup,Buffer,1);
  661.         End;
  662.              Seek(Output,0);
  663.           Repeat
  664.                  BlockRead(Output,Buffer,32768,Temp);
  665.                BlockWrite(Backup,Buffer,Temp);
  666.             Until Not(Temp=32768);
  667.             WriteOut(' Done.');
  668.       WriteOut('');
  669.         ProgressBar1.Position:=100;
  670.           Truncate(Backup);
  671.           CloseFile(Input);
  672.              CloseFile(Output);
  673.         CloseFile(Backup);
  674.             If CheckBox3.Checked Then CloseFile(Log);
  675.           Erase(Output);
  676.       End
  677.       Else
  678.       Begin
  679.           If ChunkName='idx1' Then StreamSize:=FilePos(Input)-StreamStart-4
  680.         Else StreamSize:=Filesize(Input)-StreamStart;
  681.           Seek(Input,StreamStart-4);
  682.              BlockWrite(Input,StreamSize,4);
  683.           Seek(Input,StreamStart+StreamSize);
  684.         If (StreamStart+StreamSize) MOD 2=1 Then
  685.         Begin
  686.             Buffer[0]:=0;
  687.             BlockWrite(Input,Buffer,1);
  688.         End;
  689.              Seek(Output,0);
  690.           Repeat
  691.                  BlockRead(Output,Buffer,32768,Temp);
  692.                BlockWrite(Input,Buffer,Temp);
  693.             Until Not(Temp=32768);
  694.           Truncate(Input);
  695.             WriteOut(' Done.');
  696.           WriteOut('');
  697.         ProgressBar1.Position:=100;
  698.           CloseFile(Input);
  699.              CloseFile(Output);
  700.             If CheckBox3.Checked Then CloseFile(Log);
  701.           Erase(Output);
  702.       End;
  703.     Inc(Item);
  704.   Until Item=ListBox1.Items.Count;
  705.     ListBox1.Perform(LB_SETSEL,0,Item-1);
  706.   EnableButtons;
  707. end;
  708.  
  709. procedure TForm1.Button2Click(Sender: TObject);
  710. begin
  711.     If Autoclear1.Checked Then RichEdit1.Clear;
  712.     DisableButtons;
  713.   If ListBox1.Items.Count=0 Then
  714.   Begin
  715.         WriteOut(' No file selected.');
  716.     EnableButtons;
  717.       Exit;
  718.   End;
  719.     Item:=0;
  720.   Repeat
  721.         AssignFile(Input,ListBox1.Items.Strings[Item]);
  722.       {$I-}
  723.         Reset(Input,1);
  724.         {$I+}
  725.       If IOResult<>0 Then
  726.         Begin
  727.             WriteOut(' Can not open the file.');
  728.         EnableButtons;
  729.         Exit;
  730.       End;
  731.       Seek(Input,8);
  732.       BlockRead(Input,ChunkName[1],8);
  733.       ChunkName[0]:=#8;
  734.       If ChunkName<>'AVI LIST' Then
  735.       Begin
  736.             WriteOut(' This is not an AVI file.');
  737.         CloseFile(Input);
  738.         EnableButtons;
  739.         Exit;
  740.       End;
  741.       WriteOut(' Stripping index...');
  742.         If CheckBox3.Checked Then
  743.       Begin
  744.           Logging:=True;
  745.             WriteOut(' Stripping index for file: '+ListBox1.Items.Strings[Item]);
  746.       End
  747.       Else WriteOut(' Stripping index for file: '+ListBox1.Items.Strings[Item]);
  748.          Position:=16;
  749.       Size:=0;
  750.          Chunkname[0]:=#4;
  751.       Repeat
  752.              Position:=Position+Size;
  753.           Seek(Input,Position);
  754.         BlockRead(Input,Size,4);
  755.            BlockRead(Input,Chunkname[1],4);
  756.            Inc(Position,8);
  757.       Until Chunkname='movi';
  758.          StreamStart:=Position-4;
  759.       StreamSize:=Size;
  760.       Seek(Input,StreamStart+StreamSize);
  761.       If Eof(Input) Then
  762.       Begin
  763.           WriteOut(' Unexpected end of file, index not found.');
  764.         CloseFile(Input);
  765.         EnableButtons;
  766.         Exit;
  767.       End;
  768.         Truncate(Input);
  769.       Seek(Input,StreamStart-4);
  770.         BlockWrite(Input,StreamSize,4);
  771.       CloseFile(Input);
  772.         WriteOut(' Done.');
  773.     WriteOut('');
  774.     Inc(Item);
  775.   Until Item=ListBox1.Items.Count;
  776.     EnableButtons;
  777. end;
  778.  
  779. procedure TForm1.Button3Click(Sender: TObject);
  780. Label CError;
  781. Label CStartRead;
  782.  
  783. begin
  784.     If Autoclear1.Checked Then RichEdit1.Clear;
  785.     DisableButtons;
  786.     If ListBox1.Items.Count=0 Then
  787.   Begin
  788.         WriteOut(' No file selected.');
  789.     EnableButtons;
  790.       Exit;
  791.   End;
  792.   Item:=0;
  793.   Repeat
  794.         AssignFile(Input,ListBox1.Items.Strings[Item]);
  795.       AssignFile(Log,MaskEdit3.Text);
  796.       {$I-}
  797.       FileMode:=0;
  798.         Reset(Input,1);
  799.       FileMode:=2;
  800.         {$I+}
  801.       If IOResult<>0 Then
  802.         Begin
  803.           WriteOut(' Can not open the file.');
  804.         EnableButtons;
  805.         Exit;
  806.       End;
  807.         If CheckBox3.Checked Then
  808.       Begin
  809.             {$I-}
  810.             Reset(Log);
  811.             {$I+}
  812.             If IOResult<>0 Then
  813.         Begin
  814.                 {$I-}
  815.                 Rewrite(Log);
  816.                 {$I+}
  817.                 If IOResult<>0 Then
  818.             Begin
  819.                     WriteOut(' Cannot create log file.');
  820.                 CloseFile(Input);
  821.                 EnableButtons;
  822.                 Exit;
  823.               End
  824.           Else
  825.             Begin
  826.                     CloseFile(Log);
  827.                  Append(Log);
  828.             End;
  829.         End
  830.            Else
  831.         Begin
  832.                 CloseFile(Log);
  833.              Append(Log);
  834.         End;
  835.       End;
  836.       Seek(Input,8);
  837.       BlockRead(Input,ChunkName[1],8);
  838.       ChunkName[0]:=#8;
  839.       If ChunkName<>'AVI LIST' Then
  840.       Begin
  841.           WriteOut(' This is not an AVI file.');
  842.         CloseFile(Input);
  843.             If CheckBox3.Checked Then CloseFile(Log);
  844.         EnableButtons;
  845.         Exit;
  846.       End;
  847.         If CheckBox3.Checked Then
  848.       Begin
  849.           Logging:=True;
  850.             WriteOut(' Error checking for file: '+ListBox1.Items.Strings[Item]);
  851.       End
  852.       Else WriteOut(' Error checking for file: '+ListBox1.Items.Strings[Item]);
  853.       WriteOut(' NOTE: The error checking is not perfect!');
  854.          Position:=16;
  855.       Size:=0;
  856.          Chunkname[0]:=#4;
  857.       Repeat
  858.              Position:=Position+Size;
  859.           Seek(Input,Position);
  860.         BlockRead(Input,Size,4);
  861.            BlockRead(Input,Chunkname[1],4);
  862.            Inc(Position,8);
  863.       Until Chunkname='movi';
  864.          StreamStart:=Position-4;
  865.       StreamSize:=Size;
  866.          Chunkname:='idx1';
  867.       Position:=4;
  868.          i:=0;
  869.       Frame:=0;
  870.       Interleaved:=False;
  871.       StopButton:=False;
  872.       Repeat
  873.         ProgressBar1.Position:=Position Div (FileSize(Input) Div 100);
  874.              Seek(Input,StreamStart+Position);
  875.            If Not Eof(Input) Then
  876.         Begin
  877.             CStartRead:
  878.               BlockRead(Input,Chunkname[1],4,Temp);
  879.           If ChunkName='LIST' Then
  880.           Begin
  881.               Seek(Input,FilePos(Input)+8);
  882.             Inc(Position,12);
  883.             Goto CStartRead;
  884.                 End;
  885.           If ChunkName='JUNK' Then
  886.           Begin
  887.               BlockRead(Input,Size,4);
  888.             Position:=Position+Size+8;
  889.               Seek(Input,StreamStart+Position);
  890.             Goto CStartRead;
  891.                 End;
  892.           Text2:=Copy(ChunkName,3,2);
  893.           If (Copy(ChunkName,1,2)='ix') Or (Text2='ix') Then
  894.           Begin
  895.               Seek(Input,FilePos(Input)+12);
  896.             Inc(Position,16);
  897.               Seek(Input,StreamStart+Position);
  898.             Interleaved:=True;
  899.             Goto CStartRead;
  900.                 End;
  901.           If Not Eof(Input) Then
  902.           Begin
  903.               If ((ChunkName[1] In Number) And (ChunkName[2] In Number)) And
  904.                ((Text2='dc') Or (Text2='db') Or (Text2='wb')) Then
  905.             Begin
  906.                 If (Text2='dc') Or (Text2='db') Then Inc(Frame);
  907.               If Interleaved Then
  908.               Begin
  909.                   Seek(Input,FilePos(Input)-16);
  910.                 Dec(Position,16);
  911.                 Interleaved:=False;
  912.               End;
  913.                       BlockRead(Input,Size,4,Temp);
  914.               If (Size<0) And (Temp=4) Then
  915.               Begin
  916.                   Inc(Position,4);
  917.                 Seek(Input,StreamStart+Position);
  918.                 BlockRead(Input,Chunkname[1],4);
  919.                       If ChunkName='LIST' Then
  920.                       Begin
  921.                           Seek(Input,FilePos(Input)+8);
  922.                   Inc(Position,12);
  923.                         Goto CStartRead;
  924.                             End;
  925.                 If ChunkName='JUNK' Then
  926.                       Begin
  927.                           BlockRead(Input,Size,4);
  928.                         Position:=Position+Size+8;
  929.                           Seek(Input,StreamStart+Position);
  930.                         Goto CStartRead;
  931.                             End;
  932.                 Seek(Input,StreamStart+Position);
  933.                 Goto CError;
  934.               End;
  935.                   If Not Eof(Input) Then
  936.                   Begin
  937.                       j:=(((Position+Size) Div 2)+((Position+Size) Mod 2))*2+8;
  938.                          Seek(Input,StreamStart+j-1);
  939.                          If Not Eof(Input) Then
  940.                       Begin
  941.                                Position:=(((Position+Size) Div 2)+((Position+Size) Mod 2))*2+8;
  942.                             Inc(i);
  943.                          End;
  944.                        End;
  945.             End
  946.             Else
  947.                         CError:
  948.               If Chunkname<>'idx1' Then
  949.               Begin
  950.                   Str(Frame,Text);
  951.                     Text:=' Corrupted data detected at frame '+Text;
  952.                             WriteOut(Text);
  953.                 Str(StreamStart+Position,Text);
  954.                 Text:=' Error offset: '+Text+' ($'+IntToHex(StreamStart+Position,8)+')';
  955.                 WriteOut(Text);
  956.                   Repeat
  957.                       Seek(Input,StreamStart+Position);
  958.                     If Not Eof(Input) Then
  959.                     Begin
  960.                             BlockRead(Input,Buffer[1],32768,Temp);
  961.                     j:=1;
  962.                       Repeat
  963.                               If ((Chr(Buffer[j])='d') Or (Chr(Buffer[j])='w')) And (Not Eof(Input)) Then
  964.                             Begin
  965.                                   If ((Chr(Buffer[j+1])='c') Or (Chr(Buffer[j+1])='b')) And (Not Eof(Input)) Then
  966.                              Begin
  967.                                 Seek(Input,StreamStart+Position+j-3);
  968.                                  If Not Eof(Input) Then BlockRead(Input,ChunkName[1],4);
  969.                                End;
  970.                              End;
  971.                             Inc(j);
  972.                       Text2:=Copy(ChunkName,3,2);
  973.                                     Until (((Text2='dc') Or (Text2='db') Or
  974.                               (Text2='wb')) And ((ChunkName[1] In Number) And
  975.                               (ChunkName[2] In Number))) Or (Chunkname='idx1') Or (j>32768);
  976.                       End;
  977.                   Inc(Position,j-3);
  978.                   Application.ProcessMessages;
  979.                             If StopButton Then
  980.                             Begin
  981.                                 WriteOut(' Error checking aborted...');
  982.                               ProgressBar1.Position:=0;
  983.                               StopButton:=False;
  984.                     CloseFile(Input);
  985.                                     If CheckBox3.Checked Then CloseFile(Log);
  986.                     EnableButtons;
  987.                                 Exit;
  988.                             End;
  989.                   Text2:=Copy(ChunkName,3,2);
  990.                   Until (((Text2='dc') Or (Text2='db') Or
  991.                       (Text2='wb')) And ((ChunkName[1] In Number) And
  992.                       (ChunkName[2] In Number))) Or (Chunkname='idx1') Or Eof(Input);
  993.                   If Not Eof(Input) Then Dec(Position);
  994.                 End
  995.               Else
  996.               Begin
  997.                   Seek(Input,FilePos(Input)+6);
  998.                 ChunkName[0]:=#2;
  999.                 BlockRead(Input,ChunkName[1],2);
  1000.                 Seek(Input,FilePos(Input)-8);
  1001.                 If (ChunkName='dc') Or (ChunkName='wb') Or (ChunkName='db') Then
  1002.                 Begin
  1003.                     ChunkName[0]:=#4;
  1004.                   ChunkName:='idx1';
  1005.                 End
  1006.                 Else
  1007.                 Begin
  1008.                     ChunkName[0]:=#4;
  1009.                   ChunkName:='0000';
  1010.                   Goto CError;
  1011.                 End
  1012.               End;
  1013.           End;
  1014.         End;
  1015.         Application.ProcessMessages;
  1016.         If StopButton Then
  1017.         Begin
  1018.             WriteOut(' Error checking aborted...');
  1019.           ProgressBar1.Position:=0;
  1020.           StopButton:=False;
  1021.           CloseFile(Input);
  1022.                 If CheckBox3.Checked Then CloseFile(Log);
  1023.           EnableButtons;
  1024.             Exit;
  1025.         End;
  1026.         Until (Eof(Input)) Or (ChunkName='idx1');
  1027.         WriteOut(' Done.');
  1028.       WriteOut('');
  1029.       ProgressBar1.Position:=100;
  1030.       CloseFile(Input);
  1031.         If CheckBox3.Checked Then CloseFile(Log);
  1032.       Inc(Item);
  1033.   Until Item=ListBox1.Items.Count;
  1034.     EnableButtons;
  1035. end;
  1036.  
  1037. procedure TForm1.Exit1Click(Sender: TObject);
  1038. begin
  1039.     Close;
  1040. end;
  1041.  
  1042. procedure TForm1.About1Click(Sender: TObject);
  1043. begin
  1044.     Form1.Enabled:=False;
  1045.     Form2.Show;
  1046. end;
  1047.  
  1048. procedure TForm1.StayTop(Sender: TObject);
  1049. begin
  1050.     If Stayontop1.Checked Then
  1051.   Begin
  1052.       Stayontop1.Checked:=Not(Stayontop1.Checked);
  1053.     SetWindowPos(TForm1(Self).Handle,HWND_NOTOPMOST,0,0,0,0,SWP_NOSIZE+SWP_NOMOVE);
  1054.   End
  1055.   Else
  1056.   Begin
  1057.       Stayontop1.Checked:=Not(Stayontop1.Checked);
  1058.     SetWindowPos(TForm1(Self).Handle,HWND_TOPMOST,0,0,0,0,SWP_NOSIZE+SWP_NOMOVE);
  1059.   End;
  1060. end;
  1061.  
  1062. procedure TForm1.FormCreate(Sender: TObject);
  1063. begin
  1064.     DropFileTarget1.register(Form1);
  1065.   If Tag=0 Then
  1066.   Begin
  1067.       GetDir(0,ConfigDir);
  1068.          If Copy(ConfigDir,Length(ConfigDir),1)='\' Then AssignFile(Config,ConfigDir+'DivFix.ini')
  1069.     Else AssignFile(Config,ConfigDir+'\DivFix.ini');
  1070.       {$I-}
  1071.       Reset(Config);
  1072.       {$I+}
  1073.         If IOResult=0 Then
  1074.       Begin
  1075.           While Not(Eof(Config)) Do
  1076.         Begin
  1077.                 Readln(Config,Text);
  1078.                 If Copy(Text,1,7)='LastDir' Then
  1079.           Begin
  1080.               Form1.OpenDialog1.InitialDir:=Copy(Text,9,Length(Text)-9);
  1081.             CfgDir:=Form1.OpenDialog1.InitialDir+'\';
  1082.           End;
  1083.                 If Copy(Text,1,7)='DestDir' Then
  1084.           Begin
  1085.               Form1.MaskEdit2.Text:=Copy(Text,9,Length(Text)-7);
  1086.             CfgDest:=Form1.MaskEdit2.Text;
  1087.           End;
  1088.                  If Copy(Text,1,9)='StayOnTop' Then
  1089.                  If Copy(Text,11,Length(Text)-9)='1' Then
  1090.               Begin
  1091.                         StayTop(Self);
  1092.               CfgStay:=True;
  1093.                  End
  1094.             Else CfgStay:=False;
  1095.                  If Copy(Text,1,9)='AutoClear' Then
  1096.                  If Copy(Text,11,Length(Text)-9)='1' Then
  1097.               Begin
  1098.                         Autoclear1.Checked:=True;
  1099.               CfgStay:=True;
  1100.                  End
  1101.             Else CfgStay:=False;
  1102.           If Copy(Text,1,12)='KeepOriginal' Then
  1103.                  If Copy(Text,14,Length(Text)-12)='1' Then
  1104.             Begin
  1105.                 Form1.CheckBox1.Checked:=True;
  1106.               CfgKeep:=True;
  1107.             End
  1108.             Else CfgKeep:=False;
  1109.           If Copy(Text,1,6)='CutOut' Then
  1110.               If Copy(Text,8,Length(Text)-6)='1' Then
  1111.                 If Form1.CheckBox2.Enabled Then
  1112.               Begin
  1113.                   Form1.CheckBox2.Checked:=True;
  1114.                 CfgCut:=True;
  1115.               End
  1116.               Else CfgCut:=False;
  1117.           If Copy(Text,1,9)='LogErrors' Then
  1118.               If Copy(Text,11,Length(Text)-9)='1' Then
  1119.             Begin
  1120.                 Form1.CheckBox3.Checked:=True;
  1121.               CfgLog:=True;
  1122.             End
  1123.             Else CfgLog:=False;
  1124.             End;
  1125.         CloseFile(Config);
  1126.       End;
  1127.   End;
  1128. end;
  1129.  
  1130. procedure TForm1.FormDestroy(Sender: TObject);
  1131. begin
  1132.     DropFiletarget1.Unregister;
  1133.   If Tag=0 Then
  1134.       If (CfgDir<>OpenDialog1.InitialDir+'\') Or (CfgDest<>Form1.MaskEdit2.Text) Or
  1135.          (CfgStay<>Stayontop1.Checked) Or (CfgKeep<>CheckBox1.Checked) Or
  1136.        (CfgCut<>CheckBox2.Checked) Or (CfgLog<>CheckBox3.Checked) Or
  1137.        (CfgClear<>Autoclear1.Checked) Then
  1138.       Begin
  1139.           Rewrite(Config);
  1140.         If OpenDialog1.InitialDir<>'' Then Writeln(Config,'LastDir='+OpenDialog1.InitialDir+'\')
  1141.       Else Writeln(Config,'LastDir=.\');
  1142.          If Form1.MaskEdit2.Text<>'' Then Writeln(Config,'DestDir='+Form1.MaskEdit2.Text)
  1143.       Else Writeln(Config,'DestDir=.\');
  1144.         If Stayontop1.Checked Then Writeln(Config,'StayOnTop=1')
  1145.         Else Writeln(Config,'StayOnTop=0');
  1146.       If Autoclear1.Checked Then Writeln(Config,'AutoClear=1')
  1147.         Else Writeln(Config,'AutoClear=0');
  1148.         If CheckBox1.Checked Then Writeln(Config,'KeepOriginal=1')
  1149.         Else Writeln(Config,'KeepOriginal=0');
  1150.         If CheckBox2.Checked Then Writeln(Config,'CutOut=1')
  1151.         Else Writeln(Config,'CutOut=0');
  1152.         If CheckBox3.Checked Then Writeln(Config,'LogErrors=1')
  1153.         Else Writeln(Config,'LogErrors=0');
  1154.         CloseFile(Config);
  1155.         End;
  1156. end;
  1157.  
  1158. procedure TForm1.DropFileTarget1Drop(Sender: TObject;
  1159.   ShiftState: TShiftState; Point: TPoint; var Effect: Integer);
  1160. begin
  1161.     ListBox1.Items.AddStrings(DropFileTarget1.Files);
  1162.   OpenDialog1.InitialDir:=Copy(ExtractFilePath(ListBox1.Items.Strings[0]),1,
  1163.       Length(ExtractFilePath(ListBox1.Items.Strings[0]))-1);
  1164. end;
  1165.  
  1166. procedure TForm1.Button4Click(Sender: TObject);
  1167. begin
  1168.     StopButton:=True;
  1169. end;
  1170.  
  1171. procedure TForm1.CheckBox1Click(Sender: TObject);
  1172. begin
  1173.   CheckBox2.Enabled:=Not(CheckBox2.Enabled);
  1174.   SpeedButton2.Enabled:=Not(SpeedButton2.Enabled);
  1175.   Maskedit2.Enabled:=Not(MaskEdit2.Enabled);
  1176.   If Not(CheckBox2.Enabled) Then CheckBox2.Checked:=False;
  1177. end;
  1178.  
  1179. procedure TForm1.CheckBox3Click(Sender: TObject);
  1180. begin
  1181.   SpeedButton3.Enabled:=Not(SpeedButton3.Enabled);
  1182.   Maskedit3.Enabled:=Not(MaskEdit3.Enabled);
  1183.   If Not(CheckBox2.Enabled) Then CheckBox2.Checked:=False;
  1184. end;
  1185.  
  1186. procedure TForm1.ShowWebPage(Sender: TObject);
  1187. begin
  1188.     ShellExecute(0,'open',pchar('http://divfix.maxeline.com'),nil,nil,SW_MAXIMIZE);
  1189. end;
  1190.  
  1191. procedure TForm1.Button5Click(Sender: TObject);
  1192. begin
  1193.     If OpenDialog1.Execute Then
  1194.   Begin
  1195.       OpenDialog1.InitialDir:=Copy(ExtractFilePath(OpenDialog1.FileName),1,
  1196.       Length(ExtractFilePath(OpenDialog1.FileName))-1);
  1197.     ListBox1.Items.AddStrings(OpenDialog1.Files);
  1198.   End;
  1199. end;
  1200.  
  1201. procedure TForm1.Button6Click(Sender: TObject);
  1202. Var i    :    Cardinal;
  1203.  
  1204. begin
  1205.     i:=0;
  1206.   While i<=ListBox1.Items.Count-1 Do
  1207.       If ListBox1.Selected[i] Then ListBox1.Items.Delete(i)
  1208.     Else Inc(i);
  1209. end;
  1210.  
  1211. procedure TForm1.Button7Click(Sender: TObject);
  1212. begin
  1213.     ListBox1.Items.Clear;
  1214. end;
  1215.  
  1216. procedure TForm1.Clear1Click(Sender: TObject);
  1217. begin
  1218.     RichEdit1.Clear;
  1219. end;
  1220.  
  1221. procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  1222.   Shift: TShiftState);
  1223. begin
  1224.     If Key=VK_INSERT Then Button5Click(nil);
  1225.   If Key=VK_DELETE Then Button6Click(nil);
  1226. end;
  1227.  
  1228. end.
  1229.