Exemple #1
0
        public void TestConfigXmlParser()
        {
            var configXmlParser = new ConfigXmlParser(@"E:\Users\rsmith.vcg\Desktop\configurationTest.xml");

            var clientEdition = configXmlParser.ConfigurationXml.Add.OfficeClientEdition;


            var test = "";
        }
        public void TestConfigXmlParser()
        {


            var configXmlParser = new ConfigXmlParser(@"E:\Users\rsmith.vcg\Desktop\configurationTest.xml");

            var clientEdition = configXmlParser.ConfigurationXml.Add.OfficeClientEdition;


            var test = "";


        }
        private async Task GenerateInstall(bool sign)
        {
            await Task.Run(async () =>
            {
                try
                {
                    var remoteLogPath = "";
                    if (GlobalObjects.ViewModel.RemoteLoggingPath != null &&
                        !string.IsNullOrEmpty(GlobalObjects.ViewModel.RemoteLoggingPath))
                    {
                        remoteLogPath = GlobalObjects.ViewModel.RemoteLoggingPath;
                    }
                    FixFileExtension();
                    var executablePath = "";

                    for (var i = 1; i <= 2; i++)
                    {
                        await Dispatcher.InvokeAsync(() =>
                        {
                            executablePath = FileSavePath.Text.Trim();
                            WaitImage.Visibility = Visibility.Visible;
                            GenerateButton.IsEnabled = false;
                            PreviousButton.IsEnabled = false;
                            GenerateButton.Content = "";
                            PreviousButton.Content = "";

                            if (string.IsNullOrEmpty(executablePath))
                            {
                                if (i == 1)
                                {
                                    GetSaveFilePath();
                                }
                            }
                        });

                        if (!string.IsNullOrEmpty(executablePath))
                        {
                            if (executablePath.ToLower().EndsWith(".exe") || executablePath.ToLower().EndsWith(".msi"))
                            {
                                break;
                            }
                            else
                            {
                                await Dispatcher.InvokeAsync(GetSaveFilePath);
                            }
                        }
                    }

                    if (string.IsNullOrEmpty(executablePath))
                    {
                        //throw (new Exception("File Path Required"));
                        return;
                    }

                    var directoryPath = System.IO.Path.GetDirectoryName(executablePath);
                    if (directoryPath != null)
                    {
                        if (!Directory.Exists(directoryPath))
                        {
                            var result = MessageBox.Show("The directory '" + directoryPath + "' does not exist." + Environment.NewLine + Environment.NewLine + "Create Directory?", "Create Directory", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.Yes);
                            Directory.CreateDirectory(directoryPath);

                            await Dispatcher.InvokeAsync(() => { OpenExeFolderButton.IsEnabled = true; });
                        }
                    }

                    var configFilePath = Environment.ExpandEnvironmentVariables(@"%temp%\OfficeProPlus\" + Guid.NewGuid().ToString() + ".xml");
                    Directory.CreateDirectory(Environment.ExpandEnvironmentVariables(@"%temp%\OfficeProPlus"));

                    GlobalObjects.ViewModel.ConfigXmlParser.ConfigurationXml.Logging = new ODTLogging
                    {
                        Level = LoggingLevel.Standard, Path = @"%temp%"
                    };

                    System.IO.File.WriteAllText(configFilePath, GlobalObjects.ViewModel.ConfigXmlParser.Xml);

                    string sourceFilePath = null;
                    await Dispatcher.InvokeAsync(() =>
                    {
                        if (IncludeBuild.IsChecked.HasValue && IncludeBuild.IsChecked.Value)
                        {
                            sourceFilePath = BuildFilePath.Text.Trim();
                            if (string.IsNullOrEmpty(sourceFilePath)) sourceFilePath = null;
                        }
                    });

                    var isInstallExe = false;
                    await Dispatcher.InvokeAsync(() => { isInstallExe = InstallExecutable.IsChecked.HasValue && InstallExecutable.IsChecked.Value; });

                    var configXml = GlobalObjects.ViewModel.ConfigXmlParser.ConfigurationXml;
                    string version = null;
                    if (configXml.Add.Version != null)
                    {
                        version = configXml.Add.Version.ToString();
                    }


                    if (!string.IsNullOrEmpty(sourceFilePath))
                    {
                        var branchName = "";
                        if (configXml.Add?.Branch != null)
                        {
                            branchName = configXml.Add.Branch.ToString();
                        }
                        if (configXml.Add?.ODTChannel != null)
                        {
                            branchName = configXml.Add.ODTChannel.ToString();
                        }

                        var languages = new List<string>();
                        foreach (var product in configXml.Add.Products)
                        {
                            foreach (var languageItem in product.Languages)
                            {
                                languages.Add(languageItem.ID);
                            }
                        }

                        var edition = OfficeEdition.Office32Bit;
                        if (configXml.Add.OfficeClientEdition == OfficeClientEdition.Office64Bit)
                        {
                            edition = OfficeEdition.Office64Bit;
                        }

                        var ppDownload = new ProPlusDownloader();
                        var validFiles = await ppDownload.ValidateSourceFiles(new DownloadBranchProperties()
                        {
                            TargetDirectory = sourceFilePath,                            
                            BranchName = branchName,
                            Languages = languages,
                            OfficeEdition = edition,
                            Version = version
                        });

                        var cabFilePath = sourceFilePath + @"\Office\Data\v32.cab";
                        if (configXml.Add.OfficeClientEdition == OfficeClientEdition.Office64Bit)
                        {
                            cabFilePath = sourceFilePath + @"\Office\Data\v64.cab";
                        }

                        if (string.IsNullOrEmpty(version) && System.IO.File.Exists(cabFilePath))
                        {
                            var fInfo = new FileInfo(cabFilePath);
                            var cabExtractor = new CabExtractor(cabFilePath);
                            cabExtractor.ExtractCabFiles();
                            cabExtractor.Dispose();

                            var vdPathDir = fInfo.Directory?.FullName + @"\ExtractedFiles";
                            var vdPath = vdPathDir + @"\VersionDescriptor.xml";
                            if (System.IO.File.Exists(vdPath))
                            {
                                var latestVersion = ppDownload.GetCabVersion(vdPath);
                                if (latestVersion != null)
                                {
                                    version = latestVersion;
                                }
                                if (Directory.Exists(vdPathDir))
                                {
                                    try
                                    {
                                        Directory.Delete(vdPathDir);
                                    }
                                    catch (Exception ex)
                                    {
                                        var strError = ex.Message;
                                    }
                                }
                            }
                        }

                        if (!validFiles)
                        {
                            throw (new Exception(
                                "The Office Source Files are invalid. Please verify that all of the files have been downloaded."));
                        }
                    }

                    var productName = "Microsoft Office 365 ProPlus Installer";
                    var productId = Guid.NewGuid().ToString(); //"8AA11E8A-A882-45CC-B52C-80149B4CF47A";
                    var upgradeCode = "AC89246F-38A8-4C32-9110-FF73533F417C";

                    var productVersion = new Version("1.0.0");

                    await Dispatcher.InvokeAsync(() =>
                    {
                        if (MajorVersion.Value.HasValue && MinorVersion.Value.HasValue && ReleaseVersion.Value.HasValue)
                        {
                            productVersion =
                                new Version(MajorVersion.Value.Value + "." + MinorVersion.Value.Value + "." +
                                            ReleaseVersion.Value.Value);
                        }
                    });

                    var installProperties = new List<OfficeInstallProperties>();

                    if (GlobalObjects.ViewModel.ApplicationMode == ApplicationMode.LanguagePack)
                    {
                        productName = "Microsoft Office 365 ProPlus Language Pack";

                        var languages = configXml?.Add?.Products?.FirstOrDefault()?.Languages;
                        foreach (var language in languages)
                        {
                            var configLangXml = new ConfigXmlParser(GlobalObjects.ViewModel.ConfigXmlParser.Xml);
                            configLangXml.ConfigurationXml.Add.ODTChannel = null;
                            var tmpProducts = configLangXml?.ConfigurationXml?.Add?.Products;
                            tmpProducts.FirstOrDefault().Languages = new List<ODTLanguage>()
                            {
                                new ODTLanguage()
                                {
                                    ID = language.ID
                                }
                            };

                            var tmpXmlFilePath = Environment.ExpandEnvironmentVariables(@"%temp%\" + Guid.NewGuid().ToString() + ".xml");
                            System.IO.File.WriteAllText(tmpXmlFilePath, configLangXml.Xml);

                            var tmpSourceFilePath = executablePath;

                            if (Regex.Match(executablePath, ".msi$", RegexOptions.IgnoreCase).Success)
                            {
                                tmpSourceFilePath = Regex.Replace(executablePath, ".msi$", "(" + language.ID + ").msi",
                                    RegexOptions.IgnoreCase);
                            }

                            if (Regex.Match(executablePath, ".exe", RegexOptions.IgnoreCase).Success)
                            {
                                tmpSourceFilePath = Regex.Replace(executablePath, ".exe$", "(" + language.ID + ").exe",
                                    RegexOptions.IgnoreCase);
                            }

                            var programFilesPath = @"%ProgramFiles%\Microsoft Office 365 ProPlus Installer\" + language.ID + @"\" + productVersion;

                            var langProductName = productName + " (" + language.ID + ")";

                            installProperties.Add(new OfficeInstallProperties()
                            {
                                ProductName = langProductName,
                                ProductId = langProductName.GenerateGuid(),
                                ConfigurationXmlPath = tmpXmlFilePath,
                                OfficeVersion = OfficeVersion.Office2016,
                                ExecutablePath = tmpSourceFilePath,
                                SourceFilePath = sourceFilePath,
                                BuildVersion = version,
                                UpgradeCode = language.ID.GenerateGuid(),
                                Version = productVersion,
                                Language = "en-us",
                                ProgramFilesPath = programFilesPath,
                                OfficeClientEdition = configXml.Add.OfficeClientEdition
                            });
                        }
                    }
                    else
                    {
                        installProperties.Add(new OfficeInstallProperties()
                        {
                            ProductName = productName,
                            ProductId = productId,
                            ConfigurationXmlPath = configFilePath,
                            OfficeVersion = OfficeVersion.Office2016,
                            ExecutablePath = executablePath,
                            SourceFilePath = sourceFilePath,
                            BuildVersion = version,
                            UpgradeCode = upgradeCode,
                            Version = productVersion,
                            Language = "en-us",
                            ProgramFilesPath = @"%ProgramFiles%\Microsoft Office 365 ProPlus Installer",
                            OfficeClientEdition = configXml.Add.OfficeClientEdition
                        });
                    }

                    foreach (var installProperty in installProperties)
                    {
                        IOfficeInstallGenerator installer = null;
                        if (isInstallExe)
                        {
                            installer = new OfficeInstallExecutableGenerator();
                            LogAnaylytics("/GenerateView", "GenerateExe");
                        }
                        else
                        {
                            installer = new OfficeInstallMsiGenerator();
                            LogAnaylytics("/GenerateView", "GenerateMSI");
                        }
                        installer.Generate(installProperty, remoteLogPath);
                    }


                    await Task.Delay(500);

                    if (!string.IsNullOrEmpty(GlobalObjects.ViewModel.SelectedCertificate.ThumbPrint) && sign)
                    {
                        await InstallerSign(executablePath);
                    }

                    if (InfoMessage != null)
                    {
                        if (isInstallExe)
                        {
                            InfoMessage(this, new MessageEventArgs()
                            {
                                Title = "Generate Executable", Message = "File Generation Complete"
                            });
                        }
                        else
                        {
                            InfoMessage(this, new MessageEventArgs()
                            {
                                Title = "Generate MSI", Message = "File Generation Complete"
                            });
                        }
                    }

                    await Task.Delay(500);
                }
                catch (Exception ex)
                {
                    LogErrorMessage(ex);
                    Console.WriteLine(ex.StackTrace);
                }
                finally
                {
                    Dispatcher.Invoke(() =>
                    {
                        WaitImage.Visibility = Visibility.Hidden;
                        GenerateButton.IsEnabled = true;
                        PreviousButton.IsEnabled = true;

                        GenerateButton.Content = "Generate";
                        PreviousButton.Content = "Previous";
                    });
                }
            });
        }
        private async Task GenerateInstall(bool sign)
        {
            await Task.Run(async() =>
            {
                try
                {
                    var remoteLogPath = "";
                    if (GlobalObjects.ViewModel.RemoteLoggingPath != null &&
                        !string.IsNullOrEmpty(GlobalObjects.ViewModel.RemoteLoggingPath))
                    {
                        remoteLogPath = GlobalObjects.ViewModel.RemoteLoggingPath;
                    }
                    FixFileExtension();
                    var executablePath = "";

                    for (var i = 1; i <= 2; i++)
                    {
                        await Dispatcher.InvokeAsync(() =>
                        {
                            executablePath           = FileSavePath.Text.Trim();
                            WaitImage.Visibility     = Visibility.Visible;
                            GenerateButton.IsEnabled = false;
                            PreviousButton.IsEnabled = false;
                            GenerateButton.Content   = "";
                            PreviousButton.Content   = "";

                            if (string.IsNullOrEmpty(executablePath))
                            {
                                if (i == 1)
                                {
                                    GetSaveFilePath();
                                }
                            }
                        });

                        if (!string.IsNullOrEmpty(executablePath))
                        {
                            if (executablePath.ToLower().EndsWith(".exe") || executablePath.ToLower().EndsWith(".msi"))
                            {
                                break;
                            }
                            else
                            {
                                await Dispatcher.InvokeAsync(GetSaveFilePath);
                            }
                        }
                    }

                    if (string.IsNullOrEmpty(executablePath))
                    {
                        //throw (new Exception("File Path Required"));
                        return;
                    }

                    var directoryPath = System.IO.Path.GetDirectoryName(executablePath);
                    if (directoryPath != null)
                    {
                        if (!Directory.Exists(directoryPath))
                        {
                            var result = MessageBox.Show("The directory '" + directoryPath + "' does not exist." + Environment.NewLine + Environment.NewLine + "Create Directory?", "Create Directory", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.Yes);
                            Directory.CreateDirectory(directoryPath);

                            await Dispatcher.InvokeAsync(() => { OpenExeFolderButton.IsEnabled = true; });
                        }
                    }

                    var configFilePath = Environment.ExpandEnvironmentVariables(@"%temp%\OfficeProPlus\" + Guid.NewGuid().ToString() + ".xml");
                    Directory.CreateDirectory(Environment.ExpandEnvironmentVariables(@"%temp%\OfficeProPlus"));

                    GlobalObjects.ViewModel.ConfigXmlParser.ConfigurationXml.Logging = new ODTLogging
                    {
                        Level = LoggingLevel.Standard, Path = @"%temp%"
                    };

                    System.IO.File.WriteAllText(configFilePath, GlobalObjects.ViewModel.ConfigXmlParser.Xml);

                    string sourceFilePath = null;
                    await Dispatcher.InvokeAsync(() =>
                    {
                        if (IncludeBuild.IsChecked.HasValue && IncludeBuild.IsChecked.Value)
                        {
                            sourceFilePath = BuildFilePath.Text.Trim();
                            if (string.IsNullOrEmpty(sourceFilePath))
                            {
                                sourceFilePath = null;
                            }
                        }
                    });

                    var isInstallExe = false;
                    await Dispatcher.InvokeAsync(() => { isInstallExe = InstallExecutable.IsChecked.HasValue && InstallExecutable.IsChecked.Value; });

                    var configXml  = GlobalObjects.ViewModel.ConfigXmlParser.ConfigurationXml;
                    string version = null;
                    if (configXml.Add.Version != null)
                    {
                        version = configXml.Add.Version.ToString();
                    }


                    if (!string.IsNullOrEmpty(sourceFilePath))
                    {
                        var branchName = "";
                        if (configXml.Add?.Branch != null)
                        {
                            branchName = configXml.Add.Branch.ToString();
                        }
                        if (configXml.Add?.ODTChannel != null)
                        {
                            branchName = configXml.Add.ODTChannel.ToString();
                        }

                        var languages = new List <string>();
                        foreach (var product in configXml.Add.Products)
                        {
                            foreach (var languageItem in product.Languages)
                            {
                                languages.Add(languageItem.ID);
                            }
                        }

                        var edition = OfficeEdition.Office32Bit;
                        if (configXml.Add.OfficeClientEdition == OfficeClientEdition.Office64Bit)
                        {
                            edition = OfficeEdition.Office64Bit;
                        }

                        var ppDownload = new ProPlusDownloader();
                        var validFiles = await ppDownload.ValidateSourceFiles(new DownloadBranchProperties()
                        {
                            TargetDirectory = sourceFilePath,
                            BranchName      = branchName,
                            Languages       = languages,
                            OfficeEdition   = edition,
                            Version         = version
                        });

                        var cabFilePath = sourceFilePath + @"\Office\Data\v32.cab";
                        if (configXml.Add.OfficeClientEdition == OfficeClientEdition.Office64Bit)
                        {
                            cabFilePath = sourceFilePath + @"\Office\Data\v64.cab";
                        }

                        if (string.IsNullOrEmpty(version) && System.IO.File.Exists(cabFilePath))
                        {
                            var fInfo        = new FileInfo(cabFilePath);
                            var cabExtractor = new CabExtractor(cabFilePath);
                            cabExtractor.ExtractCabFiles();
                            cabExtractor.Dispose();

                            var vdPathDir = fInfo.Directory?.FullName + @"\ExtractedFiles";
                            var vdPath    = vdPathDir + @"\VersionDescriptor.xml";
                            if (System.IO.File.Exists(vdPath))
                            {
                                var latestVersion = ppDownload.GetCabVersion(vdPath);
                                if (latestVersion != null)
                                {
                                    version = latestVersion;
                                }
                                if (Directory.Exists(vdPathDir))
                                {
                                    try
                                    {
                                        Directory.Delete(vdPathDir);
                                    }
                                    catch (Exception ex)
                                    {
                                        var strError = ex.Message;
                                    }
                                }
                            }
                        }

                        if (!validFiles)
                        {
                            throw (new Exception(
                                       "The Office Source Files are invalid. Please verify that all of the files have been downloaded."));
                        }
                    }

                    var productName = "Microsoft Office 365 ProPlus Installer";
                    var productId   = Guid.NewGuid().ToString(); //"8AA11E8A-A882-45CC-B52C-80149B4CF47A";
                    var upgradeCode = "AC89246F-38A8-4C32-9110-FF73533F417C";

                    var productVersion = new Version("1.0.0");

                    await Dispatcher.InvokeAsync(() =>
                    {
                        if (MajorVersion.Value.HasValue && MinorVersion.Value.HasValue && ReleaseVersion.Value.HasValue)
                        {
                            productVersion =
                                new Version(MajorVersion.Value.Value + "." + MinorVersion.Value.Value + "." +
                                            ReleaseVersion.Value.Value);
                        }
                    });

                    var installProperties = new List <OfficeInstallProperties>();

                    if (GlobalObjects.ViewModel.ApplicationMode == ApplicationMode.LanguagePack)
                    {
                        productName = "Microsoft Office 365 ProPlus Language Pack";

                        var languages = configXml?.Add?.Products?.FirstOrDefault()?.Languages;
                        foreach (var language in languages)
                        {
                            var configLangXml = new ConfigXmlParser(GlobalObjects.ViewModel.ConfigXmlParser.Xml);
                            configLangXml.ConfigurationXml.Add.ODTChannel = null;
                            var tmpProducts = configLangXml?.ConfigurationXml?.Add?.Products;
                            tmpProducts.FirstOrDefault().Languages = new List <ODTLanguage>()
                            {
                                new ODTLanguage()
                                {
                                    ID = language.ID
                                }
                            };

                            var tmpXmlFilePath = Environment.ExpandEnvironmentVariables(@"%temp%\" + Guid.NewGuid().ToString() + ".xml");
                            System.IO.File.WriteAllText(tmpXmlFilePath, configLangXml.Xml);

                            var tmpSourceFilePath = executablePath;

                            if (Regex.Match(executablePath, ".msi$", RegexOptions.IgnoreCase).Success)
                            {
                                tmpSourceFilePath = Regex.Replace(executablePath, ".msi$", "(" + language.ID + ").msi",
                                                                  RegexOptions.IgnoreCase);
                            }

                            if (Regex.Match(executablePath, ".exe", RegexOptions.IgnoreCase).Success)
                            {
                                tmpSourceFilePath = Regex.Replace(executablePath, ".exe$", "(" + language.ID + ").exe",
                                                                  RegexOptions.IgnoreCase);
                            }

                            var programFilesPath = @"%ProgramFiles%\Microsoft Office 365 ProPlus Installer\" + language.ID + @"\" + productVersion;

                            var langProductName = productName + " (" + language.ID + ")";

                            installProperties.Add(new OfficeInstallProperties()
                            {
                                ProductName          = langProductName,
                                ProductId            = langProductName.GenerateGuid(),
                                ConfigurationXmlPath = tmpXmlFilePath,
                                OfficeVersion        = OfficeVersion.Office2016,
                                ExecutablePath       = tmpSourceFilePath,
                                SourceFilePath       = sourceFilePath,
                                BuildVersion         = version,
                                UpgradeCode          = language.ID.GenerateGuid(),
                                Version             = productVersion,
                                Language            = "en-us",
                                ProgramFilesPath    = programFilesPath,
                                OfficeClientEdition = configXml.Add.OfficeClientEdition
                            });
                        }
                    }
                    else
                    {
                        installProperties.Add(new OfficeInstallProperties()
                        {
                            ProductName          = productName,
                            ProductId            = productId,
                            ConfigurationXmlPath = configFilePath,
                            OfficeVersion        = OfficeVersion.Office2016,
                            ExecutablePath       = executablePath,
                            SourceFilePath       = sourceFilePath,
                            BuildVersion         = version,
                            UpgradeCode          = upgradeCode,
                            Version             = productVersion,
                            Language            = "en-us",
                            ProgramFilesPath    = @"%ProgramFiles%\Microsoft Office 365 ProPlus Installer",
                            OfficeClientEdition = configXml.Add.OfficeClientEdition
                        });
                    }

                    foreach (var installProperty in installProperties)
                    {
                        IOfficeInstallGenerator installer = null;
                        if (isInstallExe)
                        {
                            installer = new OfficeInstallExecutableGenerator();
                            LogAnaylytics("/GenerateView", "GenerateExe");
                        }
                        else
                        {
                            installer = new OfficeInstallMsiGenerator();
                            LogAnaylytics("/GenerateView", "GenerateMSI");
                        }
                        installer.Generate(installProperty, remoteLogPath);
                    }


                    await Task.Delay(500);

                    if (!string.IsNullOrEmpty(GlobalObjects.ViewModel.SelectedCertificate.ThumbPrint) && sign)
                    {
                        await InstallerSign(executablePath);
                    }

                    if (InfoMessage != null)
                    {
                        if (isInstallExe)
                        {
                            InfoMessage(this, new MessageEventArgs()
                            {
                                Title = "Generate Executable", Message = "File Generation Complete"
                            });
                        }
                        else
                        {
                            InfoMessage(this, new MessageEventArgs()
                            {
                                Title = "Generate MSI", Message = "File Generation Complete"
                            });
                        }
                    }

                    await Task.Delay(500);
                }
                catch (Exception ex)
                {
                    LogErrorMessage(ex);
                    Console.WriteLine(ex.StackTrace);
                }
                finally
                {
                    Dispatcher.Invoke(() =>
                    {
                        WaitImage.Visibility     = Visibility.Hidden;
                        GenerateButton.IsEnabled = true;
                        PreviousButton.IsEnabled = true;

                        GenerateButton.Content = "Generate";
                        PreviousButton.Content = "Previous";
                    });
                }
            });
        }
        public IOfficeInstallReturn Generate(IOfficeInstallProperties installProperties, string remoteLogPath = "")
        {
            var currentDirectory = Directory.GetCurrentDirectory();
            var embededExeFiles = new List<string>();
            try
            {
                if (Directory.Exists(currentDirectory + @"\Project"))
                {
                    currentDirectory = currentDirectory + @"\Project";
                }

                var codeProvider = new CSharpCodeProvider();
                var icc = codeProvider.CreateCompiler();

                var tmpPath = Environment.ExpandEnvironmentVariables("%temp%");
                var output = currentDirectory + @"\InstallOffice365ProPlus.exe";

                if (!string.IsNullOrEmpty(installProperties.ExecutablePath))
                {
                    output = installProperties.ExecutablePath;
                }

                var parameters = new CompilerParameters
                {
                    GenerateExecutable = true,
                    OutputAssembly = output
                };
                parameters.ReferencedAssemblies.Add("System.dll");
                parameters.ReferencedAssemblies.Add("System.Xml.dll");
                parameters.ReferencedAssemblies.Add("System.Core.dll");
                parameters.ReferencedAssemblies.Add("System.Windows.Forms.dll");
                parameters.ReferencedAssemblies.Add("Microsoft.CSharp.dll");
                parameters.ReferencedAssemblies.Add("System.Management.dll");

                embededExeFiles = EmbeddedResources.GetEmbeddedItems(currentDirectory, @"\.exe$");

                File.Copy(installProperties.ConfigurationXmlPath, tmpPath + @"\configuration.xml", true);

                var productIdPath = tmpPath + @"\productid.txt";
                var remoteLog = tmpPath + @"\RemoteLog.txt";
                File.WriteAllText(productIdPath, installProperties.ProductId);
                File.WriteAllText(remoteLog, remoteLogPath);

                parameters.EmbeddedResources.Add(tmpPath + @"\configuration.xml");
                parameters.EmbeddedResources.Add(productIdPath);
                parameters.EmbeddedResources.Add(remoteLog);

                // parameters.EmbeddedResources.Add(@"\tools\");

                var office2013Setup = DirectoryHelper.GetCurrentDirectoryFilePath("Office2013Setup.exe");
                var office2016Setup = DirectoryHelper.GetCurrentDirectoryFilePath("Office2016Setup.exe");

                parameters.EmbeddedResources.Add(installProperties.OfficeVersion == OfficeVersion.Office2013
                    ? office2013Setup
                    : office2016Setup);

                var installOfficeFp = DirectoryHelper.GetCurrentDirectoryFilePath("InstallOffice.cs");

                var fileContents = File.ReadAllText(installOfficeFp);
                fileContents = fileContents.Replace("public static void Main1(string[] args)",
                    "public static void Main(string[] args)");

                var configXml = new ConfigXmlParser(tmpPath + @"\configuration.xml");
                var addNode = configXml.ConfigurationXml.Add;
                if (addNode != null && addNode.Version != null)
                {
                    fileContents = fileContents.Replace("//[assembly: AssemblyVersion(\"\")]",
                         "[assembly: AssemblyVersion(\"" + addNode.Version + "\")]");
                }

                if (configXml.ConfigurationXml.Logging == null)
                {
                    configXml.ConfigurationXml.Logging = new ODTLogging();
                }

                configXml.ConfigurationXml.Logging.Level = LoggingLevel.Standard;
                configXml.ConfigurationXml.Logging.Path = "%temp%";

                if (installProperties.SourceFilePath != null)
                {
                    if (!Directory.Exists(installProperties.SourceFilePath + @"\Office"))
                    {
                        throw (new DirectoryNotFoundException("Invalid Source Path: " + installProperties.SourceFilePath));
                    }

                    //commenting out, trying to go a different path with this, copy out the source files to the same dir as exe file
                    //possibly only copy out if contents of source file greater than 1.5 GB
                    long embeddedFileSize = CalcSize(parameters, installProperties.SourceFilePath + @"\Office", installProperties.BuildVersion, installProperties.OfficeClientEdition);
                    
                    //find file size of embedded files, if less than 1.5 GB, then embed, if greater, copy out as separate folder in same dir as the MSI or exe file
                    if (embeddedFileSize < 1900000000)
                    {
                        EmbedSourceFiles(parameters, installProperties.SourceFilePath + @"\Office",
                            installProperties.BuildVersion, installProperties.OfficeClientEdition);
                    }
                    else
                    {
                        CopyFolder(new DirectoryInfo(installProperties.SourceFilePath), new DirectoryInfo(installProperties.ExecutablePath.Substring(0, installProperties.ExecutablePath.LastIndexOf(@"\"))));
                    }
                    
                }

                if (installProperties.OfficeVersion == OfficeVersion.Office2013)
                {
                    fileContents = fileContents.Replace("//[assembly: AssemblyTitle(\"\")]",
                        "[assembly: AssemblyTitle(\"" + "Office 365 ProPlus (2013)" + "\")]");
                    fileContents = fileContents.Replace("//[assembly: AssemblyDescription(\"\")]",
                        "[assembly: AssemblyDescription(\"" + "Office 365 ProPlus (2013)" + "\")]");
                }

                if (installProperties.OfficeVersion == OfficeVersion.Office2016)
                {
                    fileContents = fileContents.Replace("//[assembly: AssemblyTitle(\"\")]",
                        "[assembly: AssemblyTitle(\"" + "Office 365 ProPlus (2016)" + "\")]");
                    fileContents = fileContents.Replace("//[assembly: AssemblyDescription(\"\")]",
                        "[assembly: AssemblyDescription(\"" + "Office 365 ProPlus (2016)" + "\")]");
                }
                
                var results = icc.CompileAssemblyFromSource(parameters, fileContents);
                //delete temp files
                foreach (var fileMarkedForDelete in filesMarkedForDelete)
                {
                    fileMarkedForDelete.Delete();
                }

                if (results.Errors.Count > 0)
                {
                    var strBuilder = new StringBuilder();
                    foreach (CompilerError CompErr in results.Errors)
                    {
                        var errorText = "Line number " + CompErr.Line +
                                        ", Error Number: " + CompErr.ErrorNumber +
                                        ", '" + CompErr.ErrorText + ";" +
                                        Environment.NewLine + Environment.NewLine;
                        strBuilder.AppendLine(errorText);
                    }
                    throw (new Exception(strBuilder.ToString()));
                }

                return new OfficeInstallReturn()
                {
                    GeneratedFilePath = output
                };
            }
            finally
            {
                foreach (var fileName in embededExeFiles)
                {
                    if (File.Exists(currentDirectory + @"\" + fileName))
                    {
                        File.Delete(currentDirectory + @"\" + fileName);
                    }
                }
            }
        }