Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

preparing a self installable application

_yilmaz_yilmaz Member Posts: 150
Hi;

I have an application that uses some text files and midi files, so
I want to prepare a self installable package that will load the
required files and the main application (.exe file) beforehand in order
to be run correctly. What can I do?

Thanks in advance.

Yilmaz

Comments

  • zibadianzibadian Member Posts: 6,349
    : Hi;
    :
    : I have an application that uses some text files and midi files, so
    : I want to prepare a self installable package that will load the
    : required files and the main application (.exe file) beforehand in order
    : to be run correctly. What can I do?
    :
    : Thanks in advance.
    :
    : Yilmaz
    :
    You could try to get an installation program creator like the InstallShield or Wise Installation System. This is the easiest option, since most of these packages (I'm sure of the Wise System) have various wizards which allow you to set which files are necessary to install and where they should be installed to. Also these programs can compress the resulting setup, so it is easier to download and upload (or get them on disk). A simple alternative to this is to create a single zip-file containing all those files.
    Or you could add the files into the executable as resources. The latter would possibly remove the need to create an install code. If you still want to save the files as separate files, you can just read them from the resources and write them to disk.
    A third option is to copy the files directly into the executable; and if the program is run and the files don't exist, you can copy them back out of there.
  • PerranPerran Member Posts: 241
    : Hi;
    :
    : I have an application that uses some text files and midi files, so
    : I want to prepare a self installable package that will load the
    : required files and the main application (.exe file) beforehand in order
    : to be run correctly. What can I do?
    :
    : Thanks in advance.
    :
    : Yilmaz
    :
    InstallShield Express comes with some versions of Delphi. I use the pro edition and it's been available in that edition since v4.0. You might want to check your install CD's. You can also download a trial version from the InstallShield web site and give it a go.
  • _yilmaz_yilmaz Member Posts: 150
    Thanks to all. I have found the InstallShield program on my CD
    and used it. It works fine. Thanks again.

    Yilmaz
  • _yilmaz_yilmaz Member Posts: 150
    : A third option is to copy the files directly into the executable; and if the program is run and the files don't exist, you can copy them back out of there.
    :

    How can I copy files into the executable?
    Thanx,
    Yilmaz

  • zibadianzibadian Member Posts: 6,349
    : : A third option is to copy the files directly into the executable; and if the program is run and the files don't exist, you can copy them back out of there.
    : :
    :
    : How can I copy files into the executable?
    : Thanx,
    : Yilmaz
    :
    :
    The following is quite advanced, but it will give you the best control over the files to be copied into the executable. The biggest problem with this approach is that you also need to be able to extract the files from the executable. This requires something more than just copying the files into the executable using the DOS copy command.
    My suggestion is that you write a special program to copy the files into the executable, including the filenames and their lengths. This info can then be used to copy the files back out. This imposes a few limitations to the filenames, which shouldn't be too much of a problem. I would suggest that you stick to the old DOS 8.3 short filenames, which gives you a constant length for it, ie. 14 characters. The length of the files can best be coded as an integer. This means that each additional file is copied into the executable in the following manner:
    [code]
    File position Data
    0..13 Filename
    14..17 File length
    18.... File itself
    [/code]
    The last thing that needs adding is to list, where the first data file starts. This is best done at the end of the entire destination file, because that gives you a known point to start from.
    Since this is such an advanced method, let me give you the entire code to add a single file to the executable.
    [code]
    type
    TMyFilename: array[1..14] of char;
    var
    SourceFilename: TMyFilename;
    Buffer: array[0..1023] of char;
    SourceFile, DestFile: file;
    begin
    AssignFile(DestFile, DestFilename); // open the destination file
    Rewrite(DestFile, 1);
    { Option: Loop through several source files }
    AssignFile(SourceFile, SourceFilename); // open the source file
    Reset(SourceFile, 1);
    Seek(DestFile, FileSize(DestFile)); // Go to end of destination file
    BlockWrite(DestFile, SourceFilename, SizeOf(TMyFilename)); // write source filename
    BlockWrite(DestFile, FileSize(SourceFile), SizeOf(integer)); // write source file size
    while not eof(SourceFile) do begin // copy entire sourcefile 1 KB at a time
    BlockRead(SourceFile, Buffer, SizeOf(Buffer), BytesRead);
    BlockWrite(DestFile, Buffer, BytesRead);
    end;
    CloseFile(SourceFile); // close source file
    { Option: End Loop }
    AssignFile(SourceFile, ExeFilename); // open the original executable
    Reset(SourceFile, 1);
    BlockWrite(DestFile, FileSize(SourceFile), SizeOf(integer)); // write its size
    CloseFile(SourceFile); // close original executable
    CloseFile(DestFile); // close resulting executable
    [/code]
    Notes:
    - Make sure that the destination file is not the same as any of the source files.
    - An array of char should be possible to be assigned to a string, ie. "SourceFilename := OpenDialog1.Filename".
    - The loop code can be something like this (SourceFilenames = TStringList OR ListBox.Items OR Memo.Lines, etc.):
    [code]
    for i := 0 to SourceFilenames.Count-1 do begin
    SourceFilename := SourceFilenames[i];
    [/code]
    Let me know if you intent to use this, then I will give you also the reading code, which is slightly more complex.
  • _yilmaz_yilmaz Member Posts: 150

    Thank you very much. I would like to use this code, but there's one more thing I want to ask. The files I would like to include are text files, and their contents may change during execution. Is it possible to reflect this changes back into the files in the executable?

    Thanks again.


    : : : A third option is to copy the files directly into the executable; and if the program is run and the files don't exist, you can copy them back out of there.
    : : :
    : :
    : : How can I copy files into the executable?
    : : Thanx,
    : : Yilmaz
    : :
    : :
    : The following is quite advanced, but it will give you the best control over the files to be copied into the executable. The biggest problem with this approach is that you also need to be able to extract the files from the executable. This requires something more than just copying the files into the executable using the DOS copy command.
    : My suggestion is that you write a special program to copy the files into the executable, including the filenames and their lengths. This info can then be used to copy the files back out. This imposes a few limitations to the filenames, which shouldn't be too much of a problem. I would suggest that you stick to the old DOS 8.3 short filenames, which gives you a constant length for it, ie. 14 characters. The length of the files can best be coded as an integer. This means that each additional file is copied into the executable in the following manner:
    : [code]
    : File position Data
    : 0..13 Filename
    : 14..17 File length
    : 18.... File itself
    : [/code]
    : The last thing that needs adding is to list, where the first data file starts. This is best done at the end of the entire destination file, because that gives you a known point to start from.
    : Since this is such an advanced method, let me give you the entire code to add a single file to the executable.
    : [code]
    : type
    : TMyFilename: array[1..14] of char;
    : var
    : SourceFilename: TMyFilename;
    : Buffer: array[0..1023] of char;
    : SourceFile, DestFile: file;
    : begin
    : AssignFile(DestFile, DestFilename); // open the destination file
    : Rewrite(DestFile, 1);
    : { Option: Loop through several source files }
    : AssignFile(SourceFile, SourceFilename); // open the source file
    : Reset(SourceFile, 1);
    : Seek(DestFile, FileSize(DestFile)); // Go to end of destination file
    : BlockWrite(DestFile, SourceFilename, SizeOf(TMyFilename)); // write source filename
    : BlockWrite(DestFile, FileSize(SourceFile), SizeOf(integer)); // write source file size
    : while not eof(SourceFile) do begin // copy entire sourcefile 1 KB at a time
    : BlockRead(SourceFile, Buffer, SizeOf(Buffer), BytesRead);
    : BlockWrite(DestFile, Buffer, BytesRead);
    : end;
    : CloseFile(SourceFile); // close source file
    : { Option: End Loop }
    : AssignFile(SourceFile, ExeFilename); // open the original executable
    : Reset(SourceFile, 1);
    : BlockWrite(DestFile, FileSize(SourceFile), SizeOf(integer)); // write its size
    : CloseFile(SourceFile); // close original executable
    : CloseFile(DestFile); // close resulting executable
    : [/code]
    : Notes:
    : - Make sure that the destination file is not the same as any of the source files.
    : - An array of char should be possible to be assigned to a string, ie. "SourceFilename := OpenDialog1.Filename".
    : - The loop code can be something like this (SourceFilenames = TStringList OR ListBox.Items OR Memo.Lines, etc.):
    : [code]
    : for i := 0 to SourceFilenames.Count-1 do begin
    : SourceFilename := SourceFilenames[i];
    : [/code]
    : Let me know if you intent to use this, then I will give you also the reading code, which is slightly more complex.
    :

  • zibadianzibadian Member Posts: 6,349
    It is possible, but very difficult and involved. But why would you want to do that?
    :
    : Thank you very much. I would like to use this code, but there's one more thing I want to ask. The files I would like to include are text files, and their contents may change during execution. Is it possible to reflect this changes back into the files in the executable?
    :
    : Thanks again.
    :
    :
    : : : : A third option is to copy the files directly into the executable; and if the program is run and the files don't exist, you can copy them back out of there.
    : : : :
    : : :
    : : : How can I copy files into the executable?
    : : : Thanx,
    : : : Yilmaz
    : : :
    : : :
    : : The following is quite advanced, but it will give you the best control over the files to be copied into the executable. The biggest problem with this approach is that you also need to be able to extract the files from the executable. This requires something more than just copying the files into the executable using the DOS copy command.
    : : My suggestion is that you write a special program to copy the files into the executable, including the filenames and their lengths. This info can then be used to copy the files back out. This imposes a few limitations to the filenames, which shouldn't be too much of a problem. I would suggest that you stick to the old DOS 8.3 short filenames, which gives you a constant length for it, ie. 14 characters. The length of the files can best be coded as an integer. This means that each additional file is copied into the executable in the following manner:
    : : [code]
    : : File position Data
    : : 0..13 Filename
    : : 14..17 File length
    : : 18.... File itself
    : : [/code]
    : : The last thing that needs adding is to list, where the first data file starts. This is best done at the end of the entire destination file, because that gives you a known point to start from.
    : : Since this is such an advanced method, let me give you the entire code to add a single file to the executable.
    : : [code]
    : : type
    : : TMyFilename: array[1..14] of char;
    : : var
    : : SourceFilename: TMyFilename;
    : : Buffer: array[0..1023] of char;
    : : SourceFile, DestFile: file;
    : : begin
    : : AssignFile(DestFile, DestFilename); // open the destination file
    : : Rewrite(DestFile, 1);
    : : { Option: Loop through several source files }
    : : AssignFile(SourceFile, SourceFilename); // open the source file
    : : Reset(SourceFile, 1);
    : : Seek(DestFile, FileSize(DestFile)); // Go to end of destination file
    : : BlockWrite(DestFile, SourceFilename, SizeOf(TMyFilename)); // write source filename
    : : BlockWrite(DestFile, FileSize(SourceFile), SizeOf(integer)); // write source file size
    : : while not eof(SourceFile) do begin // copy entire sourcefile 1 KB at a time
    : : BlockRead(SourceFile, Buffer, SizeOf(Buffer), BytesRead);
    : : BlockWrite(DestFile, Buffer, BytesRead);
    : : end;
    : : CloseFile(SourceFile); // close source file
    : : { Option: End Loop }
    : : AssignFile(SourceFile, ExeFilename); // open the original executable
    : : Reset(SourceFile, 1);
    : : BlockWrite(DestFile, FileSize(SourceFile), SizeOf(integer)); // write its size
    : : CloseFile(SourceFile); // close original executable
    : : CloseFile(DestFile); // close resulting executable
    : : [/code]
    : : Notes:
    : : - Make sure that the destination file is not the same as any of the source files.
    : : - An array of char should be possible to be assigned to a string, ie. "SourceFilename := OpenDialog1.Filename".
    : : - The loop code can be something like this (SourceFilenames = TStringList OR ListBox.Items OR Memo.Lines, etc.):
    : : [code]
    : : for i := 0 to SourceFilenames.Count-1 do begin
    : : SourceFilename := SourceFilenames[i];
    : : [/code]
    : : Let me know if you intent to use this, then I will give you also the reading code, which is slightly more complex.
    : :
    :
    :

  • _yilmaz_yilmaz Member Posts: 150
    : It is possible, but very difficult and involved. But why would you want to do that?

    My project is a game, and the text files include some data that I don't
    want to be accessed by the users by no means. For example, one of the text files include the top scores.

    Is there an easy way to achieve this?

    Thanx
  • zibadianzibadian Member Posts: 6,349
    : : It is possible, but very difficult and involved. But why would you want to do that?
    :
    : My project is a game, and the text files include some data that I don't
    : want to be accessed by the users by no means. For example, one of the text files include the top scores.
    :
    : Is there an easy way to achieve this?
    :
    : Thanx
    :
    I would then suggest some sort of encryption, because the procedure of overwriting a file inside the executable is very error-prone and unless you know how to lock-out the rest of windows, the user will be able to access the file during the game play. In the Delphi source codes on this site are several good encryptions.
Sign In or Register to comment.