Exemplo n.º 1
0
            public WixEditData(WixEditData oldVersion, XmlDocument rawData) {
                BinDirectory = oldVersion.BinDirectory;
                DarkLocation = oldVersion.DarkLocation;
                CandleLocation = oldVersion.CandleLocation;
                LightLocation = oldVersion.LightLocation;

                if (oldVersion.XsdsLocation == null) {
                    XmlNode node = rawData.SelectSingleNode("/WixEdit/XsdLocation");
                    if (node != null && node.InnerText.Length > 0) {
                        XsdsLocation = Path.GetDirectoryName(node.InnerText);
                    }
                } else {
                    XsdsLocation = oldVersion.XsdsLocation;
                }

                // Some magic to deal with a new WixEdit installation including a newer WiX version...
                if (!String.IsNullOrEmpty(BinDirectory) &&
                    (String.IsNullOrEmpty(DarkLocation) && String.IsNullOrEmpty(CandleLocation) && String.IsNullOrEmpty(LightLocation) && String.IsNullOrEmpty(XsdsLocation)))
                {
                    if (!Directory.Exists(BinDirectory))
                    {
                        DirectoryInfo oldBinDirectory = new DirectoryInfo(BinDirectory);
                        if (oldBinDirectory.Parent != null)
                        {
                            FileInfo[] files = oldBinDirectory.Parent.GetFiles("candle.exe", SearchOption.AllDirectories);
                            if (files.Length == 0 && oldBinDirectory.Parent.Parent != null)
                            {
                                files = oldBinDirectory.Parent.Parent.GetFiles("candle.exe", SearchOption.AllDirectories);
                            }

                            if (files.Length == 1)
                            {
                                BinDirectory = files[0].Directory.FullName;
                            } else if (files.Length > 1)
                            {
                                ArrayList directoryList = new ArrayList();
                                foreach (FileInfo file in files) {
                                    directoryList.Add(file.Directory.FullName);
                                }
                                directoryList.Sort();

                                BinDirectory = (string)directoryList[directoryList.Count - 1];
                            }
                        }
                    }
                }

                TemplateDirectory = oldVersion.TemplateDirectory;
                if (!String.IsNullOrEmpty(TemplateDirectory))
                {
                    TemplateDirectory = TemplateDirectory.Replace("templates", "wizard");
                }
                UseRelativeOrAbsolutePaths = oldVersion.UseRelativeOrAbsolutePaths;
                if (oldVersion.ExternalXmlEditor == null || oldVersion.ExternalXmlEditor.Length == 0) {
                    ExternalXmlEditor = Path.Combine(Environment.SystemDirectory, "notepad.exe");
                } else {
                    ExternalXmlEditor = oldVersion.ExternalXmlEditor;
                }

                UseInstanceOnly = oldVersion.UseInstanceOnly;
                WordWrapInResultsPanel = oldVersion.WordWrapInResultsPanel;

                if (oldVersion.IgnoreFilesAndDirectories != null && oldVersion.IgnoreFilesAndDirectories.Count > 0) {
                    IgnoreFilesAndDirectories = oldVersion.IgnoreFilesAndDirectories;
                } else {
                    ArrayList oldValues = new ArrayList();
                    XmlNodeList nodes = rawData.SelectNodes("/WixEdit/IgnoreFilesAndDirectories/string");
                    foreach (XmlNode node in nodes) {
                        oldValues.Add(node.InnerText);
                    }

                    if (oldValues.Count > 0) {
                        IgnoreFilesAndDirectories = oldValues;
                    }
                }

                RecentOpenedFiles = oldVersion.RecentOpenedFiles;

                DisplayFullPathInTitlebar = oldVersion.DisplayFullPathInTitlebar;

                XmlIndentation = oldVersion.XmlIndentation;

                AllowIncludeChanges = oldVersion.AllowIncludeChanges;
                BackupChangedIncludes = oldVersion.BackupChangedIncludes;
                
                if (oldVersion.EditDialog == null) {
                    EditDialog = new EditDialogData();
                } else {
                    EditDialog = oldVersion.EditDialog;
                }

                Version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
            }
Exemplo n.º 2
0
            public WixEditData(WixEditData oldVersion, XmlDocument rawData)
            {
                BinDirectory   = oldVersion.BinDirectory;
                DarkLocation   = oldVersion.DarkLocation;
                CandleLocation = oldVersion.CandleLocation;
                LightLocation  = oldVersion.LightLocation;

                if (oldVersion.XsdsLocation == null)
                {
                    XmlNode node = rawData.SelectSingleNode("/WixEdit/XsdLocation");
                    if (node != null && node.InnerText.Length > 0)
                    {
                        XsdsLocation = Path.GetDirectoryName(node.InnerText);
                    }
                }
                else
                {
                    XsdsLocation = oldVersion.XsdsLocation;
                }

                // Some magic to deal with a new WixEdit installation including a newer WiX version...
                if (!String.IsNullOrEmpty(BinDirectory) &&
                    (String.IsNullOrEmpty(DarkLocation) && String.IsNullOrEmpty(CandleLocation) && String.IsNullOrEmpty(LightLocation) && String.IsNullOrEmpty(XsdsLocation)))
                {
                    if (!Directory.Exists(BinDirectory))
                    {
                        DirectoryInfo oldBinDirectory = new DirectoryInfo(BinDirectory);
                        if (oldBinDirectory.Parent != null)
                        {
                            FileInfo[] files = oldBinDirectory.Parent.GetFiles("candle.exe", SearchOption.AllDirectories);
                            if (files.Length == 0 && oldBinDirectory.Parent.Parent != null)
                            {
                                files = oldBinDirectory.Parent.Parent.GetFiles("candle.exe", SearchOption.AllDirectories);
                            }

                            if (files.Length == 1)
                            {
                                BinDirectory = files[0].Directory.FullName;
                            }
                            else if (files.Length > 1)
                            {
                                ArrayList directoryList = new ArrayList();
                                foreach (FileInfo file in files)
                                {
                                    directoryList.Add(file.Directory.FullName);
                                }
                                directoryList.Sort();

                                BinDirectory = (string)directoryList[directoryList.Count - 1];
                            }
                        }
                    }
                }

                TemplateDirectory = oldVersion.TemplateDirectory;
                if (!String.IsNullOrEmpty(TemplateDirectory))
                {
                    TemplateDirectory = TemplateDirectory.Replace("templates", "wizard");
                }
                UseRelativeOrAbsolutePaths = oldVersion.UseRelativeOrAbsolutePaths;
                if (oldVersion.ExternalXmlEditor == null || oldVersion.ExternalXmlEditor.Length == 0)
                {
                    ExternalXmlEditor = Path.Combine(Environment.SystemDirectory, "notepad.exe");
                }
                else
                {
                    ExternalXmlEditor = oldVersion.ExternalXmlEditor;
                }

                UseInstanceOnly        = oldVersion.UseInstanceOnly;
                WordWrapInResultsPanel = oldVersion.WordWrapInResultsPanel;

                if (oldVersion.IgnoreFilesAndDirectories != null && oldVersion.IgnoreFilesAndDirectories.Count > 0)
                {
                    IgnoreFilesAndDirectories = oldVersion.IgnoreFilesAndDirectories;
                }
                else
                {
                    ArrayList   oldValues = new ArrayList();
                    XmlNodeList nodes     = rawData.SelectNodes("/WixEdit/IgnoreFilesAndDirectories/string");
                    foreach (XmlNode node in nodes)
                    {
                        oldValues.Add(node.InnerText);
                    }

                    if (oldValues.Count > 0)
                    {
                        IgnoreFilesAndDirectories = oldValues;
                    }
                }

                RecentOpenedFiles = oldVersion.RecentOpenedFiles;

                DisplayFullPathInTitlebar = oldVersion.DisplayFullPathInTitlebar;

                XmlIndentation = oldVersion.XmlIndentation;

                AllowIncludeChanges   = oldVersion.AllowIncludeChanges;
                BackupChangedIncludes = oldVersion.BackupChangedIncludes;

                if (oldVersion.EditDialog == null)
                {
                    EditDialog = new EditDialogData();
                }
                else
                {
                    EditDialog = oldVersion.EditDialog;
                }

                Version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
            }
Exemplo n.º 3
0
        void LoadFromDisk() {
            Stream xmlStream = null;
            if (File.Exists(SettingsFile)) {
                // A FileStream is needed to read the XML document.
                xmlStream = new FileStream(SettingsFile, FileMode.Open);

                using (xmlStream) {
                    // Create an instance of the XmlSerializer class;
                    // specify the type of object to be deserialized.
                    XmlSerializer serializer = new XmlSerializer(typeof(WixEditData));
    
                    // If the XML document has been altered with unknown 
                    // nodes or attributes, handle them with the 
                    // UnknownNode and UnknownAttribute events.
                    serializer.UnknownNode += new XmlNodeEventHandler(DeserializeUnknownNode);
                    serializer.UnknownAttribute += new XmlAttributeEventHandler(DeserializeUnknownAttribute);
                
    
                    // Use the Deserialize method to restore the object's state with
                    // data from the XML document
                    data = (WixEditData) serializer.Deserialize(xmlStream);
                }
            } else {
                // Support the previous situation gracefully.
                if (File.Exists(OldSettingsFile)) {
                    // Try to move to new location
                    try {
                        File.Move(OldSettingsFile, SettingsFile);
                    } catch {
                        // Move didn't work, delete the file
                        try {
                            File.Delete(OldSettingsFile);
                        } catch {}
                    }

                    // If we got rid of the old file, then load again, otherwise just continue...
                    if (File.Exists(OldSettingsFile) == false) {
                        LoadFromDisk();
                        return;
                    }
                }

                data = new WixEditData();
            }

            XmlDocument rawData = new XmlDocument();
            try {
                xmlStream = new FileStream(SettingsFile, FileMode.Open);
                using (xmlStream) {
                    rawData.Load(xmlStream);
                }
            } catch {
                rawData = null;
            }

            try {
                if (data.Version == null) {
                    data = new WixEditData(data, rawData);
                } else {
                    Version current = GetCurrentVersion();
                    Version old = new Version(data.Version);

                    if (current.CompareTo(old) != 0) {
                        // Ok, watch out.
                        if (current.CompareTo(old) < 0) {
                            // This is a config file of a future version.
                            MessageBox.Show(String.Format("The version of the configuration file is newer than the version of this application, if any problems occur remove the settings file: {0}.", SettingsFile), "Configuration file", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            data = new WixEditData(data, rawData);
                        } else {
                            // This is a config file of an old version.
                            data = new WixEditData(data, rawData);

                            if (File.Exists(SettingsFile)) {
                                string oldFileName = SettingsFile + "_v" + old.ToString();
                                while (File.Exists(oldFileName)) {
                                    oldFileName = oldFileName + "_";
                                }

                                File.Copy(SettingsFile, oldFileName);
                            }
                        }

                        SaveChanges();
                    }
                }
            } catch {
                MessageBox.Show("Failed to convert the existing configuration file to the current version, using a default configuration.", "Configuration file", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                data = new WixEditData();
            }
        }
Exemplo n.º 4
0
        void LoadFromDisk()
        {
            Stream xmlStream = null;

            if (File.Exists(SettingsFile))
            {
                // A FileStream is needed to read the XML document.
                xmlStream = new FileStream(SettingsFile, FileMode.Open);

                using (xmlStream) {
                    // Create an instance of the XmlSerializer class;
                    // specify the type of object to be deserialized.
                    XmlSerializer serializer = new XmlSerializer(typeof(WixEditData));

                    // If the XML document has been altered with unknown
                    // nodes or attributes, handle them with the
                    // UnknownNode and UnknownAttribute events.
                    serializer.UnknownNode      += new XmlNodeEventHandler(DeserializeUnknownNode);
                    serializer.UnknownAttribute += new XmlAttributeEventHandler(DeserializeUnknownAttribute);


                    // Use the Deserialize method to restore the object's state with
                    // data from the XML document
                    data = (WixEditData)serializer.Deserialize(xmlStream);
                }
            }
            else
            {
                // Support the previous situation gracefully.
                if (File.Exists(OldSettingsFile))
                {
                    // Try to move to new location
                    try {
                        File.Move(OldSettingsFile, SettingsFile);
                    } catch {
                        // Move didn't work, delete the file
                        try {
                            File.Delete(OldSettingsFile);
                        } catch {}
                    }

                    // If we got rid of the old file, then load again, otherwise just continue...
                    if (File.Exists(OldSettingsFile) == false)
                    {
                        LoadFromDisk();
                        return;
                    }
                }

                data = new WixEditData();
            }

            XmlDocument rawData = new XmlDocument();

            try {
                xmlStream = new FileStream(SettingsFile, FileMode.Open);
                using (xmlStream) {
                    rawData.Load(xmlStream);
                }
            } catch {
                rawData = null;
            }

            try {
                if (data.Version == null)
                {
                    data = new WixEditData(data, rawData);
                }
                else
                {
                    Version current = GetCurrentVersion();
                    Version old     = new Version(data.Version);

                    if (current.CompareTo(old) != 0)
                    {
                        // Ok, watch out.
                        if (current.CompareTo(old) < 0)
                        {
                            // This is a config file of a future version.
                            MessageBox.Show(String.Format("The version of the configuration file is newer than the version of this application, if any problems occur remove the settings file: {0}.", SettingsFile), "Configuration file", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            data = new WixEditData(data, rawData);
                        }
                        else
                        {
                            // This is a config file of an old version.
                            data = new WixEditData(data, rawData);

                            if (File.Exists(SettingsFile))
                            {
                                string oldFileName = SettingsFile + "_v" + old.ToString();
                                while (File.Exists(oldFileName))
                                {
                                    oldFileName = oldFileName + "_";
                                }

                                File.Copy(SettingsFile, oldFileName);
                            }
                        }

                        SaveChanges();
                    }
                }
            } catch {
                MessageBox.Show("Failed to convert the existing configuration file to the current version, using a default configuration.", "Configuration file", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                data = new WixEditData();
            }
        }