diff --git a/Core/FormBrowser.cs b/Core/FormBrowser.cs index 3e234b5c..4d8cc3e0 100644 --- a/Core/FormBrowser.cs +++ b/Core/FormBrowser.cs @@ -9,6 +9,7 @@ using TweetDick.Core.Handling; using TweetDick.Core.Other; using System.Drawing; +using TweetDick.Resources; namespace TweetDick.Core{ partial class FormBrowser : Form{ @@ -82,13 +83,7 @@ private void Browser_LoadingStateChanged(object sender, LoadingStateChangedEvent private void Browser_FrameLoadEnd(object sender, FrameLoadEndEventArgs e){ if (e.Frame.IsMain){ - string js = null; - - try{ - js = File.ReadAllText("code.js",Encoding.UTF8); - }catch(Exception ex){ - MessageBox.Show("Unfortunately, TweetDick could not load the code.js file. The program will continue running with limited functionality.\r\n\r\n"+ex.Message,"TweetDick Has Failed :(",MessageBoxButtons.OK,MessageBoxIcon.Error); - } + string js = ScriptLoader.LoadResource("code.js"); if (js != null){ browser.ExecuteScriptAsync(js); diff --git a/Resources/ScriptLoader.cs b/Resources/ScriptLoader.cs new file mode 100644 index 00000000..d8e912c8 --- /dev/null +++ b/Resources/ScriptLoader.cs @@ -0,0 +1,17 @@ +using System; +using System.IO; +using System.Text; +using System.Windows.Forms; + +namespace TweetDick.Resources{ + static class ScriptLoader{ + public static string LoadResource(string name){ + try{ + return File.ReadAllText(name,Encoding.UTF8); + }catch(Exception ex){ + MessageBox.Show("Unfortunately, TweetDick could not load the "+name+" file. The program will continue running with limited functionality.\r\n\r\n"+ex.Message,"TweetDick Has Failed :(",MessageBoxButtons.OK,MessageBoxIcon.Error); + return null; + } + } + } +} diff --git a/TweetDick.csproj b/TweetDick.csproj index fa8978b0..82da8f6c 100644 --- a/TweetDick.csproj +++ b/TweetDick.csproj @@ -145,6 +145,7 @@ <DesignTime>True</DesignTime> <DependentUpon>Resources.resx</DependentUpon> </Compile> + <Compile Include="Resources\ScriptLoader.cs" /> <None Include="Configuration\app.config" /> <None Include="Configuration\packages.config" /> </ItemGroup>