home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2003 May
/
PCWorld_2003-05_cd.bin
/
Software
/
Vyzkuste
/
divfix
/
Source
/
DivX.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
2002-09-21
|
36KB
|
1,229 lines
{DivFix is a utility for reindexing partial DivX AVI movies
Copyright (C) 2000-2002 Csaba Budai
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA}
unit DivX;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Mask, Menus, ExtCtrls, Buttons, DropSource, DropTarget,
ComCtrls, OleCtnrs, ShellApi, FileCtrl;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
SpeedButton2: TSpeedButton;
SpeedButton3: TSpeedButton;
CheckBox1: TCheckBox;
CheckBox2: TCheckBox;
CheckBox3: TCheckBox;
MaskEdit2: TMaskEdit;
MaskEdit3: TMaskEdit;
MainMenu1: TMainMenu;
File1: TMenuItem;
Open1: TMenuItem;
Rebuild1: TMenuItem;
Strip1: TMenuItem;
Check1: TMenuItem;
Exit1: TMenuItem;
Settings1: TMenuItem;
Stayontop1: TMenuItem;
Help1: TMenuItem;
About1: TMenuItem;
OpenDialog1: TOpenDialog;
OpenDialog2: TOpenDialog;
DropFileTarget1: TDropFileTarget;
ProgressBar1: TProgressBar;
Image1: TImage;
Bevel1: TBevel;
Button5: TButton;
Button6: TButton;
ListBox1: TListBox;
Bevel2: TBevel;
Button7: TButton;
RichEdit1: TRichEdit;
PopupMenu1: TPopupMenu;
Clear1: TMenuItem;
Autoclear1: TMenuItem;
procedure SpeedButton2Click(Sender: TObject);
procedure SpeedButton3Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Exit1Click(Sender: TObject);
procedure About1Click(Sender: TObject);
procedure StayTop(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure DropFileTarget1Drop(Sender: TObject; ShiftState: TShiftState;
Point: TPoint; var Effect: Integer);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure CheckBox1Click(Sender: TObject);
procedure CheckBox3Click(Sender: TObject);
procedure ShowWebPage(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
procedure Button7Click(Sender: TObject);
procedure Clear1Click(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
private
{ Private declarations }
public
Input,Output : File;
Backup : File;
Log : Text;
Config : Text;
i,j : Cardinal;
Size,Position : Cardinal;
StreamStart : Cardinal;
StreamSize : Cardinal;
Difference : Cardinal;
Frame : Cardinal;
LastInputPosition : Cardinal;
LastIndexPosition : Cardinal;
LastBackupPosition : Cardinal;
Item : Cardinal;
Interleaved : Boolean;
OnTop : Boolean;
StopButton : Boolean;
Logging : Boolean;
CommandLine : Boolean;
CfgStay : Boolean;
CfgClear : Boolean;
CfgKeep : Boolean;
CfgCut : Boolean;
CfgLog : Boolean;
CfgDir : String;
CfgDest : String;
ConfigDir : String;
Text : String;
Text2 : String[2];
Chunkname : String[8];
Temp : integer;
FrameType : Cardinal;
KeyType : Cardinal;
Buffer : Array [0..32800] Of Byte;
end;
Const
KeyFrame : Longint = 16;
NormFrame : Longint = 0;
Number : Set of char =['0'..'9'];
var
Form1: TForm1;
implementation
uses About, DirRequester;
{$R *.DFM}
procedure DisableButtons;
begin
Form1.ListBox1.Enabled:=False;
Form1.SpeedButton2.Enabled:=False;
Form1.SpeedButton3.Enabled:=False;
Form1.MaskEdit2.Enabled:=False;
Form1.MaskEdit3.Enabled:=False;
Form1.Button1.Enabled:=False;
Form1.Button2.Enabled:=False;
Form1.Button3.Enabled:=False;
Form1.Button5.Enabled:=False;
Form1.Button6.Enabled:=False;
Form1.Button7.Enabled:=False;
Form1.CheckBox1.Enabled:=False;
Form1.CheckBox2.Enabled:=False;
Form1.CheckBox3.Enabled:=False;
end;
procedure EnableButtons;
begin
Form1.ListBox1.Enabled:=True;
If Form1.CheckBox1.Checked Then
Begin
Form1.SpeedButton2.Enabled:=True;
Form1.MaskEdit2.Enabled:=True;
End;
If Form1.CheckBox3.Checked Then
Begin
Form1.SpeedButton3.Enabled:=True;
Form1.MaskEdit3.Enabled:=True;
End;
Form1.Button1.Enabled:=True;
Form1.Button2.Enabled:=True;
Form1.Button3.Enabled:=True;
Form1.Button5.Enabled:=True;
Form1.Button6.Enabled:=True;
Form1.Button7.Enabled:=True;
Form1.CheckBox1.Enabled:=True;
If Form1.CheckBox1.Checked Then Form1.CheckBox2.Enabled:=True;
Form1.CheckBox3.Enabled:=True;
end;
procedure WriteOut(Text : String);
begin
If Form1.Logging Then Writeln(Form1.Log,Text)
Else
Begin
Form1.RichEdit1.Lines.Append(Text);
Form1.RichEdit1.Perform(EM_SCROLLCARET,0,0);
End;
end;
function CheckOtherIndex(Var Input : File) : Cardinal;
Var Position,i : Cardinal;
OldPosition : Cardinal;
Buffer : Array [0..32800] of Byte;
Idx : String[4];
Temp : Integer;
begin
OldPosition:=FilePos(Input);
Position:=FileSize(Input);
i:=32768;
Idx:=' ';
If Position>32768 Then
Repeat
Dec(Position,32764);
Seek(Input,Position);
BlockRead(Input,Buffer,32768,Temp);
i:=Temp;
Repeat
Dec(i);
Move(Buffer[i],Idx[1],4);
Until (i<0) Or (Idx='idx1');
Until (Position<32768) Or (Idx='idx1');
If (Position<32768) And (Idx<>'idx1') Then
Begin
i:=Position;
Position:=0;
Seek(Input,0);
Repeat
Dec(i);
Move(Buffer[i],Idx[1],4);
Until (i<0) Or (Idx='idx1');
End;
Seek(Input,OldPosition);
If Idx='idx1' Then Result:=Position+i
Else Result:=0;
end;
procedure TForm1.SpeedButton2Click(Sender: TObject);
begin
Form4.Left:=Form1.Left+70;
Form4.Top:=Form1.Top-28;
Form1.Enabled:=False;
Application.NormalizeTopMosts;
Form4.ShowModal;
Application.RestoreTopMosts;
If Stayontop1.Checked Then
SetWindowPos(TForm1(Self).Handle,HWND_TOPMOST,0,0,0,0,SWP_NOSIZE+SWP_NOMOVE);
end;
procedure TForm1.SpeedButton3Click(Sender: TObject);
begin
If OpenDialog2.Execute Then MaskEdit3.Text:=OpenDialog2.FileName;
end;
procedure TForm1.Button1Click(Sender: TObject);
Var k : Cardinal;
Label BError;
Label BStartRead;
begin
If Autoclear1.Checked Then RichEdit1.Clear;
Logging:=False;
DisableButtons;
If ListBox1.Items.Count=0 Then
Begin
WriteOut(' No file selected.');
EnableButtons;
Exit;
End
Else
Begin
i:=0;
While i<=ListBox1.Items.Count-1 Do
Begin
ListBox1.Perform(LB_SETSEL,0,i);
Inc(i);
End;
End;
Item:=0;
Repeat
If Item>0 Then ListBox1.Perform(LB_SETSEL,0,Item-1);
ListBox1.Perform(LB_SETSEL,1,Item);
AssignFile(Input,ListBox1.Items.Strings[Item]);
AssignFile(Output,'$TEMP.IDX');
AssignFile(Log,MaskEdit3.Text);
If CheckBox1.Checked Then
Begin
{$I-}
FileMode:=0;
Reset(Input,1);
FileMode:=2;
{$I+}
End
Else
Begin
{$I-}
Reset(Input,1);
{$I+}
End;
If IOResult<>0 Then
Begin
WriteOut(' Can not open the file.');
EnableButtons;
Exit;
End;
Seek(Input,8);
BlockRead(Input,ChunkName[1],8,Temp);
ChunkName[0]:=#8;
If ChunkName<>'AVI LIST' Then
Begin
WriteOut(' This is not an AVI file.');
CloseFile(Input);
EnableButtons;
Exit;
End;
{$I-}
Rewrite(Output,1);
{$I+}
If IOResult<>0 Then
Begin
WriteOut(' Cannot create temporary index file.');
CloseFile(Input);
EnableButtons;
Exit;
End;
If CheckBox3.Checked Then
Begin
{$I-}
Reset(Log);
{$I+}
If IOResult<>0 Then
Begin
{$I-}
Rewrite(Log);
{$I+}
If IOResult<>0 Then
Begin
WriteOut(' Cannot create log file.');
CloseFile(Input);
CloseFile(Output);
EnableButtons;
Exit;
End
Else
Begin
CloseFile(Log);
Append(Log);
End;
End
Else
Begin
CloseFile(Log);
Append(Log);
End;
End;
If CheckBox1.Checked Then
Begin
AssignFile(Backup,ExtractFilePath(MaskEdit2.Text)+'DivFix.'+
ExtractFileName(ListBox1.Items.Strings[Item]));
{$I-}
Rewrite(Backup,1);
{$I+}
If IOResult<>0 Then
Begin
WriteOut(' Cannot create backup file.');
CloseFile(Input);
CloseFile(Output);
If CheckBox3.Checked Then CloseFile(Log);
Erase(Output);
EnableButtons;
Exit;
End;
End;
If CheckBox3.Checked Then
Begin
Logging:=True;
WriteOut(' Index rebuilding for file: '+ListBox1.Items.Strings[Item]);
End
Else WriteOut(' Index rebuilding for file: '+ListBox1.Items.Strings[Item]);
Position:=16;
Size:=0;
Chunkname[0]:=#4;
Repeat
Position:=Position+Size;
Seek(Input,Position);
BlockRead(Input,Size,4);
BlockRead(Input,Chunkname[1],4);
Inc(Position,8);
Until Chunkname='movi';
StreamStart:=Position-4;
StreamSize:=Size;
Chunkname:='idx1';
BlockWrite(Output,Chunkname[1],4);
BlockWrite(Output,Size,4);
LastIndexPosition:=FilePos(Output);
Position:=4;
i:=0;
Frame:=0;
Difference:=0;
Interleaved:=False;
StopButton:=False;
Seek(Input,0);
If CheckBox1.Checked Then
Begin
For k:=1 To (StreamStart+4) Div 32768 Do
Begin
BlockRead(Input,Buffer,32768,Temp);
BlockWrite(Backup,Buffer,Temp);
End;
BlockRead(Input,Buffer,((StreamStart+4) Mod 32768),Temp);
BlockWrite(Backup,Buffer,Temp);
End;
Repeat
ProgressBar1.Position:=Position Div ((FileSize(Input)-StreamStart) Div 100);
Seek(Input,StreamStart+Position);
BStartRead:
If Not Eof(Input) Then
Begin
BlockRead(Input,Chunkname[1],4,Temp);
If ChunkName='LIST' Then
Begin
Seek(Input,FilePos(Input)+8);
Inc(Position,12);
Goto BStartRead;
End;
If ChunkName='JUNK' Then
Begin
BlockRead(Input,Size,4);
Position:=Position+Size+8;
Seek(Input,StreamStart+Position);
Goto BStartRead;
End;
Text2:=Copy(ChunkName,3,2);
If (Copy(ChunkName,1,2)='ix') Or (Text2='ix') Then
Begin
Inc(Position,16);
Seek(Input,StreamStart+Position);
Interleaved:=True;
Goto BStartRead;
End;
If Not Eof(Input) Then
Begin
If ((ChunkName[1] In Number) And (ChunkName[2] In Number)) And
((Text2='dc') Or (Text2='db') Or (Text2='wb')) Then
Begin
If (Text2='dc') Or (Text2='db') Then
Begin
If Frame=0 Then
Begin
BlockRead(Input,Size,4);
BlockRead(Input,KeyType,4);
Seek(Input,FilePos(Input)-8);
End;
Inc(Frame);
End;
If Interleaved Then
Begin
Seek(Input,FilePos(Input)-16);
Dec(Position,16);
Interleaved:=False;
End;
BlockRead(Input,Size,4,Temp);
If (Size<0) And (Temp=4) Then
Begin
Inc(Position,4);
Seek(Input,StreamStart+Position);
BlockRead(Input,Chunkname[1],4,Temp);
If ChunkName='LIST' Then
Begin
Seek(Input,FilePos(Input)+8);
Inc(Position,12);
Goto BStartRead;
End;
If ChunkName='JUNK' Then
Begin
BlockRead(Input,Size,4);
Position:=Position+Size+8;
Seek(Input,StreamStart+Position);
Goto BStartRead;
End;
Seek(Input,StreamStart+Position);
Goto BError;
End;
If Not Eof(Input) Then
Begin
LastInputPosition:=Filepos(Input)-4;
BlockRead(Input,FrameType,4);
j:=(((Position+Size) Div 2)+((Position+Size) Mod 2))*2+8;
Seek(Input,StreamStart+j-1);
If Not Eof(Input) Then
Begin
LastIndexPosition:=FilePos(Output);
BlockWrite(Output,Chunkname[1],4);
Text2:=Copy(ChunkName,3,2);
If ((Text2='dc') Or (Text2='db') Or (Text2='wb')) And
((Chunkname[1]In Number) And (ChunkName[2] In Number)) Then
If (Text2='wb') Or ((((KeyType<>65536) And (FrameType And 64=0)) Or
((KeyType=65536) And (FrameType=65536))) And (Size>0)) Then
BlockWrite(Output,KeyFrame,4)
Else
BlockWrite(Output,NormFrame,4);
If CheckBox2.Checked Then
Begin
j:=Position-Difference;
BlockWrite(Output,j,4)
End
Else BlockWrite(Output,Position,4);
BlockWrite(Output,Size,4);
j:=Position;
Position:=(((Position+Size) Div 2)+((Position+Size) Mod 2))*2+8;
Seek(Input,StreamStart+j);
If CheckBox1.Checked Then
Begin
LastBackupPosition:=FilePos(Backup);
If Position-j>32768 Then
Begin
For k:=1 To (Position-j) Div 32768 Do
Begin
BlockRead(Input,Buffer,32768,Temp);
BlockWrite(Backup,Buffer,Temp);
End;
BlockRead(Input,Buffer,((Position-j) Mod 32768),Temp);
BlockWrite(Backup,Buffer,Temp);
End
Else
Begin
BlockRead(Input,Buffer,Position-j,Temp);
BlockWrite(Backup,Buffer,Temp);
End;
End;
Inc(i);
End;
End;
End
Else
Begin
BError:
If Chunkname<>'idx1' Then
Begin
Str(Frame,Text);
Text:=' Corrupted data detected at frame '+Text;
If FilePos(Output)>16 Then Seek(Output,FilePos(Output)-16);
WriteOut(Text);
Str(StreamStart+Position,Text);
Text:=' Error offset: '+Text+' ($'+IntToHex(StreamStart+Position,8)+')';
WriteOut(Text);
Seek(Output,LastIndexPosition);
If CheckBox1.Checked Then Seek(Backup,LastBackupPosition);
j:=Position;
Repeat
Seek(Input,StreamStart+Position);
If Not Eof(Input) Then
Begin
BlockRead(Input,Buffer[1],32768,Temp);
k:=1;
Repeat
If ((Chr(Buffer[k])='d') Or (Chr(Buffer[k])='w')) Then
Begin
If ((Chr(Buffer[k+1])='c') Or (Chr(Buffer[k+1])='b')) Then
Begin
Seek(Input,StreamStart+Position+k-3);
If Not Eof(Input) Then BlockRead(Input,ChunkName[1],4);
End;
End;
Inc(k);
Text2:=Copy(ChunkName,3,2);
Until (((Text2='dc') Or (Text2='db') Or (Text2='wb')) And
((ChunkName[1] In Number) And (ChunkName[2] In Number))) Or
(Chunkname='idx1') Or (k>32768);
Inc(Position,k-3);
End;
Application.ProcessMessages;
If StopButton Then
Begin
WriteOut(' Index rebuilding aborted...');
ProgressBar1.Position:=0;
StopButton:=False;
CloseFile(Input);
CloseFile(Output);
If CheckBox1.Checked Then CloseFile(Backup);
If CheckBox3.Checked Then CloseFile(Log);
Erase(Output);
EnableButtons;
Exit;
End;
Text2:=Copy(ChunkName,3,2);
Until (((Text2='dc') Or (Text2='db') Or (Text2='wb')) And
((ChunkName[1] In Number) And (ChunkName[2] In Number))) Or
(Chunkname='idx1') Or Eof(Input);
If Not Eof(Input) Then Dec(Position);
If CheckBox1.Checked Then
Begin
If Not(CheckBox2.Checked) Then
Begin
Seek(Input,StreamStart+j);
If Position-j>32768 Then
Begin
For k:=1 To (Position-j) Div 32768 Do
Begin
BlockRead(Input,Buffer,32768,Temp);
BlockWrite(Backup,Buffer,Temp);
End;
BlockRead(Input,Buffer,((Position-j) Mod 32768),Temp);
BlockWrite(Backup,Buffer,Temp);
End
Else
Begin
BlockRead(Input,Buffer,Position-j,Temp);
BlockWrite(Backup,Buffer,Temp);
End;
End
Else Difference:=Difference+LastInputPosition-FilePos(Input);
End;
End
Else
Begin
Seek(Input,FilePos(Input)+6);
ChunkName[0]:=#2;
BlockRead(Input,ChunkName[1],2);
Seek(Input,FilePos(Input)-8);
If (ChunkName='dc') Or (ChunkName='wb') Or (ChunkName='db') Then
Begin
ChunkName[0]:=#4;
ChunkName:='idx1';
End
Else
Begin
ChunkName[0]:=#4;
ChunkName:='0000';
Goto BError;
End;
End;
End;
End;
End;
Application.ProcessMessages;
If StopButton Then
Begin
WriteOut(' Index rebuilding aborted...');
ProgressBar1.Position:=0;
StopButton:=False;
CloseFile(Input);
CloseFile(Output);
If CheckBox1.Checked Then CloseFile(Backup);
If CheckBox3.Checked Then CloseFile(Log);
Erase(Output);
EnableButtons;
Exit;
End;
Until (Eof(Input)) Or (ChunkName='idx1');
Size:=i*16;
Seek(Output,4);
BlockWrite(Output,Size,4);
If CheckBox1.Checked Then
Begin
If ChunkName='idx1' Then StreamSize:=FilePos(Backup)-StreamStart-4
Else StreamSize:=Filesize(Backup)-StreamStart;
Seek(Backup,StreamStart-4);
Inc(StreamSize,4);
BlockWrite(Backup,StreamSize,4);
Seek(Backup,StreamStart+StreamSize);
If (StreamStart+StreamSize) MOD 2=1 Then
Begin
Buffer[0]:=0;
BlockWrite(Backup,Buffer,1);
End;
Seek(Output,0);
Repeat
BlockRead(Output,Buffer,32768,Temp);
BlockWrite(Backup,Buffer,Temp);
Until Not(Temp=32768);
WriteOut(' Done.');
WriteOut('');
ProgressBar1.Position:=100;
Truncate(Backup);
CloseFile(Input);
CloseFile(Output);
CloseFile(Backup);
If CheckBox3.Checked Then CloseFile(Log);
Erase(Output);
End
Else
Begin
If ChunkName='idx1' Then StreamSize:=FilePos(Input)-StreamStart-4
Else StreamSize:=Filesize(Input)-StreamStart;
Seek(Input,StreamStart-4);
BlockWrite(Input,StreamSize,4);
Seek(Input,StreamStart+StreamSize);
If (StreamStart+StreamSize) MOD 2=1 Then
Begin
Buffer[0]:=0;
BlockWrite(Input,Buffer,1);
End;
Seek(Output,0);
Repeat
BlockRead(Output,Buffer,32768,Temp);
BlockWrite(Input,Buffer,Temp);
Until Not(Temp=32768);
Truncate(Input);
WriteOut(' Done.');
WriteOut('');
ProgressBar1.Position:=100;
CloseFile(Input);
CloseFile(Output);
If CheckBox3.Checked Then CloseFile(Log);
Erase(Output);
End;
Inc(Item);
Until Item=ListBox1.Items.Count;
ListBox1.Perform(LB_SETSEL,0,Item-1);
EnableButtons;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
If Autoclear1.Checked Then RichEdit1.Clear;
DisableButtons;
If ListBox1.Items.Count=0 Then
Begin
WriteOut(' No file selected.');
EnableButtons;
Exit;
End;
Item:=0;
Repeat
AssignFile(Input,ListBox1.Items.Strings[Item]);
{$I-}
Reset(Input,1);
{$I+}
If IOResult<>0 Then
Begin
WriteOut(' Can not open the file.');
EnableButtons;
Exit;
End;
Seek(Input,8);
BlockRead(Input,ChunkName[1],8);
ChunkName[0]:=#8;
If ChunkName<>'AVI LIST' Then
Begin
WriteOut(' This is not an AVI file.');
CloseFile(Input);
EnableButtons;
Exit;
End;
WriteOut(' Stripping index...');
If CheckBox3.Checked Then
Begin
Logging:=True;
WriteOut(' Stripping index for file: '+ListBox1.Items.Strings[Item]);
End
Else WriteOut(' Stripping index for file: '+ListBox1.Items.Strings[Item]);
Position:=16;
Size:=0;
Chunkname[0]:=#4;
Repeat
Position:=Position+Size;
Seek(Input,Position);
BlockRead(Input,Size,4);
BlockRead(Input,Chunkname[1],4);
Inc(Position,8);
Until Chunkname='movi';
StreamStart:=Position-4;
StreamSize:=Size;
Seek(Input,StreamStart+StreamSize);
If Eof(Input) Then
Begin
WriteOut(' Unexpected end of file, index not found.');
CloseFile(Input);
EnableButtons;
Exit;
End;
Truncate(Input);
Seek(Input,StreamStart-4);
BlockWrite(Input,StreamSize,4);
CloseFile(Input);
WriteOut(' Done.');
WriteOut('');
Inc(Item);
Until Item=ListBox1.Items.Count;
EnableButtons;
end;
procedure TForm1.Button3Click(Sender: TObject);
Label CError;
Label CStartRead;
begin
If Autoclear1.Checked Then RichEdit1.Clear;
DisableButtons;
If ListBox1.Items.Count=0 Then
Begin
WriteOut(' No file selected.');
EnableButtons;
Exit;
End;
Item:=0;
Repeat
AssignFile(Input,ListBox1.Items.Strings[Item]);
AssignFile(Log,MaskEdit3.Text);
{$I-}
FileMode:=0;
Reset(Input,1);
FileMode:=2;
{$I+}
If IOResult<>0 Then
Begin
WriteOut(' Can not open the file.');
EnableButtons;
Exit;
End;
If CheckBox3.Checked Then
Begin
{$I-}
Reset(Log);
{$I+}
If IOResult<>0 Then
Begin
{$I-}
Rewrite(Log);
{$I+}
If IOResult<>0 Then
Begin
WriteOut(' Cannot create log file.');
CloseFile(Input);
EnableButtons;
Exit;
End
Else
Begin
CloseFile(Log);
Append(Log);
End;
End
Else
Begin
CloseFile(Log);
Append(Log);
End;
End;
Seek(Input,8);
BlockRead(Input,ChunkName[1],8);
ChunkName[0]:=#8;
If ChunkName<>'AVI LIST' Then
Begin
WriteOut(' This is not an AVI file.');
CloseFile(Input);
If CheckBox3.Checked Then CloseFile(Log);
EnableButtons;
Exit;
End;
If CheckBox3.Checked Then
Begin
Logging:=True;
WriteOut(' Error checking for file: '+ListBox1.Items.Strings[Item]);
End
Else WriteOut(' Error checking for file: '+ListBox1.Items.Strings[Item]);
WriteOut(' NOTE: The error checking is not perfect!');
Position:=16;
Size:=0;
Chunkname[0]:=#4;
Repeat
Position:=Position+Size;
Seek(Input,Position);
BlockRead(Input,Size,4);
BlockRead(Input,Chunkname[1],4);
Inc(Position,8);
Until Chunkname='movi';
StreamStart:=Position-4;
StreamSize:=Size;
Chunkname:='idx1';
Position:=4;
i:=0;
Frame:=0;
Interleaved:=False;
StopButton:=False;
Repeat
ProgressBar1.Position:=Position Div (FileSize(Input) Div 100);
Seek(Input,StreamStart+Position);
If Not Eof(Input) Then
Begin
CStartRead:
BlockRead(Input,Chunkname[1],4,Temp);
If ChunkName='LIST' Then
Begin
Seek(Input,FilePos(Input)+8);
Inc(Position,12);
Goto CStartRead;
End;
If ChunkName='JUNK' Then
Begin
BlockRead(Input,Size,4);
Position:=Position+Size+8;
Seek(Input,StreamStart+Position);
Goto CStartRead;
End;
Text2:=Copy(ChunkName,3,2);
If (Copy(ChunkName,1,2)='ix') Or (Text2='ix') Then
Begin
Seek(Input,FilePos(Input)+12);
Inc(Position,16);
Seek(Input,StreamStart+Position);
Interleaved:=True;
Goto CStartRead;
End;
If Not Eof(Input) Then
Begin
If ((ChunkName[1] In Number) And (ChunkName[2] In Number)) And
((Text2='dc') Or (Text2='db') Or (Text2='wb')) Then
Begin
If (Text2='dc') Or (Text2='db') Then Inc(Frame);
If Interleaved Then
Begin
Seek(Input,FilePos(Input)-16);
Dec(Position,16);
Interleaved:=False;
End;
BlockRead(Input,Size,4,Temp);
If (Size<0) And (Temp=4) Then
Begin
Inc(Position,4);
Seek(Input,StreamStart+Position);
BlockRead(Input,Chunkname[1],4);
If ChunkName='LIST' Then
Begin
Seek(Input,FilePos(Input)+8);
Inc(Position,12);
Goto CStartRead;
End;
If ChunkName='JUNK' Then
Begin
BlockRead(Input,Size,4);
Position:=Position+Size+8;
Seek(Input,StreamStart+Position);
Goto CStartRead;
End;
Seek(Input,StreamStart+Position);
Goto CError;
End;
If Not Eof(Input) Then
Begin
j:=(((Position+Size) Div 2)+((Position+Size) Mod 2))*2+8;
Seek(Input,StreamStart+j-1);
If Not Eof(Input) Then
Begin
Position:=(((Position+Size) Div 2)+((Position+Size) Mod 2))*2+8;
Inc(i);
End;
End;
End
Else
CError:
If Chunkname<>'idx1' Then
Begin
Str(Frame,Text);
Text:=' Corrupted data detected at frame '+Text;
WriteOut(Text);
Str(StreamStart+Position,Text);
Text:=' Error offset: '+Text+' ($'+IntToHex(StreamStart+Position,8)+')';
WriteOut(Text);
Repeat
Seek(Input,StreamStart+Position);
If Not Eof(Input) Then
Begin
BlockRead(Input,Buffer[1],32768,Temp);
j:=1;
Repeat
If ((Chr(Buffer[j])='d') Or (Chr(Buffer[j])='w')) And (Not Eof(Input)) Then
Begin
If ((Chr(Buffer[j+1])='c') Or (Chr(Buffer[j+1])='b')) And (Not Eof(Input)) Then
Begin
Seek(Input,StreamStart+Position+j-3);
If Not Eof(Input) Then BlockRead(Input,ChunkName[1],4);
End;
End;
Inc(j);
Text2:=Copy(ChunkName,3,2);
Until (((Text2='dc') Or (Text2='db') Or
(Text2='wb')) And ((ChunkName[1] In Number) And
(ChunkName[2] In Number))) Or (Chunkname='idx1') Or (j>32768);
End;
Inc(Position,j-3);
Application.ProcessMessages;
If StopButton Then
Begin
WriteOut(' Error checking aborted...');
ProgressBar1.Position:=0;
StopButton:=False;
CloseFile(Input);
If CheckBox3.Checked Then CloseFile(Log);
EnableButtons;
Exit;
End;
Text2:=Copy(ChunkName,3,2);
Until (((Text2='dc') Or (Text2='db') Or
(Text2='wb')) And ((ChunkName[1] In Number) And
(ChunkName[2] In Number))) Or (Chunkname='idx1') Or Eof(Input);
If Not Eof(Input) Then Dec(Position);
End
Else
Begin
Seek(Input,FilePos(Input)+6);
ChunkName[0]:=#2;
BlockRead(Input,ChunkName[1],2);
Seek(Input,FilePos(Input)-8);
If (ChunkName='dc') Or (ChunkName='wb') Or (ChunkName='db') Then
Begin
ChunkName[0]:=#4;
ChunkName:='idx1';
End
Else
Begin
ChunkName[0]:=#4;
ChunkName:='0000';
Goto CError;
End
End;
End;
End;
Application.ProcessMessages;
If StopButton Then
Begin
WriteOut(' Error checking aborted...');
ProgressBar1.Position:=0;
StopButton:=False;
CloseFile(Input);
If CheckBox3.Checked Then CloseFile(Log);
EnableButtons;
Exit;
End;
Until (Eof(Input)) Or (ChunkName='idx1');
WriteOut(' Done.');
WriteOut('');
ProgressBar1.Position:=100;
CloseFile(Input);
If CheckBox3.Checked Then CloseFile(Log);
Inc(Item);
Until Item=ListBox1.Items.Count;
EnableButtons;
end;
procedure TForm1.Exit1Click(Sender: TObject);
begin
Close;
end;
procedure TForm1.About1Click(Sender: TObject);
begin
Form1.Enabled:=False;
Form2.Show;
end;
procedure TForm1.StayTop(Sender: TObject);
begin
If Stayontop1.Checked Then
Begin
Stayontop1.Checked:=Not(Stayontop1.Checked);
SetWindowPos(TForm1(Self).Handle,HWND_NOTOPMOST,0,0,0,0,SWP_NOSIZE+SWP_NOMOVE);
End
Else
Begin
Stayontop1.Checked:=Not(Stayontop1.Checked);
SetWindowPos(TForm1(Self).Handle,HWND_TOPMOST,0,0,0,0,SWP_NOSIZE+SWP_NOMOVE);
End;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
DropFileTarget1.register(Form1);
If Tag=0 Then
Begin
GetDir(0,ConfigDir);
If Copy(ConfigDir,Length(ConfigDir),1)='\' Then AssignFile(Config,ConfigDir+'DivFix.ini')
Else AssignFile(Config,ConfigDir+'\DivFix.ini');
{$I-}
Reset(Config);
{$I+}
If IOResult=0 Then
Begin
While Not(Eof(Config)) Do
Begin
Readln(Config,Text);
If Copy(Text,1,7)='LastDir' Then
Begin
Form1.OpenDialog1.InitialDir:=Copy(Text,9,Length(Text)-9);
CfgDir:=Form1.OpenDialog1.InitialDir+'\';
End;
If Copy(Text,1,7)='DestDir' Then
Begin
Form1.MaskEdit2.Text:=Copy(Text,9,Length(Text)-7);
CfgDest:=Form1.MaskEdit2.Text;
End;
If Copy(Text,1,9)='StayOnTop' Then
If Copy(Text,11,Length(Text)-9)='1' Then
Begin
StayTop(Self);
CfgStay:=True;
End
Else CfgStay:=False;
If Copy(Text,1,9)='AutoClear' Then
If Copy(Text,11,Length(Text)-9)='1' Then
Begin
Autoclear1.Checked:=True;
CfgStay:=True;
End
Else CfgStay:=False;
If Copy(Text,1,12)='KeepOriginal' Then
If Copy(Text,14,Length(Text)-12)='1' Then
Begin
Form1.CheckBox1.Checked:=True;
CfgKeep:=True;
End
Else CfgKeep:=False;
If Copy(Text,1,6)='CutOut' Then
If Copy(Text,8,Length(Text)-6)='1' Then
If Form1.CheckBox2.Enabled Then
Begin
Form1.CheckBox2.Checked:=True;
CfgCut:=True;
End
Else CfgCut:=False;
If Copy(Text,1,9)='LogErrors' Then
If Copy(Text,11,Length(Text)-9)='1' Then
Begin
Form1.CheckBox3.Checked:=True;
CfgLog:=True;
End
Else CfgLog:=False;
End;
CloseFile(Config);
End;
End;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
DropFiletarget1.Unregister;
If Tag=0 Then
If (CfgDir<>OpenDialog1.InitialDir+'\') Or (CfgDest<>Form1.MaskEdit2.Text) Or
(CfgStay<>Stayontop1.Checked) Or (CfgKeep<>CheckBox1.Checked) Or
(CfgCut<>CheckBox2.Checked) Or (CfgLog<>CheckBox3.Checked) Or
(CfgClear<>Autoclear1.Checked) Then
Begin
Rewrite(Config);
If OpenDialog1.InitialDir<>'' Then Writeln(Config,'LastDir='+OpenDialog1.InitialDir+'\')
Else Writeln(Config,'LastDir=.\');
If Form1.MaskEdit2.Text<>'' Then Writeln(Config,'DestDir='+Form1.MaskEdit2.Text)
Else Writeln(Config,'DestDir=.\');
If Stayontop1.Checked Then Writeln(Config,'StayOnTop=1')
Else Writeln(Config,'StayOnTop=0');
If Autoclear1.Checked Then Writeln(Config,'AutoClear=1')
Else Writeln(Config,'AutoClear=0');
If CheckBox1.Checked Then Writeln(Config,'KeepOriginal=1')
Else Writeln(Config,'KeepOriginal=0');
If CheckBox2.Checked Then Writeln(Config,'CutOut=1')
Else Writeln(Config,'CutOut=0');
If CheckBox3.Checked Then Writeln(Config,'LogErrors=1')
Else Writeln(Config,'LogErrors=0');
CloseFile(Config);
End;
end;
procedure TForm1.DropFileTarget1Drop(Sender: TObject;
ShiftState: TShiftState; Point: TPoint; var Effect: Integer);
begin
ListBox1.Items.AddStrings(DropFileTarget1.Files);
OpenDialog1.InitialDir:=Copy(ExtractFilePath(ListBox1.Items.Strings[0]),1,
Length(ExtractFilePath(ListBox1.Items.Strings[0]))-1);
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
StopButton:=True;
end;
procedure TForm1.CheckBox1Click(Sender: TObject);
begin
CheckBox2.Enabled:=Not(CheckBox2.Enabled);
SpeedButton2.Enabled:=Not(SpeedButton2.Enabled);
Maskedit2.Enabled:=Not(MaskEdit2.Enabled);
If Not(CheckBox2.Enabled) Then CheckBox2.Checked:=False;
end;
procedure TForm1.CheckBox3Click(Sender: TObject);
begin
SpeedButton3.Enabled:=Not(SpeedButton3.Enabled);
Maskedit3.Enabled:=Not(MaskEdit3.Enabled);
If Not(CheckBox2.Enabled) Then CheckBox2.Checked:=False;
end;
procedure TForm1.ShowWebPage(Sender: TObject);
begin
ShellExecute(0,'open',pchar('http://divfix.maxeline.com'),nil,nil,SW_MAXIMIZE);
end;
procedure TForm1.Button5Click(Sender: TObject);
begin
If OpenDialog1.Execute Then
Begin
OpenDialog1.InitialDir:=Copy(ExtractFilePath(OpenDialog1.FileName),1,
Length(ExtractFilePath(OpenDialog1.FileName))-1);
ListBox1.Items.AddStrings(OpenDialog1.Files);
End;
end;
procedure TForm1.Button6Click(Sender: TObject);
Var i : Cardinal;
begin
i:=0;
While i<=ListBox1.Items.Count-1 Do
If ListBox1.Selected[i] Then ListBox1.Items.Delete(i)
Else Inc(i);
end;
procedure TForm1.Button7Click(Sender: TObject);
begin
ListBox1.Items.Clear;
end;
procedure TForm1.Clear1Click(Sender: TObject);
begin
RichEdit1.Clear;
end;
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
If Key=VK_INSERT Then Button5Click(nil);
If Key=VK_DELETE Then Button6Click(nil);
end;
end.