From b0cdc4891a797f50e8b9bd8dabbfae6759be561b Mon Sep 17 00:00:00 2001 From: Luke Usher Date: Sat, 24 Feb 2018 18:19:35 +0000 Subject: [PATCH] Format partitions by emptying the contents rather than deleting the folder --- src/CxbxKrnl/EmuFile.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/CxbxKrnl/EmuFile.cpp b/src/CxbxKrnl/EmuFile.cpp index 72662e924..4aa1c37d9 100644 --- a/src/CxbxKrnl/EmuFile.cpp +++ b/src/CxbxKrnl/EmuFile.cpp @@ -184,14 +184,14 @@ void CxbxFormatPartitionByHandle(HANDLE hFile) return; } - // Format the partition, by deleting it's folder and re-creating it - // In this case, experimental means that these functions work and are safe - // but not officially in the C++ standard yet - // Requires a compiler with C++17 support + + // Format the partition, by iterating through the contents and removing all files/folders within + // Previously, we deleted and re-created the folder, but that caused permission issues for some users try { - std::experimental::filesystem::remove_all(partitionPath); - std::experimental::filesystem::create_directory(partitionPath); + for (auto& directoryEntry : std::experimental::filesystem::recursive_directory_iterator(partitionPath)) { + std::experimental::filesystem::remove_all(directoryEntry); + } } catch (std::experimental::filesystem::filesystem_error fsException) {