Esempio n. 1
0
        public override void Run(FlagParse fp)
        {
            if (fp.Args.Length < 2)
            {
                QCol.Green("This feature allows you to show the content of a certain file.\n");
                QCol.Green("In order to do this, some additional configuration will be needed, as well as knowledge of the file system you are using.\n");
                QCol.Green("Don't worry about having to set up this file, manually. You will be prompted whenever NJCR requires more information.\n");
                QCol.Green($"The configuration can lateron be edited with your favority text editor (as long as it supports Unix LF line ends), as it will be saved as {ShowConfig}");
                return;
            }
            QCol.Doing("Reading JCR", fp.Args[1].Replace("\\", "/"));
            var jcr = JCR6.Dir(fp.Args[1]);

            if (jcr == null)
            {
                QCol.QuickError(JCR6.JERROR); return;
            }
            if (!File.Exists(ShowConfig))
            {
                QuickStream.SaveString(ShowConfig, "[rem]\nNothint to see here yet\n");
            }
            Config = GINI.ReadFromFile(ShowConfig);
            Ask("Temp.Dir", "I am in need of a temp-directory.\nYou can pick any directory you want for this, and the system will try to create the desired directory if it doesn't yet exist.\nThe files to show will be temporarily stored here, and IT'S VERY IMPORTANT THAT THIS DIRECTORY IS ONLY USED FOR THIS PURPOSE!!!", "Temp Folder");
            QCol.Doing("Temp dir", TempFolder);
            Directory.CreateDirectory(TempFolder);
            for (int i = 2; i < fp.Args.Length; i++)
            {
                Show(jcr, fp.Args[i]);
            }
        }
Esempio n. 2
0
File: F_HEX.cs Progetto: jcr6/NJCR
        public override void Run(FlagParse fp)
        {
            if (fp.Args.Length == 1)
            {
                QCol.Green("Displays a HEX output of a JCR entry");
                return;
            }
            QCol.Doing("Reading", fp.Args[1]);
            var jcr = JCR6.Dir(fp.Args[1]);

            if (jcr == null)
            {
                QCol.QuickError(JCR6.JERROR); return;
            }
            if (fp.Args.Length == 2)
            {
                foreach (TJCREntry file in jcr.Entries.Values)
                {
                    Show(jcr, file.Entry);
                }
            }
            else
            {
                for (int i = 2; i < fp.Args.Length; ++i)
                {
                    Show(jcr, fp.Args[i]);
                }
            }
        }
Esempio n. 3
0
        protected string JCRFile(FlagParse fp)
        {
            var tmp = NonFlags(fp, 1);

            if (tmp.Length < 1)
            {
                QCol.QuickError("No JCR file present");
                Environment.Exit(2);
            }
            return(tmp[0]);
        }
Esempio n. 4
0
 public string FileInfo(string f)
 {
     try {
         var fi = new FileInfo(f);
         return($"return {"{"} Size={fi.Length}, Created='{fi.CreationTime}', Modified='{fi.LastWriteTime}', Attrib='{fi.Attributes}' {"}"}");
     } catch (Exception E) {
         QCol.QuickError($".NET exception: '{E.Message}' while accessing {f}");
         Environment.Exit(100);
         // State.DoString($"error([[{E.Message}\n\n.NET ERROR\n\n]]..debug.traceback)", "Error in .NET");
         return("return {Size=0, Created='Error', Modified='Error', Attrib='Error'}");
     }
 }
Esempio n. 5
0
        public override void Run(FlagParse fp)
        {
            if (fp.Args.Length == 1)
            {
                QCol.Green("Show content of an entry as text on the console:\n\n");
                QCol.Yellow("-b              "); QCol.Cyan("When not set the ^Z character will be seen as EOF (DOS setting still working in Windows). When -b is set, everything will always be shown\n");
                QCol.Yellow("-nsh            "); QCol.Cyan("When set JCR6 will NOT try to syntax highlight");
                QCol.Yellow("-nln            "); QCol.Cyan("When set line numbers will not be displayed");
                return;
            }
            KittyHigh.Init();
            new KittyHighCS();
            new KittyHighNIL();
            new KittyHighLua();
            new KittyHighGINI();
            new KittyBlitzMax();
            new KittyHighC();
            new KittyHighPascal();
            new KittyHighBrainFuck();
            new KittyHighGo();
            new KittyHighBlitzBasic();
            new KittyHighSASKIA();
            new KittyHighPython();
            new KittyHighHtml();
            new KittyHighCobra();
            new KittyHighJava();
            new KittyHighJavaScript();
            new KittyHighNeil();
            new KittyHighVB();
            new KittyHighWhiteSpace();
            new KittyHighXml();
            var jcr = JCR6.Dir(fp.Args[1]);

            if (jcr == null)
            {
                QCol.QuickError(JCR6.JERROR);
                return;
            }
            if (fp.Args.Length == 2)
            {
                foreach (TJCREntry ent in jcr.Entries.Values)
                {
                    Show(jcr, ent.Entry, fp);
                }
            }
            else
            {
                for (int i = 2; i < fp.Args.Length; i++)
                {
                    Show(jcr, fp.Args[i], fp);
                }
            }
        }
Esempio n. 6
0
        static void Main(string[] args)
        {
            try {
                MKL.Lic("Quick Neil - QuickNeil.cs", "GNU General Public License 3");
                MKL.Version("Quick Neil - QuickNeil.cs", "20.08.14");
                if (args.Length == 0)
                {
                    Head();
                    QCol.Cyan("Usage: ");
                    QCol.Yellow($"{qstr.StripAll(MKL.MyExe)} ");
                    QCol.Green("<script file> ");
                    QCol.Magenta("[<arguments>]\n\n");
                    QCol.White($"{MKL.All()}\n\n");
                    return;
                }
                else
                {
                    var addargs = new StringBuilder("{");
                    for (int i = 1; i < args.Length; i++)
                    {
                        if (i >= 2)
                        {
                            addargs.Append(", ");
                        }
                        var arg = args[i].Replace("\\", "\\\\");
                        for (int j = 0; j < 256; j++)
                        {
                            if (j < 32 || j > 120 || (char)j == '"')
                            {
                                arg = arg.Replace($"{(char)j}", $"\\{qstr.Right($"00{j}", 3)}");
                            }
                        }
                        addargs.Append($"\"{arg}\"");
                    }
                    addargs.Append("}");
                    Debug.WriteLine($"DBG:Argument array {addargs}");
                    //throw new Exception ($"Argument array {addargs}"); // debug only!
                    LoadScript(args[0], $"{addargs}");
                }
            } catch (Exception e) {
                QCol.QuickError(e.Message);
#if DEBUG
                QCol.Cyan("Traceback\n");
                QCol.White($"{e.StackTrace}\n");
#endif
            } finally {
                TrickyDebug.AttachWait();
            }
        }
Esempio n. 7
0
        void Show(TJCRDIR jcr, string entry)
        {
            try {
                var Ext = qstr.ExtractExt(entry).ToUpper(); if (Ext == "")
                {
                    throw new Exception($"Files without extension cannot be processed: {entry}");
                }
                Ask($"APP.{Ext}", $"Which application should be used to show .{Ext} files?\nI need to know in order to view {entry}.\nJust a tag for the application, not yet a full line to execute", "Application");
                Ask($"EXE.{Config.C($"APP.{Ext}")}", $"Now I need the full line to execute the application {Config.C($"App.{Ext}")}.\nPlease note I will visit the folder where the temp file is located, and you must add {'{'}file{'}'} in the line so NJCR can subsitute that with the file needed", "Command line");
                QCol.Doing("Extracting", entry);
                var b    = jcr.JCR_B(entry);
                var tent = qstr.StripDir(entry);
                var old  = Directory.GetCurrentDirectory();
                Directory.SetCurrentDirectory(TempFolder);
                if (b == null)
                {
                    throw new Exception($"JCR ERROR: {JCR6.JERROR}");
                }
                QuickStream.SaveBytes(tent, b);
                QuickStream.SaveString("NJCRSHOW.BAT", $"{Config.C($"EXE.{Config.C($"APP.{Ext}")}").Replace("{file}", tent)}");
                // Start the child process.
                QCol.Doing("Executing", $"{Config.C($"EXE.{Config.C($"APP.{Ext}")}").Replace("{file}", tent)}");
                Process p = new Process();
                // Redirect the output stream of the child process.
                p.StartInfo.UseShellExecute        = false;
                p.StartInfo.RedirectStandardOutput = true;
                p.StartInfo.FileName = "NJCRSHOW.BAT";
                p.Start();
                // Do not wait for the child process to exit before
                // reading to the end of its redirected stream.
                // p.WaitForExit();
                // Read the output stream first and then wait.
                string output = p.StandardOutput.ReadToEnd();
                QCol.Magenta(output);
                p.WaitForExit();
                QCol.Doing("Deleting temp", tent);
                File.Delete(tent);
                Directory.SetCurrentDirectory(old);
            } catch (Exception Mislukt) {
                QCol.QuickError(Mislukt.Message);
#if DEBUG
                QCol.Magenta($"{Mislukt.StackTrace}\n");
#endif
            }
        }
Esempio n. 8
0
        static void Run(string[] args)
        {
            var f = new FlagParse(args);

            if (args.Length == 0)
            {
                QCol.White("\tUsage: ");
                QCol.Cyan($"{qstr.StripDir(MKL.MyExe)} ");
                QCol.Green("<command> ");
                QCol.Yellow("<parameters>\n\n");
                var tabx = 5;
                foreach (string k in Features.Keys)
                {
                    if (k.Length > tabx)
                    {
                        tabx = k.Length;
                    }
                }
                foreach (string k in Features.Keys)
                {
                    QCol.Green(k);
                    for (int i = k.Length; i < tabx + 2; ++i)
                    {
                        Console.Write(" ");
                    }
                    QCol.Yellow($"{Features[k].Description}\n");
                }
                return;
            }
            var cmd = args[0].ToUpper();

            if (!Features.ContainsKey(cmd))
            {
                QCol.QuickError($"Command '{cmd}' has not been understood");
                return;
            }
            Features[cmd].Parse(f);
            if (!f.Parse())
            {
                QCol.QuickError($"Bad command line input");
                return;
            }
            Features[cmd].Run(f);
        }
Esempio n. 9
0
        void XPrint(int size, ConsoleColor col, string text, Just align = Just.Left)
        {
            try {
                if (text == null)
                {
                    text = "";
                }
                var x = Console.CursorLeft;
                Console.ForegroundColor = col;
                if (text.Length > size)
                {
                    Console.WriteLine(text);
                    while (Console.CursorLeft < x + size)
                    {
                        Console.Write(" ");
                    }
                }
                else
                {
                    switch (align)
                    {
                    case Just.Left:
                        Console.Write(text);
                        for (int i = text.Length; i < size; i++)
                        {
                            Console.Write(" ");
                        }
                        break;

                    case Just.Right:
                        for (int i = 0; i < size - text.Length; i++)
                        {
                            Console.Write(" ");
                        }
                        Console.Write(text);
                        break;
                    }
                }
            } catch (Exception crap) {
                QCol.QuickError(crap.Message);
                QCol.Magenta(crap.StackTrace);
                Console.Write("\n\n");
            }
        }
Esempio n. 10
0
File: F_Add.cs Progetto: jcr6/NJCR
 public void Add2List(string ori, string tar, string sto, string aut, string notes)
 {
     if (File.Exists(ori))
     {
         Jiffy.Add(new Fil2Add(ori, tar, sto, aut, notes));
     }
     else if (Directory.Exists(ori))
     {
         var tree = FileList.GetTree(ori);
         foreach (string fil in tree)
         {
             Jiffy.Add(new Fil2Add($"{ori}/{fil}", $"{tar}/{fil}", sto, aut, notes));
         }
     }
     else
     {
         QCol.QuickError($"Neither a file nor a directory named {ori} found! Will be ignored!");
     }
 }
Esempio n. 11
0
        void Show(TJCRDIR jcr, string entry, FlagParse fp)
        {
            QCol.Doing("Reading", entry);
            var kind      = "OTHER";
            var highlight = !fp.GetBool("nsh");
            var linenums  = !fp.GetBool("nln");
            var istext    = !fp.GetBool("b");
            var src       = jcr.LoadString(entry);

            if (JCR6.JERROR != "")
            {
                QCol.QuickError(JCR6.JERROR);
                return;
            }
            if (istext)
            {
                var i = src.IndexOf((char)26);
                if (i >= 0)
                {
                    src = src.Substring(0, i);
                }
            }
            if (highlight)
            {
                var ext = qstr.ExtractExt(entry).ToLower();
                if (KittyHigh.Langs.ContainsKey(ext))
                {
                    kind = ext;
                }
                else if (ext == "bubbleproject")
                {
                    kind = "gini";
                }
            }
            var Viewer = KittyHigh.Langs[kind];

            QCol.Doing("Language", Viewer.Language);
            Console.WriteLine();
            Viewer.Show(src, linenums);
        }
Esempio n. 12
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");
                    }
                }
            }
        }
Esempio n. 13
0
File: F_HEX.cs Progetto: jcr6/NJCR
        void Show(TJCRDIR jcr, string entry)
        {
            QCol.Doing("Reading", entry);
            var b     = jcr.JCR_B(entry);
            var c     = ConsoleColor.Black;
            var stuff = "";

            if (b == null)
            {
                QCol.QuickError(JCR6.JERROR); return;
            }
            QCol.Green("................ 00 01 02 03  04 05 06 07  08 09 0A 0B  0C 0D 0E 0F");
            for (int i = 0; i < b.Length; i++)
            {
                switch (i % 16)
                {
                case 0x00:
                    QCol.ColWrite(ConsoleColor.Yellow, $"  {stuff}\n"); stuff = "";
                    QCol.ColWrite(ConsoleColor.DarkGray, $"{i.ToString("X16")} ");
                    c = ConsoleColor.Blue;
                    break;

                case 0x04:
                case 0x0C:
                    c = ConsoleColor.Cyan;
                    Console.Write(" ");
                    break;

                case 0x08:
                    c = ConsoleColor.Blue;
                    Console.Write(" ");
                    break;
                }
                if (b[i] > 31 && b[i] < 0x80)
                {
                    stuff += $"{(char)b[i]}";
                }
                else
                {
                    stuff += ".";
                }
                QCol.ColWrite(c, $"{b[i].ToString("X2")} ");
            }
            if (b.Length % 16 != 0)
            {
                for (int i = b.Length % 16; i < 16; i++)
                {
                    switch (i)
                    {
                    case 0x04:
                    case 0x0C:
                    case 0x08:
                        Console.Write(" ");
                        break;
                    }
                    Console.Write("   ");
                }
            }
            QCol.ColWrite(ConsoleColor.Yellow, $"  {stuff}\n");
            Console.WriteLine("\n");
        }
Esempio n. 14
0
File: F_Add.cs Progetto: jcr6/NJCR
        void AfterAdd(TJCREntry E, Fil2Add aFile)
        {
            if (E == null)
            {
                QCol.QuickError("Entry = null! Something went wrong!");
            }
            if (aFile == null)
            {
                QCol.QuickError("aFile = null! Something went wrong!");
            }
            QCol.Doing("Configuring", "", "\r");
            var deferrors = new List <string>();

            foreach (string vars in aFile.xBool.Keys)
            {
                if (vars[0] == '_')
                {
                    deferrors.Add($"Cannot define protected boolean variable {vars}");
                }
                else
                {
                    E.databool[vars] = aFile.xBool[vars];
                }
            }
            foreach (string vars in aFile.xInt.Keys)
            {
                if (vars[0] == '_')
                {
                    deferrors.Add($"Cannot define protected integer variable {vars}");
                }
                else
                {
                    E.dataint[vars] = aFile.xInt[vars];
                }
            }
            foreach (string vars in aFile.xString.Keys)
            {
                if (vars[0] == '_')
                {
                    deferrors.Add($"Cannot define protected string variable {vars}");
                }
                else
                {
                    E.datastring[vars] = aFile.xString[vars];
                }
            }
            if (E.Storage == "Store")
            {
                //          12345
                QCol.White("     Stored:\n");
            }
            else
            {
                var deel      = (decimal)E.CompressedSize;
                var geheel    = (decimal)E.Size;
                var pureratio = deel / geheel;
                QCol.Blue($"{qstr.Right($"   {(int)(pureratio * 100)}", 3)}% ");
                QCol.Green($"Packed: {E.Storage}\n");
            }
            if (deferrors.Count > 0)
            {
                QCol.QuickError("Although the file has been succesfully added, there are configuration errors!");
                foreach (string de in deferrors)
                {
                    QCol.Red("\t=> "); QCol.Yellow(de);
                }
            }
        }
Esempio n. 15
0
        static void Main(string[] args)
        {
            // Header
            QCol.Red("Kitty "); QCol.Magenta("Coded by: Tricky\n");
            QCol.Yellow($"(c) {MKL.CYear(2019)} Jeroen P. Broks\n\n");
            // Init
            Dirry.InitAltDrives();
            KittyHigh.Init();
            new KittyHighCS();
            new KittyHighNIL();
            new KittyHighLua();
            new KittyHighGINI();
            new KittyHighScyndi();
            new KittyBlitzMax();
            new KittyHighC();
            new KittyHighPascal();
            new KittyHighBrainFuck();
            new KittyHighGo();
            new KittyHighBlitzBasic();
            new KittyHighSASKIA();
            new KittyHighPython();
            new KittyHighJavaScript();
            new KittyHighWhiteSpace();
            new KittyHighBASIC();
            new KittyHighJava();
            new KittyHighINI();
            new KittyHighVB();
            new KittyHighCobra();
            new KittyHighHtml();
            new KittyHighXml();
            new KittyHighNeil();
            var slin = true;

            if (args.Length == 0)
            {
                QCol.Green("Kitty is a simple program which will help you view source files in syntax highlight\n");
                QCol.Magenta("Usage:\t");
                QCol.Yellow("Kitty ");
                QCol.Cyan("<switches> ");
                QCol.White("<files>");
                QCol.Green("[");
                QCol.Cyan("<switches> ");
                QCol.White("<files>");
                QCol.Green("..]");
                Console.WriteLine("\n\n");
                QCol.Yellow("Please note that switches affect all files defined after it not those that come before it. This allows you to configure each file shown\n\n");
                QCol.Cyan("-ln              "); QCol.Yellow("Toggle line numbers on/off (default is on)\n");
                QCol.Cyan("-nolinenumbers   "); QCol.Yellow("Turn line numbers off\n");
                QCol.Cyan("-Showlinenumbers "); QCol.Yellow("Turn line numbers on\n");
                QCol.Cyan("-re              "); QCol.Yellow("Toggle searching by RegEx (this allows limited support for Wild Cards and more nice things)\n");
                QCol.Cyan("-p, -more        "); QCol.Yellow("Turn \"more\" mode on/off. (Read note below)\n");
                QCol.Cyan("-support         "); QCol.Yellow("Show a list of all supported file formats\n");
                QCol.Red("\n\nThe \"more\" mode!\n");
                QCol.Yellow("Does not entirely work the same as the 'more' utility, but has the same primary function!\n");
                QCol.Yellow("When the \"more\" bar appears you can hit space to show the next line, Enter/Return to show the entire next page and escape to turn the more mode off\n");
                QCol.White("\n\nKitty can be used as as CLI tool, but the integry has been made to be included in your own projects, and has been released under the terms of the zlib license\n\n");
                return;
            }
            // Go for it
            QCol.Doing("Called from:", System.IO.Directory.GetCurrentDirectory());
            void ViewFile(string a)
            {
                try {
                    var arg = Dirry.AD(a).Replace("\\", "/");
                    QCol.Doing("Reading", arg); KittyHigh.PageBreak();
                    var src  = QuickStream.LoadString(arg);
                    var eoln = qstr.EOLNType(arg);
                    // QCol.Doing("EOLN", eoln); // didn't work anyway
                    //QCol.OriCol();
                    var       ext    = qstr.ExtractExt(arg).ToLower();
                    KittyHigh Viewer = KittyHigh.Langs["OTHER"];
                    if (KittyHigh.Langs.ContainsKey(ext))
                    {
                        Viewer = KittyHigh.Langs[ext];
                    }
                    QCol.Doing("Type", Viewer.Language); KittyHigh.PageBreak();
                    KittyHigh.WriteLine();
                    Viewer.Show(src, slin);
                } catch (Exception ex) {
                    QCol.QuickError($"{ex.Message}\n");
#if DEBUG
                    QCol.Magenta($"{ex.StackTrace}\n\n");
#endif
                }
            }

            var aregex = false;
            foreach (string a in args)
            {
                if (qstr.Prefixed(a, "-"))
                {
                    switch (a.ToLower())
                    {
                    case "-ln": slin = !slin; break;

                    case "-nolinenumbers": slin = false; break;

                    case "-showlinenumbers": slin = true; break;

                    case "-p":
                    case "-more": KittyHigh.BrkLines = !KittyHigh.BrkLines; break;

                    case "-re": aregex = !aregex; break;

                    case "-support":
                        foreach (string ext in KittyHigh.Langs.Keys)
                        {
                            QCol.Cyan(qstr.Left($"{ext}                    ", 20));
                            QCol.Yellow($"{KittyHigh.Langs[ext].Language}\n");
                        }
                        break;

                    default: QCol.QuickError($"Unknown switch: {a}"); break;
                    }
                }
                else if (aregex)
                {
                    QCol.Doing("Searching for RegEx", a);
                    var rgxl = RegExTree.Tree(a);
                    foreach (string af in rgxl)
                    {
                        ViewFile(af);
                    }
                }
                else
                {
                    ViewFile(a);
                }
            }
            TrickyDebug.AttachWait();
        }
Esempio n. 16
0
File: F_Add.cs Progetto: 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);
                }
            }
        }
Esempio n. 17
0
        public override void Run(FlagParse fp)
        {
            if (fp.Args.Length == 1 || fp.GetBool("h"))
            {
                QCol.Green("Extract files from a JCR file! Available switches are:\n\n");
                QCol.Yellow("-nx             "); QCol.Cyan("No eXternals. This means that any file imported from external JCR files will be ignored\n");
                QCol.Yellow("-ow             "); QCol.Cyan("Overwrite existing files\n");
                QCol.Yellow("-nodir          "); QCol.Cyan("Remove paths from file names\n");
                QCol.Yellow("-nac            "); QCol.Cyan("No auto-creation of new directories if needed\n");
                QCol.Yellow("-output <path>  "); QCol.Cyan("Define output path\n");
                QCol.Magenta("\n\nWhat is important to note is that JCR6 was never set up as a real archiver like ZIP, RAR and 7z.\nIt has therefore features that ZIP, RAR, 7z nor any other archiver has.\n\nIt also lacks features the others have.\n\nExtracting was never a full feature of JCR6, but was rather added for completeness sake.\nExtracting files from it can therefore have some funny results.\n\n");
                return;
            }
            var nx         = fp.GetBool("nx");
            var ow         = fp.GetBool("ow");
            var nodir      = fp.GetBool("nodir");
            var autocreate = fp.GetBool("nac");
            var outdir     = fp.GetString("output");

            if (outdir != "")
            {
                outdir = outdir.Replace("\\", "/");
                if (!qstr.Suffixed(outdir, "/"))
                {
                    outdir += "/";
                }
            }
            QCol.Doing("Reading", fp.Args[1]);
            var jcr = JCR6.Dir(fp.Args[1]);

            if (JCR6.JERROR != "")
            {
                QCol.QuickError($"JCR6 Error: {JCR6.JERROR}");
                return;
            }
            try {
                var skipreason = "";
                var allow      = true;
                var offsets    = new Dictionary <string, List <TJCREntry> >();
                var alias      = aliashanding.Ignore;
                void skip(string reason)
                {
                    if (skipreason != "")
                    {
                        skipreason += "; ";
                    }
                    skipreason += reason;
                    allow       = false;
                }
                var shared = false;
                foreach (TJCREntry Ent in jcr.Entries.Values)
                {
                    var tag = $"{Ent.MainFile}:{Ent.Offset}";
                    if (!offsets.ContainsKey(tag))
                    {
                        offsets[tag] = new List <TJCREntry>();
                    }
                    else
                    {
                        shared = true;
                    }
                    offsets[tag].Add(Ent);
                }
                if (shared)
                {
                    Console.Beep();
                    QCol.Red("\n\nWARNING!\n");
                    QCol.Yellow("This resource has some shared-references or aliases as they are properly called in JCR6.\n");
                    QCol.Yellow("Extracting from this file can therefore create tons of duplicate files, as JCR6 cannot tell which entry is more relevant than others.\n");
                    QCol.Yellow("It's strongly recommended to extract files from this resource unless you are sure about what you are doing and what the consequences are and how to deal with them\n");
                    QCol.Cyan("1 = Continue, but ask about any files that has aliases, what to do with them\n");
                    QCol.Cyan("2 = Continue, but skip all files with aliases\n");
                    QCol.Cyan("3 = Continue, and just let the duplicate files come, I don't fear them!\n");
                    QCol.Cyan("Q = Cancel this operation\n");
                    QCol.Magenta("What do you want to do? "); QCol.Green("");
                    {
                        var loop = true;
                        do
                        {
                            var ch = Console.ReadKey();
                            switch (ch.KeyChar)
                            {
                            case '1': alias = aliashanding.Ask; loop = false; break;

                            case '2': alias = aliashanding.Skip; loop = false; break;

                            case '3': alias = aliashanding.Ignore; loop = false; break;

                            case 'q':
                            case 'Q': return;
                            }
                        } while (loop);
                        Console.WriteLine($" -- {alias}");
                    }
                }
                foreach (TJCREntry Ent in jcr.Entries.Values)
                {
                    allow      = true;
                    skipreason = "";
                    // can we do this?
                    var source = Ent.Entry;
                    var target = Ent.Entry;
                    var tag    = $"{Ent.MainFile}:{Ent.Offset}";
                    if (!JCR6.CompDrivers.ContainsKey(Ent.Storage))
                    {
                        skip($"Unknown compression method ({Ent.Storage})");
                    }
                    if (offsets[tag].Count > 1)
                    {
                        switch (alias)
                        {
                        case aliashanding.Skip: skip($"Offset reference as {offsets[tag].Count} entries, and system has been set to skip those"); break;

                        case aliashanding.Ask: {
                            Console.Beep();
                            QCol.Red($"Entry {Ent.Entry} has been aliased.\n");
                            foreach (TJCREntry aliasentry in offsets[tag])
                            {
                                QCol.Magenta("= "); QCol.Cyan($"{aliasentry.Entry}\n");
                            }
                            QCol.Green("Extract ? <Y/N> ");
                            do
                            {
                                var d = Console.ReadKey().KeyChar;
                                if (d == 'Y' || d == 'y')
                                {
                                    break;
                                }
                                if (d == 'N' || d == 'n')
                                {
                                    skip("User decided not to extract"); break;
                                }
                            } while (true);
                            Console.Write("\r");
                            break;
                        }
                        }
                    }
                    if (Ent.MainFile != fp.Args[1] && nx)
                    {
                        skip("No Externals");
                    }
                    if (nodir)
                    {
                        target = qstr.StripDir(target);
                    }
                    target = $"{outdir}{target}";
                    if (!Directory.Exists(qstr.ExtractDir(target)) && !autocreate)
                    {
                        Console.Beep();
                        QCol.Red($"{target}! ");
                        QCol.Yellow($"Create directory {qstr.ExtractDir(target)} ? <Y/N> ");
                        do
                        {
                            var d = Console.ReadKey().KeyChar;
                            if (d == 'Y' || d == 'y')
                            {
                                break;
                            }
                            if (d == 'N' || d == 'n')
                            {
                                skip("User decided not to extract"); break;
                            }
                        } while (true);
                        Console.Write("\n");
                    }
                    if (File.Exists(target) && (!ow))
                    {
                        Console.Beep();
                        QCol.Red($"{target} exists! ");
                        QCol.Yellow($"Overwrite ? <Y/N> ");
                        do
                        {
                            var d = Console.ReadKey().KeyChar;
                            if (d == 'Y' || d == 'y')
                            {
                                break;
                            }
                            if (d == 'N' || d == 'n')
                            {
                                skip("User decided not to extract"); break;
                            }
                        } while (true);
                        Console.Write("\n");
                    }
                    if (allow)
                    {
                        QCol.Doing("Extracting", target, "\r");
                        Directory.CreateDirectory(qstr.ExtractDir(target));
                        var b = jcr.JCR_B(source);
                        QuickStream.SaveBytes(target, b);
                        QCol.Doing(" Extracted", target);
                    }
                    else
                    {
                        QCol.Doing("   Skipped", target, "\t"); QCol.Red($"{skipreason}\n");
                    }
                }
            } catch (Exception e) {
                QCol.QuickError($".NET Error: {e.Message}");
#if DEBUG
                QCol.Magenta(e.StackTrace);
#endif
            }
        }