-
Notifications
You must be signed in to change notification settings - Fork 81
Expand file tree
/
Copy pathAnimDataImportForm.cs
More file actions
73 lines (63 loc) · 2.6 KB
/
Copy pathAnimDataImportForm.cs
File metadata and controls
73 lines (63 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows.Forms;
using UoFiddler.Controls.Classes;
using static Ultima.Animdata;
namespace UoFiddler.Controls.Forms
{
public partial class AnimDataImportForm : Form
{
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public Action OnAfterImport { get; set; }
public AnimDataImportForm()
{
InitializeComponent();
cboConflictAction.SelectedItem = "skip";
}
private void OnClickImport(object sender, EventArgs e)
{
try
{
var fileName = txtImportFileName.Text;
var imported = ExportedAnimData.FromFile(fileName);
var overwrite = cboConflictAction.Items[cboConflictAction.SelectedIndex].ToString() == "overwrite";
// Create a new "working copy" AnimData to update, in case there's an exception thrown while processing.
// Shallow clone is okay, as UpdateAnimdata does not modify existing entries' members.
var workingAnimData = cbErase.Checked ? [] : new Dictionary<int, AnimdataEntry>(AnimData);
int importCount = imported.UpdateAnimdata(workingAnimData, overwrite);
// Since everything processed, set AnimData
AnimData = workingAnimData;
Options.ChangedUltimaClass["Animdata"] = true;
try
{
OnAfterImport?.Invoke();
}
catch
{
// Swallow any error from the OnAfterImport callback
}
MessageBox.Show($"Imported {importCount} animdata entries from: {fileName}\n\nDo not forget to save your changes!", "AnimData Import");
}
catch (Exception ex)
{
MessageBox.Show($"Error importing animdata: {ex.Message}", "AnimData Import", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
}
}
private void OnClickBrowse(object sender, EventArgs e)
{
var type = "json";
using OpenFileDialog dialog = new()
{
Multiselect = false,
Title = $"Choose {type} file to import",
CheckFileExists = true,
Filter = string.Format("{0} file (*.{0})|*.{0}", type)
};
if (dialog.ShowDialog() == DialogResult.OK)
{
txtImportFileName.Text = dialog.FileName;
}
}
}
}