-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainForm.cs
136 lines (119 loc) · 5.92 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Windows.Forms;
using TSB_Updater.util;
namespace TSB_Updater
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
private void MainForm_Load(object sender, EventArgs e)
{
this.Icon = Properties.Resources.icon;
this.FormBorderStyle = FormBorderStyle.FixedSingle;
worldPath.Text = $@"C:\Users\{Environment.UserName}\AppData\Roaming\.minecraft\saves";
}
private void browsButton_Click(object sender, EventArgs e)
{
worldFolderBrowserDialog.SelectedPath = worldPath.Text;
if (worldFolderBrowserDialog.ShowDialog() == DialogResult.OK)
{
worldPath.Text = worldFolderBrowserDialog.SelectedPath;
}
}
private void updateButton_Click(object sender, EventArgs e)
{
List<Release> releases; // リリース情報
string currentVersion;
if (Process.GetProcessesByName("javaw").Length > 0)
{
MessageBox.Show("不具合を避けるため、Minecraftを終了してから実行してください。", "Minecraftの起動を検知しました", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (!Directory.Exists(worldPath.Text))
{
MessageBox.Show("フォルダーが存在しません。\nワールドフォルダーを指定してください。", "エラー", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (!UpdaterHelper.IsTSBFolder(worldPath.Text))
{
MessageBox.Show("The Sky Blessingのワールドフォルダーを指定してください。", "エラー", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
currentVersion = UpdaterHelper.GetCurrentVersion(worldPath.Text);
if (currentVersion == "unknown")
{
MessageBox.Show("バージョン情報の取得に失敗しました。\n指定したフォルダーが正しいか確認してください。", "エラー", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
try
{
releases = GitHubHelper.GetReleases();
}
catch (Exception)
{
MessageBox.Show("リリース情報の取得に失敗しました。\n手動でアップデートしてください。", "エラー", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
var latestRelease = UpdaterHelper.GetUpdatableLatestRlease(currentVersion, releases);
if (latestRelease == null)
{
MessageBox.Show("利用可能な更新はありません。\n手動でアップデートしてください。", "エラー", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (latestRelease.Version == currentVersion)
{
if (Version.Parse(releases[0].Version).CompareTo(Version.Parse(latestRelease.Version)) == 1)
{
DialogResult result = MessageBox.Show($"最新バージョン(v{releases[0].Version})が公開されています。\nこの更新は現在のワールドと互換性が無いため、手動でダウンロードする必要があります。\nダウンロードページを開きますか?", "情報", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
if (result == DialogResult.Yes)
{
ProcessStartInfo pi = new ProcessStartInfo()
{
FileName = releases[0].Url,
UseShellExecute = true,
};
Process.Start(pi);
}
return;
}
else
{
MessageBox.Show($"すでに最新バージョン(v{currentVersion})を利用しています。", "情報", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
return;
}
var asServer = false;
if (UpdaterHelper.CheckUsedServer(worldPath.Text))
{
var result = MessageBox.Show("サーバー設定ファイルを検知しました。\nサーバー環境としてアップデートを実行しますか?", "確認", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
asServer = result == DialogResult.Yes;
}
var vif = new VersionInfoForm(worldPath.Text, currentVersion, latestRelease, asServer);
vif.ShowDialog();
if (vif.Result == UpdateResult.OK)
{
MessageBox.Show("アップデートが完了しました。", "完了", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
if (Version.Parse(releases[0].Version).CompareTo(Version.Parse(latestRelease.Version)) == 1)
{
DialogResult result = MessageBox.Show($"最新バージョン(v{releases[0].Version})が公開されています。\nこの更新は現在のワールドと互換性が無いため、手動でダウンロードする必要があります。\nダウンロードページを開きますか?", "情報", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
if (result == DialogResult.Yes)
{
ProcessStartInfo pi = new ProcessStartInfo()
{
FileName = releases[0].Url,
UseShellExecute = true,
};
Process.Start(pi);
}
return;
}
}
}
}