-
Notifications
You must be signed in to change notification settings - Fork 339
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b5e5006
commit 0eaf1a6
Showing
3 changed files
with
26 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 0 additions & 31 deletions
31
...d/service/src/main/kotlin/net/mullvad/mullvadvpn/service/util/AssetToFilesDirExtractor.kt
This file was deleted.
Oops, something went wrong.
23 changes: 23 additions & 0 deletions
23
android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/util/ContextExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package net.mullvad.mullvadvpn.service.util | ||
|
||
import android.content.Context | ||
import java.io.File | ||
import java.io.FileOutputStream | ||
|
||
fun Context.extractAndOverwriteIfAssetMoreRecent(assetName: String) { | ||
val forceOverwriteIfMoreRecent = lastUpdatedTime() > File(filesDir, assetName).lastModified() | ||
val destination = File(filesDir, assetName) | ||
|
||
if (!destination.exists() || forceOverwriteIfMoreRecent) { | ||
extractFile(assetName, destination) | ||
} | ||
} | ||
|
||
private fun Context.lastUpdatedTime(): Long = | ||
packageManager.getPackageInfo(packageName, 0).lastUpdateTime | ||
|
||
private fun Context.extractFile(asset: String, destination: File) { | ||
val destinationStream = FileOutputStream(destination) | ||
assets.open(asset).copyTo(destinationStream) | ||
destinationStream.close() | ||
} |