public void UploadBook(string storageKeyOfBookFolder, string pathToBloomBookDirectory, IProgress progress, string pdfToInclude = null)
{
BaseUrl = null;
BookOrderUrlOfRecentUpload = null;
DeleteBookData(_bucketName, storageKeyOfBookFolder); // In case we're overwriting, get rid of any deleted files.
//first, let's copy to temp so that we don't have to worry about changes to the original while we're uploading,
//and at the same time introduce a wrapper with the last part of the unique key for this person+book
string prefix = ""; // storageKey up to last slash (or empty)
string tempFolderName = storageKeyOfBookFolder; // storage key after last slash (or all of it)
// storageKeyOfBookFolder typically has a slash in it, email/id.
// We only want the id as the temp folder name.
// If there is anything before it, though, we want that as a prefix to make a parent 'folder' on parse.com.
int index = storageKeyOfBookFolder.LastIndexOf('/');
if (index >= 0)
{
prefix = storageKeyOfBookFolder.Substring(0, index + 1); // must include the slash
tempFolderName = storageKeyOfBookFolder.Substring(index + 1);
}
var wrapperPath = Path.Combine(Path.GetTempPath(), tempFolderName);
//If we previously uploaded the book, but then had a problem, this directory could still be on our harddrive. Clear it out.
if (Directory.Exists(wrapperPath))
{
DeleteFileSystemInfo(new DirectoryInfo(wrapperPath));
}
Directory.CreateDirectory(wrapperPath);
var destDirName = Path.Combine(wrapperPath, Path.GetFileName(pathToBloomBookDirectory));
CopyDirectory(pathToBloomBookDirectory, destDirName);
// Don't upload audio (todo: test).
string audioDir = Path.Combine(destDirName, "audio");
if (Directory.Exists(audioDir))
SIL.IO.RobustIO.DeleteDirectory(audioDir, true);
var unwantedPdfs = Directory.EnumerateFiles(destDirName, "*.pdf").Where(x => Path.GetFileName(x) != pdfToInclude);
foreach (var file in unwantedPdfs)
RobustFile.Delete(file);
UploadDirectory(prefix, wrapperPath, progress);
DeleteFileSystemInfo(new DirectoryInfo(wrapperPath));
}