File size: 3,809 Bytes
18a519f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | using UnityEditor.SettingsManagement;
using UnityEditor.TestTools.CodeCoverage.Utils;
namespace UnityEditor.TestTools.CodeCoverage
{
internal class CoveragePreferences : CoveragePreferencesImplementation
{
private static CoveragePreferences s_Instance = null;
private const string k_PackageName = "com.unity.testtools.codecoverage";
public static CoveragePreferences instance
{
get
{
if (s_Instance == null)
s_Instance = new CoveragePreferences();
return s_Instance;
}
}
protected CoveragePreferences() : base(k_PackageName)
{
}
}
internal class CoveragePreferencesImplementation
{
private const string k_ProjectPathAlias = "{ProjectPath}";
protected Settings m_Settings;
public CoveragePreferencesImplementation(string packageName)
{
m_Settings = new Settings(packageName);
}
public bool GetBool(string key, bool defaultValue, SettingsScope scope = SettingsScope.Project)
{
if (m_Settings.ContainsKey<bool>(key, scope))
{
return m_Settings.Get<bool>(key, scope, defaultValue);
}
return defaultValue;
}
public int GetInt(string key, int defaultValue, SettingsScope scope = SettingsScope.Project)
{
if (m_Settings.ContainsKey<int>(key, scope))
{
return m_Settings.Get<int>(key, scope, defaultValue);
}
return defaultValue;
}
public string GetStringForPaths(string key, string defaultValue, SettingsScope scope = SettingsScope.Project)
{
string value = GetString(key, defaultValue, scope);
value = value.Replace(k_ProjectPathAlias, CoverageUtils.GetProjectPath());
return value;
}
public string GetString(string key, string defaultValue, SettingsScope scope = SettingsScope.Project)
{
if (m_Settings.ContainsKey<string>(key, scope))
{
return m_Settings.Get<string>(key, scope, defaultValue);
}
return defaultValue;
}
public void SetBool(string key, bool value, SettingsScope scope = SettingsScope.Project)
{
m_Settings.Set<bool>(key, value, scope);
m_Settings.Save();
}
public void SetInt(string key, int value, SettingsScope scope = SettingsScope.Project)
{
m_Settings.Set<int>(key, value, scope);
m_Settings.Save();
}
public void SetStringForPaths(string key, string value, SettingsScope scope = SettingsScope.Project)
{
value = CoverageUtils.NormaliseFolderSeparators(value, false);
value = value.Replace(CoverageUtils.GetProjectPath(), k_ProjectPathAlias);
SetString(key, value, scope);
}
public void SetString(string key, string value, SettingsScope scope = SettingsScope.Project)
{
m_Settings.Set<string>(key, value, scope);
m_Settings.Save();
}
public void DeleteBool(string key, SettingsScope scope = SettingsScope.Project)
{
m_Settings.DeleteKey<bool>(key, scope);
m_Settings.Save();
}
public void DeleteInt(string key, SettingsScope scope = SettingsScope.Project)
{
m_Settings.DeleteKey<int>(key, scope);
m_Settings.Save();
}
public void DeleteString(string key, SettingsScope scope = SettingsScope.Project)
{
m_Settings.DeleteKey<string>(key, scope);
m_Settings.Save();
}
}
}
|