/// <summary> /// This function is the callback used to execute the command when the menu item is clicked. /// See the constructor to see how the menu item is associated with this function using /// OleMenuCommandService service and MenuCommand class. /// </summary> /// <param name="sender">Event sender.</param> /// <param name="e">Event args.</param> private void Execute(object sender, EventArgs e) { ThreadHelper.ThrowIfNotOnUIThread(); EnvDTE.DTE dte = (EnvDTE.DTE) this.ServiceProvider.GetServiceAsync(typeof(EnvDTE.DTE)).Result; EnvDTE.Projects projects = dte.Solution.Projects; string props = ""; foreach (SelectedItem selectedItem in dte.SelectedItems) { foreach (EnvDTE.Property property in selectedItem.Project.Properties) { try { props += property.Name + ":\t" + property.Value.ToString() + '\n'; } catch (Exception) { } if (property.Name == "Kind" && property.Value.ToString() != "VCProject") { throw new Exception("Wrong project type, needs to be a C++ project"); } if (property.Name == "ShowAllFiles") { property.Value = "True"; } else if (property.Name == "ProjectFile") { string vcxfilepath = property.Value.ToString(); VCXProjFileHandler.ModifyVCXProj(vcxfilepath); } else if (property.Name == "ProjectDirectory") { string projFilePath = property.Value.ToString(); Directory.CreateDirectory(projFilePath + "\\src"); using (FileStream writer = new FileStream(projFilePath + "\\src\\pch.cpp", FileMode.Create)) { byte[] arr = Encoding.ASCII.GetBytes("#include \"pch.h\"\n\n\n"); writer.Write(arr, 0, 19); } using (FileStream writer = new FileStream(projFilePath + "\\src\\pch.h", FileMode.Create)) { byte[] arr = Encoding.ASCII.GetBytes("#ifndef PCH_H\n#define PCH_H\n\n\n#endif"); writer.Write(arr, 0, 15); } using (FileStream writer = new FileStream(projFilePath + "\\src\\main.cpp", FileMode.Create)) { byte[] arr = Encoding.ASCII.GetBytes("#include \"pch.h\"\n\n\n\nint main(int argc, char** argv)\n{\n\t\n}\n\n"); writer.Write(arr, 0, 59); } } } } }
/// <summary> /// This function is the callback used to execute the command when the menu item is clicked. /// See the constructor to see how the menu item is associated with this function using /// OleMenuCommandService service and MenuCommand class. /// </summary> /// <param name="sender">Event sender.</param> /// <param name="e">Event args.</param> private void Execute(object sender, EventArgs e) { ThreadHelper.ThrowIfNotOnUIThread(); EnvDTE.DTE dte = (EnvDTE.DTE) this.ServiceProvider.GetServiceAsync(typeof(EnvDTE.DTE)).Result; EnvDTE.Projects projects = dte.Solution.Projects; string vcxfilepath = ""; string projFilePath = ""; string props = ""; foreach (EnvDTE.Project project in projects) { foreach (EnvDTE.Property property in project.Properties) { try { props += property.Name + ":\t" + property.Value.ToString() + '\n'; } catch (Exception) { } if (property.Name == "Kind" && property.Value.ToString() != "VCProject") { throw new Exception("Wrong project type, needs to be a C++ project"); } if (property.Name == "ShowAllFiles") { property.Value = "True"; } else if (property.Name == "ProjectFile") { vcxfilepath = property.Value.ToString(); } else if (property.Name == "ProjectDirectory") { projFilePath = property.Value.ToString(); } } break; } //VsShellUtilities.ShowMessageBox(this.package, props, "", 0, 0, 0); if (!vcxfilepath.Equals("")) { VCXProjFileHandler.ModifyVCXProjWin32(vcxfilepath); } Directory.CreateDirectory(projFilePath + "\\src"); using (FileStream writer = new FileStream(projFilePath + "\\src\\pch.cpp", FileMode.Create)) { byte[] arr = Encoding.ASCII.GetBytes("#include \"pch.h\"\n\n\n"); writer.Write(arr, 0, 19); } using (FileStream writer = new FileStream(projFilePath + "\\src\\pch.h", FileMode.Create)) { byte[] arr = Encoding.ASCII.GetBytes("#pragma once\n\n\n#include <Windows.h>\n\n"); writer.Write(arr, 0, 37); } using (FileStream writer = new FileStream(projFilePath + "\\src\\main.cpp", FileMode.Create)) { byte[] arr = Encoding.ASCII.GetBytes("#include \"pch.h\"\n\n\n\nint WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ PWSTR pCmdLine, _In_ int nCmdShow)\n{\n\t\n}\n\n"); writer.Write(arr, 0, 147); } }