.manifest support in dzPrepBuild

 Delphi  Comments Off on .manifest support in dzPrepBuild
Feb 232013
 

It has taken a while but I have eventually arrived in the “modern” Windows world. After many years of sticking with Windows XP (and Linux) I have updated two computers to Windows 8 (both 64 bit) and another two to Windows 7 (64 bit and 32 bit).

In doing so I have been made aware of some annoyances of Windows >= Vista, one of them being the virtual store. This is a convenience feature Microsoft added to Vista and later Windows versions to allow users to continue using old programs without escalating their security issues. This feature virtualizes write access to directories in the file system and branches of the registry that are read only on properly configured systems (like “c:\windows”, “c:\program files\…” or  HKey_LOCAL_MACHINE).

While Microsoft’s intention was good and normal users won’t have a problem with it, for a software developer this feature is rather inconvenient because it prevents him from realizing if his programs do something undesired. Rather than failing and in Delphi’s case raising an exception, these actions succeed and the programmer won’t notice. Even worse, he will not find the files or registry entries his programs were supposed to make in the place he expects them and possibly waste hours in trying to find out what’s wrong.

The idea was that newer software disables this feature with a .manifest resource. Unfortunately this will only work if the programmer updates his development tools to create these files and bind the resources to the program. Delphi 2007 did not know about .manifest resources so it needs some help. There are already many sites with information about this topic so I won’t repeat them. Suffice to say, that a .manifest resource is a special kind of resource that is added to an executable from a text file in xml format.

That format requires version information and also some descriptions, which are already part of an executable’s version resource so I added support for it to dzPrepBuild. As always, that program “eats its own dog food” (uses itself for building), so you can have a look at the source code on how it is done:

  • add {$ *_manifest.res} to the .dpr file, like the ($ *_version.res} and {$ *_icon.res} entries that were already in place.
  • add a pre-build event to the project which calls the prebuild.cmd file in buildtools if it isn’t already there
  • copy the template.manifest.in file from buildtools\templates to your source directory and rename it to <yourprogram>.manifest.in
  •  modify it to suit your needs
  • The pre-build event will, in addition to creating a *_version.rc file and compiling it, also create a *.manifest file from the contents of the *.manifest.in file + the version information, create a *_manifest.rc file and compile it. This compiled file will then be added by the Delphi compiler to the executable.

Voila: Your program has a valid .manifest resource and Windows will automatically disable virtual store for it. Now you can start finding all the bugs you never noticed. 😉

Since this is a tool created by one Delphi developer for other Delphi developers and you will probably want to have a look at how it is done anyway, I have not created a release. Just point your favourite svn client to http://svn.code.sf.net/p/dzprepbuild/code/trunk/ and make sure you also include the externals. The project requires Delphi XE2 to compile but it should be easy to revert back to Delphi 2007 if you desire so.

 Posted by on 2013-02-23 at 13:37

3.5 gigabyte text file – meet LargeTextViewer

 Delphi  Comments Off on 3.5 gigabyte text file – meet LargeTextViewer
Feb 162013
 

Recently a customer sent me an XML file which was 3.5 gigabyte in size. I had to parse this file and met some new challenges.

The first one was that I did not have any tool to display a file that large. All text editors balked at it and the few viewers (for Windows) that claimed they could handle large files I found on the Internet were slow like dogs or very difficult to use (does nobody teach those kids user interface design nowadays?). I made do with the Linux less command for a while but always putting the file(s) on the server, ssh’ing into it just to display it was an annoyance in itself.

So I ended up rolling my own. It’s of course written in Delphi and needed only a few lines of code. It relies heavily on my TdzVirtualStringGrid component to only keep that part of the file in memory that is currently being displayed. It immediately displays the first few lines of the file and in the background it reads through the file to find CR/LF characters and creates a list of Int64 values with the stream offsets of every single line in the file. While indexing you can only scroll down up to the point that has been indexed but that’s the only restriction.  For the above mentioned 3.5 gigabyte file indexing takes around 30 seconds on my computer.

Apart from displaying the file, it does nothing. There is no search function and it even does not display line numbers. But I thought it might be useful to somebody else, so I put it into my dzlib svn repository on sourceforge. You can find it in the subdirectory tools. so after I received some patches from Daniela Osterhagen for it I put up a sourceforge project for it. There is also a downloadable executable now.

 Posted by on 2013-02-16 at 12:35