2
* This file is part of SubLib.
3
* Copyright (C) 2005-2007 Pedro Castro
5
* SubLib is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* SubLib is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22
/// <summary>Represents the main mechanism for saving <see cref="Subtitles" />.</summary>
23
public class SubtitleSaver {
24
private FileProperties fileProperties = null;
27
/* Public properties */
29
/// <summary>The new properties of the file after saving.</summary>
30
/// <remarks>This includes the updated <see cref="TimingMode" /> for the subtitles after saving. When saving to
31
/// a subtitle format that supports only time or frame timing modes, this is updated to reflect that.</remarks>
32
public FileProperties FileProperties {
33
get { return fileProperties; }
38
/// <summary>Saves subtitles to the file with the specified properties.</summary>
39
/// <param name="subtitles">The subtitles to save.</param>
40
/// <param name="properties">The properties of the file to save the subtitles to. Its <see cref="TimingMode" /> property is used to
41
/// choose the timing mode for subtitle formats that support both time and frame modes.</param>
42
/// <param name="textType">The type of text content to save.</param>
43
/// <remarks>An updated <see cref="SubLib.FileProperties" /> object can be accessed with <see cref="FileProperties" /> after saving.</remarks>
44
public void Save (Subtitles subtitles, FileProperties properties, SubtitleTextType textType) {
45
SubtitleFormat format = BuiltInSubtitleFormats.GetFormat(properties.SubtitleType);
46
SubtitleOutput output = new SubtitleOutput(format, textType);
48
string text = output.Build(subtitles.Collection, subtitles.Properties, properties);
49
FileInputOutput.WriteFile(properties.Path, text, properties.Encoding);
52
fileProperties = GetUpdatedFileProperties(properties);
53
VerboseConsole.WriteLine("[*] Saved " + textType + " " + properties.Path + " with encoding " + properties.Encoding + " and format " + format.Name);
58
private FileProperties GetUpdatedFileProperties (FileProperties properties) {
59
SubtitleFormat format = BuiltInSubtitleFormats.GetFormat(properties.SubtitleType);
60
TimingMode newTimingMode = (format.Mode == SubtitleMode.Both) ? properties.TimingMode : format.ModeAsTimingMode;
62
return new FileProperties(properties.Path, properties.Encoding, properties.SubtitleType, newTimingMode, properties.NewlineType);
b'\\ No newline at end of file'