Skip to content
This repository has been archived by the owner on Apr 20, 2022. It is now read-only.

Commit

Permalink
* Configuration.cs:
Browse files Browse the repository at this point in the history
Made handling of OpenTK.dll.config more robust (still doesn't work, however).

git-svn-id: https://opentk.svn.sourceforge.net/svnroot/opentk/trunk@3053 ebc5dd9b-fb1d-0410-b6f8-d24c324e9604
  • Loading branch information
the_fiddler committed Dec 8, 2010
1 parent 4956929 commit 93ec331
Showing 1 changed file with 69 additions and 1 deletion.
70 changes: 69 additions & 1 deletion Source/OpenTK/Configuration.cs
Expand Up @@ -97,11 +97,16 @@ static Configuration()
RunningOnWindows ? "Windows" : RunningOnLinux ? "Linux" : RunningOnMacOS ? "MacOS" :
runningOnUnix ? "Unix" : RunningOnX11 ? "X11" : "Unknown Platform",
RunningOnMono ? "Mono" : ".Net");

if (RunningOnMono && !RunningOnWindows)
{
WriteConfigFile();
}
}

#endregion

#region --- Public Methods ---
#region Public Methods

#region public static bool RunningOnWindows

Expand Down Expand Up @@ -208,6 +213,69 @@ private static string DetectUnixKernel()

#endregion

#endregion

#region Private Methods

// Creates path on disk if it doesn't already exist
static void CreatePath(string path)
{
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
}

// Write OpenTK.dll.config to disk when running on non-Windows platforms.
// Mono will automatically load the config from ~/.mono/assemblies/OpenTK,
// which is great when the user forgets to copy the file on his own
static void WriteConfigFile()
{
Debug.Write("Writing config file ");
string name = null;
string monopath = null;
string asmpath = null;
string outpath = null;
string file = null;

try
{
Assembly asm = Assembly.GetAssembly(typeof(Configuration));
name = asm.GetName().Name;
monopath = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.Personal),
".mono");
asmpath = Path.Combine(monopath, "assemblies");
outpath = Path.Combine(asmpath, name);
file = Path.ChangeExtension(name, "dll.config");
Debug.Print("to {0}/{1}.", outpath, file);
CreatePath(monopath);
CreatePath(asmpath);
CreatePath(outpath);

Debug.Print("Loading embedded config.");
// Note: the dll name is hardcoded
Stream str = asm.GetManifestResourceStream("OpenTK.dll.config");
if (str != null)
{
using (str)
{
byte[] buffer = new byte[str.Length];
str.Read(buffer, 0, buffer.Length);
string config = System.Text.UnicodeEncoding.Unicode.GetString(buffer);
System.IO.File.WriteAllText(Path.Combine(outpath, file), config);
}
Debug.Print("Success!");
}
else
{
Debug.Print("[Warning] Failed, embedded config not found.");
}
}
catch (Exception e)
{
Debug.Print("[Warning] Failed to write {0} to \"{1}\". Error: {2}", file, outpath, e);
}
}

#endregion
}
}

0 comments on commit 93ec331

Please sign in to comment.