forked from ishani/ClangVSx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CVXSettings.cs
151 lines (127 loc) · 4.71 KB
/
CVXSettings.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*
* ClangVSx - Compiler Bridge for CLang in MS Visual Studio
* Harry Denholm, ishani.org 2011-2012
*
* https://github.com/ishani/ClangVSx
* http://www.ishani.org/web/articles/code/clangvsx/
*
* Released under LLVM Release License. See LICENSE.TXT for details.
*/
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Windows.Forms;
namespace ClangVSx
{
public partial class CVXSettings : Form
{
/// <summary>
/// Settings management
/// </summary>
public CVXSettings()
{
InitializeComponent();
cvxLocation.Text = CVXRegistry.PathToClang;
cvxShowCmds.Checked = CVXRegistry.ShowCommands;
cvxBatch.Checked = CVXRegistry.MakeBatchFiles;
cvxEcho.Checked = CVXRegistry.EchoInternal;
cvxPhases.Checked = CVXRegistry.ShowPhases;
cvxCOptCPP11.Checked = CVXRegistry.COptCPP11.Value;
cvxCOptMSABI.Checked = CVXRegistry.COptMSABI.Value;
cvxCommonArgs.Text = CVXRegistry.CommonArgs;
cvxTripleWin32.Text = CVXRegistry.TripleWin32;
cvxTripleX64.Text = CVXRegistry.TripleX64;
cvxTripleARM.Text = CVXRegistry.TripleARM;
cvxTOptOldSyntax.Checked = CVXRegistry.TOptOldSyntax.Value;
// blot the version number up in the title bar
Assembly assem = Assembly.GetExecutingAssembly();
Version vers = assem.GetName().Version;
Text = "ClangVSx [" + vers + "]";
}
private bool validEXELocation(String loc)
{
// scientific! -.-
return (File.Exists(loc) && loc.ToLower().EndsWith(".exe"));
}
private void cvxBrowse_Click(object sender, EventArgs e)
{
findClangExe.InitialDirectory = Path.GetDirectoryName(cvxLocation.Text);
if (findClangExe.ShowDialog(this) == DialogResult.OK)
{
cvxLocation.Text = findClangExe.FileName;
}
}
private void cvxDone_Click(object sender, EventArgs e)
{
{
// save back to the registry
CVXRegistry.PathToClang.Value = cvxLocation.Text;
CVXRegistry.ShowCommands.Value = cvxShowCmds.Checked;
CVXRegistry.MakeBatchFiles.Value = cvxBatch.Checked;
CVXRegistry.EchoInternal.Value = cvxEcho.Checked;
CVXRegistry.ShowPhases.Value = cvxPhases.Checked;
CVXRegistry.COptCPP11.Value = cvxCOptCPP11.Checked;
CVXRegistry.COptMSABI.Value = cvxCOptMSABI.Checked;
CVXRegistry.CommonArgs.Value = cvxCommonArgs.Text;
CVXRegistry.TripleWin32.Value = cvxTripleWin32.Text;
CVXRegistry.TripleX64.Value = cvxTripleX64.Text;
CVXRegistry.TripleARM.Value = cvxTripleARM.Text;
CVXRegistry.TOptOldSyntax.Value = cvxTOptOldSyntax.Checked;
}
if (!validEXELocation(cvxLocation.Text))
{
MessageBox.Show("Warning: Cannot find file specified for CLANG.EXE, will be unable to build projects.",
"ClangVSx Settings");
}
DialogResult = DialogResult.OK;
Close();
}
private void cvxLocation_TextChanged(object sender, EventArgs e)
{
if (validEXELocation(cvxLocation.Text))
{
String cvxStatsStr = "";
// execute the compiler, ask for version info
var compileProcess = new Process();
compileProcess.StartInfo.FileName = cvxLocation.Text;
compileProcess.StartInfo.Arguments = "-v";
compileProcess.StartInfo.UseShellExecute = false;
compileProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
compileProcess.StartInfo.CreateNoWindow = true;
compileProcess.StartInfo.RedirectStandardOutput = true;
compileProcess.StartInfo.RedirectStandardError = true;
compileProcess.Start();
cvxStatsStr += compileProcess.StandardError.ReadLine() + "\r\n";
cvxStatsStr += compileProcess.StandardError.ReadLine();
compileProcess.StandardError.ReadToEnd();
compileProcess.WaitForExit();
// version text contains 'clang', we can assume that's a pass
if (cvxStatsStr.Contains("clang"))
{
cvxStats.Text = cvxStatsStr;
cvxPic.Visible = true;
}
else
{
cvxStats.Text = "Cannot validate file to be Clang Compiler";
cvxPic.Visible = false;
}
}
else
{
cvxStats.Text = "Cannot find file specified";
cvxPic.Visible = false;
}
}
private void url_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
Process.Start(((LinkLabel)sender).Text);
}
private void cvxCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
}
}