Exemplo n.º 1
0
 private void SetInitialState()
 {
     InputFileTextBox.Clear();
     OutputFileTextBox.Clear();
     TestCommandBox.Clear();
     VideoEncodeCheckBox.Checked = true;
     EncodeAudioCheckBox.Checked = true;
     CopySubCheckBox.Checked     = false;
     IMDBIDBox.Clear();
     CoverPictureBox.Image     = null;
     CoverArtCheckBox.Checked  = false;
     TestFramePictureBox.Image = null;
     CropTopTextBox.Text       = "0";
     CropBottomTextBox.Text    = "0";
     CropLeftTextBox.Text      = "0";
     CropRightTextBox.Text     = "0";
     OutputResolutionDropDownBox.SelectedItem = "720p";
     OutputWidthTextBox.Text  = "1280";
     OutputHeightTextBox.Text = "-2";
     SetResolutionReadOnly();
     OutputFramerateDropDownBox.SelectedItem = "Original";
     OutputFramerateTextBox.Text             = "";
     SetFramerateReadOnly();
     AudioBitrateTextBox.Text = "192";
     OutputBitrateDropDownBox.SelectedItem = "Auto";
     SetAutoBitrate();
     SetBitrateReadOnly();
     VidCodecDropDownBox.SelectedItem = "h264_nvenc";
     MovieTitleLabel.Text             = "";
     encodeTempFile      = null;
     encodeDir           = null;
     inputFileName       = null;
     outputFileName      = null;
     outputFileExtension = null;
 }
        private void ConvertButton_Click(object sender, EventArgs e)
        {
            string searchMode = string.Empty;

            if (SearchModeCombobox.Text == "Simple")
            {
                searchMode = "simple";
            }
            else
            {
                searchMode = "regexp";
            }


            // get DateTime
            DateTime time     = DateTime.Now;
            string   format   = "yyyy-MM-dd HH:mm";
            string   datetime = time.ToString(format);

            //// declare variable to hold the category selection
            string category = CategoryTextBox.Text;

            if (category.Length > 0)
            {
                category = category.Replace("\"\"", "\"").Replace(" | ", " or ").Replace("|", "");
            }

            // declare variable to get input file
            string InputFile = InputFileTextBox.Text;

            // Check if file exists
            if (InputFile.Length < 1)
            {
                MessageBox.Show("No input file entered. Specify the full path to the Unicode text file.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            else if (!File.Exists(InputFile))
            {
                MessageBox.Show("File selected does not exist. Specify the full path to an existing Unicode text file.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            else if (File.Exists(InputFile))
            {
                long countlines = CountLinesInFile(InputFile);
                if (countlines < 1)
                {
                    MessageBox.Show("File selected contains " + countlines + " lines. Specify the full path to a correct Unicode tab-delimited text file.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }

            // get directory, filename and extension
            string extension = Path.GetExtension(InputFile);
            string filename  = Path.GetFileNameWithoutExtension(InputFile);
            string directory = Path.GetDirectoryName(InputFile);

            if (extension != ".txt")
            {
                MessageBox.Show("File extension is not .txt. Specify the full path to a correct Unicode tab-delimited text file.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // get file encoding
            Encoding encoding = GetFileEncoding(InputFile);

            if (encoding == Encoding.Default)
            {
                MessageBox.Show("File encoding is ANSI.\nSave key terms file as Unicode text file.", "Encoding error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            bool KTMismatchMode;

            if (KTMismatchCheckbox.Checked)
            {
                KTMismatchMode = true;
            }
            else
            {
                KTMismatchMode = false;
            }

            // Read input File and add strings to list
            List <Entry> list = SegmentList(InputFile, encoding, category, KTMismatchMode);

            string OutputFile = directory + "\\" + filename + ".xbckl";

            // If no list is empty
            if (list.Count() < 1)
            {
                MessageBox.Show(InputFile + " does not contain any entry.", "Error");
                return;
            }

            // Delete output file if exists
            if (File.Exists(OutputFile))
            {
                File.Copy(OutputFile, OutputFile + ".bak", true);
                File.Delete(OutputFile);
            }

            string        name      = Replacing(filename);
            XmlTextWriter xmlWriter = new XmlTextWriter(OutputFile, null)
            {
                Formatting = Formatting.Indented
            };

            xmlWriter.WriteStartDocument();
            xmlWriter.WriteStartElement("xbench-checklist");
            xmlWriter.WriteAttributeString("version", "1.0");

            xmlWriter.WriteStartElement("checklist");
            xmlWriter.WriteAttributeString("name", name);

            int counter = 0;

            foreach (Entry segment in list)
            {
                // Declare variable to hold the tags
                string source      = segment.SourceTerm;
                string target      = segment.TargetTerm;
                string description = segment.Description;
                string checkname   = segment.Checkname;

                if (source.Length < 1 && target.Length < 1)
                {
                    continue;
                }

                // Write checklist entry start element
                xmlWriter.WriteStartElement("check");
                xmlWriter.WriteAttributeString("name", checkname);
                xmlWriter.WriteAttributeString("categories", category);

                // Add source term and its parameters
                SourceParms(xmlWriter, source, searchMode);
                // Add target term and its parameters
                TargetParms(xmlWriter, target, searchMode);
                // Add description entry
                Description(xmlWriter, description);

                // Convert string to UTF8 encoding and write to checklist.
                // timestamp tag
                xmlWriter.WriteStartElement("timestamp");
                xmlWriter.WriteString(datetime);
                xmlWriter.WriteEndElement();
                // Add final tag
                xmlWriter.WriteEndElement();

                // increment counter if checklist entry is created
                counter++;
            }

            // Convert string to UTF8 encoding and write to checklist.
            // closing end tags
            xmlWriter.WriteEndElement();
            xmlWriter.WriteEndElement();
            xmlWriter.WriteEndDocument();
            xmlWriter.Close();

            string message = OutputFile + " has beem created successfully. It contains " + counter.ToString() + " entries.";

            MessageBox.Show(message, "Done!", MessageBoxButtons.OK, MessageBoxIcon.Information);

            Process.Start("explorer.exe", "/select, \"" + OutputFile + "\"");

            InputFileTextBox.Clear();
        }
Exemplo n.º 3
0
 private void InputFileClearButton_Click(object sender, EventArgs e)
 {
     InputFileTextBox.Clear();
 }