Commits

Anonymous committed a5d6ede

write extra version info to properties file

  • Participants
  • Parent commits 370ac3d

Comments (0)

Files changed (2)

File src/com/prupe/mcpatcher/MCPatcher.java

             }
 
             applyMods();
+            writeProperties();
             minecraft.checkOutput();
             minecraft.closeStreams();
 
         }
         return patched;
     }
+
+    private static void writeProperties() throws IOException {
+        Properties properties = new Properties();
+        properties.setProperty("minecraftVersion", minecraft.getVersion().getVersionString());
+        properties.setProperty("patcherVersion", MCPatcher.VERSION_STRING);
+        minecraft.writeProperties(properties);
+    }
 }

File src/com/prupe/mcpatcher/MinecraftJar.java

         return outputFile;
     }
 
+    void writeProperties(Properties properties) throws IOException {
+        try {
+            outputJar.putNextEntry(new ZipEntry("mcpatcher.properties"));
+            properties.store(outputJar, null);
+        } catch (IOException e) {
+            if (!e.toString().contains("duplicate entry")) {
+                throw e;
+            }
+        }
+    }
+
     void checkOutput() throws Exception {
         closeStreams();
         JarFile jar = null;
             }
 
             boolean haveMetaInf = false;
+            boolean havePatcherProperties = false;
             JarFile jar = null;
             try {
                 HashSet<String> entries = new HashSet<String>();
                     }
                     if (name.startsWith("META-INF")) {
                         haveMetaInf = true;
+                    } else if (name.equals("mcpatcher.properties")) {
+                        havePatcherProperties = true;
                     }
                     entries.add(name);
                 }
                 return CORRUPT_JAR;
             }
             origMD5 = getOrigMD5(minecraftJar.getParentFile(), version);
-            if (!haveMetaInf) {
+            if (!haveMetaInf || havePatcherProperties) {
                 return MODDED_JAR;
             }
             if (origMD5 == null) {
         }
 
         private static MinecraftVersion extractVersion(JarFile jar, String md5) {
-            MinecraftVersion version = null;
+            MinecraftVersion version = extractVersion(jar);
+            if (version != null) {
+                return version;
+            }
             InputStream inputStream = null;
             try {
                 ZipEntry entry = jar.getEntry("net/minecraft/client/Minecraft.class");
             return version;
         }
 
+        private static MinecraftVersion extractVersion(JarFile jar) {
+            MinecraftVersion version = null;
+            InputStream inputStream = null;
+            try {
+                ZipEntry entry = jar.getEntry("mcpatcher.properties");
+                if (entry != null) {
+                    inputStream = jar.getInputStream(entry);
+                    Properties properties = new Properties();
+                    properties.load(inputStream);
+                    String value = properties.getProperty("minecraftVersion", "");
+                    if (!value.equals("")) {
+                        return MinecraftVersion.parseShortVersion(value);
+                    }
+                }
+            } catch (IOException e) {
+                Logger.log(e);
+            } finally {
+                MCPatcherUtils.close(inputStream);
+            }
+            return version;
+        }
+
         private static String getOrigMD5(File binDir, MinecraftVersion version) {
             String md5 = MinecraftVersion.knownMD5s.get(version.getVersionString());
             if (md5 != null) {