コード例 #1
0
        /// <summary>
        /// Returns true if MainWindow should be shown afterwards.
        /// </summary>
        public static async Task <bool> ProcessArguments(IEnumerable <string> arguments, TimeSpan extraDelay = default(TimeSpan))
        {
            var showMainWindow = false;

            var list = arguments.ToList();

            if (_previousArguments?.SequenceEqual(list) == true)
            {
                return(false);
            }

            _previousArguments = list;

            var remote = (await list.Select(async x => Tuple.Create(x,
                                                                    ContentInstallationManager.IsRemoteSource(x) || ContentInstallationManager.IsAdditionalContent(x) ? x :
                                                                    await ContentInstallationManager.IsRemoteSourceFlexible(x))
                                            ).WhenAll()).Where(x => x.Item2 != null).ToList();

            if (remote.Any())
            {
                list = list.ApartFrom(remote.Select(x => x.Item1)).ToList();
                if ((await remote.Select(x => ContentInstallationManager.Instance.InstallAsync(x.Item2, new ContentInstallationParams {
                    AllowExecutables = true
                })).WhenAll()).All(x => !x))
                {
                    await Task.Delay(ContentInstallationManager.OptionFailedDelay);
                }
            }

            foreach (var arg in list)
            {
                var result = await ProcessArgument(arg);

                if (extraDelay != TimeSpan.Zero)
                {
                    await Task.Delay(extraDelay);
                }

                if (result == ArgumentHandleResult.FailedShow)
                {
                    NonfatalError.Notify(AppStrings.Main_CannotProcessArgument, AppStrings.Main_CannotProcessArgument_Commentary);
                }

                if (result == ArgumentHandleResult.SuccessfulShow || result == ArgumentHandleResult.FailedShow)
                {
                    showMainWindow = true;
                }
            }

            _previousArguments = null;
            return(showMainWindow);
        }
コード例 #2
0
ファイル: ArgumentsHandler.cs プロジェクト: tankyx/actools
        /// <summary>
        /// Returns true if MainWindow should be shown afterwards.
        /// </summary>
        public static async Task <ShowMainWindow> ProcessArguments([CanBeNull] IEnumerable <string> arguments, bool fullPathsOnly,
                                                                   TimeSpan extraDelay = default(TimeSpan))
        {
            if (arguments == null)
            {
                return(ShowMainWindow.No);
            }

            var list = arguments.Select(FixProxiedRequest).ToList();

            if (_previousArguments?.SequenceEqual(list) == true)
            {
                return(ShowMainWindow.No);
            }
            if (list.Count == 0)
            {
                return(ShowMainWindow.Immediately);
            }

            try {
                // Why it’s here?
                _previousArguments = list;

                using (BringNewWindowsInFront()) {
                    var contentToInstall = (await list.Where(x => !IsCustomUriScheme(x))
                                            .Select(async x => Tuple.Create(x,
                                                                            ContentInstallationManager.IsRemoteSource(x) || ContentInstallationManager.IsAdditionalContent(x, fullPathsOnly) ? x :
                                                                            await ContentInstallationManager.IsRemoteSourceFlexible(x))
                                                    ).WhenAll()).Where(x => x.Item2 != null).ToList();
                    if (contentToInstall.Any())
                    {
                        list = list.ApartFrom(contentToInstall.Select(x => x.Item1)).ToList();
                        if ((await contentToInstall.Select(x => ContentInstallationManager.Instance.InstallAsync(x.Item2,
                                                                                                                 new ContentInstallationParams(true))).WhenAll()).All(x => !x))
                        {
                            // TODO
                            await Task.Delay(2000);
                        }
                    }

                    var showMainWindow = false;
                    foreach (var arg in list)
                    {
                        var result = await ProcessArgument(arg);

                        if (extraDelay != TimeSpan.Zero)
                        {
                            await Task.Delay(extraDelay);
                        }

                        if (result == ArgumentHandleResult.FailedShow)
                        {
                            NonfatalError.Notify(string.Format(AppStrings.Main_CannotProcessArgument, arg), AppStrings.Main_CannotProcessArgument_Commentary);
                        }

                        if (result == ArgumentHandleResult.SuccessfulShow || result == ArgumentHandleResult.FailedShow)
                        {
                            showMainWindow = true;
                        }
                    }

                    return(showMainWindow ? ShowMainWindow.Yes : ShowMainWindow.No);
                }
            } finally {
                _previousArguments = null;
            }
        }