private void TemplateCreate()
        {
            if (TemplateNodeItemRoot?.IsModifed == true)
            {
                var result = MessageBox.Show($"Save template '{TemplateNodeItemRoot.Name}' changes?", "Save template", MessageBoxButton.YesNoCancel);
                if (result == MessageBoxResult.Cancel)
                {
                    return;
                }
                else if (result == MessageBoxResult.Yes)
                {
                    TemplateSaveCommand.ExecuteIfCan();
                }
                TemplateCloseCommand.ExecuteIfCan();
            }

            var sfd = new SaveFileDialog();

            sfd.Filter = "Zip files (*.zip)|*.zip";
            if (sfd.ShowDialog() != true)
            {
                return;
            }


            try
            {
                File.WriteAllBytes(sfd.FileName, Properties.Resources.template);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }

            TemplateOpen(sfd.FileName);
        }
        private void TemplateClose()
        {
            if (TemplateNodeItemRoot.IsModifed)
            {
                var result = MessageBox.Show("Save changes?", "Confirm", MessageBoxButton.YesNoCancel);
                if (result == MessageBoxResult.Yes)
                {
                    TemplateSaveCommand.ExecuteIfCan();
                }
                else if (result == MessageBoxResult.Cancel)
                {
                    return;
                }
            }

            _watcher.EnableRaisingEvents = false;
            TemplateNodeItemRoot.GetAllChildren().ForEach(p => p.PropertyChanged -= NodeItem_PropertyChanged);
            TemplateNodeItemRoot.PropertyChanged -= NodeItem_PropertyChanged;
            Directory.Delete(TemplateTempDir, true);
            TemplateTempDir      = null;
            TemplatePath         = null;
            TemplateNodeItemList = null;
            TemplateNodeItemRoot = null;
        }
        private void TemplateInstall()
        {
            TemplateSaveCommand.ExecuteIfCan();

            var currentProcess = Process.GetCurrentProcess();

            var proc = new Process();

            proc.StartInfo = new ProcessStartInfo(currentProcess.MainModule.FileName, "/installvstemplates");
            var vsMajorVersion = currentProcess.MainModule.FileVersionInfo.FileMajorPart.ToString();

            proc.Start();
            var executed = proc.WaitForExit(10000);

            if (!executed)
            {
                MessageBox.Show($"Cannot execute {currentProcess.MainModule.FileName} /installvstemplates");
                return;
            }

            var           vsAppDataDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\Microsoft\VisualStudio";
            var           dirs         = Directory.GetDirectories(vsAppDataDir, $"{vsMajorVersion}*", SearchOption.TopDirectoryOnly);
            List <string> vsCacheDir   = new List <string>();

            foreach (var d in dirs)
            {
                if (Regex.IsMatch(d, vsMajorVersion + @"[.]\d_[a-zA-Z0-9]{8}(Exp)?$"))
                {
                    vsCacheDir.Add(d);
                }
            }

            if (vsCacheDir.Count == 0)
            {
                MessageBox.Show("Template installed.\nCache not found.");
                return;
            }

            foreach (var dir in dirs)
            {
                var vsCacheTemplateDir = $"{dir}\\ItemTemplatesCache\\{TemplateNodeItemRoot.Name}";
                if (!Directory.Exists(vsCacheTemplateDir))
                {
                    MessageBox.Show("Template installed.\nCache not found.");
                    continue;
                }

                try
                {
                    Directory.Delete(vsCacheTemplateDir, true);
                }
                catch
                {
                    MessageBox.Show("Template installed.\nCache not updated (in use). Please restart Visual Studio to changes make effect.");
                    continue;
                }

                Copy(TemplateTempDir, vsCacheTemplateDir);

                MessageBox.Show("Template installed.\nCache updated");
            }
        }