From 69b615f2184555e8007e00dd69eb90f1a8bc4161 Mon Sep 17 00:00:00 2001
From: Kara <49822414+karashiiro@users.noreply.github.com>
Date: Fri, 12 May 2023 19:10:00 -0700
Subject: [PATCH] fix: only check FileDialog location existence during
navigation (#1196)
* Make DriveListLoader always async instead of usually async
* Simplify code
* Only check location existence during navigation
---
.../ImGuiFileDialog/DriveListLoader.cs | 29 ++++---------------
.../ImGuiFileDialog/FileDialog.Structs.cs | 3 --
.../ImGuiFileDialog/FileDialog.UI.cs | 3 +-
3 files changed, 8 insertions(+), 27 deletions(-)
diff --git a/Dalamud/Interface/ImGuiFileDialog/DriveListLoader.cs b/Dalamud/Interface/ImGuiFileDialog/DriveListLoader.cs
index 0706e0bc1..5898fefdf 100644
--- a/Dalamud/Interface/ImGuiFileDialog/DriveListLoader.cs
+++ b/Dalamud/Interface/ImGuiFileDialog/DriveListLoader.cs
@@ -1,5 +1,5 @@
-using System.Collections.Generic;
-using System.Collections.Immutable;
+using System;
+using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
@@ -10,14 +10,12 @@ namespace Dalamud.Interface.ImGuiFileDialog;
///
internal class DriveListLoader
{
- private bool initialized;
-
///
/// Initializes a new instance of the class.
///
public DriveListLoader()
{
- this.Drives = ImmutableArray.Empty;
+ this.Drives = Array.Empty();
}
///
@@ -49,23 +47,8 @@ internal class DriveListLoader
private async Task InitDrives()
{
- var drives = ImmutableArray.Empty;
- foreach (var drive in DriveInfo.GetDrives())
- {
- drives = drives.Add(drive);
- if (!this.initialized)
- {
- // Show results as soon as they load initially, but otherwise keep
- // the existing drive list
- this.Drives = drives;
- }
-
- // Force async to avoid this being invoked synchronously unless it's awaited
- await Task.Yield();
- }
-
- // Replace the whole drive list
- this.Drives = drives;
- this.initialized = true;
+ // Force async to avoid this being invoked synchronously unless it's awaited.
+ await Task.Yield();
+ this.Drives = DriveInfo.GetDrives();
}
}
diff --git a/Dalamud/Interface/ImGuiFileDialog/FileDialog.Structs.cs b/Dalamud/Interface/ImGuiFileDialog/FileDialog.Structs.cs
index 1373c9189..07e3bc20f 100644
--- a/Dalamud/Interface/ImGuiFileDialog/FileDialog.Structs.cs
+++ b/Dalamud/Interface/ImGuiFileDialog/FileDialog.Structs.cs
@@ -31,7 +31,6 @@ public partial class FileDialog
this.Text = text;
this.Location = location;
this.Icon = icon;
- this.Exists = !this.Location.IsNullOrEmpty() && Directory.Exists(this.Location);
}
public string Text { get; init; }
@@ -40,8 +39,6 @@ public partial class FileDialog
public FontAwesomeIcon Icon { get; init; }
- public bool Exists { get; init; }
-
public bool CheckExistence()
=> !this.Location.IsNullOrEmpty() && Directory.Exists(this.Location);
}
diff --git a/Dalamud/Interface/ImGuiFileDialog/FileDialog.UI.cs b/Dalamud/Interface/ImGuiFileDialog/FileDialog.UI.cs
index 608ed6d6d..d3be8da95 100644
--- a/Dalamud/Interface/ImGuiFileDialog/FileDialog.UI.cs
+++ b/Dalamud/Interface/ImGuiFileDialog/FileDialog.UI.cs
@@ -3,6 +3,7 @@ using System.IO;
using System.Linq;
using System.Numerics;
+using Dalamud.Utility;
using ImGuiNET;
namespace Dalamud.Interface.ImGuiFileDialog;
@@ -316,7 +317,7 @@ public partial class FileDialog
ImGui.SetCursorPosY(ImGui.GetCursorPosY() + Scaled(5));
var idx = 0;
- foreach (var qa in this.GetDrives().Concat(this.quickAccess).Where(qa => qa.Exists))
+ foreach (var qa in this.GetDrives().Concat(this.quickAccess).Where(qa => !qa.Location.IsNullOrEmpty()))
{
ImGui.PushID(idx++);
ImGui.SetCursorPosX(Scaled(25));