[longomatch] Remove invalid chars from proposed filename when exporting to CSV.



commit b8d6fb8a6618cbce7de08c774dd4fd2928ee38de
Author: Xavi Artigas <xartigas fluendo com>
Date:   Wed Apr 29 19:02:28 2015 +0200

    Remove invalid chars from proposed filename when exporting to CSV.

 LongoMatch.Plugins/CSVExporter.cs |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)
---
diff --git a/LongoMatch.Plugins/CSVExporter.cs b/LongoMatch.Plugins/CSVExporter.cs
index f890551..46adc5f 100644
--- a/LongoMatch.Plugins/CSVExporter.cs
+++ b/LongoMatch.Plugins/CSVExporter.cs
@@ -31,6 +31,10 @@ namespace LongoMatch.Plugins
        [Extension]
        public class CSVExporter:IExportProject
        {
+               readonly string InvalidChars =
+                       new string(Path.GetInvalidFileNameChars()) +
+                       new string(Path.GetInvalidPathChars());
+
                public string Name {
                        get {
                                return Catalog.GetString ("CSV export plugin");
@@ -57,6 +61,12 @@ namespace LongoMatch.Plugins
                public void ExportProject (Project project, IGUIToolkit guiToolkit)
                {
                        string proposed_filename = project.Description.Title + ".csv";
+
+                       // Sanitize proposed filename
+                       foreach (char c in InvalidChars) {
+                               proposed_filename = proposed_filename.Replace(c.ToString(), "");
+                       }
+
                        string filename = guiToolkit.SaveFile (Catalog.GetString ("Output file"), 
proposed_filename,
                                                  Config.HomeDir, "CSV",
                                                  new string[] { "*.csv" });


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