This repository has been archived by the owner on Oct 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProgram.cs
108 lines (87 loc) · 3.45 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
using System;
using System.Linq;
using SteamSwitcher.Database;
using SteamSwitcher.Models;
namespace SteamSwitcher
{
class Program
{
static void Main()
{
var liteDatabaseService = new LiteDatabaseService(new LiteDatabaseSettings("user.db", "users"));
for (;;)
{
Console.WriteLine("Steam Account Switcher");
Console.WriteLine("Available commands: quit, select, new, delete");
Console.WriteLine("Usage: q - quit programm, s - select ID, n - create USERNAME HINT, d - remove ID");
Console.WriteLine("Examples: s 1, n TheBottle main, d 1\n");
var savedUsers = liteDatabaseService.FindAll();
if (savedUsers != null && savedUsers.Any())
{
Console.WriteLine("Available users in database:");
foreach (var user in savedUsers)
{
Console.WriteLine($"{user.Id}) {user.Name} ({user.Hint})");
}
Console.Write("\n");
}
else
{
Console.WriteLine("No users in database, type n for creating any one\n");
}
var inputCommand = Console.ReadLine();
if (!string.IsNullOrEmpty(inputCommand))
{
var inputSplitted = inputCommand.Split();
ProcessCommand(liteDatabaseService, inputSplitted);
}
Console.Clear();
}
}
static void ProcessCommand(IDatabaseService databaseService, string[] input)
{
switch (input[0])
{
case "q":
{
Environment.Exit(0);
break;
}
case "s":
{
string userId = input.Length > 1 ? input[1] : string.Empty;
if (!string.IsNullOrEmpty(userId) && int.TryParse(userId, out int id))
{
Console.WriteLine($"Selecting user with ID: {id}");
var user = databaseService.FindById(id);
Steam.Kill();
Steam.RegistryEdit(user.Name);
Steam.Start();
}
break;
}
case "n":
{
var userName = input.Length > 1 ? input[1] : string.Empty;
var hint = input.Length > 2 ? input[2] : string.Empty;
if (!string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(hint))
{
Console.WriteLine($"Creating user with username: {userName}");
databaseService.Insert(new SteamUser {Name = userName, Hint = hint});
}
break;
}
case "d":
{
string userId = input.Length > 1 ? input[1] : string.Empty;
if (!string.IsNullOrEmpty(userId) && int.TryParse(userId, out int id))
{
Console.WriteLine($"Removing user with ID: {id}");
databaseService.Delete(id);
}
break;
}
}
}
}
}