public bool Load(string path) { // issue // android, webgl error if (!File.Exists(path)) { UnityEngine.Debug.LogError("[XAsset] File:Exists() return false."); return(false); } Clear(); name = path; using (var reader = new BinaryReader(File.OpenRead(path))) { var count = reader.ReadInt32(); for (var i = 0; i < count; i++) { var file = new VFile { Id = i }; file.Deserialize(reader); AddFile(file); } _pos = reader.BaseStream.Position; } Reindex(); return(true); }
public static List <VFile> LoadVersions(string filename, bool update = false) { var rootDir = Path.GetDirectoryName(filename); var data = update ? _updateData : _baseData; data.Clear(); using (var stream = File.OpenRead(filename)) { var reader = new BinaryReader(stream); var list = new List <VFile>(); var ver = reader.ReadInt32(); Debug.Log("LoadVersions:" + ver); var count = reader.ReadInt32(); for (var i = 0; i < count; i++) { var version = new VFile(); version.Deserialize(reader); list.Add(version); data[version.Name] = version; var dir = string.Format("{0}/{1}", rootDir, Path.GetDirectoryName(version.Name)); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } } return(list); } }
public void AddFile(string path, long len, string hash) { var file = new VFile { Name = path, Len = len, Hash = hash }; AddFile(file); }
//public static AssetBundle LoadAssetBundleFromFile(string url) //{ // if (!File.Exists(url)) // { // if (_disk != null) // { // var name = Path.GetFileName(url); // var file = _disk.GetFile(name, string.Empty); // if (file != null) // { // return AssetBundle.LoadFromFile(_disk.name, 0, (ulong)file.offset); // } // } // } // return AssetBundle.LoadFromFile(url); //} //public static AssetBundleCreateRequest LoadAssetBundleFromFileAsync(string url) //{ // if (!File.Exists(url)) // { // if (_disk != null) // { // var name = Path.GetFileName(url); // var file = _disk.GetFile(name, string.Empty); // if (file != null) // { // return AssetBundle.LoadFromFileAsync(_disk.name, 0, (ulong)file.offset); // } // } // } // return AssetBundle.LoadFromFileAsync(url); //} public static void BuildVersions(string outputPath, string[] bundles, int version) { var path = outputPath + "/" + Filename; if (File.Exists(path)) { File.Delete(path); } var dataPath = outputPath + "/" + Dataname; if (File.Exists(dataPath)) { File.Delete(dataPath); } var disk = new VDisk(); foreach (var file in bundles) { using (var fs = File.OpenRead(outputPath + "/" + file)) { disk.AddFile(file, fs.Length, Utility.GetCRC32Hash(fs)); } } disk.name = dataPath; disk.Save(); using (var stream = File.OpenWrite(path)) { var writer = new BinaryWriter(stream); writer.Write(version); writer.Write(disk.files.Count + 1); using (var fs = File.OpenRead(dataPath)) { var file = new VFile { Name = Dataname, Len = fs.Length, Hash = Utility.GetCRC32Hash(fs) }; file.Serialize(writer); } foreach (var file in disk.files) { file.Serialize(writer); } } }
private void AddDownload(VFile item) { _downloader.AddDownload(GetDownloadURL(item.Name), item.Name, _savePath + item.Name, item.Hash, item.Len); }
private void AddFile(VFile file) { _data[file.Name] = file; files.Add(file); }