unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
OpenDialog1: TOpenDialog;
Button2: TButton;
ListBox1: TListBox;
Button3: TButton;
Edit2: TEdit;
Button4: TButton;
Button5: TButton;
Edit3: TEdit;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
private
procedure generarFicheros; //genear los ficheros
function generarString(tamaño:integer):string; // generar un nuevo hash o md5
public
{ Public declarations }
end;
var
Form1: TForm1;
fichero:string;//obtendra el contenido del fichero seleccionado
extension:string;//almacenara la extension del fichero
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
OpenDialog1.FileName:='';
if OpenDialog1.Execute then
begin
Edit1.Text:=OpenDialog1.FileName;
fichero:= edit1.Text;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
if Edit2.Text<>'' then
begin
ListBox1.Items.Add(Edit2.Text);//añade la nueva palabra
Edit2.Clear; //limpia el edit
end;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
if ((ListBox1.Items.Count=0) or (edit1.Text='')) then//si no se ha cargar palabras o el fichero
begin
showmessage('Error ha olvidado cargar los nombres o el fichero');
Exit;
end;
if not FileExists('Generados') then CreateDir('Generados'); //si no existe la carpeta la crea
extension:=Edit3.Text; // obtenemos la extension
generarFicheros; //genenramos los archivos nuevos
showmessage('Listo archivos generados ');
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
if ListBox1.ItemIndex<>-1 then
begin
ListBox1.DeleteSelected;//eliminamos alguna palabra selecccionada en el listbox
end;
end;
procedure TForm1.Button5Click(Sender: TObject);
var
texto:TextFile;
linea:string;
begin
//lo de abajo nos leera el archivo txt con los nombres
OpenDialog1.FileName:='';
if OpenDialog1.Execute then
begin
AssignFile(texto,OpenDialog1.FileName);
try
reset(texto);
while not eof(texto) do
begin
readln(texto,linea);
ListBox1.Items.Add(linea);
end;
finally
CloseFile(texto);
end;
end;
end;
procedure TForm1.generarFicheros;
var
rd,rw:TFileStream;
buffer,salida:string;
I,valor: Integer;
begin
rd:=TFileStream.Create(fichero,fmOpenRead);
try
setlength(buffer,rd.Size);
rd.Read(buffer[1],rd.Size);
valor:=1;
for I := 0 to ListBox1.Items.Count-1 do
begin
rw:=TFileStream.Create('Generados\'+ListBox1.Items[i]+'.'+extension,fmCreate);
try
salida:=buffer+generarString(valor);
rw.Write(salida[1],length(salida));
inc(valor);
finally
rw.Free;
end;
end;
finally
rd.Free;
end;
end;
//generar un nuevo string que servira para cambiar el hash del fichero
function TForm1.generarString(tamaño: integer): string;
var
i: Integer;
cadena:string;
begin
randomize;
for i := 1 to tamaño do
begin
cadena:=cadena+chr(random(255));
end;
result:=cadena;
end;
end.