Пример #1
0
        public void Save()
        {
            if (!IsNew && ReadOnly())
            {
                MessageBox.Show(String.Format("\"{0}\" is read-only, cannot save this file.", wxsFile.Name), "Read Only!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (wxsWatcher != null)
            {
                wxsWatcher.EnableRaisingEvents = false;
            }

            UndoManager.DeregisterHandlers();

            XmlComment commentElement = null;

            if (projectSettings.IsEmpty() == false)
            {
                StringBuilder commentBuilder = new StringBuilder();
                commentBuilder.Append("\r\n");
                commentBuilder.Append("    # This comment is generated by WixEdit, the specific commandline\r\n");
                commentBuilder.Append("    # arguments for the WiX Toolset are stored here.\r\n\r\n");
                commentBuilder.AppendFormat("    candleArgs: {0}\r\n", projectSettings.CandleArgs);
                commentBuilder.AppendFormat("    lightArgs: {0}\r\n", projectSettings.LightArgs);

                commentElement = wxsDocument.CreateComment(commentBuilder.ToString());

                XmlNode firstElement = wxsDocument.FirstChild;
                if (firstElement != null)
                {
                    if (firstElement.NodeType == XmlNodeType.XmlDeclaration)
                    {
                        firstElement = wxsDocument.FirstChild.NextSibling;
                    }

                    wxsDocument.InsertBefore(commentElement, firstElement);
                }
                else
                {
                    wxsDocument.AppendChild(commentElement);
                }
            }

            // Handle extension namespaces. Remove all those which are not used in the file.
            foreach (string ext in xsdExtensionNames)
            {
                string theNodeNamespace = LookupExtensionNameReverse(ext);

                XmlNodeList list = wxsDocument.SelectNodes(String.Format("//{0}:*", theNodeNamespace), wxsNsmgr);
                if (list.Count == 0)
                {
                    // Error reports show that a NullReferenceException occurs on the next line now, how can this be?
                    // The wxsDocument.DocumentElement is null.
                    wxsDocument.DocumentElement.RemoveAttribute(String.Format("xmlns:{0}", theNodeNamespace));
                }
            }

            if (IncludeManager.HasIncludes)
            {
                IncludeManager.RemoveIncludes();

                ArrayList changedIncludes = UndoManager.ChangedIncludes;
                if (changedIncludes.Count > 0)
                {
                    string filesString = String.Join("\r\n\x2022 ", changedIncludes.ToArray(typeof(string)) as string[]);
                    if (DialogResult.Yes == MessageBox.Show(String.Format("Do you want to save the following changed include files?\r\n\r\n\x2022 {0}", filesString), "Save?", MessageBoxButtons.YesNo, MessageBoxIcon.Question))
                    {
                        IncludeManager.SaveIncludes(UndoManager.ChangedIncludes);
                    }
                }
            }

            FileMode mode = FileMode.OpenOrCreate;

            if (File.Exists(wxsFile.FullName))
            {
                mode = mode | FileMode.Truncate;
            }

            using (FileStream fs = new FileStream(wxsFile.FullName, mode))
            {
                XmlWriterSettings settings = new XmlWriterSettings();
                settings.Indent          = true;
                settings.IndentChars     = new string(' ', WixEditSettings.Instance.XmlIndentation);
                settings.NewLineHandling = NewLineHandling.None;
                settings.Encoding        = new System.Text.UTF8Encoding();
                XmlWriter writer = XmlWriter.Create(fs, settings);

                wxsDocument.Save(writer);

                writer.Close();
                fs.Close();
            }

            if (IncludeManager.HasIncludes)
            {
                // Remove nodes from main xml document
                IncludeManager.RestoreIncludes();
            }

            projectSettings.ChangesHasBeenSaved();

            if (commentElement != null)
            {
                wxsDocument.RemoveChild(commentElement);
            }

            if (wxsWatcher != null)
            {
                wxsWatcher.EnableRaisingEvents = true;
            }

            undoManager.DocumentIsSaved();
            UndoManager.RegisterHandlers();
        }
Пример #2
0
 public bool HasChanges()
 {
     return(UndoManager.HasChanges() || projectSettings.HasChanges() || IsNew);
 }
Пример #3
0
 public IncludeFileChangedException(UndoManager undoMgr, IReversibleCommand cmd, bool notifyUser)
 {
     this.undoMgr    = undoMgr;
     this.cmd        = cmd;
     this.notifyUser = notifyUser;
 }