1

Is it possible to get installed Minecraft version using Delphi?
The interesting part is that I need to read the %appdata%\.minecraft\bin\minecraft.jar version.
But without META-INF\MANIFEST.MF reading.

Little Helper
  • 2,419
  • 9
  • 37
  • 67

3 Answers3

4

A Java program doesn't have a version unless it's specified in the Manifest file.

Maybe the developer left the version number in some readme text file or some other resource inside of the JAR file, which, as you know, is just a ZIP archive.

If none of those work, an alternative would be to build a catalog of Minefield versions, based on the file size. Use the System FileSize() function to get the file size of the JAR file and look it up in your catalog.

Depending on the circumstances, if the file size is not found in your catalog, you may be able to assume that it's newer than the latest version you have cataloged.

Even better than relying on the file size for you catalog would be to generate a hash. Even CRC32 would be sufficient.

Marcus Adams
  • 53,009
  • 9
  • 91
  • 143
  • This not exactly true, look at `java.lang.Package.getImplementationVersion` – OnTheFly Nov 02 '11 at 17:09
  • @user539484, thanks for the info. The documentation states that `java.lang.Package.getImplementationVersion` gets its information from the manifest file. – Marcus Adams Nov 02 '11 at 17:39
  • this renders me wrong then, as manifest can be missing or tampered (AFAIK, version tag in manifest is optional even). A random observation: `>java -jar IDL2Pas.jar -version` prints `[XFEIDL] 03.03.03.C1.A2 [XBEJAV]` bracketed strings are coming from `Messages.properties` file, but what about those 5 octets? – OnTheFly Nov 02 '11 at 17:52
2

Yes, it is possible. You can use this xml data provided by mojang.

For example:

<Contents>
<Key>11w47a/minecraft.jar</Key>
<LastModified>2011-11-24T13:20:06.000Z</LastModified>
<ETag>"2ad75c809570663ec561ca707983a45b"</ETag>
<Size>2242242</Size>
<Owner>...</Owner>
<StorageClass>STANDARD</StorageClass>
</Contents>

As you can see they provide version and file name in the <Key> tag. The md5 sum of the binary is stored in <ETag> tag. As long as you haven't modified your jar this should be enough to check the version.

2

I believe JAR files are actually just ZIP files, and I heard recent versions of Delphi have a unit with tools to access Zip files. I'm not familiar with the internal structure of JAR files, but if you are, and the version info you're looking for is present somewhere, you should be able to extract it this way.

Stijn Sanders
  • 35,982
  • 11
  • 45
  • 67