forked from MonoGame/MonoGame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WineHelper.cs
89 lines (73 loc) · 3.45 KB
/
WineHelper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// MonoGame - Copyright (C) The MonoGame Team
// This file is subject to the terms and conditions defined in
// file 'LICENSE.txt', which is part of this source code package.
using System;
using System.Diagnostics;
using System.IO;
namespace MonoGame.Effect.Compiler
{
public static class WineHelper
{
public static int Run(Options options)
{
var mgfxcwine = Environment.GetEnvironmentVariable("MGFXC_WINE_PATH");
if (string.IsNullOrEmpty(mgfxcwine))
{
Console.Error.WriteLine("MGFXC effect compiler requires a valid Wine installation to be able to compile shaders.");
Console.Error.WriteLine("");
Console.Error.WriteLine("Setup instructions:");
Console.Error.WriteLine("- Create 64 bit wine prefix");
Console.Error.WriteLine("- Install d3dcompiler_47 using winetricks");
Console.Error.WriteLine("- Install .NET Core 3");
Console.Error.WriteLine("- Setup MGFXC_WINE_PATH environmental variable to point to a valid wine prefix");
Console.Error.WriteLine("");
return -1;
}
Environment.SetEnvironmentVariable("WINEARCH", "win64");
Environment.SetEnvironmentVariable("WINEDLLOVERRIDES", "d3dcompiler_47=n");
Environment.SetEnvironmentVariable("WINEPREFIX", mgfxcwine);
Environment.SetEnvironmentVariable("WINEDEBUG", "-all");
var assemblyLocation = typeof(Program).Assembly.Location;
var input = ToPrefixPath(options.SourceFile);
var output = ToPrefixPath(options.OutputFile);
var proc = new Process();
proc.StartInfo.FileName = "wine64";
proc.StartInfo.Arguments = "dotnet ";
proc.StartInfo.AddPathArgument(assemblyLocation);
proc.StartInfo.AddPathArgument(input);
proc.StartInfo.AddPathArgument(output);
proc.StartInfo.AddOptionArgument("Profile", options.Profile.Name);
proc.StartInfo.AddOptionArgument("Defines", options.Defines);
proc.StartInfo.AddOptionArgument("Debug", options.Debug);
proc.Start();
proc.WaitForExit();
if (!File.Exists(options.OutputFile) || (new FileInfo(options.OutputFile)).Length == 0)
return 1;
return proc.ExitCode;
}
public static void AddPathArgument(this ProcessStartInfo startInfo, string value)
{
if (startInfo.Arguments == null)
startInfo.Arguments = "";
startInfo.Arguments += "\"" + value + "\" ";
}
public static void AddOptionArgument(this ProcessStartInfo startInfo, string option, object value)
{
if (startInfo.Arguments == null)
startInfo.Arguments = "";
if (value == null || string.IsNullOrEmpty(value.ToString()))
return;
startInfo.Arguments += "/" + option + ":" + value + " ";
}
public static string ToPrefixPath(string localPath)
{
var proc = new Process();
proc.StartInfo.FileName = "wine64";
proc.StartInfo.Arguments = "winepath.exe -w \"" + localPath + "\"";
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardOutput = true;
proc.Start();
return proc.StandardOutput.ReadToEnd().Trim('\n');
}
}
}