Skip to content

Commit

Permalink
improve url protocol method
Browse files Browse the repository at this point in the history
  • Loading branch information
Scighost committed Oct 25, 2023
1 parent aa754b3 commit 3148189
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
12 changes: 10 additions & 2 deletions src/Starward/Services/GameService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ 12 or 22 or (>= 32 and <= 36) => GameRegistry.MIHOYOSDK_ADL_PROD_OVERSEA_h115894
/// 启动游戏
/// </summary>
/// <returns></returns>
public Process? StartGame(GameBiz biz, bool ignoreRunningGame = false)
public Process? StartGame(GameBiz biz, bool ignoreRunningGame = false, string? installPath = null)
{
const int ERROR_CANCELLED = 0x000004C7;
try
Expand All @@ -253,7 +253,15 @@ 12 or 22 or (>= 32 and <= 36) => GameRegistry.MIHOYOSDK_ADL_PROD_OVERSEA_h115894
}
}
string? exe = null, arg = null, verb = null;
if (AppConfig.GetEnableThirdPartyTool(biz))
if (Directory.Exists(installPath))
{
var e = Path.Join(installPath, GetGameExeName(biz));
if (File.Exists(e))
{
exe = e;
}
}
if (string.IsNullOrWhiteSpace(exe) && AppConfig.GetEnableThirdPartyTool(biz))
{
exe = AppConfig.GetThirdPartyToolPath(biz);
if (File.Exists(exe))
Expand Down
19 changes: 17 additions & 2 deletions src/Starward/Services/UrlProtocolService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,16 @@ public static async Task<bool> HandleUrlProtocolAsync(string url)
}
if (string.IsNullOrWhiteSpace(AppConfig.UserDataFolder))
{
throw new ArgumentNullException("UserDataFolder is null");
log.LogWarning("UserDataFolder is null");
return false;
}
if (uri.Host is "startgame")
{
if (Enum.TryParse(uri.AbsolutePath.Trim('/'), out GameBiz biz))
{
var kvs = HttpUtility.ParseQueryString(uri.Query);
string? uidStr = kvs["uid"];
string? installPath = kvs["install_path"];
var gameService = AppConfig.GetService<GameService>();
if (int.TryParse(uidStr, out int uid))
{
Expand All @@ -81,7 +83,7 @@ public static async Task<bool> HandleUrlProtocolAsync(string url)
{
log.LogWarning("Cannot parse the uid '{uid}'", uidStr);
}
var p = gameService.StartGame(biz);
var p = gameService.StartGame(biz, false, installPath);
if (p != null)
{
await AppConfig.GetService<PlayTimeService>().StartProcessToLogAsync(biz);
Expand All @@ -93,6 +95,19 @@ public static async Task<bool> HandleUrlProtocolAsync(string url)
}
return true;
}
if (uri.Host is "playtime")
{
if (Enum.TryParse(uri.AbsolutePath.Trim('/'), out GameBiz biz))
{
var kvs = HttpUtility.ParseQueryString(uri.Query);
await AppConfig.GetService<PlayTimeService>().StartProcessToLogAsync(biz);
}
else
{
throw new ArgumentException($"Cannot parse the game biz '{uri.AbsolutePath.Trim('/')}'");
}
return true;
}
}
}
catch (Exception ex)
Expand Down

0 comments on commit 3148189

Please sign in to comment.