Exemplo n.º 1
0
    private bool CompareVersion(string verName, bool needDownload = true)
    {
        remoteVersion.TryGetValue(verName, out FileList remote_ver);
        localVersion.TryGetValue(verName, out FileList local_ver);
        bool isSame = remote_ver == local_ver;

        Log.LogToFile($"{verName}版本是否相同:{isSame} ,远程版本号:{remote_ver?.md5} ,本地版本号:{local_ver?.md5}");
        if (isSame == false)
        {
            var realPath = KResourceModule.AppDataPath + verName;
            if (File.Exists(realPath) && remote_ver != null && KTool.MD5_File(realPath) == remote_ver.md5)
            {
                Log.LogToFile($"文件存在:{verName},且md5一致,跳过下载");
                return(isSame);
            }

            if (!needDownload)
            {
                return(isSame);
            }
            downloadFiles.Add(remote_ver);
            if (verName.Contains("lua"))
            {
                needUnpackLua = true;
            }
            if (verName.Contains("setting"))
            {
                needUnpackSetting = true;
            }
            downloadTotalSize += remote_ver.size;
        }

        return(isSame);
    }
Exemplo n.º 2
0
        /// <summary>
        /// 标记一个路径为打包
        /// </summary>
        public void MarkBuildVersion(params string[] sourceFiles)
        {
            if (sourceFiles == null || sourceFiles.Length == 0)
            {
                return;
            }

            foreach (string file in sourceFiles)
            {
                //StoreBuildVersion[file] = GetAssetVersion(file);
                BuildRecord theRecord;
                var         nowMd5 = KTool.MD5_File(file);
                if (!StoreBuildVersion.TryGetValue(file, out theRecord))
                {
                    theRecord = new BuildRecord();
                    theRecord.Mark(nowMd5);
                }
                else
                {
                    if (nowMd5 != theRecord.MD5) // 只有改变时才会mark,所以可能会出现情况,rebuild时,change count不改变
                    {
                        theRecord.Mark(nowMd5);
                    }
                }
                StoreBuildVersion[file] = InstanceBuildVersion[file] = theRecord; // ensure in dict

                string metaFile = file + ".meta";
                if (File.Exists(metaFile))
                {
                    BuildRecord theMetaRecord;
                    var         nowMetaMd5 = KTool.MD5_File(metaFile);
                    if (!StoreBuildVersion.TryGetValue(metaFile, out theMetaRecord))
                    {
                        theMetaRecord = new BuildRecord();
                        theMetaRecord.Mark(nowMetaMd5);
                    }
                    else
                    {
                        if (nowMetaMd5 != theMetaRecord.MD5)
                        {
                            theMetaRecord.Mark(nowMetaMd5);
                        }
                    }

                    StoreBuildVersion[metaFile] = InstanceBuildVersion[metaFile] = theMetaRecord; // ensure in dict
                }
                // meta不记录
                Current.BuildedList.Add(file);
            }
        }
        /// <summary>
        /// 检查是否需要build,
        /// 文件,要进行MD5校验
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="isFile"></param>
        /// <param name="log"></param>
        /// <returns></returns>
        private bool DoCheckBuild(string filePath, bool log = true)
        {
// #if UNITY_5
            var currentScene = UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene().path;
// #else
//             var currentScene = EditorApplication.currentScene;
// #endif
            BuildRecord assetMd5;

            if (!File.Exists(filePath))
            {
                if (log)
                {
                    Log.Error("[DoCheckBuild]Not Found 无法找到文件 {0}", filePath);
                }

                if (filePath.Contains("unity_builtin_extra"))
                {
                    Log.Error(
                        "[DoCheckBuild]Find unity_builtin_extra resource to build!! Please check it! current scene: {0}",
                        currentScene);
                }
                return(false);
            }

            if (InstanceBuildVersion.ContainsKey(filePath)) // 本次打包已经处理过,就不用重复处理了
            {
                return(false);
            }

            if (_isRebuild) // 所有rebuild,不用判断,直接需要build, 保留change count的正确性
            {
                return(true);
            }

            // 不存在记录,则需要打包吧
            if (!DoCheckExistRecord(filePath, out assetMd5))
            {
                return(true);
            }

            if (KTool.MD5_File(filePath) != assetMd5.MD5)
            {
                return(true); // different
            }
            return(false);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 检查是否需要build,
        /// 文件,要进行MD5校验
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="isFile"></param>
        /// <param name="log"></param>
        /// <returns></returns>
        private bool DoCheckBuild(string filePath, bool log = true)
        {
            BuildRecord assetMd5;

            if (!File.Exists(filePath))
            {
                if (log)
                {
                    Logger.LogError("[DoCheckBuild]Not Found 无法找到文件 {0}", filePath);
                }

                if (filePath.Contains("unity_builtin_extra"))
                {
                    Logger.LogError(
                        "[DoCheckBuild]Find unity_builtin_extra resource to build!! Please check it! current scene: {0}",
                        EditorApplication.currentScene);
                }
                return(false);
            }


            if (InstanceBuildVersion.ContainsKey(filePath)) // 本次打包已经处理过,就不用重复处理了
            {
                return(false);
            }

            if (_isRebuild) // 所有rebuild,不用判断,直接需要build, 保留change count的正确性
            {
                return(true);
            }

            if (!StoreBuildVersion.TryGetValue(filePath, out assetMd5))
            {
                return(true);
            }

            if (KTool.MD5_File(filePath) != assetMd5.MD5)
            {
                return(true); // different
            }
            return(false);
        }
Exemplo n.º 5
0
    /// <summary>
    /// 对比两个filelist,把不相同的添加到下载列表中
    /// </summary>
    /// <param name="local"></param>
    /// <param name="remote"></param>
    void GetDownloadFromFilelist(string local, string remote)
    {
        if (string.IsNullOrEmpty(local))
        {
            //TODO filelist异常
            Log.LogError("本地filelist为空");
            return;
        }

        if (string.IsNullOrEmpty(remote))
        {
            //TODO filelist异常
            Log.LogError("远程filelist为空");
            return;
        }

        Dictionary <string, FileList> localDict = new Dictionary <string, FileList>();

        using (StringReader reader = new StringReader(local))
        {
            while (true)
            {
                var line = reader.ReadLine();
                if (line == null)
                {
                    break;
                }
                var file = ParseToFileList(line);
                if (file != null)
                {
                    localDict[file.path] = file;
                }
            }
        }

        string abDirName = AppConfig.StreamingBundlesFolderName + "/" + KResourceModule.GetBuildPlatformName() + "/";
        var    savePath  = KResourceModule.AppDataPath + abDirName;

        using (StringReader reader = new StringReader(remote))
        {
            while (true)
            {
                var line = reader.ReadLine();
                if (line == null)
                {
                    break;
                }

                var file = ParseToFileList(line);
                if (file != null)
                {
                    var realPath = savePath + file.path;
                    if (File.Exists(realPath) && KTool.MD5_File(realPath) == file.md5)
                    {
                        filelistBuilder.AppendLine(file.ToFilelistFormat());
                        Log.LogToFile($"文件存在:{file.path},且md5一致,跳过下载");
                        continue;
                    }

                    if (localDict.TryGetValue(file.path, out FileList exist))
                    {
                        if (exist.md5 != file.md5 || exist.size != file.size)
                        {
                            var newFile = new FileList()
                            {
                                path = abDirName + file.path, md5 = file.md5, size = file.size
                            };
                            downloadFiles.Add(newFile);
                            downloadTotalSize += file.size;
                        }
                        else
                        {
                            filelistBuilder.AppendLine(file.ToFilelistFormat());
                        }
                    }
                    else
                    {
                        var newFile = new FileList()
                        {
                            path = abDirName + file.path, md5 = file.md5, size = file.size
                        };
                        downloadFiles.Add(newFile);
                        downloadTotalSize += file.size;
                    }
                }
            }
        }
    }