Ejemplo n.º 1
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); }
 }
Ejemplo n.º 2
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); }
 }
Ejemplo n.º 3
0
 void Open(string file)
 {
     Page page = new Page();
     page.Changed += Change;
     Change(null);
     Open(page,file);
     tabControl.TabPages.Add(page);
     tabControl.SelectedTab = page;
 }
Ejemplo n.º 4
0
 void BtnNewClick(object sender, EventArgs e)
 {
     Page page = new Page();
     page.Changed += Change;
     Change(null);
     page.Text = "unnamed.inv";
     Text = "INVedit - unnamed.inv";
     tabControl.TabPages.Add(page);
     tabControl.SelectedTab = page;
     btnSave.Enabled = true;
     btnCloseTab.Enabled = true;
     btnReload.Enabled = false;
 }
Ejemplo n.º 5
0
 void Save(Page page, string file)
 {
     try {
         FileInfo info = new FileInfo(file);
         page.file = info.FullName;
         Tag root,tag;
         if (info.Exists) {
             root = NBT.Tag.Load(page.file);
             tag = root;
         } else {
             if (info.Extension.ToLower() == ".dat") {
                 MessageBox.Show("You can create a new Minecraft file. Select an existing one instead.",
                                 "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 return;
             } root = NBT.Tag.Create("Inventory");
             tag = root;
         } if (tag.Type==TagType.Compound && tag.Contains("Data")) { tag = tag["Data"]; }
         if (tag.Type==TagType.Compound && tag.Contains("Player")) { tag = tag["Player"]; }
         if (root.Name!="Inventory" && (tag.Type!=TagType.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;
         btnReload.Enabled = true;
     } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); }
 }
Ejemplo n.º 6
0
 void Open(string file)
 {
     Page page = new Page();
     Open(page,file);
     tabControl.TabPages.Add(page);
     tabControl.SelectedTab = page;
 }