From a32788e89a45383c464974a901606ce525d51117 Mon Sep 17 00:00:00 2001 From: yutoVR Date: Sun, 22 Nov 2020 23:40:17 +0900 Subject: [PATCH] =?UTF-8?q?=E3=82=88=E3=82=8A=E5=A0=85=E7=89=A2=E3=81=AB?= =?UTF-8?q?=E4=B8=80=E6=99=82=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB=E3=82=92?= =?UTF-8?q?=E3=82=AF=E3=83=AA=E3=83=BC=E3=83=B3=E3=82=A2=E3=83=83=E3=83=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- APKInstaller/Resource.cs | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/APKInstaller/Resource.cs b/APKInstaller/Resource.cs index d1dd1d2..bf3cbc1 100644 --- a/APKInstaller/Resource.cs +++ b/APKInstaller/Resource.cs @@ -82,14 +82,44 @@ public static void Cleanup(object sender, CancelEventArgs cancelEventArgs) { if (OtherInstanceExists()) return; + Message.Add("クリーンアップ中..."); + while (IsLocked(TempDirectory)) { Thread.Sleep(500); } - Directory.Delete(TempDirectory, true); - Message.Add("完了"); - Thread.Sleep(1000); + var directoryIsEmpty = true; + var files = Directory.GetFiles(TempDirectory); + foreach (var file in files) + { + var tryout = 0; + while (IsLocked(file) && tryout < 5) + { + ++tryout; + Thread.Sleep(200); + } + + if (tryout >= 5) + { + directoryIsEmpty = false; + continue; + } + + File.Delete(file); + } + + if (directoryIsEmpty) + { + Directory.Delete(TempDirectory, true); + Message.Add("完了"); + Thread.Sleep(1000); + } + else + { + Message.Add("他のアプリケーションが通信機能を使用しているため、クリーンアップをスキップしました。"); + Thread.Sleep(4000); + } } public static bool OtherInstanceExists()