Ejemplo n.º 1
0
        static public void ViewImg(byte[] Buffer, string File)
        {
            var ext = qstr.ExtractExt(File).ToLower();

            QuickStream.SaveBytes($"{Core.ViewSwap}/Image.{ext}", Buffer);
            QuickStream.SaveString($"{Core.ViewSwap}/ViewFile.html", HTMLTemplate.Replace("<HEADER>", $"Viewing: {File}").Replace("<URI>", $"{Core.ViewSwap}/Image.{ext}"));
        }
Ejemplo n.º 2
0
        private void Butt_Extract_Click(object sender, RoutedEventArgs e)
        {
            if (DirBox.SelectedItem == null)
            {
                Debug.WriteLine("No item, so no extract"); return;
            }
            var item = (string)DirBox.SelectedItem; Debug.WriteLine($"Item: {item}"); if (item == "" || qstr.Suffixed(item, "/"))
            {
                Debug.WriteLine("Item is directory, so no extract"); return;
            }
            var xas = FFS.RequestFile(true); if (xas == "")
            {
                return;
            }
            var ix = qstr.ExtractExt(item).ToLower();
            var ex = qstr.ExtractExt(xas).ToLower();

            if (ix != ex)
            {
                switch (Confirm.YNC($"Original extention is \"{ix}\", and given extension is \"{ex}\". This does not match. Add this extension?"))
                {
                case -1:
                    return;

                case 0:
                    break;

                case 1:
                    xas += $".{ix}";
                    break;

                default:
                    throw new Exception("Invalid output from Confirm.YNC");
                }
            }
            if (Core.IN_Resource)
            {
                try {
                    var data = Core.JCR.JCR_B($"{Core.CDirectory}/{item}");
                    if (data == null)
                    {
                        throw new Exception($"Unable to get data!\nJCR6 reported: {JCR6.JERROR}");
                    }
                    QuickStream.SaveBytes(xas, data);
                } catch (Exception E) {
                    Confirm.Annoy(E.Message, "Error!", System.Windows.Forms.MessageBoxIcon.Error);
                }
            }
            else
            {
                try {
                    File.Copy($"{Core.CDirectory}/{item}", xas, true);
                } catch (Exception E) {
                    Confirm.Annoy(E.Message, "Error!", System.Windows.Forms.MessageBoxIcon.Error);
                }
            }
        }
Ejemplo n.º 3
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
            }
        }
Ejemplo n.º 4
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
            }
        }