-
Notifications
You must be signed in to change notification settings - Fork 1
feat: configuration manager offline mode (MAPCO-7262) #27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f65552c
0cf111b
e74d539
75ac0c0
caaffc7
ba71d44
cf4f7a0
ba78140
ac42d4a
3e400e6
99e69cb
80f0266
4a22626
7c58f6c
ad82b1a
7bead84
839b3bc
3e1004d
7655cb1
509bfc4
6a24b88
ea6bc38
93003d1
d8d36c4
f455b64
87e70a2
a018976
eaa871a
0012069
9fa9ee9
1a07c1d
898ee62
1c88d8d
8969c13
a331afd
81b8b6b
0913048
90ff3a6
9f35943
7eba1ce
4427201
ea50dbc
401bd39
c8e0ce3
5ee785b
8c21636
7a65e12
0612dd9
388693d
52610d1
5f11446
cf845a7
8b84cd2
096c5e6
3406001
5cd4dd0
784a789
cb42a4e
d933849
9caebcf
04db2d2
50c5cee
de84f71
1fe1d55
bdcb499
44177f9
1d64ca5
d54105e
e091e20
fbc974d
87ebec9
e5e9c4d
a334944
8666539
d45dec0
b54ada4
017445e
b7e1320
f5de997
09b110f
f275b5a
1e8bc78
04e00fe
11c85b7
c2f736e
d822a33
f454045
85ad47c
7220695
b5af15f
8531157
e31025c
87e9b0f
4d31485
9077ef1
0935e9c
1103914
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "userSettingsFile": "DataManagement/UserSettings/user_settings.json", | ||
| "offlineConfigurationFile": "DataManagement/offline_config.json", | ||
| "workspacesDirectory": "DataManagement/workspaces", | ||
| "remoteConfigurationUrl": "https://example.com/config/getConfig?v=10" | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "url": "https://www.google.com" | ||
asafMasa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| using System.IO; | ||
| using Cysharp.Threading.Tasks; | ||
| using Newtonsoft.Json; | ||
| using UnityEngine; | ||
| using UnityEngine.Networking; | ||
|
|
||
| namespace com.mapcolonies.core.Utilities | ||
| { | ||
| public enum FileLocation | ||
| { | ||
| StreamingAssets = 0, | ||
| PersistentData = 1 | ||
| } | ||
|
|
||
| public static class JsonUtilityEx | ||
| { | ||
| public static async UniTask<T> FromJsonFileAsync<T>(string path) | ||
| { | ||
| string json = await FileIOUtility.ReadTextFileAsync(path); | ||
| return JsonConvert.DeserializeObject<T>(json); | ||
| } | ||
|
|
||
| public static async UniTask SaveJsonToFileAsync<T>(string path, T data) | ||
| { | ||
| string json = JsonConvert.SerializeObject(data, Formatting.Indented); | ||
| await FileIOUtility.WriteTextFileAsync(path, json); | ||
| } | ||
|
|
||
| public static async UniTask<T> LoadRemoteJsonAsync<T>(string url) | ||
| { | ||
| using UnityWebRequest request = UnityWebRequest.Get(url); | ||
| await request.SendWebRequest(); | ||
|
|
||
| if (request.result != UnityWebRequest.Result.Success) | ||
| throw new IOException($"Failed to load remote JSON: {request.error}"); | ||
|
|
||
| return JsonConvert.DeserializeObject<T>(request.downloadHandler.text); | ||
| } | ||
|
|
||
|
|
||
| public static async UniTask<T> LoadJsonAsync<T>(string relativePath, FileLocation location = FileLocation.StreamingAssets) | ||
| { | ||
| string path; | ||
|
|
||
| switch (location) | ||
| { | ||
| case FileLocation.PersistentData: | ||
| path = Path.Combine(Application.persistentDataPath, relativePath); | ||
| break; | ||
| case FileLocation.StreamingAssets: | ||
| path = Path.Combine(Application.streamingAssetsPath, relativePath); | ||
| break; | ||
| default: | ||
| Debug.LogWarning($"Unknown file location {location}. Using streaming assets as default."); | ||
| path = Path.Combine(Application.streamingAssetsPath, relativePath); | ||
| break; | ||
| } | ||
|
|
||
| return await FromJsonFileAsync<T>(path); | ||
| } | ||
|
|
||
| public static async UniTask SaveJsonAsync<T>(string relativePath, T data) | ||
| { | ||
| string path = Path.Combine(Application.persistentDataPath, relativePath); | ||
| await SaveJsonToFileAsync(path, data); | ||
| } | ||
|
|
||
| public static async UniTask<bool> DoesJsonExistAsync(string relativePath, FileLocation location = FileLocation.PersistentData) | ||
| { | ||
| string path; | ||
|
|
||
| switch (location) | ||
| { | ||
| case FileLocation.PersistentData: | ||
| path = Path.Combine(Application.persistentDataPath, relativePath); | ||
| break; | ||
| case FileLocation.StreamingAssets: | ||
| path = Path.Combine(Application.streamingAssetsPath, relativePath); | ||
| break; | ||
| default: | ||
| Debug.LogWarning($"Unknown file location {location}. Using persistent data as default."); | ||
| path = Path.Combine(Application.persistentDataPath, relativePath); | ||
| break; | ||
| } | ||
|
|
||
| return await FileIOUtility.FileExistsAsync(path); | ||
| } | ||
| } | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.