private void selectProjectXmlButton_Click(object sender, EventArgs e)
        {
            var fileDialog = new OpenFileDialog
            {
                InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
                Filter           = "xml files (*.xml)|*.xml",
                RestoreDirectory = true
            };

            if (fileDialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            var projectPath = fileDialog.FileName;

            photoStoryProject = Ps3AndBloomSerializer.DeserializePhotoStoryXml(projectPath);

            photoStoryProjectTextBox.Text = projectPath;

            var bookName = photoStoryProject.GetProjectName();

            if (projectNameTextBox.Text.Length == 0 && bookName.Length > 0)
            {
                projectNameTextBox.Text = bookName;
            }
        }
Esempio n. 2
0
        public static void BatchConvert(string directoryPath, string bloomExePath)
        {
            var outputDirectory = Path.Combine(directoryPath, "Batch Conversion Output");

            Directory.CreateDirectory(outputDirectory);

            var tempFolder = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());

            Directory.CreateDirectory(tempFolder);
            var filesToProcess = Directory.EnumerateFiles(directoryPath, "*.wp3").Union(Directory.EnumerateFiles(directoryPath, "*.cab")).ToList();

            Console.WriteLine("Found {0} files to process in this directory...", filesToProcess.Count);
            foreach (var projectPath in filesToProcess)
            {
                CABExtracter.Program.ExpandCabFile(projectPath, tempFolder);

                var projectXmlPath    = Path.Combine(tempFolder, "project.xml");
                var photoStoryProject = Ps3AndBloomSerializer.DeserializePhotoStoryXml(projectXmlPath);
                var projectName       = photoStoryProject.GetProjectName();
                if (string.IsNullOrWhiteSpace(projectName))
                {
                    projectName = Path.GetFileNameWithoutExtension(projectPath);
                }
                var matchingDocxFile = GetMatchingDocxFile(directoryPath, projectPath);
                Convert(projectXmlPath, outputDirectory, projectName, matchingDocxFile, bloomExePath, photoStoryProject);

                DeleteAllFilesAndFoldersInDirectory(tempFolder);

                Console.Write(".");
            }

            Directory.Delete(tempFolder);

            Console.WriteLine();
            Console.WriteLine("Successfully processed {0} files.", filesToProcess.Count);
        }
Esempio n. 3
0
        public static void Convert(string projectXmlPath, string destinationFolder, string projectName, string docxPath, string bloomPath, PhotoStoryProject photoStoryProject = null, IList <string> extractedText = null)
        {
            if (photoStoryProject == null)
            {
                photoStoryProject = Ps3AndBloomSerializer.DeserializePhotoStoryXml(projectXmlPath);
                if (string.IsNullOrEmpty(projectName))
                {
                    projectName = photoStoryProject.GetProjectName();
                }
            }

            var convertedProjectDirectory = Path.Combine(destinationFolder, projectName);

            if (Directory.Exists(convertedProjectDirectory) && !overwrite)
            {
                Console.WriteLine(string.Format("Error: A book already exists with the name {0}.", projectName), "projectName");
                return;
            }
            else if (Directory.Exists(convertedProjectDirectory) && overwrite)
            {
                DeleteAllFilesAndFoldersInDirectory(convertedProjectDirectory);
            }
            else
            {
                Directory.CreateDirectory(convertedProjectDirectory);
            }

            if (extractedText == null && docxPath != null)
            {
                TextExtractor.TryExtractText(docxPath, out extractedText);
                if (extractedText == null)
                {
                    Console.WriteLine("Unable to extract text from {0}", docxPath);
                }
            }

            //Three things needed for a bloom book:
            //  book assets (images, narration audio, background audio)
            //  bloom book css and images
            //  the actual book, a generated html file built from the photostory project
            CopyAssetsAndResources(Path.GetDirectoryName(projectXmlPath), convertedProjectDirectory);
            ConvertToBloom(photoStoryProject, Path.Combine(convertedProjectDirectory, string.Format("{0}.htm", projectName)), projectName, extractedText);

            var  hydrationArguments = string.Format("hydrate --preset app --bookpath \"{0}\" --VernacularIsoCode en", convertedProjectDirectory);
            bool hydrateSuccessful;

            try
            {
                using (var process = Process.Start(bloomPath, hydrationArguments))
                {
                    process.WaitForExit();
                    hydrateSuccessful = process.ExitCode == 0;
                }
            }
            catch
            {
                hydrateSuccessful = false;
            }
            if (!hydrateSuccessful)
            {
                Console.WriteLine("Unable to hydrate {0}", projectName);
            }
            else if (!batch)
            {
                Console.WriteLine("Successfully converted {0}", projectName);
            }
        }