示例#1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FormDialogVersionHistory"/> class.
        /// <param name="icon">A <see cref="Icon"/> to use with the form.</param>
        /// <param name="programName">Name of the program which version history to show.</param>
        /// </summary>
        public FormDialogVersionHistory(Icon icon, string programName)
        {
            InitializeComponent();
            Icon = icon;

            versionHistory =
                VersionDataCache.GetVersionHistoryFromCache(programName);

            var localization = new TabDeliLocalization();

            localization.GetLocalizedTexts(Properties.Resources.version_history_localization);

            btOK.Text            = localization.GetMessage("txtOK", "OK", OverrideCultureString);
            lbSelectVersion.Text = localization.GetMessage("txtSelectVersion", "Select a version:", OverrideCultureString);

            // ReSharper disable once VirtualMemberCallInConstructor
            Text            = localization.GetMessage("txtCaption", "Version history for the '{0}' application", OverrideCultureString, programName);
            allVersionsText = localization.GetMessage("txtAllVersions", "All versions", OverrideCultureString);

            cmbVersionHistorySelector.Items.Add(allVersionsText);
            foreach (var value in versionHistory)
            {
                cmbVersionHistorySelector.Items.Add(value.Key.ToString());
            }

            cmbVersionHistorySelector.SelectedIndex = 0;
        }
示例#2
0
        /// <summary>
        /// This method is called by the constructors. Localizes the dialog and sets the assembly information fields contents.
        /// </summary>
        private void MainInit()
        {
            try // about dialog shouldn't crash the application
            {
                var localization = new TabDeliLocalization();
                localization.GetLocalizedTexts(Properties.Resources.about_dialog_localization_txt);

                btOK.Text = localization.GetMessage("txtOK", "OK", OverrideCultureString);

                try
                {
                    Text = localization.GetMessage("txtText", "About - {0}", OverrideCultureString, AssemblyTitle);
                }
                catch
                {
                    Text = localization.GetMessage("txtText", "About - {0}", OverrideCultureString); // no title in about box title
                }

                lbBuildDateAndTimeValue.Text =
                    aboutAssembly.GetBuildDateTime()?.ToString("G") ?? "-";

                lbCheckVersionText.Text = localization.GetMessage("txtCheck", "Check version:", OverrideCultureString);
                sllLinkVersion.Text     = localization.GetMessage("txtClickCheck", "click to check", OverrideCultureString);
                na = localization.GetMessage("txtCheckNA", "N/A", OverrideCultureString);
                lbBoxDescriptionText.Text =
                    localization.GetMessage("txtDescription", "Description:", OverrideCultureString);
                lbCompanyNameText.Text =
                    localization.GetMessage("txtCompanyName", "Company name:", OverrideCultureString);
                lbCopyrightText.Text   = localization.GetMessage("txtCopyright", "Copyright:", OverrideCultureString);
                lbProductNameText.Text =
                    localization.GetMessage("txtProductName", "Product name:", OverrideCultureString);
                lbVersionText.Text = localization.GetMessage("txtVersion", "Version:", OverrideCultureString);
                lbLicenseText.Text = localization.GetMessage("txtLicense", "License:", OverrideCultureString);

                lbBuildDateTime.Text = localization.GetMessage("txtBuildDateTime", "Build date and time:", OverrideCultureString);

                btViewVersionHistory.Text = localization.GetMessage("txtVersionHistory", "Version history", OverrideCultureString);

                Icon.ExtractAssociatedIcon(aboutAssembly.Location);
            }
            catch
            {
                // ignored..
            }

            btViewVersionHistory.Enabled =
                !VersionDataCache.VersionHistoryCacheIsEmpty(AssemblyProduct);

            lbProductName.Text               = AssemblyProduct;
            lbVersion.Text                   = AssemblyVersion;
            lbCopyright.Text                 = AssemblyCopyright;
            lbCompanyName.Text               = AssemblyCompany;
            tbBoxDescription.Text            = AssemblyDescription;
            tbBoxDescription.HideSelection   = true;
            tbBoxDescription.SelectionLength = 0;
            btOK.Focus();
        }
        public static bool ShowDialog(string downloadUri, string pathToDownload, IWin32Window owner = null)
        {
            var localization = new TabDeliLocalization();

            localization.GetLocalizedTexts(Properties.Resources.download_dialog_localization);


            var form = new FormDialogDownloadFile
            {
                DownloadUri    = downloadUri,
                PathToDownload = pathToDownload,

                // (C)::https://social.msdn.microsoft.com/Forums/vstudio/en-US/53c7cd54-df02-44ec-b3ad-c1aaf5db67a5/extract-file-name?forum=csharpgeneral
                lbDownloadFileNameValue = { Text = Path.GetFileName(new Uri(downloadUri).LocalPath) },

                // localize..
                lbDownloadFileNameDescription =
                {
#pragma warning disable 618
                    Text = LocalizedDownloadText ??
                           localization.GetMessage("txtDownload", "Download:", OverrideCultureString)
                },
                lbPercentageText =
                {
                    Text = LocalizedDownloadPercentageText ??
                           localization.GetMessage("txtPercentageSymbol", "%", OverrideCultureString)
                },
                lbMBOfMBText =
                {
                    Text = LocalizedMBShortText ?? localization.GetMessage("txtMegabytes", "MB", OverrideCultureString)
                },
                lbSpeedMBsText =
                {
                    Text = LocalizedDownloadSpeedMBs ?? localization.GetMessage("txtMegabytesPerSeconds",
                                                                                "Speed (MB/s):", OverrideCultureString)
                },
#pragma warning restore 618
                btCancel =
                { Text = localization.GetMessage("txtCancel", "Cancel", OverrideCultureString) },
            };

            using (form)
            {
                // set the return value based on the DialogResult value..
                return(owner == null?form.ShowDialog() == DialogResult.OK : form.ShowDialog(owner) == DialogResult.OK);
            }
        }
        /// <summary>
        /// Checks for new version of an assembly and if a new version exists a dialog with details is shown.
        /// </summary>
        /// <param name="versionCheckUri">The version check URI.</param>
        /// <param name="assembly">The assembly of which updates to check.</param>
        /// <param name="localeString">The culture name in the format languagecode2-country/regioncode2. languagecode2 is a lowercase two-letter code derived from ISO 639-1. country/regioncode2 is derived from ISO 3166 and usually consists of two uppercase letters, or a BCP-47 language tag.</param>
        /// <returns><c>true</c> if a new version exists and the user decided to download it, <c>false</c> otherwise.</returns>
        public static bool CheckForNewVersion(string versionCheckUri, Assembly assembly, string localeString)
        {
            try
            {
                CheckUri = versionCheckUri;
                var version = GetVersion(assembly, localeString);

                // null validation before usage..
                if (version != null && version.IsLargerVersion(assembly))
                {
                    using (FormCheckVersion checkVersion = new FormCheckVersion())
                    {
                        try
                        {
                            checkVersion.Icon = Icon.ExtractAssociatedIcon(assembly.Location);
                            checkVersion.pbLargerIcon.Image = Icon.ExtractAssociatedIcon(assembly.Location)?.ToBitmap();
                        }
                        catch
                        {
                            // ignored..
                        }

                        var localization = new TabDeliLocalization();
                        localization.GetLocalizedTexts(Properties.Resources.tab_deli_localization);

                        checkVersion.Text = string.Format(localization.GetMessage("txtNewVersionTitle",
                                                                                  "A new version of the '{0}' software is available", localeString), version.SoftwareName);

                        checkVersion.lbCurrentVersion.Text = localization.GetMessage("txtCurrentVersion",
                                                                                     "Current version:", localeString);

                        checkVersion.tbCurrentVersion.Text = @"v." + assembly.GetName().Version;

                        checkVersion.lbNewVersion.Text = localization.GetMessage("txtNewVersion",
                                                                                 "New version:", localeString);

                        checkVersion.tbNewVersion.Text = @"v." + version.SoftwareVersion;

                        checkVersion.lbReleaseDateTime.Text = localization.GetMessage("txtReleaseDateTime",
                                                                                      "Release date/time:", localeString);

                        checkVersion.tbReleaseDateTime.Text = version.ReleaseDate.ToLocalTime().ToString("G");

                        checkVersion.lbReleaseNotes.Text = localization.GetMessage("txtReleaseChanges",
                                                                                   "Release changes:", localeString);

                        checkVersion.tbReleaseNotes.Text =
                            version.MetaDataLocalized.Replace("* ", "• ").Replace("*", "•");

                        if (!string.IsNullOrEmpty(version.MetaDataLocalized))
                        {
                            checkVersion.tbReleaseNotes.Text =
                                version.MetaDataLocalized.Replace("* ", "• ").Replace("*", "•");
                        }

                        checkVersion.btUpdate.Text =
                            localization.GetMessage("txtUpdateSoftware", "Update the software", localeString);

                        checkVersion.btCancel.Text = localization.GetMessage("txtCancel", "Cancel", localeString);

                        if (checkVersion.ShowDialog() == DialogResult.OK)
                        {
                            if (version.IsDirectDownload)
                            {
                                string tempPath = Path.GetTempPath();
                                if (DownloadFile(version.DownloadLink, tempPath))
                                {
                                    try
                                    {
                                        IncreaseDownloadCount(version.SoftwareName);

                                        var path = new Uri(version.DownloadLink).LocalPath;

                                        if (VersionCheck.ShellExecuteFileExtensions.Any(f => f.Equals(Path.GetExtension(path), StringComparison.InvariantCultureIgnoreCase)))
                                        {
                                            Process.Start(new ProcessStartInfo
                                            {
                                                FileName = Path.Combine(tempPath,
                                                                        Path.GetFileName(path)), UseShellExecute = true
                                            });
                                        }
                                        else
                                        {
                                            Process.Start(Path.Combine(tempPath,
                                                                       Path.GetFileName(path)));
                                        }

                                        return(true);
                                    }
                                    catch
                                    {
                                        return(false);
                                    }
                                }
                            }
                            else
                            {
                                try
                                {
                                    Process.Start(version.DownloadLink);
                                    return(true);
                                }
                                catch
                                {
                                    return(false);
                                }
                            }
                        }
                    }
                }

                return(true);
            }
            catch
            {
                return(false);
            }
        }
示例#5
0
        static void Main()
        {
            string appVersion = "1.0.0.0";

            string OutputFile() // get the executable file name and the version from it..
            {
                try
                {
                    var info = FileVersionInfo.GetVersionInfo(@"..\ScriptNotepad\bin\net6.0-windows\" + Executable);
                    appVersion = string.Concat(info.FileMajorPart, ".", info.FileMinorPart, ".", info.FileBuildPart);
                    return(string.Concat(AppName, "_", info.FileMajorPart, ".", info.FileMinorPart, ".", info.FileBuildPart));
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    return(AppName);
                }
            }

            var project = new ManagedProject("ScriptNotepad",
                                             new Dir(InstallDirectory,
                                                     new WixSharp.Files(@"..\ScriptNotepad\bin\net6.0-windows\*.*"),
                                                     new File("Program.cs")),
                                             new Dir($@"%ProgramMenu%\{Company}\{AppName}",
                                                     // ReSharper disable three times StringLiteralTypo
                                                     new ExeFileShortcut(AppName, $"[INSTALLDIR]{Executable}", "")
            {
                WorkingDirectory = "[INSTALLDIR]", IconFile = ApplicationIcon
            }),
#if InstallLocalAppData
                                             new Dir($@"%LocalAppDataFolder%\{AppName}",
                                                     new File(@"..\ScriptNotepad\Localization\SQLiteDatabase\lang.sqlite"),
                                                     new Dir(@"Dictionaries\en", new File(@"..\dictionaries\en\en_US.dic"),
                                                             new File(@"..\dictionaries\en\en_US.aff")),
                                                     new Dir("Plugins", new File(@"..\PluginTemplate\bin\net6.0-windows\PluginTemplate.dll"))),
#endif
                                             new CloseApplication($"[INSTALLDIR]{Executable}", true),
                                             new Property("Executable", Executable),
                                             new Property("AppName", AppName),
                                             new Property("Company", Company))
            {
                GUID             = new Guid("E142C7BA-2A0E-48B1-BB4E-CDC759AEBF91"),
                ManagedUI        = new ManagedUI(),
                ControlPanelInfo =
                {
                    Manufacturer = Company,
                    UrlInfoAbout = "https://www.vpksoft.net",
                    Name         = $"Installer for the {AppName} application",
                    HelpLink     = "https://www.vpksoft.net",
                },
                Platform    = Platform.x64,
                OutFileName = OutputFile(),
            };

            #region Upgrade
            // the application update process..
            project.Version      = Version.Parse(appVersion);
            project.MajorUpgrade = MajorUpgrade.Default;
            #endregion

            project.Package.Name = $"Installer for the {AppName} application";

            //project.ManagedUI = ManagedUI.Empty;    //no standard UI dialogs
            //project.ManagedUI = ManagedUI.Default;  //all standard UI dialogs

            //custom set of standard UI dialogs

            project.ManagedUI.InstallDialogs.Add(Dialogs.Welcome)
            .Add(Dialogs.Licence)
#if UseRunProgramDialog
            .Add <RunProgramDialog>()
#endif
#if UseAssociationDialog
            .Add <AssociationsDialog>()
#endif
            .Add <ProgressDialog>()
            .Add(Dialogs.Exit);

            project.ManagedUI.ModifyDialogs.Add(Dialogs.MaintenanceType)
            .Add(Dialogs.Features)
            .Add(Dialogs.Progress)
            .Add(Dialogs.Exit);

            project.ControlPanelInfo.ProductIcon = ApplicationIcon;

            AutoElements.UACWarning = "";


            project.BannerImage     = @"Files\install_top.png";
            project.BackgroundImage = @"Files\install_side.png";
            project.LicenceFile     = @"Files\MIT.License.rtf";

            RegistryFileAssociation.ReportExceptionAction = delegate(Exception ex)
            {
                MessageBox.Show(ex.Message);
            };

            project.AfterInstall += delegate(SetupEventArgs args)
            {
                string locale = "en-US";
                if (args.IsInstalling)
                {
                    try
                    {
                        locale = args.Session.Property("LANGNAME");
                    }
                    catch
                    {
                        // ignored..
                    }
                }

                try
                {
                    locale = CommonCalls.GetKeyValue(Company, AppName, "LOCALE");
                    CommonCalls.DeleteValue(Company, AppName, "LOCALE");
                }
                catch
                {
                    // ignored..
                }

                var sideLocalization = new TabDeliLocalization();
                sideLocalization.GetLocalizedTexts(Properties.Resources.tabdeli_messages);

                if (args.IsUninstalling)
                {
                    RegistryFileAssociation.UnAssociateFiles(Company, AppName);
                    CommonCalls.DeleteCompanyKeyIfEmpty(Company);

                    #if ShellStarAssociate
                    try
                    {
                        var openWithMessage = sideLocalization.GetMessage("txtOpenWithShellMenu",
                                                                          "Open with ", locale);

                        RegistryStarAssociation.UnRegisterStarAssociation(openWithMessage);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                    #endif

                    #if InstallLocalAppData
                    var messageCaption = sideLocalization.GetMessage("txtDeleteLocalApplicationData",
                                                                     "Delete application data", locale);

                    var messageText = sideLocalization.GetMessage("txtDeleteApplicationDataQuery",
                                                                  "Delete application settings and other data?", locale);

                    if (MessageBox.Show(messageText,
                                        messageCaption, MessageBoxButtons.YesNo,
                                        MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
                    {
                        try
                        {
                            Directory.Delete(
                                Path.Combine(Environment.GetEnvironmentVariable("LOCALAPPDATA") ?? string.Empty,
                                             AppName), true);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }
                    }
                    #endif
                }

                if (args.IsInstalling)
                {
                    #if ShellStarAssociate
                    var messageCaption = sideLocalization.GetMessage("txtStarAssociation",
                                                                     "Add open with menu", locale);

                    var messageText = sideLocalization.GetMessage("txtStarAssociationQuery",
                                                                  "Add an open with this application to the file explorer menu?", locale);

                    if (MessageBox.Show(messageText,
                                        messageCaption, MessageBoxButtons.YesNo,
                                        MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
                    {
                        try
                        {
                            var openWithMessage = sideLocalization.GetMessage("txtOpenWithShellMenu",
                                                                              "Open with ScriptNotepad", locale);

                            RegistryStarAssociation.RegisterStarAssociation(args.Session.Property("EXENAME"), AppName,
                                                                            openWithMessage);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }
                    }
                    #endif

                    RegistryFileAssociation.AssociateFiles(Company, AppName, args.Session.Property("EXENAME"),
                                                           args.Session.Property("ASSOCIATIONS"), true);

                    try
                    {
                        CommonCalls.SetKeyValue(Company, AppName, "LOCALE", args.Session.Property("LANGNAME"));
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
            };

            project.Load          += Msi_Load;
            project.BeforeInstall += Msi_BeforeInstall;
            project.AfterInstall  += Msi_AfterInstall;


            //project.SourceBaseDir = "<input dir path>";
            //project.OutDir = "<output dir path>";

            ValidateAssemblyCompatibility();

            project.DefaultDeferredProperties += ",RUNEXE,PIDPARAM,ASSOCIATIONS,LANGNAME,EXENAME";

            project.Localize();

            project.BuildMsi();
        }