コード例 #1
0
        private static async Task <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 (!await QuickDrive.RunAsync(serializedPreset: data.ToUtf8String()))
                {
                    throw new InformativeException(AppStrings.Common_CannotStartRace, AppStrings.Arguments_CannotStartRace_Commentary);
                }

                return(ArgumentHandleResult.SuccessfulShow);

            default:
                return(ArgumentHandleResult.Failed);
            }
        }