2010-09-05 18:00:21 -04:00
|
|
|
unit wrapfiles;
|
|
|
|
|
|
|
|
{$mode objfpc}{$H+}
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
|
|
|
|
EditBtn;
|
|
|
|
|
|
|
|
type
|
|
|
|
|
|
|
|
{ TWrapFilesForm }
|
|
|
|
|
|
|
|
TWrapFilesForm = class(TForm)
|
|
|
|
dbgMemo: TMemo;
|
2010-09-10 19:10:49 -04:00
|
|
|
FileNameEdit1: TFileNameEdit;
|
|
|
|
Label1: TLabel;
|
2010-09-05 18:00:21 -04:00
|
|
|
wrpBtn: TButton;
|
|
|
|
SaveDirEdit: TDirectoryEdit;
|
|
|
|
FileButton: TButton;
|
|
|
|
FileBox: TListBox;
|
|
|
|
FileDialog: TOpenDialog;
|
|
|
|
SaveDirLabel: TLabel;
|
|
|
|
procedure FileButtonClick(Sender: TObject);
|
|
|
|
procedure FormCreate(Sender: TObject);
|
|
|
|
procedure wrpBtnClick(Sender: TObject);
|
|
|
|
private
|
|
|
|
{ private declarations }
|
|
|
|
public
|
|
|
|
{ public declarations }
|
|
|
|
end;
|
|
|
|
|
|
|
|
var
|
|
|
|
WrapFilesForm: TWrapFilesForm;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
uses
|
|
|
|
Main;
|
|
|
|
|
|
|
|
{$R *.lfm}
|
|
|
|
|
|
|
|
{ TWrapFilesForm }
|
|
|
|
|
|
|
|
procedure TWrapFilesForm.FileButtonClick(Sender: TObject);
|
|
|
|
begin
|
|
|
|
if FileDialog.Execute then
|
|
|
|
begin
|
2010-09-06 16:32:04 -04:00
|
|
|
SaveDirEdit.Directory := ExtractFileDir(FileDialog.FileName);
|
2010-09-05 18:00:21 -04:00
|
|
|
FileBox.Items.AddStrings(FileDialog.Files);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TWrapFilesForm.FormCreate(Sender: TObject);
|
|
|
|
begin
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TWrapFilesForm.wrpBtnClick(Sender: TObject);
|
|
|
|
procedure dbg(s : string);
|
|
|
|
begin
|
|
|
|
dbgMemo.Lines.Add(s);
|
|
|
|
end;
|
|
|
|
|
|
|
|
var
|
|
|
|
i : integer;
|
2010-09-10 19:10:49 -04:00
|
|
|
Input, Output,Procnames : TStringList;
|
2010-09-06 16:32:04 -04:00
|
|
|
NewFile : string;
|
|
|
|
YesToAll, NoToAll : boolean;
|
2010-09-05 18:00:21 -04:00
|
|
|
begin
|
2010-09-06 16:32:04 -04:00
|
|
|
YesToAll:= false;
|
|
|
|
NoToAll:= false;
|
2010-09-05 18:00:21 -04:00
|
|
|
if not DirectoryExists(SaveDirEdit.Directory) then
|
|
|
|
begin
|
2010-09-06 16:32:04 -04:00
|
|
|
dbg(format('Dir %s does not exist',[SaveDirEdit.Directory]));
|
2010-09-05 18:00:21 -04:00
|
|
|
exit;
|
|
|
|
end;
|
2010-09-06 16:32:04 -04:00
|
|
|
if FileBox.Items.Count < 1 then
|
2010-09-05 18:00:21 -04:00
|
|
|
begin
|
2010-09-06 16:32:04 -04:00
|
|
|
dbg('No files loaded');
|
2010-09-05 18:00:21 -04:00
|
|
|
exit;
|
|
|
|
end;
|
2010-09-10 19:10:49 -04:00
|
|
|
Procnames := TStringList.Create;
|
2010-09-05 18:00:21 -04:00
|
|
|
for i := 0 to FileBox.Items.Count - 1 do
|
|
|
|
begin
|
2010-09-06 16:32:04 -04:00
|
|
|
if not FileExists(filebox.items[i]) then
|
|
|
|
begin
|
|
|
|
dbg(format('File[%s] does not exist',[FileBox.items[i]]));
|
|
|
|
continue;
|
|
|
|
end;
|
|
|
|
NewFile := SaveDirEdit.Directory + DirectorySeparator + ExtractFileName(FileBox.Items[i]);
|
|
|
|
if not YesToAll and FileExists(NewFile) then
|
|
|
|
begin
|
|
|
|
if NoToAll then
|
|
|
|
Continue;
|
|
|
|
case MessageDlg('File already exists',Format('Do you want to overwrite the file %s',[NewFile]),
|
|
|
|
mtConfirmation,[mbYes,mbYesToAll,mbNo,mbNoToAll],0) of
|
|
|
|
mrNo : Continue;
|
|
|
|
mrNoToAll : begin
|
|
|
|
NoToAll:= True;
|
|
|
|
Continue;
|
|
|
|
end;
|
|
|
|
mrYesToAll : YesToAll:= true;
|
|
|
|
end;
|
2010-09-10 19:10:49 -04:00
|
|
|
dbg(BoolToStr(YesToAll,true));
|
2010-09-06 16:32:04 -04:00
|
|
|
end;
|
|
|
|
dbg(NewFile);
|
|
|
|
try
|
|
|
|
Input := TStringList.Create;
|
|
|
|
Input.LoadFromFile(filebox.items[i]);
|
|
|
|
Output := TStringList.Create;
|
2010-09-10 19:10:49 -04:00
|
|
|
ConvertRT(Input,dbgMemo.Lines,Output,Procnames);
|
2010-09-06 16:32:04 -04:00
|
|
|
Output.SaveToFile(NewFile);
|
|
|
|
Input.free;
|
|
|
|
Output.free;
|
|
|
|
except
|
|
|
|
dbg('Something went wrong');
|
|
|
|
end;
|
2010-09-05 18:00:21 -04:00
|
|
|
end;
|
2010-09-10 19:10:49 -04:00
|
|
|
dbg(Procnames.Text);
|
|
|
|
if FileNameEdit1.Text <> '' then
|
|
|
|
Procnames.SaveToFile(FileNameEdit1.text);
|
|
|
|
Procnames.Free;
|
2010-09-05 18:00:21 -04:00
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|
|
|
|
|