示例#1
0
        public static bool PatchFile(string DataJetLocation, JetVersion jv, List <Patch> patches, string fileName, string JetPassword = "******")
        {
            var file = Path.Combine("Assets", "JSON", fileName);

            file = file.Replace(@"\", @"/");
            foreach (Patch p in patches)
            {
                if (fileName != p.File)
                {
                    return(false);
                }
            }


            var ctn = GetFileFromJet(file, DataJetLocation, jv, JetPassword);

            foreach (Patch p in patches)
            {
                ctn = DeployPatch(ctn, p);
            }

            UpdateFileInJet(file, ctn, DataJetLocation, jv, JetPassword);


            return(true);
        }
示例#2
0
        public static bool PatchJet(string DataJetLocation, JetVersion jv, List <Mod> mods, string JetPassword = "******")
        {
            var conflits = GetModConflicts(mods);

            if (conflits.Count != 0)
            {
                return(false);
            }

            var retVal = true;

            var pf = GetPatchesForFiles(mods, jv);

            foreach (KeyValuePair <string, List <Patch> > f in pf)
            {
                retVal = retVal && PatchFile(DataJetLocation, jv, f.Value, f.Key, JetPassword);
            }

            return(retVal);
        }
示例#3
0
        public static string ExtractJet(string DataJetLocation, JetVersion jv, string StorageLocation, string Password = "******")
        {
            ZipFile zf  = ZipFile.Read(DataJetLocation);
            string  loc = Path.Combine(StorageLocation, jv.ShortHand());

            Passwords.DJ.TryGetValue(jv.ShortHand(), out var pw);
            zf.Password = Password;


            if (Password == "RETR")
            {
                zf.Password = pw;
            }
            try
            {
                zf.ExtractAll(loc);
            }
            catch (Exception) {}
            zf.Dispose();

            return(loc);
        }
示例#4
0
        public static string GetFileFromJet(string file, string DataJetLocation, JetVersion jv, string Password = "******")
        {
            ZipFile zf = ZipFile.Read(DataJetLocation);

            Passwords.DJ.TryGetValue(jv.ShortHand(), out var pw);
            var pass = Password;

            if (Password == "RETR")
            {
                pass = pw;
            }
            if (!zf.ContainsEntry(file))
            {
                return("error");
            }

            ZipEntry ze = null;

            foreach (ZipEntry e in zf)
            {
                if (e.FileName == file)
                {
                    ze = e;
                }
            }

            var ms = new MemoryStream();

            ze.ExtractWithPassword(ms, pass);
            var bytes   = ms.ToArray();
            var content = Encoding.UTF8.GetString(bytes);

            zf.Dispose();
            ms.Dispose();
            return(content);
        }
示例#5
0
        public static void UpdateFileInJet(string file, string content, string DataJetLocation, JetVersion jv, string Password = "******")
        {
            ZipFile zf = ZipFile.Read(DataJetLocation);

            Passwords.DJ.TryGetValue(jv.ShortHand(), out var pw);
            zf.Password = Password;
            if (Password == "RETR")
            {
                zf.Password = pw;
            }

            zf.UpdateEntry(file, content);

            zf.Save();
            zf.Dispose();
        }
示例#6
0
 public static void BackupDataJet(string DataJetLocation, JetVersion jv, string StorageLocation, string Name = "")
 {
     File.Copy(DataJetLocation, Path.Combine(StorageLocation, Name + jv.ShortHand() + ".jet"));
 }
示例#7
0
        public static Dictionary <string, List <Patch> > GetPatchesForFiles(List <Mod> mods, JetVersion jv)
        {
            var ret = new Dictionary <string, List <Patch> >();

            foreach (Mod m in mods)
            {
                foreach (Patch p in m.GetAllPatches())
                {
                    var f = p.File;
                    if (!ret.ContainsKey(f))
                    {
                        ret.Add(f, new List <Patch>());
                    }

                    ret.TryGetValue(f, out var patches);
                    patches.Add(p);
                }
            }

            return(ret);
        }