<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>Core/ResourceManager.cs</filename>
    </added>
    <added>
      <filename>Core/default.viewer.rb</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -102,11 +102,13 @@
     &lt;Compile Include=&quot;Repl.xaml.cs&quot;&gt;
       &lt;DependentUpon&gt;Repl.xaml&lt;/DependentUpon&gt;
     &lt;/Compile&gt;
+    &lt;Compile Include=&quot;ResourceManager.cs&quot; /&gt;
     &lt;Compile Include=&quot;Resources.cs&quot; /&gt;
     &lt;EmbeddedResource Include=&quot;Properties\Resources.resx&quot;&gt;
       &lt;Generator&gt;ResXFileCodeGenerator&lt;/Generator&gt;
       &lt;LastGenOutput&gt;Resources.Designer.cs&lt;/LastGenOutput&gt;
     &lt;/EmbeddedResource&gt;
+    &lt;EmbeddedResource Include=&quot;default.viewer.rb&quot; /&gt;
     &lt;None Include=&quot;Properties\Settings.settings&quot;&gt;
       &lt;Generator&gt;SettingsSingleFileGenerator&lt;/Generator&gt;
       &lt;LastGenOutput&gt;Settings.Designer.cs&lt;/LastGenOutput&gt;
@@ -118,11 +120,10 @@
       &lt;SubType&gt;Designer&lt;/SubType&gt;
       &lt;Generator&gt;MSBuild:Compile&lt;/Generator&gt;
     &lt;/Page&gt;
-    &lt;None Include=&quot;ReplResources.xaml&quot;&gt;
+    &lt;EmbeddedResource Include=&quot;ReplResources.xaml&quot;&gt;
       &lt;SubType&gt;Designer&lt;/SubType&gt;
       &lt;Generator&gt;MSBuild:Compile&lt;/Generator&gt;
-      &lt;CopyToOutputDirectory&gt;Always&lt;/CopyToOutputDirectory&gt;
-    &lt;/None&gt;
+    &lt;/EmbeddedResource&gt;
   &lt;/ItemGroup&gt;
   &lt;Import Project=&quot;$(MSBuildToolsPath)\Microsoft.CSharp.targets&quot; /&gt;
   &lt;!-- To modify your build process, add your task inside one of the targets below and uncomment it. </diff>
      <filename>Core/Core.csproj</filename>
    </modified>
    <modified>
      <diff>@@ -1,16 +1,19 @@
 &#65279;using System;
 using System.Collections.Generic;
 using System.IO;
+using System.Reflection;
 using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Documents;
 using System.Windows.Input;
 using System.Windows.Markup;
-using System.Xml;
 using IronRuby.Builtins;
 
 namespace Core {
     public partial class Repl : UserControl {
+        public const string RESOURCE_FILENAME = &quot;ReplResources.xaml&quot;;
+        public const string DEFAULT_VIEWER = &quot;default.viewer.rb&quot;;
+
         private Dictionary&lt;Type, bool&gt; _viewers = new Dictionary&lt;Type, bool&gt;();
         private Dictionary&lt;string, DlrEngine&gt; _languageMap = new Dictionary&lt;string, DlrEngine&gt;();
         private string _currentEngine;
@@ -30,14 +33,36 @@ namespace Core {
         #region Component initialization 
 
         private void LoadResources() {
-            // TODO: load embedded ReplResources.xaml and write to disk if we don't have one in our current dir
-            var resourceDictionary = (ResourceDictionary)XamlReader.Load(XmlReader.Create(&quot;ReplResources.xaml&quot;));
-            Application.Current.Resources.MergedDictionaries.Add(resourceDictionary);
+            using (var stream = ReplResourceManager.Load(RESOURCE_FILENAME)) {
+                var resourceDictionary = (ResourceDictionary)XamlReader.Load(stream);
+                Application.Current.Resources.MergedDictionaries.Add(resourceDictionary);
+            }
         }
 
         private void InitializePlugins() {
-            // TODO: remove hard-coded path
-            CurrentEngine.Require(@&quot;c:\teched\repl\Viewers\default.viewer.rb&quot;);
+            // TODO: generalize and refactor this
+            var path = Environment.GetEnvironmentVariable(&quot;REPL_PLUGINS&quot;);
+            if (path == null) {
+                var home = Environment.GetEnvironmentVariable(&quot;HOME&quot;);
+                var homeDrive = Environment.GetEnvironmentVariable(&quot;HOMEDRIVE&quot;);
+                path = homeDrive + home;
+                path = Path.Combine(path, &quot;ReplPlugins&quot;);
+            }
+
+            var viewerPath = Path.Combine(path, DEFAULT_VIEWER);
+            if (Directory.Exists(path) &amp;&amp; File.Exists(viewerPath)) {
+                CurrentEngine.Require(viewerPath);
+            } else {
+                Directory.CreateDirectory(path);
+                var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(&quot;Core.&quot; + DEFAULT_VIEWER);
+                var length = (int)stream.Length;
+                using (var outputStream = File.OpenWrite(viewerPath)) {
+                    var buffer = new byte[length];
+                    stream.Read(buffer, 0, length);
+                    outputStream.Write(buffer, 0, length);
+                }
+                CurrentEngine.Require(viewerPath);
+            }
         }
 
         private void InitializeScriptEngines() {</diff>
      <filename>Core/Repl.xaml.cs</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>0014c92dd8bc5c556024a96e374fe8afb8f20407</id>
    </parent>
  </parents>
  <author>
    <name>John Lam</name>
    <email>jflam@microsoft.com</email>
  </author>
  <url>http://github.com/jflam/repl-lib/commit/5b597ab4b92a6d85f3e7f22d3ae9af271444b1d4</url>
  <id>5b597ab4b92a6d85f3e7f22d3ae9af271444b1d4</id>
  <committed-date>2009-05-18T06:55:28-07:00</committed-date>
  <authored-date>2009-05-18T06:55:28-07:00</authored-date>
  <message>FEATURE: embed default configuration and viewer as resources to write out to disk on first execution</message>
  <tree>93e61a6e4fe38ebdb9f235ecceef4623154f2f59</tree>
  <committer>
    <name>John Lam</name>
    <email>jflam@microsoft.com</email>
  </committer>
</commit>
