package com.worklight.common;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.res.AssetManager;
import com.worklight.nativeandroid.common.WLUtils;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;

public class WLConfig
{
  private static final String ANDROID_ASSET = "/android_asset";
  private static final String APP_INSTALL_TIME_KEY = "appInstallTime";
  private static final String CLEAR_CACHE_NEXT_LOAD = "com.worklight.clearCacheNextLoad";
  public static final String ENABLE_SETTINGS = "enableSettings";
  private static final String EXIT_ON_SKIN_LOADER = "exitOnSkinLoader";
  private static final String IGNORED_FILE_EXTENSIONS = "ignoredFileExtensions";
  private static final String IN_PROGRESS_CHECKSUM = "inProgressChecksum";
  private static final String LANGUAGE_PREFS = "languagePreferences";
  private static final String NATIVE_EMPTY_APP_HTML = "NativeEmptyApp.html";
  public static final String WL_APP_ID = "wlAppId";
  public static final String WL_APP_VERSION = "wlAppVersion";
  public static final String WL_CLIENT_PROPS_NAME = "wlclient.properties";
  private static final String WL_DEFAULT_SERVER_URL = "WLDefaultServerURL";
  private static final String WL_ENVIRONMENT = "wlEnvironment";
  public static final String WL_GCM_SENDER = "GcmSenderId";
  private static final String WL_IS_EXTERNAL_WEBRESOURCES = "WLIsExternalWebResources";
  public static final String WL_MAIN_FILE_PATH = "wlMainFilePath";
  public static final String WL_PLATFORM_VERSION = "wlPlatformVersion";
  private static final String WL_PREFS = "WLPrefs";
  private static final String WL_RESOURCES_CHECKSUM_PREF_KEY = "wlResourcesChecksum";
  public static final String WL_SERVER_CONTEXT = "wlServerContext";
  public static final String WL_SERVER_HOST = "wlServerHost";
  public static final String WL_SERVER_PORT = "wlServerPort";
  public static final String WL_SERVER_PROTOCOL = "wlServerProtocol";
  public static final String WL_SHARE_COOKIES = "wlShareCookies";
  public static final String WL_SHARE_USER_CERT = "wlShareUserCert";
  private static final String WL_SKIN_NAME_PREF_KEY = "wlSkinName";
  private static final String WL_TEST_WEB_RESOURCES_CHECKSUM = "testWebResourcesChecksum";
  public static final String WL_WEB_RESOURCES_UNPACKD_SIZE = "webResourcesSize";
  public static final String WL_X_PLATFORM_VERSION = "x-wl-platform-version";
  public static final String WL_X_VERSION_HEADER = "x-wl-app-version";
  private static WLConfig singleton = null;
  private String absolutePathToExternalAppFiles;
  private boolean isApplicationForeground = false;
  private boolean isInitComplete = false;
  private SharedPreferences prefs = null;
  private Properties wlProperties = new Properties();

  private WLConfig(Context paramContext)
  {
    try
    {
      this.wlProperties.load(paramContext.getAssets().open("wlclient.properties"));
      this.prefs = paramContext.getSharedPreferences("WLPrefs", 0);
      this.absolutePathToExternalAppFiles = paramContext.getFilesDir().getAbsolutePath();
      return;
    }
    catch (IOException localIOException)
    {
    }
    throw new RuntimeException("WLConfig(): Can't load wlclient.properties file");
  }

  public static void createInstance(Context paramContext)
  {
    try
    {
      if (singleton == null)
        singleton = new WLConfig(paramContext.getApplicationContext());
      return;
    }
    finally
    {
      localObject = finally;
      throw localObject;
    }
  }

  private String getDefaultRootUrl()
  {
    int i;
    String str1;
    if (("https".equalsIgnoreCase(getProtocol())) && ("443".equals(getPort())))
    {
      i = 1;
      if ((!WLUtils.isStringEmpty(getPort())) && (i == 0))
        break label142;
      str1 = "";
      label43: if ((!WLUtils.isStringEmpty(getServerContext())) && (!getServerContext().equals("/")))
        break label168;
    }
    label142: label168: for (String str2 = ""; ; str2 = getServerContext())
    {
      Object[] arrayOfObject = new Object[4];
      arrayOfObject[0] = getProtocol();
      arrayOfObject[1] = getHost();
      arrayOfObject[2] = str1;
      arrayOfObject[3] = str2;
      String str3 = String.format("%s://%s%s%s", arrayOfObject);
      if (str3.endsWith("/"))
        str3 = str3.substring(0, -1 + str3.length());
      return str3;
      i = 0;
      break;
      str1 = ":" + getPort();
      break label43;
    }
  }

  public static WLConfig getInstance()
  {
    if (singleton == null)
      throw new IllegalStateException("getInstance can't be called before createInstance");
    return singleton;
  }

  private String getPropertyOrPref(String paramString1, String paramString2)
  {
    String str = this.prefs.getString(paramString2, null);
    if (str == null)
      str = (String)this.wlProperties.get(paramString1);
    return str;
  }

  public void clearWLPref()
  {
    SharedPreferences.Editor localEditor = this.prefs.edit();
    localEditor.clear();
    localEditor.commit();
  }

  public String getAppId()
  {
    return getPropertyOrPref("wlAppId", "appIdPref");
  }

  public URL getAppURL()
  {
    try
    {
      URL localURL = new URL(getRootURL() + "/apps/services/api/" + getAppId() + "/" + getWLEnvironment() + "/");
      return localURL;
    }
    catch (MalformedURLException localMalformedURLException)
    {
      throw new RuntimeException("Could not parse URL; check assets/wlclient.properties. " + localMalformedURLException.getMessage(), localMalformedURLException);
    }
  }

  public String getAppWebUrl(String paramString)
  {
    String str = getMainFileFromDescriptor();
    if (new File(getWebResourcesUrl() + "/" + paramString + "/" + "NativeEmptyApp.html").exists())
      str = "NativeEmptyApp.html";
    return getWebUrl() + "/" + paramString + "/" + str;
  }

  public String getApplicationAbsolutePathToExternalAppFiles()
  {
    return this.absolutePathToExternalAppFiles;
  }

  public String getApplicationAbsolutePathToExternalWWWFiles()
  {
    return this.absolutePathToExternalAppFiles + "/www";
  }

  public long getApplicationInstallTime()
  {
    return readLongWLPref("appInstallTime");
  }

  public String getApplicationVersion()
  {
    return getPropertyOrPref("wlAppVersion", "appVersionPref");
  }

  public String getGCMSender()
  {
    String str = this.wlProperties.getProperty("GcmSenderId");
    if (str != null)
      str = str.trim();
    return str;
  }

  public String getHost()
  {
    return this.wlProperties.getProperty("wlServerHost");
  }

  public long getInProgressChecksumPref()
  {
    return readLongWLPref("inProgressChecksum");
  }

  public String getLanguagePreferences()
  {
    return this.wlProperties.getProperty("languagePreferences");
  }

  public String getLocalStorageRoot()
  {
    if (isExternalWebResources())
      return getApplicationAbsolutePathToExternalAppFiles();
    return "/android_asset";
  }

  public String getMainFileFromDescriptor()
  {
    return this.wlProperties.getProperty("wlMainFilePath");
  }

  public String getMainFilePath()
  {
    return getAppId() + ".html";
  }

  public String[] getMediaExtensions()
  {
    String str = this.wlProperties.getProperty("ignoredFileExtensions");
    if (str != null)
      return str.replaceAll(" ", "").split(",");
    return null;
  }

  public String getPlatformVersion()
  {
    return this.wlProperties.getProperty("wlPlatformVersion");
  }

  public String getPort()
  {
    return this.wlProperties.getProperty("wlServerPort");
  }

  public String getProtocol()
  {
    return this.wlProperties.getProperty("wlServerProtocol");
  }

  public String getResourceChecksumPref()
  {
    return readWLPref("wlResourcesChecksum");
  }

  public String getRootURL()
  {
    String str = this.prefs.getString("WLServerURL", null);
    if (str == null)
      str = getDefaultRootUrl();
    return str;
  }

  public String getServerContext()
  {
    return this.wlProperties.getProperty("wlServerContext");
  }

  public String getSettingsFlag()
  {
    return this.wlProperties.getProperty("enableSettings");
  }

  public List<String> getShareCookies()
  {
    String str = this.wlProperties.getProperty("wlShareCookies");
    if (str == null)
      str = "";
    return Arrays.asList(str.split(","));
  }

  public String getSkinNamePref()
  {
    return readWLPref("wlSkinName");
  }

  public String getTestWebResourcesChecksumFlag()
  {
    return this.wlProperties.getProperty("testWebResourcesChecksum");
  }

  public String getWLEnvironment()
  {
    String str = this.wlProperties.getProperty("wlEnvironment", null);
    if (str == null)
      str = "android";
    return str;
  }

  public String getWebResourcesUnpackedSize()
  {
    return this.wlProperties.getProperty("webResourcesSize");
  }

  public String getWebResourcesUrl()
  {
    return getLocalStorageRoot() + "/www";
  }

  public String getWebUrl()
  {
    return "file://" + getWebResourcesUrl();
  }

  public boolean isClearCacheNextLoad()
  {
    return this.prefs.getBoolean("com.worklight.clearCacheNextLoad", false);
  }

  public boolean isExternalWebResources()
  {
    return Boolean.valueOf(readWLPref("WLIsExternalWebResources")).booleanValue();
  }

  public boolean isHybridActivityInForeground()
  {
    return this.isApplicationForeground;
  }

  public boolean isInitComplete()
  {
    return this.isInitComplete;
  }

  public boolean isShareUserCert()
  {
    return Boolean.valueOf(this.wlProperties.getProperty("wlShareUserCert")).booleanValue();
  }

  public boolean isShouldTestWebResourcesChecksum()
  {
    return getTestWebResourcesChecksumFlag().equals("true");
  }

  public long readLongWLPref(String paramString)
  {
    return this.prefs.getLong(paramString, 0L);
  }

  public String readWLPref(String paramString)
  {
    return this.prefs.getString(paramString, null);
  }

  public void setApplicationInstallTime(long paramLong)
  {
    writeLongWLPref("appInstallTime", paramLong);
  }

  public void setClearCacheNextLoadPref(boolean paramBoolean)
  {
    SharedPreferences.Editor localEditor = this.prefs.edit();
    localEditor.putBoolean("com.worklight.clearCacheNextLoad", paramBoolean);
    localEditor.commit();
  }

  public void setDefaultRootUrlPref()
  {
    writeWLPref("WLDefaultServerURL", getDefaultRootUrl());
  }

  public void setExitOnSkinLoaderPref(boolean paramBoolean)
  {
    writeWLPref("exitOnSkinLoader", Boolean.toString(paramBoolean));
  }

  public void setExternalWebResourcesPref(boolean paramBoolean)
  {
    writeWLPref("WLIsExternalWebResources", Boolean.toString(paramBoolean));
  }

  public void setHybridActivityInForeground(boolean paramBoolean)
  {
    this.isApplicationForeground = paramBoolean;
  }

  public void setInProgressChecksumPref(long paramLong)
  {
    writeLongWLPref("inProgressChecksum", paramLong);
  }

  public void setInitComplete(boolean paramBoolean)
  {
    this.isInitComplete = paramBoolean;
  }

  public void setResourceChecksumPref(String paramString)
  {
    writeWLPref("wlResourcesChecksum", paramString);
  }

  public void writeLongWLPref(String paramString, long paramLong)
  {
    SharedPreferences.Editor localEditor = this.prefs.edit();
    localEditor.putLong(paramString, paramLong);
    localEditor.commit();
  }

  public void writeWLPref(String paramString1, String paramString2)
  {
    SharedPreferences.Editor localEditor = this.prefs.edit();
    localEditor.putString(paramString1, paramString2);
    localEditor.commit();
  }
}

/* Location:           C:\Documents and Settings\Cesar Cabello Cea\Mis documentos\Downloads\apk-downloader\com.ikea.kompis-6_dex2jar.jar
 * Qualified Name:     com.worklight.common.WLConfig
 * JD-Core Version:    0.6.2
 */