コード例 #1
0
        private async Task LoadFile(string filename)
        {
            LoadDlg dialogue = new LoadDlg {
                Owner = this
            };

            Task t = Task.Run(() =>
            {
                Data = null;
                UndertaleData data = null;
                try
                {
                    using (var stream = new FileStream(filename, FileMode.Open))
                    {
                        data = UndertaleIO.Read(stream, warning =>
                        {
                            MessageBox.Show(warning, "Loading warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                        });
                    }
                }
                catch (Exception e)
                {
                    MessageBox.Show("An error occured while trying to load:\n" + e.Message, "Load error", MessageBoxButton.OK, MessageBoxImage.Error);
                }

                Dispatcher.Invoke(() =>
                {
                    //if (data != null)
                    //{
                    this.Data     = data;
                    this.FilePath = filename;
                    //}
                    dialogue.Close();
                });
            });

            dialogue.ShowDialog();
            await t;
        }
コード例 #2
0
        private async Task SaveFile(string filename)
        {
            if (Data == null || Data.UnsupportedBytecodeVersion)
            {
                return;
            }
            SetStatics();
            LoadDlg dialogue = null;
            Task    t        = null;
            bool    thingy   = await DoCorrupt.DoThing(Data, Values.DoSprite, Values.DoBackground, Values.DoSound, Values.DoText, Values.DoFont, Values.SpriteType, FilePath, rng, IsDelta());

            if (thingy)
            {
                MessageBox.Show("Corrupted succesfully! Probably!", "Egg?!?!?!?!??!", MessageBoxButton.OK, MessageBoxImage.None);
                dialogue = new LoadDlg {
                    Owner = this
                };

                t = Task.Run(() =>
                {
                    //OldData = Data;
                    //MessageBox.Show("Data old set", "", MessageBoxButton.OK, MessageBoxImage.None);
                    using (var stream = new FileStream(filename, FileMode.Create))
                    {
                        UndertaleIO.Write(stream, Data);
                    }

                    Dispatcher.Invoke(() =>
                    {
                        dialogue.Close();
                        //Data = OldData;
                        //MessageBox.Show("New data set", "", MessageBoxButton.OK, MessageBoxImage.None);
                    });
                });
                dialogue.ShowDialog();
                await t;
            }
        }