Skip to content

Commit

Permalink
Add default to just read all SFM files in the directory
Browse files Browse the repository at this point in the history
  • Loading branch information
phillip-hopper committed Mar 14, 2017
1 parent f951522 commit baf14fb
Showing 1 changed file with 58 additions and 43 deletions.
101 changes: 58 additions & 43 deletions D43toPT/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,17 @@ private void btnConvertToParatext_Click(object sender, System.EventArgs e)
lblStatus.Text = "Ready";
}
}
else
{
try
{
exportDirectoryToParatext(txtDoor43Directory.Text, txtParatextDirectory.Text);
}
finally
{
lblStatus.Text = "Ready";
}
}

}

Expand Down Expand Up @@ -238,63 +249,67 @@ private void exportEnglishToDoor43(string sourceDirectory, string targetDirector

private void exportPhilToParatext(string sourceDirectory, string targetDirectory)
{
// get Paratext settings
var paratextSettings = new Paratext8ProjectSettings(targetDirectory);
var projectName = paratextSettings.GetValue("Name");
var booksPresent = new int[123];
exportDirectoryToParatext(Path.Combine(sourceDirectory, "usfm"), targetDirectory);
}

// get book information
var bookData = Resources.Resources.GetBookData();
private void exportDirectoryToParatext(string sourceDirectory, string targetDirectory)
{
// get Paratext settings
var paratextSettings = new Paratext8ProjectSettings(targetDirectory);
var projectName = paratextSettings.GetValue("Name");
var booksPresent = new int[123];

// copy source usfm files
var usfmDir = Path.Combine(sourceDirectory, "usfm");
foreach (var fileName in Directory.EnumerateFiles(usfmDir).Where(filename => filename.ToLower().EndsWith("sfm")))
{
// read the source file
var usfm = File.ReadAllText(fileName);
// get book information
var bookData = Resources.Resources.GetBookData();

// get the book id and number for the Paratext file name
if (!usfm.StartsWith(@"\id "))
{
MessageBox.Show(string.Format("Not a valid USFM file: {0}", fileName));
return;
}
// copy source usfm files
foreach (var fileName in Directory.EnumerateFiles(sourceDirectory).Where(filename => filename.ToLower().EndsWith("sfm")))
{
// read the source file
var usfm = File.ReadAllText(fileName);

var bookID = usfm.Substring(4, 3);
// get the book id and number for the Paratext file name
if (!usfm.StartsWith(@"\id "))
{
MessageBox.Show(string.Format("Not a valid USFM file: {0}", fileName));
return;
}

// update books present
var bookNum = int.Parse(bookData[bookID][1]);
var bookID = usfm.Substring(4, 3);

if (bookNum > 40)
bookNum--;
// update books present
var bookNum = int.Parse(bookData[bookID][1]);

bookNum--;
booksPresent[bookNum] = 1;
if (bookNum > 40)
bookNum--;

// get paratext file name
var bookName = paratextSettings.UsfmFileName(bookData[bookID][1], bookID);
lblStatus.Text = "Exporting " + bookName;
Application.DoEvents();
bookNum--;
booksPresent[bookNum] = 1;

// clean usfm
usfm = cleanUsfm(usfm);
// get paratext file name
var bookName = paratextSettings.UsfmFileName(bookData[bookID][1], bookID);
lblStatus.Text = "Exporting " + bookName;
Application.DoEvents();

// write the usfm file
if (string.IsNullOrEmpty(usfm))
continue;
// clean usfm
usfm = cleanUsfm(usfm);

File.WriteAllText(Path.Combine(targetDirectory, bookName), usfm);
}
// write the usfm file
if (string.IsNullOrEmpty(usfm))
continue;

// update Settings.xml
paratextSettings.SetValue("BooksPresent", string.Join("", booksPresent));
paratextSettings.Save();
File.WriteAllText(Path.Combine(targetDirectory, bookName), usfm);
}

// finished
MessageBox.Show("Finished.");
}
// update Settings.xml
paratextSettings.SetValue("BooksPresent", string.Join("", booksPresent));
paratextSettings.Save();

// finished
MessageBox.Show("Finished.");
}

private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
// save settings
if (!string.IsNullOrEmpty(txtParatextDirectory.Text))
Expand Down

0 comments on commit baf14fb

Please sign in to comment.