From 04fa32029083af421ac9d9f3beaf128843239cda Mon Sep 17 00:00:00 2001 From: Jackson Wood Date: Fri, 16 Apr 2021 16:34:23 +1000 Subject: [PATCH 01/38] Updated version --- Runtime/ModIOVersion.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Runtime/ModIOVersion.cs b/Runtime/ModIOVersion.cs index be7f421a..3f0cbfe3 100644 --- a/Runtime/ModIOVersion.cs +++ b/Runtime/ModIOVersion.cs @@ -6,7 +6,7 @@ public struct ModIOVersion : System.IComparable { // ---------[ Singleton ]--------- /// Singleton instance for current version. - public static readonly ModIOVersion Current = new ModIOVersion(2, 3, 1); + public static readonly ModIOVersion Current = new ModIOVersion(2, 3, 2); // ---------[ Fields ]--------- /// Major version number. From 2ecf548df7da7d1b3a7437738fda22e403d45a75 Mon Sep 17 00:00:00 2001 From: Jackson Wood Date: Fri, 16 Apr 2021 16:35:30 +1000 Subject: [PATCH 02/38] Implemented IUserData to allow for different user-data identifiers --- Runtime/DataStorage/IUserDataIO.cs | 7 ++++ Runtime/DataStorage/UserDataStorage.cs | 48 ++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/Runtime/DataStorage/IUserDataIO.cs b/Runtime/DataStorage/IUserDataIO.cs index bad679c3..e4118cb3 100644 --- a/Runtime/DataStorage/IUserDataIO.cs +++ b/Runtime/DataStorage/IUserDataIO.cs @@ -33,4 +33,11 @@ public interface IUserDataIO /// Clears all of the active user's data. void ClearActiveUserData(ClearActiveUserDataCallback callback); } + + /// Defines the functions necessary for the platform user data IO. + public interface IUserDataIO : IUserDataIO + { + /// Initializes the storage system for the given user. + void SetActiveUser(T platformUserId, SetActiveUserCallback callback); + } } diff --git a/Runtime/DataStorage/UserDataStorage.cs b/Runtime/DataStorage/UserDataStorage.cs index 73d635b2..4865f3b4 100644 --- a/Runtime/DataStorage/UserDataStorage.cs +++ b/Runtime/DataStorage/UserDataStorage.cs @@ -98,6 +98,54 @@ public static void SetActiveUser(int platformUserId, SetActiveUserCallback }); } + /// Initializes the data storage functionality for a given user. + public static void SetActiveUser(T platformUserHandle, SetActiveUserCallback callback) + { + if(UserDataStorage.PLATFORM_IO is IUserDataIO) + { + ((IUserDataIO)UserDataStorage.PLATFORM_IO).SetActiveUser(platformUserHandle, + (id, success) => + { + if(success) + { + LocalUser.Load( + () => + { + if(callback != null) + { + callback.Invoke(id, success); + } + }); + } + else + { + LocalUser.instance = new LocalUser(); + + Debug.Log("[mod.io] Failed to set active user. LocalUser cleared."); + + if(callback != null) + { + callback.Invoke(id, success); + } + } + }); + } + else + { + Debug.LogWarning("[mod.io] Attempt to call SetActiveUser with a type of: " + + typeof(T).ToString() + + "\nThis type of user handle is unsupported by the assigned IUserDataIO implementation: " + + (UserDataStorage.PLATFORM_IO == null + ? "NULL" + : UserDataStorage.PLATFORM_IO.GetType().ToString())); + + if(callback != null) + { + callback.Invoke(platformUserHandle, false); + } + } + } + // ---------[ Directories ]--------- /// The directory for the active user's data. public static string USER_DIRECTORY From 076f15398483e415be0f75ed73ad40dfd439c08e Mon Sep 17 00:00:00 2001 From: Jackson Wood Date: Fri, 16 Apr 2021 16:54:07 +1000 Subject: [PATCH 03/38] Removed explicit string/int implementations in IUserDataIO --- Runtime/DataStorage/IUserDataIO.cs | 6 -- .../Implementations/SystemIOWrapper.cs | 2 +- Runtime/DataStorage/UserDataStorage.cs | 62 ------------------- 3 files changed, 1 insertion(+), 69 deletions(-) diff --git a/Runtime/DataStorage/IUserDataIO.cs b/Runtime/DataStorage/IUserDataIO.cs index e4118cb3..21362720 100644 --- a/Runtime/DataStorage/IUserDataIO.cs +++ b/Runtime/DataStorage/IUserDataIO.cs @@ -13,12 +13,6 @@ public interface IUserDataIO /// Initializes the storage system for the defaul user. void InitializeForDefaultUser(System.Action callback); - /// Initializes the storage system for the given user. - void SetActiveUser(string platformUserId, SetActiveUserCallback callback); - - /// Initializes the storage system for the given user. - void SetActiveUser(int platformUserId, SetActiveUserCallback callback); - // --- File I/O --- /// Reads a file. void ReadFile(string pathRelative, ReadFileCallback callback); diff --git a/Runtime/DataStorage/Implementations/SystemIOWrapper.cs b/Runtime/DataStorage/Implementations/SystemIOWrapper.cs index 45b95604..9f05b1fe 100644 --- a/Runtime/DataStorage/Implementations/SystemIOWrapper.cs +++ b/Runtime/DataStorage/Implementations/SystemIOWrapper.cs @@ -7,7 +7,7 @@ namespace ModIO { /// Wraps the System.IO functionality in an IPlatformIO class. - public class SystemIOWrapper : IPlatformIO, IUserDataIO + public class SystemIOWrapper : IPlatformIO, IUserDataIO, IUserDataIO, IUserDataIO { // ---------[ Initialization ]--------- public SystemIOWrapper() : this(PluginSettings.data.installationDirectory, diff --git a/Runtime/DataStorage/UserDataStorage.cs b/Runtime/DataStorage/UserDataStorage.cs index 4865f3b4..b5d7143b 100644 --- a/Runtime/DataStorage/UserDataStorage.cs +++ b/Runtime/DataStorage/UserDataStorage.cs @@ -36,68 +36,6 @@ static UserDataStorage() }); } - /// Initializes the data storage functionality for a given user. - public static void SetActiveUser(string platformUserId, SetActiveUserCallback callback) - { - UserDataStorage.PLATFORM_IO.SetActiveUser(platformUserId, - (id, success) => - { - if(success) - { - LocalUser.Load( - () => - { - if(callback != null) - { - callback.Invoke(id, success); - } - }); - } - else - { - LocalUser.instance = new LocalUser(); - - Debug.Log("[mod.io] Failed to set active user. LocalUser cleared."); - - if(callback != null) - { - callback.Invoke(id, success); - } - } - }); - } - - /// Initializes the data storage functionality for a given user. - public static void SetActiveUser(int platformUserId, SetActiveUserCallback callback) - { - UserDataStorage.PLATFORM_IO.SetActiveUser(platformUserId, - (id, success) => - { - if(success) - { - LocalUser.Load( - () => - { - if(callback != null) - { - callback.Invoke(id, success); - } - }); - } - else - { - LocalUser.instance = new LocalUser(); - - Debug.Log("[mod.io] Failed to set active user. LocalUser cleared."); - - if(callback != null) - { - callback.Invoke(id, success); - } - } - }); - } - /// Initializes the data storage functionality for a given user. public static void SetActiveUser(T platformUserHandle, SetActiveUserCallback callback) { From f284ff0fbea2066f2f57f53af2e14d8fa0a9ab34 Mon Sep 17 00:00:00 2001 From: Jackson Wood Date: Tue, 20 Apr 2021 11:14:13 +1000 Subject: [PATCH 04/38] Spelling mistake correction in documentation --- Runtime/DataStorage/IUserDataIO.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Runtime/DataStorage/IUserDataIO.cs b/Runtime/DataStorage/IUserDataIO.cs index 21362720..a0a81891 100644 --- a/Runtime/DataStorage/IUserDataIO.cs +++ b/Runtime/DataStorage/IUserDataIO.cs @@ -10,7 +10,7 @@ public interface IUserDataIO string UserDirectory { get; } // --- Initialization --- - /// Initializes the storage system for the defaul user. + /// Initializes the storage system for the default user. void InitializeForDefaultUser(System.Action callback); // --- File I/O --- From f9e07fc37b9b54366ec39f02b3cf2fd6b52feb6d Mon Sep 17 00:00:00 2001 From: Jackson Wood Date: Mon, 26 Apr 2021 16:32:39 +1000 Subject: [PATCH 05/38] BugFix: ParseImageData now correctly processes images --- Runtime/Utility/IOUtilities.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Runtime/Utility/IOUtilities.cs b/Runtime/Utility/IOUtilities.cs index 55c2ee9e..9eb66f91 100644 --- a/Runtime/Utility/IOUtilities.cs +++ b/Runtime/Utility/IOUtilities.cs @@ -15,7 +15,7 @@ public static class IOUtilities /// Parse data as image. public static Texture2D ParseImageData(byte[] data) { - if(data == null || data.Length > 0) { return null; } + if(data == null || data.Length == 0) { return null; } Texture2D texture = new Texture2D(0,0); texture.LoadImage(data); From ad3e1fa9f4e3bd37aa0c629cc7081390bc0fb95e Mon Sep 17 00:00:00 2001 From: Jackson Wood Date: Wed, 28 Apr 2021 12:09:53 +1000 Subject: [PATCH 06/38] Restructured error object parsing in prep for CF error parsing --- Runtime/API Objects/WebRequestError.cs | 52 ++++++++++++++++++-------- 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/Runtime/API Objects/WebRequestError.cs b/Runtime/API Objects/WebRequestError.cs index 3ae9ce37..30d40d90 100644 --- a/Runtime/API Objects/WebRequestError.cs +++ b/Runtime/API Objects/WebRequestError.cs @@ -138,34 +138,54 @@ private void ApplyAPIErrorValues() this.errorMessage = null; this.fieldValidationMessages = null; + // early out + if(this.webRequest == null) + { + this.errorMessage = "An unknown error occurred. Please try again later."; + return; + } + // null-ref and type-check if(this.webRequest.downloadHandler != null && !(this.webRequest.downloadHandler is DownloadHandlerFile)) { + string requestContent = null; + try { // get the request content - string requestContent = this.webRequest.downloadHandler.text; - if(string.IsNullOrEmpty(requestContent)) { return; } - - // deserialize into an APIError - WebRequestError.APIWrapper errorWrapper = JsonConvert.DeserializeObject(requestContent); - if(errorWrapper == null - || errorWrapper.error == null) - { - return; - } - - // extract values - this.errorReference = errorWrapper.error.errorReference; - this.errorMessage = errorWrapper.error.message; - this.fieldValidationMessages = errorWrapper.error.errors; + requestContent = this.webRequest.downloadHandler.text; } catch(System.Exception e) { - Debug.LogWarning("[mod.io] Error deserializing API Error:\n" + Debug.LogWarning("[mod.io] Error reading webRequest.downloadHandler text body:\n" + e.Message); } + + if(!string.IsNullOrEmpty(requestContent)) + { + WebRequestError.APIWrapper errorWrapper = null; + + try + { + // deserialize into an APIError + errorWrapper = JsonConvert.DeserializeObject(requestContent); + } + catch(System.Exception e) + { + Debug.LogWarning("[mod.io] Error reading webRequest.downloadHandler text body:\n" + + e.Message); + } + + if(errorWrapper != null + && errorWrapper.error != null) + { + // extract values + this.errorReference = errorWrapper.error.errorReference; + this.errorMessage = errorWrapper.error.message; + this.fieldValidationMessages = errorWrapper.error.errors; + } + } } if(this.errorMessage == null) From 83b330e39347c1802f1bda36543f6bc16d96cebb Mon Sep 17 00:00:00 2001 From: Jackson Wood Date: Wed, 28 Apr 2021 12:15:14 +1000 Subject: [PATCH 07/38] Implemented CloudFlare response parsing --- Runtime/API Objects/WebRequestError.cs | 58 ++++++++++++++++++-------- 1 file changed, 41 insertions(+), 17 deletions(-) diff --git a/Runtime/API Objects/WebRequestError.cs b/Runtime/API Objects/WebRequestError.cs index 30d40d90..64b8a719 100644 --- a/Runtime/API Objects/WebRequestError.cs +++ b/Runtime/API Objects/WebRequestError.cs @@ -166,24 +166,51 @@ private void ApplyAPIErrorValues() { WebRequestError.APIWrapper errorWrapper = null; - try + // Parse Cloudflare error + if(requestContent.StartsWith(@"")) { - // deserialize into an APIError - errorWrapper = JsonConvert.DeserializeObject(requestContent); + int readIndex = requestContent.IndexOf("what-happened-section"); + int messageEnd = -1; + + if(readIndex > 0) + { + readIndex = requestContent.IndexOf(@"

", readIndex); + + if(readIndex > 0) + { + readIndex += 3; + messageEnd = requestContent.IndexOf(@"

", readIndex); + } + } + + if(messageEnd > 0) + { + this.errorMessage = ("A Cloudflare error has occurred: " + + requestContent.Substring(readIndex, messageEnd - readIndex)); + } } - catch(System.Exception e) + else { - Debug.LogWarning("[mod.io] Error reading webRequest.downloadHandler text body:\n" - + e.Message); - } + try + { + // deserialize into an APIError + errorWrapper = JsonConvert.DeserializeObject(requestContent); + } + catch(System.Exception e) + { + Debug.LogWarning("[mod.io] Eror parsing error object from repsonse:\n" + + e.Message); - if(errorWrapper != null - && errorWrapper.error != null) - { - // extract values - this.errorReference = errorWrapper.error.errorReference; - this.errorMessage = errorWrapper.error.message; - this.fieldValidationMessages = errorWrapper.error.errors; + } + + if(errorWrapper != null + && errorWrapper.error != null) + { + // extract values + this.errorReference = errorWrapper.error.errorReference; + this.errorMessage = errorWrapper.error.message; + this.fieldValidationMessages = errorWrapper.error.errors; + } } } } @@ -390,9 +417,6 @@ private void ApplyInterpretedValues() + this.webRequest.responseCode + "]"); this.isRequestUnresolvable = true; - - Debug.LogWarning("[mod.io] An unhandled error was returned during a web request." - + "\nPlease report this to jackson@mod.io with the following information"); } } break; From 36a954d0a8e651f35c91e9134f71ba691c6604de Mon Sep 17 00:00:00 2001 From: Jackson Wood Date: Wed, 28 Apr 2021 12:18:02 +1000 Subject: [PATCH 08/38] Improved robustness in WRE.GenerateFromWebRequest --- Runtime/API Objects/WebRequestError.cs | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/Runtime/API Objects/WebRequestError.cs b/Runtime/API Objects/WebRequestError.cs index 64b8a719..bca248ec 100644 --- a/Runtime/API Objects/WebRequestError.cs +++ b/Runtime/API Objects/WebRequestError.cs @@ -72,17 +72,25 @@ public class APIError public static WebRequestError GenerateFromWebRequest(UnityWebRequest webRequest) { UnityEngine.Debug.Assert(webRequest != null); - UnityEngine.Debug.Assert(webRequest.isNetworkError || webRequest.isHttpError); - WebRequestError error = new WebRequestError(); - error.webRequest = webRequest; + if(webRequest == null) + { + Debug.LogWarning("[mod.io] WebRequestError.GenerateFromWebRequest(webRequest) parameter was null."); + WebRequestError.GenerateLocal("An unknown error occurred.") + } + else + { + WebRequestError error = new WebRequestError(); - error.timeStamp = ParseDateHeaderAsTimeStamp(webRequest); + error.webRequest = webRequest; - error.ApplyAPIErrorValues(); - error.ApplyInterpretedValues(); + error.timeStamp = ParseDateHeaderAsTimeStamp(webRequest); - return error; + error.ApplyAPIErrorValues(); + error.ApplyInterpretedValues(); + + return error; + } } public static WebRequestError GenerateLocal(string errorMessage) From 2798205932961ed7a3e09527d33c9cb6de2bc287 Mon Sep 17 00:00:00 2001 From: Jackson Wood Date: Wed, 28 Apr 2021 12:18:55 +1000 Subject: [PATCH 09/38] Implemented null-check in DownloadCompletion callback firing --- Runtime/RequestManagement/ImageRequestManager.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Runtime/RequestManagement/ImageRequestManager.cs b/Runtime/RequestManagement/ImageRequestManager.cs index acd188f4..55ecdd22 100644 --- a/Runtime/RequestManagement/ImageRequestManager.cs +++ b/Runtime/RequestManagement/ImageRequestManager.cs @@ -466,7 +466,10 @@ protected virtual void OnDownloadCompleted(UnityWebRequest webRequest, string im foreach(var errorCallback in callbacks.failed) { - errorCallback(error); + if(errorCallback != null) + { + errorCallback.Invoke(error); + } } } From d6e72857b075d8a69d07f6ee90d19afefa1db1c3 Mon Sep 17 00:00:00 2001 From: Jackson Wood Date: Wed, 28 Apr 2021 16:24:38 +1000 Subject: [PATCH 10/38] Fixed a missing return in WRE.Generate --- Runtime/API Objects/WebRequestError.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Runtime/API Objects/WebRequestError.cs b/Runtime/API Objects/WebRequestError.cs index bca248ec..148610fa 100644 --- a/Runtime/API Objects/WebRequestError.cs +++ b/Runtime/API Objects/WebRequestError.cs @@ -76,7 +76,7 @@ public static WebRequestError GenerateFromWebRequest(UnityWebRequest webRequest) if(webRequest == null) { Debug.LogWarning("[mod.io] WebRequestError.GenerateFromWebRequest(webRequest) parameter was null."); - WebRequestError.GenerateLocal("An unknown error occurred.") + return WebRequestError.GenerateLocal("An unknown error occurred."); } else { From 41a49759f346c6cfcc7b721426c6424c08d77af1 Mon Sep 17 00:00:00 2001 From: Jackson Wood Date: Fri, 30 Apr 2021 13:46:32 +1000 Subject: [PATCH 11/38] BugFix: Added a null-check in modfile view assignment --- Runtime/UI/Modfile/ModfileView.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Runtime/UI/Modfile/ModfileView.cs b/Runtime/UI/Modfile/ModfileView.cs index b9127e51..484f7e2a 100644 --- a/Runtime/UI/Modfile/ModfileView.cs +++ b/Runtime/UI/Modfile/ModfileView.cs @@ -33,7 +33,8 @@ public Modfile modfile { this.m_modfile = value; - if(string.IsNullOrEmpty(this.m_modfile.changelog)) + if(this.m_modfile != null + && string.IsNullOrEmpty(this.m_modfile.changelog)) { this.m_modfile.changelog = this.emptyChangelogText; } From 40547aa89c0b03835a199cfafc7d47024669c5c2 Mon Sep 17 00:00:00 2001 From: Jackson Wood Date: Fri, 30 Apr 2021 15:14:05 +1000 Subject: [PATCH 12/38] Bugfix: Mod Browser now saves subscriptions to cache on init --- Runtime/UI/ModBrowser.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Runtime/UI/ModBrowser.cs b/Runtime/UI/ModBrowser.cs index 1a2be421..2fbd3d6f 100644 --- a/Runtime/UI/ModBrowser.cs +++ b/Runtime/UI/ModBrowser.cs @@ -494,6 +494,8 @@ private System.Collections.IEnumerator PerformInitialSubscriptionSync() } } + CacheClient.SaveModProfiles(request_page.items, null); + // check pages allPagesReceived = (request_page.items.Length < request_page.size); if(!allPagesReceived) From 5e17c7095a5ae9dc14a8a504228da9b8dafc6071 Mon Sep 17 00:00:00 2001 From: Jackson Wood Date: Fri, 30 Apr 2021 15:42:55 +1000 Subject: [PATCH 13/38] Bugfix: VerifySubscriptionInstallations is now correctly run on init --- Runtime/UI/ModBrowser.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Runtime/UI/ModBrowser.cs b/Runtime/UI/ModBrowser.cs index 2fbd3d6f..85e52ca9 100644 --- a/Runtime/UI/ModBrowser.cs +++ b/Runtime/UI/ModBrowser.cs @@ -876,8 +876,8 @@ public System.Collections.IEnumerator UpdateSubscriptions(Action onComplete = nu && isFetchRequired) { this.m_isSyncInProgress = true; - ModBrowser._state.lastSync_userId = LocalUser.UserId; + int sync_userId = LocalUser.UserId; int timestamp = ServerTimeStamp.Now; bool invalidUserEvent = (LocalUser.AuthenticationState != AuthenticationState.NoToken && ModBrowser._state.userEventId <= 0); @@ -885,7 +885,7 @@ public System.Collections.IEnumerator UpdateSubscriptions(Action onComplete = nu // perform initial sync if(ModBrowser._state.modEventId <= 0 || invalidUserEvent - || LocalUser.UserId != ModBrowser._state.lastSync_userId) + || ModBrowser._state.lastSync_userId != sync_userId) { yield return this.StartCoroutine(this.PerformInitialSubscriptionSync()); this.VerifySubscriptionInstallations(); @@ -904,6 +904,7 @@ public System.Collections.IEnumerator UpdateSubscriptions(Action onComplete = nu this.m_isSyncInProgress = false; ModBrowser._state.lastSync_timestamp = ServerTimeStamp.Now; + ModBrowser._state.lastSync_userId = sync_userId; } else { From 4c66bcc93c33ae5df179678240b758440793c55a Mon Sep 17 00:00:00 2001 From: Jackson Wood Date: Fri, 30 Apr 2021 17:34:06 +1000 Subject: [PATCH 14/38] Bugfix: VerifySubscriptionInstallations now runs all the way through on init --- Runtime/UI/ModBrowser.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Runtime/UI/ModBrowser.cs b/Runtime/UI/ModBrowser.cs index 85e52ca9..6bfc4e24 100644 --- a/Runtime/UI/ModBrowser.cs +++ b/Runtime/UI/ModBrowser.cs @@ -888,7 +888,7 @@ public System.Collections.IEnumerator UpdateSubscriptions(Action onComplete = nu || ModBrowser._state.lastSync_userId != sync_userId) { yield return this.StartCoroutine(this.PerformInitialSubscriptionSync()); - this.VerifySubscriptionInstallations(); + this.StartCoroutine(this.VerifySubscriptionInstallations()); } // update else From 832c3e52a1ab2366af0661ce7f9b12ee730eaf03 Mon Sep 17 00:00:00 2001 From: Jackson Wood Date: Fri, 30 Apr 2021 18:36:39 +1000 Subject: [PATCH 15/38] Removed unneccessary logging from DataStorage.WriteFile --- Runtime/DataStorage/DataStorage.cs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/Runtime/DataStorage/DataStorage.cs b/Runtime/DataStorage/DataStorage.cs index 45ced8fd..94774ef9 100644 --- a/Runtime/DataStorage/DataStorage.cs +++ b/Runtime/DataStorage/DataStorage.cs @@ -107,13 +107,6 @@ public static void ReadJSONFile(string path, ReadJSONFileCallback onComple /// Writes a file. public static void WriteFile(string path, byte[] data, WriteFileCallback onComplete) { - #if DEBUG - if(data.Length == 0) - { - Debug.Log("[mod.io] Writing 0-byte file to: " + path); - } - #endif // DEBUG - DataStorage.PLATFORM_IO.WriteFile(path, data, onComplete); } From bec9d500978327d8bccea94fbe57506415d6f549 Mon Sep 17 00:00:00 2001 From: Jackson Wood Date: Fri, 30 Apr 2021 18:37:14 +1000 Subject: [PATCH 16/38] SystemIOWrapper now overwrites existing files at the MoveFile destination --- .../Implementations/SystemIOWrapper.cs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/Runtime/DataStorage/Implementations/SystemIOWrapper.cs b/Runtime/DataStorage/Implementations/SystemIOWrapper.cs index 9f05b1fe..57e33aea 100644 --- a/Runtime/DataStorage/Implementations/SystemIOWrapper.cs +++ b/Runtime/DataStorage/Implementations/SystemIOWrapper.cs @@ -371,8 +371,22 @@ public virtual bool DeleteFile(string path) /// Moves a file. public virtual bool MoveFile(string source, string destination) { - Debug.Assert(!string.IsNullOrEmpty(source)); - Debug.Assert(!string.IsNullOrEmpty(destination)); + if(string.IsNullOrEmpty(source)) + { + Debug.Log("[mod.io] Failed to move file. source is NullOrEmpty."); + return false; + } + + if(string.IsNullOrEmpty(destination)) + { + Debug.Log("[mod.io] Failed to move file. destination is NullOrEmpty."); + return false; + } + + if(!this.DeleteFile(destination)) + { + return false; + } try { From 210e3e060717c47fc2288524d5f327017602215e Mon Sep 17 00:00:00 2001 From: Jackson Wood Date: Wed, 12 May 2021 10:56:24 +1000 Subject: [PATCH 17/38] Added structure for CompressionModule --- Runtime/Compression.meta | 10 ++++++++++ Runtime/Compression/CompressionModule.cs | 17 +++++++++++++++++ Runtime/Compression/CompressionModule.cs.meta | 13 +++++++++++++ Runtime/Compression/ICompressionImpl.cs | 8 ++++++++ Runtime/Compression/ICompressionImpl.cs.meta | 13 +++++++++++++ 5 files changed, 61 insertions(+) create mode 100644 Runtime/Compression.meta create mode 100644 Runtime/Compression/CompressionModule.cs create mode 100644 Runtime/Compression/CompressionModule.cs.meta create mode 100644 Runtime/Compression/ICompressionImpl.cs create mode 100644 Runtime/Compression/ICompressionImpl.cs.meta diff --git a/Runtime/Compression.meta b/Runtime/Compression.meta new file mode 100644 index 00000000..2a634c1b --- /dev/null +++ b/Runtime/Compression.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: 5a18588e8641b7c4196d1dafb9571ebb +folderAsset: yes +timeCreated: 1620780665 +licenseType: Free +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Compression/CompressionModule.cs b/Runtime/Compression/CompressionModule.cs new file mode 100644 index 00000000..dddad08f --- /dev/null +++ b/Runtime/Compression/CompressionModule.cs @@ -0,0 +1,17 @@ +namespace ModIO +{ + /// Defines the static interface for the compression operations. + public static class CompressionModule + { + // ---------[ Constants ]--------- + /// Compression implementation to use. + public static readonly ICompressionImpl IMPLEMENTATION; + + // ---------[ Initialization ]--------- + /// Loads the compression implementation. + static CompressionModule() + { + CompressionModule.IMPLEMENTATION = null; + } + } +} diff --git a/Runtime/Compression/CompressionModule.cs.meta b/Runtime/Compression/CompressionModule.cs.meta new file mode 100644 index 00000000..0db8dad1 --- /dev/null +++ b/Runtime/Compression/CompressionModule.cs.meta @@ -0,0 +1,13 @@ +fileFormatVersion: 2 +guid: 1c7d543dc03388e47ba9af144742ed00 +timeCreated: 1620780702 +licenseType: Free +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Compression/ICompressionImpl.cs b/Runtime/Compression/ICompressionImpl.cs new file mode 100644 index 00000000..e6765c06 --- /dev/null +++ b/Runtime/Compression/ICompressionImpl.cs @@ -0,0 +1,8 @@ +namespace ModIO +{ + /// Interface for a compression implementation. + public interface ICompressionImpl + { + + } +} diff --git a/Runtime/Compression/ICompressionImpl.cs.meta b/Runtime/Compression/ICompressionImpl.cs.meta new file mode 100644 index 00000000..de4fd83a --- /dev/null +++ b/Runtime/Compression/ICompressionImpl.cs.meta @@ -0,0 +1,13 @@ +fileFormatVersion: 2 +guid: 0f7199f53bda1be409804d814015d452 +timeCreated: 1620780957 +licenseType: Free +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From bae05e257313394044513a1a4e3d58022ceb4359 Mon Sep 17 00:00:00 2001 From: Jackson Wood Date: Wed, 12 May 2021 11:04:33 +1000 Subject: [PATCH 18/38] Created interface for the compression module --- Runtime/Compression/CompressionModule.cs | 19 +++++++++++++++++++ Runtime/Compression/ICompressionImpl.cs | 8 ++++++++ 2 files changed, 27 insertions(+) diff --git a/Runtime/Compression/CompressionModule.cs b/Runtime/Compression/CompressionModule.cs index dddad08f..6d0f8bc9 100644 --- a/Runtime/Compression/CompressionModule.cs +++ b/Runtime/Compression/CompressionModule.cs @@ -13,5 +13,24 @@ static CompressionModule() { CompressionModule.IMPLEMENTATION = null; } + + // ---------[ Interface ]--------- + /// Extracts the contents of an archive. + public static bool ExtractAll(string archivePath, string targetDirectory) + { + return CompressionModule.IMPLEMENTATION.ExtractAll(archivePath, targetDirectory); + } + + /// Compresses the contents of a directory. + public static bool CompressDirectory(string directoryPath, string outputPath) + { + return CompressionModule.IMPLEMENTATION.CompressDirectory(directoryPath, outputPath); + } + + /// Compresses a single file into an output archive. + public static bool CompressFile(string filePath, string outputPath) + { + return CompressionModule.IMPLEMENTATION.CompressFile(filePath, outputPath); + } } } diff --git a/Runtime/Compression/ICompressionImpl.cs b/Runtime/Compression/ICompressionImpl.cs index e6765c06..cddf32d2 100644 --- a/Runtime/Compression/ICompressionImpl.cs +++ b/Runtime/Compression/ICompressionImpl.cs @@ -3,6 +3,14 @@ namespace ModIO /// Interface for a compression implementation. public interface ICompressionImpl { + // ---------[ Interface ]--------- + /// Extracts the contents of an archive. + bool ExtractAll(string archivePath, string targetDirectory); + /// Compresses the contents of a directory. + bool CompressDirectory(string directoryPath, string outputPath); + + /// Compresses a single file into an output archive. + bool CompressFile(string filePath, string outputPath); } } From 31d56b860c35af3ed9685163954556c8a2f4b89b Mon Sep 17 00:00:00 2001 From: Jackson Wood Date: Wed, 12 May 2021 11:07:24 +1000 Subject: [PATCH 19/38] Created DotNetZip compression impl interface --- Runtime/Compression/CompressionModule.cs | 2 +- .../Compression/DotNetZipCompressionImpl.cs | 25 +++++++++++++++++++ .../DotNetZipCompressionImpl.cs.meta | 13 ++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 Runtime/Compression/DotNetZipCompressionImpl.cs create mode 100644 Runtime/Compression/DotNetZipCompressionImpl.cs.meta diff --git a/Runtime/Compression/CompressionModule.cs b/Runtime/Compression/CompressionModule.cs index 6d0f8bc9..59cfb16e 100644 --- a/Runtime/Compression/CompressionModule.cs +++ b/Runtime/Compression/CompressionModule.cs @@ -11,7 +11,7 @@ public static class CompressionModule /// Loads the compression implementation. static CompressionModule() { - CompressionModule.IMPLEMENTATION = null; + CompressionModule.IMPLEMENTATION = new DotNetZipCompressionImpl(); } // ---------[ Interface ]--------- diff --git a/Runtime/Compression/DotNetZipCompressionImpl.cs b/Runtime/Compression/DotNetZipCompressionImpl.cs new file mode 100644 index 00000000..e87bdf5c --- /dev/null +++ b/Runtime/Compression/DotNetZipCompressionImpl.cs @@ -0,0 +1,25 @@ +namespace ModIO +{ + /// A wrapper for the DotNetZip library that matches the ICompressionImpl interface. + public class DotNetZipCompressionImpl : ICompressionImpl + { + // ---------[ Interface ]--------- + /// Extracts the contents of an archive. + public bool ExtractAll(string archivePath, string targetDirectory) + { + throw new System.NotImplementedException(); + } + + /// Compresses the contents of a directory. + public bool CompressDirectory(string directoryPath, string outputPath) + { + throw new System.NotImplementedException(); + } + + /// Compresses a single file into an output archive. + public bool CompressFile(string filePath, string outputPath) + { + throw new System.NotImplementedException(); + } + } +} diff --git a/Runtime/Compression/DotNetZipCompressionImpl.cs.meta b/Runtime/Compression/DotNetZipCompressionImpl.cs.meta new file mode 100644 index 00000000..5395ed26 --- /dev/null +++ b/Runtime/Compression/DotNetZipCompressionImpl.cs.meta @@ -0,0 +1,13 @@ +fileFormatVersion: 2 +guid: a112f01b43673c34393ae15452f38827 +timeCreated: 1620781613 +licenseType: Free +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From 09f708bd1f1af3e3be77fe94a0d82671238a8491 Mon Sep 17 00:00:00 2001 From: Jackson Wood Date: Wed, 12 May 2021 11:12:59 +1000 Subject: [PATCH 20/38] Implemented DotNetZip.ExtractAll --- .../Compression/DotNetZipCompressionImpl.cs | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/Runtime/Compression/DotNetZipCompressionImpl.cs b/Runtime/Compression/DotNetZipCompressionImpl.cs index e87bdf5c..8d80b730 100644 --- a/Runtime/Compression/DotNetZipCompressionImpl.cs +++ b/Runtime/Compression/DotNetZipCompressionImpl.cs @@ -1,3 +1,6 @@ +using Exception = System.Exception; +using Debug = UnityEngine.Debug; + namespace ModIO { /// A wrapper for the DotNetZip library that matches the ICompressionImpl interface. @@ -7,7 +10,29 @@ public class DotNetZipCompressionImpl : ICompressionImpl /// Extracts the contents of an archive. public bool ExtractAll(string archivePath, string targetDirectory) { - throw new System.NotImplementedException(); + bool success = false; + + try + { + using (var zip = Ionic.Zip.ZipFile.Read(archivePath)) + { + zip.ExtractAll(targetDirectory); + + success = true; + } + } + catch(Exception e) + { + Debug.LogWarning("[mod.io] Unable to extract archive to target directory." + + "\nArchive: " + archivePath + + "\nTarget: " + targetDirectory + + "\n\n" + + Utility.GenerateExceptionDebugString(e)); + + DataStorage.DeleteDirectory(targetDirectory, null); + } + + return success; } /// Compresses the contents of a directory. From a17699e87c02f5ae9cbdc69b25d8445a5945c981 Mon Sep 17 00:00:00 2001 From: Jackson Wood Date: Wed, 12 May 2021 11:35:20 +1000 Subject: [PATCH 21/38] Implemented CompressionModule.ExtractAll in TryInstallMod --- Runtime/Compression/DotNetZipCompressionImpl.cs | 2 -- Runtime/ModManager.cs | 17 ++++------------- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/Runtime/Compression/DotNetZipCompressionImpl.cs b/Runtime/Compression/DotNetZipCompressionImpl.cs index 8d80b730..6ada4ea7 100644 --- a/Runtime/Compression/DotNetZipCompressionImpl.cs +++ b/Runtime/Compression/DotNetZipCompressionImpl.cs @@ -28,8 +28,6 @@ public bool ExtractAll(string archivePath, string targetDirectory) + "\nTarget: " + targetDirectory + "\n\n" + Utility.GenerateExceptionDebugString(e)); - - DataStorage.DeleteDirectory(targetDirectory, null); } return success; diff --git a/Runtime/ModManager.cs b/Runtime/ModManager.cs index e98692fd..ff6508cc 100644 --- a/Runtime/ModManager.cs +++ b/Runtime/ModManager.cs @@ -99,29 +99,20 @@ public static void TryInstallMod(int modId, int modfileId, Action onComple } else { - DataStorage.DeleteDirectory(tempLocation, (dd_path, dd_success) => DataStorage.CreateDirectory(tempLocation, (cd_path, cd_success) => { if(dd_success && cd_success) { - // extract - try - { - using (var zip = Ionic.Zip.ZipFile.Read(archivePath)) - { - zip.ExtractAll(tempLocation); - } + bool didExtract = CompressionModule.ExtractAll(archivePath, tempLocation); + if(didExtract) + { // Remove old versions ModManager.UninstallMod(modId, onOldVersionsUninstalled); } - catch(Exception e) + else { - Debug.LogWarning("[mod.io] Unable to extract binary to a temporary folder." - + "\nLocation: " + tempLocation + "\n\n" - + Utility.GenerateExceptionDebugString(e)); - DataStorage.DeleteDirectory(tempLocation, null); if(onComplete != null) From 3cac7e36ff96b6df26d749b424194778e741953f Mon Sep 17 00:00:00 2001 From: Jackson Wood Date: Wed, 12 May 2021 11:49:56 +1000 Subject: [PATCH 22/38] Implemented DNZCompression.CompressFile --- .../Compression/DotNetZipCompressionImpl.cs | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/Runtime/Compression/DotNetZipCompressionImpl.cs b/Runtime/Compression/DotNetZipCompressionImpl.cs index 6ada4ea7..83cda2d2 100644 --- a/Runtime/Compression/DotNetZipCompressionImpl.cs +++ b/Runtime/Compression/DotNetZipCompressionImpl.cs @@ -42,7 +42,27 @@ public bool CompressDirectory(string directoryPath, string outputPath) /// Compresses a single file into an output archive. public bool CompressFile(string filePath, string outputPath) { - throw new System.NotImplementedException(); + bool success = false; + + try + { + using(var zip = new Ionic.Zip.ZipFile()) + { + zip.AddFile(filePath, ""); + zip.Save(outputPath); + success = true; + } + } + catch(Exception e) + { + Debug.LogWarning("[mod.io] Unable to compress file to archive." + + "\nFile: " + filePath + + "\nOutput: " + outputPath + + "\n\n" + + Utility.GenerateExceptionDebugString(e)); + } + + return success; } } } From 3b3fe2653662d2c667d3cc512955750229d6cbc6 Mon Sep 17 00:00:00 2001 From: Jackson Wood Date: Wed, 12 May 2021 11:50:46 +1000 Subject: [PATCH 23/38] Implemented CompressionModule.CompressFile in UploadModBinary --- Runtime/ModManager.cs | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/Runtime/ModManager.cs b/Runtime/ModManager.cs index ff6508cc..cabcb824 100644 --- a/Runtime/ModManager.cs +++ b/Runtime/ModManager.cs @@ -1573,33 +1573,20 @@ public static System.Collections.IEnumerator DownloadAndUpdateMods_Coroutine(ILi DataStorage.CreateDirectory(Path.GetDirectoryName(binaryZipLocation), (path, success) => { - try - { - using(var zip = new Ionic.Zip.ZipFile()) - { - zip.AddFile(unzippedBinaryLocation, ""); - zip.Save(binaryZipLocation); - } + zipSucceeded = CompressionModule.CompressFile(unzippedBinaryLocation, binaryZipLocation); - zipSucceeded = true; + if(zipSucceeded) + { + UploadModBinary_Zipped(modId, modfileValues, binaryZipLocation, setActiveBuild, onSuccess, onError); } - catch(Exception e) + else { - Debug.LogError("[mod.io] Unable to zip mod binary prior to uploading.\n\n" - + Utility.GenerateExceptionDebugString(e)); - if(onError != null) { WebRequestError error = WebRequestError.GenerateLocal("Unable to zip mod binary prior to uploading"); - - onError(error); + onError.Invoke(error); } } - - if(zipSucceeded) - { - UploadModBinary_Zipped(modId, modfileValues, binaryZipLocation, setActiveBuild, onSuccess, onError); - } }); } From 85fec4c2a13f70255d37d208fc342e5ad955e382 Mon Sep 17 00:00:00 2001 From: Jackson Wood Date: Wed, 12 May 2021 12:05:18 +1000 Subject: [PATCH 24/38] Replaced CompressDirectory with CompressFileCollection --- Runtime/Compression/CompressionModule.cs | 10 ++++++---- Runtime/Compression/DotNetZipCompressionImpl.cs | 6 ++++-- Runtime/Compression/ICompressionImpl.cs | 6 ++++-- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Runtime/Compression/CompressionModule.cs b/Runtime/Compression/CompressionModule.cs index 59cfb16e..dc0fd3f8 100644 --- a/Runtime/Compression/CompressionModule.cs +++ b/Runtime/Compression/CompressionModule.cs @@ -1,4 +1,6 @@ -namespace ModIO +using System.Collections.Generic; + +namespace ModIO { /// Defines the static interface for the compression operations. public static class CompressionModule @@ -21,10 +23,10 @@ public static bool ExtractAll(string archivePath, string targetDirectory) return CompressionModule.IMPLEMENTATION.ExtractAll(archivePath, targetDirectory); } - /// Compresses the contents of a directory. - public static bool CompressDirectory(string directoryPath, string outputPath) + /// Compresses the contents of a file collection into an output archive. + public static bool CompressFileCollection(string rootDirectory, IEnumerable fileCollection, string outputPath) { - return CompressionModule.IMPLEMENTATION.CompressDirectory(directoryPath, outputPath); + return CompressionModule.IMPLEMENTATION.CompressFileCollection(rootDirectory, fileCollection, outputPath); } /// Compresses a single file into an output archive. diff --git a/Runtime/Compression/DotNetZipCompressionImpl.cs b/Runtime/Compression/DotNetZipCompressionImpl.cs index 83cda2d2..b24176a9 100644 --- a/Runtime/Compression/DotNetZipCompressionImpl.cs +++ b/Runtime/Compression/DotNetZipCompressionImpl.cs @@ -1,3 +1,5 @@ +using System.Collections.Generic; + using Exception = System.Exception; using Debug = UnityEngine.Debug; @@ -33,8 +35,8 @@ public bool ExtractAll(string archivePath, string targetDirectory) return success; } - /// Compresses the contents of a directory. - public bool CompressDirectory(string directoryPath, string outputPath) + /// Compresses the contents of a file collection into an output archive. + public bool CompressFileCollection(string rootDirectory, IEnumerable fileCollection, string outputPath) { throw new System.NotImplementedException(); } diff --git a/Runtime/Compression/ICompressionImpl.cs b/Runtime/Compression/ICompressionImpl.cs index cddf32d2..5d994dfd 100644 --- a/Runtime/Compression/ICompressionImpl.cs +++ b/Runtime/Compression/ICompressionImpl.cs @@ -1,3 +1,5 @@ +using System.Collections.Generic; + namespace ModIO { /// Interface for a compression implementation. @@ -7,8 +9,8 @@ public interface ICompressionImpl /// Extracts the contents of an archive. bool ExtractAll(string archivePath, string targetDirectory); - /// Compresses the contents of a directory. - bool CompressDirectory(string directoryPath, string outputPath); + /// Compresses the contents of a file collection into an output archive. + bool CompressFileCollection(string rootDirectory, IEnumerable fileCollection, string outputPath); /// Compresses a single file into an output archive. bool CompressFile(string filePath, string outputPath); From e23cddab92f4b08a11bc67b04b05ea8ede0255cf Mon Sep 17 00:00:00 2001 From: Jackson Wood Date: Wed, 12 May 2021 12:05:38 +1000 Subject: [PATCH 25/38] Implemented DNZCompression.CompressFileList --- .../Compression/DotNetZipCompressionImpl.cs | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/Runtime/Compression/DotNetZipCompressionImpl.cs b/Runtime/Compression/DotNetZipCompressionImpl.cs index b24176a9..934c2dec 100644 --- a/Runtime/Compression/DotNetZipCompressionImpl.cs +++ b/Runtime/Compression/DotNetZipCompressionImpl.cs @@ -2,6 +2,7 @@ using Exception = System.Exception; using Debug = UnityEngine.Debug; +using Path = System.IO.Path; namespace ModIO { @@ -38,7 +39,38 @@ public bool ExtractAll(string archivePath, string targetDirectory) /// Compresses the contents of a file collection into an output archive. public bool CompressFileCollection(string rootDirectory, IEnumerable fileCollection, string outputPath) { - throw new System.NotImplementedException(); + bool success = false; + string lastFilePath = string.Empty; + + try + { + using(var zip = new Ionic.Zip.ZipFile()) + { + foreach(string filePath in fileCollection) + { + lastFilePath = filePath; + + string relativeFilePath = filePath.Substring(rootDirectory.Length); + string relativeDirectory = Path.GetDirectoryName(relativeFilePath); + + zip.AddFile(filePath, relativeDirectory); + } + + zip.Save(outputPath); + + success = true; + } + } + catch(Exception e) + { + Debug.LogWarning("[mod.io] Unable to compress file collection to archive." + + "\nLast Attempted File: " + lastFilePath + + "\nOutput: " + outputPath + + "\n\n" + + Utility.GenerateExceptionDebugString(e)); + } + + return success; } /// Compresses a single file into an output archive. From a100744ca7836d05e40515b69c6e5eead3423b90 Mon Sep 17 00:00:00 2001 From: Jackson Wood Date: Wed, 12 May 2021 12:10:32 +1000 Subject: [PATCH 26/38] Implemented DNZ.CompressFileCollection in UploadModBinaryFileList --- Runtime/ModManager.cs | 40 +++++++--------------------------------- 1 file changed, 7 insertions(+), 33 deletions(-) diff --git a/Runtime/ModManager.cs b/Runtime/ModManager.cs index cabcb824..b33106e1 100644 --- a/Runtime/ModManager.cs +++ b/Runtime/ModManager.cs @@ -1512,46 +1512,20 @@ public static System.Collections.IEnumerator DownloadAndUpdateMods_Coroutine(ILi { if(success) { - try - { - using(var zip = new Ionic.Zip.ZipFile()) - { - foreach(string filePath in fileList) - { - string relativeFilePath = filePath.Substring(rootDirectoryLength); - string relativeDirectory = Path.GetDirectoryName(relativeFilePath); + success = CompressionModule.CompressFileCollection(rootDirectory, fileList, archiveFilePath); - zip.AddFile(filePath, relativeDirectory); - zip.Save(archiveFilePath); - } - } - - UploadModBinary_Zipped(modId, modfileValues, archiveFilePath, setActiveBuild, onSuccess, onError); - } - catch(Exception e) + if(success) { - Debug.LogError("[mod.io] Unable to zip mod binary prior to uploading.\n\n" - + Utility.GenerateExceptionDebugString(e)); - - if(onError != null) - { - WebRequestError error = WebRequestError.GenerateLocal("Unable to zip mod binary prior to uploading"); - - onError(error); - } + UploadModBinary_Zipped(modId, modfileValues, archiveFilePath, setActiveBuild, onSuccess, onError); } } - else - { - string errorString = ("Unable to create directory for mod binary archive prior to upload." - + "\nDirectory: " + path); - - Debug.LogError("[mod.io] " + errorString); + if(!success) + { if(onError != null) { - WebRequestError error = WebRequestError.GenerateLocal(errorString); - onError(error); + WebRequestError error = WebRequestError.GenerateLocal("Unable to zip mod binary prior to uploading"); + onError.Invoke(error); } } }); From ae8d87d2309fe5314ffbc069ab200f38d9986b81 Mon Sep 17 00:00:00 2001 From: Jackson Wood Date: Wed, 12 May 2021 14:39:30 +1000 Subject: [PATCH 27/38] Implemented basic param-checks --- .../Compression/DotNetZipCompressionImpl.cs | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/Runtime/Compression/DotNetZipCompressionImpl.cs b/Runtime/Compression/DotNetZipCompressionImpl.cs index 934c2dec..ab8221ed 100644 --- a/Runtime/Compression/DotNetZipCompressionImpl.cs +++ b/Runtime/Compression/DotNetZipCompressionImpl.cs @@ -13,6 +13,21 @@ public class DotNetZipCompressionImpl : ICompressionImpl /// Extracts the contents of an archive. public bool ExtractAll(string archivePath, string targetDirectory) { + // early outs + if(string.IsNullOrEmpty(archivePath)) + { + Debug.LogWarning("[mod.io] Unable to extract archive to target directory." + + "\narchivePath is NULL or EMPTY."); + return false; + } + if(string.IsNullOrEmpty(targetDirectory)) + { + Debug.LogWarning("[mod.io] Unable to extract archive to target directory." + + "\ntargetDirectory is NULL or EMPTY."); + return false; + } + + // Extract bool success = false; try @@ -39,6 +54,27 @@ public bool ExtractAll(string archivePath, string targetDirectory) /// Compresses the contents of a file collection into an output archive. public bool CompressFileCollection(string rootDirectory, IEnumerable fileCollection, string outputPath) { + // early outs + if(string.IsNullOrEmpty(rootDirectory)) + { + Debug.LogWarning("[mod.io] Unable to compress file collection to archive." + + "\nrootDirectory is NULL or EMPTY."); + return false; + } + if(fileCollection == null) + { + Debug.LogWarning("[mod.io] Unable to compress file collection to archive." + + "\nfileCollection is NULL."); + return false; + } + if(string.IsNullOrEmpty(outputPath)) + { + Debug.LogWarning("[mod.io] Unable to compress file collection to archive." + + "\noutputPath is NULL or EMPTY."); + return false; + } + + // compress bool success = false; string lastFilePath = string.Empty; @@ -76,6 +112,21 @@ public bool CompressFileCollection(string rootDirectory, IEnumerable fil /// Compresses a single file into an output archive. public bool CompressFile(string filePath, string outputPath) { + // early outs + if(string.IsNullOrEmpty(filePath)) + { + Debug.LogWarning("[mod.io] Unable to compress file collection to archive." + + "\nfilePath is NULL or EMPTY."); + return false; + } + if(string.IsNullOrEmpty(outputPath)) + { + Debug.LogWarning("[mod.io] Unable to compress file collection to archive." + + "\noutputPath is NULL or EMPTY."); + return false; + } + + // compress bool success = false; try From e8f7b832ed91ffcb2a1b8394eb30cd14b1d378e9 Mon Sep 17 00:00:00 2001 From: Jackson Wood Date: Wed, 12 May 2021 14:44:01 +1000 Subject: [PATCH 28/38] Edit pass on parameter names --- Runtime/Compression/CompressionModule.cs | 10 +++--- .../Compression/DotNetZipCompressionImpl.cs | 32 ++++++++++--------- Runtime/Compression/ICompressionImpl.cs | 6 ++-- 3 files changed, 27 insertions(+), 21 deletions(-) diff --git a/Runtime/Compression/CompressionModule.cs b/Runtime/Compression/CompressionModule.cs index dc0fd3f8..25509461 100644 --- a/Runtime/Compression/CompressionModule.cs +++ b/Runtime/Compression/CompressionModule.cs @@ -24,15 +24,17 @@ public static bool ExtractAll(string archivePath, string targetDirectory) } /// Compresses the contents of a file collection into an output archive. - public static bool CompressFileCollection(string rootDirectory, IEnumerable fileCollection, string outputPath) + public static bool CompressFileCollection(string rootDirectory, + IEnumerable filePathCollection, + string targetFilePath) { - return CompressionModule.IMPLEMENTATION.CompressFileCollection(rootDirectory, fileCollection, outputPath); + return CompressionModule.IMPLEMENTATION.CompressFileCollection(rootDirectory, filePathCollection, targetFilePath); } /// Compresses a single file into an output archive. - public static bool CompressFile(string filePath, string outputPath) + public static bool CompressFile(string filePath, string targetFilePath) { - return CompressionModule.IMPLEMENTATION.CompressFile(filePath, outputPath); + return CompressionModule.IMPLEMENTATION.CompressFile(filePath, targetFilePath); } } } diff --git a/Runtime/Compression/DotNetZipCompressionImpl.cs b/Runtime/Compression/DotNetZipCompressionImpl.cs index ab8221ed..f00ac480 100644 --- a/Runtime/Compression/DotNetZipCompressionImpl.cs +++ b/Runtime/Compression/DotNetZipCompressionImpl.cs @@ -51,8 +51,10 @@ public bool ExtractAll(string archivePath, string targetDirectory) return success; } - /// Compresses the contents of a file collection into an output archive. - public bool CompressFileCollection(string rootDirectory, IEnumerable fileCollection, string outputPath) + /// Compresses the contents of a file collection into a new output archive. + public bool CompressFileCollection(string rootDirectory, + IEnumerable filePathCollection, + string targetFilePath) { // early outs if(string.IsNullOrEmpty(rootDirectory)) @@ -61,16 +63,16 @@ public bool CompressFileCollection(string rootDirectory, IEnumerable fil + "\nrootDirectory is NULL or EMPTY."); return false; } - if(fileCollection == null) + if(filePathCollection == null) { Debug.LogWarning("[mod.io] Unable to compress file collection to archive." - + "\nfileCollection is NULL."); + + "\nfilePathCollection is NULL."); return false; } - if(string.IsNullOrEmpty(outputPath)) + if(string.IsNullOrEmpty(targetFilePath)) { Debug.LogWarning("[mod.io] Unable to compress file collection to archive." - + "\noutputPath is NULL or EMPTY."); + + "\ntargetFilePath is NULL or EMPTY."); return false; } @@ -82,7 +84,7 @@ public bool CompressFileCollection(string rootDirectory, IEnumerable fil { using(var zip = new Ionic.Zip.ZipFile()) { - foreach(string filePath in fileCollection) + foreach(string filePath in filePathCollection) { lastFilePath = filePath; @@ -92,7 +94,7 @@ public bool CompressFileCollection(string rootDirectory, IEnumerable fil zip.AddFile(filePath, relativeDirectory); } - zip.Save(outputPath); + zip.Save(targetFilePath); success = true; } @@ -101,7 +103,7 @@ public bool CompressFileCollection(string rootDirectory, IEnumerable fil { Debug.LogWarning("[mod.io] Unable to compress file collection to archive." + "\nLast Attempted File: " + lastFilePath - + "\nOutput: " + outputPath + + "\nOutput: " + targetFilePath + "\n\n" + Utility.GenerateExceptionDebugString(e)); } @@ -109,8 +111,8 @@ public bool CompressFileCollection(string rootDirectory, IEnumerable fil return success; } - /// Compresses a single file into an output archive. - public bool CompressFile(string filePath, string outputPath) + /// Compresses a single file into a new output archive. + public bool CompressFile(string filePath, string targetFilePath) { // early outs if(string.IsNullOrEmpty(filePath)) @@ -119,10 +121,10 @@ public bool CompressFile(string filePath, string outputPath) + "\nfilePath is NULL or EMPTY."); return false; } - if(string.IsNullOrEmpty(outputPath)) + if(string.IsNullOrEmpty(targetFilePath)) { Debug.LogWarning("[mod.io] Unable to compress file collection to archive." - + "\noutputPath is NULL or EMPTY."); + + "\ntargetFilePath is NULL or EMPTY."); return false; } @@ -134,7 +136,7 @@ public bool CompressFile(string filePath, string outputPath) using(var zip = new Ionic.Zip.ZipFile()) { zip.AddFile(filePath, ""); - zip.Save(outputPath); + zip.Save(targetFilePath); success = true; } } @@ -142,7 +144,7 @@ public bool CompressFile(string filePath, string outputPath) { Debug.LogWarning("[mod.io] Unable to compress file to archive." + "\nFile: " + filePath - + "\nOutput: " + outputPath + + "\nOutput: " + targetFilePath + "\n\n" + Utility.GenerateExceptionDebugString(e)); } diff --git a/Runtime/Compression/ICompressionImpl.cs b/Runtime/Compression/ICompressionImpl.cs index 5d994dfd..39e66218 100644 --- a/Runtime/Compression/ICompressionImpl.cs +++ b/Runtime/Compression/ICompressionImpl.cs @@ -10,9 +10,11 @@ public interface ICompressionImpl bool ExtractAll(string archivePath, string targetDirectory); /// Compresses the contents of a file collection into an output archive. - bool CompressFileCollection(string rootDirectory, IEnumerable fileCollection, string outputPath); + bool CompressFileCollection(string rootDirectory, + IEnumerable filePathCollection, + string targetFilePath); /// Compresses a single file into an output archive. - bool CompressFile(string filePath, string outputPath); + bool CompressFile(string filePath, string targetFilePath); } } From f4de1988ad712a837cea153af473c9c5b6fe5c4f Mon Sep 17 00:00:00 2001 From: Jackson Wood Date: Tue, 1 Jun 2021 10:29:38 +1000 Subject: [PATCH 29/38] BugFix: Implemented CompressionModule references in SubmitModOperation --- .../ModManager_SubmitModOperation.cs | 18 +++++------------- .../Compression/DotNetZipCompressionImpl.cs | 11 +++++------ 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/Runtime/ComplexCallbacks/ModManager_SubmitModOperation.cs b/Runtime/ComplexCallbacks/ModManager_SubmitModOperation.cs index c201912b..e5e1644b 100644 --- a/Runtime/ComplexCallbacks/ModManager_SubmitModOperation.cs +++ b/Runtime/ComplexCallbacks/ModManager_SubmitModOperation.cs @@ -386,23 +386,15 @@ private void SubmitModChanges_Internal_ZipImages() { if(success) { - try - { - using(var zip = new Ionic.Zip.ZipFile()) - { - foreach(string imageFilePath in this.addedImageFilePaths) - { - zip.AddFile(imageFilePath); - } - zip.Save(imageArchivePath); - } + bool didZip = CompressionModule.CompressFileCollection(null, this.addedImageFilePaths, imageArchivePath); + if(didZip) + { DataStorage.ReadFile(imageArchivePath, this.SubmitModChanges_Internal_OnReadImageArchive); } - catch(Exception e) + else { - this.SubmissionError_Local("Unable to zip image gallery prior to uploading.\n" - + Utility.GenerateExceptionDebugString(e)); + this.SubmissionError_Local("Unable to zip image gallery prior to uploading."); } } else diff --git a/Runtime/Compression/DotNetZipCompressionImpl.cs b/Runtime/Compression/DotNetZipCompressionImpl.cs index f00ac480..82b5491f 100644 --- a/Runtime/Compression/DotNetZipCompressionImpl.cs +++ b/Runtime/Compression/DotNetZipCompressionImpl.cs @@ -57,12 +57,6 @@ public bool ExtractAll(string archivePath, string targetDirectory) string targetFilePath) { // early outs - if(string.IsNullOrEmpty(rootDirectory)) - { - Debug.LogWarning("[mod.io] Unable to compress file collection to archive." - + "\nrootDirectory is NULL or EMPTY."); - return false; - } if(filePathCollection == null) { Debug.LogWarning("[mod.io] Unable to compress file collection to archive." @@ -77,6 +71,11 @@ public bool ExtractAll(string archivePath, string targetDirectory) } // compress + if(string.IsNullOrEmpty(rootDirectory)) + { + rootDirectory = string.Empty; + } + bool success = false; string lastFilePath = string.Empty; From 0210aa868a22b6d8325dfa2df2a2893163b70e21 Mon Sep 17 00:00:00 2001 From: Jackson Wood Date: Thu, 10 Jun 2021 12:53:50 +1000 Subject: [PATCH 30/38] NavigationManager now checks for an EventSystem on init --- Runtime/UI/NavigationManager.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Runtime/UI/NavigationManager.cs b/Runtime/UI/NavigationManager.cs index 231b3487..8954a22a 100644 --- a/Runtime/UI/NavigationManager.cs +++ b/Runtime/UI/NavigationManager.cs @@ -78,6 +78,18 @@ private void Awake() #endif } + /// Asserts that an EventManager exists. + private void OnEnable() + { + if(EventSystem.current == null) + { + Debug.LogError("[mod.io] NavigationManager cannot be enabled without an active EventSystem." + + "\nAs such, the ModBrowser UI will not work as intended.", this); + + this.enabled = false; + } + } + /// Links with View Manager. private void Start() { From 0a5b561577f7b7be601af5946b0b216dcf2efdf7 Mon Sep 17 00:00:00 2001 From: Jackson Wood Date: Thu, 10 Jun 2021 13:20:44 +1000 Subject: [PATCH 31/38] BugFix: Manually add CanvasRenderer to SlideToggle's click blocker --- Runtime/_Obsolete/UI/SlideToggle.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Runtime/_Obsolete/UI/SlideToggle.cs b/Runtime/_Obsolete/UI/SlideToggle.cs index 80a67f19..4090ef0f 100644 --- a/Runtime/_Obsolete/UI/SlideToggle.cs +++ b/Runtime/_Obsolete/UI/SlideToggle.cs @@ -77,6 +77,7 @@ private void OnEnable() t.offsetMin = Vector2.zero; t.offsetMax = Vector2.zero; + m_clickBlocker.AddComponent(); m_clickBlocker.AddComponent(); m_clickBlocker.SetActive(false); } From 9732cafb9026806274f2bf609ce7cf4aed941d42 Mon Sep 17 00:00:00 2001 From: Jackson Wood Date: Thu, 10 Jun 2021 15:59:38 +1000 Subject: [PATCH 32/38] BugFix: Variable paths now resolve on Mobile --- Runtime/PluginSettings.cs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/Runtime/PluginSettings.cs b/Runtime/PluginSettings.cs index 7dab845d..4906a7d3 100644 --- a/Runtime/PluginSettings.cs +++ b/Runtime/PluginSettings.cs @@ -1,3 +1,7 @@ +#if UNITY_STANDALONE || UNITY_ANDROID || UNITY_IOS + #define MODIO_ENABLE_VARIABLE_PATHS +#endif + using Path = System.IO.Path; using UnityEngine; @@ -233,7 +237,7 @@ public static PluginSettings.Data LoadDataFromAsset(string assetPath) settings = wrapper.m_data; // - Path variable replacement - - #if UNITY_STANDALONE + #if MODIO_ENABLE_VARIABLE_PATHS && !UNITY_EDITOR // cachedir if(settings.cacheDirectory != null) @@ -256,7 +260,12 @@ public static PluginSettings.Data LoadDataFromAsset(string assetPath) settings.gameId); } - #endif // UNITY_STANDALONE + Debug.Log("[mod.io] PluginSettings variable directories resolved to:" + + "\n.cacheDirectory=" + settings.cacheDirectory + + "\n.installationDirectory=" + settings.installationDirectory + + "\n.userDirectory=" + settings.userDirectory); + + #endif // MODIO_ENABLE_VARIABLE_PATHS && !UNITY_EDITOR #if UNITY_EDITOR @@ -281,7 +290,13 @@ public static PluginSettings.Data LoadDataFromAsset(string assetPath) settings.gameId); } + Debug.Log("[mod.io] PluginSettings variable directories resolved to:" + + "\n.cacheDirectoryEditor=" + settings.cacheDirectoryEditor + + "\n.installationDirectoryEditor=" + settings.installationDirectoryEditor + + "\n.userDirectoryEditor=" + settings.userDirectoryEditor); + #endif // UNITY_EDITOR + } return settings; From 20cce7dba7af962fbb0522672cfdc934b8bf7f70 Mon Sep 17 00:00:00 2001 From: Jackson Wood Date: Thu, 10 Jun 2021 16:59:55 +1000 Subject: [PATCH 33/38] Implemented single page fetch on the mod event fetching --- Runtime/ModManager.cs | 42 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/Runtime/ModManager.cs b/Runtime/ModManager.cs index b33106e1..482b6336 100644 --- a/Runtime/ModManager.cs +++ b/Runtime/ModManager.cs @@ -1302,10 +1302,16 @@ public static System.Collections.IEnumerator DownloadAndUpdateMods_Coroutine(ILi }); } + var pagination = new APIPaginationParameters() + { + limit = APIPaginationParameters.LIMIT_MAX, + offset = 0, + }; + // - Get All Events - - ModManager.FetchAllResultsForQuery((p,s,e) => APIClient.GetAllModEvents(modEventFilter, p, s, e), - onSuccess, - onError); + APIClient.GetAllModEvents(modEventFilter, pagination, + (r) => ModManager._OnModEventSuccess(r, onSuccess), + onError); } /// Fetches all mod events after the given event id. @@ -1332,10 +1338,34 @@ public static System.Collections.IEnumerator DownloadAndUpdateMods_Coroutine(ILi }); } + var pagination = new APIPaginationParameters() + { + limit = APIPaginationParameters.LIMIT_MAX, + offset = 0, + }; + // - Get All Events - - ModManager.FetchAllResultsForQuery((p,s,e) => APIClient.GetAllModEvents(modEventFilter, p, s, e), - onSuccess, - onError); + APIClient.GetAllModEvents(modEventFilter, pagination, + (r) => ModManager._OnModEventSuccess(r, onSuccess), + onError); + } + + /// Processes results from the events fetch results. + private static void _OnModEventSuccess(RequestPage r, + Action> onSuccess) + { + if(onSuccess != null) + { + List eventList = new List(); + if(r != null + && r.items != null + && r.items.Length > 0) + { + eventList = new List(r.items); + } + + onSuccess.Invoke(eventList); + } } /// Fetches all user events for the authenticated user. From 64554381baa7aee0bf074c233adf1b3e9bd964b6 Mon Sep 17 00:00:00 2001 From: Jackson Wood Date: Thu, 10 Jun 2021 17:00:51 +1000 Subject: [PATCH 34/38] Fixed the sorting issues on the mod event fetching --- Runtime/ModManager.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Runtime/ModManager.cs b/Runtime/ModManager.cs index 482b6336..bf0c0f7d 100644 --- a/Runtime/ModManager.cs +++ b/Runtime/ModManager.cs @@ -1281,7 +1281,8 @@ public static System.Collections.IEnumerator DownloadAndUpdateMods_Coroutine(ILi { // - Filter - RequestFilter modEventFilter = new RequestFilter(); - modEventFilter.sortFieldName = GetAllModEventsFilterFields.dateAdded; + modEventFilter.sortFieldName = GetAllModEventsFilterFields.id; + modEventFilter.isSortAscending = false; modEventFilter.AddFieldFilter(GetAllModEventsFilterFields.dateAdded, new MinimumFilter() { @@ -1323,6 +1324,7 @@ public static System.Collections.IEnumerator DownloadAndUpdateMods_Coroutine(ILi // - Filter - RequestFilter modEventFilter = new RequestFilter(); modEventFilter.sortFieldName = GetAllModEventsFilterFields.id; + modEventFilter.isSortAscending = false; modEventFilter.AddFieldFilter(GetAllModEventsFilterFields.id, new MinimumFilter() { From ab365edcdb7669385f8527676b9593f3213f711d Mon Sep 17 00:00:00 2001 From: Jackson Wood Date: Thu, 10 Jun 2021 17:09:41 +1000 Subject: [PATCH 35/38] Altered mod event fetching behaviour to early-out if the filter is 0 --- Runtime/ModManager.cs | 46 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/Runtime/ModManager.cs b/Runtime/ModManager.cs index bf0c0f7d..62116a40 100644 --- a/Runtime/ModManager.cs +++ b/Runtime/ModManager.cs @@ -1279,6 +1279,25 @@ public static System.Collections.IEnumerator DownloadAndUpdateMods_Coroutine(ILi Action> onSuccess, Action onError) { + // init + int[] modIdFilterArray = null; + if(modIdFilter != null) + { + modIdFilterArray = modIdFilter.ToArray(); + } + + // early out + if(modIdFilterArray != null + && modIdFilterArray.Length == 0) + { + if(onSuccess != null) + { + onSuccess.Invoke(new List()); + } + + return; + } + // - Filter - RequestFilter modEventFilter = new RequestFilter(); modEventFilter.sortFieldName = GetAllModEventsFilterFields.id; @@ -1295,11 +1314,11 @@ public static System.Collections.IEnumerator DownloadAndUpdateMods_Coroutine(ILi isInclusive = true, }); - if(modIdFilter != null) + if(modIdFilterArray != null) { modEventFilter.AddFieldFilter(GetAllModEventsFilterFields.modId, new InArrayFilter() { - filterArray = modIdFilter.ToArray(), + filterArray = modIdFilterArray, }); } @@ -1321,6 +1340,25 @@ public static System.Collections.IEnumerator DownloadAndUpdateMods_Coroutine(ILi Action> onSuccess, Action onError) { + // init + int[] modIdFilterArray = null; + if(modIdFilter != null) + { + modIdFilterArray = modIdFilter.ToArray(); + } + + // early out + if(modIdFilterArray != null + && modIdFilterArray.Length == 0) + { + if(onSuccess != null) + { + onSuccess.Invoke(new List()); + } + + return; + } + // - Filter - RequestFilter modEventFilter = new RequestFilter(); modEventFilter.sortFieldName = GetAllModEventsFilterFields.id; @@ -1332,11 +1370,11 @@ public static System.Collections.IEnumerator DownloadAndUpdateMods_Coroutine(ILi isInclusive = false, }); - if(modIdFilter != null) + if(modIdFilterArray != null) { modEventFilter.AddFieldFilter(GetAllModEventsFilterFields.modId, new InArrayFilter() { - filterArray = modIdFilter.ToArray(), + filterArray = modIdFilterArray, }); } From f4e47e74d9a4a905441a5a59b9394589729c63e4 Mon Sep 17 00:00:00 2001 From: Jackson Wood Date: Thu, 10 Jun 2021 17:10:50 +1000 Subject: [PATCH 36/38] Modified event sort parameters --- Runtime/ModManager.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Runtime/ModManager.cs b/Runtime/ModManager.cs index 62116a40..c5362ec9 100644 --- a/Runtime/ModManager.cs +++ b/Runtime/ModManager.cs @@ -1416,7 +1416,8 @@ public static System.Collections.IEnumerator DownloadAndUpdateMods_Coroutine(ILi { // - Filter - RequestFilter userEventFilter = new RequestFilter(); - userEventFilter.sortFieldName = GetUserEventsFilterFields.dateAdded; + userEventFilter.sortFieldName = GetUserEventsFilterFields.id; + userEventFilter.isSortAscending = false; userEventFilter.AddFieldFilter(GetUserEventsFilterFields.dateAdded, new MinimumFilter() { @@ -1448,6 +1449,7 @@ public static System.Collections.IEnumerator DownloadAndUpdateMods_Coroutine(ILi // - Filter - RequestFilter userEventFilter = new RequestFilter(); userEventFilter.sortFieldName = GetUserEventsFilterFields.id; + userEventFilter.isSortAscending = false; userEventFilter.AddFieldFilter(GetUserEventsFilterFields.id, new MinimumFilter() { From 989ce2fee337b63a4197964d3d206bae5e0b7332 Mon Sep 17 00:00:00 2001 From: Jackson Wood Date: Thu, 10 Jun 2021 17:19:38 +1000 Subject: [PATCH 37/38] Implemented single-page result fetching for user events --- Runtime/ModManager.cs | 42 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/Runtime/ModManager.cs b/Runtime/ModManager.cs index c5362ec9..a662c8c4 100644 --- a/Runtime/ModManager.cs +++ b/Runtime/ModManager.cs @@ -1435,10 +1435,16 @@ public static System.Collections.IEnumerator DownloadAndUpdateMods_Coroutine(ILi filterValue = PluginSettings.GAME_ID, }); + var pagination = new APIPaginationParameters() + { + limit = APIPaginationParameters.LIMIT_MAX, + offset = 0, + }; + // - Get All Events - - ModManager.FetchAllResultsForQuery((p,s,e) => APIClient.GetUserEvents(userEventFilter, p, s, e), - onSuccess, - onError); + APIClient.GetUserEvents(userEventFilter, pagination, + (r) => ModManager._OnUserEventsFetched(r, onSuccess), + onError); } /// Fetches all user events for the authenticated user. @@ -1462,10 +1468,34 @@ public static System.Collections.IEnumerator DownloadAndUpdateMods_Coroutine(ILi filterValue = PluginSettings.GAME_ID, }); + var pagination = new APIPaginationParameters() + { + limit = APIPaginationParameters.LIMIT_MAX, + offset = 0, + }; + // - Get All Events - - ModManager.FetchAllResultsForQuery((p,s,e) => APIClient.GetUserEvents(userEventFilter, p, s, e), - onSuccess, - onError); + APIClient.GetUserEvents(userEventFilter, pagination, + (r) => ModManager._OnUserEventsFetched(r, onSuccess), + onError); + } + + /// Processes results from the events fetch results. + private static void _OnUserEventsFetched(RequestPage r, + Action> onSuccess) + { + if(onSuccess != null) + { + List eventList = new List(); + if(r != null + && r.items != null + && r.items.Length > 0) + { + eventList = new List(r.items); + } + + onSuccess.Invoke(eventList); + } } // ---------[ UPLOADING ]--------- From b0301583210e30859a55e107e6f1a897665d5b9d Mon Sep 17 00:00:00 2001 From: Jackson Wood Date: Thu, 10 Jun 2021 17:36:45 +1000 Subject: [PATCH 38/38] BugFix: DownloadAndUpdate now calls the callback on invalid auth --- Runtime/ModManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Runtime/ModManager.cs b/Runtime/ModManager.cs index a662c8c4..7d687aa2 100644 --- a/Runtime/ModManager.cs +++ b/Runtime/ModManager.cs @@ -577,7 +577,7 @@ public static System.Collections.IEnumerator DownloadAndUpdateMods_Coroutine(ILi { if(error.isAuthenticationInvalid) { - yield break; + isRequestResolved = true; } else if(error.isRequestUnresolvable) {