1
0
mirror of https://github.com/moparisthebest/Simba synced 2024-11-24 10:12:20 -05:00
Simba/Projects/RUTIS Wrappers/wrapfiles.pas

128 lines
2.8 KiB
ObjectPascal
Raw Normal View History

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;
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);
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;
begin
2010-09-06 16:32:04 -04:00
YesToAll:= false;
NoToAll:= false;
if not DirectoryExists(SaveDirEdit.Directory) then
begin
2010-09-06 16:32:04 -04:00
dbg(format('Dir %s does not exist',[SaveDirEdit.Directory]));
exit;
end;
2010-09-06 16:32:04 -04:00
if FileBox.Items.Count < 1 then
begin
2010-09-06 16:32:04 -04:00
dbg('No files loaded');
exit;
end;
2010-09-10 19:10:49 -04:00
Procnames := TStringList.Create;
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;
end;
2010-09-10 19:10:49 -04:00
dbg(Procnames.Text);
if FileNameEdit1.Text <> '' then
Procnames.SaveToFile(FileNameEdit1.text);
Procnames.Free;
end;
end.