Example #1
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
            }
        }
Example #2
0
File: F_HEX.cs Project: 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");
        }