ShowWindow() публичный статический Метод

public static ShowWindow ( System.TimeSpan initialDelay, CancellationToken token, Squirrel.Update.ProgressSource progressSource ) : void
initialDelay System.TimeSpan
token System.Threading.CancellationToken
progressSource Squirrel.Update.ProgressSource
Результат void
Пример #1
0
        int executeCommandLine(string[] args)
        {
            var animatedGifWindowToken = new CancellationTokenSource();

            using (Disposable.Create(() => animatedGifWindowToken.Cancel())) {
                this.Log().Info("Starting Squirrel Updater: " + String.Join(" ", args));

                if (args.Any(x => x.StartsWith("/squirrel", StringComparison.OrdinalIgnoreCase)))
                {
                    // NB: We're marked as Squirrel-aware, but we don't want to do
                    // anything in response to these events
                    return(0);
                }

                bool silentInstall = false;
                var  updateAction  = default(UpdateAction);

                string target            = default(string);
                string releaseDir        = default(string);
                string packagesDir       = default(string);
                string bootstrapperExe   = default(string);
                string backgroundGif     = default(string);
                string signingParameters = default(string);
                string baseUrl           = default(string);
                string processStart      = default(string);
                string processStartArgs  = default(string);
                string setupIcon         = default(string);
                string icon         = default(string);
                string shortcutArgs = default(string);
                bool   shouldWait   = false;
                bool   noMsi        = (Environment.OSVersion.Platform != PlatformID.Win32NT); // NB: WiX doesn't work under Mono / Wine

                opts = new OptionSet()
                {
                    "Usage: Squirrel.exe command [OPTS]",
                    "Manages Squirrel packages",
                    "",
                    "Commands",
                    { "install=", "Install the app whose package is in the specified directory", v => { updateAction = UpdateAction.Install; target = v; } },
                    { "uninstall", "Uninstall the app the same dir as Update.exe", v => updateAction = UpdateAction.Uninstall },
                    { "download=", "Download the releases specified by the URL and write new results to stdout as JSON", v => { updateAction = UpdateAction.Download; target = v; } },
                    { "checkForUpdate=", "Check for one available update and writes new results to stdout as JSON", v => { updateAction = UpdateAction.CheckForUpdate; target = v; } },
                    { "update=", "Update the application to the latest remote version specified by URL", v => { updateAction = UpdateAction.Update; target = v; } },
                    { "releasify=", "Update or generate a releases directory with a given NuGet package", v => { updateAction = UpdateAction.Releasify; target = v; } },
                    { "createShortcut=", "Create a shortcut for the given executable name", v => { updateAction = UpdateAction.Shortcut; target = v; } },
                    { "removeShortcut=", "Remove a shortcut for the given executable name", v => { updateAction = UpdateAction.Deshortcut; target = v; } },
                    { "updateSelf=", "Copy the currently executing Update.exe into the default location", v => { updateAction = UpdateAction.UpdateSelf; target = v; } },
                    { "processStart=", "Start an executable in the latest version of the app package", v => { updateAction = UpdateAction.ProcessStart; processStart = v; }, true },
                    { "processStartAndWait=", "Start an executable in the latest version of the app package", v => { updateAction = UpdateAction.ProcessStart; processStart = v; shouldWait = true; }, true },
                    "",
                    "Options:",
                    { "h|?|help", "Display Help and exit", _ => {} },
                    { "r=|releaseDir=", "Path to a release directory to use with releasify", v => releaseDir = v },
                    { "p=|packagesDir=", "Path to the NuGet Packages directory for C# apps", v => packagesDir = v },
                    { "bootstrapperExe=", "Path to the Setup.exe to use as a template", v => bootstrapperExe = v },
                    { "g=|loadingGif=", "Path to an animated GIF to be displayed during installation", v => backgroundGif = v },
                    { "i=|icon", "Path to an ICO file that will be used for icon shortcuts", v => icon = v },
                    { "setupIcon=", "Path to an ICO file that will be used for the Setup executable's icon", v => setupIcon = v },
                    { "n=|signWithParams=", "Sign the installer via SignTool.exe with the parameters given", v => signingParameters = v },
                    { "s|silent", "Silent install", _ => silentInstall = true },
                    { "b=|baseUrl=", "Provides a base URL to prefix the RELEASES file packages with", v => baseUrl = v, true },
                    { "a=|process-start-args=", "Arguments that will be used when starting executable", v => processStartArgs = v, true },
                    { "l=|shortcut-locations=", "Comma-separated string of shortcut locations, e.g. 'Desktop,StartMenu'", v => shortcutArgs = v },
                    { "no-msi", "Don't generate an MSI package", v => noMsi = true },
                };

                opts.Parse(args);

                // NB: setupIcon and icon are just aliases for compatibility
                // reasons, because of a dumb breaking rename I made in 1.0.1
                setupIcon = setupIcon ?? icon;

                if (updateAction == UpdateAction.Unset)
                {
                    ShowHelp();
                    return(-1);
                }

                switch (updateAction)
                {
#if !MONO
                case UpdateAction.Install:
                    var progressSource = new ProgressSource();
                    if (!silentInstall)
                    {
                        AnimatedGifWindow.ShowWindow(TimeSpan.FromSeconds(4), animatedGifWindowToken.Token, progressSource);
                    }

                    Install(silentInstall, progressSource, Path.GetFullPath(target)).Wait();
                    animatedGifWindowToken.Cancel();
                    break;

                case UpdateAction.Uninstall:
                    Uninstall().Wait();
                    break;

                case UpdateAction.Download:
                    Console.WriteLine(Download(target).Result);
                    break;

                case UpdateAction.Update:
                    Update(target).Wait();
                    break;

                case UpdateAction.CheckForUpdate:
                    Console.WriteLine(CheckForUpdate(target).Result);
                    break;

                case UpdateAction.UpdateSelf:
                    UpdateSelf().Wait();
                    break;

                case UpdateAction.Shortcut:
                    Shortcut(target, shortcutArgs, processStartArgs, setupIcon);
                    break;

                case UpdateAction.Deshortcut:
                    Deshortcut(target, shortcutArgs);
                    break;

                case UpdateAction.ProcessStart:
                    ProcessStart(processStart, processStartArgs, shouldWait);
                    break;
#endif
                case UpdateAction.Releasify:
                    Releasify(target, releaseDir, packagesDir, bootstrapperExe, backgroundGif, signingParameters, baseUrl, setupIcon, !noMsi);
                    break;
                }
            }

            return(0);
        }
Пример #2
0
        int executeCommandLine(string[] args)
        {
            var animatedGifWindowToken = new CancellationTokenSource();

#if !MONO
            // Uncomment to test Gifs

            /*
             * var ps = new ProgressSource();
             * int i = 0; var t = new Timer(_ => ps.Raise(i += 10), null, 0, 1000);
             * AnimatedGifWindow.ShowWindow(TimeSpan.FromMilliseconds(0), animatedGifWindowToken.Token, ps);
             * Thread.Sleep(10 * 60 * 1000);
             */
#endif

            using (Disposable.Create(() => animatedGifWindowToken.Cancel())) {
                this.Log().Info("Starting Squirrel Updater: " + String.Join(" ", args));

                if (args.Any(x => x.StartsWith("/squirrel", StringComparison.OrdinalIgnoreCase)))
                {
                    // NB: We're marked as Squirrel-aware, but we don't want to do
                    // anything in response to these events
                    return(0);
                }

                if (opt.updateAction == UpdateAction.Unset)
                {
                    ShowHelp();
                    return(-1);
                }

                switch (opt.updateAction)
                {
#if !MONO
                case UpdateAction.Install:
                    var progressSource = new ProgressSource();
                    if (!opt.silentInstall)
                    {
                        AnimatedGifWindow.ShowWindow(TimeSpan.FromSeconds(4), animatedGifWindowToken.Token, progressSource);
                    }

                    Install(opt.silentInstall, progressSource, Path.GetFullPath(opt.target)).Wait();
                    animatedGifWindowToken.Cancel();
                    break;

                case UpdateAction.Uninstall:
                    Uninstall().Wait();
                    break;

                case UpdateAction.Download:
                    Console.WriteLine(Download(opt.target).Result);
                    break;

                case UpdateAction.Update:
                    Update(opt.target).Wait();
                    break;

                case UpdateAction.CheckForUpdate:
                    Console.WriteLine(CheckForUpdate(opt.target).Result);
                    break;

                case UpdateAction.UpdateSelf:
                    UpdateSelf().Wait();
                    break;

                case UpdateAction.Shortcut:
                    Shortcut(opt.target, opt.shortcutArgs, opt.processStartArgs, opt.setupIcon);
                    break;

                case UpdateAction.Deshortcut:
                    Deshortcut(opt.target, opt.shortcutArgs);
                    break;

                case UpdateAction.ProcessStart:
                    ProcessStart(opt.processStart, opt.processStartArgs, opt.shouldWait);
                    break;
#endif
                case UpdateAction.Releasify:
                    Releasify(opt.target, opt.releaseDir, opt.packagesDir, opt.bootstrapperExe, opt.backgroundGif, opt.signingParameters, opt.baseUrl, opt.setupIcon, !opt.noMsi, opt.packageAs64Bit, opt.frameworkVersion, !opt.noDelta);
                    break;
                }
            }
            this.Log().Info("Finished Squirrel Updater");
            return(0);
        }
Пример #3
0
        int main(string[] args)
        {
            var animatedGifWindowToken = new CancellationTokenSource();

            // NB: Trying to delete the app directory while we have Setup.log
            // open will actually crash the uninstaller
            bool isUninstalling = args.Any(x => x.Contains("uninstall"));

            // Uncomment to test Gifs
            //AnimatedGifWindow.ShowWindow(TimeSpan.FromMilliseconds(0), animatedGifWindowToken.Token);
            //Thread.Sleep(10 * 60 * 1000);

            using (Disposable.Create(() => animatedGifWindowToken.Cancel()))
                using (var logger = new SetupLogLogger(isUninstalling)
                {
                    Level = Splat.LogLevel.Info
                }) {
                    Splat.Locator.CurrentMutable.Register(() => logger, typeof(Splat.ILogger));

                    this.Log().Info("Starting Squirrel Updater: " + String.Join(" ", args));

                    if (args.Any(x => x.StartsWith("/squirrel", StringComparison.OrdinalIgnoreCase)))
                    {
                        // NB: We're marked as Squirrel-aware, but we don't want to do
                        // anything in response to these events
                        return(0);
                    }

                    bool silentInstall = false;
                    var  updateAction  = default(UpdateAction);

                    string target            = default(string);
                    string releaseDir        = default(string);
                    string packagesDir       = default(string);
                    string bootstrapperExe   = default(string);
                    string backgroundGif     = default(string);
                    string signingParameters = default(string);
                    string baseUrl           = default(string);
                    string processStart      = default(string);
                    string processStartArgs  = default(string);
                    string appName           = default(string);
                    string setupIcon         = default(string);
                    string shortcutArgs      = default(string);

                    opts = new OptionSet()
                    {
                        "Usage: Squirrel.exe command [OPTS]",
                        "Manages Squirrel packages",
                        "",
                        "Commands",
                        { "install=", "Install the app whose package is in the specified directory", v => { updateAction = UpdateAction.Install; target = v; } },
                        { "uninstall", "Uninstall the app the same dir as Update.exe", v => updateAction = UpdateAction.Uninstall },
                        { "download=", "Download the releases specified by the URL and write new results to stdout as JSON", v => { updateAction = UpdateAction.Download; target = v; } },
                        { "update=", "Update the application to the latest remote version specified by URL", v => { updateAction = UpdateAction.Update; target = v; } },
                        { "releasify=", "Update or generate a releases directory with a given NuGet package", v => { updateAction = UpdateAction.Releasify; target = v; } },
                        { "createShortcut=", "Create a shortcut for the given executable name", v => { updateAction = UpdateAction.Shortcut; target = v; } },
                        { "removeShortcut=", "Remove a shortcut for the given executable name", v => { updateAction = UpdateAction.Deshortcut; target = v; } },
                        { "updateSelf=", "Copy the currently executing Update.exe into the default location", v => { updateAction = UpdateAction.UpdateSelf; appName = v; } },
                        { "processStart=", "Start an executable in the latest version of the app package", v => { updateAction = UpdateAction.ProcessStart; processStart = v; }, true },
                        "",
                        "Options:",
                        { "h|?|help", "Display Help and exit", _ => {} },
                        { "r=|releaseDir=", "Path to a release directory to use with releasify", v => releaseDir = v },
                        { "p=|packagesDir=", "Path to the NuGet Packages directory for C# apps", v => packagesDir = v },
                        { "bootstrapperExe=", "Path to the Setup.exe to use as a template", v => bootstrapperExe = v },
                        { "g=|loadingGif=", "Path to an animated GIF to be displayed during installation", v => backgroundGif = v },
                        { "i=|setupIcon", "Path to an ICO file that will be used for the Setup executable's icon", v => setupIcon = v },
                        { "n=|signWithParams=", "Sign the installer via SignTool.exe with the parameters given", v => signingParameters = v },
                        { "s|silent", "Silent install", _ => silentInstall = true },
                        { "b=|baseUrl=", "Provides a base URL to prefix the RELEASES file packages with", v => baseUrl = v, true },
                        { "a=|process-start-args=", "Arguments that will be used when starting executable", v => processStartArgs = v, true },
                        { "l=|shortcut-locations=", "Comma-separated string of shortcut locations, e.g. 'Desktop,StartMenu'", v => shortcutArgs = v },
                    };

                    opts.Parse(args);

                    if (updateAction == UpdateAction.Unset)
                    {
                        ShowHelp();
                        return(-1);
                    }

                    switch (updateAction)
                    {
                    case UpdateAction.Install:
                        var progressSource = new ProgressSource();
                        if (!silentInstall)
                        {
                            AnimatedGifWindow.ShowWindow(TimeSpan.FromSeconds(4), animatedGifWindowToken.Token, progressSource);
                        }

                        Install(silentInstall, progressSource, Path.GetFullPath(target)).Wait();
                        break;

                    case UpdateAction.Uninstall:
                        Uninstall().Wait();
                        break;

                    case UpdateAction.Download:
                        Console.WriteLine(Download(target).Result);
                        break;

                    case UpdateAction.Update:
                        Update(target).Wait();
                        break;

                    case UpdateAction.UpdateSelf:
                        UpdateSelf(appName).Wait();
                        break;

                    case UpdateAction.Releasify:
                        Releasify(target, releaseDir, packagesDir, bootstrapperExe, backgroundGif, signingParameters, baseUrl, setupIcon);
                        break;

                    case UpdateAction.Shortcut:
                        Shortcut(target, shortcutArgs);
                        break;

                    case UpdateAction.Deshortcut:
                        Deshortcut(target, shortcutArgs);
                        break;

                    case UpdateAction.ProcessStart:
                        ProcessStart(processStart, processStartArgs);
                        break;
                    }
                }

            return(0);
        }
Пример #4
0
        int executeCommandLine(string[] args)
        {
            var animatedGifWindowToken = new CancellationTokenSource();

#if !MONO
            // Uncomment to test Gifs

            /*
             * var ps = new ProgressSource();
             * int i = 0; var t = new Timer(_ => ps.Raise(i += 10), null, 0, 1000);
             * AnimatedGifWindow.ShowWindow(TimeSpan.FromMilliseconds(0), animatedGifWindowToken.Token, ps);
             * Thread.Sleep(10 * 60 * 1000);
             */
#endif

            using (Disposable.Create(() => animatedGifWindowToken.Cancel())) {
                this.Log().Info("Starting Squirrel Updater: " + String.Join(" ", args));

                if (args.Any(x => x.StartsWith("/squirrel", StringComparison.OrdinalIgnoreCase)))
                {
                    // NB: We're marked as Squirrel-aware, but we don't want to do
                    // anything in response to these events
                    return(0);
                }

                if (opt.updateAction == UpdateAction.Unset)
                {
                    var message = "Update.exe called with no recognized command. Arguments were " +
                                  string.Join(" ", args);
                    if (NativeMethods.GetConsoleWindow() != IntPtr.Zero)
                    {
                        // already have a console, run from command line, don't UI.
                        Console.WriteLine(message);
                        ShowHelp();
                    }
                    else
                    {
#if !MONO
                        // Enhance: if we want our version to work in Mono we'll need to reference something that supports this
                        MessageBox.Show(message);
#endif
                    }
                    return(-1);
                }

                if (opt.unknownArgs.Any())
                {
                    var message = "Update.exe called with unexpected arguments: " + string.Join(" ", opt.unknownArgs) +
                                  ". Full arguments were " +
                                  string.Join(" ", args);
                    if (NativeMethods.GetConsoleWindow() != IntPtr.Zero)
                    {
                        // already have a console, run from command line, don't UI.
                        Console.WriteLine(message);
                        ShowHelp();
                    }
                    else
                    {
#if !MONO
                        // Enhance: if we want our version to work in Mono we'll need to reference something that supports this
                        MessageBox.Show(message);
#endif
                    }
                    return(-1);
                }

                switch (opt.updateAction)
                {
#if !MONO
                case UpdateAction.Install:
                    var progressSource = new ProgressSource();
                    if (!opt.silentInstall)
                    {
                        AnimatedGifWindow.ShowWindow(TimeSpan.FromSeconds(0), animatedGifWindowToken.Token, progressSource);
                    }

                    // If we get allUsers we do NOT want to launch the program (running as admin!) afterwards. Passing silent here
                    // will prevent that and has no other effects.
                    Install(opt.silentInstall || opt.allUsers, progressSource, Path.GetFullPath(opt.target)).Wait();
                    animatedGifWindowToken.Cancel();
                    break;

                case UpdateAction.Uninstall:
                    Uninstall().Wait();
                    break;

                case UpdateAction.Download:
                    Console.WriteLine(Download(opt.target).Result);
                    break;

                case UpdateAction.Update:
                    Update(opt.target).Wait();
                    break;

                case UpdateAction.CheckForUpdate:
                    Console.WriteLine(CheckForUpdate(opt.target).Result);
                    break;

                case UpdateAction.UpdateSelf:
                    UpdateSelf().Wait();
                    break;

                case UpdateAction.Shortcut:
                    Shortcut(opt.target, opt.shortcutArgs, opt.processStartArgs, opt.setupIcon);
                    break;

                case UpdateAction.Deshortcut:
                    Deshortcut(opt.target, opt.shortcutArgs);
                    break;

                case UpdateAction.ProcessStart:
                    ProcessStart(opt.processStart, opt.processStartArgs, opt.shouldWait);
                    break;
#endif
                case UpdateAction.Releasify:
                    return(Releasify(opt.target, opt.releaseDir, opt.packagesDir, opt.bootstrapperExe, opt.backgroundGif, opt.signingParameters, opt.baseUrl, opt.setupIcon, !opt.noMsi, opt.packageAs64Bit, opt.frameworkVersion, !opt.noDelta));
                }
            }
            this.Log().Info("Finished Squirrel Updater");
            return(0);
        }