private void GenerateReadWriteVersionList() { FileStream fileStream = null; try { fileStream = new FileStream(m_ReadWriteVersionListTempFileName, FileMode.Create, FileAccess.Write); LocalVersionList.Resource[] resources = m_ResourceManager.m_ReadWriteResourceInfos.Count > 0 ? new LocalVersionList.Resource[m_ResourceManager.m_ReadWriteResourceInfos.Count] : null; if (resources != null) { int index = 0; foreach (KeyValuePair <ResourceName, ReadWriteResourceInfo> i in m_ResourceManager.m_ReadWriteResourceInfos) { resources[index] = new LocalVersionList.Resource(i.Key.Name, i.Key.Variant, i.Key.Extension, (byte)i.Value.LoadType, i.Value.Length, i.Value.HashCode); if (i.Value.UseFileSystem) { List <int> resourceIndexes = null; if (!m_CachedFileSystemsForGenerateReadWriteVersionList.TryGetValue(i.Value.FileSystemName, out resourceIndexes)) { resourceIndexes = new List <int>(); m_CachedFileSystemsForGenerateReadWriteVersionList.Add(i.Value.FileSystemName, resourceIndexes); } resourceIndexes.Add(index); } index++; } } LocalVersionList.FileSystem[] fileSystems = m_CachedFileSystemsForGenerateReadWriteVersionList.Count > 0 ? new LocalVersionList.FileSystem[m_CachedFileSystemsForGenerateReadWriteVersionList.Count] : null; if (fileSystems != null) { int index = 0; foreach (KeyValuePair <string, List <int> > i in m_CachedFileSystemsForGenerateReadWriteVersionList) { fileSystems[index++] = new LocalVersionList.FileSystem(i.Key, i.Value.ToArray()); i.Value.Clear(); } } LocalVersionList versionList = new LocalVersionList(resources, fileSystems); if (!m_ResourceManager.m_ReadWriteVersionListSerializer.Serialize(fileStream, versionList)) { throw new GameFrameworkException("Serialize read-write version list failure."); } if (fileStream != null) { fileStream.Dispose(); fileStream = null; } } catch (Exception exception) { if (fileStream != null) { fileStream.Dispose(); fileStream = null; } if (File.Exists(m_ReadWriteVersionListTempFileName)) { File.Delete(m_ReadWriteVersionListTempFileName); } throw new GameFrameworkException(Utility.Text.Format("Generate read-write version list exception '{0}'.", exception.ToString()), exception); } if (File.Exists(m_ReadWriteVersionListFileName)) { File.Delete(m_ReadWriteVersionListFileName); } File.Move(m_ReadWriteVersionListTempFileName, m_ReadWriteVersionListFileName); m_CurrentGenerateReadWriteVersionListLength = 0; }
private void GenerateReadWriteVersionList() { string readWriteVersionListFileName = Utility.Path.GetRegularPath(Path.Combine(m_ResourceManager.m_ReadWritePath, LocalVersionListFileName)); string readWriteVersionListTempFileName = Utility.Text.Format("{0}.{1}", readWriteVersionListFileName, TempExtension); SortedDictionary <string, List <int> > cachedFileSystemsForGenerateReadWriteVersionList = new SortedDictionary <string, List <int> >(StringComparer.Ordinal); FileStream fileStream = null; try { fileStream = new FileStream(readWriteVersionListTempFileName, FileMode.Create, FileAccess.Write); LocalVersionList.Resource[] resources = m_VerifyInfos.Count > 0 ? new LocalVersionList.Resource[m_VerifyInfos.Count] : null; if (resources != null) { int index = 0; foreach (VerifyInfo i in m_VerifyInfos) { resources[index] = new LocalVersionList.Resource(i.ResourceName.Name, i.ResourceName.Variant, i.ResourceName.Extension, (byte)i.LoadType, i.Length, i.HashCode); if (i.UseFileSystem) { List <int> resourceIndexes = null; if (!cachedFileSystemsForGenerateReadWriteVersionList.TryGetValue(i.FileSystemName, out resourceIndexes)) { resourceIndexes = new List <int>(); cachedFileSystemsForGenerateReadWriteVersionList.Add(i.FileSystemName, resourceIndexes); } resourceIndexes.Add(index); } index++; } } LocalVersionList.FileSystem[] fileSystems = cachedFileSystemsForGenerateReadWriteVersionList.Count > 0 ? new LocalVersionList.FileSystem[cachedFileSystemsForGenerateReadWriteVersionList.Count] : null; if (fileSystems != null) { int index = 0; foreach (KeyValuePair <string, List <int> > i in cachedFileSystemsForGenerateReadWriteVersionList) { fileSystems[index++] = new LocalVersionList.FileSystem(i.Key, i.Value.ToArray()); i.Value.Clear(); } } LocalVersionList versionList = new LocalVersionList(resources, fileSystems); if (!m_ResourceManager.m_ReadWriteVersionListSerializer.Serialize(fileStream, versionList)) { throw new GameFrameworkException("Serialize read-write version list failure."); } if (fileStream != null) { fileStream.Dispose(); fileStream = null; } } catch (Exception exception) { if (fileStream != null) { fileStream.Dispose(); fileStream = null; } if (File.Exists(readWriteVersionListTempFileName)) { File.Delete(readWriteVersionListTempFileName); } throw new GameFrameworkException(Utility.Text.Format("Generate read-write version list exception '{0}'.", exception), exception); } if (File.Exists(readWriteVersionListFileName)) { File.Delete(readWriteVersionListFileName); } File.Move(readWriteVersionListTempFileName, readWriteVersionListFileName); }