Allow to specify video file via parameter

This commit is contained in:
Nikolaj Olsson 2018-08-27 13:40:43 +02:00
parent 8c377221da
commit c38e0a57eb

View File

@ -357,6 +357,22 @@ namespace Nikse.SubtitleEdit.Forms
base.OnLoad(e); base.OnLoad(e);
} }
private static string GetArgumentAfterColon(IList<string> commandLineArguments, string requestedArgumentName)
{
for (int i = 0; i < commandLineArguments.Count; i++)
{
var argument = commandLineArguments[i];
if (argument.StartsWith(requestedArgumentName, StringComparison.OrdinalIgnoreCase))
{
var idx = argument.IndexOf(':');
if (idx >= 0)
return argument.Remove(0, idx + 1);
return argument;
}
}
return null;
}
public Main() public Main()
{ {
if (Configuration.IsRunningOnLinux()) if (Configuration.IsRunningOnLinux())
@ -461,12 +477,15 @@ namespace Nikse.SubtitleEdit.Forms
if (args.Length >= 2) if (args.Length >= 2)
{ {
fileName = args[1]; fileName = args[1];
if (args.Length > 2 && args[2].StartsWith("/srcline:", StringComparison.OrdinalIgnoreCase))
var sourceLineString = GetArgumentAfterColon(args, "/srcline:");
if (!string.IsNullOrEmpty(sourceLineString))
{ {
string srcLine = args[2].Remove(0, 9); if (!int.TryParse(sourceLineString, out srcLineNumber))
if (!int.TryParse(srcLine, out srcLineNumber))
srcLineNumber = -1; srcLineNumber = -1;
} }
_videoFileName = GetArgumentAfterColon(args, "/video:");
} }
labelAutoDuration.Visible = false; labelAutoDuration.Visible = false;
@ -505,11 +524,11 @@ namespace Nikse.SubtitleEdit.Forms
if (srcLineNumber < 0) if (srcLineNumber < 0)
{ {
if (!OpenFromRecentFiles(fileName)) if (!OpenFromRecentFiles(fileName))
OpenSubtitle(fileName, null); OpenSubtitle(fileName, null, _videoFileName, null);
} }
else else
{ {
OpenSubtitle(fileName, null); OpenSubtitle(fileName, null, _videoFileName, null);
} }
if (srcLineNumber >= 0 && GetCurrentSubtitleFormat().GetType() == typeof(SubRip) && srcLineNumber < textBoxSource.Lines.Length) if (srcLineNumber >= 0 && GetCurrentSubtitleFormat().GetType() == typeof(SubRip) && srcLineNumber < textBoxSource.Lines.Length)