diff --git a/OSCADSharp/OSCADSharp/OSCADObject.cs b/OSCADSharp/OSCADSharp/OSCADObject.cs index 67d2ab6..3e8b537 100644 --- a/OSCADSharp/OSCADSharp/OSCADObject.cs +++ b/OSCADSharp/OSCADSharp/OSCADObject.cs @@ -328,8 +328,8 @@ namespace OSCADSharp { path += ".scad"; } - - File.WriteAllLines(path, new string[] + + Settings.FileWriter.WriteAllLines(path, new string[] { Settings.OSCADSharpHeader, Settings.Globals.ToString(), diff --git a/OSCADSharp/OSCADSharp/OSCADSharp.csproj b/OSCADSharp/OSCADSharp/OSCADSharp.csproj index ae770d1..1b7c5b0 100644 --- a/OSCADSharp/OSCADSharp/OSCADSharp.csproj +++ b/OSCADSharp/OSCADSharp/OSCADSharp.csproj @@ -42,6 +42,8 @@ + + diff --git a/OSCADSharp/OSCADSharp/Scripting/DefaultFileWriter.cs b/OSCADSharp/OSCADSharp/Scripting/DefaultFileWriter.cs new file mode 100644 index 0000000..05ae2e4 --- /dev/null +++ b/OSCADSharp/OSCADSharp/Scripting/DefaultFileWriter.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OSCADSharp.Scripting +{ + internal class DefaultFileWriter : IFileWriter + { + public void WriteAllLines(string path, string[] contents) + { + File.WriteAllLines(path, contents); + } + } +} diff --git a/OSCADSharp/OSCADSharp/Scripting/IFileWriter.cs b/OSCADSharp/OSCADSharp/Scripting/IFileWriter.cs new file mode 100644 index 0000000..afdbb46 --- /dev/null +++ b/OSCADSharp/OSCADSharp/Scripting/IFileWriter.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OSCADSharp.Scripting +{ + /// + /// A class that takes text and writes to file + /// + public interface IFileWriter + { + /// + /// Writes lines of text to a file at the path specified + /// + /// + /// + void WriteAllLines(string path, string[] contents); + } +} diff --git a/OSCADSharp/OSCADSharp/Settings.cs b/OSCADSharp/OSCADSharp/Settings.cs index 3886f99..d6b183f 100644 --- a/OSCADSharp/OSCADSharp/Settings.cs +++ b/OSCADSharp/OSCADSharp/Settings.cs @@ -23,5 +23,10 @@ namespace OSCADSharp /// top of OpenSCAD scripts /// public static Variables Globals = new Variables(); + + /// + /// Used to write scripts to file + /// + public static IFileWriter FileWriter = new DefaultFileWriter(); } }