From e243727049af67a989da8746b60c204bc9fb5c8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dr=2E=20Julian-Steffen=20M=C3=BCller?= Date: Tue, 25 May 2021 14:43:42 +0200 Subject: [PATCH] Added functionality for previews. But previews are still crashing --- Zockerhoehle.xcodeproj/project.pbxproj | 4 + Zockerhoehle/Assets.xcassets/Contents.json | 9 +- .../CoreDataSample.dataset/Contents.json | 13 ++ .../libExp_2021-05-20T16:53:25+0200.json | 1 + Zockerhoehle/CDManager.swift | 115 +++++++++++++----- Zockerhoehle/CDPreview.swift | 35 ++++++ Zockerhoehle/Utils/LibraryImport.swift | 112 +++++++++-------- Zockerhoehle/Views/ConsoleLibraryView.swift | 1 + Zockerhoehle/Views/GameDetailView.swift | 1 - Zockerhoehle/Views/GameSeriesAllView.swift | 22 ++++ Zockerhoehle/Views/Overview.swift | 7 +- 11 files changed, 233 insertions(+), 87 deletions(-) create mode 100644 Zockerhoehle/Assets.xcassets/CoreDataSample.dataset/Contents.json create mode 100644 Zockerhoehle/Assets.xcassets/CoreDataSample.dataset/libExp_2021-05-20T16:53:25+0200.json create mode 100644 Zockerhoehle/CDPreview.swift diff --git a/Zockerhoehle.xcodeproj/project.pbxproj b/Zockerhoehle.xcodeproj/project.pbxproj index 70977ea..e240ff3 100644 --- a/Zockerhoehle.xcodeproj/project.pbxproj +++ b/Zockerhoehle.xcodeproj/project.pbxproj @@ -41,6 +41,7 @@ B9EC098523854C24004BC9AB /* QGrid in Frameworks */ = {isa = PBXBuildFile; productRef = B9EC098423854C24004BC9AB /* QGrid */; }; B9EC0987238555BF004BC9AB /* SettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9EC0986238555BF004BC9AB /* SettingsView.swift */; }; B9ED3DD7265534C000FD2D46 /* test_date_utils.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9ED3DD6265534C000FD2D46 /* test_date_utils.swift */; }; + B9ED3DD9265D1E5600FD2D46 /* CDPreview.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9ED3DD8265D1E5600FD2D46 /* CDPreview.swift */; }; B9F44ABA22F312E600FC6B29 /* ConsoleLibraryView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9F44AB922F312E600FC6B29 /* ConsoleLibraryView.swift */; }; B9F44ABE22F31DEF00FC6B29 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9F44ABD22F31DEF00FC6B29 /* SceneDelegate.swift */; }; /* End PBXBuildFile section */ @@ -108,6 +109,7 @@ B9EC09812383F94B004BC9AB /* LibraryExport.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LibraryExport.swift; sourceTree = ""; }; B9EC0986238555BF004BC9AB /* SettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsView.swift; sourceTree = ""; }; B9ED3DD6265534C000FD2D46 /* test_date_utils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = test_date_utils.swift; sourceTree = ""; }; + B9ED3DD8265D1E5600FD2D46 /* CDPreview.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CDPreview.swift; sourceTree = ""; }; B9F44AB922F312E600FC6B29 /* ConsoleLibraryView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConsoleLibraryView.swift; sourceTree = ""; }; B9F44ABD22F31DEF00FC6B29 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; /* End PBXFileReference section */ @@ -200,6 +202,7 @@ B93C1B9C21496BFD0014FD6E /* AppDelegate.swift */, B9F44ABD22F31DEF00FC6B29 /* SceneDelegate.swift */, B9BCF4C92168ACB600ECBAAC /* LaunchScreen.storyboard */, + B9ED3DD8265D1E5600FD2D46 /* CDPreview.swift */, B98A735F22C1738800FB3410 /* CDManager.swift */, B9BCCEB82653BDEA005F46D6 /* ICloudManager.swift */, B93C1BA321496BFE0014FD6E /* Assets.xcassets */, @@ -395,6 +398,7 @@ B9E2A07E233B6E4F00EAEB14 /* ConsoleAllView.swift in Sources */, B9BCCEB92653BDEA005F46D6 /* ICloudManager.swift in Sources */, B9EC0987238555BF004BC9AB /* SettingsView.swift in Sources */, + B9ED3DD9265D1E5600FD2D46 /* CDPreview.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Zockerhoehle/Assets.xcassets/Contents.json b/Zockerhoehle/Assets.xcassets/Contents.json index da4a164..2aa0709 100644 --- a/Zockerhoehle/Assets.xcassets/Contents.json +++ b/Zockerhoehle/Assets.xcassets/Contents.json @@ -1,6 +1,9 @@ { "info" : { - "version" : 1, - "author" : "xcode" + "author" : "xcode", + "version" : 1 + }, + "properties" : { + "compression-type" : "lossless" } -} \ No newline at end of file +} diff --git a/Zockerhoehle/Assets.xcassets/CoreDataSample.dataset/Contents.json b/Zockerhoehle/Assets.xcassets/CoreDataSample.dataset/Contents.json new file mode 100644 index 0000000..1d97559 --- /dev/null +++ b/Zockerhoehle/Assets.xcassets/CoreDataSample.dataset/Contents.json @@ -0,0 +1,13 @@ +{ + "data" : [ + { + "filename" : "libExp_2021-05-20T16:53:25+0200.json", + "idiom" : "universal", + "universal-type-identifier" : "public.json" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Zockerhoehle/Assets.xcassets/CoreDataSample.dataset/libExp_2021-05-20T16:53:25+0200.json b/Zockerhoehle/Assets.xcassets/CoreDataSample.dataset/libExp_2021-05-20T16:53:25+0200.json new file mode 100644 index 0000000..a5368aa --- /dev/null +++ b/Zockerhoehle/Assets.xcassets/CoreDataSample.dataset/libExp_2021-05-20T16:53:25+0200.json @@ -0,0 +1 @@ +{"games":[{"uuid":"5090F647-B96C-4431-960F-FEA03B6583C5","finishedDate":null,"name":"Cyberpunk","lentTo":"","isFinished":false,"console":"420CAC69-1856-4128-9E5A-63D258F4D0B2","notes":"","publisher":"","isDigital":true,"cover_icloud_path":"games\/xbox_one\/cyberpunk.jpg","inWishlist":false,"createdAt":"2021-05-20T15:42:51+0200","pickupDescription":""},{"uuid":"7FB711B7-8A85-409B-A11F-BA4F572F8D24","finishedDate":null,"name":"1080","lentTo":"","isFinished":false,"console":"46547BAC-1980-4022-93D8-F0F241EE4174","notes":"","publisher":"","isDigital":false,"cover_icloud_path":"games\/n64\/1080.jpg","inWishlist":false,"createdAt":"2021-05-19T13:42:05+0200","pickupDescription":""},{"uuid":"4370F2B3-61D7-44F1-A6F1-BD235A54F6A5","finishedDate":null,"name":"Wayne Gretzky‘s 3D Hockey 98","lentTo":"","isFinished":false,"console":"46547BAC-1980-4022-93D8-F0F241EE4174","notes":"","publisher":"","isDigital":false,"cover_icloud_path":"games\/n64\/wayne_gretzkys_3dhockey_98.jpg","inWishlist":false,"createdAt":"2021-05-19T13:42:05+0200","pickupDescription":""},{"uuid":"CB041D88-EC2F-469E-A9FA-727036176EED","finishedDate":null,"name":"Star Wars: Roque Squadron","lentTo":"","isFinished":false,"console":"46547BAC-1980-4022-93D8-F0F241EE4174","notes":"","publisher":"","isDigital":false,"cover_icloud_path":"games\/n64\/starwars_rogue_squadron.jpg","inWishlist":false,"createdAt":"2021-05-19T13:42:05+0200","pickupDescription":""},{"uuid":"68076ECF-22E6-4F71-B160-103EFEA88234","finishedDate":null,"name":"Resident Evil Outbreak","lentTo":"","isFinished":false,"console":"4C29F7C2-2F42-4479-8D81-D981B87E029B","notes":"","publisher":"","isDigital":false,"cover_icloud_path":"games\/ps2\/resident_evil_outbreak.jpg","inWishlist":false,"createdAt":"2021-05-19T13:42:05+0200","pickupDescription":""},{"uuid":"4E05130C-DFB3-461D-9DDC-ED85AEEA531F","finishedDate":null,"name":"God of War 2","lentTo":"","isFinished":false,"console":"4C29F7C2-2F42-4479-8D81-D981B87E029B","notes":"","publisher":"","isDigital":false,"cover_icloud_path":"games\/ps2\/god_of_war_2.jpg","inWishlist":false,"createdAt":"2021-05-19T13:42:05+0200","pickupDescription":""},{"uuid":"37633F64-1A84-446A-9209-AE02A506CAA3","finishedDate":null,"name":"Gears of War 4","lentTo":"","isFinished":false,"console":"420CAC69-1856-4128-9E5A-63D258F4D0B2","notes":"","publisher":"","isDigital":false,"cover_icloud_path":"games\/xbox_one\/gears_of_war_4.jpg","inWishlist":false,"createdAt":"2021-05-20T15:53:57+0200","pickupDescription":""},{"uuid":"20D48A1A-F190-4D5B-B0BF-F4F34C4F527C","finishedDate":null,"name":"Monkey Island 4 - Escape from Monkey Island","lentTo":"","isFinished":false,"console":"4C29F7C2-2F42-4479-8D81-D981B87E029B","notes":"","publisher":"","isDigital":false,"cover_icloud_path":"games\/ps2\/monkey_island_4.jpg","inWishlist":false,"createdAt":"2021-05-19T13:42:05+0200","pickupDescription":""},{"uuid":"C15A44F6-0B91-47BB-8EC7-46397CF7D9C0","finishedDate":null,"name":"Okami","lentTo":"","isFinished":false,"console":"4C29F7C2-2F42-4479-8D81-D981B87E029B","notes":"","publisher":"","isDigital":false,"cover_icloud_path":"games\/ps2\/okami.jpg","inWishlist":false,"createdAt":"2021-05-19T13:42:05+0200","pickupDescription":""},{"uuid":"DA9C81DF-AE72-4ADD-9AD8-B412E4C54DB6","finishedDate":null,"name":"Resident Evil 2","lentTo":"","isFinished":false,"console":"E56B6CC8-D449-4C79-984C-FE6D9D826A3E","notes":"","publisher":"","isDigital":false,"cover_icloud_path":"games\/ps1\/resident_evil_2.jpg","inWishlist":false,"createdAt":"2021-05-19T13:42:05+0200","pickupDescription":""},{"uuid":"6B089B8E-1F34-4137-98CE-662BEB1636A2","finishedDate":null,"name":"Mario Kart 64","lentTo":"","isFinished":false,"console":"46547BAC-1980-4022-93D8-F0F241EE4174","notes":"","publisher":"","isDigital":false,"cover_icloud_path":"games\/n64\/mario_kart_64.jpg","inWishlist":false,"createdAt":"2021-05-19T13:42:05+0200","pickupDescription":""},{"uuid":"71CEAC01-F873-45FC-8300-C5C0C342470A","finishedDate":null,"name":"Wonder Boy - The Dragon‘s Trap","lentTo":"","isFinished":false,"console":"9FA6F10A-F5CF-4105-83E8-DE666C91D6D6","notes":"","publisher":"","isDigital":false,"cover_icloud_path":"games\/switch\/wonderboy_dragons_trap.jpg","inWishlist":false,"createdAt":"2021-05-19T13:42:05+0200","pickupDescription":""},{"uuid":"5C5DF550-ED25-4047-8FDD-7B14DD1CE495","finishedDate":null,"name":"GTA - Vice City Stories","lentTo":"","isFinished":false,"console":"4C29F7C2-2F42-4479-8D81-D981B87E029B","notes":"","publisher":"","isDigital":false,"cover_icloud_path":"games\/ps2\/gta_vice_city_stories.jpg","inWishlist":false,"createdAt":"2021-05-19T13:42:05+0200","pickupDescription":""},{"uuid":"5B67C345-2664-43B7-AF09-B8387C061457","finishedDate":null,"name":"Super Bomberman R","lentTo":"","isFinished":false,"console":"9FA6F10A-F5CF-4105-83E8-DE666C91D6D6","notes":"","publisher":"","isDigital":false,"cover_icloud_path":"games\/switch\/super_bomberman_r.jpg","inWishlist":false,"createdAt":"2021-05-19T13:42:05+0200","pickupDescription":""},{"uuid":"619435F9-2F4C-4E75-B1B5-8EFB60A6B7C5","finishedDate":null,"name":"Gears of War 5","lentTo":"","isFinished":false,"console":"420CAC69-1856-4128-9E5A-63D258F4D0B2","notes":"","publisher":"","isDigital":false,"cover_icloud_path":"games\/xbox_one\/gears5.jpg","inWishlist":false,"createdAt":"2021-05-20T15:54:02+0200","pickupDescription":""},{"uuid":"FDD71E4C-5194-4934-B1D5-C8503DEC75F7","finishedDate":null,"name":"Monster Boy and the Cursed Kingdom","lentTo":"","isFinished":false,"console":"9FA6F10A-F5CF-4105-83E8-DE666C91D6D6","notes":"","publisher":"","isDigital":false,"cover_icloud_path":"games\/switch\/monsterboy_and_the_cursed_kingdom.jpg","inWishlist":false,"createdAt":"2021-05-19T13:42:05+0200","pickupDescription":""},{"uuid":"7F1DD3EA-73D8-41CC-AF4C-9AE35048F000","finishedDate":null,"name":"God of War","lentTo":"","isFinished":false,"console":"4C29F7C2-2F42-4479-8D81-D981B87E029B","notes":"","publisher":"","isDigital":false,"cover_icloud_path":"games\/ps2\/god_of_war.jpg","inWishlist":false,"createdAt":"2021-05-19T13:42:05+0200","pickupDescription":""},{"uuid":"46197A88-6719-4D11-9828-F063BEB4854C","finishedDate":null,"name":"Thimbleweed Park","lentTo":"","isFinished":false,"console":"9FA6F10A-F5CF-4105-83E8-DE666C91D6D6","notes":"","publisher":"","isDigital":false,"cover_icloud_path":"games\/switch\/thimbleweed_park.jpg","inWishlist":false,"createdAt":"2021-05-19T13:42:05+0200","pickupDescription":""},{"uuid":"C6FB9066-685B-4720-8798-BFA7B364E350","finishedDate":null,"name":"Donkey Kong 64","lentTo":"","isFinished":false,"console":"46547BAC-1980-4022-93D8-F0F241EE4174","notes":"","publisher":"","isDigital":false,"cover_icloud_path":"games\/n64\/donkeykong64.jpg","inWishlist":false,"createdAt":"2021-05-19T13:42:05+0200","pickupDescription":""},{"uuid":"5F89FC5A-128C-45A5-8B93-8A90738C649D","finishedDate":null,"name":"Turok","lentTo":"","isFinished":false,"console":"46547BAC-1980-4022-93D8-F0F241EE4174","notes":"","publisher":"","isDigital":false,"cover_icloud_path":"games\/n64\/turok.jpg","inWishlist":false,"createdAt":"2021-05-19T13:42:05+0200","pickupDescription":""},{"uuid":"43D2F3D9-3FD9-4888-AC4E-F9194EDC6516","finishedDate":621178140,"name":"Final Fantasy 7","lentTo":"","isFinished":true,"console":"E56B6CC8-D449-4C79-984C-FE6D9D826A3E","notes":"","publisher":"","isDigital":false,"cover_icloud_path":"games\/ps1\/finalfantasy7.jpg","inWishlist":false,"createdAt":"2020-06-02T13:42:00+0200","pickupDescription":"Köln Urlaub"},{"uuid":"A9408A2F-B83F-4204-8503-2BBA8140BFA6","finishedDate":null,"name":"Stars Wars - Shadows of the Empire","lentTo":"","isFinished":false,"console":"46547BAC-1980-4022-93D8-F0F241EE4174","notes":"","publisher":"","isDigital":false,"cover_icloud_path":"games\/n64\/starwars_shadow_of_the_empire.jpg","inWishlist":false,"createdAt":"2021-05-19T13:42:05+0200","pickupDescription":""},{"uuid":"D8852091-D8E2-4788-BD98-E2212A0DC570","finishedDate":null,"name":"Wave Race 64","lentTo":"","isFinished":false,"console":"46547BAC-1980-4022-93D8-F0F241EE4174","notes":"","publisher":"","isDigital":false,"cover_icloud_path":"games\/n64\/waverace64.jpg","inWishlist":false,"createdAt":"2021-05-19T13:42:05+0200","pickupDescription":""},{"uuid":"CA5C5C71-5475-46AF-AF38-4D4AE1FF091C","finishedDate":null,"name":"Collection of Mana","lentTo":"","isFinished":false,"console":"9FA6F10A-F5CF-4105-83E8-DE666C91D6D6","notes":"","publisher":"","isDigital":false,"cover_icloud_path":"games\/switch\/collection_of_mana.jpg","inWishlist":false,"createdAt":"2021-05-19T13:42:05+0200","pickupDescription":""},{"uuid":"20C300B7-576E-4A81-B10D-8F2639EE6250","finishedDate":null,"name":"Mario Kart 8 Deluxe","lentTo":"","isFinished":false,"console":"9FA6F10A-F5CF-4105-83E8-DE666C91D6D6","notes":"","publisher":"","isDigital":false,"cover_icloud_path":"games\/switch\/mario_kart_8_deluxe.jpg","inWishlist":false,"createdAt":"2021-05-19T13:42:05+0200","pickupDescription":""},{"uuid":"42C954F2-8E52-4F7A-B539-9EBE2487E990","finishedDate":null,"name":"Banjo-Kazooie","lentTo":"","isFinished":false,"console":"46547BAC-1980-4022-93D8-F0F241EE4174","notes":"","publisher":"","isDigital":false,"cover_icloud_path":"games\/n64\/banjo_kazooie.jpg","inWishlist":false,"createdAt":"2021-05-19T13:42:05+0200","pickupDescription":""},{"uuid":"10711B93-DB75-47AC-A4E4-5A93F7ACFFCE","finishedDate":null,"name":"International Superstar Soccer 64","lentTo":"","isFinished":false,"console":"46547BAC-1980-4022-93D8-F0F241EE4174","notes":"","publisher":"","isDigital":false,"cover_icloud_path":"games\/n64\/international_superstar_soccer_64.jpg","inWishlist":false,"createdAt":"2021-05-19T13:42:05+0200","pickupDescription":""},{"uuid":"4601A22E-3022-4F2C-964F-B1B727B862F2","finishedDate":null,"name":"ICO","lentTo":"","isFinished":false,"console":"4C29F7C2-2F42-4479-8D81-D981B87E029B","notes":"","publisher":"","isDigital":false,"cover_icloud_path":"games\/ps2\/ico.jpg","inWishlist":false,"createdAt":"2021-05-19T13:42:05+0200","pickupDescription":""},{"uuid":"EF86ECAA-38F1-40B6-9CB5-06B6D93351B0","finishedDate":null,"name":"Mario 64 JPN","lentTo":"","isFinished":false,"console":"46547BAC-1980-4022-93D8-F0F241EE4174","notes":"","publisher":"","isDigital":false,"cover_icloud_path":"","inWishlist":false,"createdAt":"2020-06-02T14:21:00+0200","pickupDescription":"Köln Urlaub"},{"uuid":"EC2DA0AE-EDA9-499F-B379-813B56163252","finishedDate":null,"name":"South Park","lentTo":"","isFinished":false,"console":"46547BAC-1980-4022-93D8-F0F241EE4174","notes":"","publisher":"","isDigital":false,"cover_icloud_path":"games\/n64\/south_park.jpg","inWishlist":false,"createdAt":"2021-05-19T13:42:05+0200","pickupDescription":""},{"uuid":"55FB0658-3176-4510-9FEC-AB89A62D3D91","finishedDate":null,"name":"Zelda: Breath of the Wild","lentTo":"","isFinished":false,"console":"9FA6F10A-F5CF-4105-83E8-DE666C91D6D6","notes":"","publisher":"","isDigital":false,"cover_icloud_path":"games\/switch\/zelda_breath_of_the_wild.jpg","inWishlist":false,"createdAt":"2021-05-12T13:42:00+0200","pickupDescription":""},{"uuid":"A6ABC431-36F6-4FB9-AC85-700E71C02D5F","finishedDate":null,"name":"Shadow of the Collossus","lentTo":"","isFinished":false,"console":"4C29F7C2-2F42-4479-8D81-D981B87E029B","notes":"","publisher":"","isDigital":false,"cover_icloud_path":"games\/ps2\/shadow_of_the_collossus.jpg","inWishlist":false,"createdAt":"2021-05-19T13:42:05+0200","pickupDescription":""},{"uuid":"923B8C65-4DF8-49B4-9672-F20982749CCB","finishedDate":null,"name":"Mario 64","lentTo":"","isFinished":false,"console":"46547BAC-1980-4022-93D8-F0F241EE4174","notes":"","publisher":"","isDigital":false,"cover_icloud_path":"games\/n64\/supermario64.jpg","inWishlist":false,"createdAt":"2021-05-19T13:42:05+0200","pickupDescription":""},{"uuid":"37F3C5A6-9FEA-4ADE-AC81-812BC775B58E","finishedDate":null,"name":"Zelda - Ocarina of Time","lentTo":"","isFinished":false,"console":"46547BAC-1980-4022-93D8-F0F241EE4174","notes":"","publisher":"","isDigital":false,"cover_icloud_path":"games\/n64\/ocarina_of_time.jpg","inWishlist":false,"createdAt":"2021-05-19T13:42:05+0200","pickupDescription":""},{"uuid":"6FC6C0EA-C6D2-40EA-A7EA-D11F4E403F31","finishedDate":null,"name":"Resident Evil 3","lentTo":"","isFinished":false,"console":"E56B6CC8-D449-4C79-984C-FE6D9D826A3E","notes":"","publisher":"","isDigital":false,"cover_icloud_path":"games\/ps1\/resident_evil_3.jpg","inWishlist":false,"createdAt":"2021-05-19T13:42:05+0200","pickupDescription":""},{"uuid":"39E8AAB8-06D0-4180-AA25-9D8D34C8F5B6","finishedDate":null,"name":"Zelda: Links Awakening","lentTo":"","isFinished":false,"console":"9FA6F10A-F5CF-4105-83E8-DE666C91D6D6","notes":"","publisher":"","isDigital":false,"cover_icloud_path":"games\/switch\/links_awakening.jpg","inWishlist":false,"createdAt":"2021-05-19T13:42:05+0200","pickupDescription":""},{"uuid":"8C6E46A1-3060-4946-8FB5-F88831F663A7","finishedDate":null,"name":"Black","lentTo":"","isFinished":false,"console":"4C29F7C2-2F42-4479-8D81-D981B87E029B","notes":"","publisher":"","isDigital":false,"cover_icloud_path":"games\/ps2\/black.jpg","inWishlist":false,"createdAt":"2021-05-19T13:42:05+0200","pickupDescription":""}],"consoles":[{"manufacturer":"Sony","shortName":"PS5","uuid":"1725A045-82D2-44E5-8A8B-E647073B858D","releaseDate":626884620,"accessories":[],"games":[],"logo_icloud_path":"consoles\/ps5.png","name":"Playstation 5"},{"manufacturer":"Nintendo","shortName":"Switch","uuid":"9FA6F10A-F5CF-4105-83E8-DE666C91D6D6","releaseDate":510224820,"accessories":[],"games":["55FB0658-3176-4510-9FEC-AB89A62D3D91","20C300B7-576E-4A81-B10D-8F2639EE6250","71CEAC01-F873-45FC-8300-C5C0C342470A","5B67C345-2664-43B7-AF09-B8387C061457","CA5C5C71-5475-46AF-AF38-4D4AE1FF091C","39E8AAB8-06D0-4180-AA25-9D8D34C8F5B6","46197A88-6719-4D11-9828-F063BEB4854C","FDD71E4C-5194-4934-B1D5-C8503DEC75F7"],"logo_icloud_path":"consoles\/nintendo_switch.png","name":"Nintendo Switch"},{"manufacturer":"Microsoft","shortName":"Xbox One","uuid":"420CAC69-1856-4128-9E5A-63D258F4D0B2","releaseDate":406824060,"accessories":[],"games":["5090F647-B96C-4431-960F-FEA03B6583C5","619435F9-2F4C-4E75-B1B5-8EFB60A6B7C5","37633F64-1A84-446A-9209-AE02A506CAA3"],"logo_icloud_path":"consoles\/xbox_one.jpg","name":"Xbox One"},{"manufacturer":"Sony","shortName":"PS 2","uuid":"4C29F7C2-2F42-4479-8D81-D981B87E029B","releaseDate":-26126580,"accessories":[],"games":["4601A22E-3022-4F2C-964F-B1B727B862F2","20D48A1A-F190-4D5B-B0BF-F4F34C4F527C","A6ABC431-36F6-4FB9-AC85-700E71C02D5F","68076ECF-22E6-4F71-B160-103EFEA88234","4E05130C-DFB3-461D-9DDC-ED85AEEA531F","8C6E46A1-3060-4946-8FB5-F88831F663A7","C15A44F6-0B91-47BB-8EC7-46397CF7D9C0","7F1DD3EA-73D8-41CC-AF4C-9AE35048F000","5C5DF550-ED25-4047-8FDD-7B14DD1CE495"],"logo_icloud_path":"consoles\/ps2.png","name":"Playstation 2"},{"manufacturer":"Nintendo","shortName":"N64","uuid":"46547BAC-1980-4022-93D8-F0F241EE4174","releaseDate":-142770240,"accessories":[],"games":["37F3C5A6-9FEA-4ADE-AC81-812BC775B58E","6B089B8E-1F34-4137-98CE-662BEB1636A2","D8852091-D8E2-4788-BD98-E2212A0DC570","923B8C65-4DF8-49B4-9672-F20982749CCB","EC2DA0AE-EDA9-499F-B379-813B56163252","4370F2B3-61D7-44F1-A6F1-BD235A54F6A5","5F89FC5A-128C-45A5-8B93-8A90738C649D","EF86ECAA-38F1-40B6-9CB5-06B6D93351B0","CB041D88-EC2F-469E-A9FA-727036176EED","42C954F2-8E52-4F7A-B539-9EBE2487E990","C6FB9066-685B-4720-8798-BFA7B364E350","A9408A2F-B83F-4204-8503-2BBA8140BFA6","7FB711B7-8A85-409B-A11F-BA4F572F8D24","10711B93-DB75-47AC-A4E4-5A93F7ACFFCE"],"logo_icloud_path":"consoles\/n64.png","name":"Nintendo 64"},{"manufacturer":"Sony","shortName":"PS1","uuid":"E56B6CC8-D449-4C79-984C-FE6D9D826A3E","releaseDate":-165912060,"accessories":[],"games":["6FC6C0EA-C6D2-40EA-A7EA-D11F4E403F31","DA9C81DF-AE72-4ADD-9AD8-B412E4C54DB6","43D2F3D9-3FD9-4888-AC4E-F9194EDC6516"],"logo_icloud_path":"","name":"Playstation 1"}],"accessories":[],"gameSeries":[{"games":[],"name":"Star Wars","cover_icloud_path":"game_series\/star_wars.jpg","uuid":"88BF78C1-724C-4DCD-9B66-12ACBF5E5198"},{"games":[],"name":"God of War","cover_icloud_path":"game_series\/god_of_war.jpg","uuid":"C6D2371C-F503-4D1A-90F6-39B216A68A35"},{"games":[],"name":"Legend of Zelda","cover_icloud_path":"game_series\/zelda.png","uuid":"B780AED9-B79D-4C6D-A9E9-DEFC916B6ECE"},{"games":["43D2F3D9-3FD9-4888-AC4E-F9194EDC6516"],"name":"Final Fantasy","cover_icloud_path":"game_series\/final_fantasy.png","uuid":"BEDE406D-E098-4C0E-9031-3D99B3C23432"},{"games":[],"name":"Super Mario","cover_icloud_path":"game_series\/super_mario.png","uuid":"A1D483CF-1DB7-41BF-BAA2-6783BFEA3C2E"},{"games":[],"name":"Resident Evil","cover_icloud_path":"game_series\/resident_evil.png","uuid":"177E067C-FBFA-419D-9E35-11EDE91D520D"}]} \ No newline at end of file diff --git a/Zockerhoehle/CDManager.swift b/Zockerhoehle/CDManager.swift index 22862fd..b5cf97f 100644 --- a/Zockerhoehle/CDManager.swift +++ b/Zockerhoehle/CDManager.swift @@ -13,45 +13,100 @@ class CDManager { static let shared : CDManager = CDManager(); - private init() { - + static var preview: CDManager = { + let controller = CDManager(inMemory: true) + + //INIT Core Data + + return controller + }() + + let persistentContainer : NSPersistentCloudKitContainer + + private init(inMemory: Bool = false) { + // If you didn't name your model Main you'll need + // to change this name below. + persistentContainer = NSPersistentCloudKitContainer(name: "Zockerhoehle") + + if inMemory { + persistentContainer.persistentStoreDescriptions.first?.url = URL(fileURLWithPath: "/dev/null") + } + + persistentContainer.loadPersistentStores { description, error in + if let error = error { + fatalError("Error: \(error.localizedDescription)") + } + } } // MARK: - Core Data stack - lazy var persistentContainer: NSPersistentContainer = { - /* - The persistent container for the application. This implementation - creates and returns a container, having loaded the store for the - application to it. This property is optional since there are legitimate - error conditions that could cause the creation of the store to fail. - */ - let container = NSPersistentCloudKitContainer(name: "Zockerhoehle") - - container.loadPersistentStores(completionHandler: { (storeDescription, error) in - if let error = error as NSError? { - // Replace this implementation with code to handle the error appropriately. - // fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. - - /* - Typical reasons for an error here include: - * The parent directory does not exist, cannot be created, or disallows writing. - * The persistent store is not accessible, due to permissions or data protection when the device is locked. - * The device is out of space. - * The store could not be migrated to the current model version. - Check the error message to determine what the actual problem was. - */ - fatalError("Unresolved error \(error), \(error.userInfo)") - } - }) - container.viewContext.automaticallyMergesChangesFromParent = true - return container - }() +// lazy var persistentContainer: NSPersistentContainer = { +// /* +// The persistent container for the application. This implementation +// creates and returns a container, having loaded the store for the +// application to it. This property is optional since there are legitimate +// error conditions that could cause the creation of the store to fail. +// */ +// let container = NSPersistentCloudKitContainer(name: "Zockerhoehle") +// +// container.loadPersistentStores(completionHandler: { (storeDescription, error) in +// if let error = error as NSError? { +// // Replace this implementation with code to handle the error appropriately. +// // fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. +// +// /* +// Typical reasons for an error here include: +// * The parent directory does not exist, cannot be created, or disallows writing. +// * The persistent store is not accessible, due to permissions or data protection when the device is locked. +// * The device is out of space. +// * The store could not be migrated to the current model version. +// Check the error message to determine what the actual problem was. +// */ +// fatalError("Unresolved error \(error), \(error.userInfo)") +// } +// }) +// container.viewContext.automaticallyMergesChangesFromParent = true +// return container +// }() +// +// lazy var persistentContainerPreview: NSPersistentContainer = { +// /* +// The persistent container for the application. This implementation +// creates and returns a container, having loaded the store for the +// application to it. This property is optional since there are legitimate +// error conditions that could cause the creation of the store to fail. +// */ +// let container = NSPersistentContainer(name: "Zockerhoehle") +// +// container.loadPersistentStores(completionHandler: { (storeDescription, error) in +// if let error = error as NSError? { +// // Replace this implementation with code to handle the error appropriately. +// // fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. +// +// /* +// Typical reasons for an error here include: +// * The parent directory does not exist, cannot be created, or disallows writing. +// * The persistent store is not accessible, due to permissions or data protection when the device is locked. +// * The device is out of space. +// * The store could not be migrated to the current model version. +// Check the error message to determine what the actual problem was. +// */ +// fatalError("Unresolved error \(error), \(error.userInfo)") +// } +// }) +// +// container.viewContext.automaticallyMergesChangesFromParent = true +// return container +// }() lazy var viewContext : NSManagedObjectContext = { self.persistentContainer.viewContext }() + lazy var viewContextPreview : NSManagedObjectContext = { + self.persistentContainer.viewContext + }() // MARK: - Core Data Saving support func saveContext () { diff --git a/Zockerhoehle/CDPreview.swift b/Zockerhoehle/CDPreview.swift new file mode 100644 index 0000000..5bd3395 --- /dev/null +++ b/Zockerhoehle/CDPreview.swift @@ -0,0 +1,35 @@ +// +// CDPreview.swift +// Zockerhoehle +// +// Created by Julian-Steffen Müller on 25.05.21. +// Copyright © 2021 Julian-Steffen Müller. All rights reserved. +// + +import Foundation +import CoreData +import UIKit + +struct CDPreview { + static let shared : CDPreview = CDPreview() + + private init() { + let asset_core_data = NSDataAsset(name: "CoreDataSample", bundle: Bundle.main) + + guard let data = asset_core_data?.data else { return } + + LibraryImport(context: CDManager.preview.viewContextPreview).importLIB(data: data) + } + + func consoles() -> [Console] { + let consolesFR = NSFetchRequest(entityName: "Console") + do { + let consoles : [Console] = try CDManager.preview.viewContextPreview.fetch(consolesFR) + + return consoles + }catch { + return [] + } + } + +} diff --git a/Zockerhoehle/Utils/LibraryImport.swift b/Zockerhoehle/Utils/LibraryImport.swift index 9f16d32..8718695 100644 --- a/Zockerhoehle/Utils/LibraryImport.swift +++ b/Zockerhoehle/Utils/LibraryImport.swift @@ -13,6 +13,12 @@ import CoreData // MARK: - Library Import class LibraryImport { + let CDContext : NSManagedObjectContext + + init(context CDContext: NSManagedObjectContext = CDManager.shared.viewContext) { + self.CDContext = CDContext + } + static func backupName(from filename : String) -> String? { if filename.hasPrefix("libExp_") && filename.hasSuffix(".json") { var backupName = filename @@ -48,8 +54,8 @@ class LibraryImport { } private func resetDatabase() { - CDManager.shared.viewContext.reset() - CDManager.shared.viewContext.performAndWait { + self.CDContext.reset() + self.CDContext.performAndWait { let deleteRequests = [NSBatchDeleteRequest(fetchRequest: Game.fetchRequest()), NSBatchDeleteRequest(fetchRequest: Accessory.fetchRequest()), @@ -59,7 +65,7 @@ class LibraryImport { let storeCoordinator = CDManager.shared.persistentContainer.persistentStoreCoordinator do { for deleteRequest in deleteRequests { - try storeCoordinator.execute(deleteRequest, with: CDManager.shared.viewContext) + try storeCoordinator.execute(deleteRequest, with: CDContext) } }catch let error { print(error) @@ -69,7 +75,7 @@ class LibraryImport { } private func makeCDGame(from game: BHLGame, _ gameDict: inout [UUID : Game], _ cdConsole: Console) { - let cdGame = Game(context: CDManager.shared.viewContext) + let cdGame = Game(context: self.CDContext) gameDict[game.uuid] = cdGame cdGame.name = game.name ?? "n/a" cdGame.uuid = game.uuid @@ -93,7 +99,7 @@ class LibraryImport { } private func makeCDAccessory(from accessory: BHLAccessory, _ accessoryDict: inout [UUID : Accessory], _ cdConsole: Console) { - let cdAccessory = Accessory(context: CDManager.shared.viewContext) + let cdAccessory = Accessory(context: self.CDContext) accessoryDict[accessory.uuid] = cdAccessory cdAccessory.name = accessory.name cdAccessory.uuid = accessory.uuid @@ -107,7 +113,7 @@ class LibraryImport { } private func makeCDConsole(from console : BHLConsole) -> Console { - let cdConsole = Console(context: CDManager.shared.viewContext) + let cdConsole = Console(context: self.CDContext) cdConsole.name = console.name ?? "n/a" cdConsole.uuid = console.uuid cdConsole.manufacturer = console.manufacturer @@ -119,7 +125,7 @@ class LibraryImport { } private func makeCDGameSeries(from gameSeries: BHLGameSeries, _ gameDict: inout [UUID : Game]) { - let cdGameSeries = GameSeries(context: CDManager.shared.viewContext) + let cdGameSeries = GameSeries(context: self.CDContext) cdGameSeries.name = gameSeries.name cdGameSeries.cover_icloud_path = gameSeries.cover_icloud_path @@ -132,51 +138,59 @@ class LibraryImport { } func importLIB(from filename: String) { - do { - guard let file = ICloudManager.backup_folder?.appendingPathComponent(filename) else { - print("LibraryImport:importLIB Could not get icloud backup folder") - return + guard let file = ICloudManager.backup_folder?.appendingPathComponent(filename) else { + print("LibraryImport:importLIB Could not get icloud backup folder") + return + } + + if file.isFileURL { + do { + let data = try Data(contentsOf: file) + importLIB(data: data) + }catch let error { + print("LibraryImport::importLIB::String - Cannot create data from file '\(error)'") } - - if file.isFileURL { - let library = try JSONDecoder().decode(BHLibrary.self, from: Data(contentsOf: file)) - resetDatabase() - - var gameDict = [UUID:Game]() - var accessoryDict = [UUID:Accessory]() - - for console in library.consoles { - let cdConsole = makeCDConsole(from: console) - - print("CONSOLE: \(cdConsole.name ?? "n/a") with \(console.games.count) games") - for uuid in console.games { - - if let game = library.games.first(where: {$0.uuid == uuid}) { - makeCDGame(from: game, &gameDict, cdConsole) - }else{ - print("LibraryImport::importLIB - Game with UUID '\(uuid)' not found") - } - } - - for uuid in console.accessories { - if let accessory = library.accessories.first(where: {$0.uuid == uuid}) { - makeCDAccessory(from: accessory, &accessoryDict, cdConsole) - }else{ - print("LibraryImport::importLIB - Accessory with UUID '\(uuid)' not found") - } - } - } - - for gameSeries in library.gameSeries { - makeCDGameSeries(from: gameSeries, &gameDict) - } - } - - }catch let error { - print(error) - print("LibraryImport::importLIB - Error while importing!") } } + + func importLIB(data : Data) { + do { + let library = try JSONDecoder().decode(BHLibrary.self, from: data) + resetDatabase() + + var gameDict = [UUID:Game]() + var accessoryDict = [UUID:Accessory]() + + for console in library.consoles { + let cdConsole = makeCDConsole(from: console) + + print("CONSOLE: \(cdConsole.name ?? "n/a") with \(console.games.count) games") + for uuid in console.games { + + if let game = library.games.first(where: {$0.uuid == uuid}) { + makeCDGame(from: game, &gameDict, cdConsole) + }else{ + print("LibraryImport::importLIB - Game with UUID '\(uuid)' not found") + } + } + + for uuid in console.accessories { + if let accessory = library.accessories.first(where: {$0.uuid == uuid}) { + makeCDAccessory(from: accessory, &accessoryDict, cdConsole) + }else{ + print("LibraryImport::importLIB - Accessory with UUID '\(uuid)' not found") + } + } + } + + for gameSeries in library.gameSeries { + makeCDGameSeries(from: gameSeries, &gameDict) + } + }catch let error { + print("LibraryImport::importLIB::DATA - Error while importing! '\(error)'") + } + } + } // MARK: - BHLLibrary Classes diff --git a/Zockerhoehle/Views/ConsoleLibraryView.swift b/Zockerhoehle/Views/ConsoleLibraryView.swift index 7d45a26..f7e1663 100644 --- a/Zockerhoehle/Views/ConsoleLibraryView.swift +++ b/Zockerhoehle/Views/ConsoleLibraryView.swift @@ -7,6 +7,7 @@ // import SwiftUI +import CoreData struct ModalAddToConsoleLibrary : View { @Environment(\.presentationMode) var presentationMode: Binding diff --git a/Zockerhoehle/Views/GameDetailView.swift b/Zockerhoehle/Views/GameDetailView.swift index 7782cc0..82e7c95 100644 --- a/Zockerhoehle/Views/GameDetailView.swift +++ b/Zockerhoehle/Views/GameDetailView.swift @@ -203,5 +203,4 @@ struct GameDetailView : View { }), secondaryButton: Alert.Button.cancel(Text("Lieber doch nicht"))) }) } - } diff --git a/Zockerhoehle/Views/GameSeriesAllView.swift b/Zockerhoehle/Views/GameSeriesAllView.swift index 12d8e27..6352bac 100644 --- a/Zockerhoehle/Views/GameSeriesAllView.swift +++ b/Zockerhoehle/Views/GameSeriesAllView.swift @@ -65,6 +65,8 @@ struct ModalAddGameSeries : View { } struct GameSeriesAllView: View { + @Environment(\.managedObjectContext) private var viewContext + @FetchRequest(entity: GameSeries.entity(), sortDescriptors: [NSSortDescriptor(key: "name", ascending: true)]) var gameSeries: FetchedResults @@ -104,3 +106,23 @@ struct GameSeriesAllView: View { } } } + +struct GameSeriesAllView_Preview : PreviewProvider { + static var previews: some View { + //let consoles : [Console] = CDPreview.shared.consoles() + + + //if consoles.count > 0 { + //let console : Console = consoles[0] + //let v = GameSeriesAllView()//.environment(\.managedObjectContext, CDManager.preview.viewContext) + + return Text("muzh") + //}else{ + // return Text("kuH") + //} + + //return Text("bla") + //let preview_viww = ConsoleLibraryView(console: console).environment(\.managedObjectContext, CDManager.shared.viewContextPreview) + } +} + diff --git a/Zockerhoehle/Views/Overview.swift b/Zockerhoehle/Views/Overview.swift index 1d525bd..52c03b7 100644 --- a/Zockerhoehle/Views/Overview.swift +++ b/Zockerhoehle/Views/Overview.swift @@ -104,7 +104,6 @@ struct Overview: View { var GamesOverview : some View { VStack(alignment: .leading) { - //TODO OverviewHeader(title: "Zuletzt gehortete Spiele", destination: GamePickupsView()) if games.count == 0 { @@ -205,9 +204,9 @@ struct Overview: View { NavigationView { ScrollView(.vertical, showsIndicators: true) { VStack { - //featured - Text("TODO FEATURED") - Divider() + ////featured + //Text("TODO FEATURED") + //Divider() ConsolesOverview Divider() GamesOverview