Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "Remember last folder in file pickers" setting, enabled by default #70

Merged
merged 6 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Shared.Core/KoikatuAPIBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public static bool EnableDebugLogging
}

private static ConfigEntry<bool> EnableDebugLoggingSetting { get; set; }
internal static ConfigEntry<bool> RememberFilePickerFolder { get; set; }

internal static KoikatuAPI Instance { get; private set; }
internal static new ManualLogSource Logger { get; private set; }
Expand Down Expand Up @@ -84,6 +85,7 @@ private void BaseAwake()
Logger = base.Logger;

EnableDebugLoggingSetting = Config.Bind("Debug", "Show debug messages", false, "Enables display of additional log messages when certain events are triggered within KKAPI. Useful for plugin devs to understand when controller messages are fired. Changes take effect after game restart.");
RememberFilePickerFolder = Config.Bind("General", "Remember file picker folder", true, "Setting only applies to plugins that use the file picker through this API.");
Keelhauled marked this conversation as resolved.
Show resolved Hide resolved

Logger.LogDebug($"Game version {GetGameVersion()} running under {System.Threading.Thread.CurrentThread.CurrentCulture.Name} culture");

Expand Down
20 changes: 12 additions & 8 deletions src/Shared.Core/Utilities/OpenFileDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,19 @@ public static string[] ShowDialog(string title, string initialDir, string filter
// Save and restore working directory since GetOpenFileName changes it for no good reason
var currentWorkingDirectory = Environment.CurrentDirectory;
var run = true;
BepInEx.ThreadingHelper.Instance.StartAsyncInvoke(() =>

ManlyMarco marked this conversation as resolved.
Show resolved Hide resolved
if (!KoikatuAPI.RememberFilePickerFolder.Value)
{
// Brute force seems to be the only viable way to prevent the current directory from getting changed
// Needed for compat with code running on different threads (including main unity thread) that uses relative paths
// This produces a ton of garbage and loads up one core, but `runInBackground = false` makes it much less of a problem
// Yes, this is horrible, if you know of a better way then do share
while (run) Environment.CurrentDirectory = currentWorkingDirectory;
return null;
});
BepInEx.ThreadingHelper.Instance.StartAsyncInvoke(() =>
{
// Brute force seems to be the only viable way to prevent the current directory from getting changed
// Needed for compat with code running on different threads (including main unity thread) that uses relative paths
// This produces a ton of garbage and loads up one core, but `runInBackground = false` makes it much less of a problem
// Yes, this is horrible, if you know of a better way then do share
while (run) Environment.CurrentDirectory = currentWorkingDirectory;
return null;
});
}

var success = NativeMethods.GetOpenFileName(ofn);

Expand Down