Skip to content

Commit b14e863

Browse files
committed
configure_v3: add parent directory to auto search
1 parent ca6101d commit b14e863

File tree

1 file changed

+25
-18
lines changed

1 file changed

+25
-18
lines changed

thcrap_configure_v3/Page4.xaml.cs

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -321,25 +321,9 @@ private void SetSearching(bool state)
321321
SearchButtonEverywhere.IsEnabled = true;
322322
}
323323
}
324-
private async void Search(string root, bool useAutoBehavior = false)
325-
{
326-
bool gamesListWasEmpty = this.games.Count == 0;
327-
foreach (var it in this.games)
328-
it.SetNew(false);
329-
330-
SetSearching(true);
331-
IntPtr foundPtr;
332-
if (useAutoBehavior)
333-
{
334-
foundPtr = await Task.Run(() => ThcrapDll.SearchForGamesInstalled(null));
335-
}
336-
else
337-
{
338-
foundPtr = await Task.Run(() => ThcrapDll.SearchForGames(new string[] { root, null }, null));
339-
}
340-
341-
SetSearching(false);
342324

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

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

364348
ThcrapDll.SearchForGames_free(foundPtr);
349+
}
350+
351+
private async void Search(string root, bool useAutoBehavior = false)
352+
{
353+
bool gamesListWasEmpty = this.games.Count == 0;
354+
foreach (var it in this.games)
355+
it.SetNew(false);
356+
357+
SetSearching(true);
358+
if (useAutoBehavior)
359+
{
360+
HandleGameSearchResult(await Task.Run(() => ThcrapDll.SearchForGamesInstalled(null)), gamesListWasEmpty);
361+
var dirInfo = new DirectoryInfo(".");
362+
if (dirInfo.Parent != null)
363+
{
364+
HandleGameSearchResult(await Task.Run(() => ThcrapDll.SearchForGames(new string[] { dirInfo.Parent.FullName, null }, null)), gamesListWasEmpty);
365+
}
366+
}
367+
else
368+
{
369+
HandleGameSearchResult(await Task.Run(() => ThcrapDll.SearchForGames(new string[] { root, null }, null)), gamesListWasEmpty);
370+
}
371+
SetSearching(false);
365372

366373
if (!gamesListWasEmpty)
367374
GamesScroll.ScrollToBottom();

0 commit comments

Comments
 (0)