Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
M
Magisk
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Magisk
Commits
72489387
Commit
72489387
authored
Jul 09, 2019
by
Viktor De Pasquale
Committed by
John Wu
Jul 20, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added option to intercept progress while copying files
parent
736729f5
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
7 deletions
+30
-7
MagiskRepository.kt
.../com/topjohnwu/magisk/data/repository/MagiskRepository.kt
+5
-5
XNetwork.kt
app/src/main/java/com/topjohnwu/magisk/utils/XNetwork.kt
+25
-2
No files found.
app/src/main/java/com/topjohnwu/magisk/data/repository/MagiskRepository.kt
View file @
72489387
...
@@ -12,7 +12,7 @@ import com.topjohnwu.magisk.model.entity.HideTarget
...
@@ -12,7 +12,7 @@ import com.topjohnwu.magisk.model.entity.HideTarget
import
com.topjohnwu.magisk.utils.Utils
import
com.topjohnwu.magisk.utils.Utils
import
com.topjohnwu.magisk.utils.inject
import
com.topjohnwu.magisk.utils.inject
import
com.topjohnwu.magisk.utils.toSingle
import
com.topjohnwu.magisk.utils.toSingle
import
com.topjohnwu.magisk.utils.writeToFile
import
com.topjohnwu.magisk.utils.writeTo
Cached
File
import
com.topjohnwu.superuser.Shell
import
com.topjohnwu.superuser.Shell
import
io.reactivex.Single
import
io.reactivex.Single
...
@@ -24,21 +24,21 @@ class MagiskRepository(
...
@@ -24,21 +24,21 @@ class MagiskRepository(
fun
fetchMagisk
()
=
fetchUpdate
()
fun
fetchMagisk
()
=
fetchUpdate
()
.
flatMap
{
apiRaw
.
fetchFile
(
it
.
magisk
.
link
)
}
.
flatMap
{
apiRaw
.
fetchFile
(
it
.
magisk
.
link
)
}
.
map
{
it
.
writeToFile
(
context
,
FILE_MAGISK_ZIP
)
}
.
map
{
it
.
writeTo
Cached
File
(
context
,
FILE_MAGISK_ZIP
)
}
fun
fetchManager
()
=
fetchUpdate
()
fun
fetchManager
()
=
fetchUpdate
()
.
flatMap
{
apiRaw
.
fetchFile
(
it
.
app
.
link
)
}
.
flatMap
{
apiRaw
.
fetchFile
(
it
.
app
.
link
)
}
.
map
{
it
.
writeToFile
(
context
,
FILE_MAGISK_APK
)
}
.
map
{
it
.
writeTo
Cached
File
(
context
,
FILE_MAGISK_APK
)
}
fun
fetchUninstaller
()
=
fetchUpdate
()
fun
fetchUninstaller
()
=
fetchUpdate
()
.
flatMap
{
apiRaw
.
fetchFile
(
it
.
uninstaller
.
link
)
}
.
flatMap
{
apiRaw
.
fetchFile
(
it
.
uninstaller
.
link
)
}
.
map
{
it
.
writeToFile
(
context
,
FILE_UNINSTALLER_ZIP
)
}
.
map
{
it
.
writeTo
Cached
File
(
context
,
FILE_UNINSTALLER_ZIP
)
}
fun
fetchSafetynet
()
=
apiRaw
.
fetchSafetynet
()
fun
fetchSafetynet
()
=
apiRaw
.
fetchSafetynet
()
fun
fetchBootctl
()
=
apiRaw
fun
fetchBootctl
()
=
apiRaw
.
fetchBootctl
()
.
fetchBootctl
()
.
map
{
it
.
writeToFile
(
context
,
FILE_BOOTCTL_SH
)
}
.
map
{
it
.
writeTo
Cached
File
(
context
,
FILE_BOOTCTL_SH
)
}
fun
fetchUpdate
()
=
when
(
Config
.
updateChannel
)
{
fun
fetchUpdate
()
=
when
(
Config
.
updateChannel
)
{
...
...
app/src/main/java/com/topjohnwu/magisk/utils/XNetwork.kt
View file @
72489387
...
@@ -3,13 +3,36 @@ package com.topjohnwu.magisk.utils
...
@@ -3,13 +3,36 @@ package com.topjohnwu.magisk.utils
import
android.content.Context
import
android.content.Context
import
okhttp3.ResponseBody
import
okhttp3.ResponseBody
import
java.io.File
import
java.io.File
import
java.io.InputStream
import
java.io.OutputStream
fun
ResponseBody
.
writeToFile
(
context
:
Context
,
fileName
:
String
):
File
{
inline
fun
ResponseBody
.
writeToCachedFile
(
context
:
Context
,
fileName
:
String
,
progress
:
(
Long
)
->
Unit
=
{}
):
File
{
val
file
=
File
(
context
.
cacheDir
,
fileName
)
val
file
=
File
(
context
.
cacheDir
,
fileName
)
withStreams
(
byteStream
(),
file
.
outputStream
())
{
inStream
,
outStream
->
withStreams
(
byteStream
(),
file
.
outputStream
())
{
inStream
,
outStream
->
inStream
.
copyTo
(
outStream
)
inStream
.
copyTo
WithProgress
(
outStream
,
progress
)
}
}
return
file
return
file
}
}
fun
ResponseBody
.
writeToString
()
=
string
()
fun
ResponseBody
.
writeToString
()
=
string
()
inline
fun
InputStream
.
copyToWithProgress
(
out
:
OutputStream
,
progressEmitter
:
(
Long
)
->
Unit
,
bufferSize
:
Int
=
DEFAULT_BUFFER_SIZE
):
Long
{
var
bytesCopied
:
Long
=
0
val
buffer
=
ByteArray
(
bufferSize
)
var
bytes
=
read
(
buffer
)
while
(
bytes
>=
0
)
{
out
.
write
(
buffer
,
0
,
bytes
)
bytesCopied
+=
bytes
bytes
=
read
(
buffer
)
progressEmitter
(
bytesCopied
)
}
return
bytesCopied
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment