Exemplo n.º 1
0
        public override void OnDoubleMouseClick(TreeView treeview)
        {
            IFileFormat file = OpenFile();

            if (file == null) //Format not supported so return
            {
                return;
            }

            if (Utils.HasInterface(file.GetType(), typeof(IEditor <>)))
            {
            }
            else if (file is IArchiveFile)
            {
                var FileRoot = new ArchiveRootNodeWrapper(file.FileName, (IArchiveFile)file);
                FileRoot.FillTreeNodes();

                if (file is TreeNode) //It can still be both, so add all it's nodes
                {
                    foreach (TreeNode n in ((TreeNode)file).Nodes)
                    {
                        FileRoot.Nodes.Add(n);
                    }
                }

                ReplaceNode(this.Parent, this, FileRoot);
            }
            else if (file is TreeNode)
            {
                ReplaceNode(this.Parent, this, (TreeNode)file);
            }
        }
Exemplo n.º 2
0
        public void OpenFileFormat(TreeView treeview)
        {
            IFileFormat file = ArchiveFileInfo.OpenFile();

            if (file == null) //Format not supported so return
            {
                return;
            }

            if (file.IFileInfo != null)
            {
                file.IFileInfo.ArchiveParent = ArchiveFile;
            }

            if (Utils.HasInterface(file.GetType(), typeof(IEditor <>)))
            {
                OpenControlDialog(file);
            }
            else if (Utils.HasInterface(file.GetType(), typeof(IEditorForm <>)))
            {
                OpenFormDialog(file);
            }
            else if (file is IArchiveFile)
            {
                var FileRoot = new ArchiveRootNodeWrapper(file.FileName, (IArchiveFile)file);
                FileRoot.FillTreeNodes();

                if (file is TreeNode) //It can still be both, so add all it's nodes
                {
                    foreach (TreeNode n in ((TreeNode)file).Nodes)
                    {
                        FileRoot.Nodes.Add(n);
                    }
                }

                ReplaceNode(this.Parent, treeview, this, FileRoot, RootNode);
            }
            else if (file is TreeNode)
            {
                ReplaceNode(this.Parent, treeview, this, (TreeNode)file, RootNode);
            }

            ArchiveFileInfo.FileFormat = file;
        }
Exemplo n.º 3
0
        public UserControl GetEditorControl(IFileFormat fileFormat)
        {
            Type objectType = fileFormat.GetType();

            foreach (var inter in objectType.GetInterfaces())
            {
                if (inter.IsGenericType && inter.GetGenericTypeDefinition() == typeof(IEditor <>))
                {
                    System.Reflection.MethodInfo method     = objectType.GetMethod("OpenForm");
                    System.Reflection.MethodInfo methodFill = fileFormat.GetType().GetMethod("FillEditor");

                    var control = (UserControl)method.Invoke(fileFormat, new object[0]);
                    methodFill.Invoke(fileFormat, new object[1] {
                        control
                    });
                    return(control);
                }
            }
            return(null);
        }
Exemplo n.º 4
0
        public void SetEditorForm(IFileFormat fileFormat)
        {
            if (fileFormat == null)
            {
                AddControl(new STUserControl()
                {
                    Dock = DockStyle.Fill
                });
            }

            if (fileFormat is TreeNodeFile)
            {
                var Editor       = ((TreeNodeFile)fileFormat).GetEditor();
                var ActiveEditor = GetActiveEditor(Editor.GetType());
                if (ActiveEditor == null)
                {
                    AddControl(Editor);
                }
                else
                {
                    Editor = ActiveEditor;
                }

                ((TreeNodeFile)fileFormat).FillEditor(Editor);
                return;
            }

            Type objectType = fileFormat.GetType();

            foreach (var inter in objectType.GetInterfaces())
            {
                if (inter.IsGenericType && inter.GetGenericTypeDefinition() == typeof(IEditor <>))
                {
                    System.Reflection.MethodInfo method     = objectType.GetMethod("OpenForm");
                    System.Reflection.MethodInfo methodFill = objectType.GetMethod("FillEditor");

                    var Editor       = (UserControl)method.Invoke(fileFormat, new object[0]);
                    var ActiveEditor = GetActiveEditor(Editor.GetType());
                    if (ActiveEditor == null)
                    {
                        AddControl(Editor);
                    }
                    else
                    {
                        Editor = ActiveEditor;
                    }

                    methodFill.Invoke(fileFormat, new object[1] {
                        Editor
                    });
                }
            }
        }
Exemplo n.º 5
0
            private UserControl GetEditorForm(IFileFormat fileFormat)
            {
                Type objectType = fileFormat.GetType();

                foreach (var inter in objectType.GetInterfaces())
                {
                    if (inter.IsGenericType && inter.GetGenericTypeDefinition() == typeof(IEditor <>))
                    {
                        System.Reflection.MethodInfo method = objectType.GetMethod("OpenForm");
                        return((UserControl)method.Invoke(fileFormat, new object[0]));
                    }
                }
                return(null);
            }
Exemplo n.º 6
0
        private static bool IsFileFiltered(IFileFormat fileFormat, Settings settings)
        {
            if (settings.FileFilter == null || settings.FileFilter.Length == 0)
            {
                return(false);
            }

            foreach (var type in settings.FileFilter)
            {
                if (type == fileFormat.GetType())
                {
                    return(false);
                }

                foreach (var inter in type.GetInterfaces())
                {
                    if (inter.IsGenericType && inter.GetGenericTypeDefinition() == fileFormat.GetType())
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
Exemplo n.º 7
0
 public void OpenFormDialog(IFileFormat fileFormat)
 {
     if (activeForm != null && !activeForm.IsDisposed && !activeForm.Disposing)
     {
         activeForm.Text = (((IFileFormat)fileFormat).FileName);
         System.Reflection.MethodInfo methodFill = fileFormat.GetType().GetMethod("FillEditor");
         methodFill.Invoke(fileFormat, new object[1] {
             activeForm
         });
     }
     else
     {
         activeForm             = GetEditorForm(fileFormat);
         activeForm.Text        = (((IFileFormat)fileFormat).FileName);
         activeForm.FormClosed += OnFormClosed;
         activeForm.Show();
     }
 }
Exemplo n.º 8
0
        //Todo move all of this data into one single class
        //Using ArchiveFileWrapper would be used wrong due to requring an IArchiveFile
        public override void OnDoubleMouseClick(TreeView treeview)
        {
            IFileFormat file = ArchiveFileInfo.OpenFile();

            if (file == null) //Format not supported so return
            {
                return;
            }

            ArchiveFileInfo.FileFormat = file;

            if (Utils.HasInterface(file.GetType(), typeof(IEditor <>)))
            {
                OpenFormDialog(file);
            }
            else if (file != null && file is TreeNodeFile)
            {
                ReplaceNode(this, (TreeNodeFile)file);
            }
        }
Exemplo n.º 9
0
            private void OpenFormDialog(IFileFormat fileFormat)
            {
                Type objectType = fileFormat.GetType();

                foreach (var inter in objectType.GetInterfaces())
                {
                    if (inter.IsGenericType && inter.GetGenericTypeDefinition() == typeof(IEditor <>))
                    {
                        System.Reflection.MethodInfo method = objectType.GetMethod("OpenForm");
                        var form = (STForm)method.Invoke(fileFormat, new object[0]);
                        form.Text = (((IFileFormat)fileFormat).FileName);
                        if (form.ShowDialog() == DialogResult.OK)
                        {
                            if (fileFormat.CanSave)
                            {
                                Data = fileFormat.Save();
                                UpdateHexView();
                            }
                        }
                    }
                }
            }
Exemplo n.º 10
0
            public override void OnDoubleMouseClick(TreeView treeView)
            {
                if (Data.Length <= 0)
                {
                    return;
                }

                IFileFormat file = OpenFile();

                if (file == null) //File returns null if no supported format is found
                {
                    return;
                }

                if (Utils.HasInterface(file.GetType(), typeof(IEditor <>)) && !SuppressFormDialog)
                {
                    OpenFormDialog(file);
                }
                else if (file != null)
                {
                    sarc.OpenedFiles.Add(FullPath, Data);
                    ReplaceNode(this.Parent, this, (TreeNode)file);
                }
            }
Exemplo n.º 11
0
        private static string SatisfyFileTables(IFileFormat FileFormat, string FilePath, Stream Data, uint DecompressedSize, uint CompressedSize, bool IsYaz0Compressed)
        {
            string FileLog = "";

            bool IsBotwFile = FilePath.IsSubPathOf(Runtime.BotwGamePath);
            bool IsTPHDFile = FilePath.IsSubPathOf(Runtime.TpGamePath);

            STConsole.WriteLine($"IsTPHDFile {IsTPHDFile}");

            if (Runtime.ResourceTables.BotwTable && IsBotwFile)
            {
                string newFilePath = FilePath.Replace(Runtime.BotwGamePath, string.Empty).Remove(0, 1);
                newFilePath = newFilePath.Replace(".s", ".");
                newFilePath = newFilePath.Replace( @"\", "/");

                string RealExtension = Path.GetExtension(newFilePath).Replace(".s", ".");

                string RstbPath = Path.Combine($"{Runtime.BotwGamePath}",
                    "System", "Resource", "ResourceSizeTable.product.srsizetable");

                RSTB BotwResourceTable = new RSTB();
                BotwResourceTable.LoadFile(RstbPath);

                //Create a backup first if one doesn't exist
                if (!File.Exists($"{RstbPath}.backup"))
                {
                    STConsole.WriteLine($"RSTB File found. Creating backup...");

                    BotwResourceTable.Write(new FileWriter($"{RstbPath}.backup"));
                    File.WriteAllBytes($"{RstbPath}.backup", EveryFileExplorer.YAZ0.Compress($"{RstbPath}.backup"));
                }

                //Now apply the file table then save the table
                if (BotwResourceTable.IsInTable(newFilePath))
                {
                    FileLog += $"File found in resource table! {newFilePath}";
                    STConsole.WriteLine(FileLog, 1);
                }
                else
                {
                    FileLog += $"File NOT found in resource table! {newFilePath}";
                    STConsole.WriteLine(FileLog, 0);

                }

                BotwResourceTable.SetEntry(newFilePath, Data, IsYaz0Compressed);
                BotwResourceTable.Write(new FileWriter(RstbPath));
                File.WriteAllBytes(RstbPath, EveryFileExplorer.YAZ0.Compress(RstbPath));
            }

            if (Runtime.ResourceTables.TpTable && IsTPHDFile)
            {
                string newFilePath = FilePath.Replace(Runtime.TpGamePath, string.Empty).Remove(0, 1);
                newFilePath = newFilePath.Replace(@"\", "/");

                //Read the compressed tables and set the new sizes if paths match
                TPFileSizeTable CompressedFileTbl = new TPFileSizeTable();
                CompressedFileTbl.ReadCompressedTable(new FileReader($"{Runtime.TpGamePath}/FileSizeList.txt"));
                if (CompressedFileTbl.IsInFileSizeList(newFilePath))
                {
                    STConsole.WriteLine("Found matching path in File Size List table! " + newFilePath, 1);
                    CompressedFileTbl.SetFileSizeEntry(newFilePath, CompressedSize);
                }
                else
                    STConsole.WriteLine("Failed to find path in File Size List table! " + newFilePath, 0);

                //Read decompressed file sizes
                TPFileSizeTable DecompressedFileTbl = new TPFileSizeTable();
                DecompressedFileTbl.ReadDecompressedTable(new FileReader($"{Runtime.TpGamePath}/DecompressedSizeList.txt"));

                newFilePath = $"./DVDRoot/{newFilePath}";
                newFilePath = newFilePath.Replace(".gz", string.Empty);

                //Write the decompressed file size
                if (DecompressedFileTbl.IsInDecompressedFileSizeList(newFilePath))
                {
                    STConsole.WriteLine("Found matching path in File Size List table! " + newFilePath, 1);
                    DecompressedFileTbl.SetDecompressedFileSizeEntry(newFilePath, CompressedSize, DecompressedSize);
                }
                else
                    STConsole.WriteLine("Failed to find path in File Size List table! " + newFilePath, 0);

                if (FileFormat == null)
                    return FileLog;

                //Check if archive type
                bool IsArchive = false;
                foreach (var inter in FileFormat.GetType().GetInterfaces())
                {
                    if (inter == typeof(IArchiveFile))
                        IsArchive = true;
                }

                //Write all the file sizes in the archive if it's an archive type
                //Note this seems uneeded atm
                //Todo store both compressed and decompressed sizes in archive info
                /*   if (IsArchive)
                   {
                       IArchiveFile Archive = (IArchiveFile)FileFormat;
                       foreach (var file in Archive.Files)
                       {
                           uint DecompressedArchiveFileSize = (uint)file.FileData.Length;
                           string ArchiveFilePath = $"/DVDRoot/{file.FileName}";

                           if (DecompressedFileTbl.IsInDecompressedFileSizeList(ArchiveFilePath))
                           {
                               STConsole.WriteLine("Found matching path in File Size List table! " + ArchiveFilePath, 1);
                               DecompressedFileTbl.SetDecompressedFileSizeEntry(ArchiveFilePath, DecompressedArchiveFileSize, DecompressedArchiveFileSize);
                           }
                           else
                               STConsole.WriteLine("Failed to find path in File Size List table! " + ArchiveFilePath, 0);
                       }
                   }*/

                CompressedFileTbl.WriteCompressedTable(new FileWriter($"{Runtime.TpGamePath}/FileSizeList.txt"));
                DecompressedFileTbl.WriteDecompressedTable(new FileWriter($"{Runtime.TpGamePath}/DecompressedSizeList.txt"));
            }

            return FileLog;
        }