/**
  * 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;
  }
  /**
   * Sets the state of the various controls based on the progressinfo object sent from the
   * downloader service.
   */
  @Override
  public void onDownloadProgress(DownloadProgressInfo progress) {
    mAverageSpeed.setText(
        getString(R.string.kilobytes_per_second, Helpers.getSpeedString(progress.mCurrentSpeed)));
    mTimeRemaining.setText(
        getString(R.string.time_remaining, Helpers.getTimeRemaining(progress.mTimeRemaining)));

    progress.mOverallTotal = progress.mOverallTotal;
    mPB.setMax((int) (progress.mOverallTotal >> 8));
    mPB.setProgress((int) (progress.mOverallProgress >> 8));
    mProgressPercent.setText(
        Long.toString(progress.mOverallProgress * 100 / progress.mOverallTotal) + "%");
    mProgressFraction.setText(
        Helpers.getDownloadProgressString(progress.mOverallProgress, progress.mOverallTotal));
  }
  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;
  }
Exemplo n.º 6
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"));
 }
Exemplo n.º 7
0
 @Override
 public void onDownloadProgress(DownloadProgressInfo progress) {
   Log.i(
       TAG,
       "on download progress : "
           + Helpers.getDownloadProgressPercent(
               progress.mOverallProgress, progress.mOverallTotal));
   notifyDownloadProgress(
       (float) progress.mOverallProgress / (float) progress.mOverallTotal, progress.mOverallTotal);
 }
  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;
      }
    }
  }
Exemplo n.º 9
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 void setState(int newState) {
   if (mState != newState) {
     mState = newState;
     mStatusText.setText(Helpers.getDownloaderStringResourceIDFromState(newState));
   }
 }
Exemplo n.º 11
0
 @Override
 public void onDownloadStateChanged(int newState) {
   Log.i(
       TAG,
       "on download state changed : "
           + newState
           + ", as string : "
           + Helpers.getDownloaderStringResourceIDFromState(newState));
   switch (newState) {
     case IDownloaderClient.STATE_IDLE:
       notifyDownloadStateChanged("", -1, "");
       break;
     case IDownloaderClient.STATE_FETCHING_URL:
     case IDownloaderClient.STATE_CONNECTING:
       notifyDownloadStateChanged(
           "Récupération des informations de téléchargement en cours ...",
           1,
           "AC_Expansion_Infos");
       break;
     case IDownloaderClient.STATE_DOWNLOADING:
       notifyDownloadStateChanged(
           "Téléchargement du contenu additionnel de l'application ...",
           2,
           "AC_Expansion_Download");
       break;
     case IDownloaderClient.STATE_COMPLETED:
       notifyDownloadCompleted();
       break;
     case IDownloaderClient.STATE_PAUSED_BY_REQUEST:
       notifyDownloadStateChanged("", -1, "");
       // We don't want to go into the details of those states yet, just draw a generic "no
       // connexion"
     case IDownloaderClient.STATE_PAUSED_NETWORK_UNAVAILABLE:
     case IDownloaderClient.STATE_PAUSED_WIFI_DISABLED_NEED_CELLULAR_PERMISSION:
     case IDownloaderClient.STATE_PAUSED_NEED_CELLULAR_PERMISSION:
     case IDownloaderClient.STATE_PAUSED_WIFI_DISABLED:
     case IDownloaderClient.STATE_PAUSED_NEED_WIFI:
     case IDownloaderClient.STATE_PAUSED_ROAMING:
       notifyDownloadStateChanged(
           "Aucune connexion réseau disponible, merci de réessayer après vous être connecté.",
           3,
           "AC_Expansion_NoConnexion");
       break;
     case IDownloaderClient.STATE_PAUSED_NETWORK_SETUP_FAILURE:
     case IDownloaderClient.STATE_FAILED_FETCHING_URL:
       notifyDownloadStateChanged(
           "Un problème s'est produit pendant la récupération des informations de téléchargement, merci de réessayer plus tard",
           5,
           "AC_Expansion_ProblemInfos");
       break;
     case IDownloaderClient.STATE_PAUSED_SDCARD_UNAVAILABLE:
       notifyDownloadStateChanged(
           "L'espace de stockage externe n'est pas disponible.",
           4,
           "AC_Expansion_StorageNotFound");
       break;
     case IDownloaderClient.STATE_FAILED_UNLICENSED:
       notifyDownloadStateChanged(
           "Un problème s'est produit. Merci de ré-installer l'application depuis Google Play.",
           5,
           "AC_Expansion_Reinstall");
       break;
     case IDownloaderClient.STATE_FAILED_SDCARD_FULL:
       notifyDownloadStateChanged(
           "L'espace de stockage externe est plein. Merci de libérer de l'espace et réessayer.",
           4,
           "AC_Expansion_StorageFull");
       break;
     case IDownloaderClient.STATE_FAILED_CANCELED:
     case IDownloaderClient.STATE_FAILED:
       notifyDownloadStateChanged(
           "Un problème s'est produit. Merci de réessayer ultérieurement.",
           5,
           "AC_Expansion_Problem");
       break;
   }
 }
Exemplo n.º 12
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;
  }