/// <summary> /// 从文件Ian /// </summary> /// <returns></returns> public static List <string> LoadServerUrlFromFile() { List <string> urls = new List <string>(); //获取newgui中的地址 try { var newGuiFile = ".minecraft/config/New Gui.cfg"; if (File.Exists(newGuiFile)) { using (FileStream fs = new FileStream(newGuiFile, FileMode.Open)) { using (StreamReader sr = new StreamReader(fs)) { string line = sr.ReadLine(); while (line != null) { if (line.Contains("S:Address1=")) { urls.Add(line.Replace("S:Address1=", "").Trim()); } if (line.Contains("S:Address2=")) { urls.Add(line.Replace("S:Address2=", "").Trim()); } line = sr.ReadLine(); } } } } } catch { } //获取server.data文件中的地址 try { string serverFilePath = ".minecraft/servers.dat"; if (File.Exists(serverFilePath)) { TagCompound tags = NBTFile.FromFile(serverFilePath); TagList servers = (TagList)tags["servers"]; foreach (TagCompound server in servers) { urls.Add(((TagString)server["ip"]).Value); } } } catch { } return(urls); }
/// <summary> /// パスからフォルダを再帰的に読み込み、ツリーを生成 /// </summary> /// <param name="path">ファイルパス</param> /// <param name="node">ノード</param> /// <returns></returns> private static TreeNode RecursiveLoad(string path, TreeNode node = null) { var addNode = new TreeNode(); addNode.Text.Value = Path.GetFileName(path); // ディレクトリならそのまま再帰読込 // それ以外ならNBTファイルとして読込を試みる if (File.GetAttributes(path).HasFlag(FileAttributes.Directory)) { addNode.Icon.Value = "/Assets/Icons/Folder.png"; try { foreach (var child in Directory.GetFileSystemEntries(path)) { RecursiveLoad(child, addNode); } } catch (DirectoryNotFoundException) { } } else { try { var tag = NBTFile.FromFile(path); addNode.Icon.Value = "/Assets/Icons/Container.png"; addNode.Text.Value += $" [{tag.Count} entries]"; foreach (var child in tag) { addNode.Add(AddTag(child)); } } catch { // 例外を吐いた=NBTファイルではないという安直な考え return(node); } } if (node == null && !string.IsNullOrEmpty(addNode.Icon.Value)) { return(addNode); } node.Add(addNode); return(node); }
/// <summary> /// NBTファイルを開く /// </summary> /// <param name="filePath"></param> public void FileOpen(string filePath) { treeView1.Nodes.Clear(); try { var tag = NBTFile.FromFile(filePath); var node = new TreeNode(); AddTag(tag, node); node.Nodes[0].Text = Path.GetFileName(filePath) ?? throw new InvalidOperationException(); treeView1.Nodes.Add(node.Nodes[0]); treeView1.Sort(); } catch (Exception ex) { MessageBox.Show("サポートされているファイルではありません\n" + ex.Message, "OrangeNBTEditor", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// スコアデータ読み込み /// </summary> public static void Load() { var data = NBTFile.FromFile($@"{World.Path.Value}\data\scoreboard.dat")["data"] as TagCompound; var PlayerScores = data["PlayerScores"] as TagList; // 複数のスコアオブジェクトを持っているエンティティ名を抽出 // #100を除いてユーザー名だと思われる // ソースは俺 var users = PlayerScores.Value .Select(x => ((x as TagCompound)["Name"] as TagString).Value) .GroupBy(x => x) .Where(x => x.Count() > 1) .Select(x => x.Key) .Where(x => x != "#100") .ToList(); var list = PlayerScores.Value .Where(x => users.Contains(((x as TagCompound)["Name"] as TagString).Value)) .GroupBy(x => ((x as TagCompound)["Name"] as TagString).Value) .ToList(); foreach (var user in list) { Application.Current.Dispatcher.Invoke(() => { var userData = new Player(user.Key); Players.Add(userData); PlayerCount.Value++; foreach (var tag in user) { var name = ((tag as TagCompound)["Objective"] as TagString).Value; var value = ((tag as TagCompound)["Score"] as TagInt).Value; if (name == "KnightLevel") { userData.KnightLevel = value; } if (name == "NinjaLevel") { userData.NinjaLevel = value; } if (name == "ArcherLevel") { userData.ArcherLevel = value; } if (name == "WhiteMageLevel") { userData.WhiteMageLevel = value; } if (name == "BlackMageLevel") { userData.BlackMageLevel = value; } if (name == "SummonerLevel") { userData.SummonerLevel = value; } } }); } }