如何在Delphi应用程序中使用项目版本信息?
我使用项目选项/版本来管理版本信息(NNNN 格式)。
无论如何,在我的项目中我复制了这些信息。
因此,如果在项目选项中我正在开发版本 2.4.3.178 在我的应用程序中,我有 4 个整数变量来保存 4 个数字。
我手动设置它们
Major := 2;
Minor := 4;
Release := 3;
Build := 178;
的原因很简单:我有基于版本号的许可。因此,如果用户购买版本“2.4”,则不允许升级到版本“3.0”。
但是,如果我依赖项目版本信息,用户可以(使用资源黑客工具)更改版本信息,从而“激活”产品。
用户无法以相同的方式更改 4 个变量(至少不那么容易)。
这有效,但迫使我复制信息。
你能建议一个更好的方法吗?
否则说:有没有办法使用我在这 4 个变量中写入的数据来写入版本信息。类似于构建后事件,但如何将数据传递给构建后事件?
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 tools) 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要预构建事件而不是构建后事件,因为您希望在链接之前构建 .res 文件。
我使用一个简单的 Perl 脚本执行非常类似的操作,该脚本读取包含版本号常量声明的包含文件 (.inc)。我使用正则表达式读取它们,然后创建我的 .rc 文件,并将其传递给 brcc32。这一切都是作为预构建操作调用的。
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.
既然您使用的是 Delphi-XE 并且拥有 Final Builder,为什么不充分利用它并从中构建您的“最终”版本呢?它可以为版本号问题提供一个非常好的解决方案,并且可以做更多的事情。
我就是这样做的。
换句话说,抓住机会开始使用 Final Builder。
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.
In other words, take the opportunity to start using Final Builder.
将版本号转移到代码中也很容易解决。
传递信息的一种方法是以编程方式生成 version.rc 文件(您使用 delphi 或您选择的脚本语言自己编写一个小型构建工具),并将资源链接到程序,而不是使用内置版本 -信息功能。
您的问题似乎从根本上来说是阻止用户在确定版本号后(轻松地)修改版本号的问题。
所以我的建议是你加密版本号并使用加密版本,而不是 VersionInfo 结构中的版本。
我已经使用 DCPCRYPT 来处理类似的事情。但如果你希望能够抵御黑客攻击,那么我就这么说吧;你能做的任何事情,黑客都可以撤销。如果您想更安全,您还需要对整个应用程序进行防篡改。有商业防篡改解决方案,但没有一个可以在德尔福中开箱即用。
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.