Skip to content

Commit

Permalink
Fix .gz file selection from "Recents" or "Downloads" category
Browse files Browse the repository at this point in the history
If gz files are picked from "Recents" or "Downloads" category, we will end up with weird path, to workaround this, we will copy its gz file to our directory to avoid errors.
  • Loading branch information
VegaBobo committed Feb 3, 2022
1 parent 15c38a5 commit 6d70cff
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
17 changes: 15 additions & 2 deletions app/src/main/java/vegabobo/dsusideloader/dsuhelper/PrepareDsu.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,24 @@ class PrepareDsu(
transformFile2Gzip(uri, DeCompressionUtils.Constants.IMG_TO_GZ, gsiDsuObject)
}
".gz" -> {

var gzUri = uri
if (uri.path.toString().contains("msf:")) {
updateText(c.getString(R.string.gz_copy))
gzUri = WorkspaceFilesUtils.copyFileToSafFolder(
c,
uri,
file,
WorkspaceFilesUtils.getWorkspaceFolder(c)
)
}

if (gsiDsuObject!!.fileSize != -1L)
gsiDsuObject.absolutePath =
FilenameUtils.getFilePath(uri, true)
FilenameUtils.getFilePath(gzUri, true)

transformFile2Gzip(
uri,
gzUri,
DeCompressionUtils.Constants.GZ_TO_GSI_OBJECT,
gsiDsuObject
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package vegabobo.dsusideloader.util

import android.content.Context
import android.net.Uri
import androidx.core.net.toUri
import androidx.documentfile.provider.DocumentFile
import java.io.InputStream
import java.io.OutputStream

class WorkspaceFilesUtils {

Expand All @@ -24,6 +27,32 @@ class WorkspaceFilesUtils {
}
}

fun copyFileToSafFolder(
context: Context,
inputFile: Uri,
outputFilename: String,
workspaceFolder: DocumentFile
): Uri {
val input: InputStream?
val output: OutputStream?
val finalFile: DocumentFile? =
workspaceFolder.createFile("application/octet-stream", outputFilename)
try {
output = context.contentResolver.openOutputStream(finalFile!!.uri)
input = context.contentResolver.openInputStream(inputFile)
val buffer = ByteArray(1024)
var read: Int
while (input!!.read(buffer).also { read = it } != -1) {
output!!.write(buffer, 0, read)
}
input.close()
output!!.flush()
output.close()
} catch (e: Exception) {
e.printStackTrace()
}
return finalFile!!.uri
}
}

}
1 change: 1 addition & 0 deletions app/src/main/res/values-pt-rBR/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,5 @@
<string name="credits_google">Muitas outras pelo Google/Android</string>
<string name="save_logs_file">Salvar logs para o arquivo</string>
<string name="debug_build_info">Você está executando uma build depurável.\nDSU Sideloader %1$s (%2$d)</string>
<string name="gz_copy">Copiando arquivo gz para nossa pasta…</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,5 @@
<string name="credits_google">Many others by Google/Android</string>
<string name="save_logs_file">Save logs to file</string>
<string name="debug_build_info">You\'re running a debug build.\nDSU Sideloader %1$s (%2$d)</string>
<string name="gz_copy">Copying gz file into our folder…</string>
</resources>

0 comments on commit 6d70cff

Please sign in to comment.