Ejemplo n.º 1
0
        public static string UnwrapDownloadRequest(string request)
        {
            if (!request.StartsWith($@"{CustomUriSchemeHelper.UriScheme}//", StringComparison.Ordinal))
            {
                var splitted = request.Split(new[] { '/' }, 2);
                if (splitted.Length != 2)
                {
                    return(null);
                }

                var index = splitted[1].IndexOf('?');
                if (index != -1)
                {
                    splitted[1] = splitted[1].Substring(0, index);
                }

                return(splitted[0] == @"install" ? splitted[1] : null);
            }

            CustomUriRequest custom;

            try {
                custom = CustomUriRequest.Parse(request);
            } catch (Exception e) when(e.IsCancelled())
            {
                return(null);
            } catch (Exception) {
                NonfatalError.Notify(AppStrings.Arguments_CannotParseRequest, AppStrings.Main_CannotProcessArgument_Commentary);
                return(null);
            }

            switch (custom.Path.ToLowerInvariant())
            {
            case "install":
                return(custom.Params.Get(@"url"));
            }

            return(null);
        }
Ejemplo n.º 2
0
        private static async Task <ArgumentHandleResult> ProcessUriRequest(string uri)
        {
            if (!IsCustomUriScheme(uri))
            {
                return(ArgumentHandleResult.FailedShow);
            }

            var request = uri.SubstringExt(CustomUriSchemeHelper.UriScheme.Length);

            Logging.Debug("URI Request: " + request);

            if (!request.StartsWith(@"//", StringComparison.Ordinal))
            {
#pragma warning disable 612
                return(await ProcessUriRequestObsolete(request));

#pragma warning restore 612
            }

            CustomUriRequest custom;
            try {
                custom = CustomUriRequest.Parse(uri);
            } catch (Exception e) when(e.IsCancelled())
            {
                return(ArgumentHandleResult.Failed);
            } catch (Exception) {
                NonfatalError.Notify(AppStrings.Arguments_CannotParseRequest, AppStrings.Main_CannotProcessArgument_Commentary);
                return(ArgumentHandleResult.Failed);
            }

            try {
                switch (custom.Path.ToLowerInvariant())
                {
                case "launch":
                    return(ArgumentHandleResult.SuccessfulShow);

                case "race/quick":
                    return(await ProcessRaceQuick(custom));

                case "race/config":
                    return(await ProcessRaceConfig(custom));

                case "race/online":
                    return(await ProcessRaceOnline(custom.Params));

                case "race/online/join":
                    return(await ProcessRaceOnlineJoin(custom.Params));

                case "race/raceu":
                    return(await ProcessRaceRaceU(custom.Params));

                case "race/worldsimseries":
                    return(await ProcessWorldSimSeries(custom.Params));

                case "race/worldsimseries/login":
                    return(await ProcessWorldSimSeriesLogin(custom.Params));

                case "setsteamid":
                    return(ArgumentHandleResult.Ignore);    // TODO?

                case "loadgooglespreadsheetslocale":
                    return(await ProcessGoogleSpreadsheetsLocale(custom.Params.Get(@"id"), custom.Params.Get(@"locale"), custom.Params.GetFlag(@"around")));

                case "install":
                    var urls = custom.Params.GetValues(@"url") ?? new string[0];
                    if (custom.Params.GetFlag("fromWebsite"))
                    {
                        Logging.Debug("From website:" + urls.JoinToString(@"; "));
                        ModsWebBrowser.PrepareForCommand(urls, custom.Params.GetValues(@"websiteData") ?? new string[0]);
                    }

                    return((await urls.Select(
                                x => ContentInstallationManager.Instance.InstallAsync(x, new ContentInstallationParams(true)
                    {
                        CarId = custom.Params.Get(@"car")
                    })).WhenAll()).Any() ? ArgumentHandleResult.Successful : ArgumentHandleResult.Failed);

                case "importwebsite":
                    return(await ProcessImportWebsite(custom.Params.GetValues(@"data") ?? new string[0]));

                case "replay":
                    return(await ProcessReplay(custom.Params.Get(@"url"), custom.Params.Get(@"uncompressed") == null));

                case "rsr":
                    return(await ProcessRsrEvent(custom.Params.Get(@"id")));

                case "rsr/setup":
                    return(await ProcessRsrSetup(custom.Params.Get(@"id")));

                case "thesetupmarket/setup":
                    return(await ProcessTheSetupMarketSetup(custom.Params.Get(@"id")));

                case "shared":
                    var result = ArgumentHandleResult.Ignore;
                    foreach (var id in custom.Params.GetValues(@"id") ?? new string[0])
                    {
                        result = await ProcessShared(id);
                    }
                    return(result);

                default:
                    NonfatalError.Notify(string.Format(AppStrings.Main_NotSupportedRequest, custom.Path), AppStrings.Main_CannotProcessArgument_Commentary);
                    return(ArgumentHandleResult.Failed);
                }
            } catch (Exception e) when(e.IsCancelled())
            {
                return(ArgumentHandleResult.Failed);
            } catch (Exception e) {
                NonfatalError.Notify(AppStrings.Arguments_CannotProcessRequest, AppStrings.Arguments_CannotProcessRequest_Commentary, e);
                return(ArgumentHandleResult.Failed);
            }
        }
        private static async Task <ArgumentHandleResult> ProcessUriRequest(string uri)
        {
            if (!uri.StartsWith(CustomUriSchemeHelper.UriScheme, StringComparison.OrdinalIgnoreCase))
            {
                return(ArgumentHandleResult.FailedShow);
            }

            var request = uri.SubstringExt(CustomUriSchemeHelper.UriScheme.Length);

            Logging.Debug("URI Request: " + request);

            if (!request.StartsWith(@"//", StringComparison.Ordinal))
            {
#pragma warning disable 612
                return(await ProcessUriRequestObsolete(request));

#pragma warning restore 612
            }

            CustomUriRequest custom;
            try {
                custom = CustomUriRequest.Parse(uri);
            } catch (Exception e) when(e.IsCanceled())
            {
                return(ArgumentHandleResult.Failed);
            } catch (Exception) {
                NonfatalError.Notify(AppStrings.Arguments_CannotParseRequest, AppStrings.Main_CannotProcessArgument_Commentary);
                return(ArgumentHandleResult.Failed);
            }

            try {
                switch (custom.Path.ToLowerInvariant())
                {
                case "setsteamid":
                    return(ArgumentHandleResult.Ignore);    // TODO?

                case "race/online":
                    return(await ProgressRaceOnline(custom.Params));

                case "race/online/join":
                    return(await ProgressRaceOnlineJoin(custom.Params));

                case "loadgooglespreadsheetslocale":
                    return(await ProcessGoogleSpreadsheetsLocale(custom.Params.Get(@"id"), custom.Params.Get(@"locale"), custom.Params.GetFlag(@"around")));

                case "install":
                    return(await ContentInstallationManager.Instance.InstallAsync(custom.Params.Get(@"url"), new ContentInstallationParams {
                        AllowExecutables = true
                    }) ? ArgumentHandleResult.Successful : ArgumentHandleResult.Failed);

                case "replay":
                    return(await ProcessReplay(custom.Params.Get(@"url"), custom.Params.Get(@"uncompressed") == null));

                case "rsr":
                    return(await ProcessRsrEvent(custom.Params.Get(@"id")));

                case "rsr/setup":
                    return(await ProcessRsrSetup(custom.Params.Get(@"id")));

                case "thesetupmarket/setup":
                    return(await ProcessTheSetupMarketSetup(custom.Params.Get(@"id")));

                case "shared":
                    return(await ProcessShared(custom.Params.Get(@"id")));

                default:
                    NonfatalError.Notify(string.Format(AppStrings.Main_NotSupportedRequest, custom.Path), AppStrings.Main_CannotProcessArgument_Commentary);
                    return(ArgumentHandleResult.Failed);
                }
            } catch (Exception e) when(e.IsCanceled())
            {
                return(ArgumentHandleResult.Failed);
            } catch (Exception e) {
                NonfatalError.Notify(AppStrings.Arguments_CannotProcessRequest, AppStrings.Arguments_CannotProcessRequest_Commentary, e);
                return(ArgumentHandleResult.Failed);
            }
        }