diff --git a/ProjBobcat/ProjBobcat/DefaultComponent/Launch/DefaultVersionLocator.cs b/ProjBobcat/ProjBobcat/DefaultComponent/Launch/DefaultVersionLocator.cs index a3d0717..ad6b51a 100644 --- a/ProjBobcat/ProjBobcat/DefaultComponent/Launch/DefaultVersionLocator.cs +++ b/ProjBobcat/ProjBobcat/DefaultComponent/Launch/DefaultVersionLocator.cs @@ -31,7 +31,7 @@ public sealed class DefaultVersionLocator : VersionLocatorBase /// public DefaultVersionLocator(string rootPath, Guid clientToken) : base(rootPath) { - LauncherProfileParser = new DefaultLauncherProfileParser(rootPath, clientToken); + LauncherProfileParser ??= new DefaultLauncherProfileParser(rootPath, clientToken); //防止给定路径不存在的时候Parser遍历文件夹爆炸。 //Prevents errors in the parser's folder traversal when the given path does not exist. @@ -590,14 +590,23 @@ void ProcessProfile(VersionInfo result, string id) if (string.IsNullOrEmpty(oldProfileKey) || oldProfileModel == null) { - LauncherProfileParser.LauncherProfile.Profiles!.Add(gameId, - new GameProfileModel - { - GameDir = gamePath, - LastVersionId = id, - Name = id, - Created = DateTime.Now - }); + var gameProfile = new GameProfileModel + { + GameDir = gamePath, + LastVersionId = id, + Name = id, + Created = DateTime.Now + }; + + if (!string.IsNullOrEmpty(oldProfileKey) && + LauncherProfileParser.LauncherProfile.Profiles!.ContainsKey(oldProfileKey)) + { + LauncherProfileParser.LauncherProfile.Profiles![oldProfileKey] = gameProfile; + LauncherProfileParser.SaveProfile(); + return; + } + + LauncherProfileParser.LauncherProfile.Profiles!.Add(gameId, gameProfile); LauncherProfileParser.SaveProfile(); return; diff --git a/ProjBobcat/ProjBobcat/ProjBobcat.csproj b/ProjBobcat/ProjBobcat/ProjBobcat.csproj index cb8b18c..48b6adb 100644 --- a/ProjBobcat/ProjBobcat/ProjBobcat.csproj +++ b/ProjBobcat/ProjBobcat/ProjBobcat.csproj @@ -73,7 +73,7 @@ resolved the issue that LaunchWrapper may not return the correct exit code - + all