Advertisement
Corosus

Untitled

Dec 29th, 2012
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.14 KB | None | 0 0
  1. package net.minecraft;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.DataOutputStream;
  5. import java.io.File;
  6. import java.io.InputStream;
  7. import java.io.InputStreamReader;
  8. import java.net.HttpURLConnection;
  9. import java.net.URL;
  10. //import net.minecraft.Util_OS;
  11.  
  12. public class Util {
  13.  
  14.    private static File workDir = null;
  15.    // $FF: synthetic field
  16.    private static int[] $SWITCH_TABLE$net$minecraft$Util$OS;
  17.  
  18.  
  19.    public Util() {
  20.       super();
  21.    }
  22.  
  23.    public static File getWorkingDirectory() {
  24.       if(workDir == null) {
  25.          workDir = getWorkingDirectory("minecraft");
  26.       }
  27.  
  28.       return workDir;
  29.    }
  30.  
  31.    public static File getWorkingDirectory(String applicationName) {
  32.       String userHome = System.getProperty("user.home", ".");
  33.       File workingDirectory;
  34.       switch($SWITCH_TABLE$net$minecraft$Util$OS()[getPlatform().ordinal()]) {
  35.       case 1:
  36.       case 2:
  37.          workingDirectory = new File(userHome, '.' + applicationName + '/');
  38.          break;
  39.       case 3:
  40.          String applicationData = System.getenv("APPDATA");
  41.          if(applicationData != null) {
  42.             workingDirectory = new File(applicationData, "." + applicationName + '/');
  43.          } else {
  44.             workingDirectory = new File(userHome, '.' + applicationName + '/');
  45.          }
  46.          break;
  47.       case 4:
  48.          workingDirectory = new File(userHome, "Library/Application Support/" + applicationName);
  49.          break;
  50.       default:
  51.          workingDirectory = new File(userHome, applicationName + '/');
  52.       }
  53.  
  54.       if(!workingDirectory.exists() && !workingDirectory.mkdirs()) {
  55.          throw new RuntimeException("The working directory could not be created: " + workingDirectory);
  56.       } else {
  57.          return workingDirectory;
  58.       }
  59.    }
  60.  
  61.    private static Util_OS getPlatform() {
  62.       String osName = System.getProperty("os.name").toLowerCase();
  63.       return osName.contains("win")?Util_OS.windows:(osName.contains("mac")?Util_OS.macos:(osName.contains("solaris")?Util_OS.solaris:(osName.contains("sunos")?Util_OS.solaris:(osName.contains("linux")?Util_OS.linux:(osName.contains("unix")?Util_OS.linux:Util_OS.unknown)))));
  64.    }
  65.  
  66.    public static String excutePost(String targetURL, String urlParameters) {
  67.       HttpURLConnection connection = null;
  68.       boolean var13 = false;
  69.  
  70.       String var10;
  71.       label84: {
  72.          try {
  73.             var13 = true;
  74.             URL url = new URL(targetURL);
  75.             connection = (HttpURLConnection)url.openConnection();
  76.             connection.setRequestMethod("POST");
  77.             connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
  78.             connection.setRequestProperty("Content-Length", Integer.toString(urlParameters.getBytes().length));
  79.             connection.setRequestProperty("Content-Language", "en-US");
  80.             connection.setUseCaches(false);
  81.             connection.setDoInput(true);
  82.             connection.setDoOutput(true);
  83.             DataOutputStream e = new DataOutputStream(connection.getOutputStream());
  84.             e.writeBytes(urlParameters);
  85.             e.flush();
  86.             e.close();
  87.             InputStream is = connection.getInputStream();
  88.             BufferedReader rd = new BufferedReader(new InputStreamReader(is));
  89.             StringBuffer response = new StringBuffer();
  90.  
  91.             String line;
  92.             while((line = rd.readLine()) != null) {
  93.                response.append(line);
  94.                response.append('\r');
  95.             }
  96.  
  97.             rd.close();
  98.             var10 = response.toString();
  99.             var13 = false;
  100.             break label84;
  101.          } catch (Exception var14) {
  102.             var14.printStackTrace();
  103.             var13 = false;
  104.          } finally {
  105.             if(var13) {
  106.                if(connection != null) {
  107.                   connection.disconnect();
  108.                }
  109.  
  110.             }
  111.          }
  112.  
  113.          if(connection != null) {
  114.             connection.disconnect();
  115.          }
  116.  
  117.          return null;
  118.       }
  119.  
  120.       if(connection != null) {
  121.          connection.disconnect();
  122.       }
  123.  
  124.       return var10;
  125.    }
  126.  
  127.    // $FF: synthetic method
  128.    static int[] $SWITCH_TABLE$net$minecraft$Util$OS() {
  129.       if($SWITCH_TABLE$net$minecraft$Util$OS != null) {
  130.          return $SWITCH_TABLE$net$minecraft$Util$OS;
  131.       } else {
  132.          int[] var0 = new int[Util_OS.values().length];
  133.  
  134.          try {
  135.             var0[Util_OS.linux.ordinal()] = 1;
  136.          } catch (NoSuchFieldError var5) {
  137.             ;
  138.          }
  139.  
  140.          try {
  141.             var0[Util_OS.macos.ordinal()] = 4;
  142.          } catch (NoSuchFieldError var4) {
  143.             ;
  144.          }
  145.  
  146.          try {
  147.             var0[Util_OS.solaris.ordinal()] = 2;
  148.          } catch (NoSuchFieldError var3) {
  149.             ;
  150.          }
  151.  
  152.          try {
  153.             var0[Util_OS.unknown.ordinal()] = 5;
  154.          } catch (NoSuchFieldError var2) {
  155.             ;
  156.          }
  157.  
  158.          try {
  159.             var0[Util_OS.windows.ordinal()] = 3;
  160.          } catch (NoSuchFieldError var1) {
  161.             ;
  162.          }
  163.  
  164.          $SWITCH_TABLE$net$minecraft$Util$OS = var0;
  165.          return var0;
  166.       }
  167.    }
  168. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement