static int LoadVersions(IntPtr L) { try { ToLua.CheckArgsCount(L, 1); string arg0 = ToLua.CheckString(L, 1); libx.Versions o = libx.Assets.LoadVersions(arg0); ToLua.PushObject(L, o); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
public static void CopyAssetBundlesTo(string path, bool vfs = true) { #if UNITY_IPHONE vfs = false; #endif if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } var versions = new List <VFile>(); if (!vfs) { versions.AddRange(Versions.LoadVersions(outputPath + "/" + Versions.Filename)); versions.Add(new VFile() { name = Versions.Filename }); versions.RemoveAt(versions.FindIndex(file => file.name.Equals(Versions.Dataname))); } else { versions.Add(new VFile() { name = Versions.Filename }); versions.Add(new VFile() { name = Versions.Dataname }); } foreach (var item in versions) { var src = outputPath + "/" + item.name; var dest = path + "/" + item.name; if (File.Exists(src)) { File.Copy(src, dest, true); } } AssetDatabase.Refresh(); }
private IEnumerator Checking() { if (!Directory.Exists(_savePath)) { Directory.CreateDirectory(_savePath); } this.Step = Step.Copy; if (this.Step == Step.Copy) { yield return(RequestCopy()); } if (this.Step == Step.Coping) { var path = _savePath + Versions.Filename + ".tmp"; var versions = Versions.LoadVersions(path); var basePath = GetStreamingAssetsPath() + "/"; yield return(UpdateCopy(versions, basePath)); this.Step = Step.Versions; } if (this.Step == Step.Versions) { yield return(RequestVersions()); } if (this.Step == Step.Prepared) { OnMessage("正在检查版本信息..."); var totalSize = _downloader.size; if (totalSize > 0) { Debug.Log($"发现内容更新,总计需要下载 {Downloader.GetDisplaySize(totalSize)} 内容"); _downloader.StartDownload(); this.Step = Step.Download; } else { OnComplete(); } } }
private void OnComplete() { if (enableVFS) { var dataPath = _savePath + Versions.Dataname; var downloads = _downloader.downloads; if (downloads.Count > 0 && File.Exists(dataPath)) { OnMessage("更新本地版本信息"); var files = new List <VFile>(downloads.Count); foreach (var download in downloads) { files.Add(new VFile { name = download.name, hash = download.hash, len = download.len, }); } var file = files[0]; if (!file.name.Equals(Versions.Dataname)) { Versions.UpdateDisk(dataPath, files); } } Versions.LoadDisk(dataPath); } OnProgress(1); OnMessage("更新完成"); var version = Versions.LoadVersion(_savePath + Versions.Filename); if (version > 0) { OnVersion(version.ToString()); } _step = STEP_COMPLETE; StartCoroutine(LoadGameScene()); }
private IEnumerator RequestVersions() { OnMessage("正在获取版本信息..."); if (Application.internetReachability == NetworkReachability.NotReachable) { Debug.LogError("请检查网络连接状态"); yield break; } var request = UnityWebRequest.Get(GetDownloadURL(Versions.Filename)); request.downloadHandler = new DownloadHandlerFile(_savePath + Versions.Filename); yield return(request.SendWebRequest()); var error = request.error; request.Dispose(); if (!string.IsNullOrEmpty(error)) { Debug.LogError($"获取服务器版本失败:{error}"); yield break; } try { _versions = Versions.LoadVersions(_savePath + Versions.Filename, true); if (_versions.Count > 0) { PrepareDownloads(); this.Step = Step.Prepared; } else { OnComplete(); } } catch (Exception e) { Debug.LogException(e); Debug.LogError("版本文件加载失败"); } }
private IEnumerator RequestCopy() { int v1; try { v1 = Versions.LoadVersion(_savePath + Versions.Filename); } catch (Exception e) { yield break; } var basePath = GetStreamingAssetsPath() + "/"; var request = UnityWebRequest.Get(basePath + Versions.Filename); var path = _savePath + Versions.Filename + ".tmp"; request.downloadHandler = new DownloadHandlerFile(path); yield return(request.SendWebRequest()); if (string.IsNullOrEmpty(request.error)) { var v2 = Versions.LoadVersion(path); if (v2 > v1) { var mb = MessageBox.Show("提示", "是否将资源解压到本地?", "[解压]", "[跳过]"); yield return(mb); if (mb.isOk) { var versions = Versions.LoadVersions(path); yield return(UpdateCopy(versions, basePath)); } } else { Versions.LoadVersions(path); } } request.Dispose(); }
public static Versions LoadVersions(string filename) { if (!File.Exists(filename)) { return(new Versions()); } try { using (var stream = File.OpenRead(filename)) { var reader = new BinaryReader(stream); var ver = new Versions(); ver.Deserialize(reader); return(ver); } } catch (Exception e) { Debug.LogException(e); return(new Versions()); } }
private void PrepareDownloads() { if (enableVFS) { var path = string.Format("{0}{1}", _savePath, Versions.Dataname); if (!File.Exists(path)) { AddDownload(_versions[0]); return; } Versions.LoadDisk(path); } for (var i = 1; i < _versions.Count; i++) { var item = _versions[i]; if (Versions.IsNew(string.Format("{0}{1}", _savePath, item.name), item.len, item.hash)) { AddDownload(item); } } }
private static void BuildVersions(AssetBundleManifest manifest, BuildRules rules) { var allBundles = manifest.GetAllAssetBundles(); var bundle2Ids = GetBundle2Ids(allBundles); var bundles = GetBundles(manifest, allBundles, bundle2Ids); var ver = rules.AddVersion(); var dirs = new List <string>(); var assets = new List <AssetRef>(); var patches = new List <Patch>(); var asset2Bundles = new Dictionary <string, BundleRef>(); foreach (var item in rules.assets) { var path = item.name; var dir = Path.GetDirectoryName(path); if (!string.IsNullOrEmpty(dir)) { dir = dir.Replace("\\", "/"); } var index = dirs.FindIndex(o => o.Equals(dir)); if (index == -1) { index = dirs.Count; dirs.Add(dir); } var asset = new AssetRef(); if (item.groupBy == GroupBy.None) { var id = AddBundle(path, asset, ref bundles); asset.bundle = id; } else { bundle2Ids.TryGetValue(item.bundle, out asset.bundle); } asset2Bundles[path] = bundles[asset.bundle]; asset.dir = index; asset.name = Path.GetFileName(path); assets.Add(asset); } Func <List <string>, List <int> > getFiles = delegate(List <string> list) { var ret = new List <int>(); foreach (var file in list) { BundleRef bundle; asset2Bundles.TryGetValue(file, out bundle); if (bundle != null) { if (!ret.Contains(bundle.id)) { ret.Add(bundle.id); } foreach (var child in bundle.children) { if (!ret.Contains(child)) { ret.Add(child); } } } else { Debug.LogWarning("bundle == nil, file:" + file); } } return(ret); }; for (var i = 0; i < rules.patches.Count; i++) { var item = rules.patches[i]; patches.Add(new Patch { name = item.name, files = getFiles(item.assets), }); } var versions = new Versions(); versions.activeVariants = manifest.GetAllAssetBundlesWithVariant(); versions.dirs = dirs.ToArray(); versions.assets = assets; versions.bundles = bundles; versions.patches = patches; versions.ver = ver; if (rules.allAssetsToBuild) { bundles.ForEach(obj => obj.location = 1); } else { foreach (var patchName in rules.patchesInBuild) { var patch = versions.patches.Find((Patch item) => { return(item.name.Equals(patchName)); }); if (patch != null) { foreach (var file in patch.files) { if (file >= 0 && file < bundles.Count) { bundles[file].location = 1; } } } } } versions.Save(outputPath + "/" + Assets.Versions); }
public static void BuildAssetBundles() { // Choose the output path according to the build target. var outputPath = CreateAssetBundleDirectory(); const BuildAssetBundleOptions options = BuildAssetBundleOptions.ChunkBasedCompression; var targetPlatform = EditorUserBuildSettings.activeBuildTarget; var rules = GetBuildRules(); var builds = rules.GetBuilds(); var assetBundleManifest = BuildPipeline.BuildAssetBundles(outputPath, builds, options, targetPlatform); if (assetBundleManifest == null) { return; } var manifest = GetManifest(); var dirs = new List <string> (); var assets = new List <AssetRef> (); var bundles = assetBundleManifest.GetAllAssetBundles(); var bundle2Ids = new Dictionary <string, int> (); for (var index = 0; index < bundles.Length; index++) { var bundle = bundles [index]; bundle2Ids [bundle] = index; } var bundleRefs = new List <BundleRef> (); for (var index = 0; index < bundles.Length; index++) { var bundle = bundles [index]; var deps = assetBundleManifest.GetAllDependencies(bundle); var path = string.Format("{0}/{1}", outputPath, bundle); if (File.Exists(path)) { using (var stream = File.OpenRead(path)) { bundleRefs.Add(new BundleRef { name = bundle, id = index, deps = Array.ConvertAll(deps, input => bundle2Ids [input]), len = stream.Length, hash = assetBundleManifest.GetAssetBundleHash(bundle).ToString(), }); } } else { Debug.LogError(path + " file not exsit."); } } for (var i = 0; i < rules.ruleAssets.Length; i++) { var item = rules.ruleAssets [i]; var path = item.path; var dir = Path.GetDirectoryName(path).Replace("\\", "/"); var index = dirs.FindIndex(o => o.Equals(dir)); if (index == -1) { index = dirs.Count; dirs.Add(dir); } try { var asset = new AssetRef { bundle = bundle2Ids[item.bundle], dir = index, name = Path.GetFileName(path) }; assets.Add(asset); } catch (KeyNotFoundException) { Debug.LogError($"{Path.GetFileName(path)}资源无法打进AB包"); } } manifest.dirs = dirs.ToArray(); manifest.assets = assets.ToArray(); manifest.bundles = bundleRefs.ToArray(); EditorUtility.SetDirty(manifest); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); var manifestBundleName = "manifest.unity3d"; builds = new[] { new AssetBundleBuild { assetNames = new[] { AssetDatabase.GetAssetPath(manifest), }, assetBundleName = manifestBundleName } }; BuildPipeline.BuildAssetBundles(outputPath, builds, options, targetPlatform); ArrayUtility.Add(ref bundles, manifestBundleName); Versions.BuildVersions(outputPath, bundles, GetBuildRules().AddVersion()); }
private IEnumerator Checking() { if (!Directory.Exists(_savePath)) { Directory.CreateDirectory(_savePath); } yield return(ExtractAssetsIfNeed()); if (Application.internetReachability == NetworkReachability.NotReachable) { var mb = MessageBox.Show("提示", "网络状态不可达,请联网后重试。", "重试", "退出"); yield return(mb); if (mb.isOk) { StartUpdate(); } else { Quit(); MessageBox.Dispose(); } yield break; } OnMessage("正在获取服务器版本信息..."); const string assetName = Versions.Filename; var url = downloadUrl + assetName; var request = UnityWebRequest.Get(url); yield return(request.SendWebRequest()); if (!string.IsNullOrEmpty(request.error)) { var mb = MessageBox.Show("提示", string.Format("获取服务器版本失败:{0}", request.error), "重试", "退出"); yield return(mb); if (mb.isOk) { StartUpdate(); } else { Quit(); MessageBox.Dispose(); } yield break; } var path = _savePath + assetName; var bytes = request.downloadHandler.text; File.WriteAllText(path, bytes); request.Dispose(); OnMessage("正在加载版本信息..."); if (!File.Exists(path)) { yield break; } var records = Versions.LoadVersions(path); OnMessage("正在检查版本信息..."); _serverRecords.Clear(); _downloads.Clear(); foreach (var item in records) { _serverRecords[item.name] = item; if (IsUpdate(item)) { AddDownload(item); } } if (_downloads.Count > 0) { var totalSize = 0L; foreach (var item in _downloads) { totalSize += item.len; } const float bytesToMb = 1f / (1024 * 1024); var tips = string.Format("检查到有{0}个文件需要更新,总计需要下载{1:f2}(MB)内容", _downloads.Count, totalSize * bytesToMb); var mb = MessageBox.Show("提示", tips, "下载", "跳过"); yield return(mb); if (mb.isOk) { PrepareToDownload(); yield return(UpdateDownloads(bytesToMb, totalSize)); } } OnComplete(); }
private static void BuildManifest(AssetBundleManifest assetBundleManifest, string bundleDir, BuildRules rules) { var manifest = GetManifest(); var allAssetBundles = assetBundleManifest.GetAllAssetBundles(); var bundle2Ids = GetBundle2Ids(allAssetBundles); var bundles = GetBundles(assetBundleManifest, bundleDir, allAssetBundles, bundle2Ids); var dirs = new List <string>(); var assets = new List <AssetRef>(); var patches = new List <VPatch>(); for (var i = 0; i < rules.assets.Length; i++) { var item = rules.assets[i]; var path = item.path; var dir = Path.GetDirectoryName(path).Replace("\\", "/"); var index = dirs.FindIndex(o => o.Equals(dir)); if (index == -1) { index = dirs.Count; dirs.Add(dir); } var asset = new AssetRef(); if (!bundle2Ids.TryGetValue(item.bundle, out asset.bundle)) { // 第三方资源 var bundle = new BundleRef(); bundle.id = bundles.Count; bundle.name = Path.GetFileName(path); using (var stream = File.OpenRead(path)) { bundle.len = stream.Length; bundle.crc = Utility.GetCRC32Hash(stream); } bundles.Add(bundle); asset.bundle = bundle.id; } asset.dir = index; asset.name = Path.GetFileName(path); assets.Add(asset); var patch = patches.Find(pr => pr.@by == item.patch); if (patch == null) { patch = new VPatch() { @by = item.patch }; patches.Add(patch); } if (asset.bundle != -1) { if (!patch.files.Contains(asset.bundle)) { patch.files.Add(asset.bundle); } var bundle = bundles[asset.bundle]; foreach (var child in bundle.children) { if (!patch.files.Contains(child)) { patch.files.Add(child); } } } } manifest.dirs = dirs.ToArray(); manifest.assets = assets.ToArray(); manifest.bundles = bundles.ToArray(); EditorUtility.SetDirty(manifest); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); var manifestBundleName = "manifest.unity3d"; var builds = new[] { new AssetBundleBuild { assetNames = new[] { AssetDatabase.GetAssetPath(manifest), }, assetBundleName = manifestBundleName } }; var targetPlatform = EditorUserBuildSettings.activeBuildTarget; BuildPipeline.BuildAssetBundles(bundleDir, builds, rules.buildBundleOptions, targetPlatform); { var path = bundleDir + "/" + manifestBundleName; var bundle = new BundleRef(); bundle.id = bundles.Count; bundle.name = Path.GetFileName(path); using (var stream = File.OpenRead(path)) { bundle.len = stream.Length; bundle.crc = Utility.GetCRC32Hash(stream); } var patch = patches.Find(pr => pr.@by == PatchBy.Level0); if (patch == null) { patch = new VPatch() { @by = PatchBy.Level0 }; patches.Add(patch); } bundles.Add(bundle); } Versions.BuildVersion(bundleDir, bundles, patches, GetBuildRules().AddVersion()); }
private void Complete() { updateScreen.progressBar.gameObject.SetActive(false); Versions.Save(); if (_downloads.Count > 0) { for (int i = 0; i < _downloads.Count; i++) { var item = _downloads[i]; if (!item.isDone) { break; } else { if (_serverVersions.ContainsKey(item.path)) { _versions[item.path] = _serverVersions[item.path]; } } } StringBuilder sb = new StringBuilder(); foreach (var item in _versions) { sb.AppendLine(string.Format("{0}:{1}", item.Key, item.Value)); } var path = Assets.GetRelativeUpdatePath(versionsTxt); if (File.Exists(path)) { File.Delete(path); } File.WriteAllText(path, sb.ToString()); var request = Assets.Initialize(); request.completed = delegate(AssetRequest req) { if (!string.IsNullOrEmpty(req.error)) { OnError(req.error); } else { if (completed != null) { completed(); } } }; state = State.Completed; message = string.Format("{0} files has update.", _downloads.Count); return; } if (completed != null) { completed(); } message = "nothing to update."; state = State.Completed; }
public static async void CopyAssetBundlesTo(string path) { var prefix = $"JEngine.Editor.Setting.{Application.productName}"; var jump = PlayerPrefs.GetString($"{prefix}.JumpStartUpScene", "1") == "1"; var scene = SceneManager.GetActiveScene(); if (scene.path != Setting.StartUpScenePath) { if (!jump) { Debug.LogError("请前往启动场景进行该操作,或在JEngine面板配置启动场景"); return; } string name = Setting.StartUpScenePath; scene = EditorSceneManager.OpenScene(name, OpenSceneMode.Additive); while (!scene.isLoaded) { await Task.Delay(10); } } bool vfs = Object.FindObjectOfType <Updater>().enableVFS; EditorSceneManager.CloseScene(scene, true); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } var versions = new List <VFile>(); if (!vfs) { versions.AddRange(Versions.LoadVersions(outputPath + "/" + Versions.Filename)); versions.Add(new VFile() { name = Versions.Filename }); versions.RemoveAt(versions.FindIndex(file => file.name.Equals(Versions.Dataname))); } else { versions.Add(new VFile() { name = Versions.Filename }); versions.Add(new VFile() { name = Versions.Dataname }); } foreach (var item in versions) { var src = outputPath + "/" + item.name; var dest = path + "/" + item.name; if (File.Exists(src)) { File.Copy(src, dest, true); } } AssetDatabase.Refresh(); }
private void Start() { state = State.Wait; Versions.Load(); Check(); }
private void Update() { switch (_step) { case Step.Wait: break; case Step.Version: _step = Step.Wait; OnMessage("正在获取版本信息..."); if (!Directory.Exists(_savePath)) { Directory.CreateDirectory(_savePath); } if (Application.internetReachability == NetworkReachability.NotReachable) { MessageBox.Show("提示", "请检查网络连接状态", "重试", "退出").onComplete = OnErrorAction; return; } var request = Download(Versions.Filename); var oper = request.SendWebRequest(); oper.completed += delegate(AsyncOperation operation) { if (!string.IsNullOrEmpty(request.error)) { MessageBox.Show("提示", string.Format("获取服务器版本失败:{0}", request.error), "重试", "退出").onComplete = OnErrorAction; } else { try { Versions.serverVersion = Versions.LoadFullVersion(_savePath + Versions.Filename); var newFiles = Versions.GetNewFiles(PatchId.Level1, _savePath); if (newFiles.Count > 0) { foreach (var item in newFiles) { _downloader.AddDownload(GetDownloadURL(item.name), item.name, _savePath + item.name, item.hash, item.len); } _step = Step.Prepared; } else { OnComplete(); } } catch (Exception e) { Debug.LogException(e); MessageBox.Show("提示", "版本文件加载失败", "重试", "退出").onComplete += OnErrorAction; } } }; break; case Step.Prepared: OnMessage("正在检查版本信息..."); _step = Step.Wait; var totalSize = _downloader.size; if (totalSize > 0) { var tips = string.Format("发现内容更新,总计需要下载 {0} 内容", Downloader.GetDisplaySize(totalSize)); MessageBox.Show("提示", tips, "下载", "退出").onComplete += delegate(MessageBox.EventId id) { if (id == MessageBox.EventId.Ok) { _downloader.StartDownload(); _step = Step.Download; } else { Quit(); } }; } else { OnComplete(); } break; } }
private static void OnInitialize() { var sceneAssets = new List <string>(); var rules = BuildScript.GetBuildRules(); foreach (var guid in AssetDatabase.FindAssets("t:Scene", new[] { "Assets" })) { var assetPath = AssetDatabase.GUIDToAssetPath(guid); sceneAssets.Add(assetPath); } var patches = new List <Patch>(); var assets = new List <AssetRef>(); var searchPaths = new List <string>(); var dirs = new Dictionary <string, int>(); foreach (var asset in rules.assets) { if (!File.Exists(asset.name)) { continue; } var dir = Path.GetDirectoryName(asset.name); if (!string.IsNullOrEmpty(dir)) { if (!searchPaths.Contains(dir)) { dirs[dir] = searchPaths.Count; searchPaths.Add(dir); } } var ar = new AssetRef { name = Path.GetFileName(asset.name), bundle = -1, dir = dirs[dir] }; assets.Add(ar); } var scenes = new EditorBuildSettingsScene[sceneAssets.Count]; for (var index = 0; index < sceneAssets.Count; index++) { var asset = sceneAssets[index]; scenes[index] = new EditorBuildSettingsScene(asset, true); var dir = Path.GetDirectoryName(asset); if (!searchPaths.Contains(dir)) { searchPaths.Add(dir); } } for (var i = 0; i < rules.patches.Count; i++) { var item = rules.patches[i]; var patch = new Patch(); patch.name = item.name; patches.Add(patch); } var developVersions = new Versions(); developVersions.dirs = searchPaths.ToArray(); developVersions.assets = assets; developVersions.patches = patches; Assets.basePath = Environment.CurrentDirectory.Replace("\\", "/") + "/" + BuildScript.outputPath + "/"; Assets.assetLoader = AssetDatabase.LoadAssetAtPath; Assets.versionsLoader += () => developVersions; Assets.onAssetLoaded += rules.OnLoadAsset; Assets.onAssetUnloaded += rules.OnUnloadAsset; rules.BeginSample(); EditorBuildSettings.scenes = scenes; EditorApplication.playModeStateChanged += EditorApplicationOnplayModeStateChanged; }
public static void BuildAssetBundles() { // Choose the output path according to the build target. var outputPath = CreateAssetBundleDirectory(); const BuildAssetBundleOptions options = BuildAssetBundleOptions.ChunkBasedCompression; var targetPlatform = EditorUserBuildSettings.activeBuildTarget; var rules = GetBuildRules(); var builds = rules.GetBuilds(); var assetBundleManifest = BuildPipeline.BuildAssetBundles(outputPath, builds, options, targetPlatform); if (assetBundleManifest == null) { return; } var manifest = GetManifest(); var dirs = new List <string>(); var assets = new List <AssetRef>(); var bundles = assetBundleManifest.GetAllAssetBundles(); var bundle2Ids = new Dictionary <string, int>(); for (var index = 0; index < bundles.Length; index++) { var bundle = bundles[index]; bundle2Ids[bundle] = index; } var bundleRefs = new List <BundleRef>(); for (var index = 0; index < bundles.Length; index++) { var bundle = bundles[index]; var deps = assetBundleManifest.GetAllDependencies(bundle); var path = string.Format("{0}/{1}", outputPath, bundle); if (File.Exists(path)) { using (var stream = File.OpenRead(path)) { bundleRefs.Add(new BundleRef { name = bundle, id = index, deps = Array.ConvertAll(deps, input => bundle2Ids[input]), len = stream.Length, hash = assetBundleManifest.GetAssetBundleHash(bundle).ToString(), }); } } else { Debug.LogError(path + " file not exsit."); } } for (var i = 0; i < rules.ruleAssets.Length; i++) { var item = rules.ruleAssets[i]; var path = item.path; var dir = Path.GetDirectoryName(path); var index = dirs.FindIndex(o => o.Equals(dir)); if (index == -1) { index = dirs.Count; dirs.Add(dir); } var asset = new AssetRef { bundle = bundle2Ids[item.bundle], dir = index, name = Path.GetFileName(path) }; assets.Add(asset); } manifest.searchDirs = Array.ConvertAll(rules.rules, input => input.searchPath); manifest.dirs = dirs.ToArray(); manifest.assets = assets.ToArray(); manifest.bundles = bundleRefs.ToArray(); EditorUtility.SetDirty(manifest); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); var version = 0; var versionFile = string.Format("{0}/{1}", outputPath, Versions.BuildVersion); if (File.Exists(versionFile)) { version = int.Parse(File.ReadAllText(versionFile)); version = version + 1; } File.WriteAllText(versionFile, version.ToString()); var manifestBundleName = "manifest.unity3d"; builds = new[] { new AssetBundleBuild { assetNames = new[] { AssetDatabase.GetAssetPath(manifest), }, assetBundleName = manifestBundleName } }; BuildPipeline.BuildAssetBundles(outputPath, builds, options, targetPlatform); ArrayUtility.Add(ref bundles, manifestBundleName); ArrayUtility.Add(ref bundles, Versions.BuildVersion); if (Directory.Exists(rules.outputPath)) { var files = Directory.GetFiles(rules.outputPath); foreach (var file in files) { File.Delete(file); } } else { Directory.CreateDirectory(rules.outputPath); } foreach (var item in bundles) { var sourceFileName = string.Format("{0}/{1}", outputPath, item); var destFileName = string.Format("{0}/{1}", rules.outputPath, item); File.Copy(sourceFileName, destFileName, true); } Versions.MakeRecords(rules.outputPath); }
private IEnumerator Checking() { if (!Directory.Exists(_savePath)) { Directory.CreateDirectory(_savePath); } if (_step == Step.Wait) { enableVFS = true; #if UNITY_IPHONE enableVFS = false; #endif _step = Step.Copy; } if (_step == Step.Copy) { yield return(RequestCopy()); } if (_step == Step.Coping) { var path = _savePath + Versions.Filename + ".tmp"; var versions = Versions.LoadVersions(path); var basePath = GetBasePath(); yield return(UpdateCopy(versions, basePath)); _step = Step.Versions; } if (_step == Step.Versions) { yield return(RequestVersions()); } if (_step == Step.Prepared) { OnMessage("正在检查版本信息..."); var totalSize = _downloader.size; if (totalSize > 0) { var tips = string.Format("发现内容更新,总计需要下载 {0} 内容", Downloader.GetDisplaySize(totalSize)); var mb = MessageBox.Show("提示", tips, "下载", "退出"); yield return(mb); if (mb.isOk) { _downloader.StartDownload(); _step = Step.Download; } else { Quit(); } } else { OnComplete(); } } }
private IEnumerator RequestVersions() { OnMessage("正在获取版本信息..."); if (Application.internetReachability == NetworkReachability.NotReachable) { var mb = MessageBox.Show("提示", "请检查网络连接状态", "重试", "退出"); yield return(mb); if (mb.isOk) { StartUpdate(); } else { Quit(); } yield break; } var request = UnityWebRequest.Get(GetDownloadURL(Versions.Filename)); request.downloadHandler = new DownloadHandlerFile(_savePath + Versions.Filename); yield return(request.SendWebRequest()); var error = request.error; request.Dispose(); if (!string.IsNullOrEmpty(error)) { var mb = MessageBox.Show("提示", string.Format("获取服务器版本失败:{0}", error), "重试", "退出"); yield return(mb); if (mb.isOk) { StartUpdate(); } else { Quit(); } yield break; } try { var v1 = Versions.LoadVersion(_savePath + Versions.Filename); //网络版本文件 var v2 = Versions.LoadVersion(_savePath + Versions.Filename + ".tmp"); //本地临时文件 if (v2 > v1) { //如果本地版本高于网络版本,就别更新了 OnComplete(); yield break; } //网络版本高于或者等于本地版本,则检查更新 _versions = Versions.LoadVersions(_savePath + Versions.Filename, true); if (_versions.Count > 0) { PrepareDownloads(); _step = Step.Prepared; } else { OnComplete(); } } catch (Exception e) { Debug.LogException(e); MessageBox.Show("提示", "版本文件加载失败", "重试", "退出").onComplete += delegate(MessageBox.EventId id) { if (id == MessageBox.EventId.Ok) { StartUpdate(); } else { Quit(); } }; } }
internal override void Load() { asset = Versions.LoadAssetBundleFromFile(url); if (assetBundle == null) error = url + " LoadFromFile failed."; }
public void Update() { if (isDone) { return; } switch (state) { case State.HeadRequest: if (request.error != null) { error = request.error; } if (request.isDone) { maxlen = long.Parse(request.GetResponseHeader("Content-Length")); request.Dispose(); request = null; var dir = Path.GetDirectoryName(savePath); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } fs = new FileStream(savePath, FileMode.OpenOrCreate, FileAccess.Write); len = fs.Length; var emptyVersion = string.IsNullOrEmpty(version); var oldVersion = Versions.Get(savePath); var emptyOldVersion = string.IsNullOrEmpty(oldVersion); if (emptyVersion || emptyOldVersion || !oldVersion.Equals(version)) { Versions.Set(savePath, version); len = 0; } if (len < maxlen) { fs.Seek(len, SeekOrigin.Begin); request = UnityWebRequest.Get(url); request.SetRequestHeader("Range", "bytes=" + len + "-"); request.SendWebRequest(); state = State.ContentRequest; index = 0; } else { state = State.FinishRequest; } } break; case State.ContentRequest: if (request.error != null) { error = request.error; } if (!request.isDone) { WriteBuffer(); } else { WriteBuffer(); if (fs != null) { fs.Close(); fs.Dispose(); } request.Dispose(); state = State.FinishRequest; } break; case State.FinishRequest: if (completed != null) { completed.Invoke(); } isDone = true; state = State.Completed; break; } }
private static void BuildVersions() { Versions.BuildVersions(Assets.AssetBundles); }