Skip to content

Commit

Permalink
Deleting genres now updates the GamesList.txt and removes that genre …
Browse files Browse the repository at this point in the history
…from all listings
  • Loading branch information
pekempy committed Oct 29, 2018
1 parent 445222d commit f374a7e
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 9 deletions.
10 changes: 10 additions & 0 deletions MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ private void PosterViewActive()
}

private void SettingsButton_OnClick(object sender, RoutedEventArgs e)
{
SettingsViewActive();
}

private void SettingsViewActive()
{
settingsViewModel = new SettingsViewModel();
settingsViewModel.LoadGenres();
Expand Down Expand Up @@ -129,6 +134,11 @@ public void RefreshGames()
Console.WriteLine("Banner");
BannerViewActive();
}
else if (DataContext == settingsViewModel)
{
Console.WriteLine("Settings");
SettingsViewActive();
}
else
{
Console.WriteLine("Nothing");
Expand Down
23 changes: 23 additions & 0 deletions ViewModels/ModifyFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,28 @@ public static void EditGameInfile(object gameGuid)
}
}
}

public static void RemoveGenreFromFile(object genreGuid)
{
genreGuid = genreGuid.ToString();
var text = File.ReadAllLines("./Resources/GenreList.txt", Encoding.UTF8);
for (int i = 0; i < text.Length; i++)
{
if (text[i].Contains($"{genreGuid}"))
{
try
{
text[i] = "";

text = text.Where(x => !string.IsNullOrEmpty(x)).ToArray();
File.WriteAllLines("./Resources/GenreList.txt", text);
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
}
}
}
}
2 changes: 0 additions & 2 deletions ViewModels/PosterViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using GameLauncher.Models;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows.Data;

namespace GameLauncher.ViewModels
{
Expand Down
18 changes: 12 additions & 6 deletions Views/SettingsView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
ScrollViewer.CanContentScroll="True"
Visibility="{Binding Path=IsChecked, ElementName=GenreBtn, Converter={StaticResource b2v}}">
<Grid.RowDefinitions>
<RowDefinition Height="40" />
<RowDefinition Height="60" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
Expand All @@ -135,20 +135,26 @@
VerticalAlignment="Center" />
</Button>
</StackPanel>
<TextBlock Text="Current Genres:" Margin="0 25 0 0" FontWeight="Bold" />
<TextBlock Text="Current Genres:" Margin="0 45 0 0" FontWeight="Bold" />
<ScrollViewer Grid.Row="1" Grid.RowSpan="4" VerticalScrollBarVisibility="auto" HorizontalScrollBarVisibility="Disabled">
<StackPanel>
<!--Need to get the list of current genres to fill this-->
<ItemsControl x:Name="genreListView"
Margin="10 10 0 10"
Margin="0 0 0 10"
ItemsSource="{Binding Source={StaticResource GenreListCVS}}"
ScrollViewer.HorizontalScrollBarVisibility="Disabled">
<ItemsControl.ItemTemplate>
<DataTemplate>
<WrapPanel>
<TextBlock Text="{Binding Name}" Width="180" />
<Button Tag="{Binding Guid}"
HorizontalAlignment="Right"></Button>
<TextBlock Text="{Binding Name}" Width="180" Height="20" VerticalAlignment="Center" HorizontalAlignment="Left" />
<Button Style="{StaticResource MaterialDesignFlatButton}"
Click="DeleteGenre_OnClick"
Tag="{Binding Guid}"
Padding="0 0 0 0"
HorizontalAlignment="Right"
VerticalAlignment="Center">
<materialDesign:PackIcon Kind="Delete" HorizontalAlignment="Right" />
</Button>
</WrapPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
Expand Down
67 changes: 66 additions & 1 deletion Views/SettingsView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@
using System;
using System.Configuration;
using System.IO;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;

namespace GameLauncher.Views
{
public partial class SettingsView : UserControl
{
private MainWindow MainWindow = ((MainWindow)Application.Current.MainWindow);
private LoadAllGames lag = new LoadAllGames();
public string DeletedGenre;

public SettingsView()
{
lag.LoadGenres();
InitializeComponent();
if (Settings.Default.theme == "Dark") { themeToggle.IsChecked = true; }
}
Expand Down Expand Up @@ -48,6 +51,68 @@ private void AddNewGenre_OnClick(object sender, RoutedEventArgs e)
Console.WriteLine("Exception: " + ex.Message);
}
lag.LoadGenres();
MainWindow.RefreshGames();
CollectionViewSource GenreListCVS = (CollectionViewSource)FindResource("GenreListCVS");
if (GenreListCVS != null)
GenreListCVS.View.Refresh();
}

private void DeleteGenre_OnClick(object sender, RoutedEventArgs e)
{
//Code needs to go in here to check each item in Game text file and remove the deleted genre from the record
//1. Look in GenreList.txt to match guid to a "Name"
//2. Search GamesList.txt for match to above name
//3. Replace "$name" with "" + replace " " with " " in case double whitespace
//4. Load Games again

//Check Genre file for the name of the genre to remove
string genreGuid = ((Button)sender).Tag.ToString();
var genretext = File.ReadAllLines("./Resources/GenreList.txt", Encoding.UTF8);
for (int i = 0; i < genretext.Length; i++)
{
if (genretext[i].Contains($"{genreGuid}"))
{
try
{
Console.WriteLine(genretext[i]);
string[] column = genretext[i].Split('|');
DeletedGenre = column[0];
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
}
//Check gameslist, and remove that genre from any listings
var gametext = File.ReadAllLines("./Resources/GamesList.txt", Encoding.UTF8);
for (int i2 = 0; i2 < gametext.Length; i2++)
{
if (gametext[i2].Contains(DeletedGenre))
{
try
{ //This entire section is to remove that genre from any games which contain it.
Console.WriteLine(gametext[i2]);
string[] column = gametext[i2].Split('|');
string genretoedit = column[1];
genretoedit = genretoedit.Replace(DeletedGenre + ";", "");
string gametoeditguid = column[7];
string newGenre = genretoedit.Trim();
string NewGameInfo = column[0] + "|" + newGenre + "|" + column[2] + "|" + column[3] + "|" + column[4] + "|" + column[5] + "|" + column[6] + "|" + Guid.NewGuid();
Console.WriteLine(NewGameInfo);
ModifyFile.RemoveGameFromFile(gametoeditguid);
TextWriter tw = new StreamWriter(@"./Resources/GamesList.txt", true);
tw.WriteLine(NewGameInfo);
tw.Close();
}
catch (Exception ex2)
{
Console.WriteLine(ex2.ToString());
}
}
}
ModifyFile.RemoveGenreFromFile(((Button)sender).Tag);
MainWindow.RefreshGames();
}

public void SaveSettings()
Expand Down

0 comments on commit f374a7e

Please sign in to comment.