From b6bcb29795e7e0d4b15fad2f3b5b72d7f47bf752 Mon Sep 17 00:00:00 2001 From: Lucas Tarasconi Date: Sun, 9 Sep 2018 13:27:42 +1000 Subject: [PATCH] Init Commit --- iCloudDownlader.xcodeproj/project.pbxproj | 12 ++- .../xcschemes/iCloudDownlader.xcscheme | 97 +++++++++++++++++++ .../xcschemes/xcschememanagement.plist | 8 ++ iCloudDownlader/ConsoleIO.swift | 28 ++++++ iCloudDownlader/Downloader.swift | 56 +++++++++++ iCloudDownlader/main.swift | 14 ++- 6 files changed, 212 insertions(+), 3 deletions(-) create mode 100644 iCloudDownlader.xcodeproj/xcuserdata/lucas.xcuserdatad/xcschemes/iCloudDownlader.xcscheme create mode 100644 iCloudDownlader/ConsoleIO.swift create mode 100644 iCloudDownlader/Downloader.swift diff --git a/iCloudDownlader.xcodeproj/project.pbxproj b/iCloudDownlader.xcodeproj/project.pbxproj index 97502b2..23b27c7 100644 --- a/iCloudDownlader.xcodeproj/project.pbxproj +++ b/iCloudDownlader.xcodeproj/project.pbxproj @@ -8,6 +8,8 @@ /* Begin PBXBuildFile section */ A0CF17892144B66500D1DDCC /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = A0CF17882144B66500D1DDCC /* main.swift */; }; + A0CF17902144B6D000D1DDCC /* ConsoleIO.swift in Sources */ = {isa = PBXBuildFile; fileRef = A0CF178F2144B6D000D1DDCC /* ConsoleIO.swift */; }; + A0CF17942144B8E400D1DDCC /* Downloader.swift in Sources */ = {isa = PBXBuildFile; fileRef = A0CF17932144B8E400D1DDCC /* Downloader.swift */; }; /* End PBXBuildFile section */ /* Begin PBXCopyFilesBuildPhase section */ @@ -25,6 +27,8 @@ /* Begin PBXFileReference section */ A0CF17852144B66500D1DDCC /* iCloudDownlader */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = iCloudDownlader; sourceTree = BUILT_PRODUCTS_DIR; }; A0CF17882144B66500D1DDCC /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = ""; }; + A0CF178F2144B6D000D1DDCC /* ConsoleIO.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConsoleIO.swift; sourceTree = ""; }; + A0CF17932144B8E400D1DDCC /* Downloader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Downloader.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -57,7 +61,9 @@ A0CF17872144B66500D1DDCC /* iCloudDownlader */ = { isa = PBXGroup; children = ( + A0CF178F2144B6D000D1DDCC /* ConsoleIO.swift */, A0CF17882144B66500D1DDCC /* main.swift */, + A0CF17932144B8E400D1DDCC /* Downloader.swift */, ); path = iCloudDownlader; sourceTree = ""; @@ -120,6 +126,8 @@ buildActionMask = 2147483647; files = ( A0CF17892144B66500D1DDCC /* main.swift in Sources */, + A0CF17902144B6D000D1DDCC /* ConsoleIO.swift in Sources */, + A0CF17942144B8E400D1DDCC /* Downloader.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -158,7 +166,7 @@ CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - CODE_SIGN_IDENTITY = "-"; + CODE_SIGN_IDENTITY = ""; COPY_PHASE_STRIP = NO; DEBUG_INFORMATION_FORMAT = dwarf; ENABLE_STRICT_OBJC_MSGSEND = YES; @@ -218,7 +226,7 @@ CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - CODE_SIGN_IDENTITY = "-"; + CODE_SIGN_IDENTITY = ""; COPY_PHASE_STRIP = NO; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; ENABLE_NS_ASSERTIONS = NO; diff --git a/iCloudDownlader.xcodeproj/xcuserdata/lucas.xcuserdatad/xcschemes/iCloudDownlader.xcscheme b/iCloudDownlader.xcodeproj/xcuserdata/lucas.xcuserdatad/xcschemes/iCloudDownlader.xcscheme new file mode 100644 index 0000000..a414dfb --- /dev/null +++ b/iCloudDownlader.xcodeproj/xcuserdata/lucas.xcuserdatad/xcschemes/iCloudDownlader.xcscheme @@ -0,0 +1,97 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/iCloudDownlader.xcodeproj/xcuserdata/lucas.xcuserdatad/xcschemes/xcschememanagement.plist b/iCloudDownlader.xcodeproj/xcuserdata/lucas.xcuserdatad/xcschemes/xcschememanagement.plist index 8283b7b..651e642 100644 --- a/iCloudDownlader.xcodeproj/xcuserdata/lucas.xcuserdatad/xcschemes/xcschememanagement.plist +++ b/iCloudDownlader.xcodeproj/xcuserdata/lucas.xcuserdatad/xcschemes/xcschememanagement.plist @@ -10,5 +10,13 @@ 0 + SuppressBuildableAutocreation + + A0CF17842144B66500D1DDCC + + primary + + + diff --git a/iCloudDownlader/ConsoleIO.swift b/iCloudDownlader/ConsoleIO.swift new file mode 100644 index 0000000..0789ed9 --- /dev/null +++ b/iCloudDownlader/ConsoleIO.swift @@ -0,0 +1,28 @@ +// +// ConsoleIO.swift +// iCloudDownlader +// +// Created by Lucas Tarasconi on 09/09/2018. +// Copyright © 2018 Lucas Tarasconi. All rights reserved. +// + +import Foundation + +enum OutputType { + case error + case standard + case warning +} + +class ConsoleIO { + func writeMessage(_ message: String, to: OutputType = .standard) { + switch to { + case .standard: + print("\(message)") + case .warning: + print("Warning: \(message)") + case .error: + fputs("Error: \(message)\n", stderr) + } + } + } diff --git a/iCloudDownlader/Downloader.swift b/iCloudDownlader/Downloader.swift new file mode 100644 index 0000000..f5993b1 --- /dev/null +++ b/iCloudDownlader/Downloader.swift @@ -0,0 +1,56 @@ +// +// Downloader.swift +// iCloudDownlader +// +// Created by Lucas Tarasconi on 09/09/2018. +// Copyright © 2018 Lucas Tarasconi. All rights reserved. +// + +import Foundation + +let fm = FileManager.default +let path = fm.currentDirectoryPath + +class Downloader { + let consoleIO = ConsoleIO() + + func fetchFile(fileUrl : URL) { + if fm.isUbiquitousItem(at: fileUrl){ + do { + try fm.startDownloadingUbiquitousItem(at: fileUrl) + consoleIO.writeMessage("Info : \(fileUrl.lastPathComponent) is downloading") + } catch { + consoleIO.writeMessage("Can't download \(fm.displayName(atPath: fileUrl.lastPathComponent))", to: .error) + } + } + else { + consoleIO.writeMessage("\(fm.displayName(atPath: fileUrl.lastPathComponent)) is already download", to: .warning) + } + } + + func downloadFile() { + let file = CommandLine.arguments[1] + let fileUrl = NSURL.fileURL(withPath: file) + fetchFile(fileUrl: fileUrl) + + } + + func downloadFolder() { + do { + let items = try fm.contentsOfDirectory(atPath: path) + + for item in items { + let itemUrl = NSURL.fileURL(withPath: item) + fetchFile(fileUrl: itemUrl) + } + } catch { + consoleIO.writeMessage("Can't acces the folder", to: .error) + } + + + } + + + + +} diff --git a/iCloudDownlader/main.swift b/iCloudDownlader/main.swift index 4b7cc43..b52f4ca 100644 --- a/iCloudDownlader/main.swift +++ b/iCloudDownlader/main.swift @@ -7,6 +7,18 @@ // import Foundation +let downloader = Downloader() +let consoleIO = ConsoleIO() -print("Hello, World!") +if CommandLine.argc < 2 { + consoleIO.writeMessage("No file given", to: .error) +} else { + if CommandLine.arguments[1] == "-A" { + downloader.downloadFolder() + } + else { + downloader.downloadFile() + } + +}