Skip to content

Commit

Permalink
More options
Browse files Browse the repository at this point in the history
  • Loading branch information
hopto-dot committed Dec 3, 2021
1 parent 55f0a50 commit 61f8ab7
Show file tree
Hide file tree
Showing 3 changed files with 232 additions and 18 deletions.
133 changes: 128 additions & 5 deletions LNConverter/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

72 changes: 59 additions & 13 deletions LNConverter/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ public Form1()
private void Form1_Load(object sender, EventArgs e)
{
lblTitle.Text = "";
tbxFilePath.Text = System.Environment.ExpandEnvironmentVariables("%userprofile%/downloads/");

foreach (InputLanguage language in InputLanguage.InstalledInputLanguages)
{
if (language.LayoutName == "日本語") { btnSelectFile.Text = "ファイルを選択"; btnConvert.Text = "変換"; lblTextAlignment.Text = "文字揃え"; lblFontSize.Text = "フォントサイズ"; cbDarkMode.Text = "ダークモード"; cbTategaki.Text = "縦書き"; cbMoveHtml.Text = "imagesというフォルダに.htmlを移動"; cbMoveCover.Text = "imagesというフォルダに表紙を移動"; cbxAlignment.Location = new Point(270, 182); tbxFontSize.Location = new Point(287, 219); lbPx.Location = new Point(316, 222); } // :)
}
}

String FilePath = "";
Expand All @@ -26,6 +32,7 @@ private void Form1_Load(object sender, EventArgs e)
private void btnSelectFile_Click(object sender, EventArgs e)
{
OpenFileDialog OpenFile = new OpenFileDialog();
OpenFile.Multiselect = true;
OpenFile.RestoreDirectory = true;
OpenFile.Filter = "Epub Files|*.epub";
if (OpenFile.ShowDialog() == DialogResult.OK)
Expand All @@ -47,6 +54,17 @@ private void btnSelectFile_Click(object sender, EventArgs e)
lblTitle.Text = Epub.Title;

byte[] coverImageContent = Epub.CoverImage;
if (coverImageContent == null && Epub.Content.Images.Count != 0)
{
try
{
var contentFile = Epub.Content.Images["cover1.jpeg"];
coverImageContent = contentFile.Content;
}
catch {}

}

if (coverImageContent != null)
{
using (MemoryStream coverImageStream = new MemoryStream(coverImageContent))
Expand All @@ -58,6 +76,7 @@ private void btnSelectFile_Click(object sender, EventArgs e)
}
else
{
pictureBox1.Image = null;
return;
}
}
Expand Down Expand Up @@ -124,16 +143,44 @@ private void btnConvert_Click(object sender, EventArgs e)
//{
// goto SkipSave;
//}

File.Move(imageFile.FileName.Replace("images/", ""), OutputLocation + Epub.Title + "/" + imageFile.FileName, true);
SkipSave:;
string imageMovePath = cbMoveCover.Checked && imageFile.FileName.ToLower().Contains("cover") ? OutputLocation + Epub.Title + "/images/" + imageFile.FileName : OutputLocation + Epub.Title + "/" + imageFile.FileName;
File.Move(imageFile.FileName.Replace("images/", ""), imageMovePath, true);
//SkipSave:;
}
}
}

HTMLConvert = HTMLConvert.Replace("\n", "");
File.Create(OutputLocation + Epub.Title + ".html").Dispose();
using (StreamWriter writer = new StreamWriter(System.Environment.ExpandEnvironmentVariables("%userprofile%/downloads/") + Epub.Title + ".html"))
if (cbxAlignment.Text != "") {
HTMLConvert = HTMLConvert.Replace("text-align: center;", cbxAlignment.Text.ToLower());
HTMLConvert = HTMLConvert.Replace("text-align: left;", cbxAlignment.Text.ToLower());
HTMLConvert = HTMLConvert.Replace("text-align: right;", cbxAlignment.Text.ToLower());
}
string fontSizeText = string.Empty;
if (tbxFontSize.Text != "")
{
fontSizeText = "body {" + $"font-size: {tbxFontSize.Text}px; ";
HTMLConvert = HTMLConvert.Replace("body {", fontSizeText);
}

string bodyReplacer = "<body style=\"";
if (cbDarkMode.Checked == true) {
bodyReplacer += "background-color:#181a1b; color:#FFFFFF;";
}
if (cbTategaki.Checked == true)
{
bodyReplacer += "-webkit-writing-mode: vertical-rl; -moz-writing-mode: vertical-rl; -ms-writing-mode: vertical-rl; writing-mode: vertical-rl;";
}
bodyReplacer += "\"";
if (bodyReplacer == "<body style=\"\"") { bodyReplacer = string.Empty; }
HTMLConvert = HTMLConvert.Replace("<body", bodyReplacer);

string addImagesPath = string.Empty;
if (cbMoveHtml.Checked == true) { addImagesPath = @"/images/"; }
string htmlOutputPath = OutputLocation + Epub.Title + "/" + addImagesPath + Epub.Title + ".html";

File.Create(htmlOutputPath).Dispose();
using (StreamWriter writer = new StreamWriter(htmlOutputPath)) //System.Environment.ExpandEnvironmentVariables("%userprofile%/downloads/") + Epub.Title + ".html"
{
writer.WriteLine(HTMLConvert);
}
Expand All @@ -142,22 +189,21 @@ private void btnConvert_Click(object sender, EventArgs e)

private void Form1_Resize(object sender, EventArgs e)
{
if (this.Size.Height >= 650)
if (this.Size.Height <= 410)
{
pictureBox1.Width = 340;
pictureBox1.Height = 474;
}
else if (this.Size.Height <= 400)
{
pictureBox1.Width = 170 / 2;
pictureBox1.Height = 237 / 2;
pictureBox1.Width = 123;
pictureBox1.Height = 183;
}
else
{
pictureBox1.Width = 170;
pictureBox1.Height = 237;
}
}



}

}

45 changes: 45 additions & 0 deletions LNConverter/Form1.resx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,51 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="btnSelectFile.Locked" type="System.Boolean, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e">
<value>True</value>
</metadata>
<metadata name="tbxFilePath.Locked" type="System.Boolean, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e">
<value>True</value>
</metadata>
<metadata name="btnConvert.Locked" type="System.Boolean, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e">
<value>True</value>
</metadata>
<metadata name="lblTitle.Locked" type="System.Boolean, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e">
<value>True</value>
</metadata>
<metadata name="pictureBox1.Locked" type="System.Boolean, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e">
<value>True</value>
</metadata>
<metadata name="cbMoveHtml.Locked" type="System.Boolean, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e">
<value>True</value>
</metadata>
<metadata name="cbxAlignment.Locked" type="System.Boolean, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e">
<value>True</value>
</metadata>
<metadata name="cbTategaki.Locked" type="System.Boolean, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e">
<value>True</value>
</metadata>
<metadata name="lblTextAlignment.Locked" type="System.Boolean, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e">
<value>True</value>
</metadata>
<metadata name="cbMoveCover.Locked" type="System.Boolean, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e">
<value>True</value>
</metadata>
<metadata name="lblFontSize.Locked" type="System.Boolean, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e">
<value>True</value>
</metadata>
<metadata name="tbxFontSize.Locked" type="System.Boolean, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e">
<value>True</value>
</metadata>
<metadata name="lbPx.Locked" type="System.Boolean, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e">
<value>True</value>
</metadata>
<metadata name="cbDarkMode.Locked" type="System.Boolean, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e">
<value>True</value>
</metadata>
<metadata name="$this.Locked" type="System.Boolean, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e">
<value>True</value>
</metadata>
<metadata name="$this.TrayHeight" type="System.Int32, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e">
<value>45</value>
</metadata>
Expand Down

0 comments on commit 61f8ab7

Please sign in to comment.