From 171fb6048515a871ecf5a47cb716a568374bbf44 Mon Sep 17 00:00:00 2001 From: tautcony Date: Tue, 9 May 2017 21:45:24 +0800 Subject: [PATCH 01/24] Avoid chinese in HTTP header. --- Time_Shift/Util/Updater.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Time_Shift/Util/Updater.cs b/Time_Shift/Util/Updater.cs index 31d1280..3fd1069 100644 --- a/Time_Shift/Util/Updater.cs +++ b/Time_Shift/Util/Updater.cs @@ -25,6 +25,7 @@ using System.Reflection; using System.Windows.Forms; using System.Globalization; +using System.Linq; using System.Runtime.InteropServices; using System.Text.RegularExpressions; @@ -78,7 +79,8 @@ public static void CheckUpdate() #if DEBUG webRequest = (HttpWebRequest)WebRequest.Create("http://127.0.0.1:4000/tcupdate.html"); #endif - webRequest.UserAgent = $"{Environment.UserName}({Environment.OSVersion}) / {Assembly.GetExecutingAssembly().GetName().FullName}"; + var userName = Environment.UserName.ToCharArray().Aggregate("", (current, c) => current + $"{(int)c:X} "); + webRequest.UserAgent = $"{userName}({Environment.OSVersion}) / {Assembly.GetExecutingAssembly().GetName().FullName}"; webRequest.Method = "GET"; webRequest.Credentials = CredentialCache.DefaultCredentials; webRequest.BeginGetResponse(OnResponse, webRequest); From ac1767072bec9ecdd82fcfbc01220eff41591e02 Mon Sep 17 00:00:00 2001 From: tautcony Date: Thu, 11 May 2017 13:42:00 +0800 Subject: [PATCH 02/24] Use hard link to avoid garbled path string while calling mp4v2. --- Time_Shift/Forms/Form1.cs | 6 ++++-- Time_Shift/Util/NativeMethods.cs | 26 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/Time_Shift/Forms/Form1.cs b/Time_Shift/Forms/Form1.cs index e2643a4..de4f41b 100644 --- a/Time_Shift/Forms/Form1.cs +++ b/Time_Shift/Forms/Form1.cs @@ -578,11 +578,12 @@ private void LoadMp4() } return; } + var linkedFile = Path.Combine(Path.GetPathRoot(FilePath) ?? "", Guid.NewGuid().ToString()); try { Knuckleball.ChapterList.OnLog += Log; - var mp4 = new Mp4Data(FilePath); - _info = mp4.Chapter; + NativeMethods.CreateHardLinkCMD(linkedFile, FilePath); + _info = new Mp4Data(linkedFile).Chapter; } catch (Exception exception) { @@ -591,6 +592,7 @@ private void LoadMp4() finally { Knuckleball.ChapterList.OnLog -= Log; + if (File.Exists(linkedFile)) File.Delete(linkedFile); } } diff --git a/Time_Shift/Util/NativeMethods.cs b/Time_Shift/Util/NativeMethods.cs index 2671fc3..6196553 100644 --- a/Time_Shift/Util/NativeMethods.cs +++ b/Time_Shift/Util/NativeMethods.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics; using System.Runtime.InteropServices; using System.Windows.Forms; @@ -55,5 +56,30 @@ public static void RefreshNotify() { SHChangeNotify(0x8000000, 0, IntPtr.Zero, IntPtr.Zero); } + + [DllImport("Kernel32.dll", EntryPoint = "CreateHardLinkW", CharSet = CharSet.Unicode)] + private static extern bool CreateHardLink(string lpFileName, string lpExistingFileName, IntPtr lpSecurityAttributes); + + public static bool CreateHardLink(string lpFileName, string lpExistingFileName) + { + return CreateHardLink(lpFileName, lpExistingFileName, IntPtr.Zero); + } + + public static void CreateHardLinkCMD(string lpFileName, string lpExistingFileName) + { + var process = new Process + { + StartInfo = new ProcessStartInfo + { + FileName = "fsutil", + Arguments = $"hardlink create \"{lpFileName}\" \"{lpExistingFileName}\"", + RedirectStandardOutput = true, + UseShellExecute = false, + CreateNoWindow = true + } + }; + process.Start(); + process.WaitForExit(); + } } } From 48656b7af6089aa8b2bd18659e8ae556d78c52c3 Mon Sep 17 00:00:00 2001 From: tautcony Date: Thu, 11 May 2017 13:42:33 +0800 Subject: [PATCH 03/24] Use some new grammar. --- Time_Shift/Forms/Form1.cs | 16 +++++++-------- Time_Shift/Knuckleball/Chapter.cs | 10 ++-------- Time_Shift/Knuckleball/ChapterList.cs | 5 +---- Time_Shift/Util/ChapterInfo.cs | 2 +- Time_Shift/Util/CueSharp.cs | 28 ++++++++------------------- 5 files changed, 20 insertions(+), 41 deletions(-) diff --git a/Time_Shift/Forms/Form1.cs b/Time_Shift/Forms/Form1.cs index de4f41b..96ddd16 100644 --- a/Time_Shift/Forms/Form1.cs +++ b/Time_Shift/Forms/Form1.cs @@ -321,8 +321,8 @@ private void Form1_DragEnter(object sender, DragEventArgs e) private string FilePath { - get { return _paths[0]; } - set { _paths[0] = value; } + get => _paths[0]; + set => _paths[0] = value; } private bool IsPathValid @@ -366,13 +366,13 @@ private enum FileType private static readonly Lazy MainFilter = new Lazy(() => { - Func, string> getType = enumerable => enumerable.Aggregate(string.Empty, (current, type) => current + $"*.{type};"); + string GetType(IEnumerable enumerable) => enumerable.Aggregate(string.Empty, (current, type) => current + $"*.{type};"); var ret = new StringBuilder(Resources.File_Filter_All_Support); - var types = getType(SupportTypes.SelectMany(supportType => supportType.Value)); + var types = GetType(SupportTypes.SelectMany(supportType => supportType.Value)); ret.Append($" ({types.TrimEnd(';')})|{types}"); foreach (var supportType in SupportTypes) { - types = getType(supportType.Value); + types = GetType(supportType.Value); ret.Append($"|{supportType.Key} ({types.TrimEnd(';')})|{types}"); } return ret.ToString(); @@ -403,8 +403,8 @@ private void btnLoad_Click(object sender, EventArgs e) private bool CombineChapter { - get { return combineToolStripMenuItem.Checked; } - set { combineToolStripMenuItem.Checked = value; } + get => combineToolStripMenuItem.Checked; + set => combineToolStripMenuItem.Checked = value; } private bool Loadfile() @@ -1292,7 +1292,7 @@ private void Form1_FormClosing(object sender, FormClosingEventArgs e) #region form resize private bool ExtensionPanelShow { - set { panel1.Visible = value; } + set => panel1.Visible = value; } private void btnExpand_Click(object sender, EventArgs e) => Form1_Resize(); diff --git a/Time_Shift/Knuckleball/Chapter.cs b/Time_Shift/Knuckleball/Chapter.cs index 2e8c668..2d306e8 100644 --- a/Time_Shift/Knuckleball/Chapter.cs +++ b/Time_Shift/Knuckleball/Chapter.cs @@ -39,10 +39,7 @@ public class Chapter /// public string Title { - get - { - return title; - } + get => title; set { @@ -59,10 +56,7 @@ public string Title /// public TimeSpan Duration { - get - { - return duration; - } + get => duration; set { diff --git a/Time_Shift/Knuckleball/ChapterList.cs b/Time_Shift/Knuckleball/ChapterList.cs index 180e169..ff91e32 100644 --- a/Time_Shift/Knuckleball/ChapterList.cs +++ b/Time_Shift/Knuckleball/ChapterList.cs @@ -64,10 +64,7 @@ private ChapterList() /// value to be set is already in the list public Chapter this[int index] { - get - { - return chapters[index]; - } + get => chapters[index]; set { diff --git a/Time_Shift/Util/ChapterInfo.cs b/Time_Shift/Util/ChapterInfo.cs index 516103d..a2094cb 100644 --- a/Time_Shift/Util/ChapterInfo.cs +++ b/Time_Shift/Util/ChapterInfo.cs @@ -50,7 +50,7 @@ public class ChapterInfo public Type TagType { get; set; } public object Tag { - get { return _tag; } + get => _tag; set { if (value == null) diff --git a/Time_Shift/Util/CueSharp.cs b/Time_Shift/Util/CueSharp.cs index 7e94c8f..f9baf12 100644 --- a/Time_Shift/Util/CueSharp.cs +++ b/Time_Shift/Util/CueSharp.cs @@ -37,14 +37,8 @@ public class CueSheet /// Track at the tracknumber. public Track this[int tracknumber] { - get - { - return Tracks[tracknumber]; - } - set - { - Tracks[tracknumber] = value; - } + get => Tracks[tracknumber]; + set => Tracks[tracknumber] = value; } /// @@ -831,7 +825,7 @@ public struct Index /// public int Number { - get { return _number; } + get => _number; set { if (value > 99) @@ -854,7 +848,7 @@ public int Number /// public int Minutes { - get { return _minutes; } + get => _minutes; set { if (value > 99) @@ -878,7 +872,7 @@ public int Minutes /// public int Seconds { - get { return _seconds; } + get => _seconds; set { if (value >= 60) @@ -902,7 +896,7 @@ public int Seconds /// public int Frames { - get { return _frames; } + get => _frames; set { if (value >= 75) @@ -1030,14 +1024,8 @@ public struct Track /// Index at indexnumber. public Index this[int indexnumber] { - get - { - return Indices[indexnumber]; - } - set - { - Indices[indexnumber] = value; - } + get => Indices[indexnumber]; + set => Indices[indexnumber] = value; } public string[] Comments { get; set; } From 3847666e4be698e1efc568c702ea57ae4d6eae7f Mon Sep 17 00:00:00 2001 From: tautcony Date: Thu, 11 May 2017 15:31:38 +0800 Subject: [PATCH 04/24] Simplify the ChapterList in mp4 files. --- Time_Shift/Forms/Form1.cs | 4 +- Time_Shift/Knuckleball/Chapter.cs | 20 +- Time_Shift/Knuckleball/ChapterList.cs | 323 ------------------------ Time_Shift/Knuckleball/MP4File.cs | 85 ++++++- Time_Shift/Knuckleball/NativeMethods.cs | 4 +- Time_Shift/Time_Shift.csproj | 1 - 6 files changed, 85 insertions(+), 352 deletions(-) delete mode 100644 Time_Shift/Knuckleball/ChapterList.cs diff --git a/Time_Shift/Forms/Form1.cs b/Time_Shift/Forms/Form1.cs index 96ddd16..3460497 100644 --- a/Time_Shift/Forms/Form1.cs +++ b/Time_Shift/Forms/Form1.cs @@ -581,7 +581,7 @@ private void LoadMp4() var linkedFile = Path.Combine(Path.GetPathRoot(FilePath) ?? "", Guid.NewGuid().ToString()); try { - Knuckleball.ChapterList.OnLog += Log; + Knuckleball.MP4File.OnLog += Log; NativeMethods.CreateHardLinkCMD(linkedFile, FilePath); _info = new Mp4Data(linkedFile).Chapter; } @@ -591,7 +591,7 @@ private void LoadMp4() } finally { - Knuckleball.ChapterList.OnLog -= Log; + Knuckleball.MP4File.OnLog -= Log; if (File.Exists(linkedFile)) File.Delete(linkedFile); } } diff --git a/Time_Shift/Knuckleball/Chapter.cs b/Time_Shift/Knuckleball/Chapter.cs index 2d306e8..ec23355 100644 --- a/Time_Shift/Knuckleball/Chapter.cs +++ b/Time_Shift/Knuckleball/Chapter.cs @@ -22,12 +22,8 @@ namespace Knuckleball /// public class Chapter { - /// - /// Gets the internal ID of this Chapter. - /// - internal Guid Id { get; } = Guid.NewGuid(); - private string title = string.Empty; - private TimeSpan duration = TimeSpan.FromSeconds(0); + private string _title = string.Empty; + private TimeSpan _duration = TimeSpan.FromSeconds(0); /// /// Occurs when the value of any property is changed. @@ -39,13 +35,13 @@ public class Chapter /// public string Title { - get => title; + get => _title; set { - if (title != value) + if (_title != value) { - title = value; + _title = value; OnChanged(new EventArgs()); } } @@ -56,13 +52,13 @@ public string Title /// public TimeSpan Duration { - get => duration; + get => _duration; set { - if (duration != value) + if (_duration != value) { - duration = value; + _duration = value; OnChanged(new EventArgs()); } } diff --git a/Time_Shift/Knuckleball/ChapterList.cs b/Time_Shift/Knuckleball/ChapterList.cs deleted file mode 100644 index ff91e32..0000000 --- a/Time_Shift/Knuckleball/ChapterList.cs +++ /dev/null @@ -1,323 +0,0 @@ -// ----------------------------------------------------------------------- -// -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at http://mozilla.org/MPL/2.0/. -// -// Portions created by Jim Evans are Copyright © 2012. -// All Rights Reserved. -// -// Contributors: -// Jim Evans, james.h.evans.jr@@gmail.com -// -// -// ----------------------------------------------------------------------- - -using System; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Runtime.InteropServices; -using System.Text; - -namespace Knuckleball -{ - /// - /// Represents the collection of chapters in a file, tracking whether there have - /// been changes made to the collection. - /// - [SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix", Justification = "ChapterList object has List (ordered) semantics, so a suffix of List is correct.")] - public sealed class ChapterList : IList - { - private List chapters = new List(); - private HashSet hashedIndex = new HashSet(); - - public static event Action OnLog; - - /// - /// Prevents a default instance of the class from being created. - /// - private ChapterList() - { - } - - /// - /// Gets the number of Chapters contained in this . - /// - public int Count => chapters.Count; - - /// - /// Gets a value indicating whether this is read-only. - /// - bool ICollection.IsReadOnly => false; - - /// - /// Gets or sets a value indicating whether this has been modified since being loaded. - /// - private bool IsDirty { get; set; } - - /// - /// Gets or sets the at the specified index. - /// - /// The zero-based index of the to get or set. - /// The at the specified index. - /// value to be set is - /// value to be set is already in the list - public Chapter this[int index] - { - get => chapters[index]; - - set - { - if (value == null) - { - throw new ArgumentNullException(nameof(value)); - } - - if (hashedIndex.Contains(value.Id)) - { - throw new ArgumentException("Chapter is already in the chapter list", nameof(value)); - } - - chapters[index] = value; - value.Changed += OnChapterChanged; - hashedIndex.Add(value.Id); - IsDirty = true; - } - } - - /// - /// Adds a to this . - /// - /// The to add. - /// is - /// is already in the list - public void Add(Chapter item) - { - if (item == null) - { - throw new ArgumentNullException(nameof(item)); - } - - if (hashedIndex.Contains(item.Id)) - { - throw new ArgumentException("Chapter is already in the chapter list", nameof(item)); - } - - chapters.Add(item); - item.Changed += OnChapterChanged; - hashedIndex.Add(item.Id); - IsDirty = true; - } - - /// - /// Removes all items from this - /// - public void Clear() - { - if (Count > 0) - { - hashedIndex.Clear(); - chapters.Clear(); - IsDirty = true; - } - } - - /// - /// Determines whether this contains a specific . - /// - /// The to locate in the . - /// if is found in the ; - /// otherwise, . - public bool Contains(Chapter item) - { - return hashedIndex.Contains(item.Id); - } - - /// - /// Copies the Chapters of this to an , - /// starting at a particular index. - /// - /// The one-dimensional that is the destination of the - /// Chapters copied from this . The - /// must have zero-based indexing. - /// The zero-based index in at which copying begins. - /// is . - /// is less than 0. - /// The number of elements in this is greater - /// than the available space from to the end of the destination . - public void CopyTo(Chapter[] array, int arrayIndex) - { - chapters.CopyTo(array, arrayIndex); - } - - /// - /// Determines the index of a in this - /// - /// The to locate in the - /// The index of if found in the list; otherwise, -1. - public int IndexOf(Chapter item) - { - if (!hashedIndex.Contains(item.Id)) - { - return -1; - } - return chapters.IndexOf(item); - } - - /// - /// Inserts an item to this at the specified index. - /// - /// The zero-based index at which should be inserted. - /// The to insert into the - /// is - /// is less than 0, - /// or is greater than . - /// is alrady in the list - public void Insert(int index, Chapter item) - { - if (item == null) - { - throw new ArgumentNullException(nameof(item)); - } - - if (hashedIndex.Contains(item.Id)) - { - throw new ArgumentException("Chapter is already in the chapter list", nameof(item)); - } - - chapters.Insert(index, item); - item.Changed += OnChapterChanged; - hashedIndex.Add(item.Id); - IsDirty = true; - } - - /// - /// Removes the first occurrence of a specific from the . - /// - /// The to remove from the . - /// if was successfully removed from the - /// ; otherwise, false. This method also returns - /// if is not found in the original. - public bool Remove(Chapter item) - { - var isRemoved = chapters.Remove(item); - IsDirty = IsDirty || isRemoved; - if (isRemoved) - { - item.Changed -= OnChapterChanged; - hashedIndex.Remove(item.Id); - } - return isRemoved; - } - - /// - /// Removes the at the specified index. - /// - /// The zero-based index of the to remove. - /// is less than 0, - /// or is greater than . - public void RemoveAt(int index) - { - var toRemove = this[index]; - hashedIndex.Remove(toRemove.Id); - toRemove.Changed -= OnChapterChanged; - chapters.RemoveAt(index); - IsDirty = true; - } - - /// - /// Returns an enumerator that iterates through a . - /// - /// An object that can be used to iterate - /// through the . - public IEnumerator GetEnumerator() - { - return chapters.GetEnumerator(); - } - - /// - /// Returns an enumerator that iterates through a . - /// - /// An object that can be used to iterate - /// through the . - System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() - { - return chapters.GetEnumerator(); - } - - /// - /// Reads the chapter information from the specified file. - /// - /// The handle to the file from which to read the chapter information. - /// A new instance of a object containing the information - /// about the chapters for the file. - internal static ChapterList ReadFromFile(IntPtr fileHandle) - { - var list = new ChapterList(); - var chapterListPointer = IntPtr.Zero; - var chapterCount = 0; - var chapterType = NativeMethods.MP4GetChapters(fileHandle, ref chapterListPointer, ref chapterCount, NativeMethods.MP4ChapterType.Any); - OnLog?.Invoke($"Chapter type: {chapterType}"); - if (chapterType != NativeMethods.MP4ChapterType.None && chapterCount != 0) - { - var currentChapterPointer = chapterListPointer; - for (var i = 0; i < chapterCount; ++i) - { - var currentChapter = currentChapterPointer.ReadStructure(); - var duration = TimeSpan.FromMilliseconds(currentChapter.duration); - var title = GetString(currentChapter.title); - OnLog?.Invoke($"{title} {duration}"); - list.AddInternal(new Chapter { Duration = duration, Title = title }); - currentChapterPointer = IntPtr.Add(currentChapterPointer, Marshal.SizeOf(currentChapter)); - } - } - else - { - /*int timeScale = NativeMethods.MP4GetTimeScale(fileHandle); - long duration = NativeMethods.MP4GetDuration(fileHandle); - list.AddInternal(new Chapter { Duration = TimeSpan.FromSeconds(duration / (double)timeScale), Title = "Chapter 1" });*/ - list.AddInternal(new Chapter { Duration = TimeSpan.Zero, Title = "Chapter 1" }); - } - if (chapterListPointer != IntPtr.Zero) - { - NativeMethods.MP4Free(chapterListPointer); - } - return list; - } - - /// - /// Decodes a C-Style string into a string, can handle UTF-8 or UTF-16 encoding. - /// - /// C-Style string - /// - private static string GetString(byte[] bytes) - { - var title = Encoding.UTF8.GetString(bytes); - if (bytes[0] == 0xFF && bytes[1] == 0xFE) - { - title = Encoding.Unicode.GetString(bytes); - } - else if (bytes[0] == 0xFE && bytes[1] == 0xFF) - { - title = Encoding.BigEndianUnicode.GetString(bytes); - } - return title.Substring(0, title.IndexOf('\0')); - } - - /// - /// Adds a to the list without dirtying the list. - /// - /// The to add to the list. - private void AddInternal(Chapter toAdd) - { - chapters.Add(toAdd); - toAdd.Changed += OnChapterChanged; - hashedIndex.Add(toAdd.Id); - } - - private void OnChapterChanged(object sender, EventArgs e) - { - IsDirty = true; - } - } -} diff --git a/Time_Shift/Knuckleball/MP4File.cs b/Time_Shift/Knuckleball/MP4File.cs index 30adab1..b560d75 100644 --- a/Time_Shift/Knuckleball/MP4File.cs +++ b/Time_Shift/Knuckleball/MP4File.cs @@ -13,7 +13,10 @@ // // ----------------------------------------------------------------------- using System; +using System.Collections.Generic; using System.IO; +using System.Runtime.InteropServices; +using System.Text; namespace Knuckleball { @@ -22,8 +25,9 @@ namespace Knuckleball /// public class MP4File { - private string fileName; - private ChapterList chapters; + private readonly string _fileName; + + public static event Action OnLog; /// /// Prevents a default instance of the class from being created. @@ -43,13 +47,13 @@ private MP4File(string fileName) throw new ArgumentException("Must specify a valid file name", nameof(fileName)); } - this.fileName = fileName; + _fileName = fileName; } /// /// Gets the list of chapters for this file. /// - public ChapterList Chapters => chapters; + public List Chapters { get; private set; } /// /// Opens and reads the data for the specified file. @@ -71,18 +75,75 @@ public static MP4File Open(string fileName) /// public void Load() { - var fileHandle = NativeMethods.MP4Read(fileName); - if (fileHandle != IntPtr.Zero) + var fileHandle = NativeMethods.MP4Read(_fileName); + if (fileHandle == IntPtr.Zero) return; + try { - try - { - chapters = ChapterList.ReadFromFile(fileHandle); - } - finally + Chapters = ReadFromFile(fileHandle); + } + finally + { + NativeMethods.MP4Close(fileHandle); + } + } + + /// + /// Reads the chapter information from the specified file. + /// + /// The handle to the file from which to read the chapter information. + /// A new instance of a object containing the information + /// about the chapters for the file. + internal static List ReadFromFile(IntPtr fileHandle) + { + var list = new List(); + var chapterListPointer = IntPtr.Zero; + var chapterCount = 0; + var chapterType = NativeMethods.MP4GetChapters(fileHandle, ref chapterListPointer, ref chapterCount, NativeMethods.MP4ChapterType.Any); + OnLog?.Invoke($"Chapter type: {chapterType}"); + if (chapterType != NativeMethods.MP4ChapterType.None && chapterCount != 0) + { + var currentChapterPointer = chapterListPointer; + for (var i = 0; i < chapterCount; ++i) { - NativeMethods.MP4Close(fileHandle); + var currentChapter = currentChapterPointer.ReadStructure(); + var duration = TimeSpan.FromMilliseconds(currentChapter.duration); + var title = GetString(currentChapter.title); + OnLog?.Invoke($"{title} {duration}"); + list.Add(new Chapter { Duration = duration, Title = title }); + currentChapterPointer = IntPtr.Add(currentChapterPointer, Marshal.SizeOf(currentChapter)); } } + else + { + var timeScale = NativeMethods.MP4GetTimeScale(fileHandle); + var duration = NativeMethods.MP4GetDuration(fileHandle); + list.Add(new Chapter { Duration = TimeSpan.FromSeconds(duration / (double)timeScale), Title = "Chapter 1" }); + } + if (chapterListPointer != IntPtr.Zero) + { + NativeMethods.MP4Free(chapterListPointer); + } + return list; } + + /// + /// Decodes a C-Style string into a string, can handle UTF-8 or UTF-16 encoding. + /// + /// C-Style string + /// + private static string GetString(byte[] bytes) + { + if (bytes == null) return null; + string title = null; + if (bytes.Length <= 3) title = Encoding.UTF8.GetString(bytes); + if (bytes[0] == 0xFF && bytes[1] == 0xFE) title = Encoding.Unicode.GetString(bytes); + if (bytes[0] == 0xFE && bytes[1] == 0xFF) title = Encoding.BigEndianUnicode.GetString(bytes); + if (bytes[0] == 0xEF && bytes[1] == 0xBB && bytes[2] == 0xBF) + title = new UTF8Encoding(false).GetString(bytes, 3, bytes.Length - 3); + else if (title == null) title = Encoding.UTF8.GetString(bytes); + + return title.Substring(0, title.IndexOf('\0')); + } + } } diff --git a/Time_Shift/Knuckleball/NativeMethods.cs b/Time_Shift/Knuckleball/NativeMethods.cs index d47103c..0f8b7e1 100644 --- a/Time_Shift/Knuckleball/NativeMethods.cs +++ b/Time_Shift/Knuckleball/NativeMethods.cs @@ -73,13 +73,13 @@ internal enum MP4ChapterType [DllImport("libMP4V2.dll", CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true, CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.I4)] internal static extern MP4ChapterType MP4GetChapters(IntPtr hFile, ref IntPtr chapterList, ref int chapterCount, MP4ChapterType chapterType); - /* + [DllImport("libMP4V2.dll", CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true, CallingConvention = CallingConvention.Cdecl)] internal static extern long MP4GetDuration(IntPtr hFile); [DllImport("libMP4V2.dll", CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true, CallingConvention = CallingConvention.Cdecl)] internal static extern int MP4GetTimeScale(IntPtr hFile); - */ + /// /// Represents information for a chapter in this file. /// diff --git a/Time_Shift/Time_Shift.csproj b/Time_Shift/Time_Shift.csproj index 85c0dcd..e1229b1 100644 --- a/Time_Shift/Time_Shift.csproj +++ b/Time_Shift/Time_Shift.csproj @@ -122,7 +122,6 @@ FormUpdater.cs - From ef3d84f98bec34eab7360cbebcc18884073f99d2 Mon Sep 17 00:00:00 2001 From: tautcony Date: Thu, 11 May 2017 15:32:08 +0800 Subject: [PATCH 05/24] Update the README. --- README.md | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index f96db25..3ae0ac9 100644 --- a/README.md +++ b/README.md @@ -1,25 +1,28 @@ # ChapterTool [![Build status](https://ci.appveyor.com/api/projects/status/rtc76h5ulveafj5f?svg=true)](https://ci.appveyor.com/project/tautcony/chaptertool) -- ChapterTool is made for extracting chapter from DVD, HDDVD, BluRay discs, matroska file and many other type of files and edit it. -- It's only in Chinese currently - +- ChapterTool is made for extracting chapter from various types of files and edit it. +- It's only in Chinese currently. ## Feature -- Extract chapter file from various files -- Adjust first chapter's begining time to zero -- Revise chapter time which extract by DVD Decrypter manually -- Move all time backward optionally e.g. 00:23:23.233 -- Move all chapter number backward optionally +- Extract chapter file from various types of file +- Freely time adjustment(expression in Infix notation or Reverse Polish notation) +- Move all chapter number backward optionally(for OGM format) - Load chapter name from a text file as template -- Calculate frames by chapter file -- Save in multiple formats: txt, xml, and more - +- Calculate frames from chapter time +- Supported save formats: `.txt`, `.xml`, `.qpf`, `.json` -## Install - -- You must have .NET Framework 4.6 available from Windows Update. +### Supported file type +- OGM(`.txt`) +- XML(`.xml`) +- MPLS from BluRay(`.mpls`) +- IFO from DVD(`.ifo`) +- XPL from HDDVD(`.xpl`) +- CUE plain text or embedded(`.cue`, `.flac`, `.tak`) +- Matroska file(`.mkv`, `.mka`) +- Mp4 file(`.mp4`, `.m4a`, `.m4v`) +- WebVTT(`.vtt`) ## Thanks to @@ -31,7 +34,14 @@ - [libbluray](http://www.videolan.org/developers/libbluray.html) - [BDedit](http://pel.hu/bdedit/) - [Knuckleball](https://github.com/jimevans/knuckleball) + - [mp4v2](https://code.google.com/archive/p/mp4v2/) + - [BluRay](https://github.com/lerks/BluRay) + +## Requirements +- You must have `.NET Framework 4.6` available from Windows Update. +- The matroska file's support is powerd by [`MKVToolNix`](https://mkvtoolnix.download/downloads.html#windows). +- The mp4 file's support is powerd by `libmp4v2`, you need get the dll before using this feature. ## Source Code From 48353d0ea0ff182963b1374fafc207507f498a32 Mon Sep 17 00:00:00 2001 From: tautcony Date: Thu, 11 May 2017 16:44:51 +0800 Subject: [PATCH 06/24] Finally the language switch has been implemented. --- Time_Shift/Forms/Form1.Designer.cs | 15 +- Time_Shift/Forms/Form1.cs | 36 +- Time_Shift/Forms/Form1.en-US.resx | 69 +-- Time_Shift/Forms/Form1.resx | 541 ++------------------ Time_Shift/Properties/Resources.Designer.cs | 27 +- Time_Shift/Properties/Resources.en-US.resx | 13 +- Time_Shift/Properties/Resources.resx | 9 +- 7 files changed, 116 insertions(+), 594 deletions(-) diff --git a/Time_Shift/Forms/Form1.Designer.cs b/Time_Shift/Forms/Form1.Designer.cs index dab5d8f..316c977 100644 --- a/Time_Shift/Forms/Form1.Designer.cs +++ b/Time_Shift/Forms/Form1.Designer.cs @@ -166,13 +166,13 @@ private void InitializeComponent() this.comboBox1.ForeColor = System.Drawing.SystemColors.WindowText; this.comboBox1.FormattingEnabled = true; this.comboBox1.Items.AddRange(new object[] { - resources.GetString("comboBox1.Items"), - resources.GetString("comboBox1.Items1"), - resources.GetString("comboBox1.Items2"), - resources.GetString("comboBox1.Items3"), - resources.GetString("comboBox1.Items4"), - resources.GetString("comboBox1.Items5"), - resources.GetString("comboBox1.Items6")}); + "24000 / 1001", + "24000 / 1000", + "25000 / 1000", + "30000 / 1001", + "RESER / VED", + "50000 / 1000", + "60000 / 1001"}); this.comboBox1.Name = "comboBox1"; this.comboBox1.TabStop = false; this.comboBox1.SelectionChangeCommitted += new System.EventHandler(this.comboBox1_SelectionChangeCommitted); @@ -374,6 +374,7 @@ private void InitializeComponent() this.btnPreview.FlatAppearance.MouseOverBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(207)))), ((int)(((byte)(207)))), ((int)(((byte)(207))))); resources.ApplyResources(this.btnPreview, "btnPreview"); this.btnPreview.Name = "btnPreview"; + this.btnPreview.Text = "P"; this.btnPreview.TabStop = false; this.btnPreview.UseVisualStyleBackColor = true; this.btnPreview.Click += new System.EventHandler(this.btnPreview_Click); diff --git a/Time_Shift/Forms/Form1.cs b/Time_Shift/Forms/Form1.cs index 3460497..8bdebcf 100644 --- a/Time_Shift/Forms/Form1.cs +++ b/Time_Shift/Forms/Form1.cs @@ -45,16 +45,16 @@ public partial class Form1 : Form #region Form1 public Form1() { + const string key = "Language"; + var lang = RegistryStorage.Load(name: key); + if (!string.IsNullOrEmpty(lang)) + { + LanguageHelper.SetLang(lang, this, typeof(Form1)); + } InitializeComponent(); AddCommand(); Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath); - /* - LanguageHelper.SetLang("en-US", this, typeof(Form1)); - LanguageHelper.SetLang("en-US", deviationMenuStrip, typeof(Form1)); - LanguageHelper.SetLang("en-US", combineMenuStrip, typeof(Form1)); - LanguageHelper.SetLang("en-US", createZonestMenuStrip, typeof(Form1)); - LanguageHelper.SetLang("en-US", loadMenuStrip, typeof(Form1)); - */ + } public Form1(string args) @@ -204,8 +204,7 @@ private void InsertAccuracyItems() private static void InitialLog() { - Log(Environment.UserName.ToLowerInvariant().IndexOf("yzy", StringComparison.Ordinal) > 0 - ? Resources.Log_Wu_Zong : $"{Environment.UserName}{Resources.Log_Hello}"); + Log($"{Environment.UserName}{Resources.Log_Hello}"); Log($"{Environment.OSVersion}"); if (!IsRunningOnMono) Log(NativeMethods.IsUserAnAdmin() ? Resources.Log_With_Admin : Resources.Log_Without_Admin); @@ -253,6 +252,23 @@ private void AddCommand() if (IsRunningOnMono) return; _systemMenu = new SystemMenu(this); _systemMenu.AddCommand(Resources.Update_Check, Updater.CheckUpdate, true); + var resPath = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath) ?? "", "en-US"); + if (Directory.Exists(resPath)) + { + _systemMenu.AddCommand(Resources.Menu_Switch_Language, () => + { + if (!File.Exists(Path.Combine(resPath, "ChapterTool.resources.dll"))) + { + Notification.ShowInfo("No valid language resource file found"); + return; + } + const string key = "Language"; + var lang = RegistryStorage.Load(name: key) ?? ""; + RegistryStorage.Save(name: key, value: string.IsNullOrEmpty(lang) ? "en-US" : ""); + Process.Start(Application.ExecutablePath); + Process.GetCurrentProcess().Kill(); + }, true); + } } protected override void WndProc(ref Message msg) @@ -537,7 +553,7 @@ private void LoadIfo() } else { - textBoxExpression.Text = @"t * 1.001 //修正DVD时间"; + textBoxExpression.Text = Resources.Expression_factor_1001; cbShift.Checked = true; tsTips.Text = Resources.Tips_IFO_Waring_Fixed; } diff --git a/Time_Shift/Forms/Form1.en-US.resx b/Time_Shift/Forms/Form1.en-US.resx index 14885ae..b915132 100644 --- a/Time_Shift/Forms/Form1.en-US.resx +++ b/Time_Shift/Forms/Form1.en-US.resx @@ -140,7 +140,7 @@ Save - Auto Gen + Auto name Rename the chapter name from Chapter 01 @@ -161,7 +161,7 @@ 169, 22 - tolerance scope + Tolerance scope 72, 17 @@ -173,7 +173,7 @@ 81, 21 - Shift Time + Apply expr (t) 104, 21 @@ -250,54 +250,19 @@ RU5ErkJggg== - - - AAABAAMAEBAQAAAABAAoAQAANgAAACAgEAAAAAQA6AIAAF4BAAAwMBAAAAAEAGgGAABGBAAAKAAAABAA - AAAgAAAAAQAEAAAAAACAAAAAAAAAAAAAAAAQAAAAEAAAAAAAAAAAAIAAAIAAAACAgACAAAAAgACAAICA - AACAgIAAwMDAAAAA/wAA/wAAAP//AP8AAAD/AP8A//8AAP///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA - AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA - AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP//AACAAQAAtv0AALb9 - AACAbQAAtv0AALb9AACAbQAAtv0AALb9AACAAQAAtv8AALb/AACA/wAA//8AAP//AAAoAAAAIAAAAEAA - AAABAAQAAAAAAAACAAAAAAAAAAAAABAAAAAQAAAAAAAAAAAAgAAAgAAAAICAAIAAAACAAIAAgIAAAICA - gADAwMAAAAD/AAD/AAAA//8A/wAAAP8A/wD//wAA////AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA - AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA - AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA - AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA - AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA - AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA - AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA - AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA - AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA - AAAAAAAA///////////////////////////wAAAP8AAAD/Oc/8/znP/P85z/z/AAOc/wADnP85z/z/Oc - /8/znP/P8AA5z/AAOc/znP/P85z/z/Oc/8/wAAAP8AAAD/Oc///znP//85z///AA///wAP////////// - //////////////////8oAAAAMAAAAGAAAAABAAQAAAAAAIAEAAAAAAAAAAAAABAAAAAQAAAAAAAAAAAA - gAAAgAAAAICAAIAAAACAAIAAgIAAAMDAwACAgIAAAAD/AAD/AAAA//8A/wAAAP8A/wD//wAA////AAAA - AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA - AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA - AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA - AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA - AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA - AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA - AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA - AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA - AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA - AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA - AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA - AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA - AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA - AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA - AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA - AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA - AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA - AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA - AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA - AAAAAAAAAAAAAP///////wAA////////AAD///////8AAP///////wAA////////AAD///////8AAPAA - AAAADwAA8AAAAAAPAADwAAAAAA8AAPAAAAAADwAA8PDw//8PAADw8PD//w8AAPDw8P//DwAA8PDw//8P - AADwAAAPDw8AAPAAAA8PDwAA8AAADw8PAADwAAAPDw8AAPDw8P//DwAA8PDw//8PAADw8PD//w8AAPDw - 8P//DwAA8AAADw8PAADwAAAPDw8AAPAAAA8PDwAA8AAADw8PAADw8PD//w8AAPDw8P//DwAA8PDw//8P - AADw8PD//w8AAPAAAAAADwAA8AAAAAAPAADwAAAAAA8AAPAAAAAADwAA8PDw////AADw8PD///8AAPDw - 8P///wAA8PDw////AADwAAD///8AAPAAAP///wAA8AAA////AADwAAD///8AAP///////wAA//////// - AAD///////8AAP///////wAA////////AAD///////8AAA== - + + Please set the location to be saved + + + Open file + + + LOG + + + Insert the separator + + + # \ No newline at end of file diff --git a/Time_Shift/Forms/Form1.resx b/Time_Shift/Forms/Form1.resx index f34b13c..2ad5843 100644 --- a/Time_Shift/Forms/Form1.resx +++ b/Time_Shift/Forms/Form1.resx @@ -117,19 +117,13 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 1058, 20 - + + 1058, 20 + 125, 48 - - loadMenuStrip - - - System.Windows.Forms.ContextMenuStrip, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - Flat @@ -150,18 +144,6 @@ 载入 - - btnLoad - - - System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - $this - - - 14 - 124, 22 @@ -192,18 +174,6 @@ 保存 - - btnSave - - - System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - $this - - - 13 - 12, 9 @@ -213,18 +183,6 @@ 5 - - lbPath - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - $this - - - 12 - Flat @@ -240,24 +198,9 @@ 2 - - - - - btnTrans - - - System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - $this - - - 11 - - + 489, 18 - + Flat @@ -279,42 +222,9 @@ 将章节名重新从Chapter 01开始标记 - - cbAutoGenName - - - System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - panel1 - - - 7 - Flat - - 24000 / 1001 - - - 24000 / 1000 - - - 25000 / 1000 - - - 30000 / 1001 - - - RESER / VED - - - 50000 / 1000 - - - 60000 / 1001 - 447, 52 @@ -324,33 +234,15 @@ 11 - - comboBox1 - - - System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - $this - - - 10 - True - + 10, 15 - + 125, 26 - - deviationMenuStrip - - - System.Windows.Forms.ContextMenuStrip, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - Flat @@ -366,24 +258,9 @@ 帧数取整 - - 489, 18 - 右键菜单可设置误差范围 - - cbRound - - - System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - $this - - - 9 - 124, 22 @@ -399,18 +276,6 @@ 16 - - numericUpDown1 - - - System.Windows.Forms.NumericUpDown, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - panel1 - - - 11 - True @@ -426,18 +291,6 @@ 平移章节号 - - lbShift - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - panel1 - - - 10 - True @@ -456,18 +309,6 @@ 应用表达式 (t) - - cbShift - - - System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - panel1 - - - 8 - True @@ -492,30 +333,12 @@ 不取消勾选时将持续生效 - - cbChapterName - - - System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - panel1 - - - 6 - - + 590, 18 - + 125, 26 - - combineMenuStrip - - - System.Windows.Forms.ContextMenuStrip, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - Flat @@ -528,33 +351,21 @@ 23 - - comboBox2 - - - System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - $this - - - 8 - 124, 22 合并章节 - + 175, 15 - + 请设置所要保存的位置 - + 355, 15 - + 打开文件 @@ -576,18 +387,6 @@ 逆波兰表达式 - - cbPostFix - - - System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - panel1 - - - 0 - Flat @@ -603,30 +402,18 @@ LOG - - btnLog - - - System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - panel1 - - - 9 - - + True - - + + True - - + + True - - + + True - + 12, 83 @@ -636,48 +423,24 @@ 25 - - dataGridView1 - - - System.Windows.Forms.DataGridView, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - $this - - - 7 - - - True - - # + # 21 - - True - 时间点 57 - - True - 章节名 57 - - True - 帧数 @@ -696,18 +459,6 @@ 26 - - savingType - - - System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - panel1 - - - 3 - True @@ -723,18 +474,6 @@ 保存格式 - - lbFormat - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - panel1 - - - 2 - Flat @@ -750,21 +489,6 @@ 28 - - P - - - btnPreview - - - System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - $this - - - 6 - Flat @@ -777,18 +501,6 @@ 29 - - xmlLang - - - System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - panel1 - - - 5 - True @@ -804,30 +516,12 @@ XML语言 - - lbXmlLang - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - panel1 - - - 4 - - + 755, 18 - + 137, 70 - - createZonestMenuStrip - - - System.Windows.Forms.ContextMenuStrip, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - 136, 22 @@ -846,18 +540,6 @@ 插入分隔条 - - textBoxExpression - - - System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - panel1 - - - 1 - 12, 440 @@ -867,18 +549,6 @@ 32 - - panel1 - - - System.Windows.Forms.Panel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - $this - - - 5 - 303, 37 @@ -888,21 +558,9 @@ 31 - - textBoxExpression - - - System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - panel1 - - - 1 - - + 937, 20 - + 0, 511 @@ -912,27 +570,9 @@ 33 - - statusStrip1 - - - statusStrip1 - - - System.Windows.Forms.StatusStrip, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - $this - - - 4 - 443, 17 - - - MiddleLeft @@ -941,10 +581,9 @@ - iVBORw0KGgoAAAANSUhEUgAAABsAAAAbCAYAAACN1PRVAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 - YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAABQSURBVEhLYxgFo2AUjILhAZiAuA+IDxCBQepA6ikCQkB8 - Doj/48EgeZA6qgB8FlLVIhjAZiFNLIIBZAtpahEMgCxYAKVHwSgYBaOALoCBAQCARx+VJacCbgAAAABJ - RU5ErkJggg== + iVBORw0KGgoAAAANSUhEUgAAABsAAAAbCAYAAACN1PRVAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO + wwAADsMBx2+oZAAAAFBJREFUSEtjGAWjYBSMguEBmIC4D4gPEIFB6kDqKQJCQHwOiP/jwSB5kDqqAHwW + UtUiGMBmIU0sggFkC2lqEQyALFgApUfBKBgFo4AugIEBAIBHH5UlpwJuAAAAAElFTkSuQmCC @@ -953,15 +592,12 @@ 20, 20 - - toolStripDropDownButton1 - - + True - - + + 61 - + 96, 96 @@ -974,115 +610,4 @@ 3, 4, 3, 4 - - Chapter Tool - - - reloadToolStripMenuItem - - - System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - appendToolStripMenuItem - - - System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tsmAccuracy - - - System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - combineToolStripMenuItem - - - System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - folderBrowserDialog1 - - - System.Windows.Forms.FolderBrowserDialog, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - openFileDialog1 - - - System.Windows.Forms.OpenFileDialog, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - toolTip1 - - - System.Windows.Forms.ToolTip, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - cOrder - - - System.Windows.Forms.DataGridViewTextBoxColumn, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - cTimeCode - - - System.Windows.Forms.DataGridViewTextBoxColumn, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - cChapterName - - - System.Windows.Forms.DataGridViewTextBoxColumn, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - cFrams - - - System.Windows.Forms.DataGridViewTextBoxColumn, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - creatZonesToolStripMenuItem - - - System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - ShiftForwardToolStripMenuItem - - - System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - InsertSplitToolStripMenuItem - - - System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tsTips - - - System.Windows.Forms.ToolStripStatusLabel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tsProgressBar1 - - - System.Windows.Forms.ToolStripProgressBar, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tsBtnExpand - - - System.Windows.Forms.ToolStripDropDownButton, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - Form1 - - - System.Windows.Forms.Form, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - \ No newline at end of file diff --git a/Time_Shift/Properties/Resources.Designer.cs b/Time_Shift/Properties/Resources.Designer.cs index 3e7430f..19fdeac 100644 --- a/Time_Shift/Properties/Resources.Designer.cs +++ b/Time_Shift/Properties/Resources.Designer.cs @@ -80,6 +80,15 @@ internal static System.Drawing.Bitmap arrow_drop_up { } } + /// + /// 查找类似 t * 1.001 //修正DVD时间 的本地化字符串。 + /// + internal static string Expression_factor_1001 { + get { + return ResourceManager.GetString("Expression_factor_1001", resourceCulture); + } + } + /// /// 查找类似 所有文件 的本地化字符串。 /// @@ -521,15 +530,6 @@ internal static string Log_Without_Admin { } } - /// - /// 查找类似 武总好~ 的本地化字符串。 - /// - internal static string Log_Wu_Zong { - get { - return ResourceManager.GetString("Log_Wu_Zong", resourceCulture); - } - } - /// /// 查找类似 |+XPL中共有 {0} 个片段 的本地化字符串。 /// @@ -548,6 +548,15 @@ internal static string Menu_Open_File { } } + /// + /// 查找类似 Switch language 的本地化字符串。 + /// + internal static string Menu_Switch_Language { + get { + return ResourceManager.GetString("Menu_Switch_Language", resourceCulture); + } + } + /// /// 查找类似 ChapterTool Error 的本地化字符串。 /// diff --git a/Time_Shift/Properties/Resources.en-US.resx b/Time_Shift/Properties/Resources.en-US.resx index 8af1c9e..641e952 100644 --- a/Time_Shift/Properties/Resources.en-US.resx +++ b/Time_Shift/Properties/Resources.en-US.resx @@ -121,7 +121,7 @@ ChapterTool Error - File unloaded + No file loaded Load Success (≧▽≦) @@ -183,9 +183,6 @@ +Load form position {0} - - Hello, WuZong - Progress bar has been clicked {0} times @@ -346,6 +343,12 @@ Load failed… - Require .Net4.6 or higher to support all feature,no longer remind? + Require .Net4.6 or higher to support all feature,no longer remind? + + + 切换语言 + + + t * 1.001 //Fix time of DVD \ No newline at end of file diff --git a/Time_Shift/Properties/Resources.resx b/Time_Shift/Properties/Resources.resx index ee5c4e9..9ab031b 100644 --- a/Time_Shift/Properties/Resources.resx +++ b/Time_Shift/Properties/Resources.resx @@ -186,9 +186,6 @@ +成功载入保存的窗体位置 {0} - - 武总好~ - 点击了 {0} 次进度条 @@ -358,4 +355,10 @@ 需要 .Net4.6 或以上版本以保证所有功能正常运作,是否不再提示? + + Switch language + + + t * 1.001 //修正DVD时间 + \ No newline at end of file From eafa0d9d2b9b27f2dd11b309a3b78c6e00863057 Mon Sep 17 00:00:00 2001 From: tautcony Date: Fri, 26 May 2017 12:49:29 +0800 Subject: [PATCH 07/24] Move bitreader into a single class. --- Time_Shift/Util/ChapterData/FlacData.cs | 57 -------------------- Time_Shift/Util/ChapterData/StreamUtils.cs | 60 +++++++++++++++++++++- 2 files changed, 59 insertions(+), 58 deletions(-) diff --git a/Time_Shift/Util/ChapterData/FlacData.cs b/Time_Shift/Util/ChapterData/FlacData.cs index bea0868..8691514 100644 --- a/Time_Shift/Util/ChapterData/FlacData.cs +++ b/Time_Shift/Util/ChapterData/FlacData.cs @@ -191,61 +191,4 @@ private static void ParsePicture(Stream fs, ref FlacInfo info) OnLog?.Invoke($" | indexed-color color: {indexedColorCount}"); } } - - internal class BitReader - { - private readonly byte[] _buffer; - private int _bytePosition; - private int _bitPositionInByte; - - public int Position => _bytePosition * 8 + _bitPositionInByte; - - public BitReader(byte[] source) - { - _buffer = new byte[source.Length]; - Array.Copy(source, _buffer, source.Length); - } - - public void Reset() - { - _bytePosition = 0; - _bitPositionInByte = 0; - } - - public bool GetBit() - { - if (_bytePosition >= _buffer.Length) - throw new IndexOutOfRangeException(nameof(_bytePosition)); - var ret = ((_buffer[_bytePosition] >> (7 - _bitPositionInByte)) & 1) == 1; - Next(); - return ret; - } - - private void Next() - { - ++_bitPositionInByte; - if (_bitPositionInByte != 8) return; - _bitPositionInByte = 0; - ++_bytePosition; - } - - public void Skip(int length) - { - for (var i = 0; i < length; ++i) - { - Next(); - } - } - - public long GetBits(int length) - { - long ret = 0; - for (var i = 0; i < length; ++i) - { - ret |= ((long) (_buffer[_bytePosition] >> (7 - _bitPositionInByte)) & 1) << (length - 1 - i); - Next(); - } - return ret; - } - } } diff --git a/Time_Shift/Util/ChapterData/StreamUtils.cs b/Time_Shift/Util/ChapterData/StreamUtils.cs index a52a36d..8864ea2 100644 --- a/Time_Shift/Util/ChapterData/StreamUtils.cs +++ b/Time_Shift/Util/ChapterData/StreamUtils.cs @@ -1,4 +1,5 @@ -using System.IO; +using System; +using System.IO; namespace ChapterTool.Util.ChapterData { @@ -64,4 +65,61 @@ public static int LEInt16(this Stream fs) } #endregion } + + internal class BitReader + { + private readonly byte[] _buffer; + private int _bytePosition; + private int _bitPositionInByte; + + public int Position => _bytePosition * 8 + _bitPositionInByte; + + public BitReader(byte[] source) + { + _buffer = new byte[source.Length]; + Array.Copy(source, _buffer, source.Length); + } + + public void Reset() + { + _bytePosition = 0; + _bitPositionInByte = 0; + } + + public bool GetBit() + { + if (_bytePosition >= _buffer.Length) + throw new IndexOutOfRangeException(nameof(_bytePosition)); + var ret = ((_buffer[_bytePosition] >> (7 - _bitPositionInByte)) & 1) == 1; + Next(); + return ret; + } + + private void Next() + { + ++_bitPositionInByte; + if (_bitPositionInByte != 8) return; + _bitPositionInByte = 0; + ++_bytePosition; + } + + public void Skip(int length) + { + for (var i = 0; i < length; ++i) + { + Next(); + } + } + + public long GetBits(int length) + { + long ret = 0; + for (var i = 0; i < length; ++i) + { + ret |= ((long)(_buffer[_bytePosition] >> (7 - _bitPositionInByte)) & 1) << (length - 1 - i); + Next(); + } + return ret; + } + } } From 32a1e662ea7a9812c74cae17df0ba64a35f57b40 Mon Sep 17 00:00:00 2001 From: tautcony Date: Mon, 19 Jun 2017 14:50:29 +0800 Subject: [PATCH 08/24] Update res file. --- Time_Shift/Forms/Form1.Designer.cs | 15 +- Time_Shift/Forms/Form1.resx | 529 +++++++++++++++++++++++++++-- 2 files changed, 503 insertions(+), 41 deletions(-) diff --git a/Time_Shift/Forms/Form1.Designer.cs b/Time_Shift/Forms/Form1.Designer.cs index 316c977..dab5d8f 100644 --- a/Time_Shift/Forms/Form1.Designer.cs +++ b/Time_Shift/Forms/Form1.Designer.cs @@ -166,13 +166,13 @@ private void InitializeComponent() this.comboBox1.ForeColor = System.Drawing.SystemColors.WindowText; this.comboBox1.FormattingEnabled = true; this.comboBox1.Items.AddRange(new object[] { - "24000 / 1001", - "24000 / 1000", - "25000 / 1000", - "30000 / 1001", - "RESER / VED", - "50000 / 1000", - "60000 / 1001"}); + resources.GetString("comboBox1.Items"), + resources.GetString("comboBox1.Items1"), + resources.GetString("comboBox1.Items2"), + resources.GetString("comboBox1.Items3"), + resources.GetString("comboBox1.Items4"), + resources.GetString("comboBox1.Items5"), + resources.GetString("comboBox1.Items6")}); this.comboBox1.Name = "comboBox1"; this.comboBox1.TabStop = false; this.comboBox1.SelectionChangeCommitted += new System.EventHandler(this.comboBox1_SelectionChangeCommitted); @@ -374,7 +374,6 @@ private void InitializeComponent() this.btnPreview.FlatAppearance.MouseOverBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(207)))), ((int)(((byte)(207)))), ((int)(((byte)(207))))); resources.ApplyResources(this.btnPreview, "btnPreview"); this.btnPreview.Name = "btnPreview"; - this.btnPreview.Text = "P"; this.btnPreview.TabStop = false; this.btnPreview.UseVisualStyleBackColor = true; this.btnPreview.Click += new System.EventHandler(this.btnPreview_Click); diff --git a/Time_Shift/Forms/Form1.resx b/Time_Shift/Forms/Form1.resx index 2ad5843..586f527 100644 --- a/Time_Shift/Forms/Form1.resx +++ b/Time_Shift/Forms/Form1.resx @@ -117,13 +117,19 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - + 1058, 20 - + + 125, 48 + + loadMenuStrip + + + System.Windows.Forms.ContextMenuStrip, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + Flat @@ -144,6 +150,18 @@ 载入 + + btnLoad + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 14 + 124, 22 @@ -174,6 +192,21 @@ 保存 + + btnSave + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 13 + + + NoControl + 12, 9 @@ -183,6 +216,18 @@ 5 + + lbPath + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 12 + Flat @@ -198,9 +243,21 @@ 2 - - 489, 18 + + btnTrans + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + $this + + + 11 + + + 489, 18 + Flat @@ -222,9 +279,42 @@ 将章节名重新从Chapter 01开始标记 + + cbAutoGenName + + + System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + panel1 + + + 7 + Flat + + 24000 / 1001 + + + 24000 / 1000 + + + 25000 / 1000 + + + 30000 / 1001 + + + RESER / VED + + + 50000 / 1000 + + + 60000 / 1001 + 447, 52 @@ -234,15 +324,33 @@ 11 + + comboBox1 + + + System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 10 + True - + 10, 15 - + 125, 26 + + deviationMenuStrip + + + System.Windows.Forms.ContextMenuStrip, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + Flat @@ -258,9 +366,24 @@ 帧数取整 + + 489, 18 + 右键菜单可设置误差范围 + + cbRound + + + System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 9 + 124, 22 @@ -276,6 +399,18 @@ 16 + + numericUpDown1 + + + System.Windows.Forms.NumericUpDown, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + panel1 + + + 11 + True @@ -291,6 +426,18 @@ 平移章节号 + + lbShift + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + panel1 + + + 10 + True @@ -309,6 +456,18 @@ 应用表达式 (t) + + cbShift + + + System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + panel1 + + + 8 + True @@ -333,12 +492,30 @@ 不取消勾选时将持续生效 - - 590, 18 + + cbChapterName + + + System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + panel1 + + + 6 + + + 590, 18 + 125, 26 + + combineMenuStrip + + + System.Windows.Forms.ContextMenuStrip, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + Flat @@ -351,21 +528,33 @@ 23 + + comboBox2 + + + System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 8 + 124, 22 合并章节 - + 175, 15 - + 请设置所要保存的位置 - + 355, 15 - + 打开文件 @@ -387,6 +576,18 @@ 逆波兰表达式 + + cbPostFix + + + System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + panel1 + + + 0 + Flat @@ -402,18 +603,30 @@ LOG - - True + + btnLog - - True + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - True + + panel1 - - True + + 9 + + True + + + True + + + True + + + True + 12, 83 @@ -423,24 +636,48 @@ 25 + + dataGridView1 + + + System.Windows.Forms.DataGridView, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 7 + + + True + # - 21 + 26 + + True + 时间点 57 + + True + 章节名 57 + + True + 帧数 @@ -459,6 +696,18 @@ 26 + + savingType + + + System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + panel1 + + + 3 + True @@ -474,6 +723,18 @@ 保存格式 + + lbFormat + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + panel1 + + + 2 + Flat @@ -489,6 +750,21 @@ 28 + + P + + + btnPreview + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 6 + Flat @@ -501,6 +777,18 @@ 29 + + xmlLang + + + System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + panel1 + + + 5 + True @@ -516,12 +804,30 @@ XML语言 - - 755, 18 + + lbXmlLang + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + panel1 + + + 4 + + + 755, 18 + 137, 70 + + createZonestMenuStrip + + + System.Windows.Forms.ContextMenuStrip, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + 136, 22 @@ -540,6 +846,18 @@ 插入分隔条 + + textBoxExpression + + + System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + panel1 + + + 1 + 12, 440 @@ -549,6 +867,18 @@ 32 + + panel1 + + + System.Windows.Forms.Panel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 5 + 303, 37 @@ -558,9 +888,21 @@ 31 - - 937, 20 + + textBoxExpression + + + System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + panel1 + + + 1 + + + 937, 20 + 0, 511 @@ -570,6 +912,18 @@ 33 + + statusStrip1 + + + System.Windows.Forms.StatusStrip, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 4 + 443, 17 @@ -581,9 +935,10 @@ - iVBORw0KGgoAAAANSUhEUgAAABsAAAAbCAYAAACN1PRVAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO - wwAADsMBx2+oZAAAAFBJREFUSEtjGAWjYBSMguEBmIC4D4gPEIFB6kDqKQJCQHwOiP/jwSB5kDqqAHwW - UtUiGMBmIU0sggFkC2lqEQyALFgApUfBKBgFo4AugIEBAIBHH5UlpwJuAAAAAElFTkSuQmCC + iVBORw0KGgoAAAANSUhEUgAAABsAAAAbCAYAAACN1PRVAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 + YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAABQSURBVEhLYxgFo2AUjILhAZiAuA+IDxCBQepA6ikCQkB8 + Doj/48EgeZA6qgB8FlLVIhjAZiFNLIIBZAtpahEMgCxYAKVHwSgYBaOALoCBAQCARx+VJacCbgAAAABJ + RU5ErkJggg== @@ -592,12 +947,12 @@ 20, 20 - + True - - + + 61 - + 96, 96 @@ -610,4 +965,112 @@ 3, 4, 3, 4 + + reloadToolStripMenuItem + + + System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + appendToolStripMenuItem + + + System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tsmAccuracy + + + System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + combineToolStripMenuItem + + + System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + folderBrowserDialog1 + + + System.Windows.Forms.FolderBrowserDialog, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + openFileDialog1 + + + System.Windows.Forms.OpenFileDialog, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + toolTip1 + + + System.Windows.Forms.ToolTip, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + cOrder + + + System.Windows.Forms.DataGridViewTextBoxColumn, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + cTimeCode + + + System.Windows.Forms.DataGridViewTextBoxColumn, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + cChapterName + + + System.Windows.Forms.DataGridViewTextBoxColumn, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + cFrams + + + System.Windows.Forms.DataGridViewTextBoxColumn, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + creatZonesToolStripMenuItem + + + System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + ShiftForwardToolStripMenuItem + + + System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + InsertSplitToolStripMenuItem + + + System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tsTips + + + System.Windows.Forms.ToolStripStatusLabel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tsProgressBar1 + + + System.Windows.Forms.ToolStripProgressBar, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tsBtnExpand + + + System.Windows.Forms.ToolStripDropDownButton, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Form1 + + + System.Windows.Forms.Form, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + \ No newline at end of file From c6daffa5196680d1a8873b8eaa407862b47cdfcd Mon Sep 17 00:00:00 2001 From: tautcony Date: Mon, 19 Jun 2017 14:51:50 +0800 Subject: [PATCH 09/24] Tiny improvement. --- Time_Shift/Forms/FormAbout.cs | 2 +- Time_Shift/Util/ChapterData/MplsData.cs | 53 ++++++++++++------------- Time_Shift/Util/ChapterInfo.cs | 3 +- Time_Shift/Util/LanguageHelper.cs | 47 ++++++++++------------ 4 files changed, 49 insertions(+), 56 deletions(-) diff --git a/Time_Shift/Forms/FormAbout.cs b/Time_Shift/Forms/FormAbout.cs index d22b7ad..1f209dd 100644 --- a/Time_Shift/Forms/FormAbout.cs +++ b/Time_Shift/Forms/FormAbout.cs @@ -39,7 +39,7 @@ public FormAbout() FormBorderStyle = FormBorderStyle.None; linkLabel1.Text = AssemblyProduct; label2.Text = $"Version {AssemblyVersion}"; - label3.Text = System.IO.File.GetLastWriteTime(GetType().Assembly.Location).ToString(CultureInfo.InvariantCulture); + label3.Text = System.IO.File.GetLastWriteTime(Application.ExecutablePath).ToString(CultureInfo.InvariantCulture); notifyIcon1.Visible = false; } diff --git a/Time_Shift/Util/ChapterData/MplsData.cs b/Time_Shift/Util/ChapterData/MplsData.cs index de8406c..119e57d 100644 --- a/Time_Shift/Util/ChapterData/MplsData.cs +++ b/Time_Shift/Util/ChapterData/MplsData.cs @@ -26,11 +26,12 @@ namespace ChapterTool.Util.ChapterData { + //https://github.com/lerks/BluRay/wiki/MPLS public class MplsData { - private readonly MplsHeader _mplsHeader; - private readonly PlayList _playList; - private readonly PlayListMark _playListMark; + private readonly MplsHeader _mplsHeader; + private readonly PlayList _playList; + private readonly PlayListMark _playListMark; private readonly ExtensionData _extensionData; public string Version => _mplsHeader.TypeIndicator.ToString(); @@ -75,7 +76,7 @@ public MplsData(string path) public MplsGroup GetChapters() { var ret = new MplsGroup(); - for (int i = 0; i < PlayItems.Length; ++i) + for (var i = 0; i < PlayItems.Length; ++i) { var playItem = PlayItems[i]; var attr = playItem.STNTable.StreamEntries.First(item => item is PrimaryVideoStreamEntry); @@ -284,11 +285,11 @@ public PlayList(Stream stream) NumberOfSubPaths = (ushort)stream.BEInt16(); PlayItems = new PlayItem[NumberOfPlayItems]; SubPaths = new SubPath[NumberOfSubPaths]; - for (int i = 0; i < NumberOfPlayItems; ++i) + for (var i = 0; i < NumberOfPlayItems; ++i) { PlayItems[i] = new PlayItem(stream); } - for (int i = 0; i < NumberOfSubPaths; ++i) + for (var i = 0; i < NumberOfSubPaths; ++i) { SubPaths[i] = new SubPath(stream); } @@ -411,7 +412,7 @@ public MultiAngle(Stream stream) NumberOfAngles = (byte) stream.ReadByte(); _flagField = (byte) stream.ReadByte(); Angles = new ClipNameWithRef[NumberOfAngles - 1]; - for (int i = 0; i < NumberOfAngles - 1; ++i) + for (var i = 0; i < NumberOfAngles - 1; ++i) { Angles[i] = new ClipNameWithRef(stream); } @@ -437,7 +438,7 @@ public SubPath(Stream stream) _flagField = (ushort) stream.BEInt16(); NumberOfSubPlayItems = (byte) stream.ReadByte(); SubPlayItems = new SubPlayItem[NumberOfSubPlayItems]; - for (int i = 1; i < NumberOfSubPlayItems; ++i) + for (var i = 1; i < NumberOfSubPlayItems; ++i) { SubPlayItems[i] = new SubPlayItem(stream); } @@ -478,7 +479,7 @@ public SubPlayItem(Stream stream) { NumberOfMultiClipEntries = (byte) stream.ReadByte(); MultiClipNameEntries = new ClipNameWithRef[NumberOfMultiClipEntries - 1]; - for (int i = 0; i < NumberOfMultiClipEntries - 1; ++i) + for (var i = 0; i < NumberOfMultiClipEntries - 1; ++i) { MultiClipNameEntries[i] = new ClipNameWithRef(stream); } @@ -523,14 +524,14 @@ public STNTable(Stream stream) NumberOfSecondaryAudioStreamEntries+ NumberOfSecondaryVideoStreamEntries+ NumberOfSecondaryPGStreamEntries]; - int index = 0; - for (int i = 0; i < NumberOfPrimaryVideoStreamEntries; ++i) StreamEntries[index++] = new PrimaryVideoStreamEntry(stream); - for (int i = 0; i < NumberOfPrimaryAudioStreamEntries; ++i) StreamEntries[index++] = new PrimaryAudioStreamEntry(stream); - for (int i = 0; i < NumberOfPrimaryPGStreamEntries; ++i) StreamEntries[index++] = new PrimaryPGStreamEntry(stream); - for (int i = 0; i < NumberOfSecondaryPGStreamEntries; ++i) StreamEntries[index++] = new SecondaryPGStreamEntry(stream); - for (int i = 0; i < NumberOfPrimaryIGStreamEntries; ++i) StreamEntries[index++] = new PrimaryIGStreamEntry(stream); - for (int i = 0; i < NumberOfSecondaryAudioStreamEntries; ++i) StreamEntries[index++] = new SecondaryAudioStreamEntry(stream); - for (int i = 0; i < NumberOfSecondaryVideoStreamEntries; ++i) StreamEntries[index++] = new SecondaryVideoStreamEntry(stream); + var index = 0; + for (var i = 0; i < NumberOfPrimaryVideoStreamEntries; ++i) StreamEntries[index++] = new PrimaryVideoStreamEntry(stream); + for (var i = 0; i < NumberOfPrimaryAudioStreamEntries; ++i) StreamEntries[index++] = new PrimaryAudioStreamEntry(stream); + for (var i = 0; i < NumberOfPrimaryPGStreamEntries; ++i) StreamEntries[index++] = new PrimaryPGStreamEntry(stream); + for (var i = 0; i < NumberOfSecondaryPGStreamEntries; ++i) StreamEntries[index++] = new SecondaryPGStreamEntry(stream); + for (var i = 0; i < NumberOfPrimaryIGStreamEntries; ++i) StreamEntries[index++] = new PrimaryIGStreamEntry(stream); + for (var i = 0; i < NumberOfSecondaryAudioStreamEntries; ++i) StreamEntries[index++] = new SecondaryAudioStreamEntry(stream); + for (var i = 0; i < NumberOfSecondaryVideoStreamEntries; ++i) StreamEntries[index++] = new SecondaryVideoStreamEntry(stream); stream.Skip(Length - (stream.Position - position)); } } @@ -694,7 +695,7 @@ public PlayListMark(Stream stream) var position = stream.Position; NumberOfPlayListMarks = (ushort) stream.BEInt16(); Marks = new Mark[NumberOfPlayListMarks]; - for (int i = 0; i < NumberOfPlayListMarks; ++i) + for (var i = 0; i < NumberOfPlayListMarks; ++i) { Marks[i] = new Mark(stream); } @@ -713,16 +714,14 @@ internal class ExtensionData public ExtensionData(Stream stream) { Length = stream.BEInt32(); - if (Length != 0) + if (Length == 0) return; + DataBlockStartAddress = stream.BEInt32(); + stream.Skip(3); + NumberOfExtDataEntries = (byte) stream.ReadByte(); + ExtDataEntries = new ExtDataEntry[NumberOfExtDataEntries]; + for (var i = 0; i < NumberOfExtDataEntries; ++i) { - DataBlockStartAddress = stream.BEInt32(); - stream.Skip(3); - NumberOfExtDataEntries = (byte) stream.ReadByte(); - ExtDataEntries = new ExtDataEntry[NumberOfExtDataEntries]; - for (int i = 0; i < NumberOfExtDataEntries; ++i) - { - ExtDataEntries[i] = new ExtDataEntry(stream); - } + ExtDataEntries[i] = new ExtDataEntry(stream); } } } diff --git a/Time_Shift/Util/ChapterInfo.cs b/Time_Shift/Util/ChapterInfo.cs index a2094cb..4fc5294 100644 --- a/Time_Shift/Util/ChapterInfo.cs +++ b/Time_Shift/Util/ChapterInfo.cs @@ -244,8 +244,7 @@ public static void Chapter2Qpfile(string ipath, string opath, double fps, string var segments = line.Substring(7).Split('='); if (segments.Length < 2) continue; if (!segments[0].All(char.IsDigit)) continue; - int index; - if (int.TryParse(segments[0], out index)) continue; + if (int.TryParse(segments[0], out _)) continue; var times = segments[1].Split(':'); if (times.Length > 3) continue; var time = 0.0; diff --git a/Time_Shift/Util/LanguageHelper.cs b/Time_Shift/Util/LanguageHelper.cs index e48a28b..57f692b 100644 --- a/Time_Shift/Util/LanguageHelper.cs +++ b/Time_Shift/Util/LanguageHelper.cs @@ -61,33 +61,28 @@ public static void SetLang(string lang, Control control, Type formType) /// private static void AppLang(Control control, System.ComponentModel.ComponentResourceManager resources) { - var menuStrip = control as MenuStrip; - if (menuStrip != null) + switch (control) { - resources.ApplyResources(menuStrip, menuStrip.Name); - foreach (ToolStripMenuItem c in menuStrip.Items) - { - AppLang(c, resources); - } - } - - var contextMenuStrip = control as ContextMenuStrip; - if (contextMenuStrip != null) - { - resources.ApplyResources(contextMenuStrip, contextMenuStrip.Name); - foreach (ToolStripMenuItem c in contextMenuStrip.Items) - { - AppLang(c, resources); - } - } - - var gridView = control as DataGridView; - if (gridView != null) - { - foreach (DataGridViewColumn c in gridView.Columns) - { - resources.ApplyResources(c, c.Name); - } + case MenuStrip menuStrip: + resources.ApplyResources(menuStrip, menuStrip.Name); + foreach (ToolStripMenuItem c in menuStrip.Items) + { + AppLang(c, resources); + } + break; + case ContextMenuStrip contextMenuStrip: + resources.ApplyResources(contextMenuStrip, contextMenuStrip.Name); + foreach (ToolStripMenuItem c in contextMenuStrip.Items) + { + AppLang(c, resources); + } + break; + case DataGridView gridView: + foreach (DataGridViewColumn c in gridView.Columns) + { + resources.ApplyResources(c, c.Name); + } + break; } foreach (Control c in control.Controls) From 734639788ea8cfddaed08b9ad55b53cb3e545fee Mon Sep 17 00:00:00 2001 From: tautcony Date: Sun, 16 Jul 2017 17:00:59 +0800 Subject: [PATCH 10/24] Move path label a little upper. --- Time_Shift/Forms/Form1.resx | 201 ++++++++++++++++-------------------- 1 file changed, 87 insertions(+), 114 deletions(-) diff --git a/Time_Shift/Forms/Form1.resx b/Time_Shift/Forms/Form1.resx index 586f527..a086e89 100644 --- a/Time_Shift/Forms/Form1.resx +++ b/Time_Shift/Forms/Form1.resx @@ -121,6 +121,18 @@ 1058, 20 + + 124, 22 + + + 重新载入 + + + 124, 22 + + + 追加合并 + 125, 48 @@ -162,18 +174,6 @@ 14 - - 124, 22 - - - 重新载入 - - - 124, 22 - - - 追加合并 - Flat @@ -208,7 +208,7 @@ NoControl - 12, 9 + 12, 7 374, 23 @@ -255,9 +255,6 @@ 11 - - 489, 18 - Flat @@ -276,6 +273,9 @@ 不使用章节名 + + 489, 18 + 将章节名重新从Chapter 01开始标记 @@ -342,6 +342,12 @@ 10, 15 + + 124, 22 + + + 误差范围 + 125, 26 @@ -366,9 +372,6 @@ 帧数取整 - - 489, 18 - 右键菜单可设置误差范围 @@ -384,12 +387,6 @@ 9 - - 124, 22 - - - 误差范围 - 501, 7 @@ -507,6 +504,12 @@ 590, 18 + + 124, 22 + + + 合并章节 + 125, 26 @@ -540,12 +543,6 @@ 8 - - 124, 22 - - - 合并章节 - 175, 15 @@ -618,39 +615,6 @@ True - - True - - - True - - - True - - - 12, 83 - - - 556, 351 - - - 25 - - - dataGridView1 - - - System.Windows.Forms.DataGridView, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - $this - - - 7 - - - True - # @@ -684,6 +648,27 @@ 45 + + 12, 83 + + + 556, 351 + + + 25 + + + dataGridView1 + + + System.Windows.Forms.DataGridView, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 7 + Flat @@ -819,15 +804,6 @@ 755, 18 - - 137, 70 - - - createZonestMenuStrip - - - System.Windows.Forms.ContextMenuStrip, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - 136, 22 @@ -846,6 +822,24 @@ 插入分隔条 + + 137, 70 + + + createZonestMenuStrip + + + System.Windows.Forms.ContextMenuStrip, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 303, 37 + + + 178, 23 + + + 31 + textBoxExpression @@ -879,30 +873,32 @@ 5 - - 303, 37 - - - 178, 23 + + 937, 20 + + + 443, 17 - - 31 + + MiddleLeft - - textBoxExpression + + 100, 16 - - System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + iVBORw0KGgoAAAANSUhEUgAAABsAAAAbCAYAAACN1PRVAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 + YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAABQSURBVEhLYxgFo2AUjILhAZiAuA+IDxCBQepA6ikCQkB8 + Doj/48EgeZA6qgB8FlLVIhjAZiFNLIIBZAtpahEMgCxYAKVHwSgYBaOALoCBAQCARx+VJacCbgAAAABJ + RU5ErkJggg== + - - panel1 + + Magenta - - 1 + + 20, 20 - - 937, 20 - 0, 511 @@ -924,29 +920,6 @@ 4 - - 443, 17 - - - MiddleLeft - - - 100, 16 - - - - iVBORw0KGgoAAAANSUhEUgAAABsAAAAbCAYAAACN1PRVAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 - YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAABQSURBVEhLYxgFo2AUjILhAZiAuA+IDxCBQepA6ikCQkB8 - Doj/48EgeZA6qgB8FlLVIhjAZiFNLIIBZAtpahEMgCxYAKVHwSgYBaOALoCBAQCARx+VJacCbgAAAABJ - RU5ErkJggg== - - - - Magenta - - - 20, 20 - True From 2061943d151346cefb6e246ca7b338d8793021a5 Mon Sep 17 00:00:00 2001 From: tautcony Date: Sun, 16 Jul 2017 17:02:05 +0800 Subject: [PATCH 11/24] Avoid exception in copy frame number. --- Time_Shift/Forms/Form1.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Time_Shift/Forms/Form1.cs b/Time_Shift/Forms/Form1.cs index 8bdebcf..dd996cf 100644 --- a/Time_Shift/Forms/Form1.cs +++ b/Time_Shift/Forms/Form1.cs @@ -1117,7 +1117,7 @@ private int GetAutofps(decimal accuracy) private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { - if (e.ColumnIndex != 3) return; + if (e.ColumnIndex != 3 || e.RowIndex < 0) return; Clipboard.SetText((dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value as string ?? "").TrimEnd('K', '*', ' ')); } From ced7c0f58d6a63ec24c14183e48cdee02078d56d Mon Sep 17 00:00:00 2001 From: tautcony Date: Sun, 16 Jul 2017 17:06:03 +0800 Subject: [PATCH 12/24] Fix form resize in hidpi. --- Time_Shift/Forms/Form1.cs | 8 ++++++-- Time_Shift/Util/NativeMethods.cs | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/Time_Shift/Forms/Form1.cs b/Time_Shift/Forms/Form1.cs index dd996cf..d9f35a7 100644 --- a/Time_Shift/Forms/Form1.cs +++ b/Time_Shift/Forms/Form1.cs @@ -54,7 +54,6 @@ public Form1() InitializeComponent(); AddCommand(); Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath); - } public Form1(string args) @@ -163,7 +162,10 @@ private void SwitchTypeByHotKey(Keys keyData) #region Inital private void Form1_Load(object sender, EventArgs e) { - TargetHeight[0] = Height - 66; + Screen.PrimaryScreen.GetDpi(NativeMethods.DpiType.MDT_DEFAULT, out uint x, out _); + double factor = x / 96.0; + dataGridView1.ColumnHeadersHeight = (int) (dataGridView1.ColumnHeadersHeight * factor); + TargetHeight[0] = (int) (Height - 66 * factor); TargetHeight[1] = Height; Text = $@"[VCB-Studio] ChapterTool v{Assembly.GetExecutingAssembly().GetName().Version}"; InitialLog(); @@ -1326,6 +1328,7 @@ private void Form1_Resize() Height += 2; Application.DoEvents(); } + Height = TargetHeight[1]; } else if (Height == TargetHeight[1]) { @@ -1334,6 +1337,7 @@ private void Form1_Resize() Height -= 2; Application.DoEvents(); } + Height = TargetHeight[0]; } ExtensionPanelShow = Height == TargetHeight[1]; tsBtnExpand.Image = Height == TargetHeight[0] ? Resources.arrow_drop_down : Resources.arrow_drop_up; diff --git a/Time_Shift/Util/NativeMethods.cs b/Time_Shift/Util/NativeMethods.cs index 6196553..e1deeb3 100644 --- a/Time_Shift/Util/NativeMethods.cs +++ b/Time_Shift/Util/NativeMethods.cs @@ -35,6 +35,27 @@ public static void SetState(this ProgressBar pBar, int state) [DllImport("shell32.dll", EntryPoint = "#680", CharSet = CharSet.Unicode)] public static extern bool IsUserAnAdmin(); + public enum DpiType + { + MDT_EFFECTIVE_DPI = 0, + MDT_ANGULAR_DPI, + MDT_RAW_DPI, + MDT_DEFAULT = MDT_EFFECTIVE_DPI + } + + [DllImport("user32.dll")] + private static extern IntPtr MonitorFromPoint([In] System.Drawing.Point pt, [In] uint dwFlags); + + [DllImport("shcore.dll")] + private static extern IntPtr GetDpiForMonitor([In] IntPtr hmonitor, [In] DpiType dpiType, [Out] out uint dpiX, [Out] out uint dpiY); + + public static void GetDpi(this Screen screen, DpiType dpiType, out uint dpiX, out uint dpiY) + { + var pnt = new System.Drawing.Point(screen.Bounds.Left + 1, screen.Bounds.Top + 1); + var mon = MonitorFromPoint(pnt, 2); + GetDpiForMonitor(mon, dpiType, out dpiX, out dpiY); + } + /// /// 为按钮设置UAC盾牌图标 /// From 6867e22adfd864dba6b38fd0085af3fea5eb4240 Mon Sep 17 00:00:00 2001 From: tautcony Date: Sat, 22 Jul 2017 00:34:22 +0800 Subject: [PATCH 13/24] Fix path label display under hidpi. --- Time_Shift/Forms/Form1.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Time_Shift/Forms/Form1.cs b/Time_Shift/Forms/Form1.cs index d9f35a7..1c14238 100644 --- a/Time_Shift/Forms/Form1.cs +++ b/Time_Shift/Forms/Form1.cs @@ -167,6 +167,9 @@ private void Form1_Load(object sender, EventArgs e) dataGridView1.ColumnHeadersHeight = (int) (dataGridView1.ColumnHeadersHeight * factor); TargetHeight[0] = (int) (Height - 66 * factor); TargetHeight[1] = Height; + lbPath.Height = (int) (lbPath.Height / factor); + lbPath.Width = (int) (lbPath.Width / factor); + Text = $@"[VCB-Studio] ChapterTool v{Assembly.GetExecutingAssembly().GetName().Version}"; InitialLog(); if (!IsRunningOnMono) From a991f2541d2409cf3ab26280395230128353579d Mon Sep 17 00:00:00 2001 From: tautcony Date: Sat, 22 Jul 2017 18:14:31 +0800 Subject: [PATCH 14/24] Fix file saving options. --- Time_Shift/Forms/Form1.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Time_Shift/Forms/Form1.cs b/Time_Shift/Forms/Form1.cs index 1c14238..f21a09c 100644 --- a/Time_Shift/Forms/Form1.cs +++ b/Time_Shift/Forms/Form1.cs @@ -889,13 +889,13 @@ private void SaveFile(SaveTypeEnum saveType) _info.SaveXml(savePath, string.IsNullOrWhiteSpace(key) ? "" : LanguageSelectionContainer.Languages[key], AutoGenName); break; case SaveTypeEnum.QPF: - _info.GetTimecodes().SaveAs(savePath); + _info.GetQpfile().SaveAs(savePath); break; case SaveTypeEnum.TimeCodes: _info.GetTimecodes().SaveAs(savePath); break; case SaveTypeEnum.TsmuxerMeta: - _info.GetTimecodes().SaveAs(savePath); + _info.GetTsmuxerMeta().SaveAs(savePath); break; case SaveTypeEnum.CUE: _info.GetCue(Path.GetFileName(FilePath), AutoGenName).SaveAs(savePath); From 8332c89e77b891174c96e00c5ef7b52441baa361 Mon Sep 17 00:00:00 2001 From: tautcony Date: Sat, 24 Feb 2018 12:41:22 +0800 Subject: [PATCH 15/24] Add fps variable into expression. --- Time_Shift/Forms/Form1.cs | 2 +- Time_Shift/Util/Chapter.cs | 2 +- Time_Shift/Util/Expression.cs | 15 +++++++++++++-- Time_Shift/Util/ToolKits.cs | 2 +- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/Time_Shift/Forms/Form1.cs b/Time_Shift/Forms/Form1.cs index f21a09c..234054b 100644 --- a/Time_Shift/Forms/Form1.cs +++ b/Time_Shift/Forms/Form1.cs @@ -1092,7 +1092,7 @@ private void GetFramInfo(int index = 0) foreach (var chapter in _info.Chapters) { - var frams = _info.Expr.Eval(chapter.Time.TotalSeconds) * MplsData.FrameRate[index]; + var frams = _info.Expr.Eval(chapter.Time.TotalSeconds, _info.FramesPerSecond) * MplsData.FrameRate[index]; if (Round) { var rounded = Round ? Math.Round(frams, MidpointRounding.AwayFromZero) : frams; diff --git a/Time_Shift/Util/Chapter.cs b/Time_Shift/Util/Chapter.cs index db97f71..4753f1b 100644 --- a/Time_Shift/Util/Chapter.cs +++ b/Time_Shift/Util/Chapter.cs @@ -45,7 +45,7 @@ public Chapter(string name, TimeSpan time, int number) public int IsAccuracy(decimal fps, decimal accuracy, Expression expr = null) { var frams = (decimal)Time.TotalMilliseconds * fps / 1000M; - if (expr != null) frams = expr.Eval(Time.TotalSeconds) * fps; + if (expr != null) frams = expr.Eval(Time.TotalSeconds, (double)fps) * fps; var rounded = Math.Round(frams, MidpointRounding.AwayFromZero); return Math.Abs(frams - rounded) < accuracy ? 1 : 0; } diff --git a/Time_Shift/Util/Expression.cs b/Time_Shift/Util/Expression.cs index fc43007..61192f0 100644 --- a/Time_Shift/Util/Expression.cs +++ b/Time_Shift/Util/Expression.cs @@ -403,12 +403,23 @@ public static decimal Eval(IEnumerable posfix, Dictionary values) => Eval(PostExpression, values); - public decimal Eval(double time) + public decimal Eval(double time, double fps) { if (!EvalAble) return (decimal)time; try { - return Eval(new Dictionary { ["t"] = (decimal)time }); + if (fps < 1e-5) + { + return Eval(new Dictionary + { + ["t"] = (decimal)time, + }); + } + return Eval(new Dictionary + { + ["t"] = (decimal)time, + ["fps"] = (decimal)fps + }); } catch (Exception exception) { diff --git a/Time_Shift/Util/ToolKits.cs b/Time_Shift/Util/ToolKits.cs index 45269f8..e915a58 100644 --- a/Time_Shift/Util/ToolKits.cs +++ b/Time_Shift/Util/ToolKits.cs @@ -50,7 +50,7 @@ public static class ToolKits /// public static string Time2String(this Chapter item, ChapterInfo info) { - return new TimeSpan((long)(info.Expr.Eval(item.Time.TotalSeconds) * TimeSpan.TicksPerSecond)).Time2String(); + return new TimeSpan((long)(info.Expr.Eval(item.Time.TotalSeconds, info.FramesPerSecond) * TimeSpan.TicksPerSecond)).Time2String(); } public static readonly Regex RTimeFormat = new Regex(@"(?\d+)\s*:\s*(?\d+)\s*:\s*(?\d+)\s*[\.,]\s*(?\d{3})", RegexOptions.Compiled); From 6d869ed4797b5078dd9b2656b8b69c112336a23e Mon Sep 17 00:00:00 2001 From: tautcony Date: Sat, 24 Feb 2018 12:42:34 +0800 Subject: [PATCH 16/24] Upgrade dependence. --- Time_Shift_Test/Time_Shift_Test.csproj | 10 ++++++++-- Time_Shift_Test/app.config | 11 +++++++++++ Time_Shift_Test/packages.config | 3 ++- 3 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 Time_Shift_Test/app.config diff --git a/Time_Shift_Test/Time_Shift_Test.csproj b/Time_Shift_Test/Time_Shift_Test.csproj index 00d067e..d16fced 100644 --- a/Time_Shift_Test/Time_Shift_Test.csproj +++ b/Time_Shift_Test/Time_Shift_Test.csproj @@ -59,13 +59,16 @@ true - - ..\packages\FluentAssertions.4.19.2\lib\net45\FluentAssertions.dll + + ..\packages\FluentAssertions.5.1.2\lib\net45\FluentAssertions.dll ..\packages\FluentAssertions.4.19.2\lib\net45\FluentAssertions.Core.dll + + ..\packages\System.ValueTuple.4.4.0\lib\netstandard1.0\System.ValueTuple.dll + @@ -102,6 +105,9 @@ + + Designer + diff --git a/Time_Shift_Test/app.config b/Time_Shift_Test/app.config new file mode 100644 index 0000000..00adf8d --- /dev/null +++ b/Time_Shift_Test/app.config @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Time_Shift_Test/packages.config b/Time_Shift_Test/packages.config index 85b3213..c705d55 100644 --- a/Time_Shift_Test/packages.config +++ b/Time_Shift_Test/packages.config @@ -1,4 +1,5 @@  - + + \ No newline at end of file From 73e6e765061b04fdcc7150e88bf0c3d94c087206 Mon Sep 17 00:00:00 2001 From: tautcony Date: Sat, 24 Feb 2018 13:16:08 +0800 Subject: [PATCH 17/24] Round millisecond. --- Time_Shift/Util/ToolKits.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Time_Shift/Util/ToolKits.cs b/Time_Shift/Util/ToolKits.cs index e915a58..ef1eeda 100644 --- a/Time_Shift/Util/ToolKits.cs +++ b/Time_Shift/Util/ToolKits.cs @@ -40,7 +40,11 @@ public static class ToolKits /// /// /// - public static string Time2String(this TimeSpan time) => $"{time.Hours:D2}:{time.Minutes:D2}:{time.Seconds:D2}.{time.Milliseconds:D3}"; + public static string Time2String(this TimeSpan time) + { + var millisecond = (int)Math.Round((time.TotalSeconds - Math.Floor(time.TotalSeconds)) * 1000); + return $"{time.Hours:D2}:{time.Minutes:D2}:{time.Seconds:D2}.{millisecond:D3}"; + } /// /// 将给定的章节点时间以平移、修正信息修正后转换为 hh:mm:ss.sss 形式的字符串 From 8d8bb6dbff492b5d16301520ef7b0114a7c8aed7 Mon Sep 17 00:00:00 2001 From: tautcony Date: Sat, 24 Feb 2018 13:17:09 +0800 Subject: [PATCH 18/24] Add some preset expressions. --- Time_Shift/Forms/Form1.Designer.cs | 19 ++- Time_Shift/Forms/Form1.cs | 32 +++-- Time_Shift/Forms/Form1.resx | 201 ++++++++++++++++------------- Time_Shift/Util/Expression.cs | 4 +- 4 files changed, 149 insertions(+), 107 deletions(-) diff --git a/Time_Shift/Forms/Form1.Designer.cs b/Time_Shift/Forms/Form1.Designer.cs index dab5d8f..9e17b0b 100644 --- a/Time_Shift/Forms/Form1.Designer.cs +++ b/Time_Shift/Forms/Form1.Designer.cs @@ -69,7 +69,7 @@ private void InitializeComponent() this.ShiftForwardToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.InsertSplitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.panel1 = new System.Windows.Forms.Panel(); - this.textBoxExpression = new System.Windows.Forms.TextBox(); + this.comboBoxExpression = new System.Windows.Forms.ComboBox(); this.statusStrip1 = new System.Windows.Forms.StatusStrip(); this.tsTips = new System.Windows.Forms.ToolStripStatusLabel(); this.tsProgressBar1 = new System.Windows.Forms.ToolStripProgressBar(); @@ -423,8 +423,8 @@ private void InitializeComponent() // // panel1 // + this.panel1.Controls.Add(this.comboBoxExpression); this.panel1.Controls.Add(this.cbPostFix); - this.panel1.Controls.Add(this.textBoxExpression); this.panel1.Controls.Add(this.lbFormat); this.panel1.Controls.Add(this.savingType); this.panel1.Controls.Add(this.lbXmlLang); @@ -438,11 +438,16 @@ private void InitializeComponent() resources.ApplyResources(this.panel1, "panel1"); this.panel1.Name = "panel1"; // - // textBoxExpression + // comboBoxExpression // - resources.ApplyResources(this.textBoxExpression, "textBoxExpression"); - this.textBoxExpression.Name = "textBoxExpression"; - this.textBoxExpression.TextChanged += new System.EventHandler(this.textBoxExpression_TextChanged); + this.comboBoxExpression.FormattingEnabled = true; + this.comboBoxExpression.Items.AddRange(new object[] { + resources.GetString("comboBoxExpression.Items"), + resources.GetString("comboBoxExpression.Items1")}); + resources.ApplyResources(this.comboBoxExpression, "comboBoxExpression"); + this.comboBoxExpression.Name = "comboBoxExpression"; + this.comboBoxExpression.SelectedIndexChanged += new System.EventHandler(this.comboBoxExpression_SelectedIndexChanged); + this.comboBoxExpression.TextChanged += new System.EventHandler(this.comboBoxExpression_TextChanged); // // statusStrip1 // @@ -556,12 +561,12 @@ private void InitializeComponent() private System.Windows.Forms.ToolStripProgressBar tsProgressBar1; private System.Windows.Forms.ToolStripDropDownButton tsBtnExpand; private System.Windows.Forms.ToolStripMenuItem ShiftForwardToolStripMenuItem; - private System.Windows.Forms.TextBox textBoxExpression; private System.Windows.Forms.CheckBox cbPostFix; private System.Windows.Forms.ContextMenuStrip loadMenuStrip; private System.Windows.Forms.ToolStripMenuItem reloadToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem appendToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem InsertSplitToolStripMenuItem; + private System.Windows.Forms.ComboBox comboBoxExpression; } } diff --git a/Time_Shift/Forms/Form1.cs b/Time_Shift/Forms/Form1.cs index 234054b..a558fff 100644 --- a/Time_Shift/Forms/Form1.cs +++ b/Time_Shift/Forms/Form1.cs @@ -120,6 +120,15 @@ protected override bool ProcessCmdKey(ref Message msg, Keys keyData) case Keys.Control | Keys.L: btnLog_Click(null, EventArgs.Empty); return true; + case Keys.Control | Keys.PageUp: + comboBoxExpression.SelectedIndex = + (comboBoxExpression.SelectedIndex + 1) % comboBoxExpression.Items.Count; + break; + case Keys.Control | Keys.PageDown: + comboBoxExpression.SelectedIndex = + (comboBoxExpression.SelectedIndex + comboBoxExpression.Items.Count - 1) % + comboBoxExpression.Items.Count; + break; case Keys.F11: Form1_Resize(); return true; @@ -558,7 +567,7 @@ private void LoadIfo() } else { - textBoxExpression.Text = Resources.Expression_factor_1001; + comboBoxExpression.Text = Resources.Expression_factor_1001; cbShift.Checked = true; tsTips.Text = Resources.Tips_IFO_Waring_Fixed; } @@ -1184,7 +1193,7 @@ public Color TextBack { dataGridView1.BackgroundColor = value; numericUpDown1.BackColor = value; - textBoxExpression.BackColor = value; + comboBoxExpression.BackColor = value; comboBox1.BackColor = value; comboBox2.BackColor = value; xmlLang.BackColor = value; @@ -1235,7 +1244,7 @@ public Color TextFrontColor { ForeColor = value; numericUpDown1.ForeColor = value; - textBoxExpression.ForeColor = value; + comboBoxExpression.ForeColor = value; comboBox1.ForeColor = value; comboBox2.ForeColor = value; xmlLang.ForeColor = value; @@ -1439,11 +1448,11 @@ private void cbShift_CheckedChanged(object sender, EventArgs e) if (!IsPathValid) { if(Shift) - ParseExpression(textBoxExpression.Text); + ParseExpression(comboBoxExpression.Text); return; } if (_info == null) return; - _info.Expr = Shift ? ParseExpression(textBoxExpression.Text) : Expression.Empty; + _info.Expr = Shift ? ParseExpression(comboBoxExpression.Text) : Expression.Empty; UpdataGridView(); } @@ -1458,11 +1467,11 @@ private void numericUpDown1_ValueChanged(object sender, EventArgs e) private readonly Regex _invalidVariable = new Regex(@"(?:^|[+\-*/\^%\s])\d+[a-zA-Z_]+", RegexOptions.Compiled); private readonly Regex _balanceBrackets = new Regex(@"^[^\(\)]*(((?'Open'\()[^\(\)]*)+((?'Close-Open'\))[^\(\)]*)+)*(?(Open)(?!))(?:$|(?://.*))", RegexOptions.Compiled); - private void textBoxExpression_TextChanged(object sender, EventArgs e) + private void comboBoxExpression_TextChanged(object sender, EventArgs e) { - var isValid = _vaildExpression.IsMatch(textBoxExpression.Text) && - _balanceBrackets.IsMatch(textBoxExpression.Text) && - !_invalidVariable.IsMatch(textBoxExpression.Text); + var isValid = _vaildExpression.IsMatch(comboBoxExpression.Text) && + _balanceBrackets.IsMatch(comboBoxExpression.Text) && + !_invalidVariable.IsMatch(comboBoxExpression.Text); tsTips.Text = isValid ? "Valid expression" : "Invalid expression"; } @@ -1646,5 +1655,10 @@ private void InsertSplitToolStripMenuItem_Click(object sender, EventArgs e) _splitRowInsrted = true; UpdataGridView(); } + + private void comboBoxExpression_SelectedIndexChanged(object sender, EventArgs e) + { + cbShift_CheckedChanged(sender, e); + } } } diff --git a/Time_Shift/Forms/Form1.resx b/Time_Shift/Forms/Form1.resx index a086e89..cdebaf0 100644 --- a/Time_Shift/Forms/Form1.resx +++ b/Time_Shift/Forms/Form1.resx @@ -121,18 +121,6 @@ 1058, 20 - - 124, 22 - - - 重新载入 - - - 124, 22 - - - 追加合并 - 125, 48 @@ -174,6 +162,18 @@ 14 + + 124, 22 + + + 重新载入 + + + 124, 22 + + + 追加合并 + Flat @@ -255,6 +255,9 @@ 11 + + 489, 18 + Flat @@ -273,9 +276,6 @@ 不使用章节名 - - 489, 18 - 将章节名重新从Chapter 01开始标记 @@ -342,12 +342,6 @@ 10, 15 - - 124, 22 - - - 误差范围 - 125, 26 @@ -372,6 +366,9 @@ 帧数取整 + + 489, 18 + 右键菜单可设置误差范围 @@ -387,6 +384,12 @@ 9 + + 124, 22 + + + 误差范围 + 501, 7 @@ -504,12 +507,6 @@ 590, 18 - - 124, 22 - - - 合并章节 - 125, 26 @@ -543,6 +540,12 @@ 8 + + 124, 22 + + + 合并章节 + 175, 15 @@ -583,7 +586,7 @@ panel1 - 0 + 1 Flat @@ -615,6 +618,39 @@ True + + True + + + True + + + True + + + 12, 83 + + + 556, 351 + + + 25 + + + dataGridView1 + + + System.Windows.Forms.DataGridView, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 7 + + + True + # @@ -648,27 +684,6 @@ 45 - - 12, 83 - - - 556, 351 - - - 25 - - - dataGridView1 - - - System.Windows.Forms.DataGridView, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - $this - - - 7 - Flat @@ -804,6 +819,15 @@ 755, 18 + + 137, 70 + + + createZonestMenuStrip + + + System.Windows.Forms.ContextMenuStrip, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + 136, 22 @@ -822,35 +846,32 @@ 插入分隔条 - - 137, 70 + + t * 1.001 //修正DVD时间 - - createZonestMenuStrip + + round(t * 1.001 * fps) / fps //sr专用 - - System.Windows.Forms.ContextMenuStrip, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - 303, 37 + + 304, 36 - - 178, 23 + + 177, 25 - - 31 + + 33 - - textBoxExpression + + comboBoxExpression - - System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + panel1 - - 1 + + 0 12, 440 @@ -876,6 +897,27 @@ 937, 20 + + 0, 511 + + + 580, 22 + + + 33 + + + statusStrip1 + + + System.Windows.Forms.StatusStrip, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 4 + 443, 17 @@ -899,27 +941,6 @@ 20, 20 - - 0, 511 - - - 580, 22 - - - 33 - - - statusStrip1 - - - System.Windows.Forms.StatusStrip, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - $this - - - 4 - True diff --git a/Time_Shift/Util/Expression.cs b/Time_Shift/Util/Expression.cs index 61192f0..b196fce 100644 --- a/Time_Shift/Util/Expression.cs +++ b/Time_Shift/Util/Expression.cs @@ -21,6 +21,7 @@ using System.Text; using System.Linq; using System.Collections.Generic; +using System.Globalization; namespace ChapterTool.Util { @@ -96,7 +97,7 @@ public override string ToString() ["cos"] = 1, ["sin"] = 1, ["tan"] = 1, ["cosh"] = 1, ["sinh"] = 1, ["tanh"] = 1, ["exp"] = 1, ["log"] = 1, ["log10"] = 1, ["sqrt"] = 1, - ["ceil"] = 1, ["floor"] = 1, + ["ceil"] = 1, ["floor"] = 1, ["round"] = 1, ["rand"] = 0, ["dup"] = 0, ["int"] = 1, ["sign"] = 1, ["pow"] = 2, ["max"] = 2, ["min"] = 2 }; @@ -144,6 +145,7 @@ private static Token EvalCMath(Token func, Token value, Token value2 = null) case "sqrt" : ret.Number = (decimal)Math.Sqrt ((double)value.Number); break; case "ceil" : ret.Number = Math.Ceiling(value.Number); break; case "floor": ret.Number = Math.Floor(value.Number); break; + case "round": ret.Number = Math.Round(value.Number); break; case "rand" : ret.Number = (decimal)Rnd.NextDouble(); break; case "int" : ret.Number = Math.Truncate(value.Number); break; case "sign" : ret.Number = Math.Sign(value.Number); break; From 5fae7a74084158490d2c5fcc7ad664052000627d Mon Sep 17 00:00:00 2001 From: tautcony Date: Sat, 24 Feb 2018 17:20:23 +0800 Subject: [PATCH 19/24] Upgrade .Net version. --- Time_Shift/App.config | 2 +- Time_Shift/Properties/Resources.Designer.cs | 2 +- Time_Shift/Time_Shift.csproj | 2 +- Time_Shift_Test/Time_Shift_Test.csproj | 11 +++++------ Time_Shift_Test/app.config | 15 +++++---------- Time_Shift_Test/packages.config | 3 +-- 6 files changed, 14 insertions(+), 21 deletions(-) diff --git a/Time_Shift/App.config b/Time_Shift/App.config index 3b4d337..f21126b 100644 --- a/Time_Shift/App.config +++ b/Time_Shift/App.config @@ -1,7 +1,7 @@ - + diff --git a/Time_Shift/Properties/Resources.Designer.cs b/Time_Shift/Properties/Resources.Designer.cs index 19fdeac..2a82a21 100644 --- a/Time_Shift/Properties/Resources.Designer.cs +++ b/Time_Shift/Properties/Resources.Designer.cs @@ -19,7 +19,7 @@ namespace ChapterTool.Properties { // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen // (以 /str 作为命令选项),或重新生成 VS 项目。 - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Resources { diff --git a/Time_Shift/Time_Shift.csproj b/Time_Shift/Time_Shift.csproj index e1229b1..9d57ca2 100644 --- a/Time_Shift/Time_Shift.csproj +++ b/Time_Shift/Time_Shift.csproj @@ -9,7 +9,7 @@ Properties ChapterTool ChapterTool - v4.6 + v4.7 512 false diff --git a/Time_Shift_Test/Time_Shift_Test.csproj b/Time_Shift_Test/Time_Shift_Test.csproj index d16fced..1235295 100644 --- a/Time_Shift_Test/Time_Shift_Test.csproj +++ b/Time_Shift_Test/Time_Shift_Test.csproj @@ -8,7 +8,7 @@ Properties Time_Shift_Test Time_Shift_Test - v4.6 + v4.7 512 {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 10.0 @@ -60,15 +60,12 @@ - ..\packages\FluentAssertions.5.1.2\lib\net45\FluentAssertions.dll + ..\packages\FluentAssertions.5.1.2\lib\net47\FluentAssertions.dll ..\packages\FluentAssertions.4.19.2\lib\net45\FluentAssertions.Core.dll - - ..\packages\System.ValueTuple.4.4.0\lib\netstandard1.0\System.ValueTuple.dll - @@ -108,7 +105,9 @@ Designer - + + Designer + diff --git a/Time_Shift_Test/app.config b/Time_Shift_Test/app.config index 00adf8d..e4bcd5d 100644 --- a/Time_Shift_Test/app.config +++ b/Time_Shift_Test/app.config @@ -1,11 +1,6 @@ - + - - - - - - - - - \ No newline at end of file + + + + diff --git a/Time_Shift_Test/packages.config b/Time_Shift_Test/packages.config index c705d55..732cfa9 100644 --- a/Time_Shift_Test/packages.config +++ b/Time_Shift_Test/packages.config @@ -1,5 +1,4 @@  - - + \ No newline at end of file From 80d354e79d29542dabb57a96da5f281c18a93354 Mon Sep 17 00:00:00 2001 From: tautcony Date: Sat, 24 Feb 2018 18:20:04 +0800 Subject: [PATCH 20/24] Improve calculation accuracy. --- Time_Shift/Forms/Form1.cs | 6 +++--- Time_Shift/Util/Chapter.cs | 2 +- Time_Shift/Util/ChapterData/IfoData.cs | 6 +++--- Time_Shift/Util/ChapterData/IfoParser.cs | 10 +++++----- Time_Shift/Util/ChapterData/MplsData.cs | 2 +- Time_Shift/Util/ChapterData/XplData.cs | 2 +- Time_Shift/Util/ChapterInfo.cs | 11 ++++++----- Time_Shift/Util/Expression.cs | 6 +++--- Time_Shift/Util/ToolKits.cs | 4 ++-- Time_Shift_Test/Util/ToolKitsTests.cs | 2 +- 10 files changed, 26 insertions(+), 25 deletions(-) diff --git a/Time_Shift/Forms/Form1.cs b/Time_Shift/Forms/Form1.cs index a558fff..fa8163d 100644 --- a/Time_Shift/Forms/Form1.cs +++ b/Time_Shift/Forms/Form1.cs @@ -561,7 +561,7 @@ private void LoadIfo() tsTips.Text = Resources.Tips_Chapter_Not_find; return; } - if (Math.Abs(_infoGroup.First().FramesPerSecond - 25.0) < 1e-5) + if (Math.Abs(_infoGroup.First().FramesPerSecond - 25) < 1e-5M) { tsTips.Text = Resources.Tips_IFO_Waring_Unfix; } @@ -1018,7 +1018,7 @@ private void UpdataGridView(int fpsIndex = 0, bool updateFrameInfo = true) break; default: GetFramInfo(fpsIndex); - _info.FramesPerSecond = (double)MplsData.FrameRate[comboBox1.SelectedIndex]; + _info.FramesPerSecond = MplsData.FrameRate[comboBox1.SelectedIndex]; comboBox1.Enabled = true; break; } @@ -1124,7 +1124,7 @@ private int GetAutofps(decimal accuracy) result[0] = 0; result[5] = 0; //skip two invalid frame rate. result.ForEach(count => Log(string.Format(Resources.Log_FPS_Detect_Count, count))); var autofpsCode = result.IndexOf(result.Max()); - _info.FramesPerSecond = (double) MplsData.FrameRate[autofpsCode]; + _info.FramesPerSecond = MplsData.FrameRate[autofpsCode]; Log(string.Format(Resources.Log_FPS_Detect_Result, MplsData.FrameRate[autofpsCode])); return autofpsCode == 0 ? 1 : autofpsCode; } diff --git a/Time_Shift/Util/Chapter.cs b/Time_Shift/Util/Chapter.cs index 4753f1b..6de137c 100644 --- a/Time_Shift/Util/Chapter.cs +++ b/Time_Shift/Util/Chapter.cs @@ -45,7 +45,7 @@ public Chapter(string name, TimeSpan time, int number) public int IsAccuracy(decimal fps, decimal accuracy, Expression expr = null) { var frams = (decimal)Time.TotalMilliseconds * fps / 1000M; - if (expr != null) frams = expr.Eval(Time.TotalSeconds, (double)fps) * fps; + if (expr != null) frams = expr.Eval(Time.TotalSeconds, fps) * fps; var rounded = Math.Round(frams, MidpointRounding.AwayFromZero); return Math.Abs(frams - rounded) < accuracy ? 1 : 0; } diff --git a/Time_Shift/Util/ChapterData/IfoData.cs b/Time_Shift/Util/ChapterData/IfoData.cs index b0da14e..2e92a98 100644 --- a/Time_Shift/Util/ChapterData/IfoData.cs +++ b/Time_Shift/Util/ChapterData/IfoData.cs @@ -56,7 +56,7 @@ private static ChapterInfo GetChapterInfo(string location, int titleSetNum) pgc.Title = pgc.SourceName = $"{fileName.Substring(0, barIndex)}_{titleSetNum}"; } - pgc.Chapters = GetChapters(location, titleSetNum, out TimeSpan duration, out double fps); + pgc.Chapters = GetChapters(location, titleSetNum, out TimeSpan duration, out decimal fps); pgc.Duration = duration; pgc.FramesPerSecond = fps; @@ -66,7 +66,7 @@ private static ChapterInfo GetChapterInfo(string location, int titleSetNum) return pgc; } - private static List GetChapters(string ifoFile, int programChain, out TimeSpan duration, out double fps) + private static List GetChapters(string ifoFile, int programChain, out TimeSpan duration, out decimal fps) { var chapters = new List(); duration = TimeSpan.Zero; @@ -77,7 +77,7 @@ private static List GetChapters(string ifoFile, int programChain, out T var pcgItPosition = stream.GetPCGIP_Position(); var programChainPrograms = -1; var programTime = TimeSpan.Zero; - double fpsLocal; + decimal fpsLocal; if (programChain >= 0) { var chainOffset = stream.GetChainOffset(pcgItPosition, programChain); diff --git a/Time_Shift/Util/ChapterData/IfoParser.cs b/Time_Shift/Util/ChapterData/IfoParser.cs index 755b5e4..c5f33ba 100644 --- a/Time_Shift/Util/ChapterData/IfoParser.cs +++ b/Time_Shift/Util/ChapterData/IfoParser.cs @@ -63,7 +63,7 @@ internal static int GetNumberOfPrograms(this FileStream ifoStream, long pcgitPos return ifoStream.GetFileBlock((pcgitPosition + chainOffset) + 2, 1)[0]; } - internal static TimeSpan? ReadTimeSpan(this FileStream ifoStream, long pcgitPosition, uint chainOffset, out double fps) + internal static TimeSpan? ReadTimeSpan(this FileStream ifoStream, long pcgitPosition, uint chainOffset, out decimal fps) { return ReadTimeSpan(ifoStream.GetFileBlock((pcgitPosition + chainOffset) + 4, 4), out fps); } @@ -75,11 +75,11 @@ internal static int GetNumberOfPrograms(this FileStream ifoStream, long pcgitPos /// byte[3] milliseconds in bcd format (2 high bits are the frame rate) /// /// fps of the chapter - internal static TimeSpan? ReadTimeSpan(byte[] playbackBytes, out double fps) + internal static TimeSpan? ReadTimeSpan(byte[] playbackBytes, out decimal fps) { var frames = GetFrames(playbackBytes[3]); var fpsMask = playbackBytes[3] >> 6; - fps = fpsMask == 0x01 ? 25D : fpsMask == 0x03 ? (30D / 1.001D) : 0; + fps = fpsMask == 0x01 ? 25M : fpsMask == 0x03 ? (30M / 1.001M) : 0; if (frames == null) return null; try { @@ -87,8 +87,8 @@ internal static int GetNumberOfPrograms(this FileStream ifoStream, long pcgitPos var minutes = BcdToInt(playbackBytes[1]); var seconds = BcdToInt(playbackBytes[2]); var ret = new TimeSpan(hours, minutes, seconds); - if (Math.Abs(fps) > 1e-5) - ret += TimeSpan.FromSeconds((double)frames/fps); + if (Math.Abs(fps) > 1e-5M) + ret += TimeSpan.FromSeconds((double)(frames / fps)); return ret; } catch { return null; } diff --git a/Time_Shift/Util/ChapterData/MplsData.cs b/Time_Shift/Util/ChapterData/MplsData.cs index 119e57d..a837fc2 100644 --- a/Time_Shift/Util/ChapterData/MplsData.cs +++ b/Time_Shift/Util/ChapterData/MplsData.cs @@ -85,7 +85,7 @@ public MplsGroup GetChapters() SourceType = "MPLS", SourceName = PlayItems[i].FullName, Duration = Pts2Time(playItem.TimeInfo.DeltaTime), - FramesPerSecond = (double)FrameRate[attr.StreamAttributes.FrameRate] + FramesPerSecond = FrameRate[attr.StreamAttributes.FrameRate] }; var index = i; diff --git a/Time_Shift/Util/ChapterData/XplData.cs b/Time_Shift/Util/ChapterData/XplData.cs index 896d361..197d6f5 100644 --- a/Time_Shift/Util/ChapterData/XplData.cs +++ b/Time_Shift/Util/ChapterData/XplData.cs @@ -22,7 +22,7 @@ public static IEnumerable GetStreams(string location) { SourceName = title.Element(ns + "PrimaryAudioVideoClip")?.Attribute("src")?.Value ?? "", SourceType = "HD-DVD", - FramesPerSecond = 24D, + FramesPerSecond = 24M, Chapters = new List() }; var tickBaseDivisor = (int?)title.Attribute("tickBaseDivisor") ?? 1; //optional diff --git a/Time_Shift/Util/ChapterInfo.cs b/Time_Shift/Util/ChapterInfo.cs index 4fc5294..5306cfd 100644 --- a/Time_Shift/Util/ChapterInfo.cs +++ b/Time_Shift/Util/ChapterInfo.cs @@ -41,7 +41,7 @@ public class ChapterInfo public string SourceName { get; set; } public string SourceIndex { get; set; } public string SourceType { get; set; } - public double FramesPerSecond { get; set; } + public decimal FramesPerSecond { get; set; } public TimeSpan Duration { get; set; } public List Chapters { get; set; } = new List(); @@ -142,19 +142,20 @@ private string Time2String(Chapter item) return item.Time2String(this); } - public void ChangeFps(double fps) + public void ChangeFps(decimal fps) { for (var i = 0; i < Chapters.Count; i++) { var c = Chapters[i]; - var frames = c.Time.TotalSeconds*FramesPerSecond; + var frames = (decimal) c.Time.TotalSeconds * FramesPerSecond; Chapters[i] = new Chapter { Name = c.Name, Time = new TimeSpan((long) Math.Round(frames/fps*TimeSpan.TicksPerSecond)) }; } - var totalFrames = Duration.TotalSeconds*FramesPerSecond; + + var totalFrames = (decimal) Duration.TotalSeconds * FramesPerSecond; Duration = new TimeSpan((long) Math.Round(totalFrames/fps*TimeSpan.TicksPerSecond)); FramesPerSecond = fps; } @@ -281,7 +282,7 @@ public static void Chapter2Qpfile(string ipath, string opath, double fps, string File.WriteAllLines(opath, olines); } - public string[] GetCelltimes() => Chapters.Where(c => c.Time != TimeSpan.MinValue).Select(c => ((long) Math.Round(c.Time.TotalSeconds*FramesPerSecond)).ToString()).ToArray(); + public string[] GetCelltimes() => Chapters.Where(c => c.Time != TimeSpan.MinValue).Select(c => ((long) Math.Round((decimal) c.Time.TotalSeconds * FramesPerSecond)).ToString()).ToArray(); public string GetTsmuxerMeta() { diff --git a/Time_Shift/Util/Expression.cs b/Time_Shift/Util/Expression.cs index b196fce..a365727 100644 --- a/Time_Shift/Util/Expression.cs +++ b/Time_Shift/Util/Expression.cs @@ -405,12 +405,12 @@ public static decimal Eval(IEnumerable posfix, Dictionary values) => Eval(PostExpression, values); - public decimal Eval(double time, double fps) + public decimal Eval(double time, decimal fps) { if (!EvalAble) return (decimal)time; try { - if (fps < 1e-5) + if (fps < 1e-5M) { return Eval(new Dictionary { @@ -420,7 +420,7 @@ public decimal Eval(double time, double fps) return Eval(new Dictionary { ["t"] = (decimal)time, - ["fps"] = (decimal)fps + ["fps"] = fps }); } catch (Exception exception) diff --git a/Time_Shift/Util/ToolKits.cs b/Time_Shift/Util/ToolKits.cs index ef1eeda..8eef853 100644 --- a/Time_Shift/Util/ToolKits.cs +++ b/Time_Shift/Util/ToolKits.cs @@ -104,11 +104,11 @@ public static Point String2Point(string input) /// /// /// - public static int ConvertFr2Index(double frame) + public static int ConvertFr2Index(decimal frame) { for (var i = 0; i < MplsData.FrameRate.Length; ++i) { - if (Math.Abs(frame - (double)MplsData.FrameRate[i]) < 1e-5) + if (Math.Abs(frame - MplsData.FrameRate[i]) < 1e-5M) return i; } return 0; diff --git a/Time_Shift_Test/Util/ToolKitsTests.cs b/Time_Shift_Test/Util/ToolKitsTests.cs index 3939477..4636f6a 100644 --- a/Time_Shift_Test/Util/ToolKitsTests.cs +++ b/Time_Shift_Test/Util/ToolKitsTests.cs @@ -36,7 +36,7 @@ public void Time2StringTest() [TestMethod()] public void ConvertFr2IndexTest() { - var frameRate = new List { 0, 24000D / 1001, 24D, 25D, 30000D / 1001, 50D, 60000D / 1001 }; + var frameRate = new List { 0, 24000M / 1001, 24M, 25M, 30000M / 1001, 50M, 60000M / 1001 }; var expected = new List {0, 1, 2, 3, 4, 6, 7}; frameRate.Select(ToolKits.ConvertFr2Index).ToList().ForEach(Console.Write); frameRate.Select(ToolKits.ConvertFr2Index).Should().Equal(expected); From ef9707b99fd912bb9658f5c52c172733892e135b Mon Sep 17 00:00:00 2001 From: tautcony Date: Sat, 24 Feb 2018 18:48:13 +0800 Subject: [PATCH 21/24] Tiny improvement. --- Time_Shift/Forms/Form1.cs | 2 +- Time_Shift/Knuckleball/Chapter.cs | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Time_Shift/Forms/Form1.cs b/Time_Shift/Forms/Form1.cs index fa8163d..d96f04d 100644 --- a/Time_Shift/Forms/Form1.cs +++ b/Time_Shift/Forms/Form1.cs @@ -1331,7 +1331,7 @@ private bool ExtensionPanelShow private void Form1_Resize() { - if (!TargetHeight.Any(item => item == Height)) return; + if (TargetHeight.All(item => item != Height)) return; tsBtnExpand.Image = Resources.unfold_more; if (Height == TargetHeight[0]) { diff --git a/Time_Shift/Knuckleball/Chapter.cs b/Time_Shift/Knuckleball/Chapter.cs index ec23355..07bcd8a 100644 --- a/Time_Shift/Knuckleball/Chapter.cs +++ b/Time_Shift/Knuckleball/Chapter.cs @@ -91,8 +91,7 @@ public override int GetHashCode() /// is the same as this instance; otherwise, . public override bool Equals(object obj) { - var other = obj as Chapter; - if (other == null) + if (!(obj is Chapter other)) { return false; } From 2ef6155e7d13a5c80a96a8140cc1126ff60b0ffd Mon Sep 17 00:00:00 2001 From: tautcony Date: Sat, 24 Feb 2018 18:48:27 +0800 Subject: [PATCH 22/24] Fix ifo parser accuracy. --- Time_Shift/Util/ChapterData/IfoParser.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Time_Shift/Util/ChapterData/IfoParser.cs b/Time_Shift/Util/ChapterData/IfoParser.cs index c5f33ba..952a22b 100644 --- a/Time_Shift/Util/ChapterData/IfoParser.cs +++ b/Time_Shift/Util/ChapterData/IfoParser.cs @@ -86,10 +86,11 @@ internal static int GetNumberOfPrograms(this FileStream ifoStream, long pcgitPos var hours = BcdToInt(playbackBytes[0]); var minutes = BcdToInt(playbackBytes[1]); var seconds = BcdToInt(playbackBytes[2]); - var ret = new TimeSpan(hours, minutes, seconds); + var milliPart = 0M; if (Math.Abs(fps) > 1e-5M) - ret += TimeSpan.FromSeconds((double)(frames / fps)); - return ret; + milliPart = (decimal) frames / fps; + var ticks = (long) (hours * 3600 + minutes * 60 + seconds + milliPart) * TimeSpan.TicksPerSecond; + return TimeSpan.FromTicks(ticks); } catch { return null; } } From 058b807510e70950098e00017343e28c520c362b Mon Sep 17 00:00:00 2001 From: tautcony Date: Sun, 25 Feb 2018 17:02:46 +0800 Subject: [PATCH 23/24] Add IfoTimeSpan. --- Time_Shift/Forms/Form1.cs | 72 ++++++++-------- Time_Shift/Util/ChapterData/IfoData.cs | 103 +++++++++++++++++++++-- Time_Shift/Util/ChapterData/IfoParser.cs | 9 +- Time_Shift_Test/Time_Shift_Test.csproj | 4 +- Time_Shift_Test/Util/IfoTimeTests.cs | 54 ++++++++++++ Time_Shift_Test/app.config | 4 +- Time_Shift_Test/packages.config | 2 +- 7 files changed, 192 insertions(+), 56 deletions(-) create mode 100644 Time_Shift_Test/Util/IfoTimeTests.cs diff --git a/Time_Shift/Forms/Form1.cs b/Time_Shift/Forms/Form1.cs index d96f04d..2a7f2c6 100644 --- a/Time_Shift/Forms/Form1.cs +++ b/Time_Shift/Forms/Form1.cs @@ -561,6 +561,7 @@ private void LoadIfo() tsTips.Text = Resources.Tips_Chapter_Not_find; return; } +#if false if (Math.Abs(_infoGroup.First().FramesPerSecond - 25) < 1e-5M) { tsTips.Text = Resources.Tips_IFO_Waring_Unfix; @@ -571,6 +572,7 @@ private void LoadIfo() cbShift.Checked = true; tsTips.Text = Resources.Tips_IFO_Waring_Fixed; } +#endif } private void LoadXpl() @@ -748,9 +750,9 @@ private async void LoadBDMVAsync() UpdataGridView(); } - #endregion +#endregion - #region AppendFile +#region AppendFile private void reloadToolStripMenuItem_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(FilePath)) return; @@ -774,15 +776,15 @@ private void appendToolStripMenuItem_Click(object sender, EventArgs e) GetChapterInfoFromMpls(ClipSeletIndex); UpdataGridView(); } - #endregion +#endregion - #region Global status +#region Global status private bool AutoGenName => cbAutoGenName.Checked; private bool Shift => cbShift.Checked; private bool Round => cbRound.Checked; - #endregion +#endregion - #region Save File +#region Save File private void btnSave_Click(object sender, EventArgs e) => SaveFile((SaveTypeEnum)savingType.SelectedIndex); private string _customSavingPath = string.Empty; @@ -924,9 +926,9 @@ private void SaveFile(SaveTypeEnum saveType) tsTips.Text = Resources.Tips_Save_Fail; } } - #endregion +#endregion - #region Contorl Panel +#region Contorl Panel private int ClipSeletIndex => comboBox2.SelectedIndex < 0 ? 0 : comboBox2.SelectedIndex; private void comboBox1_SelectionChangeCommitted(object sender, EventArgs e) @@ -960,9 +962,9 @@ private void combineToolStripMenuItem_Click(object sender, EventArgs e) } private void refresh_Click(object sender, EventArgs e) => UpdataGridView(); - #endregion +#endregion - #region GeneRate Chapter Info +#region GeneRate Chapter Info private void GetChapterInfoFromMpls(int index) { _info = CombineChapter ? ChapterInfo.CombineChapter(_infoGroup, "MPLS") : _infoGroup[index]; @@ -998,9 +1000,9 @@ private void GetChapterInfoFromXml(XmlDocument doc) comboBox2.SelectedIndex = ClipSeletIndex; tsTips.Text = Resources.Tips_Load_Success; } - #endregion +#endregion - #region Grid View +#region Grid View private bool _splitRowInsrted; @@ -1068,9 +1070,9 @@ private void dataGridView1_RowsRemoved(object sender, DataGridViewRowsRemovedEve { Log(string.Format(Resources.Log_Row_Delete, e.RowCount, e.RowIndex)); } - #endregion +#endregion - #region Frame Info +#region Frame Info private decimal CostumeAccuracy => decimal.Parse(tsmAccuracy.DropDownItems.OfType().First(item => item.Checked).Tag.ToString()); @@ -1150,9 +1152,9 @@ private void FrameShiftForward() private void ShiftForwardToolStripMenuItem_Click(object sender, EventArgs e) => FrameShiftForward(); - #endregion +#endregion - #region Form Color +#region Form Color private FormColor _fcolor; private void Color_MouseUp(object sender, MouseEventArgs e) @@ -1253,9 +1255,9 @@ public Color TextFrontColor } private get { return ForeColor; } } - #endregion +#endregion - #region Tips +#region Tips private void lbPath_MouseEnter(object sender, EventArgs e) => toolTip1.Show(FilePath ?? "", (IWin32Window)sender); private void btnSave_MouseEnter(object sender, EventArgs e) @@ -1275,9 +1277,9 @@ private void comboBox2_MouseEnter(object sender, EventArgs e) } private void ToolTipRemoveAll(object sender, EventArgs e) => toolTip1.Hide((IWin32Window)sender); - #endregion +#endregion - #region Close Form +#region Close Form private static void FormMove(int forward, ref Point p) { switch (forward) @@ -1316,10 +1318,10 @@ private void Form1_FormClosing(object sender, FormClosingEventArgs e) Thread.Sleep(5); } } - #endregion +#endregion - #region Extension Panel - #region form resize +#region Extension Panel +#region form resize private bool ExtensionPanelShow { set => panel1.Visible = value; @@ -1354,7 +1356,7 @@ private void Form1_Resize() ExtensionPanelShow = Height == TargetHeight[1]; tsBtnExpand.Image = Height == TargetHeight[0] ? Resources.arrow_drop_down : Resources.arrow_drop_up; } - #endregion +#endregion private void savingType_SelectedIndexChanged(object sender, EventArgs e) { @@ -1378,7 +1380,7 @@ private void xmlLang_SelectionChangeCommitted(object sender, EventArgs e) } } - #region ChapterNameTemplate +#region ChapterNameTemplate private string LoadChapterName() { openFileDialog1.Filter = Resources.File_Filter_Text + @"(*.txt)|*.txt|" + @@ -1414,7 +1416,7 @@ private void cbChapterName_CheckedChanged(object sender, EventArgs e) UpdataGridView(0, false); } - #endregion +#endregion private void cbAutoGenName_CheckedChanged(object sender, EventArgs e) => UpdataGridView(0, false); @@ -1475,9 +1477,9 @@ private void comboBoxExpression_TextChanged(object sender, EventArgs e) tsTips.Text = isValid ? "Valid expression" : "Invalid expression"; } - #endregion +#endregion - #region LogForm +#region LogForm private FormLog _logForm; private void btnLog_Click(object sender, EventArgs e) { @@ -1490,9 +1492,9 @@ private void btnLog_Click(object sender, EventArgs e) _logForm.Select(); } - #endregion +#endregion - #region PreviewForm +#region PreviewForm private FormPreview _previewForm; private void btnPreview_Click(object sender, EventArgs e) { @@ -1518,9 +1520,9 @@ private void btnPreview_MouseUp(object sender, MouseEventArgs e) RegistryStorage.SetOpenMethod(Assembly.GetExecutingAssembly().Location, ".mpls", "ChapterTool.Mpls", "ChapterTool"); } } - #endregion +#endregion - #region Open Video +#region Open Video private static void OpenFile(string path) { @@ -1602,9 +1604,9 @@ private void contextMenuStrip2_Closed(object sender, ToolStripDropDownClosedEven combineMenuStrip.Items.Clear(); combineMenuStrip.Items.Add(combine); } - #endregion +#endregion - #region Zones +#region Zones private void creatZonesToolStripMenuItem_Click(object sender, EventArgs e) { if (dataGridView1.SelectedRows.Count < 1) return; @@ -1644,7 +1646,7 @@ private void dataGridView1_CellMouseUp(object sender, DataGridViewCellMouseEvent createZonestMenuStrip.Show(MousePosition); } } - #endregion +#endregion private void InsertSplitToolStripMenuItem_Click(object sender, EventArgs e) { diff --git a/Time_Shift/Util/ChapterData/IfoData.cs b/Time_Shift/Util/ChapterData/IfoData.cs index 2e92a98..de253a6 100644 --- a/Time_Shift/Util/ChapterData/IfoData.cs +++ b/Time_Shift/Util/ChapterData/IfoData.cs @@ -56,7 +56,7 @@ private static ChapterInfo GetChapterInfo(string location, int titleSetNum) pgc.Title = pgc.SourceName = $"{fileName.Substring(0, barIndex)}_{titleSetNum}"; } - pgc.Chapters = GetChapters(location, titleSetNum, out TimeSpan duration, out decimal fps); + pgc.Chapters = GetChapters(location, titleSetNum, out IfoTimeSpan duration, out decimal fps); pgc.Duration = duration; pgc.FramesPerSecond = fps; @@ -66,10 +66,10 @@ private static ChapterInfo GetChapterInfo(string location, int titleSetNum) return pgc; } - private static List GetChapters(string ifoFile, int programChain, out TimeSpan duration, out decimal fps) + private static List GetChapters(string ifoFile, int programChain, out IfoTimeSpan duration, out decimal fps) { var chapters = new List(); - duration = TimeSpan.Zero; + duration = IfoTimeSpan.Zero; fps = 0; var stream = new FileStream(ifoFile, FileMode.Open, FileAccess.Read, FileShare.Read); @@ -113,7 +113,7 @@ private static List GetChapters(string ifoFile, int programChain, out T if (currentProgram < (programChainPrograms - 1)) exitCell = stream.GetFileBlock(((pcgItPosition + longestChainOffset) + programMapOffset) + (currentProgram + 1), 1)[0] - 1; - var totalTime = TimeSpan.Zero; + var totalTime = IfoTimeSpan.Zero; for (var currentCell = entryCell; currentCell <= exitCell; currentCell++) { var cellStart = cellTableOffset + ((currentCell - 1) * 0x18); @@ -122,14 +122,13 @@ private static List GetChapters(string ifoFile, int programChain, out T if (cellType == 0x00 || cellType == 0x01) { bytes = stream.GetFileBlock(((pcgItPosition + longestChainOffset) + cellStart) + 4, 4); - var time = IfoParser.ReadTimeSpan(bytes, out fps) ?? TimeSpan.Zero; - totalTime += time; + var ret = IfoParser.ReadTimeSpan(bytes, out fps) ?? IfoTimeSpan.Zero; + totalTime.IsNTSC = ret.IsNTSC; + totalTime += ret; } } - //add a constant amount of time for each chapter? - //totalTime += TimeSpan.FromMilliseconds(fps != 0 ? (double)1000 / fps / 8D : 0); - + duration.IsNTSC = totalTime.IsNTSC; duration += totalTime; if (currentProgram + 1 < programChainPrograms) chapters.Add(new Chapter { Name = $"Chapter {currentProgram + 2:D2}", Time = duration }); @@ -138,4 +137,90 @@ private static List GetChapters(string ifoFile, int programChain, out T return chapters; } } + + public struct IfoTimeSpan + { + public int TotalSeconds { get; set; } + public int Frames { get; set; } + public bool IsNTSC { get; set; } + + public int RawFrameRate => IsNTSC ? 30 : 25; + private decimal TimeFrameRate => IsNTSC ? 30000M / 1001 : 25; + + public int TotalFrames => TotalSeconds * RawFrameRate + Frames; + public int Hours => (int) Math.Round((TotalSeconds + Frames / TimeFrameRate) / 3600); + public int Minutes => (int)Math.Round((TotalSeconds + Frames / TimeFrameRate) / 60) % 60; + public int Second => (int)Math.Round(TotalSeconds + Frames / TimeFrameRate) % 60; + + public static readonly IfoTimeSpan Zero = new IfoTimeSpan(true); + + public IfoTimeSpan(bool isNTSC) + { + TotalSeconds = 0; + Frames = 0; + IsNTSC = isNTSC; + } + + public IfoTimeSpan(int seconds, int frames, bool isNTSC) + { + TotalSeconds = seconds; + Frames = frames; + IsNTSC = isNTSC; + } + + public IfoTimeSpan(int hour, int minute, int second, int frames, bool isNTSC) + { + TotalSeconds = hour * 3600 + minute * 60 + second; + Frames = frames; + IsNTSC = isNTSC; + } + + public IfoTimeSpan(TimeSpan time, bool isNTSC) + { + IsNTSC = isNTSC; + TotalSeconds = (int) Math.Floor(time.TotalSeconds); + Frames = 0; + Frames = (int) Math.Round((decimal) (time.TotalSeconds - TotalSeconds) / TimeFrameRate); + } + + public static implicit operator TimeSpan(IfoTimeSpan time) + { + return new TimeSpan( + (long) ((time.TotalSeconds*time.RawFrameRate + time.Frames) / time.TimeFrameRate * TimeSpan.TicksPerSecond)); + } + + public static IfoTimeSpan operator +(IfoTimeSpan t1, IfoTimeSpan t2) + { + if (t1.IsNTSC ^ t2.IsNTSC) + throw new InvalidOperationException("Unmatch frames rate mode"); + return new IfoTimeSpan(t1.TotalSeconds + t2.TotalSeconds, t1.Frames + t2.Frames, t1.IsNTSC); + } + + public static IfoTimeSpan operator -(IfoTimeSpan t1, IfoTimeSpan t2) + { + if (t1.IsNTSC ^ t2.IsNTSC) + throw new InvalidOperationException("Unmatch frames rate mode"); + return new IfoTimeSpan(t1.TotalSeconds - t2.TotalSeconds, t1.Frames - t2.Frames, t1.IsNTSC); + } + + public override int GetHashCode() + { + return (((long) TotalSeconds << 32) | ((long) Frames << 1) | (IsNTSC ? 1L : 0L)).GetHashCode(); + } + + public override bool Equals(object obj) + { + if (obj == null) + return false; + if (obj.GetType() != GetType()) + return false; + var time = (IfoTimeSpan)obj; + return TotalSeconds == time.TotalSeconds && TotalFrames == time.TotalFrames && IsNTSC == time.IsNTSC; + } + + public override string ToString() + { + return $"{Hours:D2}:{Minutes:D2}:{Second:D2}.{Frames} [{(IsNTSC?'N':'P')}]"; + } + } } diff --git a/Time_Shift/Util/ChapterData/IfoParser.cs b/Time_Shift/Util/ChapterData/IfoParser.cs index 952a22b..4b0ac37 100644 --- a/Time_Shift/Util/ChapterData/IfoParser.cs +++ b/Time_Shift/Util/ChapterData/IfoParser.cs @@ -75,22 +75,19 @@ internal static int GetNumberOfPrograms(this FileStream ifoStream, long pcgitPos /// byte[3] milliseconds in bcd format (2 high bits are the frame rate) /// /// fps of the chapter - internal static TimeSpan? ReadTimeSpan(byte[] playbackBytes, out decimal fps) + internal static IfoTimeSpan? ReadTimeSpan(byte[] playbackBytes, out decimal fps) { var frames = GetFrames(playbackBytes[3]); var fpsMask = playbackBytes[3] >> 6; fps = fpsMask == 0x01 ? 25M : fpsMask == 0x03 ? (30M / 1.001M) : 0; + var isNTSC = fpsMask == 0x03; if (frames == null) return null; try { var hours = BcdToInt(playbackBytes[0]); var minutes = BcdToInt(playbackBytes[1]); var seconds = BcdToInt(playbackBytes[2]); - var milliPart = 0M; - if (Math.Abs(fps) > 1e-5M) - milliPart = (decimal) frames / fps; - var ticks = (long) (hours * 3600 + minutes * 60 + seconds + milliPart) * TimeSpan.TicksPerSecond; - return TimeSpan.FromTicks(ticks); + return new IfoTimeSpan(hours, minutes, seconds, (int) frames, isNTSC); } catch { return null; } } diff --git a/Time_Shift_Test/Time_Shift_Test.csproj b/Time_Shift_Test/Time_Shift_Test.csproj index 1235295..f92b848 100644 --- a/Time_Shift_Test/Time_Shift_Test.csproj +++ b/Time_Shift_Test/Time_Shift_Test.csproj @@ -62,9 +62,6 @@ ..\packages\FluentAssertions.5.1.2\lib\net47\FluentAssertions.dll - - ..\packages\FluentAssertions.4.19.2\lib\net45\FluentAssertions.Core.dll - @@ -90,6 +87,7 @@ + diff --git a/Time_Shift_Test/Util/IfoTimeTests.cs b/Time_Shift_Test/Util/IfoTimeTests.cs new file mode 100644 index 0000000..932dc83 --- /dev/null +++ b/Time_Shift_Test/Util/IfoTimeTests.cs @@ -0,0 +1,54 @@ +using System; +using System.Text; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using ChapterTool.Util.ChapterData; +using FluentAssertions; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace Time_Shift_Test.Util +{ + [TestClass] + public class IfoTimeTests + { + + [TestMethod] + public void TestMethod1() + { + var times = new[] + { + new[] {0, 0, 5, 0}, new[] {0, 0, 15, 0}, + new[] {0, 1, 29, 28}, new[] {0, 0, 10, 0}, + new[] {0, 7, 54, 16}, new[] {0, 6, 40, 16}, + new[] {0, 5, 8, 22}, new[] {0, 1, 19, 28}, + new[] {0, 0, 14, 28}, new[] {0, 0, 10, 2}, + new[] {0, 0, 6, 0}, new[] {0, 0, 5, 0}, + new[] {0, 2, 44, 26}, new[] {0, 1, 29, 26}, + new[] {0, 0, 10, 0}, new[] {0, 5, 35, 20}, + new[] {0, 5, 21, 20}, new[] {0, 6, 16, 18}, + new[] {0, 1, 19, 28}, new[] {0, 0, 14, 28}, + new[] {0, 0, 10, 0}, new[] {0, 0, 6, 0} + }.Select(time => new IfoTimeSpan(time[0], time[1], time[2], time[3], true)).ToList(); + var exceptedFrames = new[] + { + 150, 600, 3298, 3598, 17834, + 29850, 39112, 41510, 41958, 42260, + 42440, 42590, 47536, 50232, 50532, + 60602, 70252, 81550, 83948, 84396, + 84696, 84876 + }; + var total = new IfoTimeSpan(true); + var frames = new List(); + foreach (var time in times) + { + total += time; + frames.Add(total.TotalFrames); + var tsp = (TimeSpan) total; + Console.WriteLine($"{tsp.Hours:D2}:{tsp.Minutes:D2}:{tsp.Seconds:D2}.{tsp.Milliseconds:D3} {total.TotalFrames}"); + } + frames.Should().BeEquivalentTo(exceptedFrames); + ((int) Math.Round((decimal) ((TimeSpan) total).TotalSeconds * (30000M / 1001))).Should().Be(84876); + } + } +} diff --git a/Time_Shift_Test/app.config b/Time_Shift_Test/app.config index e4bcd5d..feb5cd5 100644 --- a/Time_Shift_Test/app.config +++ b/Time_Shift_Test/app.config @@ -1,6 +1,6 @@ - + - + diff --git a/Time_Shift_Test/packages.config b/Time_Shift_Test/packages.config index 732cfa9..9394806 100644 --- a/Time_Shift_Test/packages.config +++ b/Time_Shift_Test/packages.config @@ -1,4 +1,4 @@  - + \ No newline at end of file From ceabde229fe378d6cec6eb28a144bf8d9f2ed066 Mon Sep 17 00:00:00 2001 From: tautcony Date: Sun, 25 Feb 2018 17:36:42 +0800 Subject: [PATCH 24/24] Bump version number to 2.33.33.31 --- ChangeLog.md | 6 ++++++ README.md | 4 ++-- Time_Shift/Properties/AssemblyInfo.cs | 4 ++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 7c1a9b1..2bff983 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -351,3 +351,9 @@ - 错误修正与效能提升 - 完整功能的UHD章节读取 - 全新喷气脑袋风格图标 + +## [2.33.33.3] +- 错误修正与效能提升 +- 增加英语界面 +- 修正部分高分屏的问题 +- 修正DVD章节读取 diff --git a/README.md b/README.md index 3ae0ac9..0ea746c 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ # ChapterTool [![Build status](https://ci.appveyor.com/api/projects/status/rtc76h5ulveafj5f?svg=true)](https://ci.appveyor.com/project/tautcony/chaptertool) - ChapterTool is made for extracting chapter from various types of files and edit it. -- It's only in Chinese currently. ## Feature @@ -36,10 +35,11 @@ - [Knuckleball](https://github.com/jimevans/knuckleball) - [mp4v2](https://code.google.com/archive/p/mp4v2/) - [BluRay](https://github.com/lerks/BluRay) + - [IfoEdit](http://www.ifoedit.com/index.html) ## Requirements -- You must have `.NET Framework 4.6` available from Windows Update. +- You must have `.NET Framework 4.7` available from Windows Update. - The matroska file's support is powerd by [`MKVToolNix`](https://mkvtoolnix.download/downloads.html#windows). - The mp4 file's support is powerd by `libmp4v2`, you need get the dll before using this feature. diff --git a/Time_Shift/Properties/AssemblyInfo.cs b/Time_Shift/Properties/AssemblyInfo.cs index d79e6d8..44c0fe1 100644 --- a/Time_Shift/Properties/AssemblyInfo.cs +++ b/Time_Shift/Properties/AssemblyInfo.cs @@ -31,5 +31,5 @@ // 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, // 方法是按如下所示使用“*”: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("2.33.33.3")] -[assembly: AssemblyFileVersion("2.33.33.3")] +[assembly: AssemblyVersion("2.33.33.31")] +[assembly: AssemblyFileVersion("2.33.33.31")]