[gnome-subtitles] When the application is run with a subtitle file as first arg, validate that arg appropriately and c
- From: Pedro Daniel da Rocha Melo e Castro <pcastro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-subtitles] When the application is run with a subtitle file as first arg, validate that arg appropriately and c
- Date: Sun, 16 Jun 2013 21:20:00 +0000 (UTC)
commit 104d49f5d19f2bc05e874bff90b606e97bda1b9b
Author: Pedro Castro <pedro gnomesubtitles org>
Date: Sun Jun 16 22:19:42 2013 +0100
When the application is run with a subtitle file as first arg, validate that arg appropriately and
convert it to absolute path if necessary (fixes #702413).
src/GnomeSubtitles/Ui/MainUi.cs | 33 ++++++++++++++++++++++++++++-----
1 files changed, 28 insertions(+), 5 deletions(-)
---
diff --git a/src/GnomeSubtitles/Ui/MainUi.cs b/src/GnomeSubtitles/Ui/MainUi.cs
index b288dfc..c96067d 100644
--- a/src/GnomeSubtitles/Ui/MainUi.cs
+++ b/src/GnomeSubtitles/Ui/MainUi.cs
@@ -98,12 +98,11 @@ public class MainUi {
/// <summary>Starts the GUI</summary>
/// <remarks>A file is opened if it was specified as argument. If it wasn't, a blank start is
performed.</summary>
public void Start () {
- string[] args = Base.ExecutionContext.Args;
- if (args.Length > 0) {
- string subtitleFile = args[0];
- Uri videoUri = Base.Config.PrefsVideoAutoChooseFile ?
VideoFiles.FindMatchingVideo(subtitleFile) : null;
+ string subtitleFilePath = GetSubtitleFileArg(Base.ExecutionContext.Args);
+ if (subtitleFilePath != null) {
+ Uri videoUri = Base.Config.PrefsVideoAutoChooseFile ?
VideoFiles.FindMatchingVideo(subtitleFilePath) : null;
int codePage = GetFileOpenCodePageFromConfig();
- Open(subtitleFile, codePage, videoUri);
+ Open(subtitleFilePath, codePage, videoUri);
}
}
@@ -456,6 +455,30 @@ public class MainUi {
}
}
+ private string GetSubtitleFileArg (string[] args) {
+ if (args.Length == 0) {
+ return null;
+ }
+
+ string file = args[0];
+ if (file == null) {
+ return null;
+ }
+
+ if (!Path.IsPathRooted(file)) {
+ try {
+ file = Path.GetFullPath(file);
+ }
+ catch (Exception e) {
+ System.Console.Error.WriteLine("Unable to read subtitle file path from
argument 0");
+ System.Console.Error.WriteLine(e);
+ return null;
+ }
+ }
+
+ return file;
+ }
+
/* Event members */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]