You've already forked CC-Framework.CrashReport
131 lines
4.5 KiB
C#
131 lines
4.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using UnityEngine;
|
|
|
|
namespace CCFramework.CrashReport.Editor
|
|
{
|
|
[Serializable]
|
|
public sealed class CrashReportBuildSettings
|
|
{
|
|
public string lastBuildProfileName = string.Empty;
|
|
public List<CrashReportBuglyProfileSettings> profiles = new List<CrashReportBuglyProfileSettings>();
|
|
}
|
|
|
|
[Serializable]
|
|
public sealed class CrashReportBuglyProfileSettings
|
|
{
|
|
public string profileName = "default";
|
|
public bool enableAndroidSymbolArchive = true;
|
|
public bool androidAutoUploadSymbols = false;
|
|
public string buglyAppId = string.Empty;
|
|
public string buglyAppKey = string.Empty;
|
|
public string buglySymbolToolPath = "Tools/BuglySymbolTool/buglyqq-upload-symbol.jar";
|
|
public string buglyJavaPath = "java";
|
|
public bool enableIOSPod = true;
|
|
public string iosPodVersion = "~> 2.6";
|
|
public bool iosRunPodInstall = false;
|
|
public string podExecutablePath = "pod";
|
|
}
|
|
|
|
public static class CrashReportBuildSettingsStore
|
|
{
|
|
private const string SettingsDirectory = "ProjectSettings/CrashReport";
|
|
private const string SettingsFileName = "crashreport-build-settings.json";
|
|
|
|
public static string SettingsPath => Path.Combine(SettingsDirectory, SettingsFileName);
|
|
|
|
public static CrashReportBuildSettings Load()
|
|
{
|
|
if (!File.Exists(SettingsPath))
|
|
{
|
|
return new CrashReportBuildSettings();
|
|
}
|
|
|
|
try
|
|
{
|
|
string json = File.ReadAllText(SettingsPath);
|
|
CrashReportBuildSettings settings = JsonUtility.FromJson<CrashReportBuildSettings>(json);
|
|
return settings ?? new CrashReportBuildSettings();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Debug.LogWarning($"[CrashReport] 构建配置读取失败,将使用默认配置:{e.Message}");
|
|
return new CrashReportBuildSettings();
|
|
}
|
|
}
|
|
|
|
public static void Save(CrashReportBuildSettings settings)
|
|
{
|
|
if (!Directory.Exists(SettingsDirectory))
|
|
{
|
|
Directory.CreateDirectory(SettingsDirectory);
|
|
}
|
|
|
|
File.WriteAllText(SettingsPath, JsonUtility.ToJson(settings ?? new CrashReportBuildSettings(), true));
|
|
}
|
|
|
|
public static CrashReportBuglyProfileSettings GetProfileSettings(CrashReportBuildSettings settings, string profileName)
|
|
{
|
|
settings = settings ?? new CrashReportBuildSettings();
|
|
string key = string.IsNullOrWhiteSpace(profileName) ? "default" : profileName;
|
|
|
|
foreach (CrashReportBuglyProfileSettings profileSettings in settings.profiles)
|
|
{
|
|
if (profileSettings != null && string.Equals(profileSettings.profileName, key, StringComparison.Ordinal))
|
|
{
|
|
Normalize(profileSettings);
|
|
return profileSettings;
|
|
}
|
|
}
|
|
|
|
CrashReportBuglyProfileSettings created = new CrashReportBuglyProfileSettings
|
|
{
|
|
profileName = key
|
|
};
|
|
Normalize(created);
|
|
settings.profiles.Add(created);
|
|
return created;
|
|
}
|
|
|
|
public static CrashReportBuglyProfileSettings GetLastBuildProfileSettings()
|
|
{
|
|
CrashReportBuildSettings settings = Load();
|
|
return GetProfileSettings(settings, settings.lastBuildProfileName);
|
|
}
|
|
|
|
public static void Normalize(CrashReportBuglyProfileSettings settings)
|
|
{
|
|
if (settings == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (string.IsNullOrWhiteSpace(settings.profileName))
|
|
{
|
|
settings.profileName = "default";
|
|
}
|
|
|
|
if (string.IsNullOrWhiteSpace(settings.buglyJavaPath))
|
|
{
|
|
settings.buglyJavaPath = "java";
|
|
}
|
|
|
|
if (string.IsNullOrWhiteSpace(settings.buglySymbolToolPath))
|
|
{
|
|
settings.buglySymbolToolPath = "Tools/BuglySymbolTool/buglyqq-upload-symbol.jar";
|
|
}
|
|
|
|
if (string.IsNullOrWhiteSpace(settings.iosPodVersion))
|
|
{
|
|
settings.iosPodVersion = "~> 2.6";
|
|
}
|
|
|
|
if (string.IsNullOrWhiteSpace(settings.podExecutablePath))
|
|
{
|
|
settings.podExecutablePath = "pod";
|
|
}
|
|
}
|
|
}
|
|
}
|