using XGame.Editor.Asset;
using System;

namespace XGame.Editor.Build
{
    [BuildCommand((uint)BuildCommandPriority.BuildPostProcessor)]
    class CmdBuildPostProcessor : BaseBuildCommand, ICommandExecuter
    {
        public BuildErrorCode Execute()
        {
            try
            {
                var abOutputPathPath = PathDefine.AssetBundleOutputPath;
                if (System.IO.Directory.Exists(abOutputPathPath))
                {
                    // 把ab输出目录也删了
                    UnityEditor.FileUtil.DeleteFileOrDirectory(abOutputPathPath);
                }
                //打包完删除streamingAssetsPath
                if (System.IO.Directory.Exists(UnityEngine.Application.streamingAssetsPath))
                {
                    UnityEditor.FileUtil.DeleteFileOrDirectory(UnityEngine.Application.streamingAssetsPath);
                    UnityEditor.AssetDatabase.Refresh();
                }
                if (!Context.config.project.isSaveSpriteAtlas)
                {
                    (new Asset.Tools.SpriteAtlasClearTask()).Run();
                }
            }
            catch (Exception ex)
            {
                BuildLog.Exception(ex);
            }
            BuildLog.Log("CmdBuildPostProcessor Finish.");
            return BuildErrorCode.CmdCompleted;
        }
    }
}
