예제 #1
0
    private void InsertCommit(VersionNode version)
    {
        // find commit hash for existing version
        string hash = VersionToCommit[version.Parent];
        // create branch
        var branchname = GetBranchName(version);

        VersionConfig.GitRepo.MakeBranch(branchname, hash);
        // if this commit is the most recent for this branch, we can just commit right on top without insertion logic
        string tophash = VersionConfig.GitRepo.BranchHash(branchname);

        if (hash == tophash)
        {
            VersionConfig.GitRepo.Checkout(branchname);
            DoCommit(version);
        }
        else
        {
            Console.WriteLine($"Needs to insert into history for this one");
            // make a branch that starts there and prepare to commit to it
            VersionConfig.GitRepo.CheckoutBranch("temp", hash);
            VersionConfig.GitRepo.MakeBranch(branchname);
            DoCommit(version);
            // insert
            Profiler.Start($"Rebasing");
            VersionConfig.GitRepo.Rebase("temp", branchname);
            VersionConfig.GitRepo.Checkout(branchname);
            VersionConfig.GitRepo.DeleteBranch("temp");
            Profiler.Stop();
            // need to rescan since commit hashes change after a rebase
            LoadCommits();
        }
    }
예제 #2
0
    private void DoCommit(VersionNode version)
    {
        Profiler.Start($"Adding commit for {version.Version}");
        // extract
        string workspace = Path.Combine(Path.GetTempPath(), "mc_version_history_workspace");

        if (Directory.Exists(workspace))
        {
            Directory.Delete(workspace, true);
        }
        Directory.CreateDirectory(workspace);
        Profiler.Run("Extracting", () =>
                     { version.Version.ExtractData(workspace, Config); });
        Profiler.Run("Translating NBT Files", () =>
                     { TranslateNbtFiles(workspace); });
        Profiler.Run($"Merging", () =>
        {
            MergeWithWorkspace(VersionConfig.GitRepo.Folder, workspace);
            Directory.Delete(workspace, true);
            Util.RemoveEmptyFolders(VersionConfig.GitRepo.Folder);
            File.WriteAllText(Path.Combine(VersionConfig.GitRepo.Folder, "version.txt"), version.Version.Name);
        });
        // commit
        Profiler.Start($"Running git commit");
        VersionConfig.GitRepo.Commit(version.Version.Name, version.Version.ReleaseTime);
        string hash = VersionConfig.GitRepo.BranchHash("HEAD");

        CommitToVersion.Add(hash, version);
        VersionToCommit.Add(version, hash);
        Profiler.Stop(); // git commit
        Profiler.Stop(); // top commit
    }
예제 #3
0
 public static int Depth(this VersionNode node)
 {
     if (!node.Children.Any())
     {
         return(1);
     }
     return(1 + node.Children.Max(x => Depth(x)));
 }
        public static TreeNode GetAllTypeNode()
        {
            TypeDatapointTypeVersionNode nodeType = new TypeDatapointTypeVersionNode();

            nodeType.Text = nodeType.KNXMainNumber + "." + nodeType.KNXSubNumber + " " + nodeType.Name;

            nodeType.Nodes.Add(VersionNode.GetTypeNode());

            return(nodeType);
        }
        public void TestSuccessor()
        {
            var first            = new VersionNode();
            var successor        = first.GetSuccessor();
            var anotherSuccessor = first.GetSuccessor();

            Assert.IsTrue(first.CompareTo(successor) < 0);
            Assert.IsTrue(first.CompareTo(anotherSuccessor) < 0);
            Assert.IsTrue(anotherSuccessor.CompareTo(successor) < 0);
        }
예제 #6
0
        public static Unit Set(string csprojPath, VersionNode node, string value)
        {
            var doc         = ProjectLoader.Load(csprojPath);
            var versionNode = NodeFinder.GetVersionNode(doc, node);

            versionNode.IfSome(x =>
            {
                x.InnerText = value;
                doc.Save(new Uri(doc.BaseURI).LocalPath);
            });

            return(Unit.Default);
        }
예제 #7
0
 private void InitialCommit(VersionNode version)
 {
     Profiler.Start("Initializing repo");
     VersionConfig.GitRepo.Init();
     if (Config.GitIgnoreContents != null)
     {
         File.WriteAllText(Path.Combine(VersionConfig.GitRepo.Folder, ".gitignore"), Config.GitIgnoreContents);
     }
     // create branch
     VersionConfig.GitRepo.CheckoutBranch(GetBranchName(version));
     Profiler.Stop();
     DoCommit(version);
 }
예제 #8
0
            static VersionNode GetNode(byte[] data, int startPosition, out int nodeLength)
            {
                nodeLength = 0;

                VersionNode node = new VersionNode
                {
                    cbNode = BitConverter.ToUInt16(data, startPosition + nodeLength),
                    cbData = BitConverter.ToUInt16(data, startPosition + nodeLength + 2)
                };

                nodeLength += 4;

                MemoryStream nameMs = new MemoryStream();

                while (data[startPosition + nodeLength] > 0)
                {
                    nameMs.WriteByte(data[startPosition + nodeLength]);
                    nodeLength++;
                }

                node.szName = Encoding.ASCII.GetString(nameMs.ToArray());
                nodeLength++;

                if (nodeLength % 4 > 0)
                {
                    nodeLength += 4 - nodeLength % 4;
                }

                node.rgbData = new byte[node.cbData];
                Array.Copy(data, startPosition + nodeLength, node.rgbData, 0, node.cbData);
                nodeLength += node.cbData;
                if (nodeLength % 4 > 0)
                {
                    nodeLength += 4 - nodeLength % 4;
                }

                List <VersionNode> children = new List <VersionNode>();

                while (nodeLength < node.cbNode)
                {
                    children.Add(GetNode(data, startPosition + nodeLength, out int childLength));
                    nodeLength += childLength;
                }

                if (children.Count > 0)
                {
                    node.children = children.ToArray();
                }

                return(node);
            }
        public void TestFromList()
        {
            VersionNode[] array = { new VersionNode(), new VersionNode(), new VersionNode(), new VersionNode(), new VersionNode() };

            VersionNode.FromList(null, array, 0);

            for (int i = 0; i < array.Length; i++)
            {
                for (int j = i + 1; j < array.Length; j++)
                {
                    Assert.Greater(array[j].CompareTo(array[i]), 0);
                }
            }
        }
예제 #10
0
            void DecodeNode(VersionNode node, string parent, string grandparent)
            {
                if (node.szName == Consts.FixedFileInfoSig)
                {
                    IntPtr infoPtr = Marshal.AllocHGlobal(node.cbData);
                    Marshal.Copy(node.rgbData, 0, infoPtr, node.cbData);
                    FixedFileInfo info = (FixedFileInfo)Marshal.PtrToStructure(infoPtr, typeof(FixedFileInfo));
                    Marshal.FreeHGlobal(infoPtr);

                    FileVersion =
                        $"{(info.dwFileVersionMS & 0xFFFF0000) >> 16}.{info.dwFileVersionMS & 0xFFFF:D2}.{(info.dwFileVersionLS & 0xFFFF0000) >> 16}.{info.dwFileVersionLS & 0xFFFF}";
                    ProductVersion =
                        $"{(info.dwProductVersionMS & 0xFFFF0000) >> 16}.{info.dwProductVersionMS & 0xFFFF:D2}.{(info.dwProductVersionLS & 0xFFFF0000) >> 16}.{info.dwProductVersionLS & 0xFFFF}";
                    FileFlags   = (VersionFileFlags)(info.dwFileFlags & info.dwFileFlagsMask);
                    FileOs      = (VersionFileOS)info.dwFileOS;
                    FileType    = (VersionFileType)info.dwFileType;
                    FileSubtype = (VersionFileSubtype)info.dwFileSubtype;
                    FileDate    = DateTime.FromFileTime(info.dwFileDateMS * 0x100000000 + info.dwFileDateLS);
                }

                if (parent == Consts.StringFileInfo)
                {
                    Dictionary <string, string> strings = new Dictionary <string, string>();
                    StringsByLanguage.Add(node.szName, strings);
                }

                if (grandparent == Consts.StringFileInfo)
                {
                    if (StringsByLanguage.TryGetValue(parent, out Dictionary <string, string> strings))
                    {
                        Encoding encoding;

                        try { encoding = Encoding.GetEncoding(Convert.ToInt32(parent.Substring(4), 16)); }
                        catch { encoding = Encoding.ASCII; }

                        strings.Add(node.szName, encoding.GetString(node.rgbData));
                    }
                }

                if (node.children == null)
                {
                    return;
                }

                foreach (VersionNode n in node.children)
                {
                    DecodeNode(n, node.szName, parent);
                }
            }
예제 #11
0
            /// <summary>
            ///     Initializes a new instance of the <see cref="T:libexeinfo.NE.Version" /> class.
            /// </summary>
            /// <param name="data">Resource data.</param>
            /// <param name="resourceName">Resource name.</param>
            public Version(byte[] data, string resourceName = null)
            {
                if (data == null || data.Length < 5)
                {
                    return;
                }

                Name = resourceName;

                StringsByLanguage = new Dictionary <string, Dictionary <string, string> >();

                VersionNode root = GetNode(data, 0, out int rootLength);

                DecodeNode(root, null, null);
            }
예제 #12
0
 private void Commit(VersionNode version)
 {
     if (VersionToCommit.ContainsKey(version))
     {
         return;
     }
     if (version.Parent == null)
     {
         Console.WriteLine($"{version.Version.Name} is the first version in the history!");
         InitialCommit(version);
     }
     else
     {
         Console.WriteLine($"Parent of {version.Version.Name} is {version.Parent.Version.Name}");
         if (!VersionToCommit.ContainsKey(version.Parent))
         {
             Console.WriteLine("Need to commit parent first");
             Commit(version.Parent);
         }
         InsertCommit(version);
     }
 }
예제 #13
0
 public static Option <XmlNode> GetVersionNode(XmlDocument document, VersionNode versionNode)
 {
     return(document.DocumentElement.SelectSingleNode(GetNodeStringMap()[versionNode]));
 }
예제 #14
0
 public static Option <string> GetVersionNodeValue(string csprojPath, VersionNode versionNode) =>
 GetReadOnlyVersionNode(csprojPath, versionNode).Select(x => x.InnerText);
예제 #15
0
 private string GetBranchName(VersionNode version) => version.ReleaseName.Replace(' ', '-');
예제 #16
0
        public static Option <XmlNode> GetReadOnlyVersionNode(string csprojPath, VersionNode versionNode)
        {
            var doc = ProjectLoader.Load(csprojPath);

            return(GetVersionNode(doc, versionNode));
        }
예제 #17
0
 public static IEnumerable <VersionNode> OrderedChildren(this VersionNode node)
 {
     return(node.Children.OrderBy(x => Depth(x)));
 }
예제 #18
0
            static VersionNode GetNode(byte[] data, int startPosition, out int nodeLength)
            {
                nodeLength = 0;

                VersionNode node = new VersionNode
                {
                    wLength      = BitConverter.ToUInt16(data, startPosition + nodeLength),
                    wValueLength = BitConverter.ToUInt16(data, startPosition + nodeLength + 2),
                    wType        = BitConverter.ToUInt16(data, startPosition + nodeLength + 4)
                };

                nodeLength += 6;

                MemoryStream nameMs = new MemoryStream();

                while (true)
                {
                    if (data[startPosition + nodeLength] == 0 && data[startPosition + nodeLength + 1] == 0)
                    {
                        break;
                    }

                    nameMs.WriteByte(data[startPosition + nodeLength]);
                    nameMs.WriteByte(data[startPosition + nodeLength + 1]);
                    nodeLength += 2;
                }

                node.szName = Encoding.Unicode.GetString(nameMs.ToArray());
                nodeLength += 2;

                if (nodeLength % 4 > 0)
                {
                    nodeLength += 4 - nodeLength % 4;
                }

                int factor = node.wType == 1 ? 2 : 1;

                node.rgbData = new byte[node.wValueLength * factor];
                Array.Copy(data, startPosition + nodeLength, node.rgbData, 0, node.rgbData.Length);
                nodeLength += node.rgbData.Length;
                if (nodeLength % 4 > 0)
                {
                    nodeLength += 4 - nodeLength % 4;
                }

                string foo = Encoding.Unicode.GetString(node.rgbData);

                List <VersionNode> children = new List <VersionNode>();

                while (nodeLength < node.wLength)
                {
                    children.Add(GetNode(data, startPosition + nodeLength, out int childLength));
                    nodeLength += childLength;
                }

                if (children.Count > 0)
                {
                    node.children = children.ToArray();
                }

                return(node);
            }