Example #1
0
 /// <summary>
 /// Creates an immutable ClientVersion object or retrieves an existing one from the internal cache.
 /// </summary>
 /// <param name="versionstruct">A ClientVersionStruct representing the version of the ClientVersion object desired.</param>
 /// <returns>a shared ClientVersion object</returns>
 public static ClientVersion Instantiate(ClientVersionStruct versionstruct)
 {
     if (!(m_byVal ?? (m_byVal = new Dictionary <ClientVersionStruct, ClientVersion>())).ContainsKey(versionstruct))
     {
         m_byVal[versionstruct] = Instantiate(ToString(versionstruct));
     }
     return(m_byVal[versionstruct]);
 }
Example #2
0
 /// <summary>
 /// Formats the client version to a string.
 /// </summary>
 /// <param name="Version">The version representing the desired version string.</param>
 /// <returns>A string in the standard version format</returns>
 public static string ToString(ClientVersionStruct Version)
 {
     if (Version < v5_0_7_0)
     {
         if (Version.Revision <= 0)
         {
             return(string.Format("{0}.{1}.{2}", Version.Major, Version.Minor, Version.Build));
         }
         else
         {
             return(string.Format("{0}.{1}.{2}{3}", Version.Major, Version.Minor, Version.Build, (char)((ushort)'a' + Version.Revision - 1)));
         }
     }
     return(string.Format("{0}.{1}.{2}.{3}", Version.Major, Version.Minor, Version.Build, Version.Revision));
 }
Example #3
0
        /// <summary>
        /// Parses the supplied sting to a ClientVersionStruct, if possible.
        /// </summary>
        /// <param name="VersionString">A string in the standard version format</param>
        /// <returns>A ClientVersionStruct representing the best interpretation of the VersionString, Zero's will appear in sections of parse failure.</returns>
        public static ClientVersionStruct Parse(string VersionString)
        {
            ClientVersionStruct ver = new ClientVersionStruct();

            string[] parts = VersionString.Split('.');
            byte     n;

            if (parts.Length >= 1 && byte.TryParse(parts[0], out n))
            {
                ver.Major = n;
                if (parts.Length >= 2 && byte.TryParse(parts[1], out n))
                {
                    ver.Minor = n;

                    if (parts.Length >= 3)
                    {     // The third section is tricky, version such as 2.0.0g1 may be possible in versions below 5.0.7.0
                        if (byte.TryParse(parts[2], out n))
                        { // easy
                            ver.Build = n;
                            if (parts.Length >= 4 && byte.TryParse(parts[3], out n))
                            {
                                ver.Revision = n;
                            }
                        }
                        else
                        {   // not as easy
                            // Find non-numeric character in string
                            int i = 0;
                            while (i < parts[2].Length && char.IsDigit(parts[2][i]))
                            {
                                i++;
                            }
                            if (i > 0 && byte.TryParse(parts[2].Substring(0, i), out n)) // extract the number
                            {
                                ver.Build = n;
                                if (char.IsLetter(parts[2][i]))  // extract the letter
                                {
                                    ver.Revision = (byte)(ASCIIEncoding.ASCII.GetBytes(parts[2].Substring(i, 1))[0] - (byte)'a' + 1);
                                    // Ignoring sub revision which occurs in two client versions. Example: 2.0.0e1, 4.0.4b2
                                }
                            }
                        }
                    }
                }
            }
            return(ver);
        }
Example #4
0
 /// <summary>
 /// Converts the client version to a unique integer hash.
 /// </summary>
 /// <param name="clientversion"></param>
 /// <returns></returns>
 public static uint ToUint(ClientVersionStruct clientversion)
 {
     return((uint)(clientversion.Major << 24) + (uint)(clientversion.Minor << 16) + (uint)(clientversion.Build << 8) + clientversion.Revision);
 }
Example #5
0
 private ClientVersion(string versionstring)
 {
     Version = Parse(versionstring);
     UIntVal = ToUint(Version);
 }