示例#1
0
        public static void AssetMovein()
        {
            System.GC.Collect();
            System.GC.Collect();

            ReadFile();
            ParseAllDir();
            RootFolderNmae();
            ParseTheVersion();
            FilesFilter();

            string path = string.Format("{0}/../../../temp/", Application.dataPath);

            if (!Directory.Exists(path))
            {
                return;
            }
            ABHelper.DirectoryMove(path, Application.dataPath + "/");
            ABHelper.DirectoryMove(string.Format("{0}/{1}", Application.dataPath, "ProjectSettings"), string.Format("{0}/../{1}", Application.dataPath, "ProjectSettings"));
            Directory.Delete(string.Format("{0}/{1}", Application.dataPath, "ProjectSettings"), true);

            AssetDatabase.Refresh();
            AssetDatabase.SaveAssets();

            System.GC.Collect();
            Debug.Log("资源移入成功!!");
        }
示例#2
0
        private static void ReadFile()
        {
            string s = ABHelper.ReadFile(Application.dataPath + "/Editor/ABStreaming.txt");

            string[] sp = s.TrimEnd().Replace("\r", "").Split('\n');
            string[] sp1;
            foreach (var v in sp)
            {
                if (string.IsNullOrEmpty(v))
                {
                    continue;
                }
                sp1 = v.Split('=');

                switch (sp1[0])
                {
                case "UseAssetsDir": UseAssetDirStr = sp1[1]; break;

                case "NotRemoveDir": NotRemoveDirStr = sp1[1]; break;

                case "NotRemoveFile": NotRemoveFileStr = sp1[1]; break;

                default: break;
                }
            }
        }
示例#3
0
        public static Dictionary <string, List <string> > ReadDependFile(string filePath)
        {
            Dictionary <string, List <string> > depenInfo = new Dictionary <string, List <string> >();

            string dependTxt = ABHelper.ReadFile(filePath);

            if (!string.IsNullOrEmpty(dependTxt))
            {
                // assets/resources/ui/tips:assets/resources/ui/tips/tips.bytes,assets/resources/ui/tips/tips@atlas2!a.png
                string[] split = dependTxt.Split('\r');
                foreach (string k in split)
                {
                    string[] split2 = k.Split(':');
                    if (!depenInfo.ContainsKey(split2[0]))
                    {
                        depenInfo.Add(split2[0], new List <string>());
                    }

                    string[] split3 = split2[1].Split(',');
                    foreach (string k3 in split3)
                    {
                        depenInfo[split2[0]].Add(k3);
                    }
                }
            }

            return(depenInfo);
        }
示例#4
0
        public static Dictionary <string, List <string> > ReadVersionFile(string filePath)
        {
            Dictionary <string, List <string> > versionInfo = new Dictionary <string, List <string> >();

            byte[] versionbytes = ABHelper.ReadFileToBytes(filePath);
            if (null == versionbytes)
            {
                return(versionInfo);
            }

            Encrypt(ref versionbytes); //RC4 加密文件
            string versionTxt = Encoding.UTF8.GetString(versionbytes);

            if (!string.IsNullOrEmpty(versionTxt))
            {
                //ui/tips.ab:ba2de82e3fc42e750d317b133096dfea:0:22455:fa7917d4974436b1214dc313fccda2a5
                //路径:内容md5:版号:size:路径md5
                string[] split = versionTxt.Split('\r');
                foreach (string k in split)
                {
                    string[] split2 = k.Split(':');
                    versionInfo.Add(split2[0], new List <string>()
                    {
                        split2[1], split2[2], split2[3], split2[4]
                    });
                }
            }

            return(versionInfo);
        }
示例#5
0
        private static void ReadBuildTxt()
        {
            string s = ABHelper.ReadFile(Application.dataPath + "/Editor/BuildAppSteps.txt");

            string[] sp = s.TrimEnd().Replace("\r", "").Split('\n');
            string[] sp1;
            foreach (var v in sp)
            {
                if (string.IsNullOrEmpty(v))
                {
                    continue;
                }
                sp1 = v.Split('=');

                switch (sp1[0])
                {
                case "commandBuildApp": m_commandBuildApp = bool.Parse(sp1[1]); break;

                case "buildApp": m_buildApp = bool.Parse(sp1[1]); break;

                case "xluaGen": m_xluaGen = bool.Parse(sp1[1]); break;

                case "isdebug": m_isDebug = bool.Parse(sp1[1]); break;

                case "target": m_buildTarget = (BuildTarget)Enum.Parse(typeof(BuildTarget), sp1[1]); break;

                default: break;
                }
            }
        }
示例#6
0
        public static void WriteManifestFile(string filePath, string replaceTxt, Dictionary <string, List <string> > manifestInfo)
        {
            StringBuilder manifestTxt = new StringBuilder();

            foreach (KeyValuePair <string, List <string> > pair in manifestInfo)
            {
                string fileName = ABHelper.GetFileFullPathWithoutFtype(pair.Key).Replace(replaceTxt, "") + ".ab";
                manifestTxt.Append(fileName + ":");

                for (int i = 0; i < pair.Value.Count; i++)
                {
                    fileName = ABHelper.GetFileFullPathWithoutFtype(pair.Value[i]).Replace(replaceTxt, "") + ".ab";
                    if (i == pair.Value.Count - 1)
                    {
                        manifestTxt.Append(fileName + "\r");
                    }
                    else
                    {
                        manifestTxt.Append(fileName + ",");
                    }
                }
            }

            byte[] manifestbytes = Encoding.UTF8.GetBytes(manifestTxt.ToString().TrimEnd().ToLower());
            Encrypt(ref manifestbytes); //RC4 加密文件
            ABHelper.WriteFileByBytes(filePath, manifestbytes);
        }
示例#7
0
        public VersionInfo(VersionNum versionId, bool isNativeVersion = false)
        {
            VersionId       = versionId;
            IsNativeVersion = isNativeVersion;

            if (isNativeVersion)
            {
                VersionFolderPath   = ABHelper.AppNativeVersionPath;
                VersionFilePath     = string.Format("{0}/{1}", VersionFolderPath, ABHelper.VersionFileName);
                NativeFilePath      = string.Format("{0}/{1}", VersionFolderPath, ABHelper.NativeFileName);
                IsVersionFileExist  = true;
                IsManifestFileExist = true;
            }
            else
            {
                bool fromNativePath = true;
                VersionFolderPath   = string.Format("{0}/{1}/{2}", ABHelper.AppVersionPath, VersionId.Id1A2, VersionId.Id3rd.ToString());
                VersionFilePath     = string.Format("{0}/{1}", VersionFolderPath, ABHelper.VersionFileName);
                IsVersionFileExist  = File.Exists(VersionFilePath);
                IsManifestFileExist = !string.IsNullOrEmpty(GetABFullPath(ABHelper.ManifestFileName, ref fromNativePath));

                if (IsValid)
                {
                    string versionNumPath = GetABFullPath(ABHelper.VersionNumFileName, ref fromNativePath);
                    if (!string.IsNullOrEmpty(versionNumPath))
                    {
                        VersionId.Update(ABHelper.ReadVersionNumFileByPath(versionNumPath));
                    }
                }
            }
        }
示例#8
0
        // 初始化AB
        public static void InitABVersion()
        {
            Debug.Log(ABHelper.AppVersionPath);
            Debug.Log(ABHelper.AppNativeVersionPath);

            // 实例化
            LocalVersionList = new Dictionary <int, VersionInfo>();
            // 需要的文件夹
            if (!Directory.Exists(ABHelper.AppVersionPath))
            {
                Directory.CreateDirectory(ABHelper.AppVersionPath);
            }

            // 版号信息
            Dictionary <string, string> versionInfo = ABHelper.ReadVersionIdFile();

            OriginalVersionId      = new VersionNum(versionInfo["ResVersion"]);
            ABHelper.ABFolderRoot  = versionInfo["ABFolderRoot"];
            ABHelper.ApkFolderRoot = versionInfo["ApkFolderRoot"];

            // 当前版号
            CurVersionId = new VersionNum(OriginalVersionId.Id1st, OriginalVersionId.Id2nd, OriginalVersionId.Id3rd, OriginalVersionId.Id4th);

            // 本地更新地址
            LocalStorgePath = string.Format("{0}/{1}", ABHelper.AppVersionPath, OriginalVersionId.Id1A2);
            if (!Directory.Exists(LocalStorgePath))
            {
                Directory.CreateDirectory(LocalStorgePath);
            }

            // 获取本地的所有版本
            LoadAllVersionInfo();
            // 现在在用的版本号
            SetCurVersionNum(CurVersionId);
        }
示例#9
0
        private static void ParseTheVersion()
        {
            Dictionary <string, string> versionInfo = ABHelper.ReadVersionIdFile();

            TheVersionNum     = ABHelper.VersionNumSplit(versionInfo["ResVersion"]);
            TheRootFolderName = versionInfo["ABFolderRoot"];
        }
示例#10
0
        private IEnumerator AsyncLoadAsset(ABLoadTask task)
        {
            ResourceRequest request;

            if (null == task.AbType)
            {
                request = Resources.LoadAsync(ABHelper.GetFileFullPathWithoutFtype(task.AbPath));
            }
            else
            {
                request = Resources.LoadAsync(ABHelper.GetFileFullPathWithoutFtype(task.AbPath), task.AbType);
            }
            while (!request.isDone)
            {
                if (null != task.Progress)
                {
                    task.Progress(request.progress);
                }
                yield return(null);
            }
            yield return(request);

            // 加载完成
            if (request.isDone)
            {
                LoadComplete(request.asset, task);
            }
        }
示例#11
0
        // 拷贝目录,包括
        private static void DirCopy(string srcPath, string tarPath, string fileExtension = null)
        {
            try
            {
                bool needAddExtension = !string.IsNullOrEmpty(fileExtension);

                // 检查目标目录是否以目录分割字符结束如果不是则添加
                if (tarPath[tarPath.Length - 1] != System.IO.Path.DirectorySeparatorChar)
                {
                    tarPath += System.IO.Path.DirectorySeparatorChar;
                }
                // 判断目标目录是否存在如果不存在则新建
                if (!System.IO.Directory.Exists(tarPath))
                {
                    System.IO.Directory.CreateDirectory(tarPath);
                }
                // 得到源目录的文件列表,该里面是包含文件以及目录路径的一个数组
                // 如果你指向copy目标文件下面的文件而不包含目录请使用下面的方法
                // string[] fileList = Directory.GetFiles(srcPath);
                string[] fileList = System.IO.Directory.GetFileSystemEntries(srcPath);
                // 遍历所有的文件和目录
                foreach (string file in fileList)
                {
                    string targetFileName = tarPath + System.IO.Path.GetFileName(file);

                    // 先当作目录处理如果存在这个目录就递归Copy该目录下面的文件
                    if (System.IO.Directory.Exists(file))
                    {
                        DirCopy(file, targetFileName, fileExtension);
                    }
                    // 否则直接Copy文件
                    else
                    {
                        // 剔除meta文件, .DS打头的文件
                        if (targetFileName.EndsWith(".meta") || targetFileName.Contains(".DS"))
                        {
                            continue;
                        }
                        // 添加后缀
                        if (needAddExtension)
                        {
                            targetFileName = targetFileName + fileExtension;
                        }
                        byte[] content = ABHelper.ReadFileToBytes(file);;
                        if (null == content || content.Length <= 0)
                        {
                            continue;
                        }
                        ABHelper.Encrypt(ref content);
                        ABHelper.WriteFileByBytes(targetFileName, content);
                    }
                }
            }
            catch (Exception e)
            {
                throw;
            }
        }
示例#12
0
        private static void WriteFile()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("UseAssetsDir=" + UseAssetDirStr + "\n");
            sb.Append("NotRemoveDir=" + NotRemoveDirStr + "\n");
            sb.Append("NotRemoveFile=" + NotRemoveFileStr + "\n");
            ABHelper.WriteFile(Application.dataPath + "/Editor/ABStreaming.txt", sb.ToString().TrimEnd());
        }
示例#13
0
 public void ParseVersionList()
 {
     if (!IsVersionFileExist)
     {
         Debug.LogFormat("<color=#FFFF33> 检测不到version文件:{0} ,需要从服务器更新</color>", VersionFilePath);
         return;
     }
     VersionInfoList = ABHelper.ReadVersionFileByPath(VersionFilePath);
 }
示例#14
0
        public static void AssetMoveout()
        {
            System.GC.Collect();
            System.GC.Collect();

            ReadFile();
            ParseAllDir();
            RootFolderNmae();
            ParseTheVersion();
            FilesFilter();

            string path = string.Format("{0}/../../../temp/", Application.dataPath);

            if (Directory.Exists(path))
            {
                Directory.Delete(path, true);
            }
            Directory.CreateDirectory(path);

            string path1;

            // ProjectSettings
            ABHelper.DirectoryCopy(string.Format("{0}/../{1}", Application.dataPath, "ProjectSettings"), path + "ProjectSettings");
            foreach (var v in RemoveResourcesDir)
            {
                path1 = ResFolder.Replace("Assets", "") + v;
                ABHelper.DirectoryMove(Application.dataPath + path1, path + path1);
            }
            foreach (var v in RemoveAssetsDir)
            {
                path1 = AssetsFolder.Replace("Assets", "") + v;
                ABHelper.DirectoryMove(Application.dataPath + path1, path + path1);
            }

            string path2;

            foreach (var v in NotRemoveFileList)
            {
                path1 = string.Format("{0}/../../../temp/{1}", Application.dataPath, v);
                if (!File.Exists(path1))
                {
                    continue;
                }
                path2 = Application.dataPath + "/" + v;
                if (File.Exists(path2))
                {
                    File.Delete(path2);
                }
                File.Move(path1, path2);
            }

            AssetDatabase.Refresh();
            AssetDatabase.SaveAssets();

            System.GC.Collect();
            Debug.Log("资源移出成功!!");
        }
示例#15
0
        private static void ParseTheVersion()
        {
            TextAsset resInfo = Resources.Load <TextAsset>("resversion");

            if (null != resInfo)
            {
                TheVersionNum = ABHelper.VersionNumSplit(resInfo.text.Replace("\r", ""));
            }
        }
示例#16
0
        private IEnumerator LoadManifest()
        {
            if (null == ABVersion.CurVersionInfo || !ABVersion.CurVersionInfo.IsManifestFileExist)
            {
                yield break;
            }

            ABManifest = ABHelper.ReadManifestFile(ABVersion.CurVersionInfo.ManifestFilePath);
        }
示例#17
0
        // 收集冗余文件
        private void CollectRedundantFiles()
        {
            List <string> allFilePath = new List <string>();

            List <string> versionFilePath = ABHelper.GetAllFilesPathInDir(ABVersion.LocalStorgePath);

            foreach (string path in versionFilePath)
            {
                allFilePath.Add(path.Replace("\\", "/"));
            }

            List <string> imageFilePath = ABHelper.GetAllFilesPathInDir(ABHttpImg.LocalStorgePath);

            foreach (string path in imageFilePath)
            {
                allFilePath.Add(path.Replace("\\", "/"));
            }

            List <string> needFilePath = new List <string>();

            if (null != ABVersion.CurVersionInfo)
            {
                needFilePath.Add(ABVersion.CurVersionInfo.VersionFilePath);
                foreach (var value in ABVersion.CurVersionInfo.VersionInfoList)
                {
                    if (int.Parse(value.Value[1]) <= ABVersion.OriginalVersionId.Id3rd)
                    {
                        continue;
                    }
                    bool   fromNativePath = true;
                    string path           = ABVersion.CurVersionInfo.GetABFullPath(value.Key, ref fromNativePath);
                    if (!fromNativePath && !string.IsNullOrEmpty(path))
                    {
                        needFilePath.Add(path);
                    }
                }
            }

            foreach (var value in allFilePath)
            {
                if (!needFilePath.Contains(value))
                {
                    deleteFiles.Add(value);
                }
            }

            List <int> versionList = new List <int>(ABVersion.LocalVersionList.Keys);

            foreach (var value in versionList)
            {
                if (value != ABVersion.ServerVersionId.Id3rd)
                {
                    ABVersion.LocalVersionList.Remove(value);
                }
            }
        }
示例#18
0
        // 初始化AB
        public static void InitABVersion()
        {
            // 实例化
            LocalVersionList = new Dictionary <int, VersionInfo>();
            // 需要的文件夹
            if (!Directory.Exists(ABHelper.AppTempCachePath))
            {
                Directory.CreateDirectory(ABHelper.AppTempCachePath);
            }

            // 本地发包时的版本号
            TextAsset resInfo = Resources.Load <TextAsset>(ABHelper.GetFileNameWithoutSuffix(ABHelper.OriginalVersionName));

            if (null == resInfo)
            {
                throw new Exception("本地资源版本号不可为空!!!");
            }

            // 初始时的版号
            OriginalVersionId = new VersionNum(resInfo.text.Replace("\r", ""));
            CurVersionId      = OriginalVersionId;

            // 本地更新地址
            LocalStorgePath = string.Format("{0}/{1}", ABHelper.AppTempCachePath, OriginalVersionId.Id1A2);
            if (!Directory.Exists(LocalStorgePath))
            {
                Directory.CreateDirectory(LocalStorgePath);
            }

            // 获取本地的所有版本
            DirectoryInfo dirInfo = new DirectoryInfo(LocalStorgePath);

            DirectoryInfo[] dirInfos = dirInfo.GetDirectories();

            // 遍历本地所有版号
            foreach (DirectoryInfo info in dirInfos)
            {
                int id3rd = int.Parse(info.Name);
                if (id3rd < OriginalVersionId.Id3rd)
                {
                    continue;
                }
                VersionNum versionId = new VersionNum(OriginalVersionId.Id1st, OriginalVersionId.Id2nd, id3rd);
                if (!LoadVersionInfo(versionId))
                {
                    continue;
                }
                if (null == CurVersionId || versionId.Id3rd > CurVersionId.Id3rd)
                {
                    CurVersionId = LocalVersionList[versionId.Id3rd].VersionId;
                }
            }

            // 现在在用的版本号
            SetCursVersionNum(CurVersionId);
        }
示例#19
0
        public static void WriteNativeFile(string filePath, List <string> nativeInfo)
        {
            StringBuilder nativeTxt = new StringBuilder();

            foreach (var pair in nativeInfo)
            {
                nativeTxt.Append(pair + "\r");
            }
            ABHelper.WriteFile(filePath, nativeTxt.ToString().TrimEnd().ToLower());
        }
示例#20
0
        private static void RootFolderName()
        {
            // TheRootFolderName = Application.dataPath;
            // TheRootFolderName = TheRootFolderName.Substring(0, TheRootFolderName.LastIndexOf("/"));
            // TheRootFolderName = "ab_" + TheRootFolderName.Substring(TheRootFolderName.LastIndexOf("/") + 1) + "_full";

            Dictionary <string, string> versionInfo = ABHelper.ReadVersionIdFile();

            TheRootFolderName = versionInfo["ABFolderRoot"];
        }
示例#21
0
        public static void WriteMd5File(string filePath, Dictionary <string, string> md5Info)
        {
            StringBuilder md5Txt = new StringBuilder();

            foreach (KeyValuePair <string, string> pair in md5Info)
            {
                md5Txt.Append(pair.Key + ":" + pair.Value + "\r");
            }
            ABHelper.WriteFile(filePath, md5Txt.ToString().TrimEnd().ToLower());
        }
示例#22
0
 public void Update(string v)
 {
     Id      = v;
     IdArray = ABHelper.VersionNumSplit(Id);
     Id1A2   = string.Format("{0}.{1}", IdArray[0], IdArray[1]);
     Id1st   = IdArray[0];
     Id2nd   = int.Parse(IdArray[1]);
     Id3rd   = int.Parse(IdArray[2]);
     Id4th   = int.Parse(IdArray[3]);
 }
示例#23
0
 public void Update(string v1, int v2, int v3, int v4)
 {
     Id      = ABHelper.VersionNumCombine(v1, v2, v3, v4);
     IdArray = ABHelper.VersionNumSplit(Id);
     Id1A2   = string.Format("{0}.{1}", IdArray[0], IdArray[1]);
     Id1st   = v1;
     Id2nd   = v2;
     Id3rd   = v3;
     Id4th   = v4;
 }
示例#24
0
        public static void Collect()
        {
            if (!Directory.Exists(m_exportPath))
            {
                Directory.CreateDirectory(m_exportPath);
            }

            StringBuilder sb = new StringBuilder();

            sb.Append("return {\n");

            foreach (string v in m_forwardLua)
            {
                sb.Append("\t\"" + v + "\",\n");
            }

            List <string> list = new List <string>();

            foreach (string v in m_folderLua)
            {
                list.AddRange(ABHelper.GetAllFilesPathInDir("Assets/Lua/" + v));
            }
            foreach (string v in list)
            {
                if (!v.EndsWith(".lua"))
                {
                    continue;
                }

                string nv = v.Replace("Assets/Lua/", "");
                nv = nv.Replace(@"/", ".");
                nv = nv.Replace(@"\", ".");
                nv = nv.Replace(".lua", "");

                if (m_exclusiveLua.Contains(nv) || m_forwardLua.Contains(nv) || m_backLua.Contains(nv))
                {
                    continue;
                }

                sb.Append("\t\"" + nv + "\",\n");
            }

            foreach (string v in m_backLua)
            {
                sb.Append("\t\"" + v + "\",\n");
            }

            sb.Append("}");

            string filePath = m_exportPath + m_configName;

            ABHelper.WriteFile(filePath, sb.ToString());

            Debug.Log(string.Format("已存储在路径{0}", filePath));
        }
示例#25
0
        private static void WriteBuildTxt()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("commandBuildApp=" + m_commandBuildApp.ToString() + "\n");
            sb.Append("buildApp=" + m_buildApp.ToString() + "\n");
            sb.Append("xluaGen=" + m_xluaGen.ToString() + "\n");
            sb.Append("isdebug=" + m_isDebug.ToString() + "\n");
            sb.Append("target=" + m_buildTarget.ToString() + "\n");
            ABHelper.WriteFile(Application.dataPath + "/Editor/BuildAppSteps.txt", sb.ToString().TrimEnd());
        }
示例#26
0
        private static void SaveTheVersion()
        {
            int num;

            if (!int.TryParse(TheVersionNum[3], out num))
            {
                Debug.LogError("资源单号错误!!!!!");
            }
            string version = ABHelper.VersionNumCombine(TheVersionNum[0], TheVersionNum[1], TheVersionNum[2], TheVersionNum[3]);

            ABHelper.WriteFile(Application.dataPath + "/Resources/" + ABHelper.OriginalVersionName, version);
        }
示例#27
0
        static void ChangeABRoot()
        {
            parseCommand();
            if (string.IsNullOrEmpty(ABRoot) || "null" == ABRoot.ToLower())
            {
                return;
            }
            Dictionary <string, string> versionInfo = ABHelper.ReadVersionIdFile();

            versionInfo["ABFolderRoot"] = ABRoot;
            ABHelper.WriteVersionIdFile(versionInfo);
        }
示例#28
0
        public static void WriteMd5File(string filePath, Dictionary <string, string> md5Info, Dictionary <string, int> crInfo)
        {
            StringBuilder md5Txt = new StringBuilder();
            int           rc     = 1;

            foreach (KeyValuePair <string, string> pair in md5Info)
            {
                rc = crInfo.ContainsKey(pair.Key) ? crInfo[pair.Key] : 1;
                md5Txt.Append(pair.Key + ":" + pair.Value + ":" + rc + "\r");
            }
            ABHelper.WriteFile(filePath, md5Txt.ToString().TrimEnd().ToLower());
        }
示例#29
0
        static void ChangeVersionId()
        {
            parseCommand();
            if (string.IsNullOrEmpty(VersionId) || "null" == VersionId.ToLower())
            {
                return;
            }
            Dictionary <string, string> versionInfo = ABHelper.ReadVersionIdFile();

            versionInfo["ResVersion"] = VersionId;
            ABHelper.WriteVersionIdFile(versionInfo);
        }
示例#30
0
        public static void WriteVersionFile(string filePath, Dictionary <string, List <string> > versionInfo)
        {
            StringBuilder versionTxt = new StringBuilder();

            foreach (KeyValuePair <string, List <string> > pair in versionInfo)
            {
                versionTxt.Append(pair.Key + ":" + pair.Value[0] + ":" + pair.Value[1] + ":" + pair.Value[2] + ":" + pair.Value[3] + "\r");
            }

            byte[] versionbytes = Encoding.UTF8.GetBytes(versionTxt.ToString().TrimEnd().ToLower());
            Encrypt(ref versionbytes); //RC4 加密文件
            ABHelper.WriteFileByBytes(filePath, versionbytes);
        }