public async Task TestProPlusGenerator() { var proPlusDownloader = new ProPlusDownloader(); proPlusDownloader.DownloadFileProgress += (sender, progress) => { var percent = progress.PercentageComplete; if (percent != null) { } }; await proPlusDownloader.DownloadBranch(new DownloadBranchProperties() { BranchName = "Current", OfficeEdition = OfficeEdition.Office64Bit, TargetDirectory = @"e:\Office", Languages = new List<string>() { "en-us", "fr-fr"} }); }
public async Task<string> GetOfficeLatestVersion(string branch, OfficeEdition edition) { var ppDownload = new ProPlusDownloader(); var latestVersion = await ppDownload.GetLatestVersionAsync(branch, edition); return latestVersion; }
public async Task<UpdateFiles> GetOfficeInstallFileXml() { var ppDownload = new ProPlusDownloader(); var installFiles = await ppDownload.DownloadCabAsync(); if (installFiles != null) { var installFile = installFiles.FirstOrDefault(); if (installFile != null) { return installFile; } } return null; }
public async Task RunUpdateOffice() { await Task.Run(async () => { InstallOffice installOffice = null; try { installOffice = new InstallOffice(); installOffice.UpdatingOfficeStatus += installOffice_UpdatingOfficeStatus; Dispatcher.Invoke(() => { UpdateStatus.Content = "Updating..."; ShowVersion.IsEnabled = false; ChangeChannel.IsEnabled = false; }); GlobalObjects.ViewModel.BlockNavigation = true; SetItemState(LocalViewItem.Update, LocalViewState.Wait); var currentChannel = LocalInstall.Channel; if (!installOffice.IsUpdateRunning()) { var ppDownloader = new ProPlusDownloader(); var baseUrl = await ppDownloader.GetChannelBaseUrlAsync(currentChannel, OfficeEdition.Office32Bit); if (string.IsNullOrEmpty(baseUrl)) throw (new Exception(string.Format("Cannot find BaseUrl for Channel: {0}", currentChannel))); installOffice.ChangeUpdateSource(baseUrl); } SetSelectedVersion(); await installOffice.RunOfficeUpdateAsync(LocalInstall.LatestVersion); Dispatcher.Invoke(() => { UpdateStatus.Content = ""; }); var installGenerator = new OfficeInstallManager(); LocalInstall = await installGenerator.CheckForOfficeInstallAsync(); if (LocalInstall.Installed) { Dispatcher.Invoke(() => { VersionLabel.Content = LocalInstall.Version; ChannelLabel.Content = LocalInstall.Channel; ProductBranch.SelectedItem = LocalInstall.Channel; }); if (LocalInstall.LatestVersionInstalled) { SetItemState(LocalViewItem.Update, LocalViewState.Success); } else { SetItemState(LocalViewItem.Update, LocalViewState.Action); Dispatcher.Invoke(() => { UpdateStatus.Content = "New version available (" + LocalInstall.LatestVersion + ")"; }); } } } catch (Exception ex) { SetItemState(LocalViewItem.Update, LocalViewState.Fail); Dispatcher.Invoke(() => { UpdateStatus.Content = "The update failed"; ErrorText.Text = ex.Message; }); LogErrorMessage(ex); } finally { installOffice.ResetUpdateSource(); Dispatcher.Invoke(() => { ShowVersion.IsEnabled = true; ChangeChannel.IsEnabled = true; }); GlobalObjects.ViewModel.BlockNavigation = false; } }); }
public async Task ChangeOfficeChannel() { await Task.Run(async () => { var installOffice = new InstallOffice(); try { installOffice = new InstallOffice(); installOffice.UpdatingOfficeStatus += installOffice_UpdatingOfficeStatus; var newChannel = ""; Dispatcher.Invoke(() => { UpdateStatus.Content = "Updating..."; newChannel = ((OfficeBranch) ProductBranch.SelectedItem).NewName; ChangeChannel.IsEnabled = false; NewVersion.IsEnabled = false; }); SetItemState(LocalViewItem.Update, LocalViewState.Wait); var ppDownloader = new ProPlusDownloader(); var baseUrl = await ppDownloader.GetChannelBaseUrlAsync(newChannel, OfficeEdition.Office32Bit); if (string.IsNullOrEmpty(baseUrl)) throw (new Exception(string.Format("Cannot find BaseUrl for Channel: {0}", newChannel))); var channelToChangeTo = ""; if (NewVersionRow.Visibility != Visibility.Visible) { channelToChangeTo = await ppDownloader.GetLatestVersionAsync(newChannel, OfficeEdition.Office32Bit); } else { Dispatcher.Invoke(() => { var manualVersion = NewVersion.Text; if (string.IsNullOrEmpty(manualVersion) && NewVersion.SelectedItem != null) { manualVersion = ((Build)NewVersion.SelectedItem).Version; } if (!string.IsNullOrEmpty(manualVersion)) { channelToChangeTo = manualVersion; } }); } if (string.IsNullOrEmpty(channelToChangeTo)) { throw (new Exception("Version required")); } else { if (!channelToChangeTo.IsValidVersion()) { throw (new Exception(string.Format("Invalid Version: {0}", channelToChangeTo))); } } await installOffice.ChangeOfficeChannel(channelToChangeTo, baseUrl); Dispatcher.Invoke(() => { UpdateStatus.Content = ""; }); var installGenerator = new OfficeInstallManager(); LocalInstall = await installGenerator.CheckForOfficeInstallAsync(); if (LocalInstall.Installed) { Dispatcher.Invoke(() => { VersionLabel.Content = LocalInstall.Version; ChannelLabel.Content = LocalInstall.Channel; ProductBranch.SelectedItem = LocalInstall.Channel; }); if (LocalInstall.LatestVersionInstalled) { SetItemState(LocalViewItem.Update, LocalViewState.Success); } else { SetItemState(LocalViewItem.Update, LocalViewState.Action); Dispatcher.Invoke(() => { UpdateStatus.Content = "New version available (" + LocalInstall.LatestVersion + ")"; }); } } } catch (Exception ex) { SetItemState(LocalViewItem.Update, LocalViewState.Fail); Dispatcher.Invoke(() => { UpdateStatus.Content = "The update failed"; ErrorText.Text = ex.Message; RetryButtonColumn.Width = new GridLength(0, GridUnitType.Pixel); }); LogErrorMessage(ex); } finally { Dispatcher.Invoke(() => { ChangeChannel.IsEnabled = true; NewVersion.IsEnabled = true; }); } }); }
private async Task GetBranchVersion(OfficeBranch branch, OfficeEdition officeEdition) { try { if (branch.Updated) return; var ppDownload = new ProPlusDownloader(); var latestVersion = await ppDownload.GetLatestVersionAsync(branch.Branch.ToString(), officeEdition); var modelBranch = GlobalObjects.ViewModel.Branches.FirstOrDefault(b => b.Branch.ToString().ToLower() == branch.Branch.ToString().ToLower()); if (modelBranch == null) return; if (modelBranch.Versions.Any(v => v.Version == latestVersion)) return; modelBranch.Versions.Insert(0, new Build() {Version = latestVersion}); modelBranch.CurrentVersion = latestVersion; //ProductVersion.ItemsSource = modelBranch.Versions; //ProductVersion.SetValue(TextBoxHelper.WatermarkProperty, modelBranch.CurrentVersion); modelBranch.Updated = true; } catch (Exception) { } }
private async Task DownloadOfficeFiles() { try { SetTabStatus(false); GlobalObjects.ViewModel.BlockNavigation = true; _tokenSource = new CancellationTokenSource(); UpdateXml(); ProductUpdateSource.IsReadOnly = true; UpdatePath.IsEnabled = false; DownloadProgressBar.Maximum = 100; DownloadPercent.Content = ""; var configXml = GlobalObjects.ViewModel.ConfigXmlParser.ConfigurationXml; var startPath = ProductUpdateSource.Text.Trim(); if (!string.IsNullOrEmpty(startPath)) { GlobalObjects.ViewModel.DownloadFolderPath = startPath; } var channelItems = (List<Channel>) lvUsers.ItemsSource; var taskList = new List<Task>(); _lastUpdated = DateTime.Now.AddDays(-10); var startTime = DateTime.Now; foreach (var channelItem in channelItems) { if (!channelItem.Selected) continue; var branch = channelItem.ChannelName; var task = Task.Run(async () => { try { var proPlusDownloader = new ProPlusDownloader(); proPlusDownloader.DownloadFileProgress += (senderfp, progress) => { if (!_tokenSource.Token.IsCancellationRequested) { DownloadFileProgress(progress, channelItems, channelItem); } }; proPlusDownloader.VersionDetected += (sender, version) => { UpdateVersion(channelItems, channelItem, version.Version); }; if (string.IsNullOrEmpty(startPath)) return; var languages = (from product in configXml.Add.Products from language in product.Languages select language.ID.ToLower()).Distinct().ToList(); var officeEdition = GetSelectedEdition(); var buildPath = GlobalObjects.SetBranchFolderPath(branch, startPath); Directory.CreateDirectory(buildPath); var setVersion = channelItem.DisplayVersion; await proPlusDownloader.DownloadBranch(new DownloadBranchProperties() { BranchName = branch, OfficeEdition = officeEdition, TargetDirectory = buildPath, Languages = languages, Version = setVersion }, _tokenSource.Token); if (!_tokenSource.Token.IsCancellationRequested) { UpdatePercentage(channelItems, channelItem.Name); } LogAnaylytics("/ProductView", "Download." + branch); } catch (Exception ex) { if (!ex.Message.ToLower().Contains("aborted")) { ex.LogException(false); UpdateError(channelItems, channelItem.Name, "ERROR: " + ex.Message); } } }); if (!GlobalObjects.ViewModel.AllowMultipleDownloads) { await task; } if (_tokenSource.Token.IsCancellationRequested) break; var timeTaken = DateTime.Now - startTime; taskList.Add(task); await Task.Delay(new TimeSpan(0, 0, 5)); } await Task.Delay(new TimeSpan(0, 0, 1)); foreach (var task in taskList) { if (task.Exception != null) { } await task; } //MessageBox.Show("Download Complete"); } finally { SetTabStatus(true); GlobalObjects.ViewModel.BlockNavigation = false; ProductUpdateSource.IsReadOnly = false; UpdatePath.IsEnabled = true; DownloadProgressBar.Value = 0; DownloadPercent.Content = ""; DownloadButton.Content = "Download"; _tokenSource = new CancellationTokenSource(); } }
public async Task<string> GenerateConfigXml() { var currentDirectory = Directory.GetCurrentDirectory() + @"\Scripts"; if (!System.IO.File.Exists(currentDirectory + @"\Generate-ODTConfigurationXML.ps1")) { currentDirectory = Directory.GetCurrentDirectory() + @"\Project\Scripts"; } var xmlFilePath = Environment.ExpandEnvironmentVariables(@"%temp%\localConfig.xml"); if (System.IO.File.Exists(xmlFilePath)) { System.IO.File.Delete(xmlFilePath); } var scriptPath = currentDirectory + @"\Generate-ODTConfigurationXML.ps1"; var scriptPathTmp = currentDirectory + @"\Tmp-Generate-ODTConfigurationXML.ps1"; if (!System.IO.File.Exists(scriptPathTmp)) { System.IO.File.Copy(scriptPath, scriptPathTmp, true); } var scriptUrl = AppSettings.GenerateScriptUrl; try { await Retry.BlockAsync(5, 1, async () => { using (var webClient = new WebClient()) { await webClient.DownloadFileTaskAsync(new Uri(scriptUrl), scriptPath); } }); } catch (Exception ex) { } var n = 1; await Retry.BlockAsync(2, 1, async () => { var arguments = @"/c Powershell -ExecutionPolicy Bypass -NoLogo -NonInteractive -NoProfile -WindowStyle " + @"Hidden -File .\RunGenerateXML.ps1"; if (n == 2) { System.IO.File.Copy(scriptPathTmp, scriptPath, true); } var p = new Process { StartInfo = new ProcessStartInfo() { FileName = "cmd", Arguments = arguments, CreateNoWindow = true, UseShellExecute = false, WorkingDirectory = currentDirectory, RedirectStandardOutput = true, RedirectStandardError = true }, }; p.Start(); p.WaitForExit(); var error = await p.StandardError.ReadToEndAsync(); if (!string.IsNullOrEmpty(error)) throw (new Exception(error)); n++; }); await Task.Delay(100); var configXml = ""; if (System.IO.File.Exists(xmlFilePath)) { configXml = System.IO.File.ReadAllText(xmlFilePath); } try { var installOffice = new InstallOffice(); var updateUrl = installOffice.GetBaseCdnUrl(); if (!string.IsNullOrEmpty(updateUrl)) { var pd = new ProPlusDownloader(); var channelName = await pd.GetChannelNameFromUrlAsync(updateUrl, OfficeEdition.Office32Bit); if (!string.IsNullOrEmpty(configXml) && !string.IsNullOrEmpty(channelName)) { configXml = installOffice.SetUpdateChannel(configXml, channelName); } } } catch { } return configXml; }
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 GetProPlusVersions() { await Retry.BlockAsync(3, 1, async () => { var cd = new ProPlusDownloader(); var channelVersionJson = await cd.GetChannelVersionJson(); var branches = GlobalObjects.ViewModel.JsonToBranches(channelVersionJson); if (branches != null) { GlobalObjects.ViewModel.Branches = branches; } var ppDownload = new ProPlusDownloader(); foreach (var channel in GlobalObjects.ViewModel.Branches) { var latestVersion = await ppDownload.GetLatestVersionAsync(channel.Branch.ToString(), OfficeEdition.Office32Bit); channel.CurrentVersion = latestVersion; if (channel.Versions.All(v => v.Version != latestVersion)) { channel.Versions.Insert(0, new Build() { Version = latestVersion }); } } }); }