Solved

adding files to the exe

Posted on 2001-06-20
8
279 Views
Last Modified: 2010-04-06
Hi,

i'm trying to make a installer program and making it so you only have the exe file. if anyone can show me some code without components would be a great help.
:-)
cheers
classic
0
Comment
Question by:classic_gaming
8 Comments
 
LVL 2

Expert Comment

by:FrodoBeggins
ID: 6210938
Use any archiver with self - extractor ;-))

Joke.

I'm not sure u want to do that. Think about the memory management windows will do about that hudge .exe. Bad idea.
0
 
LVL 6

Expert Comment

by:edey
ID: 6211024
I don't have a copy of delphi handy here, but I can give the gist of it :)

You can append anything to the end of an exe, you just need some way of knowing how much is 'extra' so you could do something like this:

declare a record type to keep track of your size info, try:

type
 TAppendedFooter = record
   sig = array[0..3] of char;
   exeSize : cardinal;
 end;

put some 4 letter string into sig, so you know that this exe has appended files.  the exeSize is the size _before_ you append, fileSize(application.exename) would be the call here.

You can't write to your own exe file while it's writing, but you can read from it, so the idea is to start with 2 files (your exe plus the file to append) and end up with a third.  To be able to read your own exe try:

var
 exefs : TFileStream;
begin
 exefs := TFileStream.create(application.exename,fmOpenRead or fmShareDenyNone);

note, I may have my constants wrong, you just need to open for read only with the none exclusive share settings.

create another filestream for your output (with write access, of course), copy everything from exefs, then copy your file to be appended, then copy your TAppendedFooter.  You can do this several times.

To extract those files, read the footer, create two dest. filestreams, write the first TAppendedFooter.exeSize bytes to one filestream (your new exe, minus the appended file) and the remaining, minus sizeOf(TAppendedFooter) to the other (your appended file).  Again, if your appended serveral files you should be able to do this several times.

GL
Mike
0
 

Expert Comment

by:d32coder
ID: 6211190
Delphi comes with an "Express Installer"??

I thought that was the purpose for it but I never looked at it.

Don
0
 

Author Comment

by:classic_gaming
ID: 6211233
woah just tried the code loads of errors :-). i'll have a go later on getting it right if it works i'll add it as a answer.
cheers
classic
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:classic_gaming
ID: 6211241
woah just tried the code loads of errors :-). i'll have a go later on getting it right if it works i'll add it as a answer.
cheers
classic
0
 

Accepted Solution

by:
x4 earned 300 total points
ID: 6211276
Not to hard at all if your using Delphi 5.  I found this online a few days ago I was looking for the same solution.

Here is the answer:

1. Go up to FILE/ADD and add a text file.
In the text file add what ever resources you want, Example:
JPG RCDATA MAME.JPG
EXE RCDATA MAME.EXE
Every new line is a new resource.
(Make sure you copy these files into the same directory where your program files for delphi are).

2. Then save your project.  Make sure you save the text as filename.rc instead of filename.txt

3. Now go up to PROJECT/ADD and select the filename.rc file you just saved.

4. Do a complete Build on your program.
This imports the resource file and all the resources into your program executable.  You can see because your program.exe should be the size it was plus the files added.
Or use resxplor.exe under your delphi\demos\resxplor\ to open your program.exe and see under RCDATA the files you added.

4. Now when you want to extract these files and use them just create a procedure in code that does this:

procedure TForm1.GetResources(Sender: TObject);
var
  RS : TResourceStream;
begin
  // Extract Mame Image
  RS := TResourceStream.Create( 0, 'JPG', RT_RCDATA);
  try
    RS.SaveToFile('c:\mame\shots\mame.jpg');
  finally
    RS.Free;
  end;
  // Extract Mame Executable
  RS := TResourceStream.Create( 0, 'EXE', RT_RCDATA);
  try
    RS.SaveToFile('c:\mame\mame.exe');
  finally
    RS.Free;
  end;
end;

Thats it!




Original answer copied from:
http://www.delphi3000.com/articles/article_2018.asp
0
 
LVL 5

Expert Comment

by:Gwena
ID: 6211454
I have some demos on my site
Http://delphi.does.it

Delphi apps that modify themselves as they run
and some that add files to themselves (not res files)
and create a new exe with the files ready to be extracted
to disk :-)

The source code is there with some of the demos...
feel free to use them as a shell to write your installer
program if you like :-)

An unfinished version of my floppy disk imager is on the site.. 'EXE2A' it works well enough so that you can see how
an installer prog might work... it sucks in a 1.44 mb
floppy and compresses the data and adds it to the end of
it's own exe file... then it changes the 3rd byte of the
exe from a 'P' to an 'A' so that the next time it runs it knows it should display as if it were a different exe...
this trick works great and the 2 programs seem to be different exe's but they are actually the same one... just change the 'MZA' back to 'MZP' and the original comes
back... you could write an installer using the same method :-)
0
 

Author Comment

by:classic_gaming
ID: 6212331
i tested it and it worked fine :-)
cheers
classic
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now