Exemple #1
0
        public void Deserialize(BinaryReader reader)
        {
            id = (PatchId)reader.ReadByte();
            var count = reader.ReadInt32();

            for (int i = 0; i < count; i++)
            {
                var file = reader.ReadInt32();
                files.Add(file);
            }
        }
Exemple #2
0
        public static List <VFile> GetNewFiles(PatchId patch, string savePath)
        {
            var list  = new List <VFile>();
            var files = serverVersion.GetFiles(patch);

            foreach (var file in files)
            {
                if (IsNew(savePath + file.name, file.len, file.hash))
                {
                    list.Add(file);
                }
            }
            return(list);
        }
Exemple #3
0
        public List <VFile> GetFiles(PatchId patchId)
        {
            List <VFile> list = new List <VFile>();
            VPatch       patch;

            if (_dataPatches.TryGetValue(patchId, out patch))
            {
                if (patch.files.Count > 0)
                {
                    foreach (var file in patch.files)
                    {
                        var item = files[file];
                        list.Add(item);
                    }
                }
            }
            return(list);
        }
Exemple #4
0
        private static void PatchAssets(PatchId patch)
        {
            var selection = Selection.GetFiltered <Object>(SelectionMode.DeepAssets);
            var rules     = BuildScript.GetBuildRules();

            foreach (var o in selection)
            {
                var path = AssetDatabase.GetAssetPath(o);
                if (string.IsNullOrEmpty(path) || Directory.Exists(path))
                {
                    continue;
                }
                rules.PatchAsset(path, patch);
            }

            EditorUtility.SetDirty(rules);
            AssetDatabase.SaveAssets();
        }
Exemple #5
0
 private void UninstallPatch(PatchId patchId)
 {
     using (var transaction = this.context.CreateTransaction())
     {
         AbstractPatch patch            = AbstractPatch.LoadById(patchId, context);
         var           patchInstallInfo = transaction.ExecuteReader(
             String.Format(
                 "select {1} from {0} where {2} = {4} and {3} = {5} for update",
                 transaction.EscapeName(this.context.PatchesTable),
                 transaction.EscapeName("ROLLBACK_DATA"),
                 transaction.EscapeName("VERSION"),
                 transaction.EscapeName("NAME"),
                 transaction.MarkParam("pversion"),
                 transaction.MarkParam("pname")
                 ),
             new Dictionary <string, object>
         {
             { "pversion", patchId.version },
             { "pname", patchId.name },
         }
             ).Single();
         patch.Rollback(transaction, XDocument.Parse(patchInstallInfo["ROLLBACK_DATA"]));
         int affectedRows = transaction.ExecuteNonQuery(
             String.Format(
                 "delete from {0} where {1} = {3} and {2} = {4}",
                 transaction.EscapeName(this.context.PatchesTable),
                 transaction.EscapeName("VERSION"),
                 transaction.EscapeName("NAME"),
                 transaction.MarkParam("pversion"),
                 transaction.MarkParam("pname")
                 ),
             new Dictionary <string, object>
         {
             { "pversion", patchId.version },
             { "pname", patchId.name },
         }
             );
         if (affectedRows != 1)
         {
             throw new ApplicationException("Unable to install patch; are you trying to run two patchers simultaneously?");
         }
         transaction.Commit();
     }
 }
Exemple #6
0
        public void PatchAsset(string path, PatchId patch)
        {
            bool Match(AssetBuild bundleAsset)
            {
                return(bundleAsset.path.Equals(path));
            }

            var asset = ArrayUtility.Find(assets, Match);

            if (asset != null)
            {
                asset.patch = patch;
                return;
            }
            ArrayUtility.Add(ref assets, new AssetBuild()
            {
                path  = path,
                patch = patch,
            });
        }
Exemple #7
0
 public static Stream loadPatch(PatchId patchId)
 {
     return Resources.ResourcesManager.GetResource(String.Format("Patch_{0:D5}_{1}.xml", patchId.version, patchId.name));
 }
Exemple #8
0
 public Stream loadPatch(PatchId patchId)
 {
     return configuration.loadPatch(patchId);
 }
Exemple #9
0
 public static Stream loadPatch(PatchId patchId)
 {
     return(Resources.ResourcesManager.GetResource(String.Format("Patch_{0:D5}_{1}.xml", patchId.version, patchId.name)));
 }
Exemple #10
0
 private void UninstallPatch(PatchId patchId)
 {
     using(var transaction = this.context.CreateTransaction())
     {
         AbstractPatch patch = AbstractPatch.LoadById(patchId, context);
         var patchInstallInfo = transaction.ExecuteReader(
             String.Format(
                 "select {1} from {0} where {2} = {4} and {3} = {5} for update",
                 transaction.EscapeName(this.context.PatchesTable),
                 transaction.EscapeName("ROLLBACK_DATA"),
                 transaction.EscapeName("VERSION"),
                 transaction.EscapeName("NAME"),
                 transaction.MarkParam("pversion"),
                 transaction.MarkParam("pname")
             ),
             new Dictionary<string, object>
             {
                 { "pversion", patchId.version },
                 { "pname", patchId.name },
             }
         ).Single();
         patch.Rollback(transaction, XDocument.Parse(patchInstallInfo["ROLLBACK_DATA"]));
         int affectedRows = transaction.ExecuteNonQuery(
             String.Format(
                 "delete from {0} where {1} = {3} and {2} = {4}",
                 transaction.EscapeName(this.context.PatchesTable),
                 transaction.EscapeName("VERSION"),
                 transaction.EscapeName("NAME"),
                 transaction.MarkParam("pversion"),
                 transaction.MarkParam("pname")
             ),
             new Dictionary<string, object>
             {
                 { "pversion", patchId.version },
                 { "pname", patchId.name },
             }
         );
         if(affectedRows != 1)
         {
             throw new ApplicationException("Unable to install patch; are you trying to run two patchers simultaneously?");
         }
         transaction.Commit();
     }
 }
Exemple #11
0
 public static AbstractPatch LoadById(PatchId id, Context context)
 {
     return Cache<AbstractPatch>.instance.get(new KeyValuePair<PatchId, Context>(id, context), () => _LoadById(id, context));
 }
Exemple #12
0
        private void InstallPatch(PatchId patchId)
        {
            AbstractPatch patch = AbstractPatch.LoadById(patchId, this.context);

            if (!patch.DoesSupportEnvironment(this.context.EnvironmentName))
            {
                this.context.console.Report(" (skipping because of unsupported environment) ");
                return;
            }

            using (var transaction = this.context.CreateTransaction())
            {
                bool      patchExistsInDB;
                XDocument rollbackData;

                var patchDBData = transaction.ExecuteReader(
                    string.Format(
                        "select {1} from {0} where {2} = {3} and {4} = {5}",
                        transaction.EscapeName(this.context.PatchesTable),
                        transaction.EscapeName("STATUS"),
                        transaction.EscapeName("VERSION"),
                        transaction.MarkParam("pversion"),
                        transaction.EscapeName("NAME"),
                        transaction.MarkParam("pname")
                        ),
                    new Dictionary <string, object>
                {
                    { "pversion", patchId.version },
                    { "pname", patchId.name },
                }
                    ).ToList();

                if (patch is PersistentPatch)
                {
                    bool reinstall;

                    if (patchDBData.Any())
                    {
                        var patchInfo = patchDBData.Single();
                        switch (patchInfo["STATUS"])
                        {
                        case STATUS_INSTALLED:
                            throw new ApplicationException("Patch is already installed");

                        case STATUS_INSTALLING:
                            reinstall = true;
                            break;

                        default:
                            throw new ApplicationException(string.Format("Unknown status {0}", patchInfo["STATUS"]));
                        }
                    }
                    else
                    {
                        reinstall = false;
                    }

                    if (reinstall)
                    {
                        patchExistsInDB = true;
                    }

                    throw new NotImplementedException("Persistent patch installation is not implemented yet");
                }
                else
                {
                    if (patchDBData.Any())
                    {
                        throw new ApplicationException("Patch is already installed");
                    }

                    patchExistsInDB = false;
                    rollbackData    = patch.Apply(transaction);
                }

                //System.Threading.Thread.Sleep(1000);
                int affectedRows = transaction.ExecuteNonQuery(
                    String.Format(
                        patchExistsInDB
                                                        ? "update {0} set {5} = {6}, {7} = {8} where {1} = {2} and {3} = {4}"
                                                        : "insert into {0}({1}, {3}, {5}, {7}) values({2}, {4}, {6}, {8})"
                        ,
                        transaction.EscapeName(this.context.PatchesTable),
                        transaction.EscapeName("VERSION"),
                        transaction.MarkParam("pversion"),
                        transaction.EscapeName("NAME"),
                        transaction.MarkParam("pname"),
                        transaction.EscapeName("ROLLBACK_DATA"),
                        transaction.MarkParam("prollbackdata"),
                        transaction.EscapeName("STATUS"),
                        transaction.MarkParam("pstatus")
                        ),
                    new Dictionary <string, object>
                {
                    { "pversion", patchId.version },
                    { "pname", patchId.name },
                    { "prollbackdata", rollbackData.ToString() },
                    { "pstatus", STATUS_INSTALLED },
                }
                    );
                if (affectedRows != 1)
                {
                    throw new ApplicationException("Unable to install patch; are you trying to run two patchers simultaneously?");
                }
                transaction.Commit();
            }
        }
Exemple #13
0
 public Stream loadPatch(PatchId patchId)
 {
     return(PatchesLoader.loadPatch(patchId));
 }
Exemple #14
0
 public Stream loadPatch(PatchId patchId)
 {
     return(this.updateParams.loadPatch(patchId));
 }
Exemple #15
0
 public Stream loadPatch(PatchId patchId)
 {
     return this.updateParams.loadPatch(patchId);
 }
Exemple #16
0
        private void InstallPatch(PatchId patchId)
        {
            AbstractPatch patch = AbstractPatch.LoadById(patchId, this.context);

            if(!patch.DoesSupportEnvironment(this.context.EnvironmentName))
            {
                this.context.console.Report(" (skipping because of unsupported environment) ");
                return;
            }

            using(var transaction = this.context.CreateTransaction())
            {

                bool patchExistsInDB;
                XDocument rollbackData;

                var patchDBData = transaction.ExecuteReader(
                    string.Format(
                        "select {1} from {0} where {2} = {3} and {4} = {5}",
                        transaction.EscapeName(this.context.PatchesTable),
                        transaction.EscapeName("STATUS"),
                        transaction.EscapeName("VERSION"),
                        transaction.MarkParam("pversion"),
                        transaction.EscapeName("NAME"),
                        transaction.MarkParam("pname")
                    ),
                    new Dictionary<string, object>
                    {
                        { "pversion", patchId.version },
                        { "pname", patchId.name },
                    }
                ).ToList();

                if(patch is PersistentPatch)
                {
                    bool reinstall;

                    if(patchDBData.Any())
                    {
                        var patchInfo = patchDBData.Single();
                        switch(patchInfo["STATUS"])
                        {
                            case STATUS_INSTALLED:
                                throw new ApplicationException("Patch is already installed");
                            case STATUS_INSTALLING:
                                reinstall = true;
                                break;
                            default:
                                throw new ApplicationException(string.Format("Unknown status {0}", patchInfo["STATUS"]));
                        }
                    } else
                    {
                        reinstall = false;
                    }

                    if(reinstall)
                    {
                        patchExistsInDB = true;
                    }

                    throw new NotImplementedException("Persistent patch installation is not implemented yet");
                } else
                {
                    if(patchDBData.Any())
                    {
                        throw new ApplicationException("Patch is already installed");
                    }

                    patchExistsInDB = false;
                    rollbackData = patch.Apply(transaction);
                }

                //System.Threading.Thread.Sleep(1000);
                int affectedRows = transaction.ExecuteNonQuery(
                    String.Format(
                        patchExistsInDB
                            ? "update {0} set {5} = {6}, {7} = {8} where {1} = {2} and {3} = {4}"
                            : "insert into {0}({1}, {3}, {5}, {7}) values({2}, {4}, {6}, {8})"
                        ,
                        transaction.EscapeName(this.context.PatchesTable),
                        transaction.EscapeName("VERSION"),
                        transaction.MarkParam("pversion"),
                        transaction.EscapeName("NAME"),
                        transaction.MarkParam("pname"),
                        transaction.EscapeName("ROLLBACK_DATA"),
                        transaction.MarkParam("prollbackdata"),
                        transaction.EscapeName("STATUS"),
                        transaction.MarkParam("pstatus")
                    ),
                    new Dictionary<string, object>
                    {
                        { "pversion", patchId.version },
                        { "pname", patchId.name },
                        { "prollbackdata", rollbackData.ToString() },
                        { "pstatus", STATUS_INSTALLED },
                    }
                );
                if(affectedRows != 1)
                {
                    throw new ApplicationException("Unable to install patch; are you trying to run two patchers simultaneously?");
                }
                transaction.Commit();
            }
        }
Exemple #17
0
 public Stream loadPatch(PatchId patchId)
 {
     return(configuration.loadPatch(patchId));
 }
Exemple #18
0
        private static AbstractPatch _LoadById(PatchId id, Context context)
        {
            XDocument data;
            using(Stream xmlStream = context.loadPatch(id))
            {
                using(XmlReader reader = XmlReader.Create(xmlStream))
                {
                    data = XDocument.Load(reader);
                }
            }
            Checker.Check(data);
            XElement version = data.Root.Element("version");
            string number = version.Element("number").Value;
            string author = version.Element("author").Value;
            if((number != id.version.ToString()) || (author != id.name))
            {
                throw new ApplicationException(string.Format("Versions mismatch on patch #{0} from {1} (got #{2} from {3})", id.version, id.name, number, author));
            }

            HashSet<string> restrictToEnvironments;
            if(data.Root.Element("restrictToEnvironments") != null)
            {
                restrictToEnvironments = new HashSet<string>(from elem in data.Root.Element("restrictToEnvironments").Elements() select elem.Value);
            } else
            {
                restrictToEnvironments = new HashSet<string>();
            }

            XElement commandSet;
            bool isStrictCommandSet;
            {
                XElement strictCommandSet = data.Root.Element("strictCommandSet");
                XElement looseCommandSet = data.Root.Element("looseCommandSet");
                if (strictCommandSet != null && looseCommandSet == null)
                {
                    commandSet = strictCommandSet;
                    isStrictCommandSet = true;
                } else if (strictCommandSet == null && looseCommandSet != null)
                {
                    commandSet = looseCommandSet;
                    isStrictCommandSet = false;
                } else if (strictCommandSet != null && looseCommandSet != null)
                {
                    throw new ApplicationException("Malformed XML: both strictCommandSet and looseCommandSet found");
                } else
                {
                    throw new ApplicationException("Malformed XML: no CommandSet found");
                }
            }

            var commands = (from elem in commandSet.Elements() select AbstractCommand.Create(elem)).ToArray();

            if(isStrictCommandSet)
            {
                var isPersistent = commands.OfType<AbstractPersistentCommand>().Any();
                if (isPersistent)
                {
                    if (commands.Length != 1)
                    {
                        throw new ApplicationException("More than one persistent command");
                    }
                    if(context.DbDriver.IsDDLTransactional)
                    {
                        return new AtomicPatch(commands, true, restrictToEnvironments, context);
                    } else
                    {
                        return new PersistentPatch(commands[0], restrictToEnvironments, context);
                    }
                }
                else
                {
                    return new AtomicPatch(commands, true, restrictToEnvironments, context);
                }
            } else
            {
                return new AtomicPatch(commands, false, restrictToEnvironments, context);
            }
        }