private static ArgumentHandleResult ProcessSharedQuickDrivePreset(SharedEntry shared, byte[] data) { var result = ShowDialog(shared, AppStrings.Arguments_Shared_JustGo); switch (result) { case Choise.Save: case Choise.ApplyAndSave: var filename = FileUtils.EnsureUnique(Path.Combine( PresetsManager.Instance.GetDirectory(QuickDrive.PresetableKeyValue), @"Loaded", shared.GetFileName())); Directory.CreateDirectory(Path.GetDirectoryName(filename) ?? ""); File.WriteAllBytes(filename, data); if (result == Choise.ApplyAndSave) { QuickDrive.LoadPreset(filename); } return(ArgumentHandleResult.SuccessfulShow); case Choise.Apply: QuickDrive.LoadSerializedPreset(data.ToUtf8String()); return(ArgumentHandleResult.SuccessfulShow); case Choise.Extra: // just go if (!QuickDrive.RunSerializedPreset(data.ToUtf8String())) { throw new InformativeException(AppStrings.Common_CannotStartRace, AppStrings.Arguments_CannotStartRace_Commentary); } return(ArgumentHandleResult.SuccessfulShow); default: return(ArgumentHandleResult.Failed); } }
private static async Task <ArgumentHandleResult> ProcessUriRequestObsolete(string request) { string key, param; NameValueCollection query; { var splitted = request.Split(new[] { '/' }, 2); if (splitted.Length != 2) { return(ArgumentHandleResult.FailedShow); } key = splitted[0]; param = splitted[1]; var index = param.IndexOf('?'); if (index != -1) { query = HttpUtility.ParseQueryString(param.SubstringExt(index + 1)); param = param.Substring(0, index); } else { query = null; } } switch (key) { case "quickdrive": var preset = Convert.FromBase64String(param).ToUtf8String(); if (!QuickDrive.RunSerializedPreset(preset)) { NonfatalError.Notify(AppStrings.Common_CannotStartRace, AppStrings.Arguments_CannotStartRace_Commentary); return(ArgumentHandleResult.Failed); } break; case "race": var raceIni = Convert.FromBase64String(param).ToUtf8String(); await GameWrapper.StartAsync(new Game.StartProperties { PreparedConfig = IniFile.Parse(raceIni) }); break; case "open": var address = Convert.FromBase64String(param).ToUtf8String(); try { return(await ProcessInputFile(await LoadRemoveFile(address, query?.Get(@"name")))); } catch (Exception e) when(e.IsCanceled()) { return(ArgumentHandleResult.Failed); } catch (Exception e) { Logging.Warning(e); return(ArgumentHandleResult.FailedShow); } case "install": return(await ContentInstallationManager.Instance.InstallAsync(param, new ContentInstallationParams { AllowExecutables = true }) ? ArgumentHandleResult.Successful : ArgumentHandleResult.Failed); } return(ArgumentHandleResult.Successful); }
private async Task <ArgumentHandleResult> ProcessUriRequestObsolete(string request) { string key, param; NameValueCollection query; { var splitted = request.Split(new[] { '/' }, 2); if (splitted.Length != 2) { return(ArgumentHandleResult.FailedShow); } key = splitted[0]; param = splitted[1]; var index = param.IndexOf('?'); if (index != -1) { query = HttpUtility.ParseQueryString(param.SubstringExt(index + 1)); param = param.Substring(0, index); } else { query = null; } } switch (key) { case "quickdrive": var preset = Convert.FromBase64String(param).ToUtf8String(); if (!QuickDrive.RunSerializedPreset(preset)) { NonfatalError.Notify(AppStrings.Common_CannotStartRace, AppStrings.Arguments_CannotStartRace_Commentary); return(ArgumentHandleResult.Failed); } break; case "race": var raceIni = Convert.FromBase64String(param).ToUtf8String(); await GameWrapper.StartAsync(new Game.StartProperties { PreparedConfig = IniFile.Parse(raceIni) }); break; case "open": case "install": var address = Convert.FromBase64String(param).ToUtf8String(); var path = await LoadRemoveFile(address, query?.Get(@"name")); if (string.IsNullOrWhiteSpace(path)) { return(ArgumentHandleResult.FailedShow); } try { if (!FileUtils.Exists(path)) { return(ArgumentHandleResult.FailedShow); } } catch (Exception) { return(ArgumentHandleResult.FailedShow); } return(await ProcessInputFile(path)); } return(ArgumentHandleResult.Successful); }