Skip to content

Commit

Permalink
up 修复导入游戏文件夹问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Coloryr committed Jun 26, 2024
1 parent caaead1 commit baa4b4f
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/ColorMC.Core/Helpers/AddGameHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public static async Task<GameRes> AddGame(AddGameArg arg)

return new GameRes
{
State = false,
State = true,
Game = game
};
}
Expand Down
33 changes: 31 additions & 2 deletions src/ColorMC.Core/LaunchPath/InstancesPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ public static List<GameSettingObj> Games

private static FileSystemWatcher s_systemWatcher;
private static bool s_init;
private static bool s_change;
private static int s_delay;

private static readonly object s_lock = new();

/// <summary>
/// 游戏实例列表
Expand Down Expand Up @@ -114,7 +118,7 @@ public static void AddToGroup(this GameSettingObj obj)

if (!s_init)
{
ColorMCCore.OnInstanceChange();
StartChange();
}
}

Expand Down Expand Up @@ -142,7 +146,32 @@ private static void RemoveFromGroup(this GameSettingObj obj)

if (!s_init)
{
ColorMCCore.OnInstanceChange();
StartChange();
}
}

private static void StartChange()
{
lock (s_lock)
{
s_delay = 500;
if (!s_change)
{
s_change = true;
Task.Run(() =>
{
while (s_delay != 0)
{
Thread.Sleep(s_delay);
lock (s_lock)
{
s_delay = 0;
}
}
ColorMCCore.OnInstanceChange();
s_change = false;
});
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/ColorMC.Gui/UI/Model/Add/AddGameTab3Model.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ public async void SetPath(string res)

private async Task Import(List<string> list)
{
BaseBinding.IsAddGame = true;
bool ok = true;
foreach (var item in list)
{
Expand All @@ -179,9 +180,11 @@ private async Task Import(List<string> list)
return;
}
}
BaseBinding.IsAddGame = false;

if (ok)
{
WindowManager.MainWindow?.LoadMain();
var model = WindowManager.MainWindow?.DataContext as MainModel;
model?.Model.Notify(App.Lang("AddGameWindow.Tab2.Info5"));
WindowClose();
Expand Down
4 changes: 4 additions & 0 deletions src/ColorMC.Gui/UI/Model/Main/GamesModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ public void SetItems(List<GameSettingObj> list)
remove.Add(item);
}

if (GameList.Count == 0 || GameList.Count - 1 < 0)
{
return;
}
GameList.RemoveAt(GameList.Count - 1);

foreach (var item in remove)
Expand Down
6 changes: 6 additions & 0 deletions src/ColorMC.Gui/UIBinding/BaseBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ public static class BaseBinding
/// </summary>
private static string s_launch;

public static bool IsAddGame;

/// <summary>
/// 初始化
/// </summary>
Expand Down Expand Up @@ -132,6 +134,10 @@ public static void Init()

private static void InstanceChange()
{
if (IsAddGame)
{
return;
}
WindowManager.MainWindow?.LoadMain();
}

Expand Down

0 comments on commit baa4b4f

Please sign in to comment.