Exemplo n.º 1
0
 public BaseViewModel(string title)
 {
     InitialVariables();
     Title = title;
     ShowMessage = new DxShowMessage();
     WposContext = new WposContext();
     LogExceptions = new NlogException();
 }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="pl"></param>
        /// <param name="log">logging messages</param>
        /// <param name="xmlContentFile"></param>
        /// <param name="targetName"></param>
        /// <param name="mode"></param>
        /// <returns></returns>
        public string Compile(EnumPlatform pl, IShowMessage log, string xmlContentFile, string targetName, string mode)
        {
            string      sError       = string.Empty;
            string      targetFolder = Path.Combine(Path.GetDirectoryName(xmlContentFile), string.Format(CultureInfo.InvariantCulture, "bin\\{0}", mode));
            XmlDocument doc          = new XmlDocument();

            doc.Load(xmlContentFile);
            _root = new WixXmlRoot(doc.DocumentElement, xmlContentFile);
            _root.Preprocess(targetName, mode, log);
            sError = WixUtil.start(doc, targetFolder, pl == EnumPlatform.x64 ? "x64" : "x86", log);
            if (string.IsNullOrEmpty(sError))
            {
                string curId = _root.General.ProductId;
                doc = new XmlDocument();
                doc.Load(xmlContentFile);
                _root = new WixXmlRoot(doc.DocumentElement, xmlContentFile);
                _root.General.LastProductId = curId;
                _root.Postprocess(targetName, mode, log);
            }
            return(sError);
        }
Exemplo n.º 3
0
 public Repository(DBEngine dbEngine, IShowMessage showMessage = null)
 {
     this.dbEngine    = dbEngine;
     this.showMessage = showMessage;
     CanExecute       = TryGetDbConnection();
 }
Exemplo n.º 4
0
        public static string start(XmlDocument docPrj, string outputfolder, string targetPlatform, IShowMessage caller)
        {
            _errors = new StringBuilder();
            _caller = caller;
            try
            {
                string msiFolder = outputfolder;
                outputfolder = Path.Combine(outputfolder, "obj");
                if (!Directory.Exists(outputfolder))
                {
                    Directory.CreateDirectory(outputfolder);
                }
                doc = new XmlDocument();
                doc.LoadXml(Resource1.wixTemplate);
                _xm = new XmlNamespaceManager(doc.NameTable);
                _xm.AddNamespace("x", uri);
                XmlNode tempProd = doc.DocumentElement.SelectSingleNode("x:Product", _xm);
                XmlNode prodNode = docPrj.DocumentElement.SelectSingleNode("Product");
                _shortcuts = new ShortCutList(prodNode.SelectSingleNode("shortCuts"));
                //
                string netVer = XmlUtil.GetAttribute(prodNode, "netfrm");
                if (string.CompareOrdinal(netVer, "NETFRAMEWORK40FULL") != 0)
                {
                    XmlNode netV = tempProd.SelectSingleNode("x:PropertyRef", _xm);
                    XmlUtil.SetAttribute(netV, "Id", netV);
                }
                //
                string prodName = XmlUtil.GetAttribute(prodNode, "productName");
                string msiName  = XmlUtil.GetAttribute(prodNode, "Name");
                //
                string upgId = XmlUtil.GetAttribute(prodNode, "UpgradeCode");

                XmlUtil.SetAttribute(tempProd, "UpgradeCode", upgId);
                string lastVer = XmlUtil.GetAttribute(prodNode, "LastVersion");
                if (string.CompareOrdinal(lastVer, XmlUtil.GetAttribute(prodNode, "Version")) == 0)
                {
                    string lastId = XmlUtil.GetAttribute(prodNode, "LastId");
                    if (string.IsNullOrEmpty(lastId))
                    {
                        XmlUtil.SetAttribute(tempProd, "Id", Guid.NewGuid().ToString("D", CultureInfo.InvariantCulture));
                    }
                    else
                    {
                        XmlUtil.SetAttribute(tempProd, "Id", lastId);
                    }
                }
                else
                {
                    XmlUtil.SetAttribute(tempProd, "Id", Guid.NewGuid().ToString("D", CultureInfo.InvariantCulture));
                }
                string ver = XmlUtil.GetAttribute(prodNode, "Version");
                XmlUtil.SetAttribute(tempProd, "Name", prodName);
                XmlUtil.SetAttribute(tempProd, "Version", ver);
                passAttribute(tempProd, prodNode, "Manufacturer");
                setProperty(tempProd, "DiskPrompt", string.Format(CultureInfo.InvariantCulture, "{0} Installation [1]", prodName));
                //
                string appIconPath = XmlUtil.GetAttribute(prodNode, "ARPPRODUCTICON");
                if (!string.IsNullOrEmpty(appIconPath) && File.Exists(appIconPath))
                {
                    string  appIconId   = string.Format(CultureInfo.InvariantCulture, "app{0}.ico", Guid.NewGuid().GetHashCode().ToString("x", CultureInfo.InvariantCulture));
                    XmlNode appIconNode = tempProd.OwnerDocument.CreateElement("Icon", uri);
                    tempProd.AppendChild(appIconNode);
                    XmlUtil.SetAttribute(appIconNode, "Id", appIconId);
                    XmlUtil.SetAttribute(appIconNode, "SourceFile", appIconPath);
                    XmlNode appIconPropNode = tempProd.OwnerDocument.CreateElement("Property", uri);
                    tempProd.AppendChild(appIconPropNode);
                    XmlUtil.SetAttribute(appIconPropNode, "Id", "ARPPRODUCTICON");
                    XmlUtil.SetAttribute(appIconPropNode, "Value", appIconId);
                }
                //
                XmlNode uiref = doc.CreateElement("UIRef", uri);
                tempProd.AppendChild(uiref);
                XmlUtil.SetAttribute(uiref, "Id", "WixUI_InstallDir");
                setProperty(tempProd, "WIXUI_INSTALLDIR", "INSTALLDIR");
                //
                XmlNode wixUI;
                string  licFIle = XmlUtil.GetAttribute(prodNode, "licFile");
                if (!string.IsNullOrEmpty(licFIle))
                {
                    wixUI = doc.CreateElement("WixVariable", uri);
                    tempProd.AppendChild(wixUI);
                    XmlUtil.SetAttribute(wixUI, "Id", "WixUILicenseRtf");
                    XmlUtil.SetAttribute(wixUI, "Value", licFIle);
                }
                //
                wixUI = doc.CreateElement("WixVariable", uri);
                tempProd.AppendChild(wixUI);
                XmlUtil.SetAttribute(wixUI, "Id", "WixUIBannerBmp");
                XmlUtil.SetAttribute(wixUI, "Value", XmlUtil.GetAttribute(prodNode, "banner"));
                //
                wixUI = doc.CreateElement("WixVariable", uri);
                tempProd.AppendChild(wixUI);
                XmlUtil.SetAttribute(wixUI, "Id", "WixUIDialogBmp");
                XmlUtil.SetAttribute(wixUI, "Value", XmlUtil.GetAttribute(prodNode, "dialog"));
                //
                XmlNode coDir = tempProd.SelectSingleNode("//x:Directory[@Id='CompanyFolder']", _xm);
                XmlUtil.SetAttribute(coDir, "Name", XmlUtil.GetAttribute(prodNode, "companyFolderName"));
                //
                XmlNode package = tempProd.SelectSingleNode("x:Package", _xm);
                string  desc    = XmlUtil.GetAttribute(prodNode, "Description");
                if (string.IsNullOrEmpty(desc))
                {
                    desc = string.Empty;
                }
                XmlUtil.SetAttribute(package, "Description", desc);
                string comments = XmlUtil.GetAttribute(prodNode, "Comments");
                XmlUtil.SetAttribute(package, "Comments", comments);
                XmlUtil.SetAttribute(package, "Manufacturer", XmlUtil.GetAttribute(prodNode, "Manufacturer"));
                //
                XmlNode appSrc  = prodNode.SelectSingleNode("appFolder");
                XmlNode appNode = tempProd.SelectSingleNode("//x:Directory[@Id='INSTALLDIR']", _xm);
                XmlUtil.SetAttribute(appNode, "Name", XmlUtil.GetAttribute(appSrc, "Name"));
                //
                XmlNode mainC = appNode.SelectSingleNode("x:Component[@Id='MainComponent']", _xm);
                XmlUtil.SetAttribute(mainC, "Guid", XmlUtil.GetAttribute(appSrc, "mainId"));
                //
                XmlNode mainF = tempProd.SelectSingleNode("x:Feature[@Id='MainFeature']", _xm);
                XmlUtil.SetAttribute(mainF, "Title", prodName);
                XmlUtil.SetAttribute(mainF, "Description", XmlUtil.GetAttribute(prodNode, "Description"));
                XmlUtil.SetAttribute(mainF, "ConfigurableDirectory", "INSTALLDIR");
                //
                string platform;
                if (string.IsNullOrEmpty(targetPlatform))
                {
                    platform = XmlUtil.GetAttribute(docPrj.DocumentElement, "platform");
                    if (string.IsNullOrEmpty(platform))
                    {
                        platform = "x86";
                    }
                }
                else
                {
                    platform = targetPlatform;
                }
                if (string.Compare(platform, "AnyCPU", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    platform = "x86";
                }
                bool    is64          = (string.Compare(platform, "x64", StringComparison.OrdinalIgnoreCase) == 0);
                XmlNode targetDirNode = tempProd.SelectSingleNode("x:Directory[@Id='TARGETDIR']", _xm);
                //add SystemFolder/System64Folder and CommonAppDataFolder
                for (int i = 0; i < _specialFolders.Count; i++)
                {
                    addSpecialFolder(_specialFolders[i], is64, targetDirNode, tempProd, prodNode, mainF);
                }
                //
                addSources(appSrc, mainF, mainC);
                XmlNodeList iconNodes = prodNode.SelectNodes("Icon");
                foreach (XmlNode inod in iconNodes)
                {
                    XmlNode icN = tempProd.OwnerDocument.CreateElement("Icon", uri);
                    tempProd.AppendChild(icN);
                    passAttribute(icN, inod, "Id");
                    passAttribute(icN, inod, "SourceFile");
                }
                //
                XmlNode menuDir   = tempProd.SelectSingleNode("//x:Directory[@Id='ProgramMenuDir']", _xm);
                XmlNode menuGroup = prodNode.SelectSingleNode("MenuGroup");
                passAttribute(menuDir, menuGroup, "Name");
                XmlNode menuComp = menuDir.SelectSingleNode("//x:Component[@Id='ProgramMenuDir']", _xm);
                passAttribute(menuComp, menuGroup, "Guid");
                //
                _shortcuts.Create(_errors);
                //
                if (is64)
                {
                    XmlNode prgNode = tempProd.SelectSingleNode("//x:Directory[@Id='ProgramFilesFolder']", _xm);
                    XmlUtil.SetAttribute(prgNode, "Id", "ProgramFiles64Folder");
                }
                //
                //
                XmlNodeList cultrueNodes = docPrj.DocumentElement.SelectNodes("Cultures/Item");
                if (cultrueNodes == null || cultrueNodes.Count == 0)
                {
                    throw new Exception("Cultures element is empty");
                }
                //
                XmlNode packageNode = tempProd.SelectSingleNode("x:Package", _xm);
                if (packageNode == null)
                {
                    throw new Exception("Package element not found");
                }
                //
                string binDir = XmlUtil.GetAttribute(docPrj.DocumentElement, "wixbin");
                bool   bOK    = true;
                foreach (XmlNode cultureNode in cultrueNodes)
                {
                    string cultureName = XmlUtil.GetAttribute(cultureNode, "name");
                    if (string.IsNullOrEmpty(cultureName))
                    {
                        throw new Exception("Culture name is missing");
                    }
                    string codepage = XmlUtil.GetAttribute(cultureNode, "SummaryCodepage");
                    if (string.IsNullOrEmpty(codepage))
                    {
                        XmlUtil.RemoveAttribute(packageNode, "SummaryCodepage");
                    }
                    else
                    {
                        XmlUtil.SetAttribute(packageNode, "SummaryCodepage", codepage);
                    }
                    string outWix = Path.Combine(outputfolder, string.Format(CultureInfo.InvariantCulture, "{0}_{1}.wix", msiName, cultureName));
                    doc.Save(outWix);
                    string outObj = Path.Combine(outputfolder, string.Format(CultureInfo.InvariantCulture, "{0}.wixobj", Path.GetFileNameWithoutExtension(outWix)));
                    string c      = string.Format(CultureInfo.InvariantCulture, "-arch {0} -out \"{1}\" \"{2}\"", platform, outObj, outWix);
                    string exe    = Path.Combine(binDir, "candle.exe");
                    if (exec(exe, c))
                    {
                        string  langFile;
                        string  licFile;
                        XmlNode nd = cultureNode.SelectSingleNode("LicFile");
                        if (nd != null)
                        {
                            licFile = nd.InnerText;
                        }
                        else
                        {
                            licFile = string.Empty;
                        }
                        nd = cultureNode.SelectSingleNode("LanguageFile");
                        if (nd != null)
                        {
                            langFile = nd.InnerText;
                        }
                        else
                        {
                            throw new Exception(string.Format(CultureInfo.InvariantCulture, "Language file not specified for culture {0}", cultureName));
                        }
                        string msi;
                        msi = Path.Combine(msiFolder, string.Format(CultureInfo.InvariantCulture, "{0}.msi", Path.GetFileNameWithoutExtension(outWix)));
                        string      uriLng = "http://schemas.microsoft.com/wix/2006/localization";
                        XmlDocument docLng = new XmlDocument();
                        docLng.Load(langFile);
                        XmlNamespaceManager xmlLng = new XmlNamespaceManager(docLng.NameTable);
                        xmlLng.AddNamespace("x", uriLng);
                        XmlNode ndLng = docLng.DocumentElement.SelectSingleNode("x:String[@Id='Version']", xmlLng);
                        if (ndLng == null)
                        {
                            ndLng = docLng.CreateElement("String", uriLng);
                            XmlUtil.SetAttribute(ndLng, "Id", "Version");
                            docLng.DocumentElement.AppendChild(ndLng);
                        }
                        ndLng.InnerText = ver;
                        //
                        docLng.Save(langFile);
                        //
                        exe = Path.Combine(binDir, "light.exe");
                        StringBuilder sb = new StringBuilder();
                        //
                        sb.Append("-ext WixUIExtension -ext WiXNetFxExtension -cultures:");
                        sb.Append(cultureName);
                        sb.Append(" -loc \"");
                        sb.Append(langFile);
                        sb.Append("\"");
                        if (!string.IsNullOrEmpty(licFile))
                        {
                            sb.Append(" -dWixUILicenseRtf=\"");
                            sb.Append(licFile);
                            sb.Append("\"");
                        }
                        sb.Append(" -out \"");
                        sb.Append(msi);
                        sb.Append("\" \"");
                        sb.Append(outObj);
                        sb.Append("\"");
                        c = sb.ToString();
                        if (exec(exe, c))
                        {
                            if (_caller != null)
                            {
                                _caller.ShowMessage("MSI generated.");
                            }
                        }
                        else
                        {
                            if (_caller != null)
                            {
                                _caller.LogError("Error calling light.exe for culture {0}, msi={1}", cultureName, msi);
                            }
                        }
                        if (_errors.Length > 0)
                        {
                            if (_caller != null)
                            {
                                _caller.LogError(_errors.ToString());
                                _errors = new StringBuilder();
                            }
                            bOK = false;
                        }
                    }
                }
                if (bOK)
                {
                }
                else
                {
                    _errors.Append("Error building installer");
                }
            }
            catch (Exception err)
            {
                showError(formErrTxt(err));
            }
            return(_errors.ToString());
        }
Exemplo n.º 5
0
        public static string start(string projectFile, string outputfolder, string targetPlatform, IShowMessage caller)
        {
            XmlDocument docPrj = new XmlDocument();

            docPrj.Load(projectFile);
            return(start(docPrj, outputfolder, targetPlatform, caller));
        }