Example #1
0
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            string baseDir = Properties.Settings.Default.LastBaseDir;

            if (String.IsNullOrEmpty(baseDir))
            {
                baseDir = Environment.CurrentDirectory;
            }
            using (var dialog = new FolderBrowserDialog {
                SelectedPath = baseDir,
                ShowNewFolderButton = false,
                Description = "Select the folder containing an update"
            }) {
                if (dialog.ShowDialog() == DialogResult.Cancel)
                {
                    return;
                }
                baseDir = Properties.Settings.Default.LastBaseDir = dialog.SelectedPath;
            }
            Properties.Settings.Default.Save();

            var product = Directory.GetFiles(baseDir, "*.exe")
                          .Select(p => Assembly.LoadFile(p).GetCustomAttribute <UpdatableAttribute>())
                          .FirstOrDefault(a => a != null);

            if (product == null)
            {
                XtraMessageBox.Show(baseDir + " does not contain any updatable assemblies.",
                                    "Shomrei Torah Update Publisher", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            UpdateInfo oldUpdate = UpdateChecker.Create(product.ProductName, new Version()).FindUpdate();               //We want to find the last update, so I search for an update for version 0.

            if (oldUpdate != null && product.CurrentVersion == oldUpdate.NewVersion &&
                DialogResult.No == XtraMessageBox.Show("The version number has not changed.\r\nCurrent clients will not download this update.\r\nDo you wish to continue?",
                                                       "Shomrei Torah Update Publisher", MessageBoxButtons.YesNo, MessageBoxIcon.Warning))
            {
                return;
            }

            ReadOnlyCollection <string> updateFiles = GetUpdateFiles(baseDir).ReadOnlyCopy();
            var element = EntryForm.Show(product, oldUpdate, updateFiles, baseDir);

            if (element == null)
            {
                return;
            }
            if (new Publisher(product, oldUpdate, element, updateFiles, baseDir).Publish())
            {
                XtraMessageBox.Show("The update has been uploaded to the server.",
                                    "Shomrei Torah Update Publisher", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }