private void btn_ok_Click(object sender, EventArgs e)
        {
            try
            {
                if (!File.Exists(xmlfile_path + "\\DAISY_settingsVer21.xml"))
                {
                    DaisyTranslationSettings.CreateDefaultSettings(xmlfile_path);
                }

                SettingsXml.Load(xmlfile_path + "\\DAISY_settingsVer21.xml");

                XmlNode node = SettingsXml.SelectSingleNode("//Settings/PageNumbers[@value]");

                if (this.radiobtn_custom.Checked == true)
                {
                    node.Attributes[0].Value = "Custom";
                }
                else
                {
                    node.Attributes[0].Value = "Automatic";
                }
                XmlNode charnode = SettingsXml.SelectSingleNode("//Settings/CharacterStyles[@value]");
                if (this.checkbox_translate.Checked == true)
                {
                    charnode.Attributes[0].Value = "True";
                }
                else
                {
                    charnode.Attributes[0].Value = "False";
                }
                XmlNode imgnode = SettingsXml.LastChild["ImageSizes"];

                if (this.radiobtn_originalimage.Checked == true)
                {
                    imgnode.Attributes[0].Value = "original";
                }
                else if (this.radiobtn_resize.Checked == true)
                {
                    imgnode.Attributes[0].Value = "resize";
                }
                else if (this.radiobtn_resample.Checked == true)
                {
                    imgnode.Attributes[0].Value = "resample";
                    imgnode.Attributes[1].Value = this.combobox_resample.SelectedItem.ToString();
                }

                SettingsXml.Save(xmlfile_path + "\\DAISY_settingsVer21.xml");
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Submit Failed", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
        private void Daisysettingsfrm_Load(object sender, EventArgs e)
        {
            xmlfile_path = Path.GetFullPath(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\SaveAsDAISY");

            if (!File.Exists(xmlfile_path + "\\DAISY_settingsVer21.xml"))
            {
                DaisyTranslationSettings.CreateDefaultSettings(xmlfile_path);
            }

            SettingsXml.Load(xmlfile_path + "\\DAISY_settingsVer21.xml");
            XmlNode node = SettingsXml.SelectSingleNode("//Settings/PageNumbers[@value]");

            if (node.Attributes[0].Value == "Custom")
            {
                this.radiobtn_custom.Checked = true;
            }
            else
            {
                this.radiobtn_auto.Checked = true;
            }

            XmlNode charnode = SettingsXml.SelectSingleNode("//Settings/CharacterStyles[@value]");

            if (charnode.Attributes[0].Value == "True")
            {
                this.checkbox_translate.Checked = true;
            }
            else
            {
                this.checkbox_translate.Checked = false;
            }
            XmlNode imgnode = SettingsXml.LastChild["ImageSizes"];

            if (imgnode.Attributes[0].Value == "original")
            {
                this.radiobtn_originalimage.Checked = true;
                this.combobox_resample.Enabled      = false;
            }
            else if (imgnode.Attributes[0].Value == "resize")
            {
                this.radiobtn_resize.Checked   = true;
                this.combobox_resample.Enabled = false;
            }
            else if (imgnode.Attributes[0].Value == "resample")
            {
                this.radiobtn_resample.Checked = true;
                this.combobox_resample.Text    = imgnode.Attributes[1].InnerXml;
                this.combobox_resample.Enabled = true;
            }
        }
        /*Core function for Translation*/
        private void btn_Ok_Click(object sender, EventArgs e)
        {
            CleanOutputDirDlg cleanUpDialog;

            if ((btnID == "DaisyMultiple" || btnID == "DaisyTabMultiple" || btnID == "Button2") && !useAScript)
            {
                if (lBx_SubDocs.Items.Count == 0)
                {
                    MessageBox.Show(manager.GetString("SubdocsError"), "SaveAsDAISY", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    btn_Browse.Focus();
                }
                else if (tBx_output.Text == "")
                {
                    MessageBox.Show(manager.GetString("ChoseDestinationFile"), manager.GetString("Error"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                    btn_Output.Focus();
                }
                else if (Directory.Exists(Path.GetDirectoryName(tBx_output.Text)) == false)
                {
                    MessageBox.Show("Directory " + string.Concat(Path.GetDirectoryName(tBx_output.Text), " ", "does not exist"), manager.GetString("Error"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                    btn_Output.Focus();
                }
                else if (Path.GetFileNameWithoutExtension(tBx_output.Text) == "")
                {
                    MessageBox.Show("Please provide proper filename", manager.GetString("Error"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                    btn_Output.Focus();
                }
                else if (tBx_Title.Text.TrimEnd() == "")
                {
                    MessageBox.Show("Please enter the Title", manager.GetString("Error"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                    tBx_Title.Focus();
                }
                else
                {
                    for (int i = 0; i < lBx_SubDocs.Items.Count; i++)
                    {
                        listDocuments.Add(lBx_SubDocs.Items[i].ToString());
                        btn_Delete.Enabled   = true;
                        btn_Populate.Enabled = true;
                    }

                    table.Add("Title", tBx_Title.Text);
                    table.Add("Creator", tBx_Creator.Text);
                    table.Add("Publisher", tBx_Publisher.Text);
                    table.Add("Subject", tBx_Subject.Text);
                    table.Add("MasterSub", "Yes");
                    table.Add("Version", this.versionInfo);


                    if (tBx_Uid.Text != "")
                    {
                        if (uId == tBx_Uid.Text)
                        {
                            table.Add("UID", "AUTO-UID-" + tBx_Uid.Text);
                        }
                        else
                        {
                            table.Add("UID", tBx_Uid.Text);
                        }
                    }
                    else
                    {
                        table.Add("UID", "AUTO-UID-" + GenerateId().ToString());
                    }


                    if (Path.GetExtension(tBx_output.Text) == "")
                    {
                        tBx_output.Text = tBx_output.Text + ".xml";
                    }

                    fileOutputPath = tBx_output.Text;
                    DaisyTranslationSettings daisySt = new DaisyTranslationSettings();
                    String imgoption      = daisySt.GetImageOption;
                    String resampleValue  = daisySt.GetResampleValue;
                    String characterStyle = daisySt.GetCharacterStyle;
                    String pagenumStyle   = daisySt.GetPagenumStyle;
                    if (imgoption != " ")
                    {
                        table.Add("ImageSizeOption", imgoption);
                        table.Add("DPI", resampleValue);
                    }
                    if (characterStyle != " ")
                    {
                        table.Add("CharacterStyles", characterStyle);
                    }
                    if (pagenumStyle != " ")
                    {
                        table.Add("Custom", pagenumStyle);
                    }

                    masterSubFlag = 1;
                    this.Close();
                }
            }

            else
            {
                string scriptOutput = string.Empty;
                for (int i = 0; i < mLayoutPanel.Controls.Count; i++)
                {
                    if (mLayoutPanel.Controls[i] is BaseUserControl)
                    {
                        ((BaseUserControl)mLayoutPanel.Controls[i]).UpdateScriptParameterValue();
                    }
                }
                for (int i = 0; i < oTableLayoutPannel.Controls.Count; i++)
                {
                    if (oTableLayoutPannel.Controls[i] is BaseUserControl)
                    {
                        ((BaseUserControl)oTableLayoutPannel.Controls[i]).UpdateScriptParameterValue();
                    }
                }

                foreach (ScriptParameter p in mParser.ParameterList)
                {
                    if (p.IsParameterRequired && (p.Name == "outputPath" || p.Name == "output"))
                    {
                        PathDataType pathDataType = p.ParameterDataType as PathDataType;
                        if (pathDataType == null)
                        {
                            continue;
                        }

                        if (pathDataType.IsFileOrDirectory == PathDataType.FileOrDirectory.File)
                        {
                            try
                            {
                                FileInfo outputFileInfo = new FileInfo(p.ParameterValue);
                                if (!string.IsNullOrEmpty(pathDataType.FileExtenssion) &&
                                    !pathDataType.FileExtenssion.Equals(outputFileInfo.Extension, StringComparison.InvariantCultureIgnoreCase))
                                {
                                    MessageBox.Show(string.Format("Please select {0} output file", pathDataType.FileExtenssion), "Error",
                                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                                    mLayoutPanel.Controls[0].Controls[0].Controls[1].Focus();
                                    return;
                                }
                                strBrtextBox = outputFileInfo.DirectoryName;
                                scriptOutput = outputFileInfo.Name;
                            }
                            catch (ArgumentException ex)
                            {
                                AddinLogger.Error(ex);
                                MessageBox.Show("Please select output file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                mLayoutPanel.Controls[0].Controls[0].Controls[1].Focus();
                                return;
                            }
                        }
                        else
                        {
                            strBrtextBox = p.ParameterValue;
                        }
                        break;
                    }
                }

                cleanUpDialog = new CleanOutputDirDlg(strBrtextBox, scriptOutput);

                if (lBx_SubDocs.Items.Count == 0)
                {
                    MessageBox.Show(manager.GetString("SubdocsError"), "SaveAsDAISY", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    btn_Browse.Focus();
                }
                else if (tBx_Title.Text.TrimEnd() == "")
                {
                    MessageBox.Show("Please enter the Title", manager.GetString("Error"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                    tBx_Title.Focus();
                }
                else if (strBrtextBox.TrimEnd() == "")
                {
                    MessageBox.Show("Please select the Destination folder", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    mLayoutPanel.Controls[0].Controls[0].Controls[1].Focus();
                }
                else if (cleanUpDialog.Clean(this) == DialogResult.Cancel)
                {
                    mLayoutPanel.Controls[0].Controls[0].Controls[1].Focus();
                }
                else
                {
                    if (strBrtextBox != cleanUpDialog.OutputDir)
                    {
                        strBrtextBox = cleanUpDialog.OutputDir;
                        foreach (ScriptParameter p in mParser.ParameterList)
                        {
                            if (p.IsParameterRequired && (p.Name == "outputPath" || p.Name == "output"))
                            {
                                p.ParameterValue = cleanUpDialog.OutputDir;
                            }
                        }
                    }


                    tBx_output.Text = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\SaveAsDAISY";
                    for (int i = 0; i < lBx_SubDocs.Items.Count; i++)
                    {
                        listDocuments.Add(lBx_SubDocs.Items[i].ToString());
                        btn_Delete.Enabled   = true;
                        btn_Populate.Enabled = true;
                    }

                    table.Add("Title", tBx_Title.Text);
                    table.Add("Creator", tBx_Creator.Text);
                    table.Add("Publisher", tBx_Publisher.Text);
                    table.Add("Subject", tBx_Subject.Text);
                    table.Add("MasterSub", "Yes");
                    table.Add("Version", this.versionInfo);

                    if (tBx_Uid.Text != "")
                    {
                        if (uId == tBx_Uid.Text)
                        {
                            table.Add("UID", "AUTO-UID-" + tBx_Uid.Text);
                        }
                        else
                        {
                            table.Add("UID", tBx_Uid.Text);
                        }
                    }
                    else
                    {
                        table.Add("UID", "AUTO-UID-" + GenerateId().ToString());
                    }

                    if (Path.GetExtension(tBx_output.Text) == "")
                    {
                        tBx_output.Text = Path.Combine(tBx_output.Text, "MultipleNarrator" + ".xml");
                    }

                    fileOutputPath = tBx_output.Text;
                    DaisyTranslationSettings daisySt = new DaisyTranslationSettings();
                    String imgoption      = daisySt.GetImageOption;
                    String resampleValue  = daisySt.GetResampleValue;
                    String characterStyle = daisySt.GetCharacterStyle;
                    String pagenumStyle   = daisySt.GetPagenumStyle;
                    if (imgoption != " ")
                    {
                        table.Add("ImageSizeOption", imgoption);
                        table.Add("DPI", resampleValue);
                    }
                    if (characterStyle != " ")
                    {
                        table.Add("CharacterStyles", characterStyle);
                    }
                    if (pagenumStyle != " ")
                    {
                        table.Add("Custom", pagenumStyle);
                    }

                    masterSubFlag = 1;
                    this.Close();
                }
            }
        }