Solved

adding files to the exe

Posted on 2001-06-20
8
281 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi 2010 Export to pdf 2 287
Thread safe  opinion 7 126
Send message from delphi to whatsapp, is it possible? 3 1,185
JAudiorecorder record freezing the app 29 60
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

895 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

16 Experts available now in Live!

Get 1:1 Help Now