Skip to content

Commit

Permalink
Init Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
farnots committed Sep 9, 2018
1 parent f79615c commit b6bcb29
Show file tree
Hide file tree
Showing 6 changed files with 212 additions and 3 deletions.
12 changes: 10 additions & 2 deletions iCloudDownlader.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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 = "<group>"; };
A0CF178F2144B6D000D1DDCC /* ConsoleIO.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConsoleIO.swift; sourceTree = "<group>"; };
A0CF17932144B8E400D1DDCC /* Downloader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Downloader.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -57,7 +61,9 @@
A0CF17872144B66500D1DDCC /* iCloudDownlader */ = {
isa = PBXGroup;
children = (
A0CF178F2144B6D000D1DDCC /* ConsoleIO.swift */,
A0CF17882144B66500D1DDCC /* main.swift */,
A0CF17932144B8E400D1DDCC /* Downloader.swift */,
);
path = iCloudDownlader;
sourceTree = "<group>";
Expand Down Expand Up @@ -120,6 +126,8 @@
buildActionMask = 2147483647;
files = (
A0CF17892144B66500D1DDCC /* main.swift in Sources */,
A0CF17902144B6D000D1DDCC /* ConsoleIO.swift in Sources */,
A0CF17942144B8E400D1DDCC /* Downloader.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0940"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "A0CF17842144B66500D1DDCC"
BuildableName = "iCloudDownlader"
BlueprintName = "iCloudDownlader"
ReferencedContainer = "container:iCloudDownlader.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "A0CF17842144B66500D1DDCC"
BuildableName = "iCloudDownlader"
BlueprintName = "iCloudDownlader"
ReferencedContainer = "container:iCloudDownlader.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "A0CF17842144B66500D1DDCC"
BuildableName = "iCloudDownlader"
BlueprintName = "iCloudDownlader"
ReferencedContainer = "container:iCloudDownlader.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<CommandLineArguments>
<CommandLineArgument
argument = "-A"
isEnabled = "NO">
</CommandLineArgument>
</CommandLineArguments>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "A0CF17842144B66500D1DDCC"
BuildableName = "iCloudDownlader"
BlueprintName = "iCloudDownlader"
ReferencedContainer = "container:iCloudDownlader.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,13 @@
<integer>0</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict>
<key>A0CF17842144B66500D1DDCC</key>
<dict>
<key>primary</key>
<true/>
</dict>
</dict>
</dict>
</plist>
28 changes: 28 additions & 0 deletions iCloudDownlader/ConsoleIO.swift
Original file line number Diff line number Diff line change
@@ -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)
}
}
}
56 changes: 56 additions & 0 deletions iCloudDownlader/Downloader.swift
Original file line number Diff line number Diff line change
@@ -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)
}


}




}
14 changes: 13 additions & 1 deletion iCloudDownlader/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

}

0 comments on commit b6bcb29

Please sign in to comment.