예제 #1
0
        void modelPanel1_DragDrop(object sender, DragEventArgs e)
        {
            if (e.Effect == DragDropEffects.Copy)
            {
                string newpath = ((string[])e.Data.GetData(DataFormats.FileDrop))[0];
                this.BeginInvoke(new Action(() => {
                    using (ResourceNode newroot = NodeFactory.FromFile(null, newpath)) {
                        if (newroot is ARCNode)
                        {
                            string basePath = _path;
                            if (Path.HasExtension(basePath))
                            {
                                basePath = basePath.Substring(0, basePath.LastIndexOf('.'));
                            }
                            FileInfo pac = new FileInfo(basePath + ".pac");
                            FileInfo pcs = new FileInfo(basePath + ".pcs");

                            bool cont = true;
                            if (pac.Exists || pcs.Exists)
                            {
                                cont = (DialogResult.OK == MessageBox.Show(
                                            "Replace " + pac.Name + "/" + pcs.Name + "?",
                                            "Overwrite?",
                                            MessageBoxButtons.OKCancel));
                            }
                            if (!cont)
                            {
                                return;
                            }

                            if (_root != null)
                            {
                                _root.Dispose();
                                _root = null;
                            }
                            pac.Directory.Create();
                            (newroot as ARCNode).ExportPAC(pac.FullName);
                            (newroot as ARCNode).ExportPCS(pcs.FullName);

                            if (ParentForm is CostumeManager)
                            {
                                (ParentForm as CostumeManager).updateCostumeSelectionPane();
                            }

                            LoadFile(_path);
                        }
                        else
                        {
                            MessageBox.Show("Invalid format: root node is not an ARC archive.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                }));
            }
        }
예제 #2
0
        public void Close()
        {
            if (_rootNode != null)
            {
                _rootNode.Dispose();
                _rootNode = null;
            }
            _rootPath = null;

            grid.SelectedObject = null;
            app.TargetSource    = null;
            app.Enabled         = grid.Enabled = false;
            lblFilename.Text    = "";
            songNameBar.Index   = -1;
        }
예제 #3
0
        private bool CloseExternal()
        {
            if (_externalAnimationsNode != null)
            {
                if (_externalAnimationsNode.IsDirty)
                {
                    DialogResult res = MessageBox.Show(this, "You have made changes to an external file. Would you like to save those changes?", "Closing external file.", MessageBoxButtons.YesNoCancel);
                    if (((res == DialogResult.Yes) && (!SaveExternal(false))) || (res == DialogResult.Cancel))
                    {
                        return(false);
                    }
                }

                ModelPanel.RemoveReference(_externalAnimationsNode);
                leftPanel._closing = true;
                leftPanel.listAnims.Items.Clear();
                leftPanel._closing = false;
                _externalAnimationsNode.Dispose();
                _externalAnimationsNode = null;

                if (SelectedBone != null)
                {
                    SelectedBone._boneColor = SelectedBone._nodeColor = Color.Transparent;
                }

                leftPanel.UpdateAnimations(TargetAnimType);
                SetAnimation(TargetAnimType, null);
                GetFiles(AnimType.None);
                UpdatePropDisplay();
                UpdateModel();
            }
            return(true);
        }
예제 #4
0
        private bool LoadExternal()
        {
            int count;

            dlgOpen.Filter = "All Files (*.*)|*.*";
            if (dlgOpen.ShowDialog() == DialogResult.OK)
            {
                ResourceNode node = null;
                listAnims.BeginUpdate();
                try
                {
                    if ((node = NodeFactory.FromFile(null, dlgOpen.FileName)) != null)
                    {
                        if (!CloseExternal())
                        {
                            return(false);
                        }

                        count = listAnims.Items.Count;
                        LoadAnims(node);

                        if (count == listAnims.Items.Count)
                        {
                            MessageBox.Show(this, "No animations could be found in external file, closing.", "Error");
                        }
                        else
                        {
                            _externalNode   = node;
                            node            = null;
                            txtExtPath.Text = Path.GetFileName(dlgOpen.FileName);

                            if (ReferenceLoaded != null)
                            {
                                ReferenceLoaded(_externalNode);
                            }

                            return(true);
                        }
                    }
                    else
                    {
                        MessageBox.Show(this, "Unable to recognize input file.");
                    }
                }
                catch (Exception x) { MessageBox.Show(this, x.ToString()); }
                finally
                {
                    if (node != null)
                    {
                        node.Dispose();
                    }
                    listAnims.EndUpdate();
                }
            }
            return(false);
        }
예제 #5
0
        private void ImportFile(string file, TreeNode t)
        {
            ResourceNode node = null;

            if (t == null)
            {
                Program.Open(file);
            }
            else
            {
                ResourceNode dest = ((BaseWrapper)t).ResourceNode;
                try
                {
                    if ((node = NodeFactory.FromFile(null, file)) != null)
                    {
                        bool ok = false;
                        if (ModifierKeys == Keys.Shift || dest.Parent == null)
                        {
                            ok = TryAddChild(node, dest);
                        }
                        else
                        {
                            ok = TryDrop(node, dest);
                        }
                        if (!ok)
                        {
                            node.Dispose();
                            node = null;
                        }
                        else
                        {
                            BaseWrapper b = FindResource(node);
                            if (b != null)
                            {
                                b.EnsureVisible();
                                SelectedNode = b;
                            }
                        }
                    }
                    else if (dest is TEX0Node || dest is REFTEntryNode || dest is TPLTextureNode)
                    {
                        dest.Replace(file);
                    }
                }
                catch { }
            }

            _timer.Enabled = false;
            _dragNode      = null;
        }
예제 #6
0
        private bool LoadExternal()
        {
            dlgOpen.Filter = "All Compatible Files (*.pac, *.pcs, *.brres, *.chr0, *.srt0, *.pat0, *.vis0, *.shp0, *.scn0, *.clr0, *.mrg)|*.pac;*.pcs;*.brres;*.chr0;*.srt0;*.pat0;*.vis0;*.shp0;*.scn0;*.clr0;*.mrg";
            if (dlgOpen.ShowDialog() == DialogResult.OK)
            {
                ResourceNode node = null;
                leftPanel.listAnims.BeginUpdate();
                try
                {
                    if ((node = NodeFactory.FromFile(null, dlgOpen.FileName)) != null)
                    {
                        if (!CloseExternal())
                        {
                            return(false);
                        }

                        if (!leftPanel.LoadAnims(node, TargetAnimType))
                        {
                            MessageBox.Show(this, "No animations could be found in external file.", "Error");
                        }
                        else
                        {
                            _externalAnimationsNode = node;
                            node = null;
                            //txtExtPath.Text = Path.GetFileName(dlgOpen.FileName);

                            ModelPanel.AddReference(_externalAnimationsNode);

                            return(true);
                        }
                    }
                    else
                    {
                        MessageBox.Show(this, "Unable to recognize input file.");
                    }
                }
                catch (Exception x) { MessageBox.Show(this, x.ToString()); }
                finally
                {
                    if (node != null)
                    {
                        node.Dispose();
                    }
                    leftPanel.listAnims.EndUpdate();
                }
            }
            return(false);
        }
        public static void RemoveFile(ResourceNode r)
        {
            if (r == null)
            {
                return;
            }

            string path = r._origPath.Substring(Program.RootPath.Length).Replace('\\', '/');

            if (_openedFilePaths.Contains(path))
            {
                _openedFiles.Remove(r);
                _openedFilePaths.Remove(path);
                r.Dispose();

                RunTime.Log("Closed " + path);
            }
        }
예제 #8
0
        public static void Copy(string kirbypath, string hatpath)
        {
            ResourceNode kirby   = NodeFactory.FromFile(null, kirbypath);
            string       temphat = Path.GetTempFileName();

            File.Copy(hatpath, temphat, true);
            ResourceNode hat = NodeFactory.FromFile(null, temphat);

            TEX0Node skin = (TEX0Node)kirby.FindChildByType("PlyKirby5KSkin", true, ResourceType.TEX0);

            if (skin == null)
            {
                MessageBox.Show(null, "Could not find the texture PlyKirby5KSkin in " + kirbypath, "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            string temptex = Path.GetTempFileName();

            skin.Export(temptex);

            TEX0Node hatskin = (TEX0Node)hat.FindChildByType("WpnKirbyKirbyMewtwoCap", true, ResourceType.TEX0);

            if (hatskin == null)
            {
                MessageBox.Show(null, "Could not find the texture WpnKirbyKirbyMewtwoCap in " + hatpath, "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            hatskin.Replace(temptex);
            hat.Merge();
            hat.Export(hatpath);

            hat.Dispose();
            kirby.Dispose();

            File.Delete(temphat);
            File.Delete(temptex);

            MessageBox.Show(Path.GetFileName(hatpath) + " has been updated.");
        }
예제 #9
0
        public static bool Close(bool force)
        {
            //Have to close external files before the root file
            while (ModelEditControl.Instances.Count > 0)
            {
                var control = ModelEditControl.Instances[0];
                if (control.ParentForm != null)
                {
                    control.ParentForm.Close();
                    if (!control.IsDisposed)
                    {
                        return(false);
                    }
                }
                else if (!control.Close())
                {
                    return(false);
                }
            }

            if (_rootNode != null)
            {
                if (_rootNode.IsDirty && !force)
                {
                    DialogResult res = MessageBox.Show("Save changes?", "Closing", MessageBoxButtons.YesNoCancel);
                    if ((res == DialogResult.Yes && !Save()) || res == DialogResult.Cancel)
                    {
                        return(false);
                    }
                }

                _rootNode.Dispose();
                _rootNode = null;

                MainForm.Instance.Reset();
            }

            _rootPath = null;
            MainForm.Instance.UpdateName();
            return(true);
        }
예제 #10
0
        public static bool Close(bool force)
        {
            if (_rootNode != null)
            {
                if ((_rootNode.IsDirty) && (!force))
                {
                    DialogResult res = MessageBox.Show("Save changes?", "Closing", MessageBoxButtons.YesNoCancel);
                    if (((res == DialogResult.Yes) && (!Save())) || (res == DialogResult.Cancel))
                    {
                        return(false);
                    }
                }

                _rootNode.Dispose();
                _rootNode = null;

                MainForm.Instance.Reset();
            }
            _rootPath = null;
            return(true);
        }
예제 #11
0
        private bool CloseExternal()
        {
            if (_externalNode != null)
            {
                if (_externalNode.IsDirty)
                {
                    DialogResult res = MessageBox.Show(this, "You have made changes to an external file. Would you like to save those changes?", "Closing external file.", MessageBoxButtons.YesNoCancel);
                    if (((res == DialogResult.Yes) && (!SaveExternal())) || (res == DialogResult.Cancel))
                    {
                        return(false);
                    }
                }
                if (ReferenceClosed != null)
                {
                    ReferenceClosed(_externalNode);
                }

                _externalNode.Dispose();
                _externalNode   = null;
                txtExtPath.Text = "";
                UpdateReferences();
            }
            return(true);
        }
예제 #12
0
        private bool CloseFile(int i, bool user)
        {
            if (OpenedFiles == null || i < 0 || i >= OpenedFiles.Count)
            {
                return(true);
            }

            ResourceNode r = OpenedFiles[i];

            if (r == null)
            {
                return(true);
            }

            bool shouldClose = _mainWindow.ShouldCloseFile(r);

            if (r.IsDirty && shouldClose)
            {
                string s = user
                    ? "Save changes?"
                    : "You have made changes to the file \"" + r._origPath +
                           "\". Would you like to save those changes?";

                DialogResult res = MessageBox.Show(this, s, "Closing external file.", MessageBoxButtons.YesNoCancel);

                if (res == DialogResult.Cancel)
                {
                    return(false);
                }

                if (res == DialogResult.Yes && !SaveExternal(r, false))
                {
                    DialogResult res2 = MessageBox.Show(this,
                                                        "Unable to save this file. Close it anyway?",
                                                        "Closing external file.",
                                                        MessageBoxButtons.YesNo);

                    if (res2 == DialogResult.No)
                    {
                        return(false);
                    }
                }
            }

            _mainWindow.Updating = true;
            for (int m = 0; m < _mainWindow.ModelPanel._renderList.Count; m++)
            {
                ResourceNode o = _mainWindow.ModelPanel._renderList[m] as ResourceNode;
                if (o != null && o.RootNode == r)
                {
                    _mainWindow.ModelPanel.RemoveTarget(o as IRenderedObject, false);
                    m--;
                }
            }

            _mainWindow.ModelPanel.RemoveReference(r, false);
            _mainWindow.UnloadAnimations(r);
            _mainWindow.Updating = false;

            if (shouldClose)
            {
                r.Dispose();
            }

            OpenedFiles.RemoveAt(i);

            return(true);
        }
예제 #13
0
        public void UpdateDirectory()
        {
            Console.WriteLine(System.Environment.CurrentDirectory);
            if (sc_selmap != null)
            {
                sc_selmap.Dispose();
            }
            if (common5 != null)
            {
                common5.Dispose();
            }
            _openFilePath       = null;
            fileSizeBar.Maximum = 1214283;
            if (File.Exists("../../menu2/sc_selmap.pac"))
            {
                common5       = null;
                sc_selmap     = TempFiles.MakeTempNode("../../menu2/sc_selmap.pac");
                _openFilePath = "../../menu2/sc_selmap.pac";
            }
            else if (File.Exists("../../menu2/sc_selmap_en.pac"))
            {
                common5       = null;
                sc_selmap     = TempFiles.MakeTempNode("../../menu2/sc_selmap_en.pac");
                _openFilePath = "../../menu2/sc_selmap_en.pac";
            }
            else if (File.Exists("../../system/common5.pac"))
            {
                common5       = TempFiles.MakeTempNode("../../system/common5.pac");
                sc_selmap     = common5.FindChild("sc_selmap_en", false);
                _openFilePath = "../../system/common5.pac";
            }
            else if (File.Exists("../../system/common5_en.pac"))
            {
                common5       = TempFiles.MakeTempNode("../../system/common5_en.pac");
                sc_selmap     = common5.FindChild("sc_selmap_en", false);
                _openFilePath = "../../system/common5_en.pac";
            }
            else
            {
                common5     = null;
                sc_selmap   = null;
                label1.Text = "Could not load sc_selmap(_en) or common5(_en).";
            }
            if (_openFilePath != null)
            {
                updateFileSize();
                TEX0Node tex0 = sc_selmap.FindChild("MiscData[80]/Textures(NW4R)/MenSelmapFrontBg", false) as TEX0Node;
                if (tex0 != null)
                {
                    scribble = tex0.GetImage(0);
                }
                FindMuMenumain();
            }
            else
            {
                fileSizeBar.Value  = 0;
                fileSizeLabel.Text = "";
            }

            // Find and load GCT, if it exists
            AutoSSS = null;
            DirectoryInfo directory = new DirectoryInfo(Environment.CurrentDirectory);

            while (directory != null)
            {
                Console.WriteLine(directory);
                if (File.Exists(directory.FullName + "/data/gecko/codes/RSBE01.gct"))
                {
                    AutoSSS = new CustomSSSCodeset(File.ReadAllBytes(directory.FullName + "/data/gecko/codes/RSBE01.gct"));
                    break;
                }
                else if (File.Exists(directory.FullName + "/codes/RSBE01.gct"))
                {
                    AutoSSS = new CustomSSSCodeset(File.ReadAllBytes(directory.FullName + "/codes/RSBE01.gct"));
                    break;
                }
                directory = directory.Parent;
            }
        }