Skip to content

Commit 31c8324

Browse files
committed
ワールドのバックアップをすべて削除する機能の追加
1 parent a2d23b6 commit 31c8324

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

MABProcessAtWait/Config.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public static List<World> SyncConfig() {
9191
//config内のworldがHDDになかった場合
9292
if (GetBackups(world).Count() == 0) {
9393
// バックアップが一つもない場合はconfigから削除
94-
logger.Info($"バックアップが一つもないのでRemoveWorldsに{world.WorldName}を追加");
94+
logger.Debug($"バックアップが一つもないのでRemoveWorldsに{world.WorldName}を追加");
9595
removeWorlds.Add(world);
9696
}
9797
else {

MABProcessAtWait/Program.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ static void Main() {
5959
Util.NotReadonly(AppConfig.BackupPath);
6060
Application.EnableVisualStyles();
6161
Application.SetCompatibleTextRenderingDefault(false);
62-
Form1 f = new Form1();
62+
Notify f = new Notify();
6363
Application.Run();
6464

6565
}
@@ -72,15 +72,15 @@ static void Main() {
7272
}
7373
}
7474

75-
public partial class Form1 :Form {
75+
public partial class Notify :Form {
7676
private static Logger logger = new Logger("MABProcess");
7777
private System.Windows.Forms.Timer timer;
7878
private string backupDataPath;
7979
private NotifyIcon notifyIcon;
8080
private bool isRunning = false;
8181
private Task backupTask;
8282

83-
public Form1() {
83+
public Notify() {
8484
logger.Info("Current Dir: "+System.Environment.CurrentDirectory);
8585
backupDataPath = AppConfig.BackupPath;
8686
this.ShowInTaskbar = false;

MainForms/BackupDataListView.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ public BackupDataListView(World worldObj) {
5151
deleteBackup.Click += new EventHandler(DeleteBackup_Click);
5252
clmnMenu.Items.Add(deleteBackup);
5353

54+
ToolStripMenuItem deleteAllBackup = new ToolStripMenuItem() {
55+
Text = "このワールドのバックアップを全て削除する",
56+
ForeColor = Color.Red,
57+
};
58+
deleteAllBackup.Click += new EventHandler(DeleteAllBackup_Click);
59+
clmnMenu.Items.Add(deleteAllBackup);
60+
5461
this.ContextMenuStrip = clmnMenu;
5562
#endregion
5663

@@ -181,5 +188,24 @@ private void DeleteBackup_Click(object sender , EventArgs e) {
181188
}
182189
}
183190

191+
private void DeleteAllBackup_Click(object sender, EventArgs e) {
192+
DialogResult result = MessageBox.Show("このワールドのバックアップを全て削除しますか?\n(この操作は取り消せません)", "Minecraft Auto Backup", MessageBoxButtons.YesNo);
193+
if (result == DialogResult.Yes) {
194+
DeleteAllBackup(selectedItem.World);
195+
this.Items.Clear();
196+
}
197+
}
198+
private void DeleteAllBackup(World world) {
199+
string deleteDirPath = $"{AppConfig.BackupPath}\\{world.WorldDir}\\{world.WorldName}";
200+
List<string> deleteWorldFileList = Directory.GetFiles(deleteDirPath).ToList();
201+
List<string> deleteWorldDirList = Directory.GetDirectories(deleteDirPath).ToList();
202+
foreach (string path in deleteWorldFileList) {
203+
File.Delete(path);
204+
}
205+
foreach(string path in deleteWorldDirList) {
206+
FileSystem.DeleteDirectory(path, UIOption.OnlyErrorDialogs, RecycleOption.DeletePermanently);
207+
}
208+
}
209+
184210
}
185211
#endregion

0 commit comments

Comments
 (0)