private void BeginInstall() { if (!RobustFile.Exists(_path)) { string msg = L10NSharp.LocalizationManager.GetString("BloomPackInstallDialog.DoesNotExist", "{0} does not exist"); ErrorReport.NotifyUserOfProblem(msg, _path); return; } //For BL-3061 at the moment, I'm just trying to log more information. Logger.WriteEvent("BloomPackInstallDialog.BeginInstall. _path is " + _path); _folderName = GetRootFolderName(); Logger.WriteEvent("BloomPackInstallDialog.BeginInstall. _folderName is " + _folderName); if (_folderName == null) { return; } _rootDestFolder = ProjectContext.GetInstalledCollectionsDirectory(); if (_folderName.ToLowerInvariant().Contains("xmatter")) { _rootDestFolder = ProjectContext.XMatterAppDataFolder; } string destinationFolder = Path.Combine(_rootDestFolder, _folderName); if (Directory.Exists(destinationFolder)) { Logger.WriteEvent("Bloom Pack already exists, asking..."); string title = L10NSharp.LocalizationManager.GetString("BloomPackInstallDialog.BloomPackInstaller", "Bloom Pack Installer", "Displayed as the message box title"); string msg = L10NSharp.LocalizationManager.GetString("BloomPackInstallDialog.Replace", "This computer already has a Bloom collection named '{0}'. Do you want to replace it with the one from this Bloom Pack?"); msg = string.Format(msg, _folderName); if (DialogResult.OK != MessageBox.Show(msg, title, MessageBoxButtons.OKCancel)) { _message.Text = L10NSharp.LocalizationManager.GetString("BloomPackInstallDialog.NotInstalled", "The Bloom collection will not be installed."); _okButton.Text = L10NSharp.LocalizationManager.GetString("Common.CancelButton", "&Cancel"); return; } try { Logger.WriteEvent("Deleting existing Bloom Pack at " + destinationFolder); DeleteExistingDirectory(destinationFolder); } catch (Exception error) { string text = L10NSharp.LocalizationManager.GetString("BloomPackInstallDialog.UnableToReplace", "Bloom was not able to remove the existing copy of '{0}'. Quit Bloom if it is running & try again. Otherwise, try again after restarting your computer."); throw new ApplicationException(string.Format(text, destinationFolder), error); } } Logger.WriteEvent("Installing Bloom Pack " + _path); _okButton.Enabled = false; _message.Text = L10NSharp.LocalizationManager.GetString("BloomPackInstallDialog.Extracting", "Extracting...", "Shown while Bloom Packs are being installed"); _backgroundWorker.RunWorkerAsync(); }
private void _backgroundWorker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) { //nb: we want exceptions to be uncaught, to be transferred up to the worker completed event using (var zip = new ZipFile(_path)) { _folderName = GetRootFolderName(zip); if (_folderName == null) { return; } zip.Close(); } var fastZip = new FastZip { CreateEmptyDirectories = true }; fastZip.ExtractZip(_path, ProjectContext.GetInstalledCollectionsDirectory(), null); var newlyAddedFolderOfThePack = Path.Combine(ProjectContext.GetInstalledCollectionsDirectory(), _folderName); CopyXMatterFoldersToWhereTheyBelong(newlyAddedFolderOfThePack); CopyReaderToolsSettingsToWhereTheyBelong(newlyAddedFolderOfThePack); }
public static bool IsInvalidCollectionToEdit(string path) { return(path.StartsWith(ProjectContext.GetInstalledCollectionsDirectory()) || path.StartsWith(BloomFileLocator.FactoryTemplateBookDirectory)); }
private void _backgroundWorker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) { //nb: we want exceptions to be uncaught, to be transferred up to the worker completed event _folderName = GetRootFolderName(); if (_folderName == null) { return; } // ZipFile internally converts all \ separators to / (at least on Linux). So using // ZipFile instead of FastZip fixes https://jira.sil.org/browse/BL-1213. ZipFile zip = null; try { zip = new ZipFile(_path); byte[] buffer = new byte[4096]; // 4K is optimum foreach (ZipEntry entry in zip) { var fullOutputPath = Path.Combine(ProjectContext.GetInstalledCollectionsDirectory(), entry.Name); if (entry.IsDirectory) { Directory.CreateDirectory(fullOutputPath); // In the SharpZipLib code, IsFile and IsDirectory are not defined exactly as inverse: a third // (or fourth) type of entry might be possible. In practice in BloomPacks, this should not be // an issue. continue; } var directoryName = Path.GetDirectoryName(fullOutputPath); if (!String.IsNullOrEmpty(directoryName)) { Directory.CreateDirectory(directoryName); } using (var instream = zip.GetInputStream(entry)) using (var writer = RobustFile.Create(fullOutputPath)) { ICSharpCode.SharpZipLib.Core.StreamUtils.Copy(instream, writer, buffer); } } } catch (Exception ex) { // Report a corrupt file instead of crashing. See http://issues.bloomlibrary.org/youtrack/issue/BL-2485. if (InvokeRequired) { Invoke(new ReportBadBloomPack(ReportErrorUnzippingBloomPack)); } else { ReportErrorUnzippingBloomPack(); } return; } finally { if (zip != null) { zip.Close(); } } var newlyAddedFolderOfThePack = Path.Combine(ProjectContext.GetInstalledCollectionsDirectory(), _folderName); CopyXMatterFoldersToWhereTheyBelong(newlyAddedFolderOfThePack); ToolboxView.CopyToolSettingsForBloomPack(newlyAddedFolderOfThePack); }
private void OnOpenAdditionalCollectionsFolderClick(object sender, EventArgs e) { PathUtilities.OpenDirectoryInExplorer(ProjectContext.GetInstalledCollectionsDirectory()); }