Skip to content

Commit

Permalink
configure_v3: add parent directory to auto search
Browse files Browse the repository at this point in the history
  • Loading branch information
brliron committed Feb 5, 2025
1 parent ca6101d commit b14e863
Showing 1 changed file with 25 additions and 18 deletions.
43 changes: 25 additions & 18 deletions thcrap_configure_v3/Page4.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -321,25 +321,9 @@ private void SetSearching(bool state)
SearchButtonEverywhere.IsEnabled = true;
}
}
private async void Search(string root, bool useAutoBehavior = false)
{
bool gamesListWasEmpty = this.games.Count == 0;
foreach (var it in this.games)
it.SetNew(false);

SetSearching(true);
IntPtr foundPtr;
if (useAutoBehavior)
{
foundPtr = await Task.Run(() => ThcrapDll.SearchForGamesInstalled(null));
}
else
{
foundPtr = await Task.Run(() => ThcrapDll.SearchForGames(new string[] { root, null }, null));
}

SetSearching(false);

private async void HandleGameSearchResult(IntPtr foundPtr, bool gamesListWasEmpty)
{
var found = ThcrapHelper.ParseNullTerminatedStructArray<ThcrapDll.game_search_result>(foundPtr);

foreach (var it in found)
Expand All @@ -362,6 +346,29 @@ private async void Search(string root, bool useAutoBehavior = false)
}

ThcrapDll.SearchForGames_free(foundPtr);
}

private async void Search(string root, bool useAutoBehavior = false)
{
bool gamesListWasEmpty = this.games.Count == 0;
foreach (var it in this.games)
it.SetNew(false);

SetSearching(true);
if (useAutoBehavior)
{
HandleGameSearchResult(await Task.Run(() => ThcrapDll.SearchForGamesInstalled(null)), gamesListWasEmpty);
var dirInfo = new DirectoryInfo(".");
if (dirInfo.Parent != null)
{
HandleGameSearchResult(await Task.Run(() => ThcrapDll.SearchForGames(new string[] { dirInfo.Parent.FullName, null }, null)), gamesListWasEmpty);
}
}
else
{
HandleGameSearchResult(await Task.Run(() => ThcrapDll.SearchForGames(new string[] { root, null }, null)), gamesListWasEmpty);
}
SetSearching(false);

if (!gamesListWasEmpty)
GamesScroll.ScrollToBottom();
Expand Down

0 comments on commit b14e863

Please sign in to comment.