diff options
author | Jacek Antonelli | 2009-01-13 00:19:34 -0600 |
---|---|---|
committer | Jacek Antonelli | 2009-01-13 00:19:34 -0600 |
commit | 106b2a600c59404ef6bb95b77f8bbf271b659baa (patch) | |
tree | 4f9394f0ca34003347de3dffff40efd8a3a43c6c /linden/indra/tools/vstool | |
parent | Merge 1.1.0 alpha into quickfilter (diff) | |
parent | Merge commit 'mccabe/1.1.0a-gstreamer' into 1.1.0a (diff) | |
download | meta-impy-106b2a600c59404ef6bb95b77f8bbf271b659baa.zip meta-impy-106b2a600c59404ef6bb95b77f8bbf271b659baa.tar.gz meta-impy-106b2a600c59404ef6bb95b77f8bbf271b659baa.tar.bz2 meta-impy-106b2a600c59404ef6bb95b77f8bbf271b659baa.tar.xz |
Merge branch '1.1.0a-gstreamer' into next
Diffstat (limited to 'linden/indra/tools/vstool')
-rw-r--r-- | linden/indra/tools/vstool/README.txt | 18 | ||||
-rw-r--r-- | linden/indra/tools/vstool/VSTool.csproj | 188 | ||||
-rw-r--r-- | linden/indra/tools/vstool/VSTool.sln | 38 | ||||
-rw-r--r-- | linden/indra/tools/vstool/main.cs | 1422 |
4 files changed, 833 insertions, 833 deletions
diff --git a/linden/indra/tools/vstool/README.txt b/linden/indra/tools/vstool/README.txt index e419180..6f64aa4 100644 --- a/linden/indra/tools/vstool/README.txt +++ b/linden/indra/tools/vstool/README.txt | |||
@@ -1,9 +1,9 @@ | |||
1 | VSTool is a command line utility to manipulate VisualStudio settings. | 1 | VSTool is a command line utility to manipulate VisualStudio settings. |
2 | 2 | ||
3 | The windows cmake project configuration uses VSTool.exe | 3 | The windows cmake project configuration uses VSTool.exe |
4 | 4 | ||
5 | A handy upgrade: | 5 | A handy upgrade: |
6 | figure out how to make cmake build this csharp app | 6 | figure out how to make cmake build this csharp app |
7 | - or write the app using script (jscript?!?) so it doesn't need to be built. | 7 | - or write the app using script (jscript?!?) so it doesn't need to be built. |
8 | 8 | ||
9 | 9 | ||
diff --git a/linden/indra/tools/vstool/VSTool.csproj b/linden/indra/tools/vstool/VSTool.csproj index 24f1031..5d8764b 100644 --- a/linden/indra/tools/vstool/VSTool.csproj +++ b/linden/indra/tools/vstool/VSTool.csproj | |||
@@ -1,95 +1,95 @@ | |||
1 | <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | 1 | <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
2 | <PropertyGroup> | 2 | <PropertyGroup> |
3 | <ProjectType>Local</ProjectType> | 3 | <ProjectType>Local</ProjectType> |
4 | <ProductVersion>8.0.50727</ProductVersion> | 4 | <ProductVersion>8.0.50727</ProductVersion> |
5 | <SchemaVersion>2.0</SchemaVersion> | 5 | <SchemaVersion>2.0</SchemaVersion> |
6 | <ProjectGuid>{96943E2D-1373-4617-A117-D0F997A94919}</ProjectGuid> | 6 | <ProjectGuid>{96943E2D-1373-4617-A117-D0F997A94919}</ProjectGuid> |
7 | <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | 7 | <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
8 | <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | 8 | <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> |
9 | <ApplicationIcon> | 9 | <ApplicationIcon> |
10 | </ApplicationIcon> | 10 | </ApplicationIcon> |
11 | <AssemblyKeyContainerName> | 11 | <AssemblyKeyContainerName> |
12 | </AssemblyKeyContainerName> | 12 | </AssemblyKeyContainerName> |
13 | <AssemblyName>VSTool</AssemblyName> | 13 | <AssemblyName>VSTool</AssemblyName> |
14 | <AssemblyOriginatorKeyFile> | 14 | <AssemblyOriginatorKeyFile> |
15 | </AssemblyOriginatorKeyFile> | 15 | </AssemblyOriginatorKeyFile> |
16 | <DefaultClientScript>JScript</DefaultClientScript> | 16 | <DefaultClientScript>JScript</DefaultClientScript> |
17 | <DefaultHTMLPageLayout>Grid</DefaultHTMLPageLayout> | 17 | <DefaultHTMLPageLayout>Grid</DefaultHTMLPageLayout> |
18 | <DefaultTargetSchema>IE50</DefaultTargetSchema> | 18 | <DefaultTargetSchema>IE50</DefaultTargetSchema> |
19 | <DelaySign>false</DelaySign> | 19 | <DelaySign>false</DelaySign> |
20 | <OutputType>Exe</OutputType> | 20 | <OutputType>Exe</OutputType> |
21 | <RootNamespace>VSTool</RootNamespace> | 21 | <RootNamespace>VSTool</RootNamespace> |
22 | <RunPostBuildEvent>Always</RunPostBuildEvent> | 22 | <RunPostBuildEvent>Always</RunPostBuildEvent> |
23 | <StartupObject>VSTool.VSToolMain</StartupObject> | 23 | <StartupObject>VSTool.VSToolMain</StartupObject> |
24 | <FileUpgradeFlags> | 24 | <FileUpgradeFlags> |
25 | </FileUpgradeFlags> | 25 | </FileUpgradeFlags> |
26 | <UpgradeBackupLocation> | 26 | <UpgradeBackupLocation> |
27 | </UpgradeBackupLocation> | 27 | </UpgradeBackupLocation> |
28 | </PropertyGroup> | 28 | </PropertyGroup> |
29 | <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | 29 | <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> |
30 | <OutputPath>.\</OutputPath> | 30 | <OutputPath>.\</OutputPath> |
31 | <AllowUnsafeBlocks>false</AllowUnsafeBlocks> | 31 | <AllowUnsafeBlocks>false</AllowUnsafeBlocks> |
32 | <BaseAddress>285212672</BaseAddress> | 32 | <BaseAddress>285212672</BaseAddress> |
33 | <CheckForOverflowUnderflow>false</CheckForOverflowUnderflow> | 33 | <CheckForOverflowUnderflow>false</CheckForOverflowUnderflow> |
34 | <ConfigurationOverrideFile> | 34 | <ConfigurationOverrideFile> |
35 | </ConfigurationOverrideFile> | 35 | </ConfigurationOverrideFile> |
36 | <DefineConstants>DEBUG;TRACE</DefineConstants> | 36 | <DefineConstants>DEBUG;TRACE</DefineConstants> |
37 | <DocumentationFile> | 37 | <DocumentationFile> |
38 | </DocumentationFile> | 38 | </DocumentationFile> |
39 | <DebugSymbols>true</DebugSymbols> | 39 | <DebugSymbols>true</DebugSymbols> |
40 | <FileAlignment>4096</FileAlignment> | 40 | <FileAlignment>4096</FileAlignment> |
41 | <NoStdLib>false</NoStdLib> | 41 | <NoStdLib>false</NoStdLib> |
42 | <NoWarn> | 42 | <NoWarn> |
43 | </NoWarn> | 43 | </NoWarn> |
44 | <Optimize>false</Optimize> | 44 | <Optimize>false</Optimize> |
45 | <RegisterForComInterop>false</RegisterForComInterop> | 45 | <RegisterForComInterop>false</RegisterForComInterop> |
46 | <RemoveIntegerChecks>false</RemoveIntegerChecks> | 46 | <RemoveIntegerChecks>false</RemoveIntegerChecks> |
47 | <TreatWarningsAsErrors>false</TreatWarningsAsErrors> | 47 | <TreatWarningsAsErrors>false</TreatWarningsAsErrors> |
48 | <WarningLevel>4</WarningLevel> | 48 | <WarningLevel>4</WarningLevel> |
49 | <DebugType>full</DebugType> | 49 | <DebugType>full</DebugType> |
50 | <ErrorReport>prompt</ErrorReport> | 50 | <ErrorReport>prompt</ErrorReport> |
51 | </PropertyGroup> | 51 | </PropertyGroup> |
52 | <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | 52 | <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> |
53 | <OutputPath>.\</OutputPath> | 53 | <OutputPath>.\</OutputPath> |
54 | <AllowUnsafeBlocks>false</AllowUnsafeBlocks> | 54 | <AllowUnsafeBlocks>false</AllowUnsafeBlocks> |
55 | <BaseAddress>285212672</BaseAddress> | 55 | <BaseAddress>285212672</BaseAddress> |
56 | <CheckForOverflowUnderflow>false</CheckForOverflowUnderflow> | 56 | <CheckForOverflowUnderflow>false</CheckForOverflowUnderflow> |
57 | <ConfigurationOverrideFile> | 57 | <ConfigurationOverrideFile> |
58 | </ConfigurationOverrideFile> | 58 | </ConfigurationOverrideFile> |
59 | <DefineConstants>TRACE</DefineConstants> | 59 | <DefineConstants>TRACE</DefineConstants> |
60 | <DocumentationFile> | 60 | <DocumentationFile> |
61 | </DocumentationFile> | 61 | </DocumentationFile> |
62 | <DebugSymbols>false</DebugSymbols> | 62 | <DebugSymbols>false</DebugSymbols> |
63 | <FileAlignment>4096</FileAlignment> | 63 | <FileAlignment>4096</FileAlignment> |
64 | <NoStdLib>false</NoStdLib> | 64 | <NoStdLib>false</NoStdLib> |
65 | <NoWarn> | 65 | <NoWarn> |
66 | </NoWarn> | 66 | </NoWarn> |
67 | <Optimize>true</Optimize> | 67 | <Optimize>true</Optimize> |
68 | <RegisterForComInterop>false</RegisterForComInterop> | 68 | <RegisterForComInterop>false</RegisterForComInterop> |
69 | <RemoveIntegerChecks>false</RemoveIntegerChecks> | 69 | <RemoveIntegerChecks>false</RemoveIntegerChecks> |
70 | <TreatWarningsAsErrors>false</TreatWarningsAsErrors> | 70 | <TreatWarningsAsErrors>false</TreatWarningsAsErrors> |
71 | <WarningLevel>4</WarningLevel> | 71 | <WarningLevel>4</WarningLevel> |
72 | <DebugType>none</DebugType> | 72 | <DebugType>none</DebugType> |
73 | <ErrorReport>prompt</ErrorReport> | 73 | <ErrorReport>prompt</ErrorReport> |
74 | </PropertyGroup> | 74 | </PropertyGroup> |
75 | <ItemGroup> | 75 | <ItemGroup> |
76 | <Reference Include="System"> | 76 | <Reference Include="System"> |
77 | <Name>System</Name> | 77 | <Name>System</Name> |
78 | </Reference> | 78 | </Reference> |
79 | <Reference Include="System.Data"> | 79 | <Reference Include="System.Data"> |
80 | <Name>System.Data</Name> | 80 | <Name>System.Data</Name> |
81 | </Reference> | 81 | </Reference> |
82 | </ItemGroup> | 82 | </ItemGroup> |
83 | <ItemGroup> | 83 | <ItemGroup> |
84 | <Compile Include="main.cs"> | 84 | <Compile Include="main.cs"> |
85 | <SubType>Code</SubType> | 85 | <SubType>Code</SubType> |
86 | </Compile> | 86 | </Compile> |
87 | </ItemGroup> | 87 | </ItemGroup> |
88 | <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> | 88 | <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> |
89 | <PropertyGroup> | 89 | <PropertyGroup> |
90 | <PreBuildEvent> | 90 | <PreBuildEvent> |
91 | </PreBuildEvent> | 91 | </PreBuildEvent> |
92 | <PostBuildEvent> | 92 | <PostBuildEvent> |
93 | </PostBuildEvent> | 93 | </PostBuildEvent> |
94 | </PropertyGroup> | 94 | </PropertyGroup> |
95 | </Project> \ No newline at end of file | 95 | </Project> \ No newline at end of file |
diff --git a/linden/indra/tools/vstool/VSTool.sln b/linden/indra/tools/vstool/VSTool.sln index 8859671..543a0a2 100644 --- a/linden/indra/tools/vstool/VSTool.sln +++ b/linden/indra/tools/vstool/VSTool.sln | |||
@@ -1,19 +1,19 @@ | |||
1 | Microsoft Visual Studio Solution File, Format Version 9.00 | 1 | Microsoft Visual Studio Solution File, Format Version 9.00 |
2 | # Visual Studio 2005 | 2 | # Visual Studio 2005 |
3 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VSTool", "VSTool.csproj", "{96943E2D-1373-4617-A117-D0F997A94919}" | 3 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VSTool", "VSTool.csproj", "{96943E2D-1373-4617-A117-D0F997A94919}" |
4 | EndProject | 4 | EndProject |
5 | Global | 5 | Global |
6 | GlobalSection(SolutionConfigurationPlatforms) = preSolution | 6 | GlobalSection(SolutionConfigurationPlatforms) = preSolution |
7 | Debug|Any CPU = Debug|Any CPU | 7 | Debug|Any CPU = Debug|Any CPU |
8 | Release|Any CPU = Release|Any CPU | 8 | Release|Any CPU = Release|Any CPU |
9 | EndGlobalSection | 9 | EndGlobalSection |
10 | GlobalSection(ProjectConfigurationPlatforms) = postSolution | 10 | GlobalSection(ProjectConfigurationPlatforms) = postSolution |
11 | {96943E2D-1373-4617-A117-D0F997A94919}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | 11 | {96943E2D-1373-4617-A117-D0F997A94919}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
12 | {96943E2D-1373-4617-A117-D0F997A94919}.Debug|Any CPU.Build.0 = Debug|Any CPU | 12 | {96943E2D-1373-4617-A117-D0F997A94919}.Debug|Any CPU.Build.0 = Debug|Any CPU |
13 | {96943E2D-1373-4617-A117-D0F997A94919}.Release|Any CPU.ActiveCfg = Release|Any CPU | 13 | {96943E2D-1373-4617-A117-D0F997A94919}.Release|Any CPU.ActiveCfg = Release|Any CPU |
14 | {96943E2D-1373-4617-A117-D0F997A94919}.Release|Any CPU.Build.0 = Release|Any CPU | 14 | {96943E2D-1373-4617-A117-D0F997A94919}.Release|Any CPU.Build.0 = Release|Any CPU |
15 | EndGlobalSection | 15 | EndGlobalSection |
16 | GlobalSection(SolutionProperties) = preSolution | 16 | GlobalSection(SolutionProperties) = preSolution |
17 | HideSolutionNode = FALSE | 17 | HideSolutionNode = FALSE |
18 | EndGlobalSection | 18 | EndGlobalSection |
19 | EndGlobal | 19 | EndGlobal |
diff --git a/linden/indra/tools/vstool/main.cs b/linden/indra/tools/vstool/main.cs index cc268d5..5c41c91 100644 --- a/linden/indra/tools/vstool/main.cs +++ b/linden/indra/tools/vstool/main.cs | |||
@@ -1,711 +1,711 @@ | |||
1 | // Code about getting running instances visual studio | 1 | // Code about getting running instances visual studio |
2 | // was borrowed from | 2 | // was borrowed from |
3 | // http://www.codeproject.com/KB/cs/automatingvisualstudio.aspx | 3 | // http://www.codeproject.com/KB/cs/automatingvisualstudio.aspx |
4 | 4 | ||
5 | 5 | ||
6 | using System; | 6 | using System; |
7 | using System.Collections; | 7 | using System.Collections; |
8 | using System.Collections.Generic; | 8 | using System.Collections.Generic; |
9 | using System.Reflection; | 9 | using System.Reflection; |
10 | using System.Runtime.InteropServices; | 10 | using System.Runtime.InteropServices; |
11 | using System.Runtime.InteropServices.ComTypes; | 11 | using System.Runtime.InteropServices.ComTypes; |
12 | using Microsoft.CSharp; | 12 | using Microsoft.CSharp; |
13 | 13 | ||
14 | namespace VSTool | 14 | namespace VSTool |
15 | { | 15 | { |
16 | // The MessageFilter class comes from: | 16 | // The MessageFilter class comes from: |
17 | // http://msdn.microsoft.com/en-us/library/ms228772(VS.80).aspx | 17 | // http://msdn.microsoft.com/en-us/library/ms228772(VS.80).aspx |
18 | // It allows vstool to get timing error messages from | 18 | // It allows vstool to get timing error messages from |
19 | // visualstudio and handle them. | 19 | // visualstudio and handle them. |
20 | public class MessageFilter : IOleMessageFilter | 20 | public class MessageFilter : IOleMessageFilter |
21 | { | 21 | { |
22 | // | 22 | // |
23 | // Class containing the IOleMessageFilter | 23 | // Class containing the IOleMessageFilter |
24 | // thread error-handling functions. | 24 | // thread error-handling functions. |
25 | 25 | ||
26 | // Start the filter. | 26 | // Start the filter. |
27 | public static void Register() | 27 | public static void Register() |
28 | { | 28 | { |
29 | IOleMessageFilter newFilter = new MessageFilter(); | 29 | IOleMessageFilter newFilter = new MessageFilter(); |
30 | IOleMessageFilter oldFilter = null; | 30 | IOleMessageFilter oldFilter = null; |
31 | CoRegisterMessageFilter(newFilter, out oldFilter); | 31 | CoRegisterMessageFilter(newFilter, out oldFilter); |
32 | } | 32 | } |
33 | 33 | ||
34 | // Done with the filter, close it. | 34 | // Done with the filter, close it. |
35 | public static void Revoke() | 35 | public static void Revoke() |
36 | { | 36 | { |
37 | IOleMessageFilter oldFilter = null; | 37 | IOleMessageFilter oldFilter = null; |
38 | CoRegisterMessageFilter(null, out oldFilter); | 38 | CoRegisterMessageFilter(null, out oldFilter); |
39 | } | 39 | } |
40 | 40 | ||
41 | // | 41 | // |
42 | // IOleMessageFilter functions. | 42 | // IOleMessageFilter functions. |
43 | // Handle incoming thread requests. | 43 | // Handle incoming thread requests. |
44 | int IOleMessageFilter.HandleInComingCall(int dwCallType, | 44 | int IOleMessageFilter.HandleInComingCall(int dwCallType, |
45 | System.IntPtr hTaskCaller, int dwTickCount, System.IntPtr | 45 | System.IntPtr hTaskCaller, int dwTickCount, System.IntPtr |
46 | lpInterfaceInfo) | 46 | lpInterfaceInfo) |
47 | { | 47 | { |
48 | //Return the flag SERVERCALL_ISHANDLED. | 48 | //Return the flag SERVERCALL_ISHANDLED. |
49 | return 0; | 49 | return 0; |
50 | } | 50 | } |
51 | 51 | ||
52 | // Thread call was rejected, so try again. | 52 | // Thread call was rejected, so try again. |
53 | int IOleMessageFilter.RetryRejectedCall(System.IntPtr | 53 | int IOleMessageFilter.RetryRejectedCall(System.IntPtr |
54 | hTaskCallee, int dwTickCount, int dwRejectType) | 54 | hTaskCallee, int dwTickCount, int dwRejectType) |
55 | { | 55 | { |
56 | if (dwRejectType == 2) | 56 | if (dwRejectType == 2) |
57 | // flag = SERVERCALL_RETRYLATER. | 57 | // flag = SERVERCALL_RETRYLATER. |
58 | { | 58 | { |
59 | // Retry the thread call immediately if return >=0 & | 59 | // Retry the thread call immediately if return >=0 & |
60 | // <100. | 60 | // <100. |
61 | return 99; | 61 | return 99; |
62 | } | 62 | } |
63 | // Too busy; cancel call. | 63 | // Too busy; cancel call. |
64 | return -1; | 64 | return -1; |
65 | } | 65 | } |
66 | 66 | ||
67 | int IOleMessageFilter.MessagePending(System.IntPtr hTaskCallee, | 67 | int IOleMessageFilter.MessagePending(System.IntPtr hTaskCallee, |
68 | int dwTickCount, int dwPendingType) | 68 | int dwTickCount, int dwPendingType) |
69 | { | 69 | { |
70 | //Return the flag PENDINGMSG_WAITDEFPROCESS. | 70 | //Return the flag PENDINGMSG_WAITDEFPROCESS. |
71 | return 2; | 71 | return 2; |
72 | } | 72 | } |
73 | 73 | ||
74 | // Implement the IOleMessageFilter interface. | 74 | // Implement the IOleMessageFilter interface. |
75 | [DllImport("Ole32.dll")] | 75 | [DllImport("Ole32.dll")] |
76 | private static extern int | 76 | private static extern int |
77 | CoRegisterMessageFilter(IOleMessageFilter newFilter, out | 77 | CoRegisterMessageFilter(IOleMessageFilter newFilter, out |
78 | IOleMessageFilter oldFilter); | 78 | IOleMessageFilter oldFilter); |
79 | } | 79 | } |
80 | 80 | ||
81 | [ComImport(), Guid("00000016-0000-0000-C000-000000000046"), | 81 | [ComImport(), Guid("00000016-0000-0000-C000-000000000046"), |
82 | InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)] | 82 | InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)] |
83 | interface IOleMessageFilter | 83 | interface IOleMessageFilter |
84 | { | 84 | { |
85 | [PreserveSig] | 85 | [PreserveSig] |
86 | int HandleInComingCall( | 86 | int HandleInComingCall( |
87 | int dwCallType, | 87 | int dwCallType, |
88 | IntPtr hTaskCaller, | 88 | IntPtr hTaskCaller, |
89 | int dwTickCount, | 89 | int dwTickCount, |
90 | IntPtr lpInterfaceInfo); | 90 | IntPtr lpInterfaceInfo); |
91 | 91 | ||
92 | [PreserveSig] | 92 | [PreserveSig] |
93 | int RetryRejectedCall( | 93 | int RetryRejectedCall( |
94 | IntPtr hTaskCallee, | 94 | IntPtr hTaskCallee, |
95 | int dwTickCount, | 95 | int dwTickCount, |
96 | int dwRejectType); | 96 | int dwRejectType); |
97 | 97 | ||
98 | [PreserveSig] | 98 | [PreserveSig] |
99 | int MessagePending( | 99 | int MessagePending( |
100 | IntPtr hTaskCallee, | 100 | IntPtr hTaskCallee, |
101 | int dwTickCount, | 101 | int dwTickCount, |
102 | int dwPendingType); | 102 | int dwPendingType); |
103 | } | 103 | } |
104 | 104 | ||
105 | class ViaCOM | 105 | class ViaCOM |
106 | { | 106 | { |
107 | public static object GetProperty(object from_obj, string prop_name) | 107 | public static object GetProperty(object from_obj, string prop_name) |
108 | { | 108 | { |
109 | try | 109 | try |
110 | { | 110 | { |
111 | Type objType = from_obj.GetType(); | 111 | Type objType = from_obj.GetType(); |
112 | return objType.InvokeMember( | 112 | return objType.InvokeMember( |
113 | prop_name, | 113 | prop_name, |
114 | BindingFlags.GetProperty, null, | 114 | BindingFlags.GetProperty, null, |
115 | from_obj, | 115 | from_obj, |
116 | null); | 116 | null); |
117 | } | 117 | } |
118 | catch (Exception e) | 118 | catch (Exception e) |
119 | { | 119 | { |
120 | Console.WriteLine("Error getting property: \"{0}\"", prop_name); | 120 | Console.WriteLine("Error getting property: \"{0}\"", prop_name); |
121 | Console.WriteLine(e.Message); | 121 | Console.WriteLine(e.Message); |
122 | throw e; | 122 | throw e; |
123 | } | 123 | } |
124 | } | 124 | } |
125 | 125 | ||
126 | public static object SetProperty(object from_obj, string prop_name, object new_value) | 126 | public static object SetProperty(object from_obj, string prop_name, object new_value) |
127 | { | 127 | { |
128 | try | 128 | try |
129 | { | 129 | { |
130 | object[] args = { new_value }; | 130 | object[] args = { new_value }; |
131 | Type objType = from_obj.GetType(); | 131 | Type objType = from_obj.GetType(); |
132 | return objType.InvokeMember( | 132 | return objType.InvokeMember( |
133 | prop_name, | 133 | prop_name, |
134 | BindingFlags.DeclaredOnly | | 134 | BindingFlags.DeclaredOnly | |
135 | BindingFlags.Public | | 135 | BindingFlags.Public | |
136 | BindingFlags.NonPublic | | 136 | BindingFlags.NonPublic | |
137 | BindingFlags.Instance | | 137 | BindingFlags.Instance | |
138 | BindingFlags.SetProperty, | 138 | BindingFlags.SetProperty, |
139 | null, | 139 | null, |
140 | from_obj, | 140 | from_obj, |
141 | args); | 141 | args); |
142 | } | 142 | } |
143 | catch (Exception e) | 143 | catch (Exception e) |
144 | { | 144 | { |
145 | Console.WriteLine("Error setting property: \"{0}\"", prop_name); | 145 | Console.WriteLine("Error setting property: \"{0}\"", prop_name); |
146 | Console.WriteLine(e.Message); | 146 | Console.WriteLine(e.Message); |
147 | throw e; | 147 | throw e; |
148 | } | 148 | } |
149 | } | 149 | } |
150 | 150 | ||
151 | public static object CallMethod(object from_obj, string method_name, params object[] args) | 151 | public static object CallMethod(object from_obj, string method_name, params object[] args) |
152 | { | 152 | { |
153 | try | 153 | try |
154 | { | 154 | { |
155 | Type objType = from_obj.GetType(); | 155 | Type objType = from_obj.GetType(); |
156 | return objType.InvokeMember( | 156 | return objType.InvokeMember( |
157 | method_name, | 157 | method_name, |
158 | BindingFlags.DeclaredOnly | | 158 | BindingFlags.DeclaredOnly | |
159 | BindingFlags.Public | | 159 | BindingFlags.Public | |
160 | BindingFlags.NonPublic | | 160 | BindingFlags.NonPublic | |
161 | BindingFlags.Instance | | 161 | BindingFlags.Instance | |
162 | BindingFlags.InvokeMethod, | 162 | BindingFlags.InvokeMethod, |
163 | null, | 163 | null, |
164 | from_obj, | 164 | from_obj, |
165 | args); | 165 | args); |
166 | } | 166 | } |
167 | catch (Exception e) | 167 | catch (Exception e) |
168 | { | 168 | { |
169 | Console.WriteLine("Error calling method \"{0}\"", method_name); | 169 | Console.WriteLine("Error calling method \"{0}\"", method_name); |
170 | Console.WriteLine(e.Message); | 170 | Console.WriteLine(e.Message); |
171 | throw e; | 171 | throw e; |
172 | } | 172 | } |
173 | } | 173 | } |
174 | }; | 174 | }; |
175 | 175 | ||
176 | /// <summary> | 176 | /// <summary> |
177 | /// The main entry point class for VSTool. | 177 | /// The main entry point class for VSTool. |
178 | /// </summary> | 178 | /// </summary> |
179 | class VSToolMain | 179 | class VSToolMain |
180 | { | 180 | { |
181 | #region Interop imports | 181 | #region Interop imports |
182 | [DllImport("ole32.dll")] | 182 | [DllImport("ole32.dll")] |
183 | public static extern int GetRunningObjectTable(int reserved, out IRunningObjectTable prot); | 183 | public static extern int GetRunningObjectTable(int reserved, out IRunningObjectTable prot); |
184 | 184 | ||
185 | [DllImport("ole32.dll")] | 185 | [DllImport("ole32.dll")] |
186 | public static extern int CreateBindCtx(int reserved, out IBindCtx ppbc); | 186 | public static extern int CreateBindCtx(int reserved, out IBindCtx ppbc); |
187 | #endregion | 187 | #endregion |
188 | 188 | ||
189 | static System.Boolean ignore_case = true; | 189 | static System.Boolean ignore_case = true; |
190 | 190 | ||
191 | static string solution_name = null; | 191 | static string solution_name = null; |
192 | static bool use_new_vs = false; | 192 | static bool use_new_vs = false; |
193 | static Hashtable projectDict = new Hashtable(); | 193 | static Hashtable projectDict = new Hashtable(); |
194 | static string startup_project = null; | 194 | static string startup_project = null; |
195 | static string config = null; | 195 | static string config = null; |
196 | 196 | ||
197 | static object dte = null; | 197 | static object dte = null; |
198 | static object solution = null; | 198 | static object solution = null; |
199 | 199 | ||
200 | /// <summary> | 200 | /// <summary> |
201 | /// The main entry point for the application. | 201 | /// The main entry point for the application. |
202 | /// </summary> | 202 | /// </summary> |
203 | [STAThread] | 203 | [STAThread] |
204 | static int Main(string[] args) | 204 | static int Main(string[] args) |
205 | { | 205 | { |
206 | int retVal = 0; | 206 | int retVal = 0; |
207 | bool need_save = false; | 207 | bool need_save = false; |
208 | 208 | ||
209 | try | 209 | try |
210 | { | 210 | { |
211 | parse_command_line(args); | 211 | parse_command_line(args); |
212 | 212 | ||
213 | Console.WriteLine("Editing solution: {0}", solution_name); | 213 | Console.WriteLine("Editing solution: {0}", solution_name); |
214 | 214 | ||
215 | bool found_open_solution = GetDTEAndSolution(); | 215 | bool found_open_solution = GetDTEAndSolution(); |
216 | 216 | ||
217 | if (dte == null || solution == null) | 217 | if (dte == null || solution == null) |
218 | { | 218 | { |
219 | retVal = 1; | 219 | retVal = 1; |
220 | } | 220 | } |
221 | else | 221 | else |
222 | { | 222 | { |
223 | MessageFilter.Register(); | 223 | MessageFilter.Register(); |
224 | 224 | ||
225 | // Walk through all of the projects in the solution | 225 | // Walk through all of the projects in the solution |
226 | // and list the type of each project. | 226 | // and list the type of each project. |
227 | foreach (DictionaryEntry p in projectDict) | 227 | foreach (DictionaryEntry p in projectDict) |
228 | { | 228 | { |
229 | string project_name = (string)p.Key; | 229 | string project_name = (string)p.Key; |
230 | string working_dir = (string)p.Value; | 230 | string working_dir = (string)p.Value; |
231 | if (SetProjectWorkingDir(solution, project_name, working_dir)) | 231 | if (SetProjectWorkingDir(solution, project_name, working_dir)) |
232 | { | 232 | { |
233 | need_save = true; | 233 | need_save = true; |
234 | } | 234 | } |
235 | } | 235 | } |
236 | 236 | ||
237 | if (config != null) | 237 | if (config != null) |
238 | { | 238 | { |
239 | need_save = SetActiveConfig(config); | 239 | need_save = SetActiveConfig(config); |
240 | } | 240 | } |
241 | 241 | ||
242 | if (startup_project != null) | 242 | if (startup_project != null) |
243 | { | 243 | { |
244 | need_save = SetStartupProject(startup_project); | 244 | need_save = SetStartupProject(startup_project); |
245 | } | 245 | } |
246 | 246 | ||
247 | if (need_save) | 247 | if (need_save) |
248 | { | 248 | { |
249 | if (found_open_solution == false) | 249 | if (found_open_solution == false) |
250 | { | 250 | { |
251 | ViaCOM.CallMethod(solution, "Close", null); | 251 | ViaCOM.CallMethod(solution, "Close", null); |
252 | } | 252 | } |
253 | } | 253 | } |
254 | } | 254 | } |
255 | } | 255 | } |
256 | catch (Exception e) | 256 | catch (Exception e) |
257 | { | 257 | { |
258 | Console.WriteLine(e.Message); | 258 | Console.WriteLine(e.Message); |
259 | retVal = 1; | 259 | retVal = 1; |
260 | } | 260 | } |
261 | finally | 261 | finally |
262 | { | 262 | { |
263 | if (solution != null) | 263 | if (solution != null) |
264 | { | 264 | { |
265 | Marshal.ReleaseComObject(solution); | 265 | Marshal.ReleaseComObject(solution); |
266 | solution = null; | 266 | solution = null; |
267 | } | 267 | } |
268 | 268 | ||
269 | if (dte != null) | 269 | if (dte != null) |
270 | { | 270 | { |
271 | Marshal.ReleaseComObject(dte); | 271 | Marshal.ReleaseComObject(dte); |
272 | dte = null; | 272 | dte = null; |
273 | } | 273 | } |
274 | 274 | ||
275 | MessageFilter.Revoke(); | 275 | MessageFilter.Revoke(); |
276 | } | 276 | } |
277 | return retVal; | 277 | return retVal; |
278 | } | 278 | } |
279 | 279 | ||
280 | public static bool parse_command_line(string[] args) | 280 | public static bool parse_command_line(string[] args) |
281 | { | 281 | { |
282 | string options_desc = | 282 | string options_desc = |
283 | "--solution <solution_name> : MSVC solution name. (required)\n" + | 283 | "--solution <solution_name> : MSVC solution name. (required)\n" + |
284 | "--use_new_vs : Ignore running versions of visual studio.\n" + | 284 | "--use_new_vs : Ignore running versions of visual studio.\n" + |
285 | "--workingdir <project> <dir> : Set working dir of a VC project.\n" + | 285 | "--workingdir <project> <dir> : Set working dir of a VC project.\n" + |
286 | "--config <config> : Set the active config for the solution.\n" + | 286 | "--config <config> : Set the active config for the solution.\n" + |
287 | "--startup <project> : Set the startup project for the solution.\n"; | 287 | "--startup <project> : Set the startup project for the solution.\n"; |
288 | 288 | ||
289 | try | 289 | try |
290 | { | 290 | { |
291 | // Command line param parsing loop. | 291 | // Command line param parsing loop. |
292 | int i = 0; | 292 | int i = 0; |
293 | for (; i < args.Length; ++i) | 293 | for (; i < args.Length; ++i) |
294 | { | 294 | { |
295 | if ("--solution" == args[i]) | 295 | if ("--solution" == args[i]) |
296 | { | 296 | { |
297 | if (solution_name != null) | 297 | if (solution_name != null) |
298 | { | 298 | { |
299 | throw new ApplicationException("Found second --solution option"); | 299 | throw new ApplicationException("Found second --solution option"); |
300 | } | 300 | } |
301 | solution_name = args[++i]; | 301 | solution_name = args[++i]; |
302 | } | 302 | } |
303 | else if ("--use_new_vs" == args[i]) | 303 | else if ("--use_new_vs" == args[i]) |
304 | { | 304 | { |
305 | use_new_vs = true; | 305 | use_new_vs = true; |
306 | } | 306 | } |
307 | 307 | ||
308 | else if ("--workingdir" == args[i]) | 308 | else if ("--workingdir" == args[i]) |
309 | { | 309 | { |
310 | string project_name = args[++i]; | 310 | string project_name = args[++i]; |
311 | string working_dir = args[++i]; | 311 | string working_dir = args[++i]; |
312 | projectDict.Add(project_name, working_dir); | 312 | projectDict.Add(project_name, working_dir); |
313 | } | 313 | } |
314 | else if ("--config" == args[i]) | 314 | else if ("--config" == args[i]) |
315 | { | 315 | { |
316 | if (config != null) | 316 | if (config != null) |
317 | { | 317 | { |
318 | throw new ApplicationException("Found second --config option"); | 318 | throw new ApplicationException("Found second --config option"); |
319 | } | 319 | } |
320 | config = args[++i]; | 320 | config = args[++i]; |
321 | } | 321 | } |
322 | else if ("--startup" == args[i]) | 322 | else if ("--startup" == args[i]) |
323 | { | 323 | { |
324 | if (startup_project != null) | 324 | if (startup_project != null) |
325 | { | 325 | { |
326 | throw new ApplicationException("Found second --startup option"); | 326 | throw new ApplicationException("Found second --startup option"); |
327 | } | 327 | } |
328 | startup_project = args[++i]; | 328 | startup_project = args[++i]; |
329 | } | 329 | } |
330 | else | 330 | else |
331 | { | 331 | { |
332 | throw new ApplicationException("Found unrecognized token on command line: " + args[i]); | 332 | throw new ApplicationException("Found unrecognized token on command line: " + args[i]); |
333 | } | 333 | } |
334 | } | 334 | } |
335 | 335 | ||
336 | if (solution_name == null) | 336 | if (solution_name == null) |
337 | { | 337 | { |
338 | throw new ApplicationException("The --solution option is required."); | 338 | throw new ApplicationException("The --solution option is required."); |
339 | } | 339 | } |
340 | } | 340 | } |
341 | catch(ApplicationException e) | 341 | catch(ApplicationException e) |
342 | { | 342 | { |
343 | 343 | ||
344 | Console.WriteLine("Oops! " + e.Message); | 344 | Console.WriteLine("Oops! " + e.Message); |
345 | Console.Write("Command line:"); | 345 | Console.Write("Command line:"); |
346 | foreach (string arg in args) | 346 | foreach (string arg in args) |
347 | { | 347 | { |
348 | Console.Write(" " + arg); | 348 | Console.Write(" " + arg); |
349 | } | 349 | } |
350 | Console.Write("\n\n"); | 350 | Console.Write("\n\n"); |
351 | Console.WriteLine("VSTool command line usage"); | 351 | Console.WriteLine("VSTool command line usage"); |
352 | Console.Write(options_desc); | 352 | Console.Write(options_desc); |
353 | throw e; | 353 | throw e; |
354 | } | 354 | } |
355 | return true; | 355 | return true; |
356 | } | 356 | } |
357 | 357 | ||
358 | public static bool GetDTEAndSolution() | 358 | public static bool GetDTEAndSolution() |
359 | { | 359 | { |
360 | bool found_open_solution = true; | 360 | bool found_open_solution = true; |
361 | 361 | ||
362 | Console.WriteLine("Looking for existing VisualStudio instance..."); | 362 | Console.WriteLine("Looking for existing VisualStudio instance..."); |
363 | 363 | ||
364 | // Get an instance of the currently running Visual Studio .NET IDE. | 364 | // Get an instance of the currently running Visual Studio .NET IDE. |
365 | // dte = (EnvDTE.DTE)System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE.7.1"); | 365 | // dte = (EnvDTE.DTE)System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE.7.1"); |
366 | string full_solution_name = System.IO.Path.GetFullPath(solution_name); | 366 | string full_solution_name = System.IO.Path.GetFullPath(solution_name); |
367 | if (false == use_new_vs) | 367 | if (false == use_new_vs) |
368 | { | 368 | { |
369 | dte = GetIDEInstance(full_solution_name); | 369 | dte = GetIDEInstance(full_solution_name); |
370 | } | 370 | } |
371 | 371 | ||
372 | if (dte == null) | 372 | if (dte == null) |
373 | { | 373 | { |
374 | try | 374 | try |
375 | { | 375 | { |
376 | Console.WriteLine(" Didn't find open solution, starting new background VisualStudio instance..."); | 376 | Console.WriteLine(" Didn't find open solution, starting new background VisualStudio instance..."); |
377 | Console.WriteLine(" Reading .sln file version..."); | 377 | Console.WriteLine(" Reading .sln file version..."); |
378 | string version = GetSolutionVersion(full_solution_name); | 378 | string version = GetSolutionVersion(full_solution_name); |
379 | 379 | ||
380 | Console.WriteLine(" Using version: {0}...", version); | 380 | Console.WriteLine(" Using version: {0}...", version); |
381 | string progid = GetVSProgID(version); | 381 | string progid = GetVSProgID(version); |
382 | 382 | ||
383 | Type objType = Type.GetTypeFromProgID(progid); | 383 | Type objType = Type.GetTypeFromProgID(progid); |
384 | dte = System.Activator.CreateInstance(objType); | 384 | dte = System.Activator.CreateInstance(objType); |
385 | Console.WriteLine(" Reading solution: \"{0}\"", full_solution_name); | 385 | Console.WriteLine(" Reading solution: \"{0}\"", full_solution_name); |
386 | 386 | ||
387 | solution = ViaCOM.GetProperty(dte, "Solution"); | 387 | solution = ViaCOM.GetProperty(dte, "Solution"); |
388 | object[] openArgs = { full_solution_name }; | 388 | object[] openArgs = { full_solution_name }; |
389 | ViaCOM.CallMethod(solution, "Open", openArgs); | 389 | ViaCOM.CallMethod(solution, "Open", openArgs); |
390 | } | 390 | } |
391 | catch (Exception e) | 391 | catch (Exception e) |
392 | { | 392 | { |
393 | Console.WriteLine(e.Message); | 393 | Console.WriteLine(e.Message); |
394 | Console.WriteLine("Quitting do to error opening: {0}", full_solution_name); | 394 | Console.WriteLine("Quitting do to error opening: {0}", full_solution_name); |
395 | solution = null; | 395 | solution = null; |
396 | dte = null; | 396 | dte = null; |
397 | return found_open_solution; | 397 | return found_open_solution; |
398 | } | 398 | } |
399 | found_open_solution = false; | 399 | found_open_solution = false; |
400 | } | 400 | } |
401 | 401 | ||
402 | if (solution == null) | 402 | if (solution == null) |
403 | { | 403 | { |
404 | solution = ViaCOM.GetProperty(dte, "Solution"); | 404 | solution = ViaCOM.GetProperty(dte, "Solution"); |
405 | } | 405 | } |
406 | 406 | ||
407 | return found_open_solution; | 407 | return found_open_solution; |
408 | } | 408 | } |
409 | 409 | ||
410 | /// <summary> | 410 | /// <summary> |
411 | /// Get the DTE object for the instance of Visual Studio IDE that has | 411 | /// Get the DTE object for the instance of Visual Studio IDE that has |
412 | /// the specified solution open. | 412 | /// the specified solution open. |
413 | /// </summary> | 413 | /// </summary> |
414 | /// <param name="solutionFile">The absolute filename of the solution</param> | 414 | /// <param name="solutionFile">The absolute filename of the solution</param> |
415 | /// <returns>Corresponding DTE object or null if no such IDE is running</returns> | 415 | /// <returns>Corresponding DTE object or null if no such IDE is running</returns> |
416 | public static object GetIDEInstance( string solutionFile ) | 416 | public static object GetIDEInstance( string solutionFile ) |
417 | { | 417 | { |
418 | Hashtable runningInstances = GetIDEInstances( true ); | 418 | Hashtable runningInstances = GetIDEInstances( true ); |
419 | IDictionaryEnumerator enumerator = runningInstances.GetEnumerator(); | 419 | IDictionaryEnumerator enumerator = runningInstances.GetEnumerator(); |
420 | 420 | ||
421 | while ( enumerator.MoveNext() ) | 421 | while ( enumerator.MoveNext() ) |
422 | { | 422 | { |
423 | try | 423 | try |
424 | { | 424 | { |
425 | object ide = enumerator.Value; | 425 | object ide = enumerator.Value; |
426 | if (ide != null) | 426 | if (ide != null) |
427 | { | 427 | { |
428 | object sol = ViaCOM.GetProperty(ide, "Solution"); | 428 | object sol = ViaCOM.GetProperty(ide, "Solution"); |
429 | if (0 == string.Compare((string)ViaCOM.GetProperty(sol, "FullName"), solutionFile, ignore_case)) | 429 | if (0 == string.Compare((string)ViaCOM.GetProperty(sol, "FullName"), solutionFile, ignore_case)) |
430 | { | 430 | { |
431 | return ide; | 431 | return ide; |
432 | } | 432 | } |
433 | } | 433 | } |
434 | } | 434 | } |
435 | catch{} | 435 | catch{} |
436 | } | 436 | } |
437 | 437 | ||
438 | return null; | 438 | return null; |
439 | } | 439 | } |
440 | 440 | ||
441 | /// <summary> | 441 | /// <summary> |
442 | /// Get a table of the currently running instances of the Visual Studio .NET IDE. | 442 | /// Get a table of the currently running instances of the Visual Studio .NET IDE. |
443 | /// </summary> | 443 | /// </summary> |
444 | /// <param name="openSolutionsOnly">Only return instances that have opened a solution</param> | 444 | /// <param name="openSolutionsOnly">Only return instances that have opened a solution</param> |
445 | /// <returns>A hashtable mapping the name of the IDE in the running object table to the corresponding DTE object</returns> | 445 | /// <returns>A hashtable mapping the name of the IDE in the running object table to the corresponding DTE object</returns> |
446 | public static Hashtable GetIDEInstances( bool openSolutionsOnly ) | 446 | public static Hashtable GetIDEInstances( bool openSolutionsOnly ) |
447 | { | 447 | { |
448 | Hashtable runningIDEInstances = new Hashtable(); | 448 | Hashtable runningIDEInstances = new Hashtable(); |
449 | Hashtable runningObjects = GetRunningObjectTable(); | 449 | Hashtable runningObjects = GetRunningObjectTable(); |
450 | 450 | ||
451 | IDictionaryEnumerator rotEnumerator = runningObjects.GetEnumerator(); | 451 | IDictionaryEnumerator rotEnumerator = runningObjects.GetEnumerator(); |
452 | while ( rotEnumerator.MoveNext() ) | 452 | while ( rotEnumerator.MoveNext() ) |
453 | { | 453 | { |
454 | string candidateName = (string) rotEnumerator.Key; | 454 | string candidateName = (string) rotEnumerator.Key; |
455 | if (!candidateName.StartsWith("!VisualStudio.DTE")) | 455 | if (!candidateName.StartsWith("!VisualStudio.DTE")) |
456 | continue; | 456 | continue; |
457 | 457 | ||
458 | object ide = rotEnumerator.Value; | 458 | object ide = rotEnumerator.Value; |
459 | if (ide == null) | 459 | if (ide == null) |
460 | continue; | 460 | continue; |
461 | 461 | ||
462 | if (openSolutionsOnly) | 462 | if (openSolutionsOnly) |
463 | { | 463 | { |
464 | try | 464 | try |
465 | { | 465 | { |
466 | object sol = ViaCOM.GetProperty(ide, "Solution"); | 466 | object sol = ViaCOM.GetProperty(ide, "Solution"); |
467 | string solutionFile = (string)ViaCOM.GetProperty(sol, "FullName"); | 467 | string solutionFile = (string)ViaCOM.GetProperty(sol, "FullName"); |
468 | if (solutionFile != String.Empty) | 468 | if (solutionFile != String.Empty) |
469 | { | 469 | { |
470 | runningIDEInstances[ candidateName ] = ide; | 470 | runningIDEInstances[ candidateName ] = ide; |
471 | } | 471 | } |
472 | } | 472 | } |
473 | catch {} | 473 | catch {} |
474 | } | 474 | } |
475 | else | 475 | else |
476 | { | 476 | { |
477 | runningIDEInstances[ candidateName ] = ide; | 477 | runningIDEInstances[ candidateName ] = ide; |
478 | } | 478 | } |
479 | } | 479 | } |
480 | return runningIDEInstances; | 480 | return runningIDEInstances; |
481 | } | 481 | } |
482 | 482 | ||
483 | /// <summary> | 483 | /// <summary> |
484 | /// Get a snapshot of the running object table (ROT). | 484 | /// Get a snapshot of the running object table (ROT). |
485 | /// </summary> | 485 | /// </summary> |
486 | /// <returns>A hashtable mapping the name of the object in the ROT to the corresponding object</returns> | 486 | /// <returns>A hashtable mapping the name of the object in the ROT to the corresponding object</returns> |
487 | [STAThread] | 487 | [STAThread] |
488 | public static Hashtable GetRunningObjectTable() | 488 | public static Hashtable GetRunningObjectTable() |
489 | { | 489 | { |
490 | Hashtable result = new Hashtable(); | 490 | Hashtable result = new Hashtable(); |
491 | 491 | ||
492 | int numFetched = 0; | 492 | int numFetched = 0; |
493 | IRunningObjectTable runningObjectTable; | 493 | IRunningObjectTable runningObjectTable; |
494 | IEnumMoniker monikerEnumerator; | 494 | IEnumMoniker monikerEnumerator; |
495 | IMoniker[] monikers = new IMoniker[1]; | 495 | IMoniker[] monikers = new IMoniker[1]; |
496 | 496 | ||
497 | GetRunningObjectTable(0, out runningObjectTable); | 497 | GetRunningObjectTable(0, out runningObjectTable); |
498 | runningObjectTable.EnumRunning(out monikerEnumerator); | 498 | runningObjectTable.EnumRunning(out monikerEnumerator); |
499 | monikerEnumerator.Reset(); | 499 | monikerEnumerator.Reset(); |
500 | 500 | ||
501 | while (monikerEnumerator.Next(1, monikers, new IntPtr(numFetched)) == 0) | 501 | while (monikerEnumerator.Next(1, monikers, new IntPtr(numFetched)) == 0) |
502 | { | 502 | { |
503 | IBindCtx ctx; | 503 | IBindCtx ctx; |
504 | CreateBindCtx(0, out ctx); | 504 | CreateBindCtx(0, out ctx); |
505 | 505 | ||
506 | string runningObjectName; | 506 | string runningObjectName; |
507 | monikers[0].GetDisplayName(ctx, null, out runningObjectName); | 507 | monikers[0].GetDisplayName(ctx, null, out runningObjectName); |
508 | 508 | ||
509 | object runningObjectVal; | 509 | object runningObjectVal; |
510 | runningObjectTable.GetObject( monikers[0], out runningObjectVal); | 510 | runningObjectTable.GetObject( monikers[0], out runningObjectVal); |
511 | 511 | ||
512 | result[ runningObjectName ] = runningObjectVal; | 512 | result[ runningObjectName ] = runningObjectVal; |
513 | } | 513 | } |
514 | 514 | ||
515 | return result; | 515 | return result; |
516 | } | 516 | } |
517 | 517 | ||
518 | public static string GetSolutionVersion(string solutionFullFileName) | 518 | public static string GetSolutionVersion(string solutionFullFileName) |
519 | { | 519 | { |
520 | string version; | 520 | string version; |
521 | System.IO.StreamReader solutionStreamReader = null; | 521 | System.IO.StreamReader solutionStreamReader = null; |
522 | string firstLine; | 522 | string firstLine; |
523 | string format; | 523 | string format; |
524 | 524 | ||
525 | try | 525 | try |
526 | { | 526 | { |
527 | solutionStreamReader = new System.IO.StreamReader(solutionFullFileName); | 527 | solutionStreamReader = new System.IO.StreamReader(solutionFullFileName); |
528 | do | 528 | do |
529 | { | 529 | { |
530 | firstLine = solutionStreamReader.ReadLine(); | 530 | firstLine = solutionStreamReader.ReadLine(); |
531 | } | 531 | } |
532 | while (firstLine == ""); | 532 | while (firstLine == ""); |
533 | 533 | ||
534 | format = firstLine.Substring(firstLine.LastIndexOf(" ")).Trim(); | 534 | format = firstLine.Substring(firstLine.LastIndexOf(" ")).Trim(); |
535 | 535 | ||
536 | switch(format) | 536 | switch(format) |
537 | { | 537 | { |
538 | case "7.00": | 538 | case "7.00": |
539 | version = "VC70"; | 539 | version = "VC70"; |
540 | break; | 540 | break; |
541 | 541 | ||
542 | case "8.00": | 542 | case "8.00": |
543 | version = "VC71"; | 543 | version = "VC71"; |
544 | break; | 544 | break; |
545 | 545 | ||
546 | case "9.00": | 546 | case "9.00": |
547 | version = "VC80"; | 547 | version = "VC80"; |
548 | break; | 548 | break; |
549 | 549 | ||
550 | case "10.00": | 550 | case "10.00": |
551 | version = "VC90"; | 551 | version = "VC90"; |
552 | break; | 552 | break; |
553 | default: | 553 | default: |
554 | throw new ApplicationException("Unknown .sln version: " + format); | 554 | throw new ApplicationException("Unknown .sln version: " + format); |
555 | } | 555 | } |
556 | } | 556 | } |
557 | finally | 557 | finally |
558 | { | 558 | { |
559 | if(solutionStreamReader != null) | 559 | if(solutionStreamReader != null) |
560 | { | 560 | { |
561 | solutionStreamReader.Close(); | 561 | solutionStreamReader.Close(); |
562 | } | 562 | } |
563 | } | 563 | } |
564 | 564 | ||
565 | return version; | 565 | return version; |
566 | } | 566 | } |
567 | 567 | ||
568 | public static string GetVSProgID(string version) | 568 | public static string GetVSProgID(string version) |
569 | { | 569 | { |
570 | string progid = null; | 570 | string progid = null; |
571 | switch(version) | 571 | switch(version) |
572 | { | 572 | { |
573 | case "VC70": | 573 | case "VC70": |
574 | progid = "VisualStudio.DTE.7"; | 574 | progid = "VisualStudio.DTE.7"; |
575 | break; | 575 | break; |
576 | 576 | ||
577 | case "VC71": | 577 | case "VC71": |
578 | progid = "VisualStudio.DTE.7.1"; | 578 | progid = "VisualStudio.DTE.7.1"; |
579 | break; | 579 | break; |
580 | 580 | ||
581 | case "VC80": | 581 | case "VC80": |
582 | progid = "VisualStudio.DTE.8.0"; | 582 | progid = "VisualStudio.DTE.8.0"; |
583 | break; | 583 | break; |
584 | 584 | ||
585 | case "VC90": | 585 | case "VC90": |
586 | progid = "VisualStudio.DTE.9.0"; | 586 | progid = "VisualStudio.DTE.9.0"; |
587 | break; | 587 | break; |
588 | default: | 588 | default: |
589 | throw new ApplicationException("Can't handle VS version: " + version); | 589 | throw new ApplicationException("Can't handle VS version: " + version); |
590 | } | 590 | } |
591 | 591 | ||
592 | return progid; | 592 | return progid; |
593 | } | 593 | } |
594 | 594 | ||
595 | public static bool SetProjectWorkingDir(object sol, string project_name, string working_dir) | 595 | public static bool SetProjectWorkingDir(object sol, string project_name, string working_dir) |
596 | { | 596 | { |
597 | bool made_change = false; | 597 | bool made_change = false; |
598 | Console.WriteLine("Looking for project {0}...", project_name); | 598 | Console.WriteLine("Looking for project {0}...", project_name); |
599 | try | 599 | try |
600 | { | 600 | { |
601 | object prjs = ViaCOM.GetProperty(sol, "Projects"); | 601 | object prjs = ViaCOM.GetProperty(sol, "Projects"); |
602 | object count = ViaCOM.GetProperty(prjs, "Count"); | 602 | object count = ViaCOM.GetProperty(prjs, "Count"); |
603 | for(int i = 1; i <= (int)count; ++i) | 603 | for(int i = 1; i <= (int)count; ++i) |
604 | { | 604 | { |
605 | object[] prjItemArgs = { (object)i }; | 605 | object[] prjItemArgs = { (object)i }; |
606 | object prj = ViaCOM.CallMethod(prjs, "Item", prjItemArgs); | 606 | object prj = ViaCOM.CallMethod(prjs, "Item", prjItemArgs); |
607 | string name = (string)ViaCOM.GetProperty(prj, "Name"); | 607 | string name = (string)ViaCOM.GetProperty(prj, "Name"); |
608 | if (0 == string.Compare(name, project_name, ignore_case)) | 608 | if (0 == string.Compare(name, project_name, ignore_case)) |
609 | { | 609 | { |
610 | Console.WriteLine("Found project: {0}", project_name); | 610 | Console.WriteLine("Found project: {0}", project_name); |
611 | Console.WriteLine("Setting working directory"); | 611 | Console.WriteLine("Setting working directory"); |
612 | 612 | ||
613 | string full_project_name = (string)ViaCOM.GetProperty(prj, "FullName"); | 613 | string full_project_name = (string)ViaCOM.GetProperty(prj, "FullName"); |
614 | Console.WriteLine(full_project_name); | 614 | Console.WriteLine(full_project_name); |
615 | 615 | ||
616 | // *NOTE:Mani Thanks to incompatibilities between different versions of the | 616 | // *NOTE:Mani Thanks to incompatibilities between different versions of the |
617 | // VCProjectEngine.dll assembly, we can't cast the objects recevied from the DTE to | 617 | // VCProjectEngine.dll assembly, we can't cast the objects recevied from the DTE to |
618 | // the VCProjectEngine types from a different version than the one built | 618 | // the VCProjectEngine types from a different version than the one built |
619 | // with. ie, VisualStudio.DTE.7.1 objects can't be converted in a project built | 619 | // with. ie, VisualStudio.DTE.7.1 objects can't be converted in a project built |
620 | // in VS 8.0. To avoid this problem, we can use the com object interfaces directly, | 620 | // in VS 8.0. To avoid this problem, we can use the com object interfaces directly, |
621 | // without the type casting. Its tedious code, but it seems to work. | 621 | // without the type casting. Its tedious code, but it seems to work. |
622 | 622 | ||
623 | // oCfgs should be assigned to a 'Project.Configurations' collection. | 623 | // oCfgs should be assigned to a 'Project.Configurations' collection. |
624 | object oCfgs = ViaCOM.GetProperty(ViaCOM.GetProperty(prj, "Object"), "Configurations"); | 624 | object oCfgs = ViaCOM.GetProperty(ViaCOM.GetProperty(prj, "Object"), "Configurations"); |
625 | 625 | ||
626 | // oCount will be assigned to the number of configs present in oCfgs. | 626 | // oCount will be assigned to the number of configs present in oCfgs. |
627 | object oCount = ViaCOM.GetProperty(oCfgs, "Count"); | 627 | object oCount = ViaCOM.GetProperty(oCfgs, "Count"); |
628 | 628 | ||
629 | for (int cfgIndex = 1; cfgIndex <= (int)oCount; ++cfgIndex) | 629 | for (int cfgIndex = 1; cfgIndex <= (int)oCount; ++cfgIndex) |
630 | { | 630 | { |
631 | object[] itemArgs = {(object)cfgIndex}; | 631 | object[] itemArgs = {(object)cfgIndex}; |
632 | object oCfg = ViaCOM.CallMethod(oCfgs, "Item", itemArgs); | 632 | object oCfg = ViaCOM.CallMethod(oCfgs, "Item", itemArgs); |
633 | object oDebugSettings = ViaCOM.GetProperty(oCfg, "DebugSettings"); | 633 | object oDebugSettings = ViaCOM.GetProperty(oCfg, "DebugSettings"); |
634 | ViaCOM.SetProperty(oDebugSettings, "WorkingDirectory", (object)working_dir); | 634 | ViaCOM.SetProperty(oDebugSettings, "WorkingDirectory", (object)working_dir); |
635 | } | 635 | } |
636 | 636 | ||
637 | break; | 637 | break; |
638 | } | 638 | } |
639 | } | 639 | } |
640 | made_change = true; | 640 | made_change = true; |
641 | } | 641 | } |
642 | catch( Exception e ) | 642 | catch( Exception e ) |
643 | { | 643 | { |
644 | Console.WriteLine(e.Message); | 644 | Console.WriteLine(e.Message); |
645 | Console.WriteLine("Failed to set working dir for project, {0}.", project_name); | 645 | Console.WriteLine("Failed to set working dir for project, {0}.", project_name); |
646 | } | 646 | } |
647 | 647 | ||
648 | return made_change; | 648 | return made_change; |
649 | } | 649 | } |
650 | 650 | ||
651 | public static bool SetStartupProject(string startup_project) | 651 | public static bool SetStartupProject(string startup_project) |
652 | { | 652 | { |
653 | bool result = false; | 653 | bool result = false; |
654 | try | 654 | try |
655 | { | 655 | { |
656 | // You need the 'unique name of the project to set StartupProjects. | 656 | // You need the 'unique name of the project to set StartupProjects. |
657 | // find the project by generic name. | 657 | // find the project by generic name. |
658 | Console.WriteLine("Trying to set \"{0}\" to the startup project", startup_project); | 658 | Console.WriteLine("Trying to set \"{0}\" to the startup project", startup_project); |
659 | object prjs = ViaCOM.GetProperty(solution, "Projects"); | 659 | object prjs = ViaCOM.GetProperty(solution, "Projects"); |
660 | object count = ViaCOM.GetProperty(prjs, "Count"); | 660 | object count = ViaCOM.GetProperty(prjs, "Count"); |
661 | for (int i = 1; i <= (int)count; ++i) | 661 | for (int i = 1; i <= (int)count; ++i) |
662 | { | 662 | { |
663 | object[] itemArgs = { (object)i }; | 663 | object[] itemArgs = { (object)i }; |
664 | object prj = ViaCOM.CallMethod(prjs, "Item", itemArgs); | 664 | object prj = ViaCOM.CallMethod(prjs, "Item", itemArgs); |
665 | object prjName = ViaCOM.GetProperty(prj, "Name"); | 665 | object prjName = ViaCOM.GetProperty(prj, "Name"); |
666 | if (0 == string.Compare((string)prjName, startup_project, ignore_case)) | 666 | if (0 == string.Compare((string)prjName, startup_project, ignore_case)) |
667 | { | 667 | { |
668 | object solBuild = ViaCOM.GetProperty(solution, "SolutionBuild"); | 668 | object solBuild = ViaCOM.GetProperty(solution, "SolutionBuild"); |
669 | ViaCOM.SetProperty(solBuild, "StartupProjects", ViaCOM.GetProperty(prj, "UniqueName")); | 669 | ViaCOM.SetProperty(solBuild, "StartupProjects", ViaCOM.GetProperty(prj, "UniqueName")); |
670 | Console.WriteLine(" Success!"); | 670 | Console.WriteLine(" Success!"); |
671 | result = true; | 671 | result = true; |
672 | break; | 672 | break; |
673 | } | 673 | } |
674 | } | 674 | } |
675 | 675 | ||
676 | if (result == false) | 676 | if (result == false) |
677 | { | 677 | { |
678 | Console.WriteLine(" Could not find project \"{0}\" in the solution.", startup_project); | 678 | Console.WriteLine(" Could not find project \"{0}\" in the solution.", startup_project); |
679 | } | 679 | } |
680 | } | 680 | } |
681 | catch (Exception e) | 681 | catch (Exception e) |
682 | { | 682 | { |
683 | Console.WriteLine(" Failed to set the startup project!"); | 683 | Console.WriteLine(" Failed to set the startup project!"); |
684 | Console.WriteLine(e.Message); | 684 | Console.WriteLine(e.Message); |
685 | } | 685 | } |
686 | return result; | 686 | return result; |
687 | } | 687 | } |
688 | 688 | ||
689 | public static bool SetActiveConfig(string config) | 689 | public static bool SetActiveConfig(string config) |
690 | { | 690 | { |
691 | bool result = false; | 691 | bool result = false; |
692 | try | 692 | try |
693 | { | 693 | { |
694 | Console.WriteLine("Trying to set active config to \"{0}\"", config); | 694 | Console.WriteLine("Trying to set active config to \"{0}\"", config); |
695 | object solBuild = ViaCOM.GetProperty(solution, "SolutionBuild"); | 695 | object solBuild = ViaCOM.GetProperty(solution, "SolutionBuild"); |
696 | object solCfgs = ViaCOM.GetProperty(solBuild, "SolutionConfigurations"); | 696 | object solCfgs = ViaCOM.GetProperty(solBuild, "SolutionConfigurations"); |
697 | object[] itemArgs = { (object)config }; | 697 | object[] itemArgs = { (object)config }; |
698 | object solCfg = ViaCOM.CallMethod(solCfgs, "Item", itemArgs); | 698 | object solCfg = ViaCOM.CallMethod(solCfgs, "Item", itemArgs); |
699 | ViaCOM.CallMethod(solCfg, "Activate", null); | 699 | ViaCOM.CallMethod(solCfg, "Activate", null); |
700 | Console.WriteLine(" Success!"); | 700 | Console.WriteLine(" Success!"); |
701 | result = true; | 701 | result = true; |
702 | } | 702 | } |
703 | catch (Exception e) | 703 | catch (Exception e) |
704 | { | 704 | { |
705 | Console.WriteLine(" Failed to set \"{0}\" as the active config.", config); | 705 | Console.WriteLine(" Failed to set \"{0}\" as the active config.", config); |
706 | Console.WriteLine(e.Message); | 706 | Console.WriteLine(e.Message); |
707 | } | 707 | } |
708 | return result; | 708 | return result; |
709 | } | 709 | } |
710 | } | 710 | } |
711 | } | 711 | } |