| | 1 | | using Cysharp.Threading.Tasks; |
| | 2 | | using System; |
| | 3 | | using UnityEngine; |
| | 4 | |
|
| | 5 | | namespace DCLServices.DCLFileBrowser |
| | 6 | | { |
| | 7 | | public class DCLFileBrowserServiceMock : IDCLFileBrowserService |
| | 8 | | { |
| 425 | 9 | | public void Initialize() { } |
| | 10 | |
|
| | 11 | | public string OpenSingleFile(string title, string directory, string defaultName, params ExtensionFilter[] extens |
| | 12 | | { |
| | 13 | | #if UNITY_EDITOR |
| 0 | 14 | | return $"{Application.persistentDataPath}/{directory}/{defaultName}"; |
| | 15 | | #endif |
| | 16 | | throw new NotImplementedException("Using mock implementation of DCLFileBrowserService in production"); |
| | 17 | | } |
| | 18 | |
|
| | 19 | | public void SaveFile(string title, string directory, string defaultName, byte[] content, params ExtensionFilter[ |
| | 20 | | { |
| | 21 | | #if UNITY_EDITOR |
| 0 | 22 | | defaultName = GetNameWithExtension(defaultName, extensions); |
| 0 | 23 | | var path = $"{Application.persistentDataPath}/{defaultName}"; |
| 0 | 24 | | System.IO.File.WriteAllBytes(path, content); |
| 0 | 25 | | Debug.Log($"Exported at {path}"); |
| 0 | 26 | | return; |
| | 27 | | #endif |
| | 28 | | throw new NotImplementedException("Using mock implementation of DCLFileBrowserService in production"); |
| | 29 | | } |
| | 30 | |
|
| | 31 | | public UniTask SaveFileAsync(string title, string directory, string defaultName, byte[] content, ExtensionFilter |
| | 32 | | { |
| | 33 | | #if UNITY_EDITOR |
| 0 | 34 | | defaultName = GetNameWithExtension(defaultName, extensions); |
| 0 | 35 | | var path = $"{Application.persistentDataPath}/{defaultName}"; |
| 0 | 36 | | System.IO.File.WriteAllBytes(path, content); |
| 0 | 37 | | Debug.Log($"Exported at {path}"); |
| 0 | 38 | | return UniTask.CompletedTask; |
| | 39 | | #endif |
| | 40 | | throw new NotImplementedException("Using mock implementation of DCLFileBrowserService in production"); |
| | 41 | | } |
| | 42 | |
|
| 425 | 43 | | public void Dispose() { } |
| | 44 | |
|
| | 45 | | private string GetNameWithExtension(string fileName, ExtensionFilter[] extensionsFilter) |
| | 46 | | { |
| 0 | 47 | | if (extensionsFilter.Length > 0 && extensionsFilter[0].Extensions.Length > 0 && !FileNameContainsAnyExtensi |
| | 48 | | { |
| 0 | 49 | | fileName += $".{extensionsFilter[0].Extensions[0]}"; |
| | 50 | | } |
| | 51 | |
|
| 0 | 52 | | return fileName; |
| | 53 | | } |
| | 54 | |
|
| | 55 | | private bool FileNameContainsAnyExtension(string fileName, ExtensionFilter[] extensionsFilter) |
| | 56 | | { |
| 0 | 57 | | foreach (ExtensionFilter extensionFilter in extensionsFilter) |
| | 58 | | { |
| 0 | 59 | | foreach (string extension in extensionFilter.Extensions) |
| | 60 | | { |
| 0 | 61 | | if (fileName.EndsWith(extension)) |
| 0 | 62 | | return true; |
| | 63 | | } |
| | 64 | | } |
| 0 | 65 | | return false; |
| | 66 | | } |
| | 67 | | } |
| | 68 | | } |