< Summary

Class:WebGLFileSaver
Assembly:DCLFileBrowser
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLServices/DCLFileBrowser/WebGLFileSaverForUnity/WebGLFileSaver.cs
Covered lines:0
Uncovered lines:32
Coverable lines:32
Total lines:89
Line coverage:0% (0 of 32)
Covered branches:0
Total branches:0
Covered methods:0
Total methods:5
Method coverage:0% (0 of 5)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
SaveFile(...)0%6200%
SaveFile(...)0%12300%
CheckSupportAndInit()0%20400%
CheckInit()0%6200%
IsSavingSupported()0%12300%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLServices/DCLFileBrowser/WebGLFileSaverForUnity/WebGLFileSaver.cs

#LineLine coverage
 1using System.Collections;
 2using System.Collections.Generic;
 3using UnityEngine;
 4using System.Runtime.InteropServices;
 5
 6public class WebGLFileSaver
 7{
 8
 9    [DllImport("__Internal")]
 10    private static extern void UNITY_SAVE(string content, string name, string MIMEType);
 11
 12    [DllImport ("__Internal")]
 13    private static extern void UNITY_SAVE_BYTEARRAY(byte[] array, int byteLength, string name, string MIMEType);
 14
 15    [DllImport("__Internal")]
 16    private static extern void init();
 17
 18    [DllImport("__Internal")]
 19    private static extern bool UNITY_IS_SUPPORTED();
 20
 21    static bool hasinit = false;
 22
 23    public static void SaveFile(string content, string fileName, string MIMEType = "text/plain;charset=utf-8")
 24    {
 025       if (!CheckSupportAndInit()) return;
 26
 027        UNITY_SAVE (content, fileName, MIMEType);
 028    }
 29
 30    public static void SaveFile(byte[] content, string fileName, string MIMEType = "text/plain;charset=utf-8")
 31    {
 032        if (content == null)
 33        {
 034            Debug.LogError("null parameter passed for content byte array");
 035            return;
 36        }
 037        if (!CheckSupportAndInit()) return;
 38
 039        UNITY_SAVE_BYTEARRAY (content, content.Length, fileName, MIMEType);
 040    }
 41
 42    static bool CheckSupportAndInit()
 43    {
 044        if (Application.isEditor)
 45        {
 046            Debug.Log("Saving will not work in editor.");
 047            return false;
 48        }
 049        if (Application.platform != RuntimePlatform.WebGLPlayer)
 50        {
 051            Debug.Log("Saving must be on a WebGL build.");
 052            return false;
 53        }
 54
 055        CheckInit();
 56
 057        if (!IsSavingSupported())
 58        {
 059            Debug.LogWarning("Saving is not supported on this device.");
 060            return false;
 61        }
 062        return true;
 63    }
 64
 65    static void CheckInit()
 66    {
 067        if (!hasinit)
 68        {
 069            init();
 070            hasinit = true;
 71        }
 072    }
 73
 74    public static bool IsSavingSupported()
 75    {
 076        if (Application.isEditor)
 77        {
 078            Debug.Log("Saving will not work in editor.");
 079            return false;
 80        }
 081        if (Application.platform != RuntimePlatform.WebGLPlayer)
 82        {
 083            Debug.Log("Saving must be on a WebGL build.");
 084            return false;
 85        }
 086        CheckInit();
 087        return UNITY_IS_SUPPORTED();
 88    }
 89}