示例#1
0
        private void Listbox_Favs_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (Listbox_Favs.SelectedItem == null)
            {
                return;
            }
            var rf = (string)Listbox_Favs.SelectedItem;
            var rc = JCR6.Recognize(rf);

            Debug.WriteLine($"Analysing {rf} => {rc}");
            if (rc == "NONE")
            {
                Confirm.Annoy($"{rf} was not recognized");
                return;
            }
            Core.IN_Resource = true;
            Core.Resource    = rf;
            Core.CDirectory  = "";
            //Core.Config.ListAddNew(Platform, "Used", rf);
            //RenewUsed();
            UpdateDirBox();
            ResTableSTG.Content = Core.JCR.FATstorage;
            ResType.Content     = rc;
            return;
        }
示例#2
0
        private void DirBox_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            if (DirBox.SelectedItem == null)
            {
                return;
            }
            var item = (string)DirBox.SelectedItem;

            //var d = item.Content.ToString();
            Debug.WriteLine($"Double-clicked {item}");
            if (!qstr.Suffixed(item, "/"))
            {
                if (Core.IN_Resource)
                {
                    return;
                }
                var rf = $"{Core.CDirectory}/{item}";
                var rc = JCR6.Recognize(rf);
                Debug.WriteLine($"Analysing {rf} => {rc}");
                if (rc == "NONE")
                {
                    return;
                }
                Core.IN_Resource = true;
                Core.Resource    = rf;
                Core.CDirectory  = "";
                Core.Config.ListAddNew(Platform, "Used", rf);
                RenewUsed();
                UpdateDirBox();
                ResTableSTG.Content = Core.JCR.FATstorage;
                ResType.Content     = rc;
                return;
            }
            if (Core.IN_Resource)
            {
                if (item == "../")
                {
                    if (Core.CDirectory == "")
                    {
                        Directory.SetCurrentDirectory(qstr.ExtractDir(Core.Resource));
                        Core.IN_Resource = false;
                        Core.CDirectory  = Directory.GetCurrentDirectory().Replace('\\', '/');
                        UpdateDirBox();
                        return;
                    }
                    Core.CDirectory = qstr.ExtractDir(Core.CDirectory);
                    UpdateDirBox();
                    return;
                }
                else
                {
                    if (Core.CDirectory == "")
                    {
                        Core.CDirectory = item.Substring(0, item.Length - 1);
                    }
                    else
                    {
                        Core.CDirectory += $"/{item.Substring(0, item.Length - 1)}";
                    }
                    UpdateDirBox();
                    return;
                }
            }
            else
            {
                Directory.SetCurrentDirectory(item);
                Core.CDirectory = Directory.GetCurrentDirectory().Replace('\\', '/');
                UpdateDirBox();
            }
        }
示例#3
0
        public override void Run(FlagParse fp)
        {
            var ShowXStuff = fp.GetBool("x");
            var ShowAlias  = fp.GetBool("a");
            var ShowAllDat = fp.GetBool("xd");

            if (fp.Args.Length == 1)
            {
                QCol.Green("Verboses the files in a JCR resource:\n\n");
                QCol.Yellow("-x              "); QCol.Cyan("Show notes and author (if available)\n");
                QCol.Yellow("-a              "); QCol.Cyan("List out all aliases");
                QCol.Yellow("-xd             "); QCol.Cyan("Show all entry variable settings");
                return;
            }
            if (fp.Args.Length > 2)
            {
                QCol.QuickError("Only ONE file please!");
                return;
            }
            var jcr = JCR6.Dir(fp.Args[1]);

            if (jcr == null)
            {
                QCol.QuickError(JCR6.JERROR); return;
            }
            { // Resources
                var ResCount = new TMap <string, int>();
                var CmpCount = new TMap <string, int>();
                foreach (TJCREntry ent in jcr.Entries.Values)
                {
                    ResCount[ent.MainFile]++;
                    CmpCount[ent.Storage]++;
                }
                XPrint(15, ConsoleColor.White, "Type");
                XPrint(9, ConsoleColor.White, "Entries", Just.Right);
                XPrint(10, ConsoleColor.White, " Resource:"); Console.WriteLine();
                XPrint(15, ConsoleColor.White, "====");
                XPrint(9, ConsoleColor.White, " =======", Just.Right);
                XPrint(10, ConsoleColor.White, " ========="); Console.WriteLine();
                foreach (string k in ResCount.Keys)
                {
                    var rec = JCR6.Recognize(k);
                    if (rec != "NONE")
                    {
                        XPrint(15, ConsoleColor.Blue, JCR6.FileDrivers[rec].name);
                        XPrint(9, ConsoleColor.Cyan, ResCount[k]);
                        Console.ForegroundColor = ConsoleColor.White;
                        Console.WriteLine($" {k}");
                    }
                }
                Console.WriteLine();
                XPrint(20, ConsoleColor.White, "Storage Method");
                XPrint(10, ConsoleColor.White, "Used", Just.Right); Console.WriteLine();
                XPrint(20, ConsoleColor.White, "==============");
                XPrint(10, ConsoleColor.White, "====", Just.Right); Console.WriteLine();
                foreach (string k in CmpCount.Keys)
                {
                    XPrint(20, ConsoleColor.Blue, k);
                    XPrint(10, ConsoleColor.Cyan, CmpCount[k], Just.Right);
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.WriteLine();
                }
            }
            Console.WriteLine();
            // Comments
            foreach (string name in jcr.Comments.Keys)
            {
                QCol.White($"{name}\n");
                for (int i = 0; i < name.Length; i++)
                {
                    QCol.White("=");
                }
                QCol.Yellow($"\n{jcr.Comments[name]}\n\n");
            }
            // Blocks (if any)
            //if (jcr.Blocks.Count>0) {
            bool bfirst = true;

            foreach (var B in jcr.Blocks.Values)
            {
                if (bfirst)
                {
                    bfirst = false;
                    Console.WriteLine();
                    XPrint(5, ConsoleColor.White, "Block", Just.Right); WhiteSpace(2);
                    XPrint(10, ConsoleColor.White, "Compressed", Just.Right); WhiteSpace(2);
                    XPrint(10, ConsoleColor.White, "Size", Just.Right); WhiteSpace(2);
                    XPrint(5, ConsoleColor.White, "Ratio", Just.Right); WhiteSpace(2);
                    XPrint(7, ConsoleColor.White, "Storage"); Console.WriteLine();
                    XPrint(5, ConsoleColor.White, "=====", Just.Right); WhiteSpace(2);
                    XPrint(10, ConsoleColor.White, "==========", Just.Right); WhiteSpace(2);
                    XPrint(10, ConsoleColor.White, "====", Just.Right); WhiteSpace(2);
                    XPrint(5, ConsoleColor.White, "=====", Just.Right); WhiteSpace(2);
                    XPrint(7, ConsoleColor.White, "======="); Console.WriteLine();
                }
                XPrint(5, ConsoleColor.Blue, B.ID); WhiteSpace(2);
                XPrint(10, ConsoleColor.Green, B.CompressedSize); WhiteSpace(2);
                XPrint(10, ConsoleColor.Red, B.Size); WhiteSpace(2);
                XPrint(5, ConsoleColor.Magenta, $"{B.Ratio}%", Just.Right); WhiteSpace(2);
                XPrint(7, ConsoleColor.Yellow, B.Storage); Console.WriteLine();
            }
            //foreach (var BK in jcr.Blocks.Keys) Console.WriteLine(BK);

            //}
            // Entries
            Console.WriteLine();
            XPrint(15, ConsoleColor.White, "Kind"); WhiteSpace(2);
            XPrint(10, ConsoleColor.White, "Compressed", Just.Right); WhiteSpace(2);
            XPrint(10, ConsoleColor.White, "Size", Just.Right); WhiteSpace(2);
            XPrint(5, ConsoleColor.White, "Ratio", Just.Right); WhiteSpace(2);
            XPrint(7, ConsoleColor.White, "Storage"); WhiteSpace(2);
            Console.WriteLine("Entry");
            XPrint(15, ConsoleColor.White, "===="); WhiteSpace(2);
            XPrint(10, ConsoleColor.White, "==========", Just.Right); WhiteSpace(2);
            XPrint(10, ConsoleColor.White, "====", Just.Right); WhiteSpace(2);
            XPrint(5, ConsoleColor.White, "=====", Just.Right); WhiteSpace(2);
            XPrint(7, ConsoleColor.White, "======="); WhiteSpace(2);
            Console.WriteLine("=====");
            foreach (TJCREntry ent in jcr.Entries.Values)
            {
                Console.BackgroundColor = ConsoleColor.Black;
                if (ent.MainFile != fp.Args                    [1].Replace("\\", "/"))
                {
                    Console.BackgroundColor = ConsoleColor.DarkBlue;
                }
                XPrint(15, ConsoleColor.Blue, FTypes[qstr.ExtractExt(ent.Entry).ToLower()]); WhiteSpace(2);
                if (ent.Block == 0)
                {
                    XPrint(10, ConsoleColor.Green, ent.CompressedSize);
                }
                else
                {
                    XPrint(10, ConsoleColor.DarkGreen, $"Block: {ent.Block}");
                }
                WhiteSpace(2);
                XPrint(10, ConsoleColor.Red, ent.Size); WhiteSpace(2);
                if (ent.Block == 0)
                {
                    XPrint(5, ConsoleColor.Magenta, ent.Ratio, Just.Right);
                }
                else
                {
                    XPrint(5, ConsoleColor.Magenta, "");
                } WhiteSpace(2);
                XPrint(7, ConsoleColor.Yellow, ent.Storage); WhiteSpace(2);
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine(ent.Entry);
                if (ShowXStuff)
                {
                    if (ent.Author != "")
                    {
                        QCol.Doing("\tAuthor", ent.Author);
                    }
                    if (ent.Notes != "")
                    {
                        QCol.Green($"{ent.Notes}\n");
                    }
                }
                if (ShowAlias)
                {
                    foreach (string AlFile in jcr.Aliases(ent))
                    {
                        QCol.Doing("\tAlias", AlFile);
                    }
                }
                if (ShowAllDat)
                {
                    foreach (string k in ent.databool.Keys)
                    {
                        QCol.Magenta("\tbool   "); QCol.Yellow(k); QCol.White(" = "); if (ent.databool[k])
                        {
                            QCol.Green("True\n");
                        }
                        else
                        {
                            QCol.Red("False\n");
                        }
                    }
                    foreach (string k in ent.datastring.Keys)
                    {
                        QCol.Magenta("\tstring "); QCol.Yellow(k); QCol.White(" = "); QCol.Green($"\"{ent.datastring[k]}\"\n");
                    }
                    foreach (string k in ent.dataint.Keys)
                    {
                        QCol.Magenta("\tint    "); QCol.Yellow(k); QCol.White(" = "); QCol.Cyan($"{ent.dataint[k]}\n");
                    }
                }
            }
        }
示例#4
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");
                    }
                }
            }
        }
示例#5
0
文件: F_Add.cs 项目: jcr6/NJCR
        public void Go()
        {
            // Create or update?
            TJCRCreate jout;
            var        temp = $"{qstr.ExtractDir(jcrfile)}/{qstr.md5($"{jcrfile}.{DateTime.Now.ToString()}")}.$jcr";
            TJCRDIR    jtmp = null;

            if (updating)
            {
                jout = new TJCRCreate(temp, filetablecompression, sig);
            }
            else
            {
                jout = new TJCRCreate(jcrfile, filetablecompression, sig);
            }
            if (jout == null || jout.mystream == null)
            {
                QCol.QuickError($"Error creating JCR file >> {JCR6.JERROR}");
                return;
            }


            // Add Comments
            foreach (string n in Comments.Keys)
            {
                QCol.Doing("Comment", n);
                jout.AddComment(n, Comments[n]);
            }

            // Add Dependencies
            foreach (var d in Imports)
            {
                QCol.Doing("Import", d);
                jout.Import(d);
            }
            foreach (var d in Requires)
            {
                QCol.Doing("Require", d);
                jout.Require(d);
            }



            // Add files
            foreach (Fil2Add aFile in Jiffy)
            {
                try {
                    if (nomerge || JCR6.Recognize(aFile.source) == "NONE")
                    {
                        QCol.Doing("Adding", aFile.source, "\r");
                        jout.AddFile(aFile.source, aFile.target, aFile.storage, aFile.author, aFile.notes);
                        //Console.WriteLine("\nBefore AfterAdd\n");
#if DEBUG
                        QCol.Doing("TARGET:", $"{aFile.target}=>{aFile.TARGET}");
#endif
                        var E = jout.Entries[aFile.TARGET];
                        AfterAdd(E, aFile);
                        //Console.WriteLine("\nAfter AfterAdd\n");
                    }
                    else
                    {
                        QCol.Doing("Merging", aFile.source);
                        var merge = JCR6.Dir(aFile.source);
                        foreach (TJCREntry ent in merge.Entries.Values)
                        {
                            QCol.Doing("Adding", "", "");
                            QCol.Magenta($"{aFile.source}/");
                            QCol.Cyan($"{ent.Entry}\r");
                            var tar = $"{aFile.target}/{ent.Entry}";
                            if (puremerge)
                            {
                                jout.JCRCopy(merge, ent.Entry, tar);
                            }
                            else
                            {
                                var buf = merge.JCR_B(ent.Entry);
                                jout.AddBytes(buf, tar, aFile.storage, ent.Author, ent.Notes);
                            }
                            //var E = jout.Entries[tar.ToUpper()];
                            var E = jout.LastAddedEntry;
                            AfterAdd(E, aFile);
                        }
                    }
                } catch (Exception crap) {
                    QCol.Red("     Failed:\n");
                    if (JCR6.JERROR != "")
                    {
                        QCol.QuickError($"JCR6: {JCR6.JERROR}");
                    }
                    QCol.QuickError($".NET: {crap.Message}");
#if DEBUG
                    QCol.Magenta($"{crap.StackTrace}\n\n");
#endif
                }
            }

            // Process aliases
            //foreach(string ori in AliasList.Keys) {
            foreach (SAlias SAL in AliasList)
            {
                QCol.Yellow("Alias: ");
                QCol.Red(SAL.ori);
                QCol.White(" => ");
                QCol.Green(SAL.tar);
                jout.Alias(SAL.ori, SAL.tar);
                QCol.White("\n");
            }

            // Reorganize Files
            if (updating)
            {
                try {
                    QCol.Doing("Reorganizing", "Data");
                    jtmp = JCR6.Dir(jcrfile);
                    if (jtmp == null)
                    {
                        throw new Exception($"JCR failed to analyse the old archive: {JCR6.JERROR}");
                    }
                    var indicator = 0;
                    foreach (TJCREntry entry in jtmp.Entries.Values)
                    {
                        indicator++;
                        if (indicator % 5 == 0)
                        {
                            QCol.Blue("\r                \r.\b");
                        }
                        else
                        {
                            QCol.Blue(".\b");
                        }
                        if (!jout.Entries.ContainsKey(entry.Entry.ToUpper()))
                        {
                            QCol.Green("O");
                            jout.JCRCopy(jtmp, entry.Entry);
                        }
                        else
                        {
                            QCol.Red("X");
                        }
                    }
                    Console.WriteLine();
                } catch (Exception well) {
                    QCol.QuickError(well.Message);
                }
            }

            // Add dependency requests
            // TODO: Dependency requests

            // Closure and overwrite old JCR file if applicable.
            QCol.Doing("Finalizing", jcrfile);
            jout.Close();
            if (updating)
            {
                try {
                    File.Delete(jcrfile);
                    File.Move(temp, jcrfile);
                } catch (Exception E) {
                    QCol.QuickError(E.Message);
                }
            }
        }