Skip to content

Commit

Permalink
Add settings:
Browse files Browse the repository at this point in the history
- Changing account file location
- Changing encryption key
- Copying plain text data to clipboard
  • Loading branch information
MELVARDEV committed May 25, 2021
1 parent 368dec1 commit 27a1ea1
Show file tree
Hide file tree
Showing 2 changed files with 146 additions and 16 deletions.
46 changes: 35 additions & 11 deletions League Pass Manager/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,45 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:League_Pass_Manager"
FocusManager.FocusedElement="{Binding ElementName=encryptionKey}"
mc:Ignorable="d"

Title="League Pass Manager" Height="103" Width="409" MinWidth="300" MinHeight="130" WindowStartupLocation="CenterScreen" Icon="/internet_lock_locked_padlock_password_secure_security_icon_127100.ico">
Title="League Pass Manager" Height="306" Width="409" MinWidth="300" MinHeight="130" WindowStartupLocation="CenterScreen" Icon="/internet_lock_locked_padlock_password_secure_security_icon_127100.ico">
<Grid>
<Grid Visibility="Hidden" x:Name="mainGrid" >
<Button Content="Fill" Margin="10,38,113,8" Click="Button_Click" RenderTransformOrigin="0.5,1" VerticalAlignment="Bottom" Height="40"/>
<DataGrid x:Name="datagrid1" Margin="0,0,0,59" AutoGenerateColumns="True" ItemsSource="{Binding Path=accounts, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" CellEditEnding="datagrid1_CellEditEnding" GridLinesVisibility="All" RowEditEnding="datagrid1_RowEditEnding" CurrentCellChanged="datagrid1_CurrentCellChanged" >
<DataGrid.Columns>

</DataGrid.Columns>
</DataGrid>
<Button Content="Remove" HorizontalAlignment="Right" Margin="0,0,10,8" VerticalAlignment="Bottom" Height="40" Width="98" Click="Button_Click_1"/>
<Grid x:Name="mainGrid" >
<TabControl mah:HeaderedControlHelper.HeaderFontSize="16" mah:TabControlHelper.Underlined="TabPanel" Padding="0,2,0,0" Margin="-1,0,-1,0" >
<TabItem Header="Accounts" HorizontalAlignment="Center" Height="28" VerticalAlignment="Center" Width="79" Padding="6,2,6,2">
<Grid>
<Separator VerticalAlignment="Top" />
<Button Content="Fill" Margin="10,38,113,8" Click="Button_Click" RenderTransformOrigin="0.5,1" VerticalAlignment="Bottom" Height="40"/>
<DataGrid x:Name="datagrid1" Margin="0,0,0,59" AutoGenerateColumns="True" ItemsSource="{Binding Path=accounts, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" CellEditEnding="datagrid1_CellEditEnding" GridLinesVisibility="None" RowEditEnding="datagrid1_RowEditEnding" CurrentCellChanged="datagrid1_CurrentCellChanged" BorderBrush="Transparent" VerticalGridLinesBrush="#337E7E7E" HorizontalGridLinesBrush="#337E7E7E" HeadersVisibility="Column" Foreground="#E5FFFFFF" >
<DataGrid.Columns>

</DataGrid.Columns>
</DataGrid>
<Button Content="Remove" HorizontalAlignment="Right" Margin="0,0,10,8" VerticalAlignment="Bottom" Height="40" Width="98" Click="Button_Click_1"/>

</Grid>
</TabItem>
<TabItem Header="Options" HorizontalAlignment="Center" Height="28" VerticalAlignment="Center" Width="68">
<Grid>
<StackPanel HorizontalAlignment="Left" Width="196" Margin="6,7,0,0">
<Button Content="Change password file location" Height="28" Click="Button_Click_3"/>
<Button x:Name="copyDataToClipboardBtn" Content="Copy data to clipboard" Margin="0,6,0,0" Click="copyDataToClipboardBtn_Click"/>
<Button Content="Change encryption key " Margin="0,6,0,0" Click="Button_Click_2"/>
</StackPanel>
<StackPanel HorizontalAlignment="Stretch" Margin="215,7,8,0">
<TextBox x:Name="passFileLocation" Text="" TextWrapping="Wrap" HorizontalAlignment="Stretch" IsReadOnly="True" Height="28" TextChanged="passFileLocation_TextChanged" />
<TextBox x:Name="newEncryptionKey" Text="" TextWrapping="Wrap" Margin="0,39,0,0" Height="27.3" HorizontalAlignment="Stretch" mah:TextBoxHelper.Watermark="New encryption key..."/>
</StackPanel>

</Grid>
</TabItem>
</TabControl>

</Grid>
<Grid x:Name="passwordPromptGrid">
<PasswordBox x:Name="encryptionKey" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Margin="33,0,33,57" mah:TextBoxHelper.Watermark="Encryption Key"/>
<Grid Visibility="Hidden" x:Name="passwordPromptGrid">
<PasswordBox x:Name="encryptionKey" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Margin="16,0,16,57" mah:TextBoxHelper.Watermark="Encryption Key"/>
<Button x:Name="unlockButton" Content="Unlock" Margin="16,0,16,17" VerticalAlignment="Bottom" Click="unlockButton_Click" IsDefault="True"/>

</Grid>
Expand Down
116 changes: 111 additions & 5 deletions League Pass Manager/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using Rijndael256;
using System.IO;
using System.ComponentModel;
using Microsoft.Win32;

namespace League_Pass_Manager
{
Expand Down Expand Up @@ -51,6 +52,11 @@ public partial class MainWindow : MetroWindow
[DllImport("user32.dll")]
public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);

public class Settings
{
public string filePath { get; set; } = "accounts.txt";
}

public class Account
{
public string region { get; set; }
Expand All @@ -59,22 +65,29 @@ public class Account
public string password { get; set; }
}

public Settings settings = new Settings();

public List<Account> accounts = new List<Account>();
string password;

void saveAccounts(string password)
{
string jsonList = JsonConvert.SerializeObject(accounts);
string aeCiphertext = RijndaelEtM.Encrypt(jsonList, password, KeySize.Aes256);
File.WriteAllText("accounts.txt", aeCiphertext);
try { File.WriteAllText(settings.filePath, aeCiphertext); }
catch(System.UnauthorizedAccessException ex)
{
MessageBox.Show("You dont have permission to write to " + settings.filePath + Environment.NewLine + "Change account file location in settings or launch the app as an administrator.");
}

}

bool readAccounts()
{
string jsonString = "";
try
{
jsonString = File.ReadAllText("accounts.txt");
jsonString = File.ReadAllText(settings.filePath);
} catch(Exception e)
{
MessageBox.Show("Account file doesn't exist yet and will be created now. Double check your encryption key and memorize it or write it down. You won't be able to access your account data without it!" + Environment.NewLine + Environment.NewLine + "Your encryption key: " + password, "WARNING", MessageBoxButton.OK, MessageBoxImage.Exclamation);
Expand Down Expand Up @@ -102,9 +115,43 @@ bool readAccounts()
return true;
}

public void saveSettings()
{
File.WriteAllText("settings.json", JsonConvert.SerializeObject(settings));
}

public void loadSettings()
{
string settingsJson = "";

try
{

settingsJson = File.ReadAllText("settings.json");
settings = JsonConvert.DeserializeObject<Settings>(settingsJson);
}
catch(Exception e)
{
saveSettings();
settingsJson = File.ReadAllText("settings.json");
settings = JsonConvert.DeserializeObject<Settings>(settingsJson);

}
}


public MainWindow()
{
InitializeComponent();
mainGrid.Visibility = Visibility.Hidden;
passwordPromptGrid.Visibility = Visibility.Visible;
Application.Current.MainWindow.Height = 103;
Application.Current.MainWindow.Width = 300;


//settings.filePath = "accounts.txt";
loadSettings();
passFileLocation.Text = settings.filePath;
}

private void Button_Click(object sender, RoutedEventArgs e)
Expand All @@ -116,7 +163,7 @@ private void Button_Click(object sender, RoutedEventArgs e)
if (pr.ProcessName == "RiotClientUx")
{
hWnd = pr.MainWindowHandle;
ShowWindow(hWnd, 3);
//ShowWindow(hWnd, 3);
SetForegroundWindow(hWnd);
var inputSimulator = new InputSimulator();
Account selectedAccount = new Account();
Expand All @@ -132,9 +179,9 @@ private void Button_Click(object sender, RoutedEventArgs e)
Account result = accounts.Find(x => x.userName == selectedAccount.userName);

inputSimulator.Keyboard.TextEntry(result.userName);
inputSimulator.Keyboard.KeyDown((VirtualKeyCode.TAB));
inputSimulator.Keyboard.KeyPress((VirtualKeyCode.TAB));
inputSimulator.Keyboard.TextEntry(result.password);
inputSimulator.Keyboard.KeyDown((VirtualKeyCode.RETURN));
inputSimulator.Keyboard.KeyPress((VirtualKeyCode.RETURN));
}
}
}
Expand All @@ -156,6 +203,7 @@ private void unlockButton_Click(object sender, RoutedEventArgs e)
datagrid1.Items.Refresh();
passwordPromptGrid.Visibility = Visibility.Hidden;
Application.Current.MainWindow.Height = 400;
Application.Current.MainWindow.Width = 450;

mainGrid.Visibility = Visibility.Visible;
}
Expand Down Expand Up @@ -190,5 +238,63 @@ private void datagrid1_CurrentCellChanged(object sender, EventArgs e)
{
saveAccounts(password);
}

private void copyDataToClipboardBtn_Click(object sender, RoutedEventArgs e)
{
if (MessageBox.Show("Are you sure you want to copy all data in PLAIN TEXT to the clipboard?","Warning", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
{
string jsonString = JsonConvert.SerializeObject(accounts);

Clipboard.SetText(jsonString);
MessageBox.Show("Data copied to clipboard.");
}
}


// Change encryption key
private void Button_Click_2(object sender, RoutedEventArgs e)
{
if (String.IsNullOrWhiteSpace(newEncryptionKey.Text))
{
MessageBox.Show("New encryption key input is empty. Please enter new encryption key!");
return;
} else
{
password = newEncryptionKey.Text;
saveAccounts(password);
newEncryptionKey.Text = "";
MessageBox.Show("Encryption key changed successfully.");
}
}

//Change pass file directory
private void Button_Click_3(object sender, RoutedEventArgs e)
{

SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.AddExtension = true;
saveFileDialog.DefaultExt = "txt";
saveFileDialog.Filter = "Text file (*.txt)|*.txt";
if (saveFileDialog.ShowDialog() == true)
{
try
{
File.Move(settings.filePath, saveFileDialog.FileName);
} catch (Exception excep)
{

}
settings.filePath = saveFileDialog.FileName;
passFileLocation.Text = saveFileDialog.FileName;
saveSettings();

MessageBox.Show("New path saved.");
}
}

private void passFileLocation_TextChanged(object sender, TextChangedEventArgs e)
{

}
}
}

0 comments on commit 27a1ea1

Please sign in to comment.