Пример #1
0
        /*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();
                }
            }
        }
Пример #2
0
        private bool ValidateForFullDaisyTranslate()
        {
            string fileName    = Path.GetFileNameWithoutExtension(mInputPath);
            string otpfileName = fileName + ".xml";

            tBx_Browse.Text = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\SaveAsDAISY\";
            if (tBx_Title.Text.TrimEnd() == "")
            {
                MessageBox.Show(resManager.GetString("Title"), resManager.GetString("Error"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                tBx_Title.Focus();
                return(false);
            }

            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(false);
                            }
                            strBrtextBox = outputFileInfo.DirectoryName;
                        }
                        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(false);
                        }
                    }
                    else
                    {
                        strBrtextBox = p.ParameterValue;
                    }

                    //TODO:::
                    if (string.IsNullOrEmpty(strBrtextBox.TrimEnd()))
                    {
                        MessageBox.Show("Please select the Destination folder", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        mLayoutPanel.Controls[0].Controls[0].Controls[1].Focus();
                        return(false);
                    }

                    CleanOutputDirDlg cleanOutputDirDlg = new CleanOutputDirDlg(strBrtextBox, otpfileName);
                    if (cleanOutputDirDlg.Clean(this) == DialogResult.Cancel)
                    {
                        mLayoutPanel.Controls[0].Controls[0].Controls[1].Focus();
                        return(false);
                    }
                    if (strBrtextBox != cleanOutputDirDlg.OutputDir)
                    {
                        strBrtextBox     = cleanOutputDirDlg.OutputDir;
                        p.ParameterValue = cleanOutputDirDlg.OutputDir;
                    }

                    break;
                }
            }



            //if (File.Exists(strBrtextBox + "\\" + otpfileName))
            //{
            //    DialogResult objResult;
            //    objResult = MessageBox.Show(otpfileName + " already exists in the destination folder. Do you want to overwrite?", "Confirm File Replace", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
            //    if (objResult != DialogResult.Yes)
            //    {
            //        mLayoutPanel.Controls[0].Controls[0].Focus();
            //        return false;
            //    }
            //}

            return(true);
        }