Skip to content
This repository has been archived by the owner on Sep 21, 2022. It is now read-only.

Commit

Permalink
Merge pull request #74 from modio/cleanup
Browse files Browse the repository at this point in the history
Cleanup
  • Loading branch information
modio-jackson authored Feb 15, 2021
2 parents 52802c2 + 71660a5 commit 9387c77
Show file tree
Hide file tree
Showing 55 changed files with 199 additions and 187 deletions.
2 changes: 0 additions & 2 deletions Runtime/API Objects/GameProfile.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System;

using Newtonsoft.Json;

namespace ModIO
Expand Down
1 change: 0 additions & 1 deletion Runtime/API Objects/ModComment.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Runtime.Serialization;

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace ModIO
{
Expand Down
1 change: 0 additions & 1 deletion Runtime/API Objects/ModEvent.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Runtime.Serialization;

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace ModIO
{
Expand Down
1 change: 0 additions & 1 deletion Runtime/API Objects/ModRating.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Runtime.Serialization;

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace ModIO
{
Expand Down
1 change: 0 additions & 1 deletion Runtime/API Objects/ModTagCategory.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Runtime.Serialization;

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace ModIO
{
Expand Down
1 change: 0 additions & 1 deletion Runtime/API Objects/UserEvent.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Runtime.Serialization;

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace ModIO
{
Expand Down
3 changes: 0 additions & 3 deletions Runtime/API/RequestPage.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
using System.Collections;
using System.Collections.Generic;

using Newtonsoft.Json;

namespace ModIO
Expand Down
43 changes: 26 additions & 17 deletions Runtime/APIClient.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using ModIO.API;

using System;
using System.Collections;
using System.Collections.Generic;

using Newtonsoft.Json;
Expand Down Expand Up @@ -43,23 +42,33 @@ private struct GetRequestHandle
/// <summary>Header key for the external auth user consent value.</summary>
public static readonly string EXTERNAL_AUTH_CONSENT_KEY = "terms_agreed";

/// <summary>Platform header value.</summary>
/// <summary>Header key for the platform header.</summary>
public const string PLATFORM_HEADER_KEY = "x-modio-platform";

#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
public const string PLATFORM_HEADER = "windows_draft";
/// <summary>Platform header value. (Windows)</summary>
public const string PLATFORM_HEADER_VALUE = "windows_draft";
#elif UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
public const string PLATFORM_HEADER = "osx_draft";
/// <summary>Platform header value. (Mac OS)</summary>
public const string PLATFORM_HEADER_VALUE = "osx_draft";
#elif UNITY_EDITOR_LINUX || UNITY_STANDALONE_LINUX
public const string PLATFORM_HEADER = "linux_draft";
/// <summary>Platform header value. (Linux)</summary>
public const string PLATFORM_HEADER_VALUE = "linux_draft";
#elif UNITY_WII
public const string PLATFORM_HEADER = "wii_draft";
/// <summary>Platform header value. (Wii)</summary>
public const string PLATFORM_HEADER_VALUE = "wii_draft";
#elif UNITY_IOS
public const string PLATFORM_HEADER = "ios_draft";
/// <summary>Platform header value. (iOS)</summary>
public const string PLATFORM_HEADER_VALUE = "ios_draft";
#elif UNITY_ANDROID
public const string PLATFORM_HEADER = "android_draft";
/// <summary>Platform header value. (Android)</summary>
public const string PLATFORM_HEADER_VALUE = "android_draft";
#elif UNITY_PS4
public const string PLATFORM_HEADER = "ps4_draft";
/// <summary>Platform header value. (PS4)</summary>
public const string PLATFORM_HEADER_VALUE = "ps4_draft";
#elif UNITY_XBOXONE
public const string PLATFORM_HEADER = "xboxone_draft";
/// <summary>Platform header value. (Xbox One)</summary>
public const string PLATFORM_HEADER_VALUE = "xboxone_draft";
#endif

/// <summary>Collection of the HTTP request header keys used by mod.io.</summary>
Expand All @@ -70,7 +79,7 @@ private struct GetRequestHandle
"content-type",
"x-unity-version",
"user-agent",
"x-modio-platform",
APIClient.PLATFORM_HEADER_KEY,
APIClient.EXTERNAL_AUTH_CONSENT_KEY,
};

Expand Down Expand Up @@ -154,7 +163,7 @@ public static UnityWebRequest GenerateQuery(string endpointURL,

webRequest.SetRequestHeader("Accept-Language", APIClient.languageCode);
webRequest.SetRequestHeader("user-agent", APIClient.USER_AGENT_HEADER);
webRequest.SetRequestHeader("x-modio-platform", APIClient.PLATFORM_HEADER);
webRequest.SetRequestHeader(APIClient.PLATFORM_HEADER_KEY, APIClient.PLATFORM_HEADER_VALUE);

return webRequest;
}
Expand Down Expand Up @@ -185,7 +194,7 @@ public static UnityWebRequest GenerateGetRequest(string endpointURL,
webRequest.SetRequestHeader("Authorization", "Bearer " + LocalUser.OAuthToken);
webRequest.SetRequestHeader("Accept-Language", APIClient.languageCode);
webRequest.SetRequestHeader("user-agent", APIClient.USER_AGENT_HEADER);
webRequest.SetRequestHeader("x-modio-platform", APIClient.PLATFORM_HEADER);
webRequest.SetRequestHeader(APIClient.PLATFORM_HEADER_KEY, APIClient.PLATFORM_HEADER_VALUE);

return webRequest;
}
Expand All @@ -210,7 +219,7 @@ public static UnityWebRequest GeneratePutRequest(string endpointURL,
webRequest.SetRequestHeader("Authorization", "Bearer " + LocalUser.OAuthToken);
webRequest.SetRequestHeader("Accept-Language", APIClient.languageCode);
webRequest.SetRequestHeader("user-agent", APIClient.USER_AGENT_HEADER);
webRequest.SetRequestHeader("x-modio-platform", APIClient.PLATFORM_HEADER);
webRequest.SetRequestHeader(APIClient.PLATFORM_HEADER_KEY, APIClient.PLATFORM_HEADER_VALUE);

return webRequest;
}
Expand Down Expand Up @@ -243,7 +252,7 @@ public static UnityWebRequest GeneratePostRequest(string endpointURL,
webRequest.SetRequestHeader("Authorization", "Bearer " + LocalUser.OAuthToken);
webRequest.SetRequestHeader("Accept-Language", APIClient.languageCode);
webRequest.SetRequestHeader("user-agent", APIClient.USER_AGENT_HEADER);
webRequest.SetRequestHeader("x-modio-platform", APIClient.PLATFORM_HEADER);
webRequest.SetRequestHeader(APIClient.PLATFORM_HEADER_KEY, APIClient.PLATFORM_HEADER_VALUE);

return webRequest;
}
Expand All @@ -268,7 +277,7 @@ public static UnityWebRequest GenerateDeleteRequest(string endpointURL,
webRequest.SetRequestHeader("Authorization", "Bearer " + LocalUser.OAuthToken);
webRequest.SetRequestHeader("Accept-Language", APIClient.languageCode);
webRequest.SetRequestHeader("user-agent", APIClient.USER_AGENT_HEADER);
webRequest.SetRequestHeader("x-modio-platform", APIClient.PLATFORM_HEADER);
webRequest.SetRequestHeader(APIClient.PLATFORM_HEADER_KEY, APIClient.PLATFORM_HEADER_VALUE);

return webRequest;
}
Expand Down Expand Up @@ -601,7 +610,7 @@ public static UnityWebRequest GenerateAuthenticationRequest(string endpointURL,
UnityWebRequest webRequest = UnityWebRequest.Post(endpointURL, form);
webRequest.SetRequestHeader("Accept-Language", APIClient.languageCode);
webRequest.SetRequestHeader("user-agent", APIClient.USER_AGENT_HEADER);
webRequest.SetRequestHeader("x-modio-platform", APIClient.PLATFORM_HEADER);
webRequest.SetRequestHeader(APIClient.PLATFORM_HEADER_KEY, APIClient.PLATFORM_HEADER_VALUE);

return webRequest;
}
Expand Down
4 changes: 0 additions & 4 deletions Runtime/CacheClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@

using UnityEngine;

using Newtonsoft.Json;

using ModIO.API;

namespace ModIO
{
/// <summary>An interface for storing/loading data retrieved for the mod.io servers on disk.</summary>
Expand Down
1 change: 0 additions & 1 deletion Runtime/DataStorage/Callbacks/UserDataIOCallbacks.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;

namespace ModIO.UserDataIOCallbacks
{
Expand Down
38 changes: 30 additions & 8 deletions Runtime/DataStorage/DataStorage.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
using System;
using System.Text;
using System.Collections.Generic;

using UnityEngine;

using Newtonsoft.Json;

using ModIO.API;
using ModIO.PlatformIOCallbacks;

namespace ModIO
Expand All @@ -28,6 +20,36 @@ static DataStorage()
#else
DataStorage.PLATFORM_IO = new SystemIOWrapper();
#endif

#if DEBUG

// NOTE(@jackson): Due to hardcoded directory names the following configuration of
// directories causes errors during the mod installation process.

const string modCacheDir = "mods";

string cacheDirNoSep = DataStorage.PLATFORM_IO.CacheDirectory;
if(IOUtilities.PathEndsWithDirectorySeparator(cacheDirNoSep))
{
cacheDirNoSep = cacheDirNoSep.Substring(0, cacheDirNoSep.Length-1);
}

string installDirNoSep = DataStorage.PLATFORM_IO.InstallationDirectory;
if(IOUtilities.PathEndsWithDirectorySeparator(installDirNoSep))
{
installDirNoSep = installDirNoSep.Substring(0, installDirNoSep.Length-1);
}

if(System.IO.Path.GetDirectoryName(installDirNoSep) == cacheDirNoSep
&& installDirNoSep.Substring(cacheDirNoSep.Length+1) == modCacheDir)
{
Debug.LogError("[mod.io] The installation directory cannot be a directory named"
+ " 'mods' and a child of the cache directory as this will cause"
+ " issues during the installation process."
+ "\nPlease change the values in your PluginSettings.");
}

#endif
}

// ---------[ Data Management Interface ]---------
Expand Down
3 changes: 0 additions & 3 deletions Runtime/DataStorage/IPlatformIO.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
using System;
using System.Collections.Generic;

using ModIO.PlatformIOCallbacks;

namespace ModIO
Expand Down
3 changes: 3 additions & 0 deletions Runtime/DataStorage/IUserDataIO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ public interface IUserDataIO
string UserDirectory { get; }

// --- Initialization ---
/// <summary>Initializes the storage system for the defaul user.</summary>
void InitializeForDefaultUser(System.Action<bool> callback);

/// <summary>Initializes the storage system for the given user.</summary>
void SetActiveUser(string platformUserId, SetActiveUserCallback<string> callback);

Expand Down
13 changes: 13 additions & 0 deletions Runtime/DataStorage/Implementations/SystemIOWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,19 @@ void IPlatformIO.GetDirectories(string path,
public string UserDirectory { get; private set; }

// --- Initialization ---
/// <summary>Initializes the storage system for the defaul user.</summary>
public virtual void InitializeForDefaultUser(Action<bool> callback)
{
this.SetActiveUser(null,
(userId, success) =>
{
if(callback != null)
{
callback.Invoke(success);
}
});
}

/// <summary>Initializes the storage system for the given user.</summary>
public virtual void SetActiveUser(string platformUserId, UserDataIOCallbacks.SetActiveUserCallback<string> callback)
{
Expand Down
3 changes: 0 additions & 3 deletions Runtime/DataStorage/Implementations/SystemIOWrapper_Editor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
using UnityEngine;
using UnityEditor;

using System;
using System.Collections.Generic;

namespace ModIO
{
/// <summary>Wraps the System.IO functionality and adds AssetDatabase refreshes.</summary>
Expand Down
Loading

0 comments on commit 9387c77

Please sign in to comment.