/**
 *  Copyright 2011 Ryszard Wiśniewski <brut.alll@gmail.com>
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package brut.androlib;

import org.jf.baksmali.baksmali;
import org.jf.smali.main;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.util.logging.Logger;

/**
 * @author Ryszard Wiśniewski <brut.alll@gmail.com>
 */
public class ApktoolProperties {
	public static String get(String key) {
		return get().getProperty(key);
	}

	public static Properties get() {
		if (sProps == null) {
			loadProps();
		}
		return sProps;
	}

	private static void loadProps() {
		InputStream in = ApktoolProperties.class.getResourceAsStream("/properties/apktool.properties");
		sProps = new Properties();
		try {
			sProps.load(in);
			in.close();
		} catch (IOException ex) {
			LOGGER.warning("Can't load properties.");
		}

		InputStream templateStream = baksmali.class.getClassLoader().getResourceAsStream("baksmali.properties");
		Properties properties = new Properties();
		String version = "(unknown)";

        if (templateStream != null) {
            try {
                properties.load(templateStream);
                version = properties.getProperty("application.version");
            } catch (IOException ignored) {
            }
        }
		sProps.put("baksmaliVersion", version);


		templateStream = main.class.getClassLoader().getResourceAsStream("smali.properties");
		properties = new Properties();
		version = "(unknown)";

        if (templateStream != null) {
            try {
                properties.load(templateStream);
                version = properties.getProperty("application.version");
            } catch (IOException ignored) {
            }
        }
		sProps.put("smaliVersion", version);
	}

	private static Properties sProps;

	private static final Logger LOGGER = Logger
			.getLogger(ApktoolProperties.class.getName());
}
@@ -926,17 +926,20 @@
 rties %7B%0A
-%09
+    
 public s
@@ -969,18 +969,24 @@
  key) %7B%0A
-%09%09
+        
 return g
@@ -1008,21 +1008,27 @@
 y(key);%0A
-%09%7D%0A%0A%09
+    %7D%0A%0A    
 public s
@@ -1052,18 +1052,24 @@
 get() %7B%0A
-%09%09
+        
 if (sPro
@@ -1082,19 +1082,28 @@
 null) %7B%0A
-%09%09%09
+            
 loadProp
@@ -1111,14 +1111,26 @@
 ();%0A
-%09%09%7D%0A%09%09
+        %7D%0A        
 retu
@@ -1140,21 +1140,27 @@
 sProps;%0A
-%09%7D%0A%0A%09
+    %7D%0A%0A    
 private 
@@ -1185,18 +1185,24 @@
 ops() %7B%0A
-%09%09
+        
 InputStr
@@ -1289,18 +1289,24 @@
 ties%22);%0A
-%09%09
+        
 sProps =
@@ -1328,19 +1328,34 @@
 ();%0A
-%09%09try %7B%0A%09%09%09
+        try %7B%0A            
 sPro
@@ -1367,19 +1367,28 @@
 ad(in);%0A
-%09%09%09
+            
 in.close
@@ -1391,18 +1391,24 @@
 lose();%0A
-%09%09
+        
 %7D catch 
@@ -1426,19 +1426,28 @@
 n ex) %7B%0A
-%09%09%09
+            
 LOGGER.w
@@ -1484,15 +1484,27 @@
 %22);%0A
-%09%09%7D%0A%0A%09%09
+        %7D%0A%0A        
 Inpu
@@ -1604,18 +1604,24 @@
 ties%22);%0A
-%09%09
+        
 Properti
@@ -1654,18 +1654,24 @@
 ties();%0A
-%09%09
+        
 String v
@@ -1931,34 +1931,40 @@
     %7D%0A        %7D%0A
-%09%09
+        
 sProps.put(%22baks
@@ -1989,18 +1989,24 @@
 ion);%0A%0A%0A
-%09%09
+        
 template
@@ -2083,18 +2083,24 @@
 ties%22);%0A
-%09%09
+        
 properti
@@ -2122,18 +2122,24 @@
 ties();%0A
-%09%09
+        
 version 
@@ -2400,18 +2400,24 @@
       %7D%0A
-%09%09
+        
 sProps.p
@@ -2449,13 +2449,19 @@
 n);%0A
-%09%7D%0A%0A%09
+    %7D%0A%0A    
 priv
@@ -2491,17 +2491,20 @@
 Props;%0A%0A
-%09
+    
 private 
@@ -2543,11 +2543,20 @@
 ger%0A
-%09%09%09
+            
 .get

fix spacing