private void Apply(string path, List <LanguageItem> items, List <LanguageItem> signs, List <LanguageItem> containers, List <LanguageItem> Entities, List <LanguageItem> MobSpawners) { //try //{ string[] files = Directory.GetFiles(path + "\\region"); for (int i = 0; i < files.Length; i++) { Dispatcher.BeginInvoke(new Action(delegate { totalProgress.Value += 1; progress.Value = 0; })); RegionFile region = new RegionFile(files[i]); for (int I = 0; I < 32; I++) { for (int J = 0; J < 32; J++) { Dispatcher.BeginInvoke(new Action(delegate { progress.Value += 1; })); if (region.HasChunk(I, J)) { try { NbtTree nbtTree = new NbtTree(); nbtTree.ReadFrom(region.GetChunkDataInputStream(I, J)); TagNodeList tagNodeList = nbtTree.Root["Level"].ToTagCompound()["TileEntities"].ToTagList(); TagNodeList entityList = nbtTree.Root["Level"].ToTagCompound()["Entities"].ToTagList(); bool flag = false; if (entityList != null) { foreach (TagNodeCompound tagNodeCompound in entityList) { if (LangTranslator.EntityTranslator(tagNodeCompound, Entities)) { flag = true; } } } if (tagNodeList != null) { foreach (TagNodeCompound tagNodeCompound in tagNodeList) { string data = tagNodeCompound["id"].ToTagString().Data; if (data == CMDBLOCK) { if (LangTranslator.CommandBlockTranslator(tagNodeCompound, items)) { flag = true; } } else if (data == SIGN) { if (LangTranslator.SignTranslator(tagNodeCompound, signs)) { flag = true; } } else if (tagNodeCompound.ContainsKey("Items") || tagNodeCompound.ContainsKey("RecordItem")) { if (LangTranslator.ContainerTranslator(tagNodeCompound, containers)) { flag = true; } } else if (tagNodeCompound.ContainsKey("SpawnData")) { if (LangTranslator.EntityTranslator(tagNodeCompound["SpawnData"].ToTagCompound(), MobSpawners)) { flag = true; } } } } if (flag) { using (Stream chunkDataOutputStream = region.GetChunkDataOutputStream(I, J)) { nbtTree.WriteTo(chunkDataOutputStream); } } } catch { } } } } } Dispatcher.BeginInvoke(new Action(delegate { progress.Value = 0; totalProgress.Value = 0; progress.IsIndeterminate = true; totalProgress.IsIndeterminate = true; })); //} //catch //{ // Dispatcher.BeginInvoke(new Action(delegate { (System.Windows.Application.Current.MainWindow as MetroWindow).ShowMessageAsync("无法完成操作", "存档可能已经损坏", MessageDialogStyle.Affirmative, new MetroDialogSettings() { AffirmativeButtonText = "确定" }); })); //} }