Example #1
0
 void Open(Page page, string file)
 {
     try {
         FileInfo info = new FileInfo(file);
         page.file = info.FullName;
         if (info.Name == "level.dat")
         {
             page.Text = info.Directory.Name;
         }
         else
         {
             page.Text = info.Name;
         }
         Text                = "INVedit - " + page.Text;
         page.changed        = false;
         btnSave.Enabled     = true;
         btnCloseTab.Enabled = true;
         btnReload.Enabled   = true;
         NbtTag tag = NbtTag.Load(file);
         if (tag.Type == NbtTagType.Compound && tag.Contains("Data"))
         {
             tag = tag["Data"];
         }
         if (tag.Type == NbtTagType.Compound && tag.Contains("Player"))
         {
             tag = tag["Player"];
         }
         if (tag.Type == NbtTagType.Compound && tag.Contains("Inventory"))
         {
             tag = tag["Inventory"];
         }
         if (tag.Name != "Inventory")
         {
             throw new Exception("Can't find Inventory tag.");
         }
         Inventory.Load(tag, page.slots);
     } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); }
 }
Example #2
0
 void Save(Page page, string file)
 {
     try {
         FileInfo info = new FileInfo(file);
         if (info.Exists && page.file != info.FullName)
         {
             string str;
             if (info.Name == "level.dat")
             {
                 str = "Are you sure you want to overwrite " + info.Directory.Name + "?";
             }
             else
             {
                 str = "Are you sure you want to overwrite '" + info.Name + "'?";
             }
             DialogResult result = MessageBox.Show(str, "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
             if (result != DialogResult.Yes)
             {
                 return;
             }
         }
         page.file = info.FullName;
         NbtTag root, tag;
         if (info.Exists)
         {
             root = NbtTag.Load(page.file);
             if (info.Extension.ToLower() == ".dat")
             {
                 CreateBackup(file);
             }
             tag = root;
         }
         else
         {
             if (info.Extension.ToLower() == ".dat")
             {
                 MessageBox.Show("You can't create a new Minecraft level/player file.\n" +
                                 "Select an existing one instead.", "Error",
                                 MessageBoxButtons.OK, MessageBoxIcon.Error);
                 return;
             }
             root = NbtTag.CreateCompound("Inventory", NbtTag.CreateList(NbtTagType.Compound));
             tag  = root;
         } if (tag.Type == NbtTagType.Compound && tag.Contains("Data"))
         {
             tag = tag["Data"];
         }
         if (tag.Type == NbtTagType.Compound && tag.Contains("Player"))
         {
             tag = tag["Player"];
         }
         if (tag.Type != NbtTagType.Compound || !tag.Contains("Inventory"))
         {
             throw new Exception("Can't find Inventory tag.");
         }
         Inventory.Save(tag, page.slots);
         root.Save(page.file);
         if (info.Name == "level.dat")
         {
             page.Text = info.Directory.Name;
         }
         else
         {
             page.Text = info.Name;
         }
         Text              = "INVedit - " + page.Text;
         page.changed      = false;
         btnReload.Enabled = true;
     } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); }
 }