Exemplo n.º 1
0
        /// <summary>
        /// Creates a new SRT subtitle in file path containing one empty line
        /// </summary>
        /// <param name="filePath">Address to the new SRT subtitle file</param>
        /// <param name="overwrite">Wether overwrite if file exists</param>
        /// <returns>SrtSubtitle object if was successfully created otherwise returns null</returns>
        public static SrtSubtitle CreateNew(string filePath, bool overwrite)
        {
            if (File.Exists(filePath) && !overwrite)
            {
                return(null);
            }
            // check for the SRT ending of the file

            using (var fileStream = File.Create(filePath))
            {
                string text = "1\n" +
                              //"00:00:00.000 --> 00:00:00.000\n" +
                              "\n";
                byte[] bytes = new UTF8Encoding(true).GetBytes(text);
                fileStream.Write(bytes, 0, bytes.Length);
            }

            var srt = new SrtSubtitle();

            srt.FileName = filePath;
            srt._lines   = new List <SrtSubtitleLine>(10);
            srt._lines.Add(new SrtSubtitleLine()
            {
                Text = "", ShowTime = "0", HideTime = "0"
            });
            return(srt);
        }
Exemplo n.º 2
0
        private void newToolButton_Click(object sender, EventArgs e)
        {
            var sfd = new SaveFileDialog();

            if (sfd.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            srt = SrtSubtitle.CreateNew(sfd.FileName, false);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates and returns a new SrtSubtitle from file
        /// </summary>
        /// <param name="file">Address to a SRT subtitle file</param>
        /// <returns>SrtSubtitle object if Read was successful otherwise returns null</returns>
        public static SrtSubtitle CreateFrom(string file)
        {
            //if file exists
            var srt = new SrtSubtitle();

            srt.FileName = file;
            if (srt.Read())
            {
                return(srt);
            }
            else
            {
                return(null);
            }
        }