Пример #1
0
        /// <summary>
        /// Enables source resiliency for the installer.
        /// Creates a symbolic link/hard link or makes a copy of the original MSI package in the specified location and points SOURCELIST to it.
        /// </summary>
        /// <param name="project">The project.</param>
        /// <param name="resilientSourceDir">Resilient source directory.</param>
        public static void EnableResilientPackage(this Project project, string resilientSourceDir)
        {
            project.AddActions(
                new SetPropertyAction(new Id($"WixSharp_SetProperty_{WIXSHARP_RESILIENT_SOURCE_DIR}"),
                                      WIXSHARP_RESILIENT_SOURCE_DIR, $"[{resilientSourceDir}]",
                                      Return.check,
                                      When.Before, Step.InstallInitialize,
                                      $"{WIXSHARP_RESILIENT_SOURCE_DIR}=\"\""),

                new SetPropertyAction(new Id("WixSharp_SetProperty_SOURCELIST"),
                                      "SOURCELIST", $"[{WIXSHARP_RESILIENT_SOURCE_DIR}]",
                                      Return.check,
                                      When.Before, Step.PublishProduct,
                                      Condition.NOT_Installed)
                );

            var assembly = typeof(ResilientPackage).Assembly.Location;

            project.AddActions(
                new ManagedAction(new Id(nameof(WixSharp_SetPackageName_Action)),
                                  WixSharp_SetPackageName_Action, assembly,
                                  Return.ignore,
                                  When.Before, Step.InstallInitialize,
                                  Condition.BeingRemoved),

                new ElevatedManagedAction(new Id(nameof(WixSharp_RemoveResilientPackage_Action)),
                                          WixSharp_RemoveResilientPackage_Action, assembly,
                                          Return.ignore,
                                          When.Before, Step.RemoveFiles,
                                          Condition.BeingRemoved)
            {
                UsesProperties = $"{WIXSHARP_RESILIENT_SOURCE_DIR},{WIXSHARP_PACKAGENAME}"
            },

                new ElevatedManagedAction(new Id(nameof(WixSharp_CreateResilientPackage_Action)),
                                          WixSharp_CreateResilientPackage_Action, assembly,
                                          Return.ignore,
                                          When.Before, Step.InstallFinalize,
                                          Condition.NOT_Installed | "REINSTALL<>\"\"")
            {
                UsesProperties = $"UserSID,OriginalDatabase,ALLUSERS,{WIXSHARP_RESILIENT_SOURCE_DIR}"
            }
                );
        }
Пример #2
0
        internal void AddMembersTo(Project project)
        {
            var properties = new List <Property>();
            var actions    = new List <Action>();

            foreach (PropertyInfo prop in this.GetType().GetProperties())
            {
                object value = prop.GetValue(this, new object[0]);

                if (value != null)
                {
                    var attr = (ArpPropertyAttribute)prop.GetCustomAttributes(typeof(ArpPropertyAttribute), false).FirstOrDefault();
                    if (attr != null)
                    {
                        bool propertyExists = project.Properties.Any(a => a.Name == attr.Name);
                        bool actionExists   = project.Actions.OfType <SetPropertyAction>().Any(a => a.PropName == attr.Name);

                        if (attr.Name == "ARPPRODUCTICON")
                        {
                            if (!propertyExists)
                            {
                                properties.Add(new Property(attr.Name, "app_icon.ico")
                                {
                                    AttributesDefinition = "Icon:Id=app_icon.ico;Icon:SourceFile=" + value
                                });
                            }
                        }
                        else
                        {
                            if (attr.SetAsAction)
                            {
                                if (!actionExists)
                                {
                                    actions.Add(new SetPropertyAction(new Id("Set_" + attr.Name), attr.Name, value.ToString())
                                    {
                                        Step = Step.CostFinalize
                                    });
                                }
                            }
                            else
                            {
                                if (!propertyExists)
                                {
                                    properties.Add(new Property(attr.Name, value.ToString()));
                                }
                            }
                        }
                    }
                }
            }

            project.AddProperties(properties.ToArray());
            project.AddActions(actions.ToArray());
        }