Exemplo n.º 1
0
        public async Task ApplyUpdateAsync(ApplyUpdateArgs args)
        {
            var source      = config.FullFileName;
            var destination = args.Target;

            // If no destination was specified, default to overwrite current path, trimmming ".update.exe" to ".exe"
            if (string.IsNullOrWhiteSpace(destination))
            {
                destination = source;
                if (destination.EndsWith(config.UpdateSuffix))
                {
                    destination = destination.Substring(0, destination.Length - config.UpdateSuffix.Length) + ".exe";
                }
            }

            // Make sure the destination exe doesn't have any running processes that would prevent an overwrite
            WaitForOtherProcesses(Path.GetFileNameWithoutExtension(destination));

            File.Copy(source, destination, true);

            // Launch the updated app
            if (args.Launch)
            {
                // Add arguments to delete the temporary exe now that the update is applied
                Launch(new LaunchArgs {
                    Target = destination
                });
            }
        }
Exemplo n.º 2
0
        public async Task <bool> ExecuteAsync()
        {
            // Use the application updater configuration and the command line to figure
            // out what we're going to be doing
            var commandline = CommandLineArgumentsFactory.Parse(config);

            // We didn't find any valid InstallSharp command, so return early
            if (commandline.Command == Command.None)
            {
                return(false);
            }

            switch (commandline.Command)
            {
            case Command.Install:
                break;

            case Command.Update:
                throw new NotImplementedException();

            case Command.ApplyUpdate:

                var args = new ApplyUpdateArgs
                {
                    Elevate = commandline.Elevate,
                    Launch  = commandline.Launch,
                    Target  = commandline.Target
                };

                await ApplyUpdateAsync(args).ConfigureAwait(false);

                break;

            case Command.Uninstall:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            return(true);
        }