aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/App.xaml
blob: 5765971343fad936db173d752f8ee860d526a21d (plain)
1
2
3
4
5
6
7
8
9
10
11
<Application x:Class="Tango.PPC.Browser.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="pack://application:,,,/Tango.PPC.Common;component/Resources/Merged.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>
ame.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Tango.Core.Components;

namespace Tango.AdvancedInstaller
{
    public class InstallerBuilder
    {
        private const string ADVANCED_INSTALLER_BASE_FOLDER = @"C:\Program Files (x86)\Caphyon";

        public String AdvancedInstallerPath { get; set; }

        public String ProjectFile { get; private set; }

        private InstallerBuilder()
        {
            double latestVersion = 0.0;

            //Extract the latest advanced installer version...
            foreach (var folder in Directory.GetDirectories(ADVANCED_INSTALLER_BASE_FOLDER))
            {
                try
                {
                    var versionString = Regex.Match(Path.GetFileName(folder), @"\d+\.*\d+").Value;
                    double version = double.Parse(versionString);
                    if (version > latestVersion)
                    {
                        latestVersion = version;
                    }
                }
                catch { }
            }

            AdvancedInstallerPath = $@"{ADVANCED_INSTALLER_BASE_FOLDER}\Advanced Installer {latestVersion}\bin\x86\AdvancedInstaller.com";
        }

        public InstallerBuilder(String projectFile) : this()
        {
            ProjectFile = projectFile;
        }

        public InstallerBuilder(String advancedInstallerPath, String projectFile) : this(projectFile)
        {
            AdvancedInstallerPath = advancedInstallerPath;
        }

        public Task<String> GetProperty(ProjectProperty property)
        {
            return Task.Factory.StartNew<String>(() =>
            {
                CmdCommand command = new CmdCommand(AdvancedInstallerPath, $"/edit \"{ProjectFile}\" /GetProperty {property.ToString()}");
                var result = command.Run().Result;
                return result.StandardOutput.Replace("\r", "").Replace("\n", "");
            });
        }

        public Task SetProperty(ProjectProperty property, String value)
        {
            return Task.Factory.StartNew(() =>
            {
                CmdCommand command = new CmdCommand(AdvancedInstallerPath, $"/edit \"{ProjectFile}\" /SetProperty {property.ToString()}=\"{value}\"");
                command.Run().Wait();

                String propValue = GetProperty(property).Result;

                if (propValue != value)
                {
                    throw new ArgumentException("The property set command had succeeded but the property value validation has failed.");
                }
            });
        }

        public Task Build(String productVersion, String outputFile)
        {
            return Task.Factory.StartNew(() =>
            {
                CmdCommand command = new CmdCommand(AdvancedInstallerPath, $"/edit \"{ProjectFile}\" /SetVersion {productVersion}");
                command.Run().Wait();

                command = new CmdCommand(AdvancedInstallerPath, $"/edit \"{ProjectFile}\" /SetPackageName \"{outputFile}\" -buildname DefaultBuild");
                command.Run().Wait();

                command = new CmdCommand(AdvancedInstallerPath, $"/rebuild \"{ProjectFile}\"");
                command.Timeout = TimeSpan.FromMinutes(2);
                command.Run().Wait();
            });
        }

        public Task Uninstall()
        {
            return Task.Factory.StartNew(() =>
            {
                String productName = GetProperty(ProjectProperty.ProductName).Result;
                CmdCommand command = new CmdCommand("wmic", $"product where name=\"{productName}\" call uninstall /nointeractive");
                command.ExitStrategy = CmdCommand.ExitStrategies.StandardOutput;
                command.Run().Wait();
            });
        }

        public Task<bool> IsInstalled()
        {
            return Task.Factory.StartNew<bool>(() =>
            {
                String productName = GetProperty(ProjectProperty.ProductName).Result;
                CmdCommand command = new CmdCommand("wmic", $"product get name");
                command.ExitStrategy = CmdCommand.ExitStrategies.StandardOutput;
                var result = command.Run().Result;

                List<String> list = result.StandardOutput.Split(new[] { '\r', '\n' }).ToList();

                bool found = list.Any(x => x.Trim() == productName);

                return found;
            });
        }
    }
}