/// <summary>
    /// 获得构建版本
    /// </summary>
    /// <param name="versionOption"></param>
    /// <param name="customizeVersion"></param>
    /// <param name="buildTarget"></param>
    /// <returns></returns>
    public static AppVersion GetBuildVersion(VersionOption versionOption, AppVersion customizeVersion, BuildTarget buildTarget)
    {
        AppVersion lastBuildVersion = GetLastBuildVersion(buildTarget);
        AppVersion newVersion       = lastBuildVersion;

        switch (versionOption)
        {
        case VersionOption.PromotePatch:
        {
            if (lastBuildVersion == AppVersion.InitVersion)
            {
                Debug.Log("try check is first version build");
                // 是否是第一个版本,如果是就不增加补丁位。为了处理第一次打包
                string dir = PlatformEditorUtils.GetBuildToolVersionPatchDir(buildTarget, AppVersion.InitVersion);
                if (!Directory.Exists(dir) || Directory.GetDirectories(dir).Length == 0)
                {
                    Debug.Log("it's first version build");
                    break;
                }
            }
            newVersion.Revision += 1;
        }
        break;

        case VersionOption.PromoteMinorVersion:
        {
            newVersion.MinorVersion += 1;
            newVersion.Revision      = 0;
        }
        break;

        case VersionOption.PromoteLargeVersion:
        {
            newVersion.MajorVersion += 1;
            newVersion.MinorVersion  = 0;
            newVersion.Revision      = 0;
        }
        break;

        case VersionOption.CustomizeVersion:
        {
            newVersion = customizeVersion;
        }
        break;

        default:
            throw new ArgumentOutOfRangeException("versionOption", versionOption, null);
        }

        Debug.LogFormat("GetBuildVersion lastBuildVersion:{0}  newVersion:{1}", lastBuildVersion, newVersion);
        return(newVersion);
    }
    /// <summary>
    /// 获得先前的版本时间戳目录
    /// </summary>
    /// <returns></returns>
    private string GetPreviousLastestVersionPath(AppVersion previousVersion)
    {
        string previousVersionOutputRoot = PlatformEditorUtils.GetBuildToolVersionPatchDir(_buildTarget, previousVersion);

        var previousPaths = Directory.GetDirectories(previousVersionOutputRoot);

        if (previousPaths.Length == 0)
        {
            Debug.LogError("could not found previous version info:" + previousVersionOutputRoot);
            return(string.Empty);
        }

        // 根据时间戳升序,跟字符串序是一样
        Array.Sort(previousPaths);

        return(previousPaths[previousPaths.Length - 1]);
    }
    void OnError()
    {
        Debug.Log("补丁构建失败:" + _appVersion);
        FileUtils.DelDir(_currentBuildVersionRootPath);


        string path = PlatformEditorUtils.GetBuildToolVersionPatchDir(_buildTarget, _appVersion);

        if (Directory.Exists(path) && Directory.GetDirectories(path).Length == 0)
        {
            FileUtils.DelDir(path);
        }

        path = PlatformEditorUtils.GetBuildToolVersionMajorMinorDir(_buildTarget, _appVersion);
        if (Directory.Exists(path) && Directory.GetDirectories(path).Length == 0)
        {
            FileUtils.DelDir(path);
        }
    }
    public VersionPatchBuilder(BuildTarget buildTarget, AppVersion appVersion, long buildNum)
    {
        _appVersion      = appVersion;
        _buildNum        = buildNum;
        _buildTarget     = buildTarget;
        VersionOutputDir = PlatformEditorUtils.GetBuildToolVersionDir(buildTarget);
        FileUtils.CreateDirectory(VersionOutputDir);

        string versionOutputRoot = PlatformEditorUtils.GetBuildToolVersionPatchDir(_buildTarget, _appVersion);

        FileUtils.CreateDirectory(versionOutputRoot);

        _timeVersionDirName = string.Format("{0:yyyy-MM-dd hh_mm_ss}({1})", DateTime.Now, buildNum);

        // 以当前的时间戳来命名文件夹
        _currentBuildVersionRootPath = versionOutputRoot + "/" + _timeVersionDirName;

        FileUtils.CreateDirectory(_currentBuildVersionRootPath);
        FileUtils.CreateDirectory(PatchDir);
        FileUtils.CreateDirectory(SnapshotDir);
    }