Skip to content

Commit b5347da

Browse files
committed
#61 の追加
1 parent 3007b07 commit b5347da

File tree

2 files changed

+37
-12
lines changed

2 files changed

+37
-12
lines changed

MainForms/BackupDataListView.cs

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
using System.IO;
66
using System.Linq;
77
using System.Windows.Forms;
8+
using Microsoft.VisualBasic.FileIO;
89
#region tab backup
910
class BackupDataListView :ListView {
10-
private ContextMenuStrip cMenu;
11+
private ContextMenuStrip clmnMenu;
1112
private BackupDataListViewItem selectedItem = null;
1213
private ColumnHeader clmnBackupTime; // 'バックアップ日時' 列ヘッダ
1314
private ColumnHeader clmnAffiliationWorldName; // '所属ワールド名' 列ヘッダ
@@ -25,28 +26,32 @@ public BackupDataListView(World worldObj) {
2526
Dock = DockStyle.Fill;
2627
Scrollable = false;
2728
Sorting = SortOrder.Descending;
28-
29-
30-
cMenu = new ContextMenuStrip();
29+
clmnMenu = new ContextMenuStrip();
3130

3231
#region contextmenu
3332

34-
cMenu.Opening += new CancelEventHandler(Menu_Opening);
33+
clmnMenu.Opening += new CancelEventHandler(Menu_Opening);
3534
ToolStripMenuItem returnBackup = new ToolStripMenuItem() {
3635
Text = "このバックアップから復元する(&B)"
3736
};
3837
returnBackup.Click += new EventHandler(ReturnBackup_Click);
39-
cMenu.Items.Add(returnBackup);
38+
clmnMenu.Items.Add(returnBackup);
4039

4140
ToolStripMenuItem openInExplorer = new ToolStripMenuItem() {
4241
Text = "エクスプローラーで開く(&X)"
4342
};
44-
4543
openInExplorer.Click += new EventHandler(OpenInExplorer_Click);
4644
if (worldObj.IsAlive)
47-
cMenu.Items.Add(openInExplorer);
45+
clmnMenu.Items.Add(openInExplorer);
46+
47+
ToolStripMenuItem deleteBackup = new ToolStripMenuItem() {
48+
Text = "このバックアップを削除する(&B)",
49+
ForeColor = Color.Red,
50+
};
51+
deleteBackup.Click += new EventHandler(DeleteBackup_Click);
52+
clmnMenu.Items.Add(deleteBackup);
4853

49-
this.ContextMenuStrip = cMenu;
54+
this.ContextMenuStrip = clmnMenu;
5055
#endregion
5156

5257
clmnBackupTime = new ColumnHeader() { Text = "バックアップ日時" };
@@ -153,8 +158,28 @@ private void ReturnBackup_Click(object sender, EventArgs e) {
153158
}
154159

155160
private void OpenInExplorer_Click(object sender, EventArgs e) {
156-
ContextMenuStrip menu = sender as ContextMenuStrip;
157-
System.Diagnostics.Process.Start("EXPLORER.EXE", Util.makePathToWorld(selectedItem.SubItems[1].Text, selectedItem.SubItems[2].Text));
161+
System.Diagnostics.Process.Start("EXPLORER.EXE", Util.MakePathToWorld(selectedItem.SubItems[1].Text, selectedItem.SubItems[2].Text));
162+
}
163+
164+
private void DeleteBackup_Click(object sender , EventArgs e) {
165+
DialogResult result = MessageBox.Show("このバックアップを削除しますか?","Minecraft Auto Backup",MessageBoxButtons.YesNo);
166+
if (result == DialogResult.Yes) {
167+
DateTime dt = DateTime.ParseExact(selectedItem.SubItems[0].Text, "yyyy-MM-dd HH:mm", null);
168+
string fileName = dt.ToString("yyyyMMddHHmm");
169+
string backupPath;
170+
if (File.Exists($"{AppConfig.BackupPath}\\{selectedItem.SubItems[2].Text}\\{selectedItem.World.WorldName}\\{fileName}.zip")) {
171+
// バックアップがzipだった場合
172+
backupPath = $"{AppConfig.BackupPath}\\{selectedItem.SubItems[2].Text}\\{selectedItem.World.WorldName}\\{fileName}.zip";
173+
FileSystem.DeleteFile(backupPath);
174+
175+
}
176+
else {
177+
// バックアップがzipじゃなかった場合
178+
backupPath = $"{AppConfig.BackupPath}\\{selectedItem.SubItems[2].Text}\\{selectedItem.World.WorldName}\\{fileName}";
179+
FileSystem.DeleteDirectory(backupPath, UIOption.OnlyErrorDialogs,RecycleOption.DeletePermanently);
180+
}
181+
this.Items.Remove(selectedItem);
182+
}
158183
}
159184

160185
}

MainForms/Util.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public static string TrimDoubleQuotationMarks(string target) {
2121
return target.Trim(new char[] { '"' });
2222
}
2323

24-
public static string makePathToWorld(string name, string dir) {
24+
public static string MakePathToWorld(string name, string dir) {
2525
return $"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}\\{dir}\\saves\\{name}";
2626
}
2727

0 commit comments

Comments
 (0)