Beispiel #1
0
        private int VersionUpToDate()
        {
            try
            {
                var currentParts   = CurrentVersion.Split(' ');
                var availableParts = AvailableVersion.Split(' ');
                //Version ID's are EXACTLY the same (eg. 0.8 vs 0.8)
                if (CurrentVersion == AvailableVersion)
                {
                    return(0);
                }
                var availableNum = Convert.ToDouble(availableParts[0], System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
                var currentNum   = Convert.ToDouble(currentParts[0], System.Globalization.CultureInfo.InvariantCulture.NumberFormat);

                //Cases where the a pre-release version is used (eg. 0.85 pre vs 0.8)
                if (availableNum < currentNum)
                {
                    return(1);
                }

                //Cases where version number is the same, but suffix is different (eg. 2.0 a1 vs 2.0 a2)
                if (availableNum == currentNum && currentParts.Length > 1 && availableParts.Length > 1)
                {
                    return(String.CompareOrdinal(currentParts[1], availableParts[1]));
                }
                //Cases where either an old release is used (eg 0.7 vs 0.8)
                //Or Version numbers don't quite match, (like 0.8 beta 1 vs 0.8)
                return(-1);
            }
            // Show the new version available if anything goes wrong, just to be safe.
            catch (Exception)
            {
                return(-1);
            }
        }
        public void SetVersion()
        {
            var content = System.IO.File.ReadAllText(FileProjectPath);

            var matches = System.Text.RegularExpressions.Regex.Matches(content, @"<Version>([^""]*)</Version>");

            if (matches.Any())
            {
                CurrentVersion = matches[0].Groups[1].Value;
                var versionSplit = CurrentVersion.Split('.');

                var major  = 1;
                var middle = 0;
                var minor  = 0;

                if (versionSplit.Length == 3)
                {
                    int.TryParse(versionSplit[0], out major);
                    int.TryParse(versionSplit[1], out middle);
                    int.TryParse(versionSplit[2], out minor);

                    minor++;
                }

                NewVersion = $"{major}.{middle}.{minor}";

                var newContentCsProj = content.Replace($"<Version>{CurrentVersion}</Version>", $"<Version>{NewVersion}</Version>");

                File.WriteAllText(FileProjectPath, newContentCsProj);
            }
        }
Beispiel #3
0
        public bool isNewVersionAvailable()
        {
            CheckForNewVersion();
            var newV     = NewestVersion.Split('.');
            var currentV = CurrentVersion.Split('.');

            for (int i = 0; i < newV.Length; i++)
            {
                int newVersion     = int.Parse(newV[i]);
                int currentVersion = int.Parse(currentV[i]);
                if (newVersion > currentVersion)
                {
                    return(true);
                }
                else if (newVersion < currentVersion)
                {
                    return(false);
                }
            }
            return(false);
        }