少年修仙传客户端基础资源
liuxue
2021-07-26 fb7bcf7867266056d87042aaca3fb03a1fe0add6
0000 增加bugly功能
5个文件已添加
275 ■■■■■ 已修改文件
Assets/Editor/bugly.meta 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Assets/Editor/bugly/FileTool.cs 106 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Assets/Editor/bugly/FileTool.cs.meta 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Assets/Editor/bugly/UpLoadBuglySo.cs 139 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Assets/Editor/bugly/UpLoadBuglySo.cs.meta 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Assets/Editor/bugly.meta
New file
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 3140bbaa075328b4d941950eec5a906d
folderAsset: yes
DefaultImporter:
  externalObjects: {}
  userData:
  assetBundleName:
  assetBundleVariant:
Assets/Editor/bugly/FileTool.cs
New file
@@ -0,0 +1,106 @@
using System.Collections.Generic;
using System.IO;
using UnityEditor;
using Debug = UnityEngine.Debug;
public class FileTool
{
    public static bool CheckFolder(string path){
        if (Directory.Exists(path)) {
            return true;
        }
        UnityEditor.EditorUtility.DisplayDialog("Error", "Path does not exist \n\t" + path, "确认");
        return false;
    }
    public static void OpenFolder(string path){
        if (CheckFolder(path)) {
            System.Diagnostics.Process.Start( path);
        }
    }
    public static void CopyFolder(Dictionary<string, string> copyDic){
        foreach (KeyValuePair<string, string> path in copyDic) {
            if (CheckFolder(path.Key)) {
                CopyDir(path.Key, path.Value);
                Debug.Log("Copy Success : \n\tFrom:" + path.Key + " \n\tTo:" + path.Value);
            }
        }
        EditorUtility.ClearProgressBar();
    }
    public static void CopyFolder(string fromPath, string toPath){
        CopyDir(fromPath, toPath);
        Debug.Log("Copy Success : \n\tFrom:" + fromPath + " \n\tTo:" + toPath);
        EditorUtility.ClearProgressBar();
    }
    public static void CreateFolder(string path){
        if (Directory.Exists(path)) {
            Directory.Delete(path, true);
        }
        Directory.CreateDirectory(path);
    }
    public static void DeleteFolder(string path){
        if (Directory.Exists(path)) {
            Directory.Delete(path, true);
        }
    }
    private static void CopyDir(string origin, string target){
#if UNITY_IOS
        if (!origin.EndsWith("/"))
        {
            origin += "/";
        }
        if (!target.EndsWith("/"))
        {
            target += "/";
        }
#else
          if (!origin.EndsWith("\\")) {
            origin += "\\";
        }
        if (!target.EndsWith("\\")) {
            target += "\\";
        }
#endif
        if (!Directory.Exists(target)) {
            Directory.CreateDirectory(target);
        }
        DirectoryInfo info = new DirectoryInfo(origin);
        FileInfo[] fileList = info.GetFiles();
        DirectoryInfo[] dirList = info.GetDirectories();
        float index = 0;
        foreach (FileInfo fi in fileList) {
            if (fi.Extension == ".zip" || fi.Extension == ".meta"|| fi.Extension == ".rar") {
                Debug.Log("dont copy :"+fi.FullName);
                continue;
            }
            float progress = (index / (float)fileList.Length);
            EditorUtility.DisplayProgressBar("Copy ", "Copying: "+Path.GetFileName(fi.FullName),progress);
            File.Copy(fi.FullName, target + fi.Name, true);
            index++;
        }
        foreach (DirectoryInfo di in dirList) {
            if (di.FullName.Contains(".svn")) {
                Debug.Log("Continue SVN "+di.FullName);
                continue;
            }
            CopyDir(di.FullName, target + "\\" + di.Name);
        }
    }
}
Assets/Editor/bugly/FileTool.cs.meta
New file
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6ea4eacde18633e4da1f62f98e089004
MonoImporter:
  externalObjects: {}
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}
  userData:
  assetBundleName:
  assetBundleVariant:
Assets/Editor/bugly/UpLoadBuglySo.cs
New file
@@ -0,0 +1,139 @@
using System.Diagnostics;
using System.IO;
using System.Text;
using UnityEditor;
using UnityEngine;
using Debug = UnityEngine.Debug;
public class UpLoadBuglySo
{
    private static string[] soFolders = {"arm64-v8a", "armeabi-v7a","unity"};
    private static string soCmdAnroid =
        "java -jar buglyqq-upload-symbol.jar -inputSymbol #SOPATH# -appid #ID# -appkey #KEY# -bundleid #BUNDLEID# -version #VERSION# -platform Android";
    private static string soCmdIOS =
        "java -jar buglyqq-upload-symbol.jar -inputSymbol ./IOS/UnityFramework.framework.dSYM -appid #ID# -appkey #KEY# -bundleid #BUNDLEID# -version #VERSION# -platform IOS";
    /// <summary>
    /// 打完包后调用此方法 自动上传符号表文件
    /// </summary>
    [MenuItem("Tools/自动上传符号表/Android", priority = 2049)]
    public static void UploadAndroidBuglyso(){
        DeleteSo();
        CopyBuglySo();
        if (EditCommand(out string arg)) {
            Debug.Log("EditCommand: " + arg);
            RunCmd(arg, BuglyToolPath());
        }
    }
    [MenuItem("Tools/自动上传符号表/IOS", priority = 2049)]
    public static void UploadIOSBuglyso()
    {
        if (EditCommandIOS(out string arg))
        {
            Debug.Log("EditCommand: " + arg);
            RunCmd(arg, BuglyToolPath());
        }
    }
    private static void CopyBuglySo(){
        FileTool.CopyFolder(DeBugSOPath(), BuglyToolPath() + "/Android/");
        FileTool.OpenFolder(BuglyToolPath());
    }
    private static void DeleteSo(){
        foreach (var folder in soFolders) {
            FileTool.DeleteFolder(BuglyToolPath() + "/Android/");
        }
    }
    private static bool EditCommand(out string arg){
        bool exists = false;
        var versionInfo = StringUtility.Contact(VersionConfig.Get().version, "_", VersionConfig.Get().buildIndex, "_", VersionConfig.Get().buildTime);
        StringBuilder sb = new StringBuilder();
        foreach (var folder in soFolders)
        {
            exists = true;
            sb.Append(soCmdAnroid).Append(" & ");
            if(folder == "unity")
            {
                sb.Replace("#SOPATH#", "libunity.sym.so");
            }
            else
            {
                string soPath = BuglyToolPath() + "/Android/" + folder ;
                if (FileTool.CheckFolder(soPath))
                {
                    soPath = soPath + "/libil2cpp.sym.so";
                    sb.Replace("#SOPATH#", soPath);
                }
                else
                {
                    exists = false;
                    break;
                }
            }
            sb.Replace("#ID#", ExceptionCatcher.AppIDAndroid);  //这里注意一下要改成自己的id
            sb.Replace("#KEY#", ExceptionCatcher.AppKeyAndroid); //自己的key
            sb.Replace("#BUNDLEID#", VersionConfig.Get().appId);
            sb.Replace("#VERSION#", versionInfo);
        }
        sb.Append("exit").Replace("/", @"\");
        arg = sb.ToString();
        return exists;
    }
    private static bool EditCommandIOS(out string arg)
    {
        bool exists = true;
        var versionInfo = StringUtility.Contact(VersionConfig.Get().version, "_", VersionConfig.Get().buildIndex, "_", VersionConfig.Get().buildTime);
        StringBuilder sb = new StringBuilder();
        sb.Append(soCmdIOS).Append(" & ");
        sb.Replace("#ID#", ExceptionCatcher.AppIDIOS);  //这里注意一下要改成自己的id
        sb.Replace("#KEY#", ExceptionCatcher.AppKeyIOS); //自己的key
        sb.Replace("#BUNDLEID#", VersionConfig.Get().appId);
        sb.Replace("#VERSION#", versionInfo);
        sb.Append("exit").Replace("/", @"\");
        arg = sb.ToString();
        return exists;
    }
    public static string DeBugSOPath(){
        return Path.GetFullPath(Application.dataPath + "/../Temp/StagingArea/symbols");
    }
    public static string BuglyToolPath(){
        return Path.GetFullPath(Application.dataPath + "/../buglytools");
    }
    public static void RunCmd(string arg, string workingDirectory,string exe ="cmd.exe"){
        ProcessStartInfo info = new ProcessStartInfo(exe);
        info.Arguments = "/c " + arg;
        info.WorkingDirectory = workingDirectory;
        info.CreateNoWindow = false;
        info.ErrorDialog = true;
        info.UseShellExecute = true;
        if (info.UseShellExecute) {
            info.RedirectStandardOutput = false;
            info.RedirectStandardError = false;
            info.RedirectStandardInput = false;
        }
        else {
            info.RedirectStandardOutput = true;
            info.RedirectStandardError = true;
            info.RedirectStandardInput = true;
            info.StandardOutputEncoding = System.Text.UTF8Encoding.UTF8;
            info.StandardErrorEncoding = System.Text.UTF8Encoding.UTF8;
        }
        Debug.Log("RunCmd: "+info.Arguments);
        Process process = Process.Start(info);
        if (!info.UseShellExecute) {
            Debug.Log(process.StandardOutput);
            Debug.Log(process.StandardError);
        }
        process.WaitForExit();
        process.Close();
    }
}
Assets/Editor/bugly/UpLoadBuglySo.cs.meta
New file
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 96f47911762121d4781e591f7e86f21b
MonoImporter:
  externalObjects: {}
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}
  userData:
  assetBundleName:
  assetBundleVariant: