C# Class Bloom.Book.BookStorage

Inheritance: IBookStorage
Show file Open project: BloomBooks/BloomDesktop Class Usage Examples

Private Properties

Property Type Description
AssertIsAlreadyInitialized void
AttemptToReplaceMissingImage bool
EnsureDoesntHaveLinkToStyleSheet void
EnsureHasLinkToStyleSheet void
EnsureHasLinksToStylesheets void
ExpensiveInitialization void
GetBaseForRelativePaths string
GetImagePathsRelativeToBook List
GetNameForATempFileInStorageFolder string
GetNormalizedPathForOS string
GetUniqueFolderName string
GetUniqueFolderPath string
IsPathReadonly bool
MakeCssLinksAppropriateForStoredFile void
ProcessAccessDeniedError void
RemoveDangerousCharacters string
SanitizeNameForFileSystem string
Update void
UpdateSupportFiles void
ValidateBook string

Public Methods

Method Description
BookStorage ( string folderPath, SIL baseFileLocator, BookRenamedEvent bookRenamedEvent, CollectionSettings collectionSettings ) : System
CheckBook ( IProgress progress, string pathToFolderOfReplacementImages = null ) : void

The image-replacement feature is perhaps a one-off for a project where an advisor replaced the folders with a version that lacked most of the images (perhaps because dropbox copies small files first and didn't complete the sync)

CleanupUnusedImageFiles ( ) : void

Compare the images we find in the top level of the book folder to those referenced in the dom, and remove any unreferenced on

FindBookHtmlInFolder ( string folderPath ) : string
GetBrokenBookRecommendationHtml ( ) : string
GetFileLocator ( ) : IFileLocator

this is a method because it wasn't clear if we will eventually generate it on the fly (book paths do change as they are renamed)

GetHtmlMessageIfVersionIsIncompatibleWithThisBloom ( HtmlDom dom, string path ) : string
GetLooksOk ( ) : bool
GetRelocatableCopyOfDom ( IProgress log ) : HtmlDom

creates a relocatable copy of our main HtmlDom

GetValidateErrors ( ) : string
HandleRetiredXMatterPacks ( HtmlDom dom, string nameOfXMatterPack ) : string
MakeDomRelocatable ( HtmlDom dom, IProgress log = null ) : HtmlDom

this one works on the dom passed to it

RemoveBookThumbnail ( string fileName ) : bool

Save ( ) : void
SaveHtml ( HtmlDom dom ) : string
SetBaseForRelativePaths ( HtmlDom dom, string folderPath ) : void
SetBookName ( string name ) : void
TryGetPremadeThumbnail ( string fileName, Image &image ) : bool
UpdateBookFileAndFolderName ( CollectionSettings collectionSettings ) : void
ValidateBook ( string path ) : string

Protected Methods

Method Description
OnFolderPathChanged ( ) : void

Private Methods

Method Description
AssertIsAlreadyInitialized ( ) : void
AttemptToReplaceMissingImage ( string missingFile, string pathToFolderOfReplacementImages, IProgress progress ) : bool
EnsureDoesntHaveLinkToStyleSheet ( HtmlDom dom, string path ) : void
EnsureHasLinkToStyleSheet ( HtmlDom dom, string path ) : void
EnsureHasLinksToStylesheets ( HtmlDom dom ) : void
ExpensiveInitialization ( ) : void

Do whatever is needed to do more than just show a title and thumbnail

GetBaseForRelativePaths ( string folderPath ) : string
GetImagePathsRelativeToBook ( XmlElement element ) : List

Return the paths, relative to the book folder, of all the images referred to in the element.

GetNameForATempFileInStorageFolder ( ) : string

Get a temporary file pathname in the current book's folder. This is needed to ensure proper permissions are granted to the resulting file later after FileUtils.ReplaceFileWithUserInteractionIfNeeded is called. That method may call File.Replace which replaces both the file content and the file metadata (permissions). The result of that if we use the user's temp directory is described in http://issues.bloomlibrary.org/youtrack/issue/BL-3954.

GetNormalizedPathForOS ( string path ) : string
GetUniqueFolderName ( string parentPath, string name ) : string

if necessary, append a number to make the subfolder name unique within the given folder

GetUniqueFolderPath ( string folderPath ) : string

if necessary, append a number to make the folder path unique

IsPathReadonly ( string path ) : bool
MakeCssLinksAppropriateForStoredFile ( HtmlDom dom ) : void

/// Creates a relative path from one file or folder to another. ///

ProcessAccessDeniedError ( UnauthorizedAccessException error ) : void
RemoveDangerousCharacters ( string name ) : string
SanitizeNameForFileSystem ( string name ) : string
Update ( string fileName, string factoryPath = "" ) : void
UpdateSupportFiles ( ) : void

we update these so that the file continues to look the same when you just open it in firefox

ValidateBook ( HtmlDom dom, string path ) : string

Method Details

BookStorage() public method

public BookStorage ( string folderPath, SIL baseFileLocator, BookRenamedEvent bookRenamedEvent, CollectionSettings collectionSettings ) : System
folderPath string
baseFileLocator SIL
bookRenamedEvent BookRenamedEvent
collectionSettings Bloom.Collection.CollectionSettings
return System

CheckBook() public method

The image-replacement feature is perhaps a one-off for a project where an advisor replaced the folders with a version that lacked most of the images (perhaps because dropbox copies small files first and didn't complete the sync)
public CheckBook ( IProgress progress, string pathToFolderOfReplacementImages = null ) : void
progress IProgress
pathToFolderOfReplacementImages string We'll find any matches in the entire folder, regardless of sub-folder name
return void

CleanupUnusedImageFiles() public method

Compare the images we find in the top level of the book folder to those referenced in the dom, and remove any unreferenced on
public CleanupUnusedImageFiles ( ) : void
return void

FindBookHtmlInFolder() public static method

public static FindBookHtmlInFolder ( string folderPath ) : string
folderPath string
return string

GetBrokenBookRecommendationHtml() public method

public GetBrokenBookRecommendationHtml ( ) : string
return string

GetFileLocator() public method

this is a method because it wasn't clear if we will eventually generate it on the fly (book paths do change as they are renamed)
public GetFileLocator ( ) : IFileLocator
return IFileLocator

GetHtmlMessageIfVersionIsIncompatibleWithThisBloom() public static method

public static GetHtmlMessageIfVersionIsIncompatibleWithThisBloom ( HtmlDom dom, string path ) : string
dom HtmlDom
path string
return string

GetLooksOk() public method

public GetLooksOk ( ) : bool
return bool

GetRelocatableCopyOfDom() public method

creates a relocatable copy of our main HtmlDom
public GetRelocatableCopyOfDom ( IProgress log ) : HtmlDom
log IProgress
return HtmlDom

GetValidateErrors() public method

public GetValidateErrors ( ) : string
return string

HandleRetiredXMatterPacks() public method

public HandleRetiredXMatterPacks ( HtmlDom dom, string nameOfXMatterPack ) : string
dom HtmlDom
nameOfXMatterPack string
return string

MakeDomRelocatable() public method

this one works on the dom passed to it
public MakeDomRelocatable ( HtmlDom dom, IProgress log = null ) : HtmlDom
dom HtmlDom
log IProgress
return HtmlDom

OnFolderPathChanged() protected method

protected OnFolderPathChanged ( ) : void
return void

RemoveBookThumbnail() public method

public RemoveBookThumbnail ( string fileName ) : bool
fileName string
return bool

Save() public method

public Save ( ) : void
return void

SaveHtml() public method

public SaveHtml ( HtmlDom dom ) : string
dom HtmlDom
return string

SetBaseForRelativePaths() public static method

public static SetBaseForRelativePaths ( HtmlDom dom, string folderPath ) : void
dom HtmlDom
folderPath string
return void

SetBookName() public method

public SetBookName ( string name ) : void
name string
return void

TryGetPremadeThumbnail() public method

public TryGetPremadeThumbnail ( string fileName, Image &image ) : bool
fileName string
image Image
return bool

UpdateBookFileAndFolderName() public method

public UpdateBookFileAndFolderName ( CollectionSettings collectionSettings ) : void
collectionSettings Bloom.Collection.CollectionSettings
return void

ValidateBook() public static method

public static ValidateBook ( string path ) : string
path string
return string