开发者

How to use project version information inside a Delphi application?

开发者 https://www.devze.com 2023-02-21 22:13 出处:网络
I use Project Options / Version to manage the version info (N.N.N.N format). Anyway inside my project I duplicate those info.

I use Project Options / Version to manage the version info (N.N.N.N format).

Anyway inside my project I duplicate those info.

So if in project options I am working on release 2.4.3.178 inside my application I have 4 integer variables that hold the 4 numbers.

I manually set them

Major := 2;
Minor := 4;
Release := 3;
Build := 178;

The reason of this is simple: I have licensing based on version number. So if the user buys release "2.4" it is not allowed to upgrade to version "3.0".

But if I rely on project version info the user can (with Resource Hacker tool开发者_开发问答s) change the version info and therefore "activate" the product.

The user cannot change the 4 variables in the same way (not as easily at least).

This works but forces me duplicate the info.

Could you suggest a better approach?

Otherwise said: is there a way to write the version info using the data I write in those 4 variables. Something like in Post Build Events, but how do I pass data to post build events?


You'd need a pre-build event rather than a post-build event since you'd want to get the .res file built before linking.

I do something very similar with a simple Perl script that reads an include file (.inc) containing constant declarations of the version numbers. I read them in using a regex and then create my .rc file which I pass to brcc32. It's all invoked as a pre-build action.


Since you're on Delphi-XE and have Final Builder, why don't you put it to good use and make your "final" build from it? It can give a very nice solution to the version number problem, and can do a lot more.

Here's how I'd do it.

  • Set up a small INI file that holds the relevant parts of the version information.
  • Optionally make a small Delphi forms application that reads the version number from the INI files and gives you a chance to change it. When changes are saved to the INI file, the delphi application should automatically generate a small Delphi PAS file that defines the constants!
  • Create a FinalBuilder project that does the following:
    • Calls your Delphi exe to set up version number. You'll be in charge of changing whatever needs changing, and this is probably appropriate since your licensing scheme depends on version information.
    • Set up a few project variables to hold the version information numbers
    • Add "Read INI file" actions to read the version information from the ini files into your project variables.
    • (optional) Build the unit test project, if you have one.
    • (optional) Call the unit test project.
    • Add a "build Delphi project" action, set it up to build your project using whatever options you need. Add a small "Before" script to set up the version information numbers to what you've got in the project variables you just read from the INI file.
    • (optional) create setup packages using whatever tool you use.
    • (optional) upload those setup packages to a website.

In other words, take the opportunity to start using Final Builder.


Moving your version numbers into code is also easy to get around.

One way to pass the information is to generate a version.rc file programmatically (you write a tiny build tool yourself using delphi or a scripting language of your choice), and link the resources to the program, instead of using the built in version-info feature.

Your question seems to be fundamentally a matter of preventing the user from modifying (easily) the version number once you have determined it.

So my suggestion is that you encrypt the version number and you use the encrypted version, instead of the version in the VersionInfo structure.

I have used DCPCRYPT for things like this. But if you hope to be hacker-proof let me just say this; Anything you can do, hackers can undo. If you want to be more secure, you will also need to tamper proof your whole application. There are commercial tamper proofing solutions but none work fabulously out of the box with Delphi.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号