Skip to content

Commit

Permalink
Add Profile System
Browse files Browse the repository at this point in the history
  • Loading branch information
Elaviers committed Apr 29, 2019
1 parent 6aa80a9 commit 0c2cced
Show file tree
Hide file tree
Showing 13 changed files with 501 additions and 25 deletions.
22 changes: 22 additions & 0 deletions GCManager/GCManager.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="Profile.cs" />
<Compile Include="JobEntry.xaml.cs">
<DependentUpon>JobEntry.xaml</DependentUpon>
</Compile>
Expand All @@ -96,6 +97,15 @@
<Compile Include="ModListOnline.cs" />
<Compile Include="ModManager.cs" />
<Compile Include="OnlineManifest.cs" />
<Compile Include="ProfileLoadWindow.xaml.cs">
<DependentUpon>ProfileLoadWindow.xaml</DependentUpon>
</Compile>
<Compile Include="ProfileManager.xaml.cs">
<DependentUpon>ProfileManager.xaml</DependentUpon>
</Compile>
<Compile Include="ProfileCreateWindow.xaml.cs">
<DependentUpon>ProfileCreateWindow.xaml</DependentUpon>
</Compile>
<Compile Include="Utility.cs" />
<Compile Include="Version.cs" />
<Page Include="JobEntry.xaml">
Expand Down Expand Up @@ -126,6 +136,18 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="ProfileLoadWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="ProfileManager.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="ProfileCreateWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<Compile Include="ModInstallWindow.xaml.cs">
Expand Down
12 changes: 7 additions & 5 deletions GCManager/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<Grid.RowDefinitions>
<RowDefinition Height="120"/>
<RowDefinition/>
<RowDefinition Height="78"/>
<RowDefinition Height="100"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
Expand All @@ -56,11 +56,13 @@
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Button Content="Launch Risk of Rain 2" Grid.ColumnSpan="2" Grid.Row="2" Click="Launch_Click" Foreground="#FF006D8D" FontWeight="Bold" Grid.Column="1" Background="#FFC3FCFF"/>
<Button Content="Open download folder" Grid.Row="1" Grid.Column="1" Click="OpenDownloads_Click" Grid.ColumnSpan="2"/>
<Button Content="Update all mods" Grid.Row="1" Click="UpdateMods_Click"/>
<Button Content="Uninstall and delete all mods" Grid.Row="2" Click="DeleteMods_Click"/>
<Button Content="Launch Risk of Rain 2" Grid.ColumnSpan="2" Grid.Row="3" Click="Launch_Click" Foreground="#FF006D8D" FontWeight="Bold" Grid.Column="1" Background="#FFC3FCFF"/>
<Button Content="Open Profile Manager" Grid.Row="1" Grid.ColumnSpan="3" Click="OpenProfileManager_Click"/>
<Button Content="Open download folder" Grid.Row="2" Grid.Column="1" Click="OpenDownloads_Click" Grid.ColumnSpan="2"/>
<Button Content="Update all mods" Grid.Row="2" Click="UpdateMods_Click"/>
<Button Content="Uninstall and delete all mods" Grid.Row="3" Click="DeleteMods_Click"/>
<Button Content="Change Game Directory" Grid.Column="2" HorizontalAlignment="Right" Click="ChangeGameDir_Click"/>

<Viewbox Grid.ColumnSpan="2" Margin="5,0">
Expand Down
9 changes: 9 additions & 0 deletions GCManager/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public partial class MainWindow : Window
ModListOnline onlineModList = new ModListOnline();
ModListDownloaded downloadedModList = new ModListDownloaded();

ProfileManager profileManager;
public MainWindow()
{
InitializeComponent();
Expand Down Expand Up @@ -71,5 +72,13 @@ private void ChangeGameDir_Click(object sender, RoutedEventArgs e)
inst.Save();
}
}

private void OpenProfileManager_Click(object sender, RoutedEventArgs e)
{
if (profileManager == null || profileManager.isClosed)
profileManager = new ProfileManager();

profileManager.Show();
}
}
}
14 changes: 10 additions & 4 deletions GCManager/ManagerInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ public class ManagerInfo
private static ManagerInfo _instance = null;

public string installDir = null;
public string DownloadDirectory = null;
public string DownloadDirectory = "Downloads";
public string ProfileDirectory = "Profiles";

public static string GetConfigFileName()
{
Expand All @@ -22,6 +23,11 @@ public string GetFullDownloadDirectory()
return Path.Combine(AppDomain.CurrentDomain.BaseDirectory, this.DownloadDirectory);
}

public string GetFullProfileDirectory()
{
return Path.Combine(AppDomain.CurrentDomain.BaseDirectory, this.ProfileDirectory);
}

public static ManagerInfo Get()
{
if (_instance == null)
Expand All @@ -48,15 +54,15 @@ public static ManagerInfo Get()
}
}

if (_instance.DownloadDirectory == null)
_instance.DownloadDirectory = "Downloads";

_instance.Save();
}

if (!Directory.Exists(_instance.GetFullDownloadDirectory()))
Directory.CreateDirectory(_instance.GetFullDownloadDirectory());

if (!Directory.Exists(_instance.GetFullProfileDirectory()))
Directory.CreateDirectory(_instance.GetFullProfileDirectory());

return _instance;
}

Expand Down
29 changes: 21 additions & 8 deletions GCManager/Mod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ public string GetDownloadDirectory()

public string GetInstallDirectory()
{
return Path.Combine(ManagerInfo.Get().installDir, "BepInEx", "plugins", this.fullName);
return GetInstallDirectory(this.fullName);
}

public static string GetInstallDirectory(string fullName)
{
return Path.Combine(ManagerInfo.Get().installDir, "BepInEx", "plugins", fullName);
}

public void Install()
Expand Down Expand Up @@ -80,14 +85,24 @@ public void Install()
}

public void Uninstall()
{
Uninstall(this.fullName);

this.isInstalled = false;
}

public static void Uninstall(string name, bool silent = false)
{
try
{
if (this.fullName == "bbepis-BepInExPack")
if (name == "bbepis-BepInExPack")
{
MessageBoxResult result = MessageBox.Show("Uninstalling BepInEx will also uninstall all of your mods!\nYou sure about this?", "Warning", MessageBoxButton.YesNo);
if (result != MessageBoxResult.Yes)
return;
if (!silent)
{
MessageBoxResult result = MessageBox.Show("Uninstalling BepInEx will also uninstall all of your mods!\nYou sure about this?", "Warning", MessageBoxButton.YesNo);
if (result != MessageBoxResult.Yes)
return;
}

string installDir = ManagerInfo.Get().installDir;

Expand All @@ -97,12 +112,10 @@ public void Uninstall()
}
else
{
Directory.Delete(GetInstallDirectory(), true);
Directory.Delete(GetInstallDirectory(name), true);
}
}
catch (IOException) { }

this.isInstalled = false;
}

public bool CheckIfInstalled()
Expand Down
21 changes: 13 additions & 8 deletions GCManager/ModManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class ModManager

public static ModList onlineModList = null;

public static bool silent = false;

class DownloadInfo
{
public Mod mod;
Expand All @@ -35,7 +37,7 @@ class DownloadInfo
private static List<string> _priorityInstalls = new List<string>();
private static Queue<Mod> _pendingInstalls = new Queue<Mod>();

public static void RefreshLists()
public static void UpdateInstalledStatuses()
{
App app = (App)Application.Current;
if (app.window != null)
Expand Down Expand Up @@ -240,12 +242,15 @@ public static void InstallMod(Mod mod, string version = null)
}
else if (!dependencyMod.CheckIfInstalled())
{
MessageBoxResult result = MessageBox.Show(
"This mod requires the dependency \"" + dependency + "\".\nDo you want to install this? (You probably should!)",
"You must install additional mods", MessageBoxButton.YesNo);
if (!silent)
{
MessageBoxResult result = MessageBox.Show(
"This mod requires the dependency \"" + dependency + "\".\nDo you want to install this? (You probably should!)",
"You must install additional mods", MessageBoxButton.YesNo);

if (result == MessageBoxResult.Yes)
ActivateMod(dependencyMod);
if (result == MessageBoxResult.Yes || silent)
ActivateMod(dependencyMod);
}
}

_priorityInstalls.Remove(dependencyFullName);
Expand All @@ -262,15 +267,15 @@ public static void InstallMod(Mod mod, string version = null)
InstallMod(_pendingInstalls.Dequeue());
}

RefreshLists();
UpdateInstalledStatuses();
}

public static void UninstallMod(Mod mod)
{
mod.Uninstall();
GetEntryInfo(mod).status = EntryStatus.UNINSTALLED;

RefreshLists();
UpdateInstalledStatuses();
}

public static void UpdateMod(Mod localMod)
Expand Down
60 changes: 60 additions & 0 deletions GCManager/Profile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace GCManager
{
public class Profile
{
public class ProfileEntry
{
public string fullName;
public string version;

public ProfileEntry()
{

}

public ProfileEntry(Mod mod)
{
this.fullName = mod.fullName;
this.version = mod.version;
}
}

public string name;

public List<ProfileEntry> entries = new List<ProfileEntry>();

public void Install(ModList onlineMods, bool installProfileVersions)
{
foreach (ProfileEntry entry in entries)
{
Mod mod = onlineMods.Find(entry.fullName);

if (mod != null)
{
ModManager.ActivateMod(mod, installProfileVersions ? entry.version : null);
}
else
MessageBox.Show("Could not find mod \"" + entry.fullName + "\"!", "Profile Load Error", MessageBoxButton.OK);
}
}

public void Add(Mod localMod)
{
entries.Add(new ProfileEntry(localMod));
}

public void Save()
{
File.WriteAllText(Path.Combine(ManagerInfo.Get().GetFullProfileDirectory(), (name + ".json")), JsonConvert.SerializeObject(this));
}
}
}
16 changes: 16 additions & 0 deletions GCManager/ProfileCreateWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Window x:Class="GCManager.ProfileCreateWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:GCManager"
mc:Ignorable="d"
Title="New Profile" Height="130" Width="300" ResizeMode="NoResize">
<Grid>
<TextBlock HorizontalAlignment="Left" Margin="10,10,0,0" TextWrapping="Wrap" Text="New Profile Name" VerticalAlignment="Top"/>
<TextBox Height="23" Margin="10,30,10,0" TextWrapping="Wrap" Text="{Binding profileName, UpdateSourceTrigger=PropertyChanged}" VerticalAlignment="Top"/>
<Button Content="Create Profile" HorizontalAlignment="Right" Margin="0,0,10,10" VerticalAlignment="Bottom" Width="75" IsDefault="True" Click="Create_Click"/>
<Button Content="Cancel" HorizontalAlignment="Left" Margin="10,0,0,10" VerticalAlignment="Bottom" Width="75" IsCancel="True" Click="Cancel_Click"/>

</Grid>
</Window>
39 changes: 39 additions & 0 deletions GCManager/ProfileCreateWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace GCManager
{

public partial class ProfileCreateWindow : Window
{
public string profileName { get; set; }

public ProfileCreateWindow()
{
InitializeComponent();

this.DataContext = this;
}

private void Cancel_Click(object sender, RoutedEventArgs e)
{
this.DialogResult = false;
}

private void Create_Click(object sender, RoutedEventArgs e)
{
this.DialogResult = true;
}
}
}
17 changes: 17 additions & 0 deletions GCManager/ProfileLoadWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Window x:Class="GCManager.ProfileLoadWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:GCManager"
mc:Ignorable="d"
Title="Load Profile" Height="130" Width="300" ResizeMode="NoResize">
<Grid>
<Button Content="Load" HorizontalAlignment="Right" Margin="0,0,10,10" VerticalAlignment="Bottom" Width="75" IsDefault="True" Click="Load_Click"/>
<Button Content="Cancel" HorizontalAlignment="Left" Margin="10,0,0,10" VerticalAlignment="Bottom" Width="75" IsCancel="True" Click="Cancel_Click"/>
<CheckBox IsChecked="{Binding installOverExisting}" Content="Do not uninstall existing mods before load" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top"/>
<CheckBox IsChecked="{Binding installProfileVersions}" Content="Install versions specified in profile" HorizontalAlignment="Left" Margin="10,30,0,0" VerticalAlignment="Top"/>
<TextBlock HorizontalAlignment="Left" Margin="38,45,0,0" TextWrapping="Wrap" Text="(Otherwise, latest versions will be used)" VerticalAlignment="Top" FontSize="11" Foreground="#FF979797"/>

</Grid>
</Window>
Loading

0 comments on commit 0c2cced

Please sign in to comment.