예제 #1
0
        public async void UpdateFileOffset()
        {
            var result = new StringBuilder();

            using (var reader = new StreamReader(SrtFile.OpenReadStream()))
            {
                while (!reader.EndOfStream)
                {
                    string lineText = await reader.ReadLineAsync();

                    if (lineText.Contains("-->"))
                    {
                        Offset = Offset.Replace(",", ".");
                        TimeSpan.TryParseExact(Offset, @"hh\:mm\:ss\.fff", null, out TimeSpan offsetTime);

                        DateTime firstTimeCode = DateTime.Parse(lineText.Replace(",", ".").Substring(0, 12));
                        DateTime lastTimeCode  = DateTime.Parse(lineText.Replace(",", ".").Substring(17));
                        firstTimeCode = firstTimeCode.Add(offsetTime);
                        lastTimeCode  = lastTimeCode.Add(offsetTime);

                        lineText = $"{firstTimeCode.ToString("HH:mm:ss,fff")} --> {lastTimeCode.ToString("HH:mm:ss,fff")}";
                    }

                    result.AppendLine(lineText);
                }
                OffsetResult = result.ToString();
            }
        }
예제 #2
0
        private async Task <bool> FileSignatureIsNotTrusted()
        {
            using (var reader = new StreamReader(SrtFile.OpenReadStream()))
            {
                int loopCount = 1;
                int tries     = 5;

                while (!reader.EndOfStream && loopCount < 4)
                {
                    string lineText = await reader.ReadLineAsync();

                    if (int.TryParse(lineText, out int subtitleOrder))
                    {
                        if (subtitleOrder == loopCount)
                        {
                            loopCount++;
                            tries = 5;
                            continue;
                        }
                        else
                        {
                            continue;
                        }
                    }
                    else if (loopCount == 1)
                    {
                        return(true);
                    }
                    else if (tries == 0)
                    {
                        return(true);
                    }
                    else
                    {
                        tries--;
                        continue;
                    }
                }

                return(false);
            }
        }