Recent

Author Topic: SOLVED: A simple project  (Read 2752 times)

AsleyCruz

  • Jr. Member
  • **
  • Posts: 98
    • Graphic and web designer
SOLVED: A simple project
« on: April 04, 2020, 05:33:07 pm »
Hi team

I have to create a simple project at my university and would like to create a "Installer Creator" / "Setup Creator"
like the attached image.

The program will work like this:
* Select directory of files
* Select destination folder (i.g. C\Program files\My Application)
* Compile files (create a setup with the forms designed in Lazarus)

This is the idea... but the big question is... How can I compile the files into a simple exe using FPC?
Maybe someone can help me and any idea is appreciated.

Thanks a lot coders.

« Last Edit: April 08, 2020, 10:26:53 pm by AsleyCruz »
Graphic & web designer

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: A simple project
« Reply #1 on: April 04, 2020, 05:53:43 pm »
look at "Inno Setup" which creates an installable file in a single EXE if you wish..

I don't know about the program you are showing here.
The only true wisdom is knowing you know nothing

AsleyCruz

  • Jr. Member
  • **
  • Posts: 98
    • Graphic and web designer
Re: A simple project
« Reply #2 on: April 04, 2020, 05:57:38 pm »
look at "Inno Setup" which creates an installable file in a single EXE if you wish..

I don't know about the program you are showing here.

Hi Jamie
I know about Inno Setup and others installers creators but in this case I would like to create a simple
installer creator (it is a university project). I just need to know how to compile files into an exe file using Free Pascal.

Thanks.
Graphic & web designer

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
Re: A simple project
« Reply #3 on: April 04, 2020, 07:02:39 pm »
I'm not sure how others do it but I ever did such the thing you mentioned. Actually, what you want to do is not simple, you really need some or maybe good programming knowledge to be able to do it.

Here is how I did it:

First, I wrote code to merge to 2 binary files into a single file. But I have to put a marker between them. The first part is the installer itself, then marker, and the last is the data: exe + marker + data.

The installer itself has the ability to load itself's file to memory and scan for the position of the marker. So it can know where is the position the data started.

Then I improved the installer to be able extract the data to files. The data (in the memory) actually is the compressed files (into a single file in memory), so I can uncompressed them back to files and save them to the disk.

I haven't write code make it automatically compress the files into single file, it is not hard but I can simply compress files using my Linux file manager.

The installer I wrote actually is a 2 programs in a single exe file:
- It can scan itself, separate the data and uncompressed files to disk
- It can merge binary and zip file into a single binary

I wrote it as a feature for my game builder. It works, I quickly tested on Linux and Windows. But I think it may trigger some antivirus or Windows security issue.
« Last Edit: April 04, 2020, 07:06:41 pm by Handoko »

440bx

  • Hero Member
  • *****
  • Posts: 3944
Re: A simple project
« Reply #4 on: April 04, 2020, 07:10:00 pm »
I just need to know how to compile files into an exe file using Free Pascal.

Thanks.
It's quite simple.  Compile/build the .exe then, include the .exe as a binary resource file in your installer.  That way the .exe is just another resource in the installer program.  I'd give you some code but, I only know how to do it using straight Windows API.  I have no clue how to get that done in the Lazarus environment.  Hopefully someone else can fill that part.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

AsleyCruz

  • Jr. Member
  • **
  • Posts: 98
    • Graphic and web designer
Re: A simple project
« Reply #5 on: April 04, 2020, 07:28:49 pm »
I'm not sure how others do it but I ever did such the thing you mentioned. Actually, what you want to do is not simple, you really need some or maybe good programming knowledge to be able to do it...

Interesting work. Maybe you could share us some code to have a better idea.
Thanks
Graphic & web designer

AsleyCruz

  • Jr. Member
  • **
  • Posts: 98
    • Graphic and web designer
Re: A simple project
« Reply #6 on: April 04, 2020, 07:29:51 pm »
I just need to know how to compile files into an exe file using Free Pascal.

Thanks.
It's quite simple.  Compile/build the .exe then, include the .exe as a binary resource file in your installer.  That way the .exe is just another resource in the installer program.  I'd give you some code but, I only know how to do it using straight Windows API.  I have no clue how to get that done in the Lazarus environment.  Hopefully someone else can fill that part.

Please, share your code. It will be easier to have an idea on how to do it..
Thanks a lot
Graphic & web designer

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: A simple project
« Reply #7 on: April 04, 2020, 07:34:56 pm »
It's quite simple.  Compile/build the .exe then, include the .exe as a binary resource file in your installer.  That way the .exe is just another resource in the installer program.  I'd give you some code but, I only know how to do it using straight Windows API.  I have no clue how to get that done in the Lazarus environment.  Hopefully someone else can fill that part.

Shouldn't be too difficult combining a TResourceStream to read the binary with a TFileStream to save it to file.

Note also that it's relatively easy to compile the "original", copy it to the "setup" project folder and build the "setup" project (so as to include the newly created exe). Just a matter of using FindAllFiles() to find the original .lpi, a TProcess to execute lazbuild, CopyFile() to copy and another (or the same) TProcess to build the installer. Piece of cake :D
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

fabiopesaju

  • Jr. Member
  • **
  • Posts: 93
Re: A simple project
« Reply #8 on: April 04, 2020, 08:01:51 pm »

440bx

  • Hero Member
  • *****
  • Posts: 3944
Re: A simple project
« Reply #9 on: April 06, 2020, 01:25:27 am »
Please, share your code. It will be easier to have an idea on how to do it..
Thanks a lot
Sure.

Here is a little test program I wrote over 20 years ago.  Some of the comments refer to Windows 95, you can ignore them but, they apply to current versions of Windows too.

When you load the .lpr select "Simple program" not anything else because if you do, Lazarus will overwrite the .res file with a res file it creates and doesn't even warn you that the res file is overwritten.

Also, the .rc file included is compiled with Borland's resource compiler (BRCC32.exe) I doubt it can be compiled with something else.

This test program defines binary data directly in the .rc file (have a look in the .rc if you are curious.)  To replace that data with your executable, use ResourceHacker to edit the .res file (or the resulting program directly, your choice.)  You will find resource hacker at http://www.angusj.com/resourcehacker/  it is a very nice and very useful utility.

In this test program, the binary data is displayed in the main window during the processing of the WM_PAINT.  In the case of an embedded executable, it's quite unlikely you'd want to do that.  Instead you'd probably want to load the resource and write it out in some other part of your program.  Where the code should go in your program is up to you.

I know Lazarus most likely provides a way to do this with less code but, as I stated before, I only use OS functions, Windows API in this case, therefore I have no clue how the same thing is done the Lazarus/FPC way.

You're welcome.  Hopefully, it will be helpful to you in spite of being pure Windows API.



(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

avk

  • Hero Member
  • *****
  • Posts: 752
Re: A simple project
« Reply #10 on: April 06, 2020, 04:19:46 pm »
It seems that there is another (more Lazarus-ish?) way to save separate binary files inside your application. Somewhere I had the simplest non-visual component that allows you to load binary data at design time and use it at runtime. If you are interested, I will find it.

AsleyCruz

  • Jr. Member
  • **
  • Posts: 98
    • Graphic and web designer
Re: A simple project
« Reply #11 on: April 06, 2020, 07:41:34 pm »
It seems that there is another (more Lazarus-ish?) way to save separate binary files inside your application. Somewhere I had the simplest non-visual component that allows you to load binary data at design time and use it at runtime. If you are interested, I will find it.
Hi avk, it would be great if you share that component. Thanks in advance.

Thank to all of you... still looking for a way to bind files in a stub through Lazarus.
Graphic & web designer

avk

  • Hero Member
  • *****
  • Posts: 752
Re: A simple project
« Reply #12 on: April 06, 2020, 08:55:13 pm »
Well, I hope you find it useful.

AsleyCruz

  • Jr. Member
  • **
  • Posts: 98
    • Graphic and web designer
Re: A simple project
« Reply #13 on: April 08, 2020, 02:25:03 am »
Well, I hope you find it useful.
Many thanks avk. It works great.

It saves the file into the exe but in design time.
The component has only two procedures: SaveToStream and SaveToFile.

Is it possible to save any file into the exe but in run time?
I have tried but nothing.

Thanks again for your time.
Graphic & web designer

440bx

  • Hero Member
  • *****
  • Posts: 3944
Re: A simple project
« Reply #14 on: April 08, 2020, 02:29:20 am »
Is it possible to save any file into the exe but in run time?
Only if you create a copy of the exe at runtime because, while the exe is running, the O/S won't allow you to make any changes to its file.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

 

TinyPortal © 2005-2018