Beispiel #1
0
        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);
                }
            }
        }
Beispiel #2
0
 public override void Run(FlagParse fp)
 {
     if (fp.Args.Length == 1 || fp.GetBool("h"))
     {
         QCol.Green("Add files to a JCR file! Available switches are:\n\n");
         QCol.Yellow("-doj             "); QCol.Cyan("Destroy original JCR file, so begin completely fresh, always\n");
         QCol.Yellow("-i               "); QCol.Cyan("Input file(s) or directory/directories. (deprecated)\n");
         QCol.Yellow("-cm <method>     "); QCol.Cyan("Compression method for the files inside the JCR file (default is lzma)\n");
         QCol.Yellow("-fc <method>     "); QCol.Cyan("Compression method for the file table inside the JCR file (default is lzma)\n");
         QCol.Yellow("-jif <file>      "); QCol.Cyan("Read a JCR Instruction File to see how files must be stored and under which conditions\n");
         QCol.Yellow("-author <author> "); QCol.Cyan("Add an author to the files added (jif files ignore this flag)\n");
         QCol.Yellow("-notes <notes>   "); QCol.Cyan("Add notes to the files added (jif files ignore this flag)\n");
         QCol.Yellow("-nomerge         "); QCol.Cyan("When set, files detected as JCR6 compatible files will not be merged, but just be addd as a regular file!\n");
         QCol.Yellow("-puremerge       "); QCol.Cyan("When set, entries being added due to JCR-merging will not be repacked, but be directly copied\n");
         QCol.Yellow("                 "); QCol.Magenta("It goes without saying, but using -nomerge and -puremerge in one run is not a very clever thing to do.");
         //QCol.Yellow("-qu              "); QCol.Cyan("Quick update. (Type \"NJCR quhelp\" for more information)\n");
         QCol.Blue("\n\n\n");
         QCol.Green("JCR6 supports the next compression methods:\n");
         foreach (string name in JCR6.CompDrivers.Keys)
         {
             QCol.Red("\t* "); QCol.Yellow($"{name}\n");
         }
         return;
     }
     quick   = fp.GetBool("qu");
     jcrfile = fp.Args[1];
     toadd   = Files(fp);
     filetablecompression = fp.GetString("fc");
     compressionmethod    = fp.GetString("cm");
     puremerge            = fp.GetBool("puremerge");
     nomerge = fp.GetBool("nomerge");
     if (fp.GetString("i") != "")
     {
         var l = new List <string>(toadd);
         l.Add(fp.GetString("i"));
         toadd = l.ToArray();
     }
     updating = File.Exists(jcrfile) && !fp.GetBool("doj");
     if (toadd.Length == 0)
     {
         Add2List(Directory.GetCurrentDirectory(), "", compressionmethod, fp.GetString("author"), fp.GetString("notes"));
     }
     else
     {
         foreach (string fil in toadd)
         {
             Add2List(fil, qstr.StripDir(fil), compressionmethod, fp.GetString("author"), fp.GetString("notes"));
         }
     }
     if (fp.GetString("jif") != "")
     {
         ParseJIF(fp.GetString("jif"));
     }
     if (updating)
     {
         QCol.Doing("Updating", jcrfile);
     }
     else
     {
         QCol.Doing("Creating", jcrfile);
     }
     QCol.Doing("File Storage", compressionmethod);
     QCol.Doing("Table Storage", filetablecompression);
     QCol.Doing("No merge", $"{nomerge}");
     QCol.Doing("Pure merge", $"{puremerge}");
     QCol.Doing("Files", $"{Jiffy.Count}");
     QCol.Doing("NJCR", MKL.MyExe);
     QCol.Doing("PWD", Directory.GetCurrentDirectory());
     Console.WriteLine("\n\n");
     Go();
 }
Beispiel #3
0
        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);
                }
            }
        }