Allow to have different updates using the same filename
This commit is contained in:
@@ -356,6 +356,10 @@ public class UpdaterController implements UpdaterControllerInt {
|
|||||||
}
|
}
|
||||||
UpdateDownload update = mDownloads.get(downloadId).mUpdate;
|
UpdateDownload update = mDownloads.get(downloadId).mUpdate;
|
||||||
File destination = new File(mDownloadRoot, update.getName());
|
File destination = new File(mDownloadRoot, update.getName());
|
||||||
|
if (destination.exists()) {
|
||||||
|
destination = Utils.appendSequentialNumber(destination);
|
||||||
|
Log.d(TAG, "Changing name with " + destination.getName());
|
||||||
|
}
|
||||||
update.setFile(destination);
|
update.setFile(destination);
|
||||||
DownloadClient downloadClient = new DownloadClient.Builder()
|
DownloadClient downloadClient = new DownloadClient.Builder()
|
||||||
.setUrl(update.getDownloadUrl())
|
.setUrl(update.getDownloadUrl())
|
||||||
|
@@ -247,4 +247,25 @@ public class Utils {
|
|||||||
|
|
||||||
preferences.edit().putBoolean(DOWNLOADS_CLEANUP_DONE, true).apply();
|
preferences.edit().putBoolean(DOWNLOADS_CLEANUP_DONE, true).apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static File appendSequentialNumber(final File file) {
|
||||||
|
String name;
|
||||||
|
String extension;
|
||||||
|
int extensionPosition = file.getName().lastIndexOf(".");
|
||||||
|
if (extensionPosition > 0) {
|
||||||
|
name = file.getName().substring(0, extensionPosition);
|
||||||
|
extension = file.getName().substring(extensionPosition);
|
||||||
|
} else {
|
||||||
|
name = file.getName();
|
||||||
|
extension = "";
|
||||||
|
}
|
||||||
|
final File parent = file.getParentFile();
|
||||||
|
for (int i = 1; i < Integer.MAX_VALUE; i++) {
|
||||||
|
File newFile = new File(parent, name + "-" + i + extension);
|
||||||
|
if (!newFile.exists()) {
|
||||||
|
return newFile;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new IllegalStateException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user