[longomatch] Use the same checks in the the video conversion discovering files



commit b65ed9c0c3440f0b0236acd23b744748bdde2576
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Mon Dec 1 12:20:02 2014 +0100

    Use the same checks in the the video conversion discovering files

 LongoMatch.GUI.Helpers/Misc.cs                   |   62 +++++++++++++---------
 LongoMatch.GUI/Gui/Dialog/VideoConversionTool.cs |   30 +---------
 2 files changed, 40 insertions(+), 52 deletions(-)
---
diff --git a/LongoMatch.GUI.Helpers/Misc.cs b/LongoMatch.GUI.Helpers/Misc.cs
index 6a3c7fd..a0c4db3 100644
--- a/LongoMatch.GUI.Helpers/Misc.cs
+++ b/LongoMatch.GUI.Helpers/Misc.cs
@@ -291,27 +291,18 @@ namespace LongoMatch.Gui.Helpers
                        }
                }
 
-               public static MediaFile OpenFile (object parent)
+               public static MediaFile DiscoverFile (string filename, object parent)
                {
-                       IBusyDialog busy = null;
                        MediaFile mediaFile = null;
-                       IGUIToolkit gui = Config.GUIToolkit;
-                       IMultimediaToolkit multimedia = Config.MultimediaToolkit; 
-                       string folder, filename;
-                       
-                       
-                       folder = System.Environment.GetFolderPath (Environment.SpecialFolder.Personal);
-                       filename = gui.OpenFile (Catalog.GetString ("Open file"), null, folder);              
               
-                       if (filename == null)
-                               return null;
-                       
+                       IBusyDialog busy = null;
+
                        try {
                                Exception ex = null;
-                               busy = gui.BusyDialog (Catalog.GetString ("Analyzing video file:") + "\n" + 
filename,
-                                                      parent);
+                               busy = Config.GUIToolkit.BusyDialog (Catalog.GetString ("Analyzing video 
file:") + "\n" +
+                                       filename, parent);
                                Task task = new Task (() => {
                                        try {
-                                               mediaFile = multimedia.DiscoverFile (filename);
+                                               mediaFile = Config.MultimediaToolkit.DiscoverFile (filename);
                                        } catch (Exception e) {
                                                ex = e;
                                        }
@@ -332,21 +323,42 @@ namespace LongoMatch.Gui.Helpers
                                } else if (mediaFile.HasVideo && mediaFile.Duration.MSeconds == 0) {
                                        throw new Exception (Catalog.GetString ("This file contains a video 
stream but its length is 0."));
                                }
-
-                               if (multimedia.FileNeedsRemux (mediaFile)) {
-                                       string q = Catalog.GetString ("This file needs to be converted into a 
more suitable format." +
-                                               "(this step only requires a few minutes)");
-                                       gui.InfoMessage (q, parent);
-                                       string newFilename = multimedia.RemuxFile (mediaFile, parent);
-                                       if (newFilename != null)
-                                               mediaFile = multimedia.DiscoverFile (newFilename);
-                               }
                        } catch (Exception ex) {
                                busy.Destroy ();
-                               gui.ErrorMessage (ex.Message, parent);
+                               Config.GUIToolkit.ErrorMessage (ex.Message, parent);
                                return null;
                        }
+                       return mediaFile;
+               }
+
+               public static MediaFile OpenFile (object parent)
+               {
+                       MediaFile mediaFile;
+                       IGUIToolkit gui = Config.GUIToolkit;
+                       IMultimediaToolkit multimedia = Config.MultimediaToolkit;
+                       string folder, filename;
                        
+                       folder = System.Environment.GetFolderPath (Environment.SpecialFolder.Personal);
+                       filename = gui.OpenFile (Catalog.GetString ("Open file"), null, folder);
+                       if (filename == null)
+                               return null;
+                       
+                       mediaFile = DiscoverFile (filename, parent);
+                       if (mediaFile != null) {
+                               try {
+                                       if (multimedia.FileNeedsRemux (mediaFile)) {
+                                               string q = Catalog.GetString ("This file needs to be 
converted into a more suitable format." +
+                                                       "(this step only requires a few minutes)");
+                                               gui.InfoMessage (q, parent);
+                                               string newFilename = multimedia.RemuxFile (mediaFile, parent);
+                                               if (newFilename != null)
+                                                       mediaFile = multimedia.DiscoverFile (newFilename);
+                                       }
+                               } catch (Exception ex) {
+                                       gui.ErrorMessage (ex.Message, parent);
+                                       return null;
+                               }
+                       }
                        return mediaFile;
                }
 
diff --git a/LongoMatch.GUI/Gui/Dialog/VideoConversionTool.cs 
b/LongoMatch.GUI/Gui/Dialog/VideoConversionTool.cs
index a0b53a4..b335154 100644
--- a/LongoMatch.GUI/Gui/Dialog/VideoConversionTool.cs
+++ b/LongoMatch.GUI/Gui/Dialog/VideoConversionTool.cs
@@ -137,35 +137,11 @@ namespace LongoMatch.Gui.Dialog
                        var msg = Catalog.GetString ("Add file");
                        List<string> paths = FileChooserHelper.OpenFiles (this, msg, null,
                                                                          Config.HomeDir, null, null);
-                       List<string> errors = new List<string> ();
                        foreach (string path in paths) {
-                               try {
-                                       string error = null;
-                                       MediaFile mediaFile = Config.MultimediaToolkit.DiscoverFile (path, 
true);
-                                       if (mediaFile == null) {
-                                               continue;
-                                       }
-                                       if(!mediaFile.HasVideo || mediaFile.VideoCodec == "") {
-                                               throw new Exception (Catalog.GetString("This file doesn't 
contain a video stream."));
-                                       }
-                                       if(mediaFile.HasVideo && mediaFile.Duration.MSeconds == 0) {
-                                               throw new Exception (Catalog.GetString("This file contains a 
video stream but its length is 0."));
-                                       }
-                                       if (error != null) {
-                                               Config.GUIToolkit.ErrorMessage (error, this);
-                                       } else {
-                                               AppendFile (Config.MultimediaToolkit.DiscoverFile (path, 
true));
-                                       }
-                               } catch (Exception) {
-                                       errors.Add (path);
-                               }
-                       }
-                       if (errors.Count != 0) {
-                               string s = Catalog.GetString ("Error adding files:");
-                               foreach (string p in errors) {
-                                       s += '\n' + p;
+                               MediaFile mediaFile = Misc.DiscoverFile (path, this);
+                               if (mediaFile != null) {
+                                       AppendFile (mediaFile);
                                }
-                               GUIToolkit.Instance.ErrorMessage (s);
                        }
                        CheckStatus ();
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]