From 5cfb6f764404388d4999cf90e904d10b2ca8cdcd Mon Sep 17 00:00:00 2001 From: Mahdi Hosseini Date: Fri, 6 Dec 2024 22:49:45 +0330 Subject: [PATCH] simplify RunStarted in VSIX --- .../TemplateWizard/SharedWizard.cs | 476 +++++++++--------- .../TemplateWizard/TemplateConfig.cs | 19 + .../TemplateWizard/TemplateType.cs | 10 - .../WinUIAppBlankUnitTestWizard.cs | 2 +- .../TemplateWizard/WinUIAppBlankWizard.cs | 2 +- .../WinUIAppMVVMNavigationWizard.cs | 2 +- .../TemplateWizard/WinUIAppMVVMWizard.cs | 2 +- .../WinUIAppNavigationWizard.cs | 2 +- .../TemplateWizard/WinUIAppWizard.cs | 2 +- 9 files changed, 265 insertions(+), 252 deletions(-) create mode 100644 VSIX/DevWinUI_Template/DevWinUI_Template/TemplateWizard/TemplateConfig.cs delete mode 100644 VSIX/DevWinUI_Template/DevWinUI_Template/TemplateWizard/TemplateType.cs diff --git a/VSIX/DevWinUI_Template/DevWinUI_Template/TemplateWizard/SharedWizard.cs b/VSIX/DevWinUI_Template/DevWinUI_Template/TemplateWizard/SharedWizard.cs index 188612f..b38df1a 100644 --- a/VSIX/DevWinUI_Template/DevWinUI_Template/TemplateWizard/SharedWizard.cs +++ b/VSIX/DevWinUI_Template/DevWinUI_Template/TemplateWizard/SharedWizard.cs @@ -92,7 +92,7 @@ private void OnSolutionRestoreFinished(IReadOnlyList projects) /// /// /// - public async void RunStarted(object automationObject, Dictionary replacementsDictionary, string templateName, bool hasPages, bool isMVVMTemplate = false, bool hasNavigationView = false, bool isBlank = false, bool isTest = false) + public async void RunStarted(object automationObject, Dictionary replacementsDictionary, TemplateConfig templateConfig) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); _componentModel = (IComponentModel)ServiceProvider.GlobalProvider.GetService(typeof(SComponentModel)); @@ -113,312 +113,315 @@ public async void RunStarted(object automationObject, Dictionary DestinationDirectory = replacementsDictionary["$destinationdirectory$"]; _shouldAddProjectItem = false; - WizardConfig.HasPages = hasPages; - WizardConfig.IsBlank = isBlank; + WizardConfig.HasPages = templateConfig.HasPages; + WizardConfig.IsBlank = templateConfig.IsBlank; await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); _dte = automationObject as _DTE; - var inputForm = new MainWindow(); - var result = inputForm.ShowDialog(); + if (!templateConfig.IsBlank) + { + var inputForm = new MainWindow(); + var result = inputForm.ShowDialog(); - await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); + await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); - if (result.HasValue && result.Value) - { - var vsix = await GetVSIXPathAsync(templateName); - VSTemplateFilePath = vsix.VSTemplatePath; - ProjectTemplatesFolderPath = vsix.ProjectTemplatesFolder; - VSIXRootFolderPath = vsix.VSIXRootFolder; - - _shouldAddProjectItem = true; - - AddEditorConfigFile(); - - // Add Base Library Versions - replacementsDictionary.Add("$DotNetVersion$", WizardConfig.DotNetVersion.ToString()); - replacementsDictionary.Add("$TargetFrameworkVersion$", WizardConfig.TargetFrameworkVersion.ToString()); - replacementsDictionary.Add("$MinimumTargetPlatform$", WizardConfig.MinimumTargetPlatform.ToString()); - replacementsDictionary.Add("$Platforms$", WizardConfig.Platforms.ToString()); - replacementsDictionary.Add("$RuntimeIdentifiers$", WizardConfig.RuntimeIdentifiers.ToString()); - - replacementsDictionary.Add("$Nullable$", WizardConfig.Nullable); - replacementsDictionary.Add("$TrimMode$", WizardConfig.TrimMode); - replacementsDictionary.Add("$PublishAot$", WizardConfig.PublishAot.ToString()); - - replacementsDictionary.Add("$AddJsonSettings$", WizardConfig.UseJsonSettings.ToString()); - replacementsDictionary.Add("$AddEditorConfig$", WizardConfig.UseEditorConfigFile.ToString()); - replacementsDictionary.Add("$AddSolutionFolder$", WizardConfig.UseSolutionFolder.ToString()); - replacementsDictionary.Add("$AddHomeLandingPage$", WizardConfig.UseHomeLandingPage.ToString()); - replacementsDictionary.Add("$AddSettingsPage$", WizardConfig.UseSettingsPage.ToString()); - replacementsDictionary.Add("$AddGeneralSettingPage$", WizardConfig.UseGeneralSettingPage.ToString()); - replacementsDictionary.Add("$AddThemeSettingPage$", WizardConfig.UseThemeSettingPage.ToString()); - replacementsDictionary.Add("$AddAppUpdatePage$", WizardConfig.UseAppUpdatePage.ToString()); - replacementsDictionary.Add("$AddAboutPage$", WizardConfig.UseAboutPage.ToString()); - replacementsDictionary.Add("$T4_NAMESPACE$", SafeProjectName); - - var libs = WizardConfig.LibraryDic; - - #region Libs - // Assuming package list is passed via a custom parameter in the .vstemplate file - if (replacementsDictionary.TryGetValue("$NuGetPackages$", out string packages)) + if (result.HasValue && result.Value) { - _nuGetPackages = new(); - var basePackages = packages.Split(';').Where(p => !string.IsNullOrEmpty(p)); - foreach (var baseItem in basePackages) - { - _nuGetPackages.Add(new Library(baseItem, WizardConfig.UsePreReleaseVersion)); - } + var vsix = await GetVSIXPathAsync(templateConfig.TemplateType.ToString()); + VSTemplateFilePath = vsix.VSTemplatePath; + ProjectTemplatesFolderPath = vsix.ProjectTemplatesFolder; + VSIXRootFolderPath = vsix.VSIXRootFolder; - foreach (var lib in libs.Values) - { - _nuGetPackages.Add(new Library(lib.Name, lib.IncludePreRelease)); - } + _shouldAddProjectItem = true; - if (WizardConfig.UseJsonSettings) + AddEditorConfigFile(); + + // Add Base Library Versions + replacementsDictionary.Add("$DotNetVersion$", WizardConfig.DotNetVersion.ToString()); + replacementsDictionary.Add("$TargetFrameworkVersion$", WizardConfig.TargetFrameworkVersion.ToString()); + replacementsDictionary.Add("$MinimumTargetPlatform$", WizardConfig.MinimumTargetPlatform.ToString()); + replacementsDictionary.Add("$Platforms$", WizardConfig.Platforms.ToString()); + replacementsDictionary.Add("$RuntimeIdentifiers$", WizardConfig.RuntimeIdentifiers.ToString()); + + replacementsDictionary.Add("$Nullable$", WizardConfig.Nullable); + replacementsDictionary.Add("$TrimMode$", WizardConfig.TrimMode); + replacementsDictionary.Add("$PublishAot$", WizardConfig.PublishAot.ToString()); + + replacementsDictionary.Add("$AddJsonSettings$", WizardConfig.UseJsonSettings.ToString()); + replacementsDictionary.Add("$AddEditorConfig$", WizardConfig.UseEditorConfigFile.ToString()); + replacementsDictionary.Add("$AddSolutionFolder$", WizardConfig.UseSolutionFolder.ToString()); + replacementsDictionary.Add("$AddHomeLandingPage$", WizardConfig.UseHomeLandingPage.ToString()); + replacementsDictionary.Add("$AddSettingsPage$", WizardConfig.UseSettingsPage.ToString()); + replacementsDictionary.Add("$AddGeneralSettingPage$", WizardConfig.UseGeneralSettingPage.ToString()); + replacementsDictionary.Add("$AddThemeSettingPage$", WizardConfig.UseThemeSettingPage.ToString()); + replacementsDictionary.Add("$AddAppUpdatePage$", WizardConfig.UseAppUpdatePage.ToString()); + replacementsDictionary.Add("$AddAboutPage$", WizardConfig.UseAboutPage.ToString()); + replacementsDictionary.Add("$T4_NAMESPACE$", SafeProjectName); + + var libs = WizardConfig.LibraryDic; + + #region Libs + // Assuming package list is passed via a custom parameter in the .vstemplate file + if (replacementsDictionary.TryGetValue("$NuGetPackages$", out string packages)) { - _nuGetPackages.Add(new Library("nucs.JsonSettings", WizardConfig.UsePreReleaseVersion)); - _nuGetPackages.Add(new Library("nucs.JsonSettings.AutoSaveGenerator", WizardConfig.UsePreReleaseVersion)); + _nuGetPackages = new(); + var basePackages = packages.Split(';').Where(p => !string.IsNullOrEmpty(p)); + foreach (var baseItem in basePackages) + { + _nuGetPackages.Add(new Library(baseItem, WizardConfig.UsePreReleaseVersion)); + } + + foreach (var lib in libs.Values) + { + _nuGetPackages.Add(new Library(lib.Name, lib.IncludePreRelease)); + } + + if (WizardConfig.UseJsonSettings && !templateConfig.IsBlank && !templateConfig.IsTest) + { + _nuGetPackages.Add(new Library("nucs.JsonSettings", WizardConfig.UsePreReleaseVersion)); + _nuGetPackages.Add(new Library("nucs.JsonSettings.AutoSaveGenerator", WizardConfig.UsePreReleaseVersion)); + } + + _nuGetPackages = _nuGetPackages.Distinct().ToList(); } + #endregion - _nuGetPackages = _nuGetPackages.Distinct().ToList(); - } - #endregion + #region CSProjectElements + // Add CSProjectElements + if (WizardConfig.CSProjectElements != null && WizardConfig.CSProjectElements.Count > 0) + { + StringBuilder sb = new StringBuilder(); - #region CSProjectElements - // Add CSProjectElements - if (WizardConfig.CSProjectElements != null && WizardConfig.CSProjectElements.Count > 0) - { - StringBuilder sb = new StringBuilder(); + foreach (var entity in WizardConfig.CSProjectElements) + { + sb.AppendLine($"{entity.Value}"); + } - foreach (var entity in WizardConfig.CSProjectElements) + replacementsDictionary.Add("$CustomCSProjectElement$", Environment.NewLine + $"{sb.ToString().Trim()}"); + } + else { - sb.AppendLine($"{entity.Value}"); + replacementsDictionary.Add("$CustomCSProjectElement$", ""); } - replacementsDictionary.Add("$CustomCSProjectElement$", Environment.NewLine + $"{sb.ToString().Trim()}"); - } - else - { - replacementsDictionary.Add("$CustomCSProjectElement$", ""); - } + #endregion - #endregion + #region AppxManifest + if (WizardConfig.UnvirtualizedResources != null && WizardConfig.UnvirtualizedResources.Count > 0) + { + StringBuilder sb = new StringBuilder(); - #region AppxManifest - if (WizardConfig.UnvirtualizedResources != null && WizardConfig.UnvirtualizedResources.Count > 0) - { - StringBuilder sb = new StringBuilder(); + foreach (var entity in WizardConfig.UnvirtualizedResources) + { + sb.AppendLine($"{entity.Value}"); + } - foreach (var entity in WizardConfig.UnvirtualizedResources) + replacementsDictionary.Add("$UnvirtualizedResourcesCapability$", Environment.NewLine + " "); + replacementsDictionary.Add("$UnvirtualizedResources$", Environment.NewLine + $"{sb.ToString().Trim()}"); + replacementsDictionary.Add("$AppxManifestDesktop6$", Environment.NewLine + " xmlns:desktop6=\"http://schemas.microsoft.com/appx/manifest/desktop/windows10/6\""); + } + else { - sb.AppendLine($"{entity.Value}"); + replacementsDictionary.Add("$UnvirtualizedResourcesCapability$", ""); + replacementsDictionary.Add("$UnvirtualizedResources$", ""); + replacementsDictionary.Add("$AppxManifestDesktop6$", ""); } + #endregion - replacementsDictionary.Add("$UnvirtualizedResourcesCapability$", Environment.NewLine + " "); - replacementsDictionary.Add("$UnvirtualizedResources$", Environment.NewLine + $"{sb.ToString().Trim()}"); - replacementsDictionary.Add("$AppxManifestDesktop6$", Environment.NewLine + " xmlns:desktop6=\"http://schemas.microsoft.com/appx/manifest/desktop/windows10/6\""); - } - else - { - replacementsDictionary.Add("$UnvirtualizedResourcesCapability$", ""); - replacementsDictionary.Add("$UnvirtualizedResources$", ""); - replacementsDictionary.Add("$AppxManifestDesktop6$", ""); - } - #endregion + #region Add Xaml Dictionary if User Use Extra Lib + #region Blank + + if (templateConfig.IsBlank) + { + if (libs != null && libs.ContainsKey(Constants.DevWinUI_Controls)) + { + replacementsDictionary.Add("$DevWinUI.Controls$", Environment.NewLine + Constants.DevWinUI_Controls_Xaml); + } + else + { + replacementsDictionary.Add("$DevWinUI.Controls$", ""); + } + } - #region Add Xaml Dictionary if User Use Extra Lib - #region Blank + #endregion - if (isBlank) - { - if (libs != null && libs.ContainsKey(Constants.DevWinUI_Controls)) + if (libs != null && libs.ContainsKey(Constants.DevWinUI_ContextMenu)) { - replacementsDictionary.Add("$DevWinUI.Controls$", Environment.NewLine + Constants.DevWinUI_Controls_Xaml); + WizardConfig.UseWindow11ContextMenu = true; + replacementsDictionary.Add("$CLSID$", Guid.NewGuid().ToString()); + var windows11ContextMenu = PredefinedCodes.Windows11ContextMenuInitializer; + var windows11ContextMenuMVVM = PredefinedCodes.Windows11ContextMenuMVVMInitializer; + windows11ContextMenu = windows11ContextMenu.Replace("$projectname$", ProjectName); + windows11ContextMenuMVVM = windows11ContextMenuMVVM.Replace("$projectname$", ProjectName); + replacementsDictionary.Add("$Windows11ContextMenuInitializer$", Environment.NewLine + windows11ContextMenu); + replacementsDictionary.Add("$Windows11ContextMenuMVVMInitializer$", Environment.NewLine + Environment.NewLine + windows11ContextMenuMVVM); } else { - replacementsDictionary.Add("$DevWinUI.Controls$", ""); + WizardConfig.UseWindow11ContextMenu = false; + replacementsDictionary.Add("$CLSID$", ""); + replacementsDictionary.Add("$Windows11ContextMenuInitializer$", ""); + replacementsDictionary.Add("$Windows11ContextMenuMVVMInitializer$", ""); } - } - #endregion + #endregion - if (libs != null && libs.ContainsKey(Constants.DevWinUI_ContextMenu)) - { - WizardConfig.UseWindow11ContextMenu = true; - replacementsDictionary.Add("$CLSID$", Guid.NewGuid().ToString()); - var windows11ContextMenu = PredefinedCodes.Windows11ContextMenuInitializer; - var windows11ContextMenuMVVM = PredefinedCodes.Windows11ContextMenuMVVMInitializer; - windows11ContextMenu = windows11ContextMenu.Replace("$projectname$", ProjectName); - windows11ContextMenuMVVM = windows11ContextMenuMVVM.Replace("$projectname$", ProjectName); - replacementsDictionary.Add("$Windows11ContextMenuInitializer$", Environment.NewLine + windows11ContextMenu); - replacementsDictionary.Add("$Windows11ContextMenuMVVMInitializer$", Environment.NewLine + Environment.NewLine + windows11ContextMenuMVVM); - } - else - { - WizardConfig.UseWindow11ContextMenu = false; - replacementsDictionary.Add("$CLSID$", ""); - replacementsDictionary.Add("$Windows11ContextMenuInitializer$", ""); - replacementsDictionary.Add("$Windows11ContextMenuMVVMInitializer$", ""); - } - - #endregion - - #region IsUnPackaged - if (WizardConfig.IsUnPackagedMode) - { - replacementsDictionary.Add("$WindowsPackageType$", "None"); - } - else - { - replacementsDictionary.Add("$WindowsPackageType$", "MSIX"); - } - #endregion - - if (hasNavigationView) - { - new ColorsDicOption().ConfigColorsDic(replacementsDictionary, WizardConfig.UseHomeLandingPage); - } + #region IsUnPackaged + if (WizardConfig.IsUnPackagedMode) + { + replacementsDictionary.Add("$WindowsPackageType$", "None"); + } + else + { + replacementsDictionary.Add("$WindowsPackageType$", "MSIX"); + } + #endregion - // Add Xaml Dictionary - new DictionaryOption().ConfigDictionary(replacementsDictionary, hasNavigationView, WizardConfig.UseHomeLandingPage, WizardConfig.UseColorsDic, WizardConfig.UseStylesDic, WizardConfig.UseConvertersDic, WizardConfig.UseFontsDic); + if (templateConfig.HasNavigationView) + { + new ColorsDicOption().ConfigColorsDic(replacementsDictionary, WizardConfig.UseHomeLandingPage); + } - #region Codes - var configCodes = new ConfigCodes(WizardConfig.UseAboutPage, WizardConfig.UseAppUpdatePage, WizardConfig.UseGeneralSettingPage, WizardConfig.UseHomeLandingPage, WizardConfig.UseSettingsPage, WizardConfig.UseThemeSettingPage, WizardConfig.UseDeveloperModeSetting, WizardConfig.UseJsonSettings, WizardConfig.UseWindow11ContextMenu); + // Add Xaml Dictionary + new DictionaryOption().ConfigDictionary(replacementsDictionary, templateConfig.HasNavigationView, WizardConfig.UseHomeLandingPage, WizardConfig.UseColorsDic, WizardConfig.UseStylesDic, WizardConfig.UseConvertersDic, WizardConfig.UseFontsDic); - if (isMVVMTemplate) - { - configCodes.ConfigAllMVVM(SafeProjectName); - } - else - { - configCodes.ConfigAll(SafeProjectName); - } + #region Codes + var configCodes = new ConfigCodes(WizardConfig.UseAboutPage, WizardConfig.UseAppUpdatePage, WizardConfig.UseGeneralSettingPage, WizardConfig.UseHomeLandingPage, WizardConfig.UseSettingsPage, WizardConfig.UseThemeSettingPage, WizardConfig.UseDeveloperModeSetting, WizardConfig.UseJsonSettings, WizardConfig.UseWindow11ContextMenu); - configCodes.ConfigGeneral(); + if (templateConfig.IsMVVM) + { + configCodes.ConfigAllMVVM(SafeProjectName); + } + else + { + configCodes.ConfigAll(SafeProjectName); + } - var configs = configCodes.GetConfigJson(); - var services = configCodes.GetServices(); - var settingsCards = configCodes.GetSettingsPageOptions(); - var generalSettingsCards = configCodes.GetGeneralSettingsPageOptions(); + configCodes.ConfigGeneral(); - if (configCodes.ConfigJsonDic.Count > 0) - { - replacementsDictionary.Add("$ConfigDefaultPages$", Environment.NewLine + configs); - } - else - { - replacementsDictionary.Add("$ConfigDefaultPages$", ""); - } + var configs = configCodes.GetConfigJson(); + var services = configCodes.GetServices(); + var settingsCards = configCodes.GetSettingsPageOptions(); + var generalSettingsCards = configCodes.GetGeneralSettingsPageOptions(); - if (configCodes.ServiceDic.Count > 0) - { - replacementsDictionary.Add("$Services$", Environment.NewLine + services); - } - else - { - replacementsDictionary.Add("$Services$", ""); - } + if (configCodes.ConfigJsonDic.Count > 0) + { + replacementsDictionary.Add("$ConfigDefaultPages$", Environment.NewLine + configs); + } + else + { + replacementsDictionary.Add("$ConfigDefaultPages$", ""); + } - replacementsDictionary.Add("$SettingsCards$", settingsCards); + if (configCodes.ServiceDic.Count > 0) + { + replacementsDictionary.Add("$Services$", Environment.NewLine + services); + } + else + { + replacementsDictionary.Add("$Services$", ""); + } - #endregion + replacementsDictionary.Add("$SettingsCards$", settingsCards); - #region Serilog - var serilog = new SerilogOption(); - serilog.ConfigSerilog(replacementsDictionary, libs, WizardConfig.UseJsonSettings, WizardConfig.UseDeveloperModeSetting); - UseFileLogger = serilog.UseFileLogger; - UseDebugLogger = serilog.UseDebugLogger; + #endregion - if (libs.ContainsKey("Serilog.Sinks.Debug") || libs.ContainsKey("Serilog.Sinks.File")) - { - replacementsDictionary.AddIfNotExists("$GeneralSettingsCards$", generalSettingsCards); + #region Serilog + var serilog = new SerilogOption(); + serilog.ConfigSerilog(replacementsDictionary, libs, WizardConfig.UseJsonSettings, WizardConfig.UseDeveloperModeSetting); + UseFileLogger = serilog.UseFileLogger; + UseDebugLogger = serilog.UseDebugLogger; - if (WizardConfig.UseJsonSettings && WizardConfig.UseDeveloperModeSetting && WizardConfig.UseSettingsPage && WizardConfig.UseGeneralSettingPage) + if (libs.ContainsKey("Serilog.Sinks.Debug") || libs.ContainsKey("Serilog.Sinks.File")) { - replacementsDictionary.AddIfNotExists("$GoToLogPathEvent$", Environment.NewLine + Environment.NewLine + PredefinedCodes.GoToLogPathEvent); - replacementsDictionary.AddIfNotExists("$DeveloperModeConfig$", Environment.NewLine + "public bool useDeveloperMode { get; set; }"); + replacementsDictionary.AddIfNotExists("$GeneralSettingsCards$", generalSettingsCards); + + if (WizardConfig.UseJsonSettings && WizardConfig.UseDeveloperModeSetting && WizardConfig.UseSettingsPage && WizardConfig.UseGeneralSettingPage) + { + replacementsDictionary.AddIfNotExists("$GoToLogPathEvent$", Environment.NewLine + Environment.NewLine + PredefinedCodes.GoToLogPathEvent); + replacementsDictionary.AddIfNotExists("$DeveloperModeConfig$", Environment.NewLine + "public bool useDeveloperMode { get; set; }"); + } + else + { + replacementsDictionary.AddIfNotExists("$GoToLogPathEvent$", ""); + replacementsDictionary.AddIfNotExists("$DeveloperModeConfig$", ""); + } } else { replacementsDictionary.AddIfNotExists("$GoToLogPathEvent$", ""); + replacementsDictionary.AddIfNotExists("$GeneralSettingsCards$", ""); replacementsDictionary.AddIfNotExists("$DeveloperModeConfig$", ""); } - } - else - { - replacementsDictionary.AddIfNotExists("$GoToLogPathEvent$", ""); - replacementsDictionary.AddIfNotExists("$GeneralSettingsCards$", ""); - replacementsDictionary.AddIfNotExists("$DeveloperModeConfig$", ""); - } - #endregion + #endregion - #region Json Settings - if (WizardConfig.UseJsonSettings) - { - if (isMVVMTemplate) + #region Json Settings + if (WizardConfig.UseJsonSettings) { - replacementsDictionary.Add("$AppUpdateMVVMGetDateTime$", Environment.NewLine + """LastUpdateCheck = Settings.LastUpdateCheck;"""); - replacementsDictionary.Add("$AppUpdateMVVMSetDateTime$", Environment.NewLine + """Settings.LastUpdateCheck = DateTime.Now.ToShortDateString();"""); + if (templateConfig.IsMVVM) + { + replacementsDictionary.Add("$AppUpdateMVVMGetDateTime$", Environment.NewLine + """LastUpdateCheck = Settings.LastUpdateCheck;"""); + replacementsDictionary.Add("$AppUpdateMVVMSetDateTime$", Environment.NewLine + """Settings.LastUpdateCheck = DateTime.Now.ToShortDateString();"""); + } + else + { + replacementsDictionary.Add("$AppUpdateGetDateTime$", Environment.NewLine + Environment.NewLine + """TxtLastUpdateCheck.Text = Settings.LastUpdateCheck;"""); + replacementsDictionary.Add("$AppUpdateSetDateTime$", Environment.NewLine + """Settings.LastUpdateCheck = DateTime.Now.ToShortDateString();"""); + } + + replacementsDictionary.Add("$AppConfigFilePath$", Environment.NewLine + """public static readonly string AppConfigPath = Path.Combine(RootDirectoryPath, "AppConfig.json");"""); + + if (WizardConfig.UseAppUpdatePage && WizardConfig.UseSettingsPage) + { + replacementsDictionary.Add("$AppUpdateConfig$", Environment.NewLine + """public string lastUpdateCheck { get; set; }"""); + } + else + { + replacementsDictionary.Add("$AppUpdateConfig$", ""); + } } else { - replacementsDictionary.Add("$AppUpdateGetDateTime$", Environment.NewLine + Environment.NewLine + """TxtLastUpdateCheck.Text = Settings.LastUpdateCheck;"""); - replacementsDictionary.Add("$AppUpdateSetDateTime$", Environment.NewLine + """Settings.LastUpdateCheck = DateTime.Now.ToShortDateString();"""); + replacementsDictionary.Add("$AppUpdateMVVMGetDateTime$", ""); + replacementsDictionary.Add("$AppUpdateMVVMSetDateTime$", ""); + replacementsDictionary.Add("$AppConfigFilePath$", ""); + replacementsDictionary.Add("$AppUpdateConfig$", ""); } + #endregion - replacementsDictionary.Add("$AppConfigFilePath$", Environment.NewLine + """public static readonly string AppConfigPath = Path.Combine(RootDirectoryPath, "AppConfig.json");"""); - if (WizardConfig.UseAppUpdatePage && WizardConfig.UseSettingsPage) + if (WizardConfig.UseWindow11ContextMenu) { - replacementsDictionary.Add("$AppUpdateConfig$", Environment.NewLine + """public string lastUpdateCheck { get; set; }"""); + replacementsDictionary.Add("$OnLaunchedAsyncKeyword$", "async "); } else { - replacementsDictionary.Add("$AppUpdateConfig$", ""); + replacementsDictionary.Add("$OnLaunchedAsyncKeyword$", ""); } - } - else - { - replacementsDictionary.Add("$AppUpdateMVVMGetDateTime$", ""); - replacementsDictionary.Add("$AppUpdateMVVMSetDateTime$", ""); - replacementsDictionary.Add("$AppConfigFilePath$", ""); - replacementsDictionary.Add("$AppUpdateConfig$", ""); - } - #endregion + new GlobalUsingOption(replacementsDictionary, SafeProjectName, UseFileLogger, UseDebugLogger); - if (WizardConfig.UseWindow11ContextMenu) - { - replacementsDictionary.Add("$OnLaunchedAsyncKeyword$", "async "); + WizardConfig.LibraryDic?.Clear(); + WizardConfig.CSProjectElements?.Clear(); + + //if (UseSettingsPage && UseThemeSettingPage) + //{ + // replacementsDictionary.Add("$BackdropTintColorViewModel$", Environment.NewLine + "themeService.ConfigBackdropTintColor();"); + // replacementsDictionary.Add("$BackdropTintColor$", Environment.NewLine + "ThemeService.ConfigBackdropTintColor();"); + //} + //else + //{ + // replacementsDictionary.Add("$BackdropTintColorViewModel$", ""); + // replacementsDictionary.Add("$BackdropTintColor$", ""); + //} } else { - replacementsDictionary.Add("$OnLaunchedAsyncKeyword$", ""); + inputForm.Close(); + throw new WizardBackoutException(); } - - new GlobalUsingOption(replacementsDictionary, SafeProjectName, UseFileLogger, UseDebugLogger); - - WizardConfig.LibraryDic?.Clear(); - WizardConfig.CSProjectElements?.Clear(); - - //if (UseSettingsPage && UseThemeSettingPage) - //{ - // replacementsDictionary.Add("$BackdropTintColorViewModel$", Environment.NewLine + "themeService.ConfigBackdropTintColor();"); - // replacementsDictionary.Add("$BackdropTintColor$", Environment.NewLine + "ThemeService.ConfigBackdropTintColor();"); - //} - //else - //{ - // replacementsDictionary.Add("$BackdropTintColorViewModel$", ""); - // replacementsDictionary.Add("$BackdropTintColor$", ""); - //} - } - else - { - inputForm.Close(); - throw new WizardBackoutException(); } } @@ -537,6 +540,7 @@ public async void CopyFileToDestination(string inputfile, string outputfile) public async Task<(string VSIXRootFolder, string ProjectTemplatesFolder, string VSTemplatePath)> GetVSIXPathAsync(string vstemplateName) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); + vstemplateName = vstemplateName?.Replace("_", "-"); Solution2 soln = (Solution2)_dte.Solution; var vstemplateFileName = soln.GetProjectTemplate($"{vstemplateName}.vstemplate", "CSharp"); diff --git a/VSIX/DevWinUI_Template/DevWinUI_Template/TemplateWizard/TemplateConfig.cs b/VSIX/DevWinUI_Template/DevWinUI_Template/TemplateWizard/TemplateConfig.cs new file mode 100644 index 0000000..5ce628b --- /dev/null +++ b/VSIX/DevWinUI_Template/DevWinUI_Template/TemplateWizard/TemplateConfig.cs @@ -0,0 +1,19 @@ +namespace DevWinUI_Template; +public class TemplateConfig +{ + public bool IsMVVM { get; set; } + public bool HasNavigationView { get; set; } + public bool IsBlank { get; set; } + public bool IsTest { get; set; } + public bool HasPages { get; set; } + public TemplateType TemplateType { get; set; } +} +public enum TemplateType +{ + WinUIApp_Blank_UnitTest, + WinUIApp_Blank, + WinUIApp_MVVM_NavigationView, + WinUIApp_MVVM, + WinUIApp_NavigationView, + WinUIApp +} diff --git a/VSIX/DevWinUI_Template/DevWinUI_Template/TemplateWizard/TemplateType.cs b/VSIX/DevWinUI_Template/DevWinUI_Template/TemplateWizard/TemplateType.cs deleted file mode 100644 index 6e5e1c9..0000000 --- a/VSIX/DevWinUI_Template/DevWinUI_Template/TemplateWizard/TemplateType.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace DevWinUI_Template; -public enum TemplateType -{ - WinUIApp_Blank_UnitTest, - WinUIApp_Blank, - WinUIApp_MVVM_NavigationView, - WinUIApp_MVVM, - WinUIApp_NavigationView, - WinUIApp -} diff --git a/VSIX/DevWinUI_Template/DevWinUI_Template/TemplateWizard/WinUIAppBlankUnitTestWizard.cs b/VSIX/DevWinUI_Template/DevWinUI_Template/TemplateWizard/WinUIAppBlankUnitTestWizard.cs index d222f8f..7b5cd43 100644 --- a/VSIX/DevWinUI_Template/DevWinUI_Template/TemplateWizard/WinUIAppBlankUnitTestWizard.cs +++ b/VSIX/DevWinUI_Template/DevWinUI_Template/TemplateWizard/WinUIAppBlankUnitTestWizard.cs @@ -30,7 +30,7 @@ public void RunFinished() public void RunStarted(object automationObject, Dictionary replacementsDictionary, WizardRunKind runKind, object[] customParams) { WizardImplementation = new SharedWizard(); - WizardImplementation.RunStarted(automationObject, replacementsDictionary, "WinUIApp-Blank-UnitTest", false, false, false, true, true); + WizardImplementation.RunStarted(automationObject, replacementsDictionary, new TemplateConfig { IsBlank = true, IsTest = true, TemplateType = TemplateType.WinUIApp_Blank_UnitTest }); } public bool ShouldAddProjectItem(string filePath) diff --git a/VSIX/DevWinUI_Template/DevWinUI_Template/TemplateWizard/WinUIAppBlankWizard.cs b/VSIX/DevWinUI_Template/DevWinUI_Template/TemplateWizard/WinUIAppBlankWizard.cs index e2a7696..6cce7f9 100644 --- a/VSIX/DevWinUI_Template/DevWinUI_Template/TemplateWizard/WinUIAppBlankWizard.cs +++ b/VSIX/DevWinUI_Template/DevWinUI_Template/TemplateWizard/WinUIAppBlankWizard.cs @@ -30,7 +30,7 @@ public void RunFinished() public void RunStarted(object automationObject, Dictionary replacementsDictionary, WizardRunKind runKind, object[] customParams) { WizardImplementation = new SharedWizard(); - WizardImplementation.RunStarted(automationObject, replacementsDictionary, "WinUIApp-Blank", false, false, false, true); + WizardImplementation.RunStarted(automationObject, replacementsDictionary, new TemplateConfig { IsBlank = true , TemplateType = TemplateType.WinUIApp_Blank }); } public bool ShouldAddProjectItem(string filePath) diff --git a/VSIX/DevWinUI_Template/DevWinUI_Template/TemplateWizard/WinUIAppMVVMNavigationWizard.cs b/VSIX/DevWinUI_Template/DevWinUI_Template/TemplateWizard/WinUIAppMVVMNavigationWizard.cs index de82dc8..955b5a1 100644 --- a/VSIX/DevWinUI_Template/DevWinUI_Template/TemplateWizard/WinUIAppMVVMNavigationWizard.cs +++ b/VSIX/DevWinUI_Template/DevWinUI_Template/TemplateWizard/WinUIAppMVVMNavigationWizard.cs @@ -30,7 +30,7 @@ public void RunFinished() public void RunStarted(object automationObject, Dictionary replacementsDictionary, WizardRunKind runKind, object[] customParams) { WizardImplementation = new SharedWizard(); - WizardImplementation.RunStarted(automationObject, replacementsDictionary, "WinUIApp-MVVM-NavigationView", true, true, true); + WizardImplementation.RunStarted(automationObject, replacementsDictionary, new TemplateConfig { HasPages = true, IsMVVM = true, HasNavigationView = true, TemplateType = TemplateType.WinUIApp_MVVM_NavigationView }); } public bool ShouldAddProjectItem(string filePath) diff --git a/VSIX/DevWinUI_Template/DevWinUI_Template/TemplateWizard/WinUIAppMVVMWizard.cs b/VSIX/DevWinUI_Template/DevWinUI_Template/TemplateWizard/WinUIAppMVVMWizard.cs index 35e95bb..baefe9e 100644 --- a/VSIX/DevWinUI_Template/DevWinUI_Template/TemplateWizard/WinUIAppMVVMWizard.cs +++ b/VSIX/DevWinUI_Template/DevWinUI_Template/TemplateWizard/WinUIAppMVVMWizard.cs @@ -30,7 +30,7 @@ public void RunFinished() public void RunStarted(object automationObject, Dictionary replacementsDictionary, WizardRunKind runKind, object[] customParams) { WizardImplementation = new SharedWizard(); - WizardImplementation.RunStarted(automationObject, replacementsDictionary, "WinUIApp-MVVM", false, true); + WizardImplementation.RunStarted(automationObject, replacementsDictionary, new TemplateConfig { IsMVVM = true, TemplateType = TemplateType.WinUIApp_MVVM }); } public bool ShouldAddProjectItem(string filePath) diff --git a/VSIX/DevWinUI_Template/DevWinUI_Template/TemplateWizard/WinUIAppNavigationWizard.cs b/VSIX/DevWinUI_Template/DevWinUI_Template/TemplateWizard/WinUIAppNavigationWizard.cs index 0ca757b..b817409 100644 --- a/VSIX/DevWinUI_Template/DevWinUI_Template/TemplateWizard/WinUIAppNavigationWizard.cs +++ b/VSIX/DevWinUI_Template/DevWinUI_Template/TemplateWizard/WinUIAppNavigationWizard.cs @@ -30,7 +30,7 @@ public void RunFinished() public void RunStarted(object automationObject, Dictionary replacementsDictionary, WizardRunKind runKind, object[] customParams) { WizardImplementation = new SharedWizard(); - WizardImplementation.RunStarted(automationObject, replacementsDictionary, "WinUIApp-NavigationView", true, false, true); + WizardImplementation.RunStarted(automationObject, replacementsDictionary, new TemplateConfig { HasPages = true, HasNavigationView = true, TemplateType = TemplateType.WinUIApp_NavigationView }); } public bool ShouldAddProjectItem(string filePath) diff --git a/VSIX/DevWinUI_Template/DevWinUI_Template/TemplateWizard/WinUIAppWizard.cs b/VSIX/DevWinUI_Template/DevWinUI_Template/TemplateWizard/WinUIAppWizard.cs index d7151af..a12eb5b 100644 --- a/VSIX/DevWinUI_Template/DevWinUI_Template/TemplateWizard/WinUIAppWizard.cs +++ b/VSIX/DevWinUI_Template/DevWinUI_Template/TemplateWizard/WinUIAppWizard.cs @@ -30,7 +30,7 @@ public void RunFinished() public void RunStarted(object automationObject, Dictionary replacementsDictionary, WizardRunKind runKind, object[] customParams) { WizardImplementation = new SharedWizard(); - WizardImplementation.RunStarted(automationObject, replacementsDictionary, "WinUIApp", false); + WizardImplementation.RunStarted(automationObject, replacementsDictionary, new TemplateConfig { TemplateType = TemplateType.WinUIApp }); } public bool ShouldAddProjectItem(string filePath)