Esempio n. 1
0
        private OptionsForm(bool local)
        {
            InitializeComponent();

            // Copy the Bootstrap.exe file to New.exe,
            // so that the configuration file will load properly
            string currentDir = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
            string sandboxDir = Path.Combine(currentDir, "Sandbox");

            if (!File.Exists(Path.Combine(sandboxDir, "New.exe")))
            {
                File.Copy(
                    Path.Combine(sandboxDir, "Bootstrap.exe"),
                    Path.Combine(sandboxDir, "New.exe")
                    );
            }

            string filename = local ? "New.exe" : "Bootstrap.exe";
            string filepath = Path.Combine(sandboxDir, filename);

            _Configuration = ConfigurationManager.OpenExeConfiguration(filepath);

            // Get the DDay.Update configuration section
            _Cfg = _Configuration.GetSection("DDay.Update") as DDayUpdateConfigurationSection;

            // Set the default setting on which application folder to use.
            cbAppFolder.SelectedIndex = 0;

            SetValuesFromConfig();

            if (!local)
            {
                _Configuration.SaveAs(Path.Combine(sandboxDir, "New.exe.config"));
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Tries to determine an update notifier via the configuration file.
        /// </summary>
        static private void EnsureUpdateNotifier()
        {
            DDayUpdateConfigurationSection cfg = ConfigurationManager.GetSection("DDay.Update")
                                                 as DDayUpdateConfigurationSection;

            // Determine the update notifier that will be used to handle
            // update GUI display.
            if (cfg != null)
            {
                _UpdateNotifier = cfg.UpdateNotifier;
            }
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

            // Get the DDay.Update configuration section
            DDayUpdateConfigurationSection cfg = ConfigurationManager.GetSection("DDay.Update")
                                                 as DDayUpdateConfigurationSection;

            // Set the command line parameters to the application
            UpdateManager.SetCommandLineParameters(args);

            try
            {
                // Determine if an update is available
                if (cfg.Automatic)
                {
                    if (UpdateManager.IsUpdateAvailable(cfg.Uri, cfg.Username, cfg.Password, cfg.Domain))
                    {
                        log.Debug("Update is available, beginning update process...");

                        // Perform the update, which performs the following steps:
                        // 1. Updates to a new version of the application
                        // 2. Saves new deployment and application manifests locally
                        // 3. Removes previous versions of the application (depending on configuration settings)
                        UpdateManager.Update();
                    }
                    else
                    {
                        log.Debug("Application is up-to-date.");
                    }
                }
                else
                {
                    log.Debug("Automatic updates are disabled.");
                }
            }
            finally
            {
                // Start the application
                UpdateManager.StartApplication();
            }

            log.Debug("Exiting bootstrap application...");
        }
Esempio n. 4
0
        private void WriteConfigurationValues(string exeFilename)
        {
            System.Configuration.Configuration configuration =
                ConfigurationManager.OpenExeConfiguration(exeFilename);

            DDayUpdateConfigurationSection cfg = configuration.GetSection("DDay.Update")
                                                 as DDayUpdateConfigurationSection;

            // Set the update notifier in the configuration file
            ComboBoxItem cbi = cbUpdateNotifier.SelectedItem as ComboBoxItem;

            cfg.NotifierString = cbi.Value.ToString();

            // Set the update uri in the configuration file
            cfg.Uri = new Uri(txtUpdateURI.Text);

            // Save the configuration file
            configuration.Save();
        }
Esempio n. 5
0
        /// <summary>
        /// Copies the previous version of the application
        /// to the current version.
        /// </summary>
        /// <exception cref="DeploymentManifestException">
        /// if the deployment manifest has not yet been loaded
        /// </exception>
        private void CopyPreviousVersion()
        {
            // If the local deployment manifest does not exists, then
            // silently return; the update process will download all files
            if (LocalDeploymentManifest == null)
            {
                return;
            }

            if (DeploymentManifest == null)
            {
                throw new DeploymentManifestException();
            }

            string previousVersionFolder = LocalDeploymentManifest.CurrentPublishedVersion.ToString();
            string destinationFolder     = DeploymentManifest.CurrentPublishedVersion.ToString();

            // If the previous version exists, copy its contents to the destination folder!
            if (Directory.Exists(previousVersionFolder))
            {
                // Use the "Remove" configuration section to determine
                // the file patterns that should be removed from this version.
                List <string> patternsToExclude    = new List <string>();
                DDayUpdateConfigurationSection cfg = ConfigurationManager.GetSection("DDay.Update")
                                                     as DDayUpdateConfigurationSection;
                if (cfg != null)
                {
                    foreach (KeyValuePairConfigurationElement kvpe in cfg.Remove)
                    {
                        if (!string.IsNullOrEmpty(kvpe.Value))
                        {
                            patternsToExclude.Add(kvpe.Value);
                        }
                    }
                }

                CopyDirectoryStructure(previousVersionFolder, string.Empty, destinationFolder, patternsToExclude.ToArray());
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Removes previous versions of the application based
        /// on the bootstrap's configuration settings.
        /// </summary>
        static private void RemovePreviousVersions()
        {
            DDayUpdateConfigurationSection cfg = ConfigurationManager.GetSection("DDay.Update")
                                                 as DDayUpdateConfigurationSection;

            if (cfg != null)
            {
                if (cfg.KeepVersions != null &&
                    cfg.KeepVersions.HasValue)
                {
                    int numToKeep = cfg.KeepVersions.Value;
                    if (numToKeep >= 0)
                    {
                        List <Version> versions = new List <Version>();
                        string[]       dirs     = Directory.GetDirectories(VersionRepositoryFolder);
                        foreach (string dir in dirs)
                        {
                            try
                            {
                                Version v = new Version(Path.GetFileName(dir));
                                versions.Add(v);
                            }
                            catch
                            {
                            }
                        }

                        // Sort the versions in descending order
                        versions.Sort(delegate(Version v1, Version v2)
                        {
                            return(v2.CompareTo(v1));
                        });

                        if (versions.Count > 1)
                        {
                            // Remove the current version from the list
                            // (always keep the current version)
                            versions.RemoveAt(0);

                            // Remove the versions we want to keep
                            // from the list
                            while (numToKeep-- > 0 &&
                                   versions.Count > 0)
                            {
                                versions.RemoveAt(0);
                            }

                            // We are left with a list of versions
                            // that need to be removed.  Remove them!
                            foreach (Version v in versions)
                            {
                                cfg.VersionManager.RemoveVersion(v);
                            }
                        }
                    }
                }

                if (cfg.RemovePriorToVersion != null)
                {
                    // Get the maximum version that will
                    // be retained.
                    Version version = cfg.RemovePriorToVersion;
                    if (version != null)
                    {
                        List <Version> versions = new List <Version>();
                        string[]       dirs     = Directory.GetDirectories(VersionRepositoryFolder);
                        foreach (string dir in dirs)
                        {
                            try
                            {
                                // Get all versions that are less than
                                // the version provided
                                Version v = new Version(Path.GetFileName(dir));
                                if (v < version)
                                {
                                    versions.Add(v);
                                }
                            }
                            catch
                            {
                            }
                        }

                        // Remove each previous version
                        foreach (Version v in versions)
                        {
                            cfg.VersionManager.RemoveVersion(v);
                        }
                    }
                }
            }
        }
Esempio n. 7
0
        static public ApplicationManifest GetCurrentApplicationManifest()
        {
            ApplicationManifest appManifest = null;

            DDayUpdateConfigurationSection cfg = ConfigurationManager.GetSection("DDay.Update")
                                                 as DDayUpdateConfigurationSection;

            // Try to load a local deployment manifest
            if (LocalDeploymentManifest == null)
            {
                LoadLocalDeploymentManifest();
            }

            DeploymentManifest deploymentManifest = LocalDeploymentManifest ?? DeploymentManifest;

            // Try to retrieve the application manifest from the
            // deployment manifest.
            if (deploymentManifest != null)
            {
                // Load the deployment manifest, if we haven't done so already!
                log.Debug("Loading application manifest from deployment manifest...");
                try
                {
                    deploymentManifest.LoadApplicationManifest();
                    appManifest = deploymentManifest.ApplicationManifest;
                    log.Debug("Loaded.");
                }
                catch
                {
                }
            }

            // If we haven't found an application manifest yet, then let's try to load
            // it from a previous version!
            if (appManifest == null)
            {
                log.Debug("The application manifest could not be located; searching previous versions...");
                if (cfg != null)
                {
                    Version[] localVersions = cfg.VersionManager.LocalVersions;

                    if (localVersions.Length > 0)
                    {
                        for (int i = 0; i < localVersions.Length; i++)
                        {
                            log.Debug("Searching version '" + localVersions[i] + "'...");

                            // Try to load an application manifest
                            // from this version!
                            try
                            {
                                string directory = Path.Combine(VersionRepositoryFolder, localVersions[i].ToString());
                                Uri    uri       = new Uri(
                                    Path.Combine(
                                        directory,
                                        LocalApplicationManifestFilename
                                        )
                                    );

                                log.Debug("Attempting to load manifest from '" + uri.AbsolutePath + "'...");

                                // Get the application manifest
                                appManifest = new ApplicationManifest(uri);
                            }
                            catch { }

                            // If we found an application manifest, then check to see
                            // if the application name matches our bootstrap executable
                            // name.  If it doesn't, then we're looking at a version
                            // of a *different* application, and should ignore it!
                            if (appManifest.EntryPoint != null &&
                                appManifest.EntryPoint.AssemblyIdentity != null &&
                                appManifest.EntryPoint.AssemblyIdentity.Name != null)
                            {
                                string manifestName = appManifest.EntryPoint.AssemblyIdentity.Name;
                                string appName      = Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().Location);
                                if (!object.Equals(manifestName, appName))
                                {
                                    log.Debug("The application manifest for application '" + manifestName + "' was found and ignored (looking for '" + appName + "')");
                                    appManifest = null;
                                }
                            }

                            // We found an application manifest that we can use!
                            if (appManifest != null)
                            {
                                log.Debug("Application manifest found!");
                                break;
                            }
                        }
                    }
                }
            }

            return(appManifest);
        }
Esempio n. 8
0
        /// <summary>
        /// Updates bootstrap files.  This should be called
        /// as the first line of code in the main application.
        /// </summary>
        static public void UpdateBootstrapFiles()
        {
            Assembly currentAssembly = Assembly.GetEntryAssembly();

            // Ensure we aren't running from the bootstrap application
            if (!currentAssembly.FullName.Contains("DDay.Update.Bootstrap"))
            {
                DDayUpdateConfigurationSection cfg = ConfigurationManager.GetSection("DDay.Update")
                                                     as DDayUpdateConfigurationSection;

                // Determine the name of the bootstrap files folder
                string bootstrapFolderName = BootstrapFolder;
                if (cfg != null &&
                    !string.IsNullOrEmpty(cfg.BootstrapFilesFolder))
                {
                    bootstrapFolderName = cfg.BootstrapFilesFolder;
                }

                string assemblyLocation = Path.GetDirectoryName(currentAssembly.Location);
                string assemblyName     = Path.GetFileName(currentAssembly.Location);
                string bootstrapFolder  = Path.Combine(assemblyLocation, bootstrapFolderName);
                string baseLocation     = BaseApplicationFolder;

                log.Debug("Looking for bootstrap folder at '" + bootstrapFolder + "'...");

                // Ensure the bootstrap folder exists
                if (Directory.Exists(bootstrapFolder))
                {
                    log.Debug("Found bootstrap folder!");

                    try
                    {
                        // Find all files in the bootstrap folder
                        string[] files = Directory.GetFiles(bootstrapFolder);
                        foreach (string file in files)
                        {
                            // Determine the name of the destination file
                            string filename = Path.GetFileName(file);
                            if (filename.EndsWith(BootstrapFilesExtension))
                            {
                                filename = filename.Substring(filename.Length - BootstrapFilesExtension.Length);
                            }

                            // Determine the destination path...
                            string destFile = Path.Combine(baseLocation, filename);
                            log.Debug("File destination is: '" + destFile + "'");

                            // Rename the previous file, if it exists
                            if (File.Exists(destFile))
                            {
                                log.Debug("Renaming file '" + destFile + "' to '" + destFile + ".backup'...");
                                File.Move(destFile, destFile + ".backup");
                            }

                            log.Debug("Copying '" + file + "' to '" + destFile + "'...");
                            File.Copy(file, destFile);

                            // If we got this far OK, then delete the backup file!
                            if (File.Exists(destFile + ".backup"))
                            {
                                log.Debug("Deleting '" + destFile + ".backup'...");
                                File.Delete(destFile + ".backup");
                            }
                        }

                        // Delete each file in the bootstrap folder
                        foreach (string file in files)
                        {
                            File.Delete(file);
                        }

                        // Delete the bootstrap folder altogether
                        Directory.Delete(bootstrapFolder);
                    }
                    catch (Exception ex)
                    {
                        log.Error("An error occurred while updating the bootstrap files: " + ex.Message);
                        log.Debug("Restoring backup files...");

                        string[] files = Directory.GetFiles(baseLocation, "*.backup");
                        foreach (string file in files)
                        {
                            string destFile = file.Substring(0, file.Length - ".backup".Length);
                            if (File.Exists(destFile))
                            {
                                File.Move(destFile, destFile + ".old");
                            }

                            File.Move(file, destFile);

                            File.Delete(destFile + ".old");
                        }
                    }
                }
                else
                {
                    log.Debug("The bootstrap folder could not be found.");
                }
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Downloads updated versions of each file that is outdated.
        /// </summary>
        /// <exception cref="DeploymentManifestException">
        /// if the deployment manifest has not yet been loaded
        /// </exception>
        private bool UpdateFiles()
        {
            // Ensure the deployment manifest has been loaded
            if (DeploymentManifest == null)
            {
                throw new DeploymentManifestException();
            }

            // First, load the application manifest from the deployment manifest
            DeploymentManifest.LoadApplicationManifest();

            // Start a list of file downloaders the will be obtained from
            // the application manifest.
            _FileDownloaders = new List <FileDownloader>();
            _Saved           = new List <FileDownloader>();

            // Then, iterate through each downloadable file, determine if
            // an update is required for it, and download a new version
            // if necessary.
            foreach (IDownloadableFile file in
                     DeploymentManifest.ApplicationManifest.DownloadableFiles)
            {
                FileDownloader download = file.GetDownloader();
                download.Completed += new EventHandler(download_Completed);
                download.Cancelled += new EventHandler(download_Cancelled);
                download.Error     += new EventHandler <ExceptionEventArgs>(download_Error);
                download.Saved     += new EventHandler(download_Saved);

                log.Debug("Retrieved a downloader for '" + download.DestinationName + "'...");
                _FileDownloaders.Add(download);
            }

            log.Debug("Determining total download size...");

            // Determine the file patterns that are preserved (never overwritten)
            // during the update process...
            List <string> preservedPatterns    = new List <string>();
            DDayUpdateConfigurationSection cfg = ConfigurationManager.GetSection("DDay.Update")
                                                 as DDayUpdateConfigurationSection;

            if (cfg != null)
            {
                foreach (KeyValuePairConfigurationElement kvpe in cfg.Preserve)
                {
                    if (!string.IsNullOrEmpty(kvpe.Value))
                    {
                        preservedPatterns.Add(kvpe.Value);
                    }
                }
            }

            // Determine the preserved status of each file downloader.
            // Preserved files will not be downloaded
            foreach (FileDownloader downloader in _FileDownloaders)
            {
                downloader.DeterminePreservedStatus(preservedPatterns.ToArray());
            }

            // Determine the total size in bytes of updates to be made
            long totalSize = 0;

            foreach (FileDownloader downloader in _FileDownloaders)
            {
                totalSize += downloader.DownloadSize;
            }

            log.Debug("Total download size is " + totalSize + " bytes; notifying GUI...");

            // Notify of the total update size in bytes
            if (UpdateNotifier != null)
            {
                UpdateNotifier.NotifyTotalUpdateSize(totalSize);
            }

            // Setup an event to synchronize with...
            _DownloadEvent = new AutoResetEvent(false);

            log.Debug("Downloading each file to be updated...");

            // Download each file
            foreach (FileDownloader downloader in _FileDownloaders)
            {
                if (!CancelledOrError)
                {
                    // Download the new copy of the file
                    downloader.Download(UpdateNotifier);

                    // Wait for the item to be downloaded
                    _DownloadEvent.WaitOne();
                }
                else
                {
                    break;
                }
            }

            log.Info("File downloads finished.");
            return(true);
        }
Esempio n. 10
0
        private static void Main(string[] args)
        {
            bool   flag;
            string name = @"Global\StrongholdKingdomsAlphaUpdater";

            using (new Mutex(true, name, out flag))
            {
                DDText.loadText(Application.StartupPath + @"\");
                if (!flag)
                {
                    MessageBox.Show(tm(), DDText.getText(6), DDText.getText(7));
                    return;
                }
                AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(Program.CurrentDomain_UnhandledException);
                DDayUpdateConfigurationSection section = ConfigurationManager.GetSection("DDay.Update") as DDayUpdateConfigurationSection;
                UpdateManager.SetCommandLineParameters(args);
                bool flag2 = true;
                bool flag3 = false;
                bool flag4 = false;
                bool flag5 = false;
                try
                {
                    if (((args != null) && (args.Length > 0)) && (args[0] == "-uninstall"))
                    {
                        flag2 = false;
                        UpdateManager.Uninstall();
                    }
                    log.Debug("Starting Updater V" + SelfUpdater.CurrentBuildMajorVersion.ToString() + "." + SelfUpdater.CurrentBuildMinorVersion.ToString());
                    Form owner = null;
                    if (!section.Automatic || !flag2)
                    {
                        goto Label_03D2;
                    }
                    Uri uri = SelfUpdater.isSelfUpdaterAvailable(section.Uri, DDText.getText(0x17) == "XX");
                    if (uri != null)
                    {
                        MessageBoxButtons oKCancel = MessageBoxButtons.OKCancel;
                        if (MessageBox.Show(tm(), DDText.getText(8) + Environment.NewLine + DDText.getText(9) + Environment.NewLine + Environment.NewLine + DDText.getText(10), DDText.getText(11), oKCancel) == DialogResult.OK)
                        {
                            string path = SelfUpdater.downloadSelfUpdater(uri);
                            if ((path != null) && (path.Length > 0))
                            {
                                SelfUpdater.runInstaller(path);
                            }
                        }
                        flag2 = false;
                        return;
                    }
                    if (!UpdateManager.IsUpdateAvailable(section.Uri, section.Username, section.Password, section.Domain))
                    {
                        goto Label_03C1;
                    }
                    log.Debug("Update is available, beginning update process...");
                    int num = 30;
Label_01D3:
                    if (num < 0)
                    {
                        flag2 = false;
                        log.Debug("Run App Cancelled 1.");
                        flag3 = true;
                    }
                    else
                    {
                        if (num != 30)
                        {
                            UpdateManager.SysDelay(0x3e8);
                            if (flag5)
                            {
                                UpdateManager.IsUpdateAvailable(section.Uri, section.Username, section.Password, section.Domain);
                            }
                        }
                        if (UpdateManager.ManifestIssue)
                        {
                            MessageBox.Show(tm(), DDText.getText(12) + Environment.NewLine + Environment.NewLine + UpdateManager.ManifestString, DDText.getText(13));
                            flag2 = false;
                        }
                        else
                        {
                            bool flag6 = true;
                            while (UpdateManager.ConnectionIssue)
                            {
                                if (num == 30)
                                {
                                    UpdateManager.SysDelay(500);
                                }
                                MessageBoxButtons retryCancel = MessageBoxButtons.RetryCancel;
                                DialogResult      cancel      = DialogResult.Cancel;
                                if (UpdateManager._UpdateNotifier != null)
                                {
                                    owner = UpdateManager._UpdateNotifier.GetForm();
                                }
                                else
                                {
                                    owner = null;
                                }
                                if (owner != null)
                                {
                                    cancel = MessageBox.Show(owner, DDText.getText(14) + Environment.NewLine + Environment.NewLine + UpdateManager.WebErrorString, DDText.getText(15), retryCancel);
                                }
                                else
                                {
                                    cancel = MessageBox.Show(tm(), DDText.getText(14) + Environment.NewLine + Environment.NewLine + UpdateManager.WebErrorString, DDText.getText(15), retryCancel);
                                }
                                if (cancel == DialogResult.Retry)
                                {
                                    if (UpdateManager.IsUpdateAvailable(section.Uri, section.Username, section.Password, section.Domain))
                                    {
                                        continue;
                                    }
                                    flag6 = false;
                                }
                                else
                                {
                                    flag2 = false;
                                    flag6 = false;
                                    flag3 = false;
                                    flag5 = false;
                                    log.Debug("Run App Cancelled 2.");
                                }
                                break;
                            }
                            if (flag6)
                            {
                                flag5 = false;
                                log.Debug("Calling Update Manager...");
                                UpdateManager.Update();
                                num--;
                                if (UpdateManager.UserCancelled)
                                {
                                    flag2 = false;
                                    log.Debug("Run App Cancelled 3.");
                                    flag4 = true;
                                }
                                else
                                {
                                    if (UpdateManager.UserError)
                                    {
                                        flag5 = true;
                                    }
                                    if (flag5 || UpdateManager.IsUpdateAvailable(section.Uri, section.Username, section.Password, section.Domain))
                                    {
                                        goto Label_01D3;
                                    }
                                }
                            }
                        }
                    }
                    goto Label_04FF;
Label_03C1:
                    log.Debug("Application is up-to-date.");
                    goto Label_04FF;
Label_03D2:
                    log.Debug("Automatic updates are disabled.");
                }
                finally
                {
                    if (UpdateManager._UpdateNotifier != null)
                    {
                        Form form = UpdateManager._UpdateNotifier.GetForm();
                        if (form != null)
                        {
                            form.Close();
                        }
                    }
                    log.Debug("Main - Finally.");
                    if (flag2)
                    {
                        log.Debug("Main - Start App.");
                        string[] parameters = null;
                        if (DDText.getText(0x17) == "XX")
                        {
                            parameters = new string[] { "-InstallerVersion", "", "", "st" };
                        }
                        else
                        {
                            parameters = new string[] { "-InstallerVersion", "", "" };
                        }
                        parameters[1] = SelfUpdater.CurrentBuildVersion.ToString();
                        parameters[2] = DDText.getText(0);
                        UpdateManager.SetCommandLineParameters(parameters);
                        UpdateManager.StartApplication();
                    }
                    if (flag3 || flag5)
                    {
                        MessageBox.Show(tm(), DDText.getText(0x10), DDText.getText(13));
                    }
                    if (flag4)
                    {
                        MessageBox.Show(tm(), DDText.getText(0x11), DDText.getText(13));
                    }
                }
Label_04FF:
                log.Debug("Exiting bootstrap application...");
                Application.Exit();
            }
        }