/**
  * Go through each of the APK Expansion files defined in the structure above and determine if the
  * files are present and match the required size. Free applications should definitely consider
  * doing this, as this allows the application to be launched for the first time without having a
  * network connection present. Paid applications that use LVL should probably do at least one LVL
  * check that requires the network to be present, so this is not as necessary.
  *
  * @return true if they are present.
  */
 boolean expansionFilesDelivered() {
   for (XAPKFile xf : xAPKS) {
     String fileName = Helpers.getExpansionAPKFileName(this, xf.mIsMain, xf.mFileVersion);
     File fileForNewFile = new File(Helpers.generateSaveFileName(this, fileName));
     if (!fileForNewFile.exists()) {
       return false;
     }
   }
   return true;
 }
  boolean onlySingleExpansionFileFound() {
    for (OBBData.XAPKFile xf : OBBData.xAPKS) {
      String fileName = Helpers.getExpansionAPKFileName(this, xf.mIsMain, xf.mFileVersion);
      GameActivity.Log.debug("Checking for file : " + fileName);
      String fileForNewFile = Helpers.generateSaveFileName(this, fileName);
      String fileForDevFile = Helpers.generateSaveFileNameDevelopment(this, fileName);

      if (Helpers.doesFileExist(this, fileName, xf.mFileSize, false)
          && Helpers.doesFileExistDev(this, fileName, xf.mFileSize, false)) return false;
    }

    return true;
  }
  /**
   * Go through each of the APK Expansion files defined in the structure above and determine if the
   * files are present and match the required size. Free applications should definitely consider
   * doing this, as this allows the application to be launched for the first time without having a
   * network connection present. Paid applications that use LVL should probably do at least one LVL
   * check that requires the network to be present, so this is not as necessary.
   *
   * @return true if they are present.
   */
  boolean expansionFilesDelivered() {

    for (OBBData.XAPKFile xf : OBBData.xAPKS) {
      String fileName = Helpers.getExpansionAPKFileName(this, xf.mIsMain, xf.mFileVersion);
      GameActivity.Log.debug("Checking for file : " + fileName);
      String fileForNewFile = Helpers.generateSaveFileName(this, fileName);
      String fileForDevFile = Helpers.generateSaveFileNameDevelopment(this, fileName);
      GameActivity.Log.debug(
          "which is really being resolved to : " + fileForNewFile + "\n Or : " + fileForDevFile);
      if (!Helpers.doesFileExist(this, fileName, xf.mFileSize, false)
          && !Helpers.doesFileExistDev(this, fileName, xf.mFileSize, false)) return false;
    }
    return true;
  }
  boolean expansionFilesUptoData() {

    File cacheFile = getFileDetailsCacheFile();
    // Read data into an array or something...
    Map<String, Long> fileDetailsMap = new HashMap<String, Long>();

    if (cacheFile.exists()) {
      try {
        FileReader fileCache = new FileReader(cacheFile);
        BufferedReader bufferedFileCache = new BufferedReader(fileCache);
        List<String> lines = new ArrayList<String>();
        String line = null;
        while ((line = bufferedFileCache.readLine()) != null) {
          lines.add(line);
        }
        bufferedFileCache.close();

        for (String dataLine : lines) {
          GameActivity.Log.debug("Splitting dataLine => " + dataLine);
          String[] parts = dataLine.split(",");
          fileDetailsMap.put(parts[0], Long.parseLong(parts[1]));
        }
      } catch (Exception e) {
        GameActivity.Log.debug("Exception thrown during file details reading.");
        e.printStackTrace();
        fileDetailsMap.clear();
      }
    }

    for (OBBData.XAPKFile xf : OBBData.xAPKS) {
      String fileName = Helpers.getExpansionAPKFileName(this, xf.mIsMain, xf.mFileVersion);
      String fileForNewFile = Helpers.generateSaveFileName(this, fileName);
      String fileForDevFile = Helpers.generateSaveFileNameDevelopment(this, fileName);
      // check to see if time/data on files match cached version
      // if not return false
      File srcFile = new File(fileForNewFile);
      File srcDevFile = new File(fileForDevFile);
      long lastModified = srcFile.lastModified();
      long lastModifiedDev = srcDevFile.lastModified();
      if (!(srcFile.exists()
              && fileDetailsMap.containsKey(fileName)
              && lastModified == fileDetailsMap.get(fileName))
          && !(srcDevFile.exists()
              && fileDetailsMap.containsKey(fileName)
              && lastModifiedDev == fileDetailsMap.get(fileName))) return false;
    }
    return true;
  }
Esempio n. 5
0
 public static boolean expansionExists(boolean main) {
   String fileName = null;
   int version = 0;
   for (XAPKFile xf : xAPKS) {
     if (xf.mIsMain) {
       fileName =
           Helpers.getExpansionAPKFileName(
               NativeUtility.getMainActivity(), xf.mIsMain, xf.mFileVersion);
       if (!Helpers.doesFileExist(
           NativeUtility.getMainActivity(), fileName, xf.mFileSize, false)) {
         fileName = "NOTDOWNLOADED";
       } else {
         version = xf.mFileVersion;
       }
     }
   }
   return fileName != null && version != 0 && !fileName.equals(new String("NOTDOWNLAODED"));
 }
Esempio n. 6
0
 /* return the relative path of  the expansion if everything works well
  * return null if there is no information about that expansion
  */
 public static String getExpansionFileName(boolean main) {
   String fileName = null;
   int version = 0;
   for (XAPKFile xf : xAPKS) {
     if (xf.mIsMain) {
       fileName =
           Helpers.getExpansionAPKFileName(
               NativeUtility.getMainActivity(), xf.mIsMain, xf.mFileVersion);
       version = xf.mFileVersion;
     }
   }
   if (fileName == null || version == 0) { // early return because there was an error
     return fileName;
   }
   String packageName = NativeUtility.getMainActivity().getPackageName();
   // That's the file name, according to the documentation. Pretty complicated if you ask me.
   return (main ? "main." : "patch.") + version + "." + packageName + ".obb";
 }
  private static void RemoveOBBFile(int OBBToDelete) {

    for (OBBData.XAPKFile xf : OBBData.xAPKS) {
      String fileName =
          Helpers.getExpansionAPKFileName(
              DownloaderActivity._download, xf.mIsMain, xf.mFileVersion);
      switch (OBBToDelete) {
        case 0:
          String fileForNewFile =
              Helpers.generateSaveFileName(DownloaderActivity._download, fileName);
          File srcFile = new File(fileForNewFile);
          srcFile.delete();
          break;
        case 1:
          String fileForDevFile =
              Helpers.generateSaveFileNameDevelopment(DownloaderActivity._download, fileName);
          File srcDevFile = new File(fileForDevFile);
          srcDevFile.delete();
          break;
      }
    }
  }
Esempio n. 8
0
  /**
   * Allow to know if the expansion files was downloaded Always return true in debug mode It's the
   * caller responsibility to setup the download UI if it returns false
   *
   * @return true if the expansion was delivered, false if it's starting to download
   */
  public static boolean checkExpansionFiles() {
    boolean isDebuggable =
        (0
            != (NativeUtility.getMainActivity().getApplicationInfo().flags
                & ApplicationInfo.FLAG_DEBUGGABLE));
    if (isDebuggable) {
      // return true;
    }
    if (xAPKS == null) {
      return true;
    }
    for (XAPKFile xf : xAPKS) {
      String fileName =
          Helpers.getExpansionAPKFileName(
              NativeUtility.getMainActivity(), xf.mIsMain, xf.mFileVersion);
      if (!Helpers.doesFileExist(NativeUtility.getMainActivity(), fileName, xf.mFileSize, false)) {
        // Build an Intent to start this activity from the Notification
        Intent notifierIntent =
            new Intent(NativeUtility.getMainActivity(), NativeUtility.getMainActivity().getClass());
        notifierIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);

        PendingIntent pendingIntent =
            PendingIntent.getActivity(
                NativeUtility.getMainActivity(),
                0,
                notifierIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);

        // Start the download service (if required)
        int startResult = -1;
        try {
          startResult =
              DownloaderClientMarshaller.startDownloadServiceIfRequired(
                  NativeUtility.getMainActivity(), pendingIntent, ExpansionSupport.class);
        } catch (NameNotFoundException e) {
          e.printStackTrace();
        }
        // If download has started, initialize this activity to show download progress
        if (startResult != DownloaderClientMarshaller.NO_DOWNLOAD_REQUIRED) {
          // The caller will setup the download UI
          Log.i(TAG, "creating stub for download ...");
          NativeUtility.getMainActivity()
              .runOnUiThread(
                  new Runnable() {
                    public void
                        run() { // For some reasons, that needs to be runned on UI Thread because it
                      // requires a Looper ....
                      try {
                        mDownloaderClientStub =
                            DownloaderClientMarshaller.CreateStub(
                                ExpansionSupport.getInstance(), ExpansionSupport.class);
                        if (NativeUtility.getMainActivity().isActive()) {
                          mDownloaderClientStub.connect(NativeUtility.getMainActivity());
                        }
                      } catch (Exception e) {
                        e.printStackTrace();
                      }
                    }
                  });
          Log.i(TAG, "Stub created! Returning false");

          return false;
        }
      }
    }
    Log.i(TAG, "Expansion file exists");
    return true;
  }