public void TestGetFilesSourceAppPath()
 {
     ControlLicense license = new ControlLicense();
     license.LicenseFile = @"#APPPATH\license.txt";
     string supportdir = Environment.CurrentDirectory;
     ResourceFileCollection resources = license.GetResources(supportdir);
     Assert.AreEqual(1, resources.Count);
     Assert.AreEqual(Path.Combine(Environment.CurrentDirectory, "license.txt"), resources[0].path);
     Assert.AreEqual("RES_LICENSE", resources[0].id);
 }
 public void TestControlLicenseResources()
 {
     InstallerLinkerArguments args = new InstallerLinkerArguments();
     string licenseFile = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".txt");
     try
     {
         Uri uri = new Uri(Assembly.GetExecutingAssembly().CodeBase);
         string binPath = Path.GetDirectoryName(HttpUtility.UrlDecode(uri.AbsolutePath));
         ConfigFile configFile = new ConfigFile();
         SetupConfiguration setupConfiguration = new SetupConfiguration();
         configFile.Children.Add(setupConfiguration);
         ControlLicense license = new ControlLicense();
         license.LicenseFile = licenseFile;
         Console.WriteLine("Writing '{0}'", license.LicenseFile);
         File.WriteAllText(license.LicenseFile, "Lorem ipsum");
         setupConfiguration.Children.Add(license);
         args.config = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".xml");
         Console.WriteLine("Writing '{0}'", args.config);
         configFile.SaveAs(args.config);
         args.output = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".exe");
         Console.WriteLine("Linking '{0}'", args.output);
         args.template = dotNetInstallerExeUtils.Executable;
         InstallerLib.InstallerLinker.CreateInstaller(args);
         // check that the linker generated output
         Assert.IsTrue(File.Exists(args.output));
         Assert.IsTrue(new FileInfo(args.output).Length > 0);
         using (ResourceInfo ri = new ResourceInfo())
         {
             ri.Load(args.output);
             Assert.IsTrue(ri.Resources.ContainsKey(new ResourceId("CUSTOM")));
             List<Resource> custom = ri.Resources[new ResourceId("CUSTOM")];
             Assert.AreEqual("RES_BANNER", custom[0].Name.Name);
             Assert.AreEqual("RES_CONFIGURATION", custom[1].Name.ToString());
             Assert.AreEqual("RES_LICENSE", custom[2].Name.ToString());
         }
     }
     finally
     {
         if (File.Exists(licenseFile))
             File.Delete(licenseFile);
         if (File.Exists(args.config))
             File.Delete(args.config);
         if (File.Exists(args.output))
             File.Delete(args.output);
     }
 }
        public static Control CreateFromXml(XmlElement element)
        {
            string      xmltype = element.Attributes["type"].InnerText;
            Control     control = null;
            ControlType type    = (ControlType)Enum.Parse(typeof(ControlType), xmltype);

            switch (type)
            {
            case ControlType.label:
                control = new ControlLabel();
                break;

            case ControlType.checkbox:
                control = new ControlCheckBox();
                break;

            case ControlType.edit:
                control = new ControlEdit();
                break;

            case ControlType.browse:
                control = new ControlBrowse();
                break;

            case ControlType.license:
                control = new ControlLicense();
                break;

            case ControlType.hyperlink:
                control = new ControlHyperlink();
                break;

            case ControlType.image:
                control = new ControlImage();
                break;

            default:
                throw new Exception(string.Format("Invalid type: {0}", xmltype));
            }
            control.FromXml(element);
            return(control);
        }
Exemple #4
0
 public static Control CreateFromXml(XmlElement element)
 {
     string xmltype = element.Attributes["type"].InnerText;
     Control control = null;
     ControlType type = (ControlType)Enum.Parse(typeof(ControlType), xmltype);
     switch (type)
     {
         case ControlType.label:
             control = new ControlLabel();
             break;
         case ControlType.checkbox:
             control = new ControlCheckBox();
             break;
         case ControlType.edit:
             control = new ControlEdit();
             break;
         case ControlType.browse:
             control = new ControlBrowse();
             break;
         case ControlType.license:
             control = new ControlLicense();
             break;
         case ControlType.hyperlink:
             control = new ControlHyperlink();
             break;
         case ControlType.image:
             control = new ControlImage();
             break;
         default:
             throw new Exception(string.Format("Invalid type: {0}", xmltype));
     }
     control.FromXml(element);
     return control;
 }
        public void TestUserControlLicense()
        {
            Console.WriteLine("TestUserControlLicense");

            string configFilename = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".xml");
            // a configuration with a license agreement control
            ConfigFile configFile = new ConfigFile();
            SetupConfiguration setupConfiguration = new SetupConfiguration();
            configFile.Children.Add(setupConfiguration);
            ControlLicense license = new ControlLicense();
            license.Accepted = true;
            license.ResourceId = "MY_RES_LICENSE";
            license.LicenseFile = configFilename;
            setupConfiguration.Children.Add(license);
            ComponentCmd cmd = new ComponentCmd();
            cmd.command = "cmd.exe /C exit /b [MY_RES_LICENSE]";
            cmd.required_install = true;
            setupConfiguration.Children.Add(cmd);
            // save config file
            Console.WriteLine("Writing '{0}'", configFilename);
            configFile.SaveAs(configFilename);
            // create a setup with the license file
            InstallerLinkerArguments args = new InstallerLinkerArguments();
            args.config = configFilename;
            args.output = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".exe");
            args.template = dotNetInstallerExeUtils.Executable;
            Console.WriteLine("Linking '{0}'", args.output);
            InstallerLinkerExeUtils.CreateInstaller(args);
            Assert.IsTrue(File.Exists(args.output));
            // execute dotNetInstaller
            Assert.AreEqual(1, dotNetInstallerExeUtils.Run(args.output, "/q"));
            File.Delete(args.config);
            File.Delete(args.output);
        }