Exemplo n.º 1
0
        public static Options Load()
        {
            if (File.Exists("XrmToolBox.Settings.xml"))
            {
                var document = new XmlDocument();
                document.Load("XrmToolBox.Settings.xml");

                return((Options)XmlSerializerHelper.Deserialize(document.OuterXml, typeof(Options)));
            }

            return(new Options());
        }
Exemplo n.º 2
0
        private static void RemovePlugins()
        {
            var updateFile = Path.Combine(Paths.XrmToolBoxPath, "Deletion.xml");

            if (!File.Exists(updateFile))
            {
                return;
            }

            try
            {
                using (StreamReader reader = new StreamReader(updateFile))
                {
                    var pds = (PluginDeletions)XmlSerializerHelper.Deserialize(reader.ReadToEnd(), typeof(PluginDeletions));

                    try
                    {
                        var oldProcess = Process.GetProcessById(pds.PreviousProcessId);
                        oldProcess.WaitForExit();
                    }
                    catch { }

                    foreach (var pd in pds.Plugins)
                    {
                        foreach (var filePath in pd.Files)
                        {
                            var pathToDelete = Path.Combine(Paths.XrmToolBoxPath, filePath);

                            if (File.Exists(pathToDelete))
                            {
                                File.Delete(pathToDelete);
                            }
                            else
                            {
                                pathToDelete = Path.Combine(Paths.PluginsPath, filePath);
                                if (File.Exists(pathToDelete))
                                {
                                    File.Delete(pathToDelete);
                                }
                            }
                        }
                    }
                }

                File.Delete(updateFile);
            }
            catch (Exception error)
            {
                MessageBox.Show(
                    $"An error occured when trying to delete some plugins: {error.Message}.\n\nPlease start XrmToolBox again to fix this problem.",
                    @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 3
0
        public static bool Load(out Options options, out string errorMessage)
        {
            errorMessage = string.Empty;

            if (!Directory.Exists(Paths.SettingsPath))
            {
                Directory.CreateDirectory(Paths.SettingsPath);
            }

            var settingsFile = Path.Combine(Paths.SettingsPath, "XrmToolBox.Settings.xml");

            if (File.Exists(settingsFile))
            {
                try
                {
                    var document = new XmlDocument();
                    document.Load(settingsFile);

                    options = (Options)XmlSerializerHelper.Deserialize(document.OuterXml, typeof(Options));

                    if (options.DisplayOrder == null)
                    {
                        if (options.DisplayMostUsedFirst)
                        {
                            options.DisplayOrder = "Most used";
                        }
                        else if (options.DisplayRecentlyUpdatedFirst)
                        {
                            options.DisplayOrder = "Recently updated";
                        }
                        else
                        {
                            options.DisplayOrder = "Alphabetically";
                        }
                    }

                    return(true);
                }
                catch (Exception error)
                {
                    errorMessage = error.Message;
                    options      = new Options();
                    return(false);
                }
            }

            options = new Options();
            return(true);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Updates plugin that need to be updated after having use Plugins Store
        /// </summary>
        private static void CopyUpdatedPlugins()
        {
            var updateFile = Path.Combine(Paths.XrmToolBoxPath, "Update.xml");

            if (!File.Exists(updateFile))
            {
                return;
            }

            try
            {
                using (StreamReader reader = new StreamReader(updateFile))
                {
                    var pus = (PluginUpdates)XmlSerializerHelper.Deserialize(reader.ReadToEnd(),
                                                                             typeof(PluginUpdates));

                    try
                    {
                        var oldProcess = Process.GetProcessById(pus.PreviousProcessId);
                        oldProcess.WaitForExit();
                    }
                    catch { }

                    foreach (var pu in pus.Plugins)
                    {
                        if (!Directory.Exists(Path.GetDirectoryName(pu.Destination)))
                        {
                            Directory.CreateDirectory(Path.GetDirectoryName(pu.Destination));
                        }

                        File.Copy(pu.Source, pu.Destination, true);
                    }
                }

                File.Delete(updateFile);
            }
            catch (Exception error)
            {
                MessageBox.Show(
                    $@"An error occured when trying to update files: {error.Message}

Please start XrmToolBox again to fix this problem",
                    @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 5
0
        private static void CopyUpdatedPlugins()
        {
            var updateFile = Path.Combine(new FileInfo(Assembly.GetExecutingAssembly().Location).DirectoryName, "Update.xml");

            if (!File.Exists(updateFile))
            {
                return;
            }



            using (StreamReader reader = new StreamReader(updateFile))
            {
                var pus = (PluginUpdates)XmlSerializerHelper.Deserialize(reader.ReadToEnd(), typeof(PluginUpdates));

                try
                {
                    var oldProcess = Process.GetProcessById(pus.PreviousProcessId);
                    if (oldProcess != null)
                    {
                        oldProcess.WaitForExit(1000);
                    }
                }
                catch { }

                foreach (var pu in pus.Plugins)
                {
                    var destinationDirectory = Path.GetDirectoryName(pu.Destination);
                    if (!Directory.Exists(destinationDirectory))
                    {
                        Directory.CreateDirectory(destinationDirectory);
                    }
                    File.Copy(pu.Source, pu.Destination, true);
                }
            }

            File.Delete(updateFile);
        }
Exemplo n.º 6
0
        private static void RemovePlugins()
        {
            var updateFile = Path.Combine(Paths.XrmToolBoxPath, "Deletion.xml");

            if (!File.Exists(updateFile))
            {
                return;
            }

            using (StreamReader reader = new StreamReader(updateFile))
            {
                var pds = (PluginDeletions)XmlSerializerHelper.Deserialize(reader.ReadToEnd(), typeof(PluginDeletions));
                foreach (var pd in pds.Plugins)
                {
                    foreach (var filePath in pd.Files)
                    {
                        var pathToDelete = Path.Combine(Paths.XrmToolBoxPath, filePath);

                        if (File.Exists(pathToDelete))
                        {
                            File.Delete(pathToDelete);
                        }
                        else
                        {
                            pathToDelete = Path.Combine(Paths.PluginsPath, filePath);
                            if (File.Exists(pathToDelete))
                            {
                                File.Delete(pathToDelete);
                            }
                        }
                    }
                }
            }

            File.Delete(updateFile);
        }