Java Code Examples for com.google.android.vending.expansion.downloader.Helpers#generateSaveFileName()

The following examples show how to use com.google.android.vending.expansion.downloader.Helpers#generateSaveFileName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DownloadThread.java    From QtAndroidTools with MIT License 6 votes vote down vote up
/**
 * Called after a successful completion to take any necessary action on the
 * downloaded file.
 */
private void finalizeDestinationFile(State state) throws StopRequest {
    syncDestination(state);
    String tempFilename = state.mFilename;
    String finalFilename = Helpers.generateSaveFileName(mService, mInfo.mFileName);
    if (!state.mFilename.equals(finalFilename)) {
        File startFile = new File(tempFilename);
        File destFile = new File(finalFilename);
        if (mInfo.mTotalBytes != -1 && mInfo.mCurrentBytes == mInfo.mTotalBytes) {
            if (!startFile.renameTo(destFile)) {
                throw new StopRequest(DownloaderService.STATUS_FILE_ERROR,
                        "unable to finalize destination file");
            }
        } else {
            throw new StopRequest(DownloaderService.STATUS_FILE_DELIVERED_INCORRECTLY,
                    "file delivered with incorrect size. probably due to network not browser configured");
        }
    }
}
 
Example 2
Source File: DownloadThread.java    From play-apk-expansion with Apache License 2.0 6 votes vote down vote up
/**
 * Called after a successful completion to take any necessary action on the
 * downloaded file.
 */
private void finalizeDestinationFile(State state) throws StopRequest {
    syncDestination(state);
    String tempFilename = state.mFilename;
    String finalFilename = Helpers.generateSaveFileName(mService, mInfo.mFileName);
    if (!state.mFilename.equals(finalFilename)) {
        File startFile = new File(tempFilename);
        File destFile = new File(finalFilename);
        if (mInfo.mTotalBytes != -1 && mInfo.mCurrentBytes == mInfo.mTotalBytes) {
            if (!startFile.renameTo(destFile)) {
                throw new StopRequest(DownloaderService.STATUS_FILE_ERROR,
                        "unable to finalize destination file");
            }
        } else {
            throw new StopRequest(DownloaderService.STATUS_FILE_DELIVERED_INCORRECTLY,
                    "file delivered with incorrect size. probably due to network not browser configured");
        }
    }
}
 
Example 3
Source File: DownloaderService.java    From play-apk-expansion with Apache License 2.0 6 votes vote down vote up
/**
 * The APK has been updated and a filename has been sent down from the
 * Market call. If the file has the same name as the previous file, we do
 * nothing as the file is guaranteed to be the same. If the file does not
 * have the same name, we download it if it hasn't already been delivered by
 * Market.
 *
 * @param index the index of the file from market (0 = main, 1 = patch)
 * @param filename the name of the new file
 * @param fileSize the size of the new file
 * @return
 */
public boolean handleFileUpdated(DownloadsDB db, int index,
        String filename, long fileSize) {
    DownloadInfo di = db.getDownloadInfoByFileName(filename);
    if (null != di) {
        String oldFile = di.mFileName;
        // cleanup
        if (null != oldFile) {
            if (filename.equals(oldFile)) {
                return false;
            }

            // remove partially downloaded file if it is there
            String deleteFile = Helpers.generateSaveFileName(this, oldFile);
            File f = new File(deleteFile);
            if (f.exists())
                f.delete();
        }
    }
    return !Helpers.doesFileExist(this, filename, fileSize, true);
}
 
Example 4
Source File: DownloadThread.java    From travelguide with Apache License 2.0 6 votes vote down vote up
/**
 * Called after a successful completion to take any necessary action on the
 * downloaded file.
 */
private void finalizeDestinationFile(State state) throws StopRequest {
    syncDestination(state);
    String tempFilename = state.mFilename;
    String finalFilename = Helpers.generateSaveFileName(mService, mInfo.mFileName);
    if (!state.mFilename.equals(finalFilename)) {
        File startFile = new File(tempFilename);
        File destFile = new File(finalFilename);
        if (mInfo.mTotalBytes != -1 && mInfo.mCurrentBytes == mInfo.mTotalBytes) {
            if (!startFile.renameTo(destFile)) {
                throw new StopRequest(DownloaderService.STATUS_FILE_ERROR,
                        "unable to finalize destination file");
            }
        } else {
            throw new StopRequest(DownloaderService.STATUS_FILE_DELIVERED_INCORRECTLY,
                    "file delivered with incorrect size. probably due to network not browser configured");
        }
    }
}
 
Example 5
Source File: DownloaderService.java    From travelguide with Apache License 2.0 6 votes vote down vote up
/**
 * The APK has been updated and a filename has been sent down from the
 * Market call. If the file has the same name as the previous file, we do
 * nothing as the file is guaranteed to be the same. If the file does not
 * have the same name, we download it if it hasn't already been delivered by
 * Market.
 * 
 * @param index the index of the file from market (0 = main, 1 = patch)
 * @param filename the name of the new file
 * @param fileSize the size of the new file
 * @return
 */
public boolean handleFileUpdated(DownloadsDB db, int index,
        String filename, long fileSize) {
    DownloadInfo di = db.getDownloadInfoByFileName(filename);
    if (null != di) {
        String oldFile = di.mFileName;
        // cleanup
        if (null != oldFile) {
            if (filename.equals(oldFile)) {
                return false;
            }

            // remove partially downloaded file if it is there
            String deleteFile = Helpers.generateSaveFileName(this, oldFile);
            File f = new File(deleteFile);
            if (f.exists())
                f.delete();
        }
    }
    return !Helpers.doesFileExist(this, filename, fileSize, true);
}
 
Example 6
Source File: DownloadThread.java    From Alite with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Called after a successful completion to take any necessary action on the
 * downloaded file.
 */
private void finalizeDestinationFile(State state) throws StopRequest {
    syncDestination(state);
    String tempFilename = state.mFilename;
    String finalFilename = Helpers.generateSaveFileName(mService, mInfo.mFileName);
    if (!state.mFilename.equals(finalFilename)) {
        File startFile = new File(tempFilename);
        File destFile = new File(finalFilename);
        if (mInfo.mTotalBytes != -1 && mInfo.mCurrentBytes == mInfo.mTotalBytes) {
            if (!startFile.renameTo(destFile)) {
                throw new StopRequest(DownloaderService.STATUS_FILE_ERROR,
                        "unable to finalize destination file");
            }
        } else {
            throw new StopRequest(DownloaderService.STATUS_FILE_DELIVERED_INCORRECTLY,
                    "file delivered with incorrect size. probably due to network not browser configured");
        }
    }
}
 
Example 7
Source File: DownloaderService.java    From Alite with GNU General Public License v3.0 6 votes vote down vote up
/**
 * The APK has been updated and a filename has been sent down from the
 * Market call. If the file has the same name as the previous file, we do
 * nothing as the file is guaranteed to be the same. If the file does not
 * have the same name, we download it if it hasn't already been delivered by
 * Market.
 * 
 * @param index the index of the file from market (0 = main, 1 = patch)
 * @param filename the name of the new file
 * @param fileSize the size of the new file
 * @return
 */
public boolean handleFileUpdated(DownloadsDB db, int index,
        String filename, long fileSize) {
    DownloadInfo di = db.getDownloadInfoByFileName(filename);
    if (null != di) {
        String oldFile = di.mFileName;
        // cleanup
        if (null != oldFile) {
            if (filename.equals(oldFile)) {
                return false;
            }

            // remove partially downloaded file if it is there
            String deleteFile = Helpers.generateSaveFileName(this, oldFile);
            File f = new File(deleteFile);
            if (f.exists())
                f.delete();
        }
    }
    return !Helpers.doesFileExist(this, filename, fileSize, true);
}
 
Example 8
Source File: DownloadThread.java    From UnityOBBDownloader with Apache License 2.0 6 votes vote down vote up
/**
 * Called after a successful completion to take any necessary action on the
 * downloaded file.
 */
private void finalizeDestinationFile(State state) throws StopRequest {
    syncDestination(state);
    String tempFilename = state.mFilename;
    String finalFilename = Helpers.generateSaveFileName(mService, mInfo.mFileName);
    if (!state.mFilename.equals(finalFilename)) {
        File startFile = new File(tempFilename);
        File destFile = new File(finalFilename);
        if (mInfo.mTotalBytes != -1 && mInfo.mCurrentBytes == mInfo.mTotalBytes) {
            if (!startFile.renameTo(destFile)) {
                throw new StopRequest(DownloaderService.STATUS_FILE_ERROR,
                        "unable to finalize destination file");
            }
        } else {
            throw new StopRequest(DownloaderService.STATUS_FILE_DELIVERED_INCORRECTLY,
                    "file delivered with incorrect size. probably due to network not browser configured");
        }
    }
}
 
Example 9
Source File: DownloaderService.java    From UnityOBBDownloader with Apache License 2.0 6 votes vote down vote up
/**
 * The APK has been updated and a filename has been sent down from the
 * Market call. If the file has the same name as the previous file, we do
 * nothing as the file is guaranteed to be the same. If the file does not
 * have the same name, we download it if it hasn't already been delivered by
 * Market.
 *
 * @param index the index of the file from market (0 = main, 1 = patch)
 * @param filename the name of the new file
 * @param fileSize the size of the new file
 * @return
 */
public boolean handleFileUpdated(DownloadsDB db, int index,
        String filename, long fileSize) {
    DownloadInfo di = db.getDownloadInfoByFileName(filename);
    if (null != di) {
        String oldFile = di.mFileName;
        // cleanup
        if (null != oldFile) {
            if (filename.equals(oldFile)) {
                return false;
            }

            // remove partially downloaded file if it is there
            String deleteFile = Helpers.generateSaveFileName(this, oldFile);
            File f = new File(deleteFile);
            if (f.exists())
                f.delete();
        }
    }
    return !Helpers.doesFileExist(this, filename, fileSize, true);
}
 
Example 10
Source File: AliteStartManager.java    From Alite with GNU General Public License v3.0 5 votes vote down vote up
private boolean expansionFilesDelivered() {
       File oldObb = new File(Environment.getExternalStorageDirectory() + "/Android/obb/de.phbouillon.android.games.alite/main.2170.de.phbouillon.android.games.alite.obb");
       if (oldObb.exists()) {
       	oldObb.delete();
       }
    String fileName = Helpers.getExpansionAPKFileName(this, true, AliteConfig.EXTENSION_FILE_VERSION);
    File fileForNewFile = new File(Helpers.generateSaveFileName(this, fileName));
    AliteLog.e("Check for OBB", "OBB exists? " + fileForNewFile.getAbsolutePath());
    return Helpers.doesFileExist(this, fileName, AliteConfig.EXTENSION_FILE_LENGTH, false);
}