Is it possible to insert the build time into an application?

泄露秘密 提交于 2019-12-04 01:54:40

问题


A game has this:

I'm curious to whether this was the actual build time, and sure enough, the 'File Last Modified' date of Crysis.exe (the program) is 03/31/2009, 01:40.

Sure, the developer could easily have manually inputted that value, and built the application in under a minute, but I'm curious to whether it is actually possible to input the current date/time (to the nearest second) when the application is actually building.

This would have many advantages, including easy identification of different builds of the application.

Is this possible?


回答1:


Yes the time of built is provided by the __TIME__ macro. In your example they also use __DATE__ macro which provides the date.

LIVE DEMO




回答2:


Yes. Several approaches come to mind:

  1. Use C's __DATE__ and __TIME__ macros. They're part of the standard, however, they take the time the particular file was last built. So that means if you e.g. put the build date in your app's about screen, then the date will only be updated when you either do a complete clean build, or you change the about screen source file. To fix this, you could add a script to your build process that e.g. calls

    touch AboutScreen.cpp
    

    To forcibly trigger a rebuild.

  2. Write a shell script that you run before each build that generates a header file like

    #define BUILD_DATE  "2014-07-03 20:15"
    

    and run that script before each build. Since the file is generated new each time, your build process should notice it has changed and automatically trigger a new build of the about screen or whatever shows your build date/time.



来源:https://stackoverflow.com/questions/24561214/is-it-possible-to-insert-the-build-time-into-an-application

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!