コード例 #1
0
        /// <summary>
        /// 尝试恢复读写区资源列表
        /// </summary>
        /// <returns>是否恢复成功</returns>
        private bool TryRecoverReadWriteList()
        {
            string file       = PathUtil.GetCombinePath(m_ResourceManager.ReadWritePath, PathUtil.GetResourceNameWithSuffix(ResourceListFileName));
            string backupFile = file + BackupFileSuffixName;

            try
            {
                if (!File.Exists(backupFile))
                {
                    return(false);
                }

                if (File.Exists(file))
                {
                    File.Delete(file);
                }

                File.Move(backupFile, file);
            }
            catch
            {
                return(false);
            }

            return(true);
        }
コード例 #2
0
        private void GenerateReadWriteList()
        {
            string file       = PathUtil.GetCombinePath(m_ResourceManager.ReadWritePath, PathUtil.GetResourceNameWithSuffix(ResourceListFileName));
            string backupFile = null;

            if (File.Exists(file))
            {
                backupFile = file + BackupFileSuffixName;
                if (File.Exists(backupFile))
                {
                    File.Delete(backupFile);
                }

                File.Move(file, backupFile);
            }


            try
            {
                using (FileStream fileStream = new FileStream(file, FileMode.CreateNew, FileAccess.Write))
                {
                    byte[] buffer = null;
                    using (MMO_MemoryStream ms = new MMO_MemoryStream())
                    {
                        ms.WriteInt(m_ResourceManager.ReadWriteResourceInfos.Count);
                        foreach (var readWriteResourceInfo in m_ResourceManager.ReadWriteResourceInfos)
                        {
                            int length   = readWriteResourceInfo.Value.Length;
                            int hashcode = readWriteResourceInfo.Value.HashCode;

                            ms.WriteUTF8String(readWriteResourceInfo.Key);
                            ms.WriteInt(length);
                            ms.WriteInt(hashcode);
                        }
                        buffer = ms.ToArray();
                    }
                    fileStream.Write(buffer, 0, buffer.Length);
                }

                if (!string.IsNullOrEmpty(backupFile))
                {
                    File.Delete(backupFile);
                }
            }
            catch (Exception exception)
            {
                if (File.Exists(file))
                {
                    File.Delete(file);
                }

                if (!string.IsNullOrEmpty(backupFile))
                {
                    File.Move(backupFile, file);
                }

                throw new Exception(TextUtil.Format("Pack save exception '{0}'.", exception.Message), exception);
            }
        }
コード例 #3
0
        private void RefreshCheckInfoStatus()
        {
            if (!m_VersionListReady || !m_ReadOnlyListReady || !m_ReadWriteListReady)
            {
                return;
            }

            int  removedCount         = 0;
            int  updateCount          = 0;
            long updateTotalLength    = 0L;
            long updateTotalZipLength = 0L;

            foreach (KeyValuePair <string, CheckInfo> checkInfo in m_CheckInfos)
            {
                CheckInfo ci = checkInfo.Value;
                ci.RefreshStatus();
                if (ci.Status == CheckInfo.CheckStatus.StorageInReadOnly)
                {
                    ProcessResourceInfo(ci.ResourceName, ci.Length, ci.HashCode, true);
                }
                else if (ci.Status == CheckInfo.CheckStatus.StorageInReadWrite)
                {
                    ProcessResourceInfo(ci.ResourceName, ci.Length, ci.HashCode, false);
                }
                else if (ci.Status == CheckInfo.CheckStatus.NeedUpdate)
                {
                    updateCount++;
                    updateTotalLength    += ci.Length;
                    updateTotalZipLength += ci.ZipLength;

                    ResourceNeedUpdate(ci.ResourceName, ci.Length, ci.HashCode, ci.ZipLength, ci.ZipHashCode);
                }
                else if (ci.Status == CheckInfo.CheckStatus.Disuse)
                {
                    // Do nothing.
                }
                else
                {
                    throw new Exception(TextUtil.Format("Check resources '{0}' error with unknown status.", ci.ResourceName));
                }

                if (ci.NeedRemove)
                {
                    removedCount++;
                    string path = PathUtil.GetCombinePath(m_ResourceManager.ReadWritePath, PathUtil.GetResourceNameWithSuffix(ci.ResourceName));
                    File.Delete(path);

                    if (!m_ResourceManager.ReadWriteResourceInfos.ContainsKey(ci.ResourceName))
                    {
                        throw new Exception(TextUtil.Format("Resource '{0}' is not exist in read-write list.", ci.ResourceName));
                    }

                    m_ResourceManager.ReadWriteResourceInfos.Remove(ci.ResourceName);
                }
            }

            ResourceCheckComplete(removedCount, updateCount, updateTotalLength, updateTotalZipLength);
        }
コード例 #4
0
ファイル: VersionListProcessor.cs プロジェクト: 542767059/ABC
        /// <summary>
        /// 更新版本资源列表
        /// </summary>
        /// <param name="versionListLength">版本资源列表大小</param>
        /// <param name="versionListHashCode">版本资源列表哈希值</param>
        /// <param name="versionListZipLength">版本资源列表压缩后大小</param>
        /// <param name="versionListZipHashCode">版本资源列表压缩后哈希值</param>
        public void UpdateVersionList(int versionListLength, int versionListHashCode, int versionListZipLength, int versionListZipHashCode)
        {
            if (GameEntry.Download == null)
            {
                throw new Exception("You must set download manager first.");
            }

            m_VersionListLength      = versionListLength;
            m_VersionListHashCode    = versionListHashCode;
            m_VersionListZipLength   = versionListZipLength;
            m_VersionListZipHashCode = versionListZipHashCode;
            string versionListFileName       = PathUtil.GetResourceNameWithSuffix(VersionListFileName);
            string latestVersionListFileName = PathUtil.GetResourceNameWithCrc32AndSuffix(VersionListFileName, m_VersionListHashCode);
            string localVersionListFilePath  = PathUtil.GetCombinePath(m_ResourceManager.ReadWritePath, versionListFileName);
            string latestVersionListFileUri  = PathUtil.GetRemotePath(m_ResourceManager.UpdatePrefixUri, latestVersionListFileName);

            GameEntry.Download.AddDownload(localVersionListFilePath, latestVersionListFileUri, this);
        }
コード例 #5
0
 private void OnCheckerResourceNeedUpdate(string resourceName, int length, int hashCode, int zipLength, int zipHashCode)
 {
     m_ResourceUpdater.AddResourceUpdate(resourceName, length, hashCode, zipLength, zipHashCode, PathUtil.GetCombinePath(m_ReadWritePath, PathUtil.GetResourceNameWithSuffix(resourceName)));
 }
コード例 #6
0
        /// <summary>
        /// 开始处理加载资源任务
        /// </summary>
        /// <param name="task">要处理的加载资源任务</param>
        /// <returns>开始处理任务的状态</returns>
        public StartTaskStatus StartTask(ResourceLoaderTask task)
        {
            if (task == null)
            {
                throw new Exception("Task is invalid.");
            }

            m_Task           = task;
            m_Task.StartTime = DateTime.Now;

            if (string.IsNullOrEmpty(m_Task.AssetName))
            {
                if (IsResourceLoading(m_Task.AssetBundleName))
                {
                    m_Task.StartTime = default(DateTime);
                    return(StartTaskStatus.HasToWait);
                }

                AssetBundleInfo bundleInfo = m_AssetBundlePool.SpawnAsset(m_Task.AssetBundleName);
                if (bundleInfo != null)
                {
                    OnResourceObjectReady((AssetBundle)bundleInfo.Asset);
                    return(StartTaskStatus.CanResume);
                }

                s_LoadingResourceNames.Add(m_Task.AssetBundleName);

                ResourceInfo resourcinfo = GameEntry.Resource.GetResourceInfo(m_Task.AssetBundleName);
                string       fullpath    = PathUtil.GetCombinePath(resourcinfo.StorageInReadOnly ? GameEntry.Resource.ReadOnlyPath : GameEntry.Resource.ReadWritePath, PathUtil.GetResourceNameWithSuffix(resourcinfo.ResourceName));
                ReadBytes(fullpath);
                //if (resourceInfo.StorageInReadOnly)
                //{
                //    ReadOnlyByte(resourcinfo.ResourceName);
                //}
                //else
                //{
                //    ReadWriteByte(resourcinfo.ResourceName);
                //}
                return(StartTaskStatus.CanResume);
            }

            if (IsAssetLoading(m_Task.AssetName))
            {
                m_Task.StartTime = default(DateTime);
                return(StartTaskStatus.HasToWait);
            }

            if (!m_Task.IsScene)
            {
                AssetInfo assetInfo = m_AssetPool.SpawnAsset(m_Task.AssetName);
                if (assetInfo != null)
                {
                    OnAssetObjectReady((UnityEngine.Object)assetInfo.Asset);
                    return(StartTaskStatus.Done);
                }
            }

            foreach (string dependencyAssetName in m_Task.GetDependencyAssetNames())
            {
                if (!m_AssetBundlePool.CanSpawnAsset(dependencyAssetName))
                {
                    m_Task.StartTime = default(DateTime);
                    return(StartTaskStatus.HasToWait);
                }
            }

            if (IsResourceLoading(m_Task.AssetBundleName))
            {
                m_Task.StartTime = default(DateTime);
                return(StartTaskStatus.HasToWait);
            }

            s_LoadingAssetNames.Add(m_Task.AssetName);

            AssetBundleInfo assetBundleInfo = m_AssetBundlePool.SpawnAsset(m_Task.AssetBundleName);

            if (assetBundleInfo != null)
            {
                OnResourceObjectReady((AssetBundle)assetBundleInfo.Asset);
                return(StartTaskStatus.CanResume);
            }

            s_LoadingResourceNames.Add(m_Task.AssetBundleName);

            ResourceInfo resourceInfo = GameEntry.Resource.GetResourceInfo(m_Task.AssetBundleName);
            string       fullPath     = PathUtil.GetCombinePath(resourceInfo.StorageInReadOnly ? GameEntry.Resource.ReadOnlyPath : GameEntry.Resource.ReadWritePath, PathUtil.GetResourceNameWithSuffix(resourceInfo.ResourceName));

            ReadBytes(fullPath);
            //if (resourceInfo.StorageInReadOnly)
            //{
            //    ReadOnlyByte(resourceInfo.ResourceName);
            //}
            //else
            //{
            //    ReadWriteByte(resourceInfo.ResourceName);
            //}
            return(StartTaskStatus.CanResume);
        }