196 lines
6.4 KiB
C#
196 lines
6.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using SRF;
|
|
using SRF.Service;
|
|
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
|
|
namespace SRDebugger.Services.Implementation
|
|
{
|
|
[Service(typeof(ISystemInformationService))]
|
|
public class StandardSystemInformationService : ISystemInformationService
|
|
{
|
|
private class Info : ISystemInfo
|
|
{
|
|
private Func<object> _valueGetter;
|
|
|
|
public string Title { get; set; }
|
|
|
|
public object Value
|
|
{
|
|
get
|
|
{
|
|
try
|
|
{
|
|
return _valueGetter();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return "Error ({0})".Fmt(ex.GetType().Name);
|
|
}
|
|
}
|
|
}
|
|
|
|
public bool IsPrivate { get; set; }
|
|
|
|
public static Info Create(string name, Func<object> getter, bool isPrivate = false)
|
|
{
|
|
Info info = new Info();
|
|
info.Title = name;
|
|
info._valueGetter = getter;
|
|
info.IsPrivate = isPrivate;
|
|
return info;
|
|
}
|
|
|
|
public static Info Create(string name, object value, bool isPrivate = false)
|
|
{
|
|
Info info = new Info();
|
|
info.Title = name;
|
|
info._valueGetter = () => value;
|
|
info.IsPrivate = isPrivate;
|
|
return info;
|
|
}
|
|
}
|
|
|
|
private readonly Dictionary<string, IList<ISystemInfo>> _info = new Dictionary<string, IList<ISystemInfo>>();
|
|
|
|
public StandardSystemInformationService()
|
|
{
|
|
CreateDefaultSet();
|
|
}
|
|
|
|
public IEnumerable<string> GetCategories()
|
|
{
|
|
return _info.Keys;
|
|
}
|
|
|
|
public IList<ISystemInfo> GetInfo(string category)
|
|
{
|
|
IList<ISystemInfo> value;
|
|
if (!_info.TryGetValue(category, out value))
|
|
{
|
|
Debug.LogError("[SystemInformationService] Category not found: {0}".Fmt(category));
|
|
return new ISystemInfo[0];
|
|
}
|
|
return value;
|
|
}
|
|
|
|
public Dictionary<string, Dictionary<string, object>> CreateReport(bool includePrivate = false)
|
|
{
|
|
Dictionary<string, Dictionary<string, object>> dictionary = new Dictionary<string, Dictionary<string, object>>();
|
|
foreach (KeyValuePair<string, IList<ISystemInfo>> item in _info)
|
|
{
|
|
Dictionary<string, object> dictionary2 = new Dictionary<string, object>();
|
|
foreach (ISystemInfo item2 in item.Value)
|
|
{
|
|
if (!item2.IsPrivate || includePrivate)
|
|
{
|
|
dictionary2.Add(item2.Title, item2.Value);
|
|
}
|
|
}
|
|
dictionary.Add(item.Key, dictionary2);
|
|
}
|
|
return dictionary;
|
|
}
|
|
|
|
private void CreateDefaultSet()
|
|
{
|
|
_info.Add("System", new Info[7]
|
|
{
|
|
Info.Create("Operating System", SystemInfo.operatingSystem),
|
|
Info.Create("Device Name", SystemInfo.deviceName, true),
|
|
Info.Create("Device Type", SystemInfo.deviceType),
|
|
Info.Create("Device Model", SystemInfo.deviceModel),
|
|
Info.Create("CPU Type", SystemInfo.processorType),
|
|
Info.Create("CPU Count", SystemInfo.processorCount),
|
|
Info.Create("System Memory", SRFileUtil.GetBytesReadable((long)SystemInfo.systemMemorySize * 1024L * 1024))
|
|
});
|
|
_info.Add("Unity", new Info[7]
|
|
{
|
|
Info.Create("Version", Application.unityVersion),
|
|
Info.Create("Debug", Debug.isDebugBuild),
|
|
Info.Create("Unity Pro", Application.HasProLicense()),
|
|
Info.Create("Genuine", "{0} ({1})".Fmt((!Application.genuine) ? "No" : "Yes", (!Application.genuineCheckAvailable) ? "Untrusted" : "Trusted")),
|
|
Info.Create("System Language", Application.systemLanguage),
|
|
Info.Create("Platform", Application.platform),
|
|
Info.Create("SRDebugger Version", "1.4.6")
|
|
});
|
|
_info.Add("Display", new Info[4]
|
|
{
|
|
Info.Create("Resolution", () => Screen.width + "x" + Screen.height),
|
|
Info.Create("DPI", () => Screen.dpi),
|
|
Info.Create("Fullscreen", () => Screen.fullScreen),
|
|
Info.Create("Orientation", () => Screen.orientation)
|
|
});
|
|
_info.Add("Runtime", new Info[4]
|
|
{
|
|
Info.Create("Play Time", () => Time.unscaledTime),
|
|
Info.Create("Level Play Time", () => Time.timeSinceLevelLoad),
|
|
Info.Create("Current Level", delegate
|
|
{
|
|
Scene activeScene = SceneManager.GetActiveScene();
|
|
return "{0} (Index: {1})".Fmt(activeScene.name, activeScene.buildIndex);
|
|
}),
|
|
Info.Create("Quality Level", () => QualitySettings.names[QualitySettings.GetQualityLevel()] + " (" + QualitySettings.GetQualityLevel() + ")")
|
|
});
|
|
TextAsset textAsset = (TextAsset)Resources.Load("UnityCloudBuildManifest.json");
|
|
Dictionary<string, object> dictionary = ((!(textAsset != null)) ? null : (Json.Deserialize(textAsset.text) as Dictionary<string, object>));
|
|
if (dictionary != null)
|
|
{
|
|
List<ISystemInfo> list = new List<ISystemInfo>(dictionary.Count);
|
|
foreach (KeyValuePair<string, object> item in dictionary)
|
|
{
|
|
if (item.Value != null)
|
|
{
|
|
string value = item.Value.ToString();
|
|
list.Add(Info.Create(GetCloudManifestPrettyName(item.Key), value));
|
|
}
|
|
}
|
|
_info.Add("Build", list);
|
|
}
|
|
_info.Add("Features", new Info[4]
|
|
{
|
|
Info.Create("Location", SystemInfo.supportsLocationService),
|
|
Info.Create("Accelerometer", SystemInfo.supportsAccelerometer),
|
|
Info.Create("Gyroscope", SystemInfo.supportsGyroscope),
|
|
Info.Create("Vibration", SystemInfo.supportsVibration)
|
|
});
|
|
_info.Add("Graphics", new Info[15]
|
|
{
|
|
Info.Create("Device Name", SystemInfo.graphicsDeviceName),
|
|
Info.Create("Device Vendor", SystemInfo.graphicsDeviceVendor),
|
|
Info.Create("Device Version", SystemInfo.graphicsDeviceVersion),
|
|
Info.Create("Max Tex Size", SystemInfo.maxTextureSize),
|
|
Info.Create("Fill Rate", (SystemInfo.graphicsPixelFillrate <= 0) ? "Unknown" : "{0}mpix/s".Fmt(SystemInfo.graphicsPixelFillrate)),
|
|
Info.Create("NPOT Support", SystemInfo.npotSupport),
|
|
Info.Create("Render Textures", "{0} ({1})".Fmt((!SystemInfo.supportsRenderTextures) ? "No" : "Yes", SystemInfo.supportedRenderTargetCount)),
|
|
Info.Create("3D Textures", SystemInfo.supports3DTextures),
|
|
Info.Create("Compute Shaders", SystemInfo.supportsComputeShaders),
|
|
Info.Create("Vertex Programs", SystemInfo.supportsVertexPrograms),
|
|
Info.Create("Image Effects", SystemInfo.supportsImageEffects),
|
|
Info.Create("Cubemaps", SystemInfo.supportsRenderToCubemap),
|
|
Info.Create("Shadows", SystemInfo.supportsShadows),
|
|
Info.Create("Stencil", SystemInfo.supportsStencil),
|
|
Info.Create("Sparse Textures", SystemInfo.supportsSparseTextures)
|
|
});
|
|
}
|
|
|
|
private static string GetCloudManifestPrettyName(string name)
|
|
{
|
|
switch (name)
|
|
{
|
|
case "scmCommitId":
|
|
return "Commit";
|
|
case "scmBranch":
|
|
return "Branch";
|
|
case "cloudBuildTargetName":
|
|
return "Build Target";
|
|
case "buildStartTime":
|
|
return "Build Date";
|
|
default:
|
|
return name.Substring(0, 1).ToUpper() + name.Substring(1);
|
|
}
|
|
}
|
|
}
|
|
}
|