diff --git a/GCDWebServer.xcodeproj/project.pbxproj b/GCDWebServer.xcodeproj/project.pbxproj index 0c9faa4..9b42f50 100644 --- a/GCDWebServer.xcodeproj/project.pbxproj +++ b/GCDWebServer.xcodeproj/project.pbxproj @@ -159,12 +159,10 @@ E2DDD1BC1BE69551002CE867 /* libxml2.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = E2DDD1BB1BE69551002CE867 /* libxml2.tbd */; }; E2DDD1BE1BE6956F002CE867 /* MobileCoreServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E2DDD1BD1BE6956F002CE867 /* MobileCoreServices.framework */; }; E2DDD1C01BE69576002CE867 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E2DDD1BF1BE69576002CE867 /* UIKit.framework */; }; - E2DDD1CB1BE698A8002CE867 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = E2DDD1CA1BE698A8002CE867 /* main.m */; }; - E2DDD1CE1BE698A8002CE867 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = E2DDD1CD1BE698A8002CE867 /* AppDelegate.m */; }; - E2DDD1D11BE698A8002CE867 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E2DDD1D01BE698A8002CE867 /* ViewController.m */; }; + E2DDD1CE1BE698A8002CE867 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2DDD1CD1BE698A8002CE867 /* AppDelegate.swift */; }; + E2DDD1D11BE698A8002CE867 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2DDD1D01BE698A8002CE867 /* ViewController.swift */; }; E2DDD1D41BE698A8002CE867 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = E2DDD1D21BE698A8002CE867 /* Main.storyboard */; }; E2DDD1D61BE698A8002CE867 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = E2DDD1D51BE698A8002CE867 /* Assets.xcassets */; }; - E2DDD1DD1BE69B1C002CE867 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E2DDD1BF1BE69576002CE867 /* UIKit.framework */; }; E2DDD1DE1BE69BB7002CE867 /* GCDWebServer.m in Sources */ = {isa = PBXBuildFile; fileRef = E28BAE1718F99C810095C089 /* GCDWebServer.m */; }; E2DDD1DF1BE69BB7002CE867 /* GCDWebServerConnection.m in Sources */ = {isa = PBXBuildFile; fileRef = E28BAE1918F99C810095C089 /* GCDWebServerConnection.m */; }; E2DDD1E01BE69BB7002CE867 /* GCDWebServerFunctions.m in Sources */ = {isa = PBXBuildFile; fileRef = E28BAE1B18F99C810095C089 /* GCDWebServerFunctions.m */; }; @@ -340,11 +338,8 @@ E2DDD1BD1BE6956F002CE867 /* MobileCoreServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MobileCoreServices.framework; path = Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS9.0.sdk/System/Library/Frameworks/MobileCoreServices.framework; sourceTree = DEVELOPER_DIR; }; E2DDD1BF1BE69576002CE867 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS9.0.sdk/System/Library/Frameworks/UIKit.framework; sourceTree = DEVELOPER_DIR; }; E2DDD1C71BE698A8002CE867 /* GCDWebServer.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = GCDWebServer.app; sourceTree = BUILT_PRODUCTS_DIR; }; - E2DDD1CA1BE698A8002CE867 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; - E2DDD1CC1BE698A8002CE867 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; - E2DDD1CD1BE698A8002CE867 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; - E2DDD1CF1BE698A8002CE867 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; - E2DDD1D01BE698A8002CE867 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; + E2DDD1CD1BE698A8002CE867 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + E2DDD1D01BE698A8002CE867 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; E2DDD1D31BE698A8002CE867 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; E2DDD1D51BE698A8002CE867 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; E2DDD1D71BE698A8002CE867 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; @@ -423,7 +418,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - E2DDD1DD1BE69B1C002CE867 /* UIKit.framework in Frameworks */, E2DDD1ED1BE69BC5002CE867 /* MobileCoreServices.framework in Frameworks */, E2DDD1EE1BE69BC5002CE867 /* CFNetwork.framework in Frameworks */, E2DDD1EF1BE69BC5002CE867 /* libxml2.tbd in Frameworks */, @@ -616,14 +610,11 @@ E2DDD1C81BE698A8002CE867 /* tvOS */ = { isa = PBXGroup; children = ( - E2DDD1CC1BE698A8002CE867 /* AppDelegate.h */, - E2DDD1CD1BE698A8002CE867 /* AppDelegate.m */, - E2DDD1CF1BE698A8002CE867 /* ViewController.h */, - E2DDD1D01BE698A8002CE867 /* ViewController.m */, + E2DDD1CD1BE698A8002CE867 /* AppDelegate.swift */, + E2DDD1D01BE698A8002CE867 /* ViewController.swift */, E2DDD1D21BE698A8002CE867 /* Main.storyboard */, E2DDD1D51BE698A8002CE867 /* Assets.xcassets */, E2DDD1D71BE698A8002CE867 /* Info.plist */, - E2DDD1CA1BE698A8002CE867 /* main.m */, ); path = tvOS; sourceTree = ""; @@ -1081,9 +1072,8 @@ E2DDD1EA1BE69BB7002CE867 /* GCDWebServerStreamedResponse.m in Sources */, E2DDD1EB1BE69BB7002CE867 /* GCDWebDAVServer.m in Sources */, E2DDD1EC1BE69BB7002CE867 /* GCDWebUploader.m in Sources */, - E2DDD1D11BE698A8002CE867 /* ViewController.m in Sources */, - E2DDD1CE1BE698A8002CE867 /* AppDelegate.m in Sources */, - E2DDD1CB1BE698A8002CE867 /* main.m in Sources */, + E2DDD1D11BE698A8002CE867 /* ViewController.swift in Sources */, + E2DDD1CE1BE698A8002CE867 /* AppDelegate.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1408,6 +1398,7 @@ isa = XCBuildConfiguration; buildSettings = { INFOPLIST_FILE = tvOS/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_NAME = GCDWebServer; SDKROOT = appletvos; TVOS_DEPLOYMENT_TARGET = 9.0; @@ -1418,6 +1409,7 @@ isa = XCBuildConfiguration; buildSettings = { INFOPLIST_FILE = tvOS/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_NAME = GCDWebServer; SDKROOT = appletvos; TVOS_DEPLOYMENT_TARGET = 9.0; diff --git a/format-source.sh b/format-source.sh index 26920bd..e93fba6 100755 --- a/format-source.sh +++ b/format-source.sh @@ -39,10 +39,7 @@ popd pushd "Mac" clang-format -style=file -i *.m popd -pushd "tvOS" -clang-format -style=file -i *.h *.m -popd -build/swiftformat --indent 2 "iOS" +build/swiftformat --indent 2 "iOS" "tvOS" echo "OK" diff --git a/tvOS/AppDelegate.h b/tvOS/AppDelegate.h deleted file mode 100644 index 8b0876f..0000000 --- a/tvOS/AppDelegate.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - Copyright (c) 2012-2015, Pierre-Olivier Latour - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - * The name of Pierre-Olivier Latour may not be used to endorse - or promote products derived from this software without specific - prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL PIERRE-OLIVIER LATOUR BE LIABLE FOR ANY - DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#import - -@interface AppDelegate : UIResponder -@property(strong, nonatomic) UIWindow* window; -@end diff --git a/tvOS/AppDelegate.m b/tvOS/AppDelegate.m deleted file mode 100644 index bfd0518..0000000 --- a/tvOS/AppDelegate.m +++ /dev/null @@ -1,36 +0,0 @@ -/* - Copyright (c) 2012-2015, Pierre-Olivier Latour - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - * The name of Pierre-Olivier Latour may not be used to endorse - or promote products derived from this software without specific - prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL PIERRE-OLIVIER LATOUR BE LIABLE FOR ANY - DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#import "AppDelegate.h" - -@implementation AppDelegate - -- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions { - return YES; -} - -@end diff --git a/tvOS/ViewController.h b/tvOS/AppDelegate.swift similarity index 92% rename from tvOS/ViewController.h rename to tvOS/AppDelegate.swift index 5400bd5..ce76fa7 100644 --- a/tvOS/ViewController.h +++ b/tvOS/AppDelegate.swift @@ -1,7 +1,7 @@ /* Copyright (c) 2012-2015, Pierre-Olivier Latour All rights reserved. - + Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright @@ -12,7 +12,7 @@ * The name of Pierre-Olivier Latour may not be used to endorse or promote products derived from this software without specific prior written permission. - + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -25,7 +25,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#import +import UIKit -@interface ViewController : UIViewController -@end +@UIApplicationMain +class AppDelegate: UIResponder, UIApplicationDelegate { + var window: UIWindow? +} diff --git a/tvOS/Base.lproj/Main.storyboard b/tvOS/Base.lproj/Main.storyboard index e0010f2..c7f3e64 100644 --- a/tvOS/Base.lproj/Main.storyboard +++ b/tvOS/Base.lproj/Main.storyboard @@ -1,13 +1,18 @@ - - + + + + + - + + + - + @@ -16,21 +21,22 @@ - - + - - + + + - + diff --git a/tvOS/ViewController.m b/tvOS/ViewController.m deleted file mode 100644 index fbeae6b..0000000 --- a/tvOS/ViewController.m +++ /dev/null @@ -1,77 +0,0 @@ -/* - Copyright (c) 2012-2015, Pierre-Olivier Latour - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - * The name of Pierre-Olivier Latour may not be used to endorse - or promote products derived from this software without specific - prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL PIERRE-OLIVIER LATOUR BE LIABLE FOR ANY - DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#import "ViewController.h" -#import "GCDWebUploader.h" - -@interface ViewController () -@property(weak, nonatomic) IBOutlet UILabel* label; -@end - -@implementation ViewController { -@private - GCDWebUploader* _webServer; -} - -- (void)viewWillAppear:(BOOL)animated { - [super viewWillAppear:animated]; - - NSString* documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]; - _webServer = [[GCDWebUploader alloc] initWithUploadDirectory:documentsPath]; - _webServer.delegate = self; - _webServer.allowHiddenItems = YES; - if ([_webServer start]) { - _label.text = [NSString stringWithFormat:NSLocalizedString(@"GCDWebServer running locally on port %i", nil), (int)_webServer.port]; - } else { - _label.text = NSLocalizedString(@"GCDWebServer not running!", nil); - } -} - -- (void)viewDidDisappear:(BOOL)animated { - [super viewDidDisappear:animated]; - - [_webServer stop]; - _webServer = nil; -} - -- (void)webUploader:(GCDWebUploader*)uploader didUploadFileAtPath:(NSString*)path { - NSLog(@"[UPLOAD] %@", path); -} - -- (void)webUploader:(GCDWebUploader*)uploader didMoveItemFromPath:(NSString*)fromPath toPath:(NSString*)toPath { - NSLog(@"[MOVE] %@ -> %@", fromPath, toPath); -} - -- (void)webUploader:(GCDWebUploader*)uploader didDeleteItemAtPath:(NSString*)path { - NSLog(@"[DELETE] %@", path); -} - -- (void)webUploader:(GCDWebUploader*)uploader didCreateDirectoryAtPath:(NSString*)path { - NSLog(@"[CREATE] %@", path); -} - -@end diff --git a/tvOS/main.m b/tvOS/ViewController.swift similarity index 51% rename from tvOS/main.m rename to tvOS/ViewController.swift index bd96dd5..21b4c06 100644 --- a/tvOS/main.m +++ b/tvOS/ViewController.swift @@ -1,7 +1,7 @@ /* Copyright (c) 2012-2015, Pierre-Olivier Latour All rights reserved. - + Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright @@ -12,7 +12,7 @@ * The name of Pierre-Olivier Latour may not be used to endorse or promote products derived from this software without specific prior written permission. - + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -25,10 +25,52 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#import "AppDelegate.h" +import UIKit -int main(int argc, char* argv[]) { - @autoreleasepool { - return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); +class ViewController: UIViewController { + @IBOutlet var label: UILabel? + var webServer: GCDWebUploader! + + override func viewWillAppear(_ animated: Bool) { + super.viewWillAppear(animated) + + let documentsPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first! + webServer = GCDWebUploader(uploadDirectory: documentsPath) + webServer.delegate = self + webServer.allowHiddenItems = true + if webServer.start() { + label?.text = "GCDWebServer running locally on port \(webServer.port)" + } else { + label?.text = "GCDWebServer not running!" + } + } + + override func viewDidDisappear(_ animated: Bool) { + super.viewDidDisappear(animated) + + webServer.stop() + webServer = nil + } +} + +extension ViewController: GCDWebUploaderDelegate { + func webUploader(_: GCDWebUploader, didUploadFileAtPath path: String) { + print("[UPLOAD] \(path)") + } + + func webUploader(_: GCDWebUploader, didDownloadFileAtPath path: String) { + print("[DOWNLOAD] \(path)") + } + + func webUploader(_: GCDWebUploader, didMoveItemFromPath fromPath: String, toPath: String) { + print("[MOVE] \(fromPath) -> \(toPath)") + } + + func webUploader(_: GCDWebUploader, didCreateDirectoryAtPath path: String) { + print("[CREATE] \(path)") + } + + func webUploader(_: GCDWebUploader, didDeleteItemAtPath path: String) { + print("[DELETE] \(path)") } }