示例#1
0
文件: KittyViewer.cs 项目: jcr6/Stach
        static public void View(string file, string showme)
        {
            if (HexViewer.IsBinary(showme))
            {
                HexViewer.View(showme, file);
                return;
            }
            if (!InitDone)
            {
                Init();
            }
            Debug.WriteLine("Setting up view");
            var KV   = new KittyViewer();
            var ext  = qstr.ExtractExt(file).ToLower();
            var odir = Core.Config[Core.Platform, "VIEWSWAP"];

            Debug.WriteLine("Linking to Kitty");
            KittyHigh.Console = (KittyOutput)KV;
            if (KittyHigh.Langs.ContainsKey(ext))
            {
                KittyHigh.Langs[ext].Show(showme, LineNumbers);
            }
            else
            {
                KittyHigh.Langs["OTHER"].Show(showme, LineNumbers);
            }
            Directory.CreateDirectory(odir);
            QuickStream.SaveString($"{odir}/ViewFile.html", KV.ToString());
        }
示例#2
0
        private void DirBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            Entry_Alias.Items.Clear();
            Entry_Ratio.Content = "N/A";
            Entry_Main.Content  = "--";
            if (DirBox.SelectedItem == null)
            {
                foreach (string EL in EntryLink.Keys)
                {
                    EntryLink[EL].Content = "--";
                }
                UpdateBlockView(false);
                return;
            }
            var item = (string)DirBox.SelectedItem;

            if (Core.IN_Resource)
            {
                var ename = $"{Core.CDirectory}/{item}";
                while (ename != "" && ename[0] == '/')
                {
                    ename = ename.Substring(1);
                }
                if (qstr.Suffixed(ename, "/"))
                {
                    foreach (string EL in EntryLink.Keys)
                    {
                        EntryLink[EL].Content = "N/A";
                    }
                    Entry_Entry.Content = ename;
                    Entry_Type.Content  = "Directory";
                    UpdateBlockView(false);
                }
                else
                {
                    var E = Core.JCR.Entries[ename.ToUpper()];
                    UpdateBlockView(E.Block != 0);
                    foreach (TJCREntry ECHK in Core.JCR.Entries.Values)
                    {
                        if (ECHK != E && ECHK.MainFile == E.MainFile && ECHK.Offset == E.Offset && ECHK.Block == E.Block)
                        {
                            Entry_Alias.Items.Add(ECHK.Entry);
                        }
                    }
                    foreach (string k in E.databool.Keys)
                    {
                        if (EntryLink.ContainsKey(k))
                        {
                            if (E.databool[k])
                            {
                                EntryLink[k].Content = "Yes";
                            }
                            else
                            {
                                EntryLink[k].Content = "No";
                            }
                        }
                    }
                    foreach (string k in E.dataint.Keys)
                    {
                        if (EntryLink.ContainsKey(k))
                        {
                            EntryLink[k].Content = $"{E.dataint[k]}";
                        }
                    }
                    foreach (string k in E.datastring.Keys)
                    {
                        if (EntryLink.ContainsKey(k))
                        {
                            EntryLink[k].Content = $"{E.datastring[k]}";
                        }
                    }
                    Entry_Main.Content  = E.MainFile;
                    Entry_Ratio.Content = E.Ratio;
                    if (E.Block != 0)
                    {
                        Entry_Ratio.Content  = "Unavailable (block)";
                        Entry_Offset.Content = "Unavailable (block)";
                        var B = Core.JCR.Blocks[$"{E.Block}:{E.MainFile}"];
                        Entry_Entry_Block.Content = E.Entry;
                        Entry_Block.Content       = $"{E.Block}";
                        Block_Entries.Items.Clear();
                        foreach (var BE in Core.JCR.Entries.Values)
                        {
                            if (BE.Block == E.Block)
                            {
                                Block_Entries.Items.Add(BE.Entry);
                            }
                        }
                        Block_EntryOffset.Content = $"{E.Offset}";
                        Block_Offset.Content      = $"{B.Offset}";
                        Block_Size.Content        = $"{B.Size}";
                        Block_CSize.Content       = $"{B.CompressedSize}";
                        Block_Ratio.Content       = $"{B.Ratio}%";
                    }
                    if (Core.Config[Core.Platform, "ViewSwap"] == "")
                    {
                        Viewer.Navigate($"file://{Core.MyExeDir}/NoViewSwap.html");
                    }
                    else
                    {
                        switch (qstr.ExtractExt(E.Entry).ToLower())
                        {
                        case "jpg":
                        case "jpeg":
                        case "gif":
                        case "bmp":
                        case "png":
                            ImgViewer.ViewImg(Core.JCR.JCR_B(E.Entry), $"{E.MainFile}/{E.Entry}");
                            Viewer.Refresh();
                            break;

                        default:
                            KittyViewer.View($"{E.MainFile}/{E.Entry}", Core.JCR.LoadString(E.Entry));
                            break;
                        }
                        Viewer.Navigate($"file://{Core.Config[Core.Platform, "VIEWSWAP"]}/ViewFile.html");
                    }
                }
            }
            else
            {
                var ename = $"{Core.CDirectory}/{item}";
                if (!qstr.Suffixed(ename, "/"))
                {
                    if (Core.Config[Core.Platform, "ViewSwap"] == "")
                    {
                        Viewer.Navigate($"file://{Core.MyExeDir}/NoViewSwap.html");
                    }
                    else if (JCR6.Recognize(ename).ToUpper() != "NONE")
                    {
                        var odir = Core.Config[Core.Platform, "VIEWSWAP"];
                        var KV   = new KittyViewer();
                        KV.ForegroundColor = ConsoleColor.Yellow;
                        KV.WriteLine("JCR6 resource");
                        KV.ForegroundColor = ConsoleColor.White;
                        KV.WriteLine($"File {qstr.StripDir(ename)} has been recognized as: {JCR6.Recognize(ename)}");
                        KV.WriteLine($"JCR6 understands this format, so why don't you open it to see its contents?");
                        Directory.CreateDirectory(odir);
                        QuickStream.SaveString($"{odir}/ViewJCRFile.html", KV.ToString());
                        Viewer.Navigate($"{odir}/ViewJCRFile.html");
                    }
                    else
                    {
                        switch (qstr.ExtractExt(ename).ToLower())
                        {
                        case "jpg":
                        case "jpeg":
                        case "gif":
                        case "bmp":
                        case "png":
                            ImgViewer.ViewImg(QuickStream.GetFile(ename), ename);
                            break;

                        default:
                            KittyViewer.View($"{ename}", QuickStream.LoadString(ename));
                            break;
                        }
                        Viewer.Navigate($"file://{Core.Config[Core.Platform, "VIEWSWAP"]}/ViewFile.html");
                    }
                }
            }
        }