Exemplo n.º 1
0
        public AppInfoViewModel(AppInfo model) : base(model, false)
        {
            AppSpec = new AppSpecViewModel(model.AppSpec);

            CompositeDisposable.Add(new PropertyChangedEventListener(model, (sender, e) =>
            {
                if (e.PropertyName == nameof(StartCount))
                {
                    RaisePropertyChanged(nameof(StartCount));
                }
            }));
        }
        public async void Generate()
        {
            if (!CanGenerate())
            {
                return;
            }

            if (!Directory.Exists(TargetDirectory))
            {
                Messenger.Raise(new InformationMessage("ターゲットディレクトリが存在しません。", "エラー", System.Windows.MessageBoxImage.Error, "Information"));
                return;
            }

            var paths = new[] { ScreenshotPath, ExecutablePath, SourceDirectory };
            var rels  = paths.Select(s => { string rel; return(Utils.TryGetRelativePath(TargetDirectory, s, out rel) ? rel : null); });

            if (paths.Concat(rels).Concat(new[] { Title }).Any(s => string.IsNullOrEmpty(s)))
            {
                var msg = new ConfirmationMessage("正しく入力されていない項目があります。続行しますか?\r\nこのまま続行した場合、CTRL Launcher に正しく表示されない可能性があります。",
                                                  "入力が不十分です", System.Windows.MessageBoxImage.Question, System.Windows.MessageBoxButton.YesNo, "Confirmation");
                Messenger.Raise(msg);
                if (!(msg.Response ?? false))
                {
                    return;
                }
            }
            else if (rels.Any(s => s.StartsWith(@"..\")))
            {
                var msg = new ConfirmationMessage("ターゲットディレクトリ内に含まれていないパス設定があります。続行しますか?\r\nこのまま続行した場合、CTRL Launcher に正しく表示されない可能性があります。",
                                                  "ファイル配置に問題があります", System.Windows.MessageBoxImage.Question, System.Windows.MessageBoxButton.YesNo, "Confirmation");
                Messenger.Raise(msg);
                if (!(msg.Response ?? false))
                {
                    return;
                }
            }

            try
            {
                IsSaving = true;

                var spec = new AppSpecViewModel();

                spec.Id             = Id.Trim();
                spec.Title          = Title;
                spec.Genre          = Genre;
                spec.ScreenshotPath = rels.ElementAt(0);
                spec.ExecutablePath = rels.ElementAt(1);
                spec.Argument       = Argument;
                spec.SourcePath     = rels.ElementAt(2);
                spec.TimeLimit      = new TimeSpan(0, TimeLimitMinutes, TimeLimitSeconds);
                spec.Description    = Description;

                await spec.SaveAsync(Path.Combine(TargetDirectory, "spec.yml"));

                Messenger.Raise(new InformationMessage("保存に成功しました。\r\n" + TargetDirectory + " を zip 圧縮して所定の場所にアップロードしてください。",
                                                       "完了", System.Windows.MessageBoxImage.Information, "Information"));
                Messenger.Raise(new InteractionMessage("Close"));
            }
            catch (Exception ex)
            {
                Messenger.Raise(new InformationMessage(ex.Message, "エラー", System.Windows.MessageBoxImage.Error, "Information"));
            }
            finally
            {
                IsSaving = false;
            }
        }