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.

- 2,419
- 9
- 37
- 67
-
Are you trying to figure out the version number, or what? – thedaian Nov 02 '11 at 15:33
-
Yes. I don't know Minecraft, but if the main EXE has the same path in every version, then you can simply read the version info from this EXE, [like so](http://stackoverflow.com/questions/5539316/how-can-i-read-details-of-file). If the file path varies, then you migth be able to find it using the app path registry keys. – Andreas Rejbrand Nov 02 '11 at 15:34
-
@JohnRiselvato What's the link? – GolezTrol Nov 02 '11 at 15:34
-
I want to check minecraft version (1.2 or 1.9 pre-release and etc). At least build number. – Little Helper Nov 02 '11 at 15:36
-
1how about reading that from `META-INF/MANIFEST.MF`? – Premature Optimization Nov 02 '11 at 15:41
-
3@AndreasRejbrand AFAIK, Minecraft is Java program, so there's not necessary EXE file. – Harriv Nov 02 '11 at 15:46
-
5"But without META-INF\MANIFEST.MF reading." Why? http://blogs.msdn.com/b/oldnewthing/archive/2010/07/28/10043237.aspx – CodesInChaos Nov 02 '11 at 15:54
-
I second CodeInChaos's question. – Premature Optimization Nov 02 '11 at 15:57
-
Because a lot of users delete Manifest.mf for because of mod install – Little Helper Nov 02 '11 at 15:59
-
Are you trying reading the `JAR File Specification` http://download.oracle.com/javase/6/docs/technotes/guides/jar/jar.html ? – RRUZ Nov 02 '11 at 16:18
-
I think your problem is covered by answer to [this q](http://stackoverflow.com/questions/7976131/access-to-java-jar-from-delphi) – OnTheFly Nov 02 '11 at 16:33
-
Not at all, @User. That question asks how to *execute* Java code. It has nothing to do with reading the contents of a jar file. – Rob Kennedy Nov 02 '11 at 17:18
-
Wow. Talk about "limited usefulness" of a question. Why not rephrase it in more generic terms? (Read version of Java assembly directly from its java binaries, but not from manifest) – Warren P Nov 02 '11 at 17:20
-
@Robrok: Yes, I added the `minecraft` tag and removed `game-development`, but the `delphi` and `delphi-7` tags were there before that, so don't blame me! :) – Andreas Rejbrand Nov 02 '11 at 17:26
-
@Rob, you probably know the different approach then. Elaborate please. – OnTheFly Nov 02 '11 at 17:30
-
This can be strictly Java Q if there is no other way to read version from compiled bytecode (eg: minesraft specific version tag in well known location) – OnTheFly Nov 02 '11 at 17:34
3 Answers
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.

- 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
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.

- 23
- 6
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.

- 35,982
- 11
- 45
- 67