/// <summary> /// Generate nfo line with proper indent and alignment /// </summary> /// <param name="style">NFO style parameter</param> /// <param name="content">the mutable part in this line</param> /// <returns>a well-formed nfo line</returns> private List <byte> GenerateMutableLine(NFOStyle style, string content, Alignment align) { List <byte> byteList = new List <byte>(); byteList.AddRange(style.Prefix1); switch (align) { case Alignment.Left: byteList.AddRange(CharacterEncodingUtil.StringToBytes(content.PadRight(style.LengthLimit, style.LinePaddingChar))); byteList.AddRange(style.Suffix); break; case Alignment.Middle: int remainingSpace = style.LengthLimit - content.Length; int leftRemainingSpace = remainingSpace / 2; int rightRemainingSpace = remainingSpace - leftRemainingSpace; byteList.AddRange(Enumerable.Repeat(CharacterEncodingUtil.CharToByte(style.LinePaddingChar), leftRemainingSpace).ToArray()); byteList.AddRange(CharacterEncodingUtil.StringToBytes(content)); byteList.AddRange(Enumerable.Repeat(CharacterEncodingUtil.CharToByte(style.LinePaddingChar), rightRemainingSpace).ToArray()); byteList.AddRange(style.Suffix); break; case Alignment.Right: byteList.AddRange(CharacterEncodingUtil.StringToBytes(content.PadLeft(style.LengthLimit, style.LinePaddingChar))); byteList.AddRange(style.Suffix); break; default: byteList.AddRange(CharacterEncodingUtil.StringToBytes(content.PadRight(style.LengthLimit, style.LinePaddingChar))); byteList.AddRange(style.Suffix); break; } return(byteList); }
public DictionaryLine(KeyValuePair <string, string> dataPair, NFOStyle style) { this.key = dataPair.Key; this.value = dataPair.Value; if (this.value == "") { base.byteList.AddRange(GenerateDictionaryLine(style, key, "", true)); base.bytes = byteList.ToArray(); base.line = Encoding.Default.GetString(bytes); } else { List <string> lines = SplitByLength(value, style.LineLength); int count = lines.Count; if (count > 0) { base.byteList.AddRange(GenerateDictionaryLine(style, key, lines[0], true)); if (count > 1) { for (int i = 1; i < count; i++) { base.byteList.AddRange(GenerateDictionaryLine(style, key, lines[i], false)); } } base.bytes = byteList.ToArray(); base.line = Encoding.Default.GetString(bytes); } } }
public MutableLine(KeyValuePair <string, Alignment> dataPair, NFOStyle style) { Alignment align = dataPair.Value; string content = dataPair.Key; List <string> lines = SplitByLength(content, style.LengthLimit); int count = lines.Count; if (count > 0) { for (int i = 0; i < count; i++) { base.byteList.AddRange(GenerateMutableLine(style, lines[i], align)); //base.line += GenerateMutableLine(style, lines[i], align); } base.bytes = byteList.ToArray(); base.line = Encoding.Default.GetString(base.bytes); } }
/// <summary> /// Generate nfo line with proper indent and alignment /// </summary> /// <param name="nfoStyle">NFO style parameter</param> /// <param name="key">key for dictionary</param> /// <param name="line">a line from value for dictionary under length limit</param> /// <param name="containsKey">contains key when generate nfo line. Yes for the first line and No for others</param> /// <returns>a well-formed nfo line</returns> private List <byte> GenerateDictionaryLine(NFOStyle nfoStyle, string key, string line, bool containsKey) { List <byte> list = new List <byte>(); if (containsKey) { list.AddRange(nfoStyle.Prefix1); list.AddRange(CharacterEncodingUtil.StringToBytes(key)); list.AddRange(Enumerable.Repeat(CharacterEncodingUtil.CharToByte(nfoStyle.KeyPaddingChar), nfoStyle.KeyLength - key.Length).ToArray()); list.AddRange(nfoStyle.ConcatString); list.AddRange(CharacterEncodingUtil.StringToBytes(line)); list.AddRange(Enumerable.Repeat(CharacterEncodingUtil.CharToByte(nfoStyle.LinePaddingChar), nfoStyle.LineLength - line.Length).ToArray()); list.AddRange(nfoStyle.Suffix); } else { list.AddRange(nfoStyle.Prefix2); list.AddRange(CharacterEncodingUtil.StringToBytes(line)); list.AddRange(Enumerable.Repeat(CharacterEncodingUtil.CharToByte(nfoStyle.LinePaddingChar), nfoStyle.LineLength - line.Length).ToArray()); list.AddRange(nfoStyle.Suffix); } return(list); }
private void btnProcess_Click(object sender, EventArgs e) { if (this.cmbNfoTemplate.Items.Count < 1) { MessageBox.Show(@"Cannot find any template on '.\Template\' folder.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { string audioCombined = ""; string subCombined = ""; string chapters = ""; try { // Combine all the audio info's into one string. for (int i = 0; i < this.lstAudio.Items.Count; i++) { audioCombined += this.lstAudio.Items[i].ToString() + Environment.NewLine; } // Combine all the subtitle info's into one string. for (int i = 0; i < this.lstSubtitle.Items.Count; i++) { subCombined += this.lstSubtitle.Items[i].ToString() + ", "; } // Convert chapters info. if (this.chkGeneralChaptersIncluded.Checked) { if (this.chkGeneralChaptersNamed.Checked) { chapters = "Included & Named"; } else { chapters = "Included & Unnamed"; } } else { chapters = "Not Included"; } } catch (Exception ex) { MessageBox.Show(ExceptionUtil.FullMessage(ex) + "There is an exception when gathering info from the Window: " + Environment.NewLine + ex.StackTrace, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } try { NFOStyle style = NFOStyle.ImportTemplate(@"./Templates/" + cmbNfoTemplate.SelectedItem.ToString()); NFOInfo info = new NFOInfo(this.txtGeneralReleaseName.Text, Alignment.Left, this.txtIMDb.Text == "" ? "N/A" : this.txtIMDb.Text, this.txtSourceName.Text == "" ? "N/A" : (this.txtSourceName.Text + " - Thanks!"), this.txtGeneralSize.Text, this.txtGeneralDuration.Text, this.txtVideoBitrate.Text, this.txtVideoWidth.Text + " x " + this.txtVideoHeight.Text, this.txtVideoFramerate.Text, audioCombined == "" ? "N/A" : audioCombined, subCombined == "" ? "N/A" : subCombined, chapters, this.txtVideoNote.Text ); NFODocument nfo = new NFODocument(info, style); nfo.WriteNfoFile(this.txtTargetLocation.Text + @"\" + this.txtGeneralReleaseName.Text + ".nfo"); SetStatus("File saved! " + this.txtTargetLocation.Text + @"\" + this.txtGeneralReleaseName.Text + ".nfo"); } catch (Exception ex) { MessageBox.Show(ExceptionUtil.FullMessage(ex) + "There is an exception when generating NFO: " + Environment.NewLine + ex.StackTrace, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }