diff --git a/Documentation~/README.md b/Documentation~/README.md index d9352db..7d4f49f 100644 --- a/Documentation~/README.md +++ b/Documentation~/README.md @@ -170,6 +170,15 @@ response.Validate(debug: true); #### Caching +You can set the parent directory of the download cache to one of the following predefined locations: + +- `Application.temporaryCachePath` (default) +- `Application.persistentDataPath` +- `Application.dataPath` +- `Application.streamingAssetsPath` + +The actual cache directory will be a subfolder named `download_cache` inside of the parent `DownloadCacheDirectory`. + ```csharp // cache directory defaults to {Application.temporaryCachePath}/download_cache/ Debug.Log(Rest.DownloadCacheDirectory); diff --git a/Runtime/Rest.cs b/Runtime/Rest.cs index 4a1e798..b06e507 100644 --- a/Runtime/Rest.cs +++ b/Runtime/Rest.cs @@ -511,6 +511,9 @@ private static IDownloadCache Cache private static string downloadLocation = Application.temporaryCachePath; + /// + /// The top level directory to create the directory. + /// public static string DownloadLocation { get => downloadLocation; @@ -518,6 +521,9 @@ public static string DownloadLocation { if (allowedDownloadLocations.Contains(value)) { + if (downloadLocation == value) { return; } + var downloadCacheDirectory = Path.Combine(downloadLocation, download_cache); + if (Directory.Exists(downloadCacheDirectory)) { Directory.Delete(downloadCacheDirectory, true); } downloadLocation = value; } else @@ -530,8 +536,18 @@ public static string DownloadLocation /// /// The download cache directory.
///
+ /// + /// This directory is a subdirectory of the named .
+ ///
public static string DownloadCacheDirectory - => Path.Combine(DownloadLocation, download_cache); + { + get + { + var downloadCacheDirectory = Path.Combine(DownloadLocation, download_cache); + if (!Directory.Exists(downloadCacheDirectory)) { Directory.CreateDirectory(downloadCacheDirectory); } + return downloadCacheDirectory; + } + } /// /// Creates the if it doesn't exist. diff --git a/Runtime/Utilities.Rest.asmdef b/Runtime/Utilities.Rest.asmdef index 032a258..3d3b7bb 100644 --- a/Runtime/Utilities.Rest.asmdef +++ b/Runtime/Utilities.Rest.asmdef @@ -1,6 +1,6 @@ { "name": "Utilities.Rest", - "rootNamespace": "Utilities.Rest", + "rootNamespace": "Utilities.WebRequestRest", "references": [ "GUID:a6609af893242c7438d701ddd4cce46a", "GUID:84651a3751eca9349aac36a66bba901b" diff --git a/Tests.meta b/Tests.meta new file mode 100644 index 0000000..1735409 --- /dev/null +++ b/Tests.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 7d13e97320d46454aa91ff59fe5892ea +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Tests/TestFixture_01_DownloadCache.cs b/Tests/TestFixture_01_DownloadCache.cs new file mode 100644 index 0000000..a4c8982 --- /dev/null +++ b/Tests/TestFixture_01_DownloadCache.cs @@ -0,0 +1,38 @@ +// Licensed under the MIT License. See LICENSE in the project root for license information. + +using NUnit.Framework; +using System.IO; +using UnityEngine; + +namespace Utilities.WebRequestRest.Tests +{ + public class TestFixture_01_DownloadCache + { + [Test] + public void TestFixture_01_DownloadCache_Locations() + { + Debug.Log(Rest.DownloadLocation); + Debug.Log(Rest.DownloadCacheDirectory); + Assert.IsTrue(Rest.DownloadLocation == Application.temporaryCachePath); + Assert.IsTrue(Directory.Exists(Rest.DownloadCacheDirectory)); + + Rest.DownloadLocation = Application.persistentDataPath; + Debug.Log(Rest.DownloadLocation); + Debug.Log(Rest.DownloadCacheDirectory); + Assert.IsTrue(Rest.DownloadLocation == Application.persistentDataPath); + Assert.IsTrue(Directory.Exists(Rest.DownloadCacheDirectory)); + + Rest.DownloadLocation = Application.dataPath; + Debug.Log(Rest.DownloadLocation); + Debug.Log(Rest.DownloadCacheDirectory); + Assert.IsTrue(Rest.DownloadLocation == Application.dataPath); + Assert.IsTrue(Directory.Exists(Rest.DownloadCacheDirectory)); + + Rest.DownloadLocation = Application.streamingAssetsPath; + Debug.Log(Rest.DownloadLocation); + Debug.Log(Rest.DownloadCacheDirectory); + Assert.IsTrue(Rest.DownloadLocation == Application.streamingAssetsPath); + Assert.IsTrue(Directory.Exists(Rest.DownloadCacheDirectory)); + } + } +} diff --git a/Tests/TestFixture_01_DownloadCache.cs.meta b/Tests/TestFixture_01_DownloadCache.cs.meta new file mode 100644 index 0000000..f0f110b --- /dev/null +++ b/Tests/TestFixture_01_DownloadCache.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 2e12af5a82032324c884338f335de705 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Tests/Utilities.Rest.Tests.asmdef b/Tests/Utilities.Rest.Tests.asmdef new file mode 100644 index 0000000..54f6487 --- /dev/null +++ b/Tests/Utilities.Rest.Tests.asmdef @@ -0,0 +1,25 @@ +{ + "name": "Utilities.Rest.Tests", + "rootNamespace": "Utilities.WebRequest.Tests", + "references": [ + "GUID:27619889b8ba8c24980f49ee34dbb44a", + "GUID:0acc523941302664db1f4e527237feb3", + "GUID:7958db66189566541a6363568aee1575", + "GUID:28b599e4adde9c94a9b9667d7b08fe83" + ], + "includePlatforms": [ + "Editor" + ], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": true, + "precompiledReferences": [ + "nunit.framework.dll" + ], + "autoReferenced": false, + "defineConstraints": [ + "UNITY_INCLUDE_TESTS" + ], + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file diff --git a/Tests/Utilities.Rest.Tests.asmdef.meta b/Tests/Utilities.Rest.Tests.asmdef.meta new file mode 100644 index 0000000..f526ab5 --- /dev/null +++ b/Tests/Utilities.Rest.Tests.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 1000ed716ff71cd47a9ef685869d4e41 +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/package.json b/package.json index 12778a5..56c091b 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "displayName": "Utilities.Rest", "description": "This package contains useful RESTful utilities for the Unity Game Engine.", "keywords": [], - "version": "3.2.1", + "version": "3.2.2", "unity": "2021.3", "documentationUrl": "https://github.com/RageAgainstThePixel/com.utilities.rest#documentation", "changelogUrl": "https://github.com/RageAgainstThePixel/com.utilities.rest/releases", @@ -15,8 +15,8 @@ "author": "Stephen Hodgson", "url": "https://github.com/StephenHodgson", "dependencies": { - "com.utilities.async": "2.1.6", - "com.utilities.extensions": "1.1.15", + "com.utilities.async": "2.1.7", + "com.utilities.extensions": "1.1.16", "com.unity.modules.unitywebrequest": "1.0.0", "com.unity.modules.unitywebrequestassetbundle": "1.0.0", "com.unity.modules.unitywebrequestaudio": "1.0.0",