Ejemplo n.º 1
0
            /// <summary>
            /// Create a legal MSI identifier from a resource name and an index.
            /// </summary>
            /// <param name="name">The name of the resource for which an identifier should be created.</param>
            /// <param name="index">An index to append to the end of the identifier to make it unique.</param>
            /// <returns>A legal MSI identifier.</returns>
            public string CreateIdentifier(string name, int index)
            {
                if (null == name)
                {
                    throw new ArgumentNullException("name");
                }

                StringBuilder identifier = new StringBuilder();

                // Convert the name to a standard MSI identifier
                identifier.Append(Common.GetIdentifierFromName(name));

                // no legal identifier characters were found, use the base id instead
                if (0 == identifier.Length)
                {
                    identifier.Append(this.baseName);
                }

                // truncate the identifier if it's too long (reserve 3 characters for up to 99 collisions)
                int adjustedMaxLength = this.MaxIdentifierLength - (index != 0 ? 3 : 0);

                if (adjustedMaxLength < identifier.Length)
                {
                    identifier.Length = adjustedMaxLength;
                }

                // if the index is not zero, then append it to the identifier name
                if (0 != index)
                {
                    identifier.AppendFormat("_{0}", index);
                }

                return(identifier.ToString());
            }
Ejemplo n.º 2
0
 /// <summary>
 /// Return an identifier based on passed file/directory name
 /// </summary>
 /// <param name="name">File/directory name to generate identifer from</param>
 /// <returns>A version of the name that is a legal identifier.</returns>
 public static string GetIdentifierFromName(string name)
 {
     return(Common.GetIdentifierFromName(name));
 }