Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
Companion App iOS
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
3
Issues
3
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
card10
Companion App iOS
Commits
d53fccf7
Commit
d53fccf7
authored
Aug 19, 2019
by
Philip Brechler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Download eggs to file system and inform delegate
parent
ccdb1a85
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
2 deletions
+38
-2
card10badge/Hatchery/HatcheryClient.swift
card10badge/Hatchery/HatcheryClient.swift
+25
-2
card10badge/Hatchery/HatcheryDetailViewController.swift
card10badge/Hatchery/HatcheryDetailViewController.swift
+9
-0
card10badge/Hatchery/HatcheryRootTableViewController.swift
card10badge/Hatchery/HatcheryRootTableViewController.swift
+4
-0
No files found.
card10badge/Hatchery/HatcheryClient.swift
View file @
d53fccf7
...
...
@@ -11,6 +11,8 @@ import SWCompression
protocol
HatcheryClientDelegate
:
class
{
func
didRefreshListOfEggs
()
func
didDownloadEggToPath
(
_
path
:
URL
)
func
didFailToDownloadEgg
()
}
class
HatcheryClient
:
NSObject
,
URLSessionDelegate
{
...
...
@@ -127,17 +129,38 @@ class HatcheryClient: NSObject, URLSessionDelegate {
private
func
unpackEgg
(
_
localFile
:
URL
)
{
let
data
=
try
?
Data
.
init
(
contentsOf
:
localFile
)
let
unpackUrl
=
FileManager
.
default
.
temporaryDirectory
let
unpackUrl
=
FileManager
.
default
.
temporaryDirectory
.
appendingPathComponent
(
"downloaded_eggs"
)
do
{
let
decompressedTarData
=
try
GzipArchive
.
unarchive
(
archive
:
data
!
)
let
unpackedTar
=
try
TarContainer
.
open
(
container
:
decompressedTarData
)
var
createdFileCount
:
Int
=
0
var
folderNameForEgg
:
String
?
for
tarEntry
in
unpackedTar
{
let
fileName
=
unpackUrl
.
appendingPathComponent
(
tarEntry
.
info
.
name
)
let
data
=
tarEntry
.
data
//TODO: Upload files to card10 or safe?
if
folderNameForEgg
==
nil
{
folderNameForEgg
=
fileName
.
deletingLastPathComponent
()
.
path
// Kind of betting on that there are no subfolders
}
try
FileManager
.
default
.
createDirectory
(
at
:
fileName
.
deletingLastPathComponent
(),
withIntermediateDirectories
:
true
,
attributes
:
nil
)
if
(
FileManager
.
default
.
createFile
(
atPath
:
fileName
.
path
,
contents
:
data
,
attributes
:
nil
))
{
createdFileCount
+=
1
//Increment so we know if we wrote all the files
}
else
{
print
(
"Failed to write file to path "
,
fileName
)
}
}
if
createdFileCount
==
unpackedTar
.
count
{
//Success, we downloaded and stored all the files
delegate
?
.
didDownloadEggToPath
(
URL
(
string
:
folderNameForEgg
!
)
??
unpackUrl
)
}
else
{
delegate
?
.
didFailToDownloadEgg
()
}
}
catch
let
error
{
print
(
error
)
delegate
?
.
didFailToDownloadEgg
()
}
}
...
...
card10badge/Hatchery/HatcheryDetailViewController.swift
View file @
d53fccf7
...
...
@@ -44,7 +44,16 @@ class HatcheryDetailViewController: UIViewController,HatcheryClientDelegate {
func
didRefreshListOfEggs
()
{}
func
didDownloadEggToPath
(
_
path
:
URL
)
{
//TODO: Call BluetoothManager to upload? Just tell the user and they do it Control?
}
func
didFailToDownloadEgg
()
{
let
failedAlert
=
UIAlertController
(
title
:
"Error"
,
message
:
"Failed to download egg"
,
preferredStyle
:
.
alert
)
failedAlert
.
addAction
(
UIAlertAction
.
init
(
title
:
"OK"
,
style
:
.
default
,
handler
:
nil
))
self
.
present
(
failedAlert
,
animated
:
true
)
}
}
card10badge/Hatchery/HatcheryRootTableViewController.swift
View file @
d53fccf7
...
...
@@ -77,5 +77,9 @@ class HatcheryRootTableViewController: UITableViewController,HatcheryClientDeleg
@IBAction
func
refreshEggs
(
sender
:
UIRefreshControl
)
{
self
.
client
?
.
updateListOfHatcheryEggs
()
}
func
didDownloadEggToPath
(
_
path
:
URL
)
{}
func
didFailToDownloadEgg
()
{}
}
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