Exemplo n.º 1
0
        private void DeleteDataDir_btn_Click(object sender, RoutedEventArgs e)
        {
            if (Directory.Exists(XmlHelper.FileFolder))
            {
                var files    = dir.GetFiles(XmlHelper.FileFolder, "*.*", SearchOption.TopDirectoryOnly);
                var folders  = dir.GetDirectories(XmlHelper.FileFolder, "*", SearchOption.TopDirectoryOnly);
                var data_dir = $"{Directory.GetCurrentDirectory() + @"\" + XmlHelper.FileFolder}";

                if (files.Length > 1 || folders.Length > 0)
                {
                    string foundFilesList   = string.Join(",\n\t", files);
                    string foundFoldersList = string.Join(",\n\t", folders);

                    if (foundFilesList.Length == 0)
                    {
                        foundFilesList = "None";
                    }
                    if (foundFoldersList.Length == 0)
                    {
                        foundFoldersList = "None";
                    }

                    var choice = misc.YesNoPrompt($"Found {files.Length} files, {folders.Length} folders in {data_dir}:\n\nFiles Found:\n\t{foundFilesList}\n\nFolders found:\n\t{foundFoldersList}\n\n Do you still want to delete the directory?",
                                                  "Data folder delete confirmation");

                    if (choice == MessageBoxResult.No)
                    {
                        logger.Log("Data folder removal canceled!");
                        return;
                    }

                    foreach (var file in files)
                    {
                        dir.DeleteFileIfExist(file);
                    }

                    foreach (var folder in folders)
                    {
                        Directory.Delete(folder);
                    }
                }

                dir.DeleteFileIfExist(XmlHelper.FilePath);
                Directory.Delete(XmlHelper.FileFolder);
                logger.Log("Deleted Data Directory!");
            }
        }