-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMainWindow.xaml.cs
105 lines (96 loc) · 3.52 KB
/
MainWindow.xaml.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
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Forms;
using System.Threading;
namespace SteamAccountSwitcher
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
Steam steam = new Steam();
Thread updateInfoThread;
string accountDir = "accounts";
public void buildMenu()
{
// Current account
if(updateInfoThread != null) updateInfoThread.Abort();
currentUser.Items.Clear();
if (steam.IsAuthorized())
{
currentUser.Items.Add(steam.GetCurrentUser());
// Get avatar & profile name [sync void]
updateInfoThread = new Thread(() => {
steam.UpdateInfo((SteamAccount)currentUser.Items[0]);
Dispatcher.Invoke((Action)(() =>
{
currentUser.Items.Refresh();
}));
});
updateInfoThread.Start();
}
// Other accounts
steamAccounts.Items.Clear();
if (System.IO.Directory.Exists(accountDir))
{
foreach (string subdirectory in System.IO.Directory.GetDirectories(accountDir).Select(System.IO.Path.GetFileName))
{
string profileDir = accountDir + "/" + subdirectory;
string configFile = profileDir + "/account.json";
if (System.IO.File.Exists(configFile))
{
SteamAccount account = JsonConvert.DeserializeObject<SteamAccount>(System.IO.File.ReadAllText(configFile));
account.selected = false;
account.filePath = profileDir;
if (currentUser.Items.Count == 0 || !(((SteamAccount)currentUser.Items[0]).selected && ((SteamAccount)currentUser.Items[0]).username == account.username))
{
steamAccounts.Items.Add(account);
}
}
}
}
}
public MainWindow()
{
InitializeComponent();
steam_path.Text = steam.GetPath();
buildMenu();
}
private void changeDirBtn_Click(object sender, RoutedEventArgs e)
{
var fbd = new FolderBrowserDialog();
fbd.ShowDialog();
if (fbd.SelectedPath != "")
{
steam.SetPath(fbd.SelectedPath);
steam_path.Text = steam.GetPath();
}
}
private void switchBtn_Click(object sender, RoutedEventArgs e)
{
steam.Close();
if (steam.IsAuthorized()) steam.Backup(accountDir);
steam.Logout();
steam.Restore((SteamAccount)steamAccounts.Items[steamAccounts.SelectedIndex]);
steam.Open();
buildMenu();
}
private void newUserBtn_Click(object sender, RoutedEventArgs e)
{
steam.Close();
if (steam.IsAuthorized()) steam.Backup(accountDir);
steam.Logout();
steam.Open();
buildMenu();
}
private void accountsList_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
switchBtn.IsEnabled = steamAccounts.SelectedIndex != -1;
}
}
}