forked from michaelmob/steam_account_manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathform_main.cs
144 lines (116 loc) · 3.61 KB
/
form_main.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
using System;
using System.IO;
using System.Diagnostics;
using System.Windows.Forms;
namespace Steam_Account_Manager
{
public partial class form_main : Form
{
public form_main()
{
InitializeComponent();
}
string find_steam_location() {
foreach (Process Proc in Process.GetProcessesByName("Steam"))
{
string fullpath = Proc.MainModule.FileName;
return fullpath;
}
return null;
}
string base64_encode(string str) {
return Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(str));
}
string base64_decode(string str) {
return System.Text.Encoding.UTF8.GetString(Convert.FromBase64String(str));
}
void kill_steam() {
try {
Process[] proc = Process.GetProcessesByName("Steam");
proc[0].Kill();
} catch { }
}
void login_steam(string steam_location, string username, string password) {
Process.Start(steam_location, " -login " + username + " " + base64_decode(password));
}
void write_settings() {
string output = "";
foreach(ListViewItem item in list_accounts.Items) {
for(int i = 0; i < item.SubItems.Count; i++)
output += item.SubItems[i].Text.Replace("|", "/") + "|";
output += Environment.NewLine;
}
File.WriteAllText("save.dat", output);
}
void read_settings() {
if(!File.Exists("save.dat"))
return;
var file = new StreamReader("save.dat");
string line;
while((line = file.ReadLine()) != null)
{
string[] data = line.Split('|');
var item = new ListViewItem(data);
list_accounts.Items.Add(item);
}
file.Close();
}
void MainFormLoad(object sender, System.EventArgs e)
{
read_settings();
Button_get_steam_processClick(sender, e);
}
void LoginToolStripMenuItemClick(object sender, System.EventArgs e)
{
if(list_accounts.SelectedItems.Count == 1) {
list_accounts.SelectedItems[0].SubItems[2].Text = DateTime.Now.ToString("dd/MM/yyyy");
kill_steam();
login_steam(text_steam_location.Text, list_accounts.SelectedItems[0].SubItems[0].Text, list_accounts.SelectedItems[0].SubItems[1].Text);
}
write_settings();
}
void Button_get_steam_processClick(object sender, System.EventArgs e)
{
string steam_location = find_steam_location();
if(steam_location != null)
text_steam_location.Text = steam_location;
else
MessageBox.Show("Steam is not running.", "Error");
}
void AddAccountToolStripMenuItemClick(object sender, System.EventArgs e)
{
var form_account = new form_account();
if (form_account.ShowDialog(this) == DialogResult.OK) {
string[] row = { form_account.username, base64_encode(form_account.password), "", "" };
var item = new ListViewItem(row);
list_accounts.Items.Add(item);
write_settings();
}
}
void DeleteToolStripMenuItemClick(object sender, System.EventArgs e)
{
foreach(ListViewItem item in list_accounts.SelectedItems) {
item.Remove();
}
write_settings();
}
void NotesToolStripMenuItemClick(object sender, System.EventArgs e)
{
if(list_accounts.SelectedItems.Count == 1) {
var form_notes = new form_notes(list_accounts.SelectedItems[0].SubItems[3].Text);
if (form_notes.ShowDialog(this) == DialogResult.OK) {
list_accounts.SelectedItems[0].SubItems[3].Text = form_notes.notes;
}
}
write_settings();
}
void ShutdownSteamToolStripMenuItemClick(object sender, System.EventArgs e)
{
kill_steam();
}
void Link_githubLinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
{
Process.Start("https://github.com/TheTarkus");
}
}
}