Skip to content

Commit

Permalink
com.utilities.rest 3.2.2 (#85)
Browse files Browse the repository at this point in the history
- com.utilities.async -> 2.1.7
- com.utilities.extensions -> 1.1.16
- Added `DownloadCacheDirectory` Tests and clarified usage in docs
  • Loading branch information
StephenHodgson authored Aug 17, 2024
1 parent 391d6d6 commit 651bbf1
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 5 deletions.
9 changes: 9 additions & 0 deletions Documentation~/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
18 changes: 17 additions & 1 deletion Runtime/Rest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -511,13 +511,19 @@ private static IDownloadCache Cache

private static string downloadLocation = Application.temporaryCachePath;

/// <summary>
/// The top level directory to create the <see cref="download_cache"/> directory.
/// </summary>
public static string DownloadLocation
{
get => downloadLocation;
set
{
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
Expand All @@ -530,8 +536,18 @@ public static string DownloadLocation
/// <summary>
/// The download cache directory.<br/>
/// </summary>
/// <remarks>
/// This directory is a subdirectory of the <see cref="DownloadLocation"/> named <see cref="download_cache"/>.<br/>
/// </remarks>
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;
}
}

/// <summary>
/// Creates the <see cref="DownloadCacheDirectory"/> if it doesn't exist.
Expand Down
2 changes: 1 addition & 1 deletion Runtime/Utilities.Rest.asmdef
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Utilities.Rest",
"rootNamespace": "Utilities.Rest",
"rootNamespace": "Utilities.WebRequestRest",
"references": [
"GUID:a6609af893242c7438d701ddd4cce46a",
"GUID:84651a3751eca9349aac36a66bba901b"
Expand Down
8 changes: 8 additions & 0 deletions Tests.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions Tests/TestFixture_01_DownloadCache.cs
Original file line number Diff line number Diff line change
@@ -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));
}
}
}
11 changes: 11 additions & 0 deletions Tests/TestFixture_01_DownloadCache.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions Tests/Utilities.Rest.Tests.asmdef
Original file line number Diff line number Diff line change
@@ -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
}
7 changes: 7 additions & 0 deletions Tests/Utilities.Rest.Tests.asmdef.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down

0 comments on commit 651bbf1

Please sign in to comment.