Skip to content
Draft
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
69 changes: 50 additions & 19 deletions Application/OasisBot/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public class CommandLineOptions
[Option('p', "profile", Required = false, HelpText = "Set the profile name to use.")]
public string Profile { get; set; }

[Option('a', "account", Required = false, HelpText = "Set the account name to use.")]
public string Account { get; set; }

[Option("launch-client", Required = false, HelpText = "Start with client")]
public bool LaunchClient { get; set; }

Expand All @@ -50,25 +53,43 @@ public class CommandLineOptions

[Option("headless", Required = false, HelpText = "Start the bot without graphical user interface")]
public bool Headless { get; set; }

[Option('h', "help", Required = false, HelpText = "Show help message.")]
public bool Help { get; set; }
}

private static void DisplayHelp(ParserResult<CommandLineOptions> result)
{
var helpText = HelpText.AutoBuild(
result,
h =>
{
h.AdditionalNewLineAfterOption = false;
h.AddDashesToOption = true;
return HelpText.DefaultParsingErrorsHandler(result, h);
}
var helpText = new HelpText
{
Heading = new HeadingInfo(AssemblyTitle, AssemblyVersion),
AdditionalNewLineAfterOption = false,
AddDashesToOption = true,
};
helpText.AddPreOptionsLine(
"Copyright (C) 2017-2021 ngoedde; 2021-2026 RSBot Team; 2026 Silkroad Developer Community"
);
helpText.AddOptions(result);

var lines = helpText.ToString().Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);
var filteredLines = lines.Where(line =>
!line.TrimStart().StartsWith("--help") && !line.TrimStart().StartsWith("--version")
);
Console.WriteLine(helpText);

Console.WriteLine(string.Join(Environment.NewLine, filteredLines));
}

[STAThread]
private static void Main(string[] args)
{
// 1. Initialize configuration and run migrations as early as possible
RSBot.Core.Config.Initialize();
if (RSBot.Core.Config.MigrationTriggered)
{
System.Diagnostics.Process.Start(Environment.ProcessPath, args);
Environment.Exit(0);
}

var parser = new Parser(with => with.HelpWriter = null);
var parserResult = parser.ParseArguments<CommandLineOptions>(args);

Expand All @@ -77,16 +98,19 @@ private static void Main(string[] args)
parserResult
.WithParsed(options =>
{
if (options.Help)
{
DisplayHelp(parserResult);
Environment.Exit(0);
}

RunOptions(options);
isHeadless = options.Headless;
})
.WithNotParsed(errs =>
{
DisplayHelp(parserResult);
var isHelp = errs.Any(e =>
e.Tag == ErrorType.HelpRequestedError || e.Tag == ErrorType.VersionRequestedError
);
Environment.Exit(isHelp ? 0 : 1);
Environment.Exit(1);
});

//CultureInfo.CurrentCulture = CultureInfo.InvariantCulture;
Expand Down Expand Up @@ -174,13 +198,20 @@ private static void RunOptions(CommandLineOptions options)

ProfileManager.IsProfileLoadedByArgs = true;
Log.Debug($"Selected profile by args: {profile}");
}

if (!string.IsNullOrEmpty(options.Character))
{
var character = options.Character;
ProfileManager.SelectedCharacter = character;
Log.Debug($"Selected character by args: {character}");
if (!string.IsNullOrEmpty(options.Account))
{
var account = options.Account;
ProfileManager.SelectedAccount = account;
Log.Debug($"Selected account by args: {account}");

if (!string.IsNullOrEmpty(options.Character))
{
var character = options.Character;
ProfileManager.SelectedCharacter = character;
Log.Debug($"Selected character by args: {character}");
}
}
}
}
}

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

23 changes: 2 additions & 21 deletions Application/OasisBot/Views/Dialog/ProfileSelectionDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public ProfileSelectionDialog()
InitializeComponent();

LoadProfiles();
checkSaveSelection.Checked = !ProfileManager.ShowProfileDialog;
BackColor = ColorScheme.BackColor;
}

Expand Down Expand Up @@ -70,8 +69,8 @@ private string CreateNewProfile()
return string.Empty;
}

string[] reservedNames = { "Profiles", "Default", "Settings" };
if (reservedNames.Any(n => n.Equals(profile, StringComparison.InvariantCultureIgnoreCase)))
string[] reservedNames = { "Settings", "Logs" };
if (reservedNames.Any(n => n.Equals(profile, StringComparison.OrdinalIgnoreCase)))
{
MessageBox.Show(
$"The name '{profile}' is reserved and cannot be used!",
Expand Down Expand Up @@ -101,26 +100,8 @@ private void comboProfiles_SelectedIndexChanged(object sender, EventArgs e)
SelectedProfile = (string)comboProfiles.SelectedItem;
}

private void checkSaveSelection_CheckedChanged(object sender, EventArgs e)
{
ProfileManager.ShowProfileDialog = !checkSaveSelection.Checked;
}

private void buttonDeleteProfile_Click(object sender, EventArgs e)
{
var selectedProfile = (string)comboProfiles.SelectedItem;
if (selectedProfile == "Default") //Default
{
MessageBox.Show(
"You can not delete the default profile!",
"Default profile",
MessageBoxButtons.OK,
MessageBoxIcon.Error
);

return;
}

if (ProfileManager.SelectedProfile == (string)comboProfiles.SelectedItem) //Active profile?
{
MessageBox.Show(
Expand Down
Loading
Loading