public static string GenerateIdForRegKey(WixBackendCompiler backend, PackageItem item, int root, string path, string name)
        {
            string stringRoot;

            switch (root)
            {
            case -1:
                stringRoot = "HKMU";
                break;

            case 0:
                stringRoot = "HKCR";
                break;

            case 1:
                stringRoot = "HKCU";
                break;

            case 2:
                stringRoot = "HKLM";
                break;

            case 3:
                stringRoot = "HKU";
                break;

            default:
                throw new ArgumentException("root");
            }

            path = String.Concat(stringRoot, "\\", path, name ?? String.Empty);
            path = GenerateSafeMsiIdFromPath(path);
            return(GenerateId(backend, item, path, path));
        }
        public static string GenerateMsiId(WixBackendCompiler backend, PackageItem item, string prefix, params string[] args)
        {
            string id = item.Id;

            if (String.IsNullOrEmpty(id))
            {
                if (args.Length == 0)
                {
                    // TODO: display error message.
                    return(null);
                }

                string stringData = String.Join("|", args);
                byte[] data       = Encoding.Unicode.GetBytes(stringData);

                // hash the data
                byte[] hash;
                using (SHA1 sha1 = new SHA1CryptoServiceProvider())
                {
                    hash = sha1.ComputeHash(data);
                }

                // build up the identifier
                int           prefixLength = String.IsNullOrEmpty(prefix) ? 0 : prefix.Length + 1;
                StringBuilder identifier   = new StringBuilder(prefixLength + hash.Length * 2, prefixLength + hash.Length * 2);

                if (!String.IsNullOrEmpty(prefix))
                {
                    identifier.Append(prefix);
                    identifier.Append(WixBackendCompilerServices.MsiIdSeparator);
                }

                for (int i = 0; i < hash.Length; i++)
                {
                    identifier.Append(hash[i].ToString("X2", CultureInfo.InvariantCulture.NumberFormat));
                }

                id = identifier.ToString();
            }

            if (!item.System)
            {
                if (backend.Architecture != PackageArchitecture.Neutral)
                {
                    id = String.Concat(id, WixBackendCompilerServices.MsiIdSeparator, backend.Architecture.ToString().ToLowerInvariant());
                }

                if (backend.Languages != null && backend.Languages.Length > 0)
                {
                    id = String.Concat(id, WixBackendCompilerServices.MsiIdSeparator, backend.Languages[0].ThreeLetterWindowsLanguageName.ToLowerInvariant());
                }
            }

            return(id);
        }
        public static string GenerateMsiIdForFileReference(WixBackendCompiler backend, IFileReference fs)
        {
            string id = null;

            WixItem item = backend.WixItems[fs.GetPackageItem()];

            if (item.Item is Lexicon.File)
            {
                id = String.Concat("[#", item.MsiId, "]");
            }
            else if (item.Item is Lexicon.Msi.Property)
            {
                id = String.Concat("[", item.MsiId, "]");
            }
            else if (item.Item is Lexicon.Msi.FileSearch)
            {
                id = String.Concat("[", item.MsiId, "]");
            }

            return(id);
        }
Exemple #4
0
 public WixFile(WixBackendCompiler backend, File file) :
     base(backend, file)
 {
 }
 public WixFolder(WixBackendCompiler backend, Folder folder) :
     base(backend, folder)
 {
 }
Exemple #6
0
 public WixFolderReference(WixBackendCompiler backend, Folder folderRef) :
     base(backend, folderRef)
 {
 }
 public WixNativeImage(WixBackendCompiler backend, NgenPackageItem ngen) :
     base(backend, ngen)
 {
 }
 public WixFileSearch(WixBackendCompiler backend, FileSearch fileSearch) :
     base(backend, fileSearch)
 {
 }
 public WixGroup(WixBackendCompiler backend, Group group) :
     base(backend, group)
 {
     this.ContainedWixItems = new List <WixItem>();
 }
        public static string GenerateId(WixBackendCompiler backend, PackageItem item, string prefix, params string[] args)
        {
            // System items do not get suffixes. All other items do unless we're are building a completely
            // neutral output.
            string suffix = String.Empty;

            if (item != null && !item.System && (backend.Architecture != PackageArchitecture.Neutral || backend.Languages != null && backend.Languages.Length > 0))
            {
                suffix = WixBackendCompilerServices.MsiIdSeparator;

                if (backend.Architecture != PackageArchitecture.Neutral)
                {
                    suffix = String.Concat(suffix, backend.Architecture.ToString().ToLowerInvariant());
                }

                if (backend.Languages != null && backend.Languages.Length > 0)
                {
                    suffix = String.Concat(suffix, backend.Languages[0].ThreeLetterWindowsLanguageName.ToLowerInvariant());
                }
            }

            // It the item has an identifier, we'll use that. Otherwise, we'll to generate an identity.
            string id = item == null ? String.Empty : item.Id;

            if (String.IsNullOrEmpty(id))
            {
                if (args.Length == 0)
                {
                    // TODO: display error message.
                    return(null);
                }

                // Generate a hash of the arguments and add the result to the suffix. We'll base64
                // encode the hash since that squishes the data down pretty well and we only need
                // to trim off some equal signs and change plus signs to dots to make it a valid MSI
                // identifier.
                byte[] data = Encoding.Unicode.GetBytes(String.Join("|", args));

                // Murmur hash creates very small hashes but is not quite unqiue enough to prevent collisions
                // in large installations where file paths may differ by only a single character. So, back to
                // SHA1 hashes to be safe.
                //uint murmur = MurmurHash3.Hash(data);
                byte[] hash; // BitConverter.GetBytes(murmur)
                using (SHA1 sha1 = new SHA1CryptoServiceProvider())
                {
                    hash = sha1.ComputeHash(data);
                }

                string stringHash = Convert.ToBase64String(hash);
                stringHash = stringHash.TrimEnd(WixBackendCompilerServices.TrimBase64).Replace('+', '.').Replace('/', '_');

                suffix = String.Concat(WixBackendCompilerServices.MsiIdSeparator, stringHash, suffix);

                // If the prefix is too long, take only the first and last half (hopefully nothing useful
                // was in the middle).
                if (!String.IsNullOrEmpty(prefix))
                {
                    int maxLength = WixBackendCompilerServices.MaxMsiIdLength - suffix.Length;
                    if (prefix.Length > maxLength)
                    {
                        int half  = maxLength / 2;
                        int extra = maxLength % 2 == 0 ? 1 : 0;
                        prefix = String.Concat(prefix.Substring(0, half), WixBackendCompilerServices.MsiIdSeparator, prefix.Substring(prefix.Length - half + extra));
                        Debug.Assert(prefix.Length == maxLength);
                    }

                    id = GenerateSafeMsiId(prefix);
                }
            }

            return(String.Concat(id, suffix));
        }
 public WixReference(WixBackendCompiler backend, PackageItem item) :
     base(backend, item)
 {
 }
Exemple #12
0
 public WixProperty(WixBackendCompiler backend, Property property) :
     base(backend, property)
 {
 }
Exemple #13
0
 public WixItem(WixBackendCompiler backend, PackageItem item)
 {
     this.Backend = backend;
     this.Item    = item;
 }
 public WixClassId(WixBackendCompiler backend, OutprocServer outproc) :
     base(backend, outproc)
 {
 }
 public WixClassId(WixBackendCompiler backend, InprocServer inproc) :
     base(backend, inproc)
 {
     this.inproc = true;
 }