Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 117 additions & 0 deletions src/Starward.Language/Lang.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions src/Starward.Language/Lang.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1782,6 +1782,45 @@ Do you accept the risk and continue to use it?</value>
<data name="StartGameButton_Verify" xml:space="preserve">
<value>Verify</value>
</data>
<data name="StartGameButton_DefaultLaunchOption" xml:space="preserve">
<value>Default</value>
</data>
<data name="StartGameButton_ChooseLaunchOption" xml:space="preserve">
<value>Choose launch option</value>
</data>
<data name="GameLauncherSettingDialog_LaunchOptions" xml:space="preserve">
<value>Launch Options</value>
</data>
<data name="GameLauncherSettingDialog_LaunchOptionsDescription" xml:space="preserve">
<value>Define multiple launch commands, and pick one from the dropdown next to the Start Game button when launching the game.</value>
</data>
<data name="GameLauncherSettingDialog_AddLaunchOption" xml:space="preserve">
<value>Add Launch Option</value>
</data>
<data name="GameLauncherSettingDialog_LaunchOptionName" xml:space="preserve">
<value>Name</value>
</data>
<data name="GameLauncherSettingDialog_LaunchOptionExecutable" xml:space="preserve">
<value>Executable (leave empty to use the game's default executable)</value>
</data>
<data name="GameLauncherSettingDialog_LaunchOptionArguments" xml:space="preserve">
<value>Command Line Arguments</value>
</data>
<data name="GameLauncherSettingDialog_LaunchOptionRunAsAdmin" xml:space="preserve">
<value>Run as administrator</value>
</data>
<data name="GameLauncherSettingDialog_LaunchOptionDefaultTooltip" xml:space="preserve">
<value>Uses the settings above (custom executable + command line arguments).</value>
</data>
<data name="GameLauncherSettingDialog_LaunchOptionMoveUp" xml:space="preserve">
<value>Move up</value>
</data>
<data name="GameLauncherSettingDialog_LaunchOptionMoveDown" xml:space="preserve">
<value>Move down</value>
</data>
<data name="GameLauncherSettingDialog_LaunchOptionNameRequired" xml:space="preserve">
<value>Name is required</value>
</data>
<data name="SettingPage_RPCServiceIsNotRunning" xml:space="preserve">
<value>RPC Service is not Running</value>
</data>
Expand Down
39 changes: 39 additions & 0 deletions src/Starward.Language/Lang.zh-CN.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1782,6 +1782,45 @@
<data name="StartGameButton_Verify" xml:space="preserve">
<value>校验</value>
</data>
<data name="StartGameButton_DefaultLaunchOption" xml:space="preserve">
<value>默认</value>
</data>
<data name="StartGameButton_ChooseLaunchOption" xml:space="preserve">
<value>选择启动方式</value>
</data>
<data name="GameLauncherSettingDialog_LaunchOptions" xml:space="preserve">
<value>启动方式</value>
</data>
<data name="GameLauncherSettingDialog_LaunchOptionsDescription" xml:space="preserve">
<value>可以定义多个启动命令行,启动游戏时在“开始游戏”按钮旁的下拉菜单中选择。</value>
</data>
<data name="GameLauncherSettingDialog_AddLaunchOption" xml:space="preserve">
<value>添加启动方式</value>
</data>
<data name="GameLauncherSettingDialog_LaunchOptionName" xml:space="preserve">
<value>名称</value>
</data>
<data name="GameLauncherSettingDialog_LaunchOptionExecutable" xml:space="preserve">
<value>启动程序(留空则使用游戏本体的默认启动程序)</value>
</data>
<data name="GameLauncherSettingDialog_LaunchOptionArguments" xml:space="preserve">
<value>命令行参数</value>
</data>
<data name="GameLauncherSettingDialog_LaunchOptionRunAsAdmin" xml:space="preserve">
<value>以管理员身份运行</value>
</data>
<data name="GameLauncherSettingDialog_LaunchOptionDefaultTooltip" xml:space="preserve">
<value>使用上方设置项(自定义启动程序 + 命令行参数)。</value>
</data>
<data name="GameLauncherSettingDialog_LaunchOptionMoveUp" xml:space="preserve">
<value>上移</value>
</data>
<data name="GameLauncherSettingDialog_LaunchOptionMoveDown" xml:space="preserve">
<value>下移</value>
</data>
<data name="GameLauncherSettingDialog_LaunchOptionNameRequired" xml:space="preserve">
<value>名称不能为空</value>
</data>
<data name="SettingPage_RPCServiceIsNotRunning" xml:space="preserve">
<value>RPC 服务未运行</value>
</data>
Expand Down
35 changes: 35 additions & 0 deletions src/Starward/AppConfig.Setting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,41 @@ public static void SetEnableDX12(GameBiz biz, bool value)
}


/// <summary>
/// 自定义启动预设列表(JSON 序列化的 <see cref="Features.GameLauncher.GameLaunchScheme"/> 数组),
/// 参考 <see href="https://github.com/Scighost/Starward/issues/1858"/>
/// </summary>
public static string? GetLaunchSchemes(GameBiz biz)
{
return GetValue<string>(default, $"launch_schemes_{biz}");
}

/// <summary>
/// 自定义启动预设列表(JSON 序列化的 <see cref="Features.GameLauncher.GameLaunchScheme"/> 数组)
/// </summary>
public static void SetLaunchSchemes(GameBiz biz, string? value)
{
SetValue(value, $"launch_schemes_{biz}");
}


/// <summary>
/// 最近选择的启动预设 Id,为空或匹配 <see cref="Features.GameLauncher.GameLaunchScheme.BuiltInDefaultId"/> 表示使用内置默认预设
/// </summary>
public static string? GetSelectedLaunchSchemeId(GameBiz biz)
{
return GetValue<string>(default, $"selected_launch_scheme_{biz}");
}

/// <summary>
/// 最近选择的启动预设 Id
/// </summary>
public static void SetSelectedLaunchSchemeId(GameBiz biz, string? value)
{
SetValue(value, $"selected_launch_scheme_{biz}");
}


#endregion


Expand Down
117 changes: 117 additions & 0 deletions src/Starward/Features/GameLauncher/GameLaunchScheme.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
using System;
using System.Collections.Generic;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Starward.Features.GameLauncher;


/// <summary>
/// 自定义启动预设。用户可以定义多个启动命令行,例如通过 FPS Unlocker、脚本等方式启动游戏。
/// 参考 <see href="https://github.com/Scighost/Starward/issues/1858"/>
/// </summary>
public sealed class GameLaunchScheme
{

/// <summary>
/// 唯一标识
/// </summary>
public string Id { get; set; } = Guid.NewGuid().ToString("N");


/// <summary>
/// 显示名称
/// </summary>
public string Name { get; set; } = string.Empty;


/// <summary>
/// 启动程序的完整路径。为空时使用游戏本体的默认启动程序。
/// </summary>
public string? ExecutablePath { get; set; }


/// <summary>
/// 附加的命令行参数。
/// </summary>
public string? Arguments { get; set; }


/// <summary>
/// 需要以管理员权限运行。仅当 <see cref="ExecutablePath"/> 为 .exe 或 .bat 时有效。
/// </summary>
public bool RunAsAdmin { get; set; }


/// <summary>
/// 是否是默认(内置)预设。内置预设不可删除,且始终采用当前设置页的 “自定义启动程序” 与 “命令行参数” 值。
/// </summary>
[JsonIgnore]
public bool IsBuiltIn { get; set; }


/// <summary>
/// 内置默认预设 Id
/// </summary>
public const string BuiltInDefaultId = "__default__";


public GameLaunchScheme Clone()
{
return new GameLaunchScheme
{
Id = Id,
Name = Name,
ExecutablePath = ExecutablePath,
Arguments = Arguments,
RunAsAdmin = RunAsAdmin,
IsBuiltIn = IsBuiltIn,
};
}


internal static List<GameLaunchScheme> Deserialize(string? json)
{
if (string.IsNullOrWhiteSpace(json))
{
return new List<GameLaunchScheme>();
}
try
{
List<GameLaunchScheme>? list = JsonSerializer.Deserialize<List<GameLaunchScheme>>(json);
if (list is null)
{
return new List<GameLaunchScheme>();
}
for (int i = list.Count - 1; i >= 0; i--)
{
GameLaunchScheme item = list[i];
if (string.IsNullOrEmpty(item.Id))
{
item.Id = Guid.NewGuid().ToString("N");
}
// 用户不能通过配置构造出内置预设
if (item.Id == BuiltInDefaultId)
{
list.RemoveAt(i);
}
}
return list;
}
catch
{
return new List<GameLaunchScheme>();
}
}


internal static string? Serialize(List<GameLaunchScheme>? list)
{
if (list is null || list.Count == 0)
{
return null;
}
return JsonSerializer.Serialize(list, AppConfig.JsonSerializerOptions);
}

}
1 change: 1 addition & 0 deletions src/Starward/Features/GameLauncher/GameLauncherPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@
HorizontalAlignment="Right"
GameCommand="{x:Bind ClickStartGameButtonCommand}"
GameState="{x:Bind GameState}"
LaunchOptionSelected="Button_StartGame_LaunchOptionSelected"
RunningGameInfo="{x:Bind RunningGameInfo}"
SettingCommand="{x:Bind OpenGameLauncherSettingDialogCommand}" />

Expand Down
Loading