-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMainForm.cs
89 lines (80 loc) · 2.88 KB
/
MainForm.cs
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
using System;
using System.IO;
using System.Windows.Forms;
using Newtonsoft.Json;
using RaidExtractor.Core;
using System.IO.Compression;
using System.Threading.Tasks;
using Raid.Client;
namespace RaidExtractor
{
public partial class MainForm : Form
{
private readonly RaidToolkitClient client;
public MainForm()
{
InitializeComponent();
Icon = System.Drawing.Icon.ExtractAssociatedIcon(Application.ExecutablePath);
ShowIcon = true;
client = new RaidToolkitClient();
}
private async void SaveButton_Click(object sender, EventArgs e)
{
var result = await GetDump();
if (result == null) return;
if (SaveJSONDialog.ShowDialog() != DialogResult.OK) return;
try
{
File.WriteAllText(SaveJSONDialog.FileName, JsonConvert.SerializeObject(result, Program.SerializerSettings));
if (SaveZipFile.Checked)
{
File.Delete(Path.ChangeExtension(SaveJSONDialog.FileName, ".ZIP"));
using (var memoryStream = new MemoryStream())
{
using (ZipArchive archive = ZipFile.Open(Path.ChangeExtension(SaveJSONDialog.FileName, ".ZIP"), ZipArchiveMode.Create))
{
var artifactFile = archive.CreateEntry("artifacts.json");
using (var entryStream = artifactFile.Open())
{
using (var streamWriter = new StreamWriter(entryStream))
{
streamWriter.Write(JsonConvert.SerializeObject(result, Formatting.Indented, Program.SerializerSettings));
}
}
}
}
}
}
catch (Exception exception)
{
MessageBox.Show(exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private async Task<AccountDump> GetDump()
{
try
{
client.Connect();
var accounts = await client.AccountApi.GetAccounts();
return await client.AccountApi.GetAccountDump(accounts[0].Id);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return null;
}
finally
{
client.Disconnect();
}
}
private async void MainForm_Load(object sender, EventArgs e)
{
try
{
await RaidToolkitClient.EnsureInstalled();
}
catch (Exception) { }
}
}
}