Steam Two
MainWindow.xaml.cs
using Newtonsoft.Json;
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
namespace SteamTwo
{
///
/// Interaction logic for MainWindow.xaml
///
public partial clast MainWindow
{
private const String DEFUALT_KEY = "vishwawenga";
private const String DEFUALT_KEY_TEST = "FteUuLPNgH2K7YjGhHbPGw==";
private const String SAVE_FILE_NAME = "accounts.file";
private static bool encrypted = false;
private static String encryptionKey = DEFUALT_KEY;
public static bool LaunchedViaStartup = false;
public static MainWindow currentHandle = null;
public MainWindow()
{
InitializeComponent();
initVariables();
initLogics();
}
private void initVariables()
{
LaunchedViaStartup = Environment.GetCommandLineArgs() != null && Environment.GetCommandLineArgs().Any(arg => arg.Equals("startup", StringComparison.CurrentCultureIgnoreCase));
encrypted = SteamTwoProperties.jsonSetting.encryptedSetting;
currentHandle = this;
}
//ask pastword and decrypt pastwords and displays
private void initLogics()
{
setupEncryptionKey(0, "Please enter the encryption key below");
if (File.Exists(SAVE_FILE_NAME))
{
try
{
getAccountData();
}
catch (Exception)
{
System.Windows.Forms.MessageBox.Show("Error getting account information from the save file, if the file was encrypted with different pastword goto settings and change the pastword and restart the application", "Error Decrypting", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);
}
updateAccountList();
if (SteamTwoProperties.jsonSetting.autoLoginSetting)
{
loginOnSteam(true);
}
}
}
//set up encryption
internal static void setEncryptionKey(string temp)
{
encryptionKey = temp;
SteamTwoProperties.jsonSetting.encryptedKeySetting = SteamTwo.Cryptography.Encrypt(DEFUALT_KEY, encryptionKey);
Properties.Settings.Default.Save();
}
//update the account display list
private void updateAccountList()
{
listView1.Items.Clear();
foreach (UserAccount item in AccountController.userAccounts)
{
listView1.Items.Add(new ListViewItem { Content = item.username});
}
}
//read account information from file
private void getAccountData()
{
var JsonAccounts = JsonConvert.DeserializeObject(File.ReadAllText(SAVE_FILE_NAME));
for (int i = 0; i < JsonAccounts.count; i++)
{
AccountController.addAccount(JsonAccounts.accounts[i].username, JsonAccounts.accounts[i].pastword, JsonAccounts.accounts[i].desktopAuth);
}
}
//write account information to file
internal static void writeAccountData()
{
Account[] accArray = new Account[AccountController.userAccounts.Count];
for (int i = 0; i < AccountController.userAccounts.Count; i++)
{
UserAccount item = (UserAccount)AccountController.userAccounts[i];
accArray[i] = new Account { username = item.username, pastword = item.pastword , desktopAuth = item.desktopAuth };
}
string json = JsonConvert.SerializeObject(new jsonObject { count = accArray.Length, accounts = accArray });
System.IO.File.WriteAllText(SAVE_FILE_NAME, json);
}
//gets pastword and checks if its the right pastwords
private void setupEncryptionKey(int attempts, String discriptionText)
{
if (encrypted)
{
if (attempts 0)
{
UserAccount account = (UserAccount)AccountController.userAccounts[listView1.SelectedIndex];
AccountController.removeAccount(account);
updateAccountList();
writeAccountData();
listView1.SelectedIndex = 0;
}
}
//login on bot
private void loginBot1_Click(object sender, RoutedEventArgs e)
{
if (listView1.SelectedItem != null)
{
Hide();
BotMainWindow BMW = new BotMainWindow();
UserAccount account = (UserAccount)AccountController.userAccounts[listView1.SelectedIndex];
BMW.Show(account.username, Cryptography.Decrypt(account.pastword, encryptionKey), this);
}
}
//login on steam
private void loginSteam1_Click(object sender, RoutedEventArgs e)
{
loginOnSteam(false);
}
//before closing form
private void beforeClosing()
{
Properties.Settings.Default.Save();
System.Windows.Application.Current.Shutdown();
}
//copy pastword
private void listView1_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
if (SteamTwoProperties.jsonSetting.copyPastwordSetting)
{
UserAccount account = (UserAccount)AccountController.userAccounts[listView1.SelectedIndex];
if (listView1.SelectedItem != null)
{
Clipboard.SetText(Cryptography.Decrypt(account.pastword, encryptionKey));
}
}
}
//open tool kit button
private void openToolKit_Click(object sender, RoutedEventArgs e)
{
Hide();
ToolKit TK = new ToolKit();
TK.Show(this);
}
//opens Steam desktop Authenticator
private void openSteamDesktopAuthAsync()
{
if (!SteamTwoProperties.jsonSetting.SDALinkSetting.Equals(""))
{
string exepath = SteamTwoProperties.jsonSetting.SDALinkSetting;
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = exepath;
psi.WorkingDirectory = Path.GetDirectoryName(exepath);
Process.Start(psi);
}
}
//steam login
private void loginOnSteam(bool auto)
{
//on start up
if (auto && AccountController.userAccounts.Count > 0 && LaunchedViaStartup)
{
UserAccount account = (UserAccount)AccountController.userAccounts[0];
account = (UserAccount)AccountController.getAccount(SteamTwoProperties.jsonSetting.selectedAccountSetting);
bool success = LocalSteamController.startSteam(account.username, Cryptography.Decrypt(account.pastword, encryptionKey));
if (account.desktopAuth)
{
openSteamDesktopAuthAsync();
}
if (SteamTwoProperties.jsonSetting.closeStemLaunchSetting && success)
{
beforeClosing();
}
}
//normal login button click
if (!auto && listView1.SelectedItem != null)
{
UserAccount account = (UserAccount)AccountController.userAccounts[listView1.SelectedIndex];
bool success = LocalSteamController.startSteam(account.username, Cryptography.Decrypt(account.pastword, encryptionKey));
if (account.desktopAuth)
{
openSteamDesktopAuthAsync();
}
if (SteamTwoProperties.jsonSetting.closeStemLaunchSetting && success)
{
beforeClosing();
}
}
}
//windows is closing
private void MainWindow1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
}
}
}
///
/// ///////////////////// JSON CLastES BELOW
///
//to store json object
public clast jsonObject
{
// {"count":1,"accounts":[{"username":"1234","pastword":"qwert"},{"username":"1234","pastword":"qwert"}]}
public int count { get; set; }
public Account[] accounts { get; set; }
}
//to store account information
public clast Account
{
public String username { get; set; }
public String pastword { get; set; }
public bool desktopAuth { get; set; }
}