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
8b7144c9
Commit
8b7144c9
authored
May 03, 2019
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rewrite ZipUtils in Kotlin
parent
d3f5f5ee
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
67 deletions
+48
-67
FlashZip.java
app/src/main/java/com/topjohnwu/magisk/tasks/FlashZip.java
+2
-2
ZipUtils.java
app/src/main/java/com/topjohnwu/magisk/utils/ZipUtils.java
+0
-65
ZipUtils.kt
app/src/main/java/com/topjohnwu/magisk/utils/ZipUtils.kt
+46
-0
No files found.
app/src/main/java/com/topjohnwu/magisk/tasks/FlashZip.java
View file @
8b7144c9
...
...
@@ -5,7 +5,7 @@ import android.net.Uri;
import
com.topjohnwu.magisk.App
;
import
com.topjohnwu.magisk.Const
;
import
com.topjohnwu.magisk.utils.Utils
;
import
com.topjohnwu.magisk.utils.ZipUtils
;
import
com.topjohnwu.magisk.utils.ZipUtils
Kt
;
import
com.topjohnwu.superuser.Shell
;
import
com.topjohnwu.superuser.ShellUtils
;
import
com.topjohnwu.superuser.internal.UiThreadHandler
;
...
...
@@ -34,7 +34,7 @@ public abstract class FlashZip {
}
private
boolean
unzipAndCheck
()
throws
IOException
{
ZipUtils
.
unzip
(
tmpFile
,
tmpFile
.
getParentFile
(),
"META-INF/com/google/android"
,
true
);
ZipUtils
Kt
.
unzip
(
tmpFile
,
tmpFile
.
getParentFile
(),
"META-INF/com/google/android"
,
true
);
return
Shell
.
su
(
"grep -q '#MAGISK' "
+
new
File
(
tmpFile
.
getParentFile
(),
"updater-script"
))
.
exec
().
isSuccess
();
}
...
...
app/src/main/java/com/topjohnwu/magisk/utils/ZipUtils.java
deleted
100644 → 0
View file @
d3f5f5ee
package
com
.
topjohnwu
.
magisk
.
utils
;
import
com.topjohnwu.signing.JarMap
;
import
com.topjohnwu.signing.SignAPK
;
import
com.topjohnwu.superuser.ShellUtils
;
import
com.topjohnwu.superuser.io.SuFile
;
import
com.topjohnwu.superuser.io.SuFileOutputStream
;
import
java.io.BufferedInputStream
;
import
java.io.BufferedOutputStream
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.util.zip.ZipEntry
;
import
java.util.zip.ZipInputStream
;
public
class
ZipUtils
{
public
static
void
unzip
(
File
zip
,
File
folder
,
String
path
,
boolean
junkPath
)
throws
IOException
{
InputStream
in
=
new
BufferedInputStream
(
new
FileInputStream
(
zip
));
unzip
(
in
,
folder
,
path
,
junkPath
);
in
.
close
();
}
public
static
void
unzip
(
InputStream
zip
,
File
folder
,
String
path
,
boolean
junkPath
)
throws
IOException
{
try
{
ZipInputStream
zipfile
=
new
ZipInputStream
(
zip
);
ZipEntry
entry
;
while
((
entry
=
zipfile
.
getNextEntry
())
!=
null
)
{
if
(!
entry
.
getName
().
startsWith
(
path
)
||
entry
.
isDirectory
()){
// Ignore directories, only create files
continue
;
}
String
name
;
if
(
junkPath
)
{
name
=
entry
.
getName
().
substring
(
entry
.
getName
().
lastIndexOf
(
'/'
)
+
1
);
}
else
{
name
=
entry
.
getName
();
}
File
dest
=
new
File
(
folder
,
name
);
if
(!
dest
.
getParentFile
().
exists
()
&&
!
dest
.
getParentFile
().
mkdirs
())
{
dest
=
new
SuFile
(
folder
,
name
);
dest
.
getParentFile
().
mkdirs
();
}
try
(
OutputStream
out
=
new
SuFileOutputStream
(
dest
))
{
ShellUtils
.
pump
(
zipfile
,
out
);
}
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
throw
e
;
}
}
public
static
void
signZip
(
File
input
,
File
output
)
throws
Exception
{
try
(
JarMap
map
=
new
JarMap
(
input
,
false
);
BufferedOutputStream
out
=
new
BufferedOutputStream
(
new
FileOutputStream
(
output
)))
{
SignAPK
.
sign
(
map
,
out
);
}
}
}
app/src/main/java/com/topjohnwu/magisk/utils/ZipUtils.kt
0 → 100644
View file @
8b7144c9
package
com.topjohnwu.magisk.utils
import
com.topjohnwu.superuser.io.SuFile
import
com.topjohnwu.superuser.io.SuFileOutputStream
import
java.io.File
import
java.io.IOException
import
java.io.InputStream
import
java.util.zip.ZipEntry
import
java.util.zip.ZipInputStream
@Throws
(
IOException
::
class
)
@JvmOverloads
fun
unzip
(
zip
:
File
,
folder
:
File
,
path
:
String
=
""
,
junkPath
:
Boolean
=
false
)
{
zip
.
inputStream
().
buffered
().
use
{
unzip
(
it
,
folder
,
path
,
junkPath
)
}
}
@Throws
(
IOException
::
class
)
fun
unzip
(
zip
:
InputStream
,
folder
:
File
,
path
:
String
,
junkPath
:
Boolean
)
{
try
{
val
zin
=
ZipInputStream
(
zip
)
var
entry
:
ZipEntry
while
(
true
)
{
entry
=
zin
.
nextEntry
?:
break
if
(!
entry
.
name
.
startsWith
(
path
)
||
entry
.
isDirectory
)
{
// Ignore directories, only create files
continue
}
val
name
=
if
(
junkPath
)
entry
.
name
.
substring
(
entry
.
name
.
lastIndexOf
(
'/'
)
+
1
)
else
entry
.
name
var
dest
=
File
(
folder
,
name
)
if
(!
dest
.
parentFile
!!
.
exists
()
&&
!
dest
.
parentFile
!!
.
mkdirs
())
{
dest
=
SuFile
(
folder
,
name
)
dest
.
parentFile
!!
.
mkdirs
()
}
SuFileOutputStream
(
dest
).
use
{
out
->
zin
.
copyTo
(
out
)
}
}
}
catch
(
e
:
IOException
)
{
e
.
printStackTrace
()
throw
e
}
}
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