Solved

adding files to the exe

Posted on 2001-06-20
8
289 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

690 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