Example #1
0
        /// <summary>
        /// Patches a file into a JCR6 resource, if JCR6 can recognise it as a resource.
        /// </summary>
        /// <param name="file">File.</param>
        public void PatchFile(string file)
        {
            JCR6.dCHAT($"Patching: {file}");
            var p = JCR6.Dir(file);

            if (p == null)
            {
                JCR6.JERROR = ("PATCH ERROR:" + JCR6.JERROR);
                return;
            }
            Patch(p);
        }
Example #2
0
        public override bool Recognize(string file)
        {
            bool ret = false;

            if (!File.Exists(file))
            {
                JCR6.dCHAT(file + " not found!");
                return(false);
            }
            var bt = QuickStream.ReadFile(file);

            ret = bt.Size > 10; // I don't believe a JCR6 file can even get close to that!
            ret = ret && bt.ReadString(checkheader.Length) == checkheader;
            bt.Close();
            //Console.WriteLine(ret);
            return(ret);
        }
Example #3
0
        public override TJCRDIR Dir(string file)
        {
            //Private
            //Function JCR_FetchWAD:TJCRDir(WAD$, SupportLevel= 1)
            var Returner = new TJCRDIR();
            //var Ret:TMap = New TMap; returner.entries = ret
            TJCREntry E;
            var       BT    = QuickStream.ReadFile(file, QuickStream.LittleEndian);
            var       Level = "";

            string[] LevelFiles = { "THINGS", "LINEDEFS", "SIDEDEFS", "VERTEXES", "SEGS", "SSECTORS", "NODES", "SECTORS", "REJECT", "BLOCKMAP", "BEHAVIOR" }; //' All files used in a DOOM/HERETIC/HEXEN level, in which I must note that "BEHAVIOR" is only used in HEXEN.
            if (BT == null)
            {
                JCR6.JERROR = "WAD file could not be read!\n" + file;
                return(null);
            }
            //BT = LittleEndianStream(BT) ' WADs were all written for the MS-DOS platform, which used LittleEndian, so we must make sure that (even if the routine is used on PowerPC Macs) that LittleEndian is used
            //WAD files start with a header that can either be 'IWAD' for main wad files or 'PWAD' for patch WAD files. For JCR this makes no difference it all (it didn't even to WAD for that matter), but this is our only way to check if the WAD loaded is actually a WAD file.
            var Header = BT.ReadString(4);

            switch (Header)
            {
            case "IWAD":
                Returner.Comments["Important notice"] = "The WAD file you are viewing is an IWAD,\nmeaning it belongs to a copyrighted project.\n\nAll content within it is very likely protected by copyright\neither by iD software or Apogee's Developers of Incredible Power or Raven Software.\n\nNothing can stop you from analysing this file and viewing its contents,\nbut don't extract and distribute any contents of this file\nwithout proper permission from the original copyright holder";
                break;

            case "PWAD":
                Returner.Comments["Notice"] = "This WAD file is a PWAD or Patch-WAD. It's not part of any official file of the games using the WAD system. Please respect the original copyright holders copyrights though!";
                break;

            default:
                JCR6.JERROR = "JCR_FetchWAD('" + file + "'): Requested file is not a WAD file";
                return(null);
            }
            Returner.CFGbool["__CaseSensitive"] = false;
            //'Next in the WAD files are 2 32bit int values telling how many files the WAD file contains and where in the WAD file the File Table is stored
            var FileCount = BT.ReadInt();
            var DirOffset = BT.ReadInt();

            //DebugLog "This WAD contains "+FileCount+" entries starting at "+DirOffset
            BT.Position = DirOffset;
            // And let's now read all the crap
            for (int Ak = 1; Ak <= FileCount; Ak++)
            {
                //    'DebugLog "Reading entry #"+Ak
                E = new TJCREntry();
                // E.PVars = New StringMap ' Just has to be present to prevent crashes in viewer based software. // Not an issue in the C# version.
                E.MainFile       = file;
                E.Offset         = BT.ReadInt();
                E.Size           = BT.ReadInt();
                E.Entry          = BT.ReadString(8).Trim().Replace("\0", ""); //Replace(Trim(ReadString(BT, 8)), Chr(0), "")
                E.CompressedSize = E.Size;
                E.Storage        = "Store";                                   // WAD does not support compression, so always deal this as "Stored"
                //    'E.Encryption = 0  ' WAD does not support encryption, so always value 0
                if (SupportLevel)                                             // ' If set the system will turn DOOM levels into a folder for better usage. When unset the system will just dump everything together with not the best results, but hey, who cares :)
                {
                    //'Print "File = "+E.FileName+" >> Level = ~q"+Level+"~q >> Len="+Len(E.FileName)+" >> 1 = "+Left(E.FileName,1)+" >> 3 = "+Mid(E.FileName,3,1)
                    //'If Level=""
                    if (qstr.Left(E.Entry, 3) == "MAP")
                    {
                        Level = "MAP_" + E.Entry + "/";
                    }
                    else if (E.Entry.Length == 4 && qstr.Left(E.Entry, 1) == "E" && qstr.Mid(E.Entry, 3, 1) == "M")
                    {
                        Level = "MAP_" + E.Entry + "/";
                    }
                    else if (Level != "")
                    {
                        var Ok = false;
                        foreach (string S in LevelFiles)
                        {
                            Ok = Ok || E.Entry == S;
                            //'Print "Comparing "+E.FileName+" with "+S+"   >>>> "+Ok
                        }
                        if (Ok)
                        {
                            E.Entry = Level + E.Entry;
                        }
                        else
                        {
                            Level = "";
                        }
                    }
                }
                JCR6.dCHAT("Adding: " + E.Entry);
                Returner.Entries[E.Entry.ToUpper()] = E;
            }
            BT.Close();
            //Return Ret
            return(Returner);
        }
Example #4
0
        private TJCRDIR RDir(string file, bool ap)
        {
            // init
            var ret  = new TJCRDIR();
            var path = file;
            var w    = new List <string>();
            var di   = new DirectoryInfo(path);

            ret.Comments["Real Dir"] = "Actually \"" + path + "\" is not a JCR6 resource, but a directory \"faked\" into a JCR6 resource.";
            // Check
            if (!di.Exists)
            {
                FLError = "UseJCR6.JCR6_RealDir.Dir(\"" + path + "\"): Directory does not exist!";
                return(null);
            }
            // Listout
            foreach (DirectoryInfo fi in di.GetDirectories())
            {
                if (allowhidden || fi.Name.Substring(0, 1) != ".")
                {
                    JCR6.dCHAT("Recursing: " + fi.Name);
                    var a = JCR6.Dir(path + "/" + fi.Name);
                    foreach (string k in a.Entries.Keys)
                    {
                        var ke = a.Entries[k];
                        ret.Entries[(fi.Name + "/" + k).ToUpper()] = ke;
                        ke.Entry    = fi.Name + "/" + ke.Entry;
                        ke.MainFile = path + "/" + fi.Name + "/" + ke.Entry;
                    }
                }
            }
            foreach (FileInfo fi in di.GetFiles())
            {
                if (automerge && JCR6.Recognize(path + "/" + fi.Name) != "NONE")
                {
                    var a = JCR6.Dir(path + "/" + fi.Name);
                    if (a == null)
                    {
                        Console.WriteLine($"WARNING! Scanning {fi.Name} failed >> {JCR6.JERROR}");
                    }
                    else
                    {
                        foreach (string k in a.Entries.Keys)
                        {
                            var ke = a.Entries[k];
                            ret.Entries[(fi.Name + "/" + k).ToUpper()] = ke;
                            ke.Entry    = fi.Name + "/" + ke.Entry;
                            ke.MainFile = path + "/" + ke.Entry;
                        }
                        foreach (string k in a.Comments.Keys)
                        {
                            ret.Comments[k] = a.Comments[k];
                        }
                    }
                }
                else
                {
                    var e = new TJCREntry();
                    e.Entry          = fi.Name;
                    e.MainFile       = path + "/" + fi.Name;
                    e.Storage        = "Store";
                    e.CompressedSize = (int)fi.Length;
                    e.Size           = (int)fi.Length;
                    ret.Entries[fi.Name.ToUpper()] = e;
                }
            }



            // return the crap
            return(ret);
        }