Bloom.CollectionTab.LibraryModel.MakeBloomPack C# (CSharp) Method

MakeBloomPack() public method

public MakeBloomPack ( string path, bool forReaderTools = false ) : void
path string
forReaderTools bool
return void
        public void MakeBloomPack(string path, bool forReaderTools = false)
        {
            try
            {
                if(RobustFile.Exists(path))
                {
                    // UI already got permission for this
                    RobustFile.Delete(path);
                }

                Logger.WriteEvent("Making BloomPack at "+path+" forReaderTools="+forReaderTools.ToString());

                using (var pleaseWait = new SimpleMessageDialog("Creating BloomPack...", "Bloom"))
                {
                    try
                    {
                        pleaseWait.Show();
                        pleaseWait.BringToFront();
                        Application.DoEvents(); // actually show it
                        Cursor.Current = Cursors.WaitCursor;

                        var dir = TheOneEditableCollection.PathToDirectory;

                        var rootName = Path.GetFileName(dir);
                        if (rootName == null) return;

                        var dirNameOffest = dir.Length - rootName.Length;

                        Logger.WriteEvent("BloomPack path will be " + path + ", made from " + dir + " with rootName " + rootName);
                        using (var fsOut = RobustFile.Create(path))
                        {
                            using (ZipOutputStream zipStream = new ZipOutputStream(fsOut))
                            {
                                zipStream.SetLevel(9);

                                CompressDirectory(dir, zipStream, dirNameOffest, forReaderTools);

                                zipStream.IsStreamOwner = true; // makes the Close() also close the underlying stream
                                zipStream.Close();
                            }
                        }

                        // show it
                        Logger.WriteEvent("Showing BloomPack on disk");
                        PathUtilities.SelectFileInExplorer(path);
                        Analytics.Track("Create BloomPack");
                    }
                    finally
                    {
                        Cursor.Current = Cursors.Default;
                        pleaseWait.Close();
                    }
                }
            }
            catch (Exception e)
            {
                ErrorReport.NotifyUserOfProblem(e, "Could not make the BloomPack");
            }
        }

Usage Example

Example #1
0
 private void OnMakeBloomPackButton_Click(object sender, EventArgs e)
 {
     using (var dlg = new SaveFileDialog())
     {
         dlg.FileName         = _model.GetSuggestedBloomPackPath();
         dlg.Filter           = "BloomPack|*.BloomPack";
         dlg.RestoreDirectory = true;
         dlg.OverwritePrompt  = true;
         if (DialogResult.Cancel == dlg.ShowDialog())
         {
             return;
         }
         _model.MakeBloomPack(dlg.FileName);
     }
 }
All Usage Examples Of Bloom.CollectionTab.LibraryModel::MakeBloomPack