Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Stefan Zabka
Companion App Android
Commits
0318c9ab
Commit
0318c9ab
authored
Aug 18, 2019
by
Anon
Browse files
Set up card10 folder structure and launcher script.
parent
2fc8dac7
Changes
1
Hide whitespace changes
Inline
Side-by-side
app/src/main/java/de/ccc/events/badge/card10/hatchery/AppDetailFragment.kt
View file @
0318c9ab
...
...
@@ -22,7 +22,6 @@
package
de.ccc.events.badge.card10.hatchery
import
android.content.DialogInterface
import
android.os.AsyncTask
import
android.os.Bundle
import
android.util.Log
...
...
@@ -34,7 +33,6 @@ import androidx.fragment.app.Fragment
import
de.ccc.events.badge.card10.R
import
de.ccc.events.badge.card10.common.LoadingDialog
import
kotlinx.android.synthetic.main.app_detail_fragment.*
import
org.apache.commons.compress.archivers.tar.TarArchiveEntry
import
org.apache.commons.compress.archivers.tar.TarArchiveInputStream
import
org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream
import
java.io.File
...
...
@@ -90,6 +88,7 @@ class AppDetailFragment : Fragment() {
return
try
{
cacheDir
.
deleteRecursively
()
cacheDir
.
mkdir
()
val
appDir
=
File
(
cacheDir
.
absolutePath
+
"/apps"
).
mkdirs
()
val
inputStream
=
HatcheryClient
().
openDownloadStream
(
app
)
val
file
=
File
.
createTempFile
(
app
.
slug
,
".tar.gz"
,
cacheDir
)
...
...
@@ -97,7 +96,7 @@ class AppDetailFragment : Fragment() {
inputStream
.
copyTo
(
outputStream
)
val
unpacked
Files
=
mutableListOf
<
String
>()
val
app
Files
=
mutableListOf
<
String
>()
val
tarStream
=
TarArchiveInputStream
(
GzipCompressorInputStream
(
file
.
inputStream
()))
while
(
true
)
{
val
entry
=
tarStream
.
nextTarEntry
?:
break
...
...
@@ -106,15 +105,18 @@ class AppDetailFragment : Fragment() {
}
// TODO: A bit hacky. Maybe there is a better way?
val
targetFile
=
File
(
cacheDir
,
entry
.
name
)
val
targetFile
=
File
(
cacheDir
,
"apps/${
entry.name
}"
)
targetFile
.
parentFile
?.
mkdirs
()
targetFile
.
createNewFile
()
Log
.
d
(
TAG
,
"Extracting ${entry.name} to ${targetFile.absolutePath}"
)
tarStream
.
copyTo
(
targetFile
.
outputStream
())
unpacked
Files
.
add
(
entry
.
name
)
app
Files
.
add
(
"apps/${
entry.name
}"
)
}
unpackedFiles
val
launcher
=
createLauncher
(
app
.
slug
,
cacheDir
)
appFiles
.
add
(
launcher
)
appFiles
}
catch
(
e
:
Exception
)
{
null
}
...
...
@@ -129,5 +131,21 @@ class AppDetailFragment : Fragment() {
loadingDialog
.
dismiss
()
}
fun
createLauncher
(
slug
:
String
,
cacheDir
:
File
):
String
{
val
fileName
=
"$slug.py"
val
file
=
File
(
cacheDir
,
fileName
)
file
.
createNewFile
()
val
src
=
"""
# Launcher script for $slug
import os
os.exec("apps/$slug/__init__.py")
"""
.
trimIndent
()
file
.
writeText
(
src
)
return
fileName
}
}
}
Write
Preview
Supports
Markdown
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