Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manage ModData functionality to 1.0.6.3 #271

Merged
merged 2 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions FrostyModManager/FrostyModManager.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@
<Compile Include="Windows\KeyPromptWindow.xaml.cs">
<DependentUpon>KeyPromptWindow.xaml</DependentUpon>
</Compile>
<Compile Include="Windows\ManageModDataWindow.xaml.cs">
<DependentUpon>ManageModDataWindow.xaml</DependentUpon>
</Compile>
<Compile Include="Windows\PrelaunchWindow2.xaml.cs">
<DependentUpon>PrelaunchWindow2.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -177,6 +180,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Windows\ManageModDataWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Windows\PrelaunchWindow2.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down Expand Up @@ -284,6 +291,7 @@
<Resource Include="Images\SecondaryActionAdd.png" />
<Resource Include="Images\PrimaryActionAdd.png" />
<Resource Include="Images\PrimaryActionMerge.png" />
<Resource Include="Images\Open.png" />
<Content Include="ThirdParty\Newtonsoft.Json.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
Expand Down
Binary file added FrostyModManager/Images/Open.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions FrostyModManager/Windows/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,9 @@
<MenuItem x:Name="toolsMenuItem"
Header="Tools"
Height="22">
<MenuItem x:Name="manageModData"
Header="Manage ModData"
Click="modDataMenuItem_Click"/>
</MenuItem>
<MenuItem Header="Help"
Height="22">
Expand Down
7 changes: 7 additions & 0 deletions FrostyModManager/Windows/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1446,6 +1446,13 @@ private void aboutMenuItem_Click(object sender, RoutedEventArgs e)
AboutWindow win = new AboutWindow();
win.ShowDialog();
}

private void modDataMenuItem_Click(object sender, RoutedEventArgs e)
{
ManageModDataWindow win = new ManageModDataWindow();
win.ShowDialog();
}

private void appliedModsList_SelectionChanged(object sender, SelectionChangedEventArgs e) => updateAppliedModButtons();

private void updateAppliedModButtons()
Expand Down
76 changes: 76 additions & 0 deletions FrostyModManager/Windows/ManageModDataWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<!--
ManageModDataWindow
Author: Stoichiom, Dyvinia
-->
<ctrl:FrostyDockableWindow x:Class="FrostyModManager.ManageModDataWindow"
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:FrostyModManager"
xmlns:ctrl="clr-namespace:Frosty.Controls;assembly=FrostyControls"
mc:Ignorable="d"
Title="Manage ModData" SizeToContent="Height" Width="500" Height="Auto" MaxHeight="250"
ResizeMode="NoResize" WindowStartupLocation="CenterOwner">
<Grid Background="{StaticResource ListBackground}">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition Height="0"/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Orientation="Vertical" Margin="8">
<TextBlock Grid.Column="0" Text="Packs in ModData:" Foreground="{StaticResource FontColor}" HorizontalAlignment="Left" VerticalAlignment="Center" Height="16" Margin="0,1"/>
<ListBox x:Name="modDataList" Grid.Column="1" HorizontalContentAlignment="Stretch" ScrollViewer.HorizontalScrollBarVisibility="Disabled" MinHeight="22" MaxHeight="128" BorderBrush="{StaticResource ControlBackground}" BorderThickness="1" Background="{StaticResource WindowBackground}" Padding="0">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="16"/>
<ColumnDefinition Width="4"/>
<ColumnDefinition Width="16"/>
<ColumnDefinition Width="4"/>
<ColumnDefinition Width="16"/>
</Grid.ColumnDefinitions>

<TextBlock Grid.Column="0" Text="{Binding Name}" VerticalAlignment="Center"/>
<Button x:Name="launchModData" Grid.Column="1" Click="launchModData_Click" ToolTip="Attempts to launch game with existing ModData">
<Image Source="/FrostyModManager;component/Images/Play.png"/>
</Button>
<Button x:Name="openModData" Grid.Column="3" Click="openModData_Click" ToolTip="Open Folder">
<Image Source="/FrostyModManager;component/Images/Open.png"/>
</Button>
<Button x:Name="deleteModData" Grid.Column="5" Click="deleteModData_Click" ToolTip="Delete Folder">
<Image Source="/FrostyModManager;component/Images/Remove.png"/>
</Button>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}" BasedOn="{StaticResource {x:Type ListBoxItem}}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<Border x:Name="Bd" BorderBrush="Transparent" BorderThickness="0" Background="Transparent" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="True">
<ContentPresenter SnapsToDevicePixels="True" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ListBox.ItemContainerStyle>
</ListBox>

<TextBlock Grid.Column="2" Text="ModData Path:" Foreground="{StaticResource FontColor}" HorizontalAlignment="Left" VerticalAlignment="Center" Height="16" Margin="0,9,0,1"/>
<TextBox IsReadOnly="True" Grid.Column="3" x:Name="modDataNameTextBox" BorderThickness="1" VerticalContentAlignment="Center" Height="22"/>
</StackPanel>

<Grid Grid.Row="1" Margin="4">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>

<Button Grid.Column="0" x:Name="closeButton" Content="Close" Width="50" Height="22" HorizontalAlignment="Left" Click="closeButton_Click"/>
</Grid>
</Grid>
</ctrl:FrostyDockableWindow>
130 changes: 130 additions & 0 deletions FrostyModManager/Windows/ManageModDataWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
using System.Diagnostics;
using System.IO;
using System.Windows;
using System.Windows.Controls;
using Frosty.Controls;
using Frosty.Core;
using Frosty.ModSupport;
using FrostySdk;

namespace FrostyModManager
{

public class Pack
{
public string Name { get; set; }
public string Path { get; set; }
}

/// <summary>
/// Author: Stoichiom, Dyvinia
/// Class <c>ManageModDataWindow</c> handles the logic for deleting specified ModData folders.
/// </summary>
public partial class ManageModDataWindow : FrostyDockableWindow
{
public ManageModDataWindow()
{
InitializeComponent();

// Draws the window in the center of the screen
Window mainWin = Application.Current.MainWindow;
if (mainWin != null)
{
double x = mainWin.Left + (mainWin.Width / 2.0);
double y = mainWin.Top + (mainWin.Height / 2.0);

Left = x - (Width / 2.0);
Top = y - (MaxHeight / 2.0);
}

// Draws the user's ModData directory on modDataNameTextBox
string modDataPath = getModDataPath();
modDataNameTextBox.Text = modDataPath;

// Done to avoid potential IO error on init
if (!Directory.Exists(modDataPath))
Directory.CreateDirectory(modDataPath);

listPacks();
}

/// <summary>
/// Method <c>getModDataPath</c> Returns the path to the ModData folder.
/// </summary>
private string getModDataPath()
{
return Config.Get<string>("GamePath", "", ConfigScope.Game, ProfilesLibrary.ProfileName) + "\\ModData";
}

/// <summary>
/// Method <c>listPacks</c> lists the available packs in the ModData folder
/// </summary>
private void listPacks()
{
// Cleans out old items
modDataList.Items.Clear();

string modDataPath = getModDataPath();

// Grabs the packs currently in the ModData folder.
string[] modDataPacks = Directory.GetDirectories(modDataPath, "*", SearchOption.TopDirectoryOnly);

// Adds them to the ComboBox in the window.
foreach (string packNamePath in modDataPacks)
{
modDataList.Items.Add(new Pack { Name = Path.GetFileName(packNamePath), Path = packNamePath });
}
}

/// <summary>
/// Method <c>closeButton_Click</c> closes the window
/// </summary>
private void closeButton_Click(object sender, RoutedEventArgs e)
{
DialogResult = false;
Close();
}

/// <summary>
/// Method <c>deleteModData_Click</c> Delete operation for the selected ModData pack folder
/// </summary>
private void deleteModData_Click(object sender, RoutedEventArgs e)
{
Pack selectedPack = ((Button)sender).DataContext as Pack;

MessageBoxResult result = FrostyMessageBox.Show("Do you want to delete pack \"" + selectedPack.Name + "\"?", "Frosty Mod Manager", MessageBoxButton.YesNo);
if (result == MessageBoxResult.Yes)
{
try
{
Directory.Delete(selectedPack.Path, true);
listPacks();
}
catch (IOException)
{
System.Threading.Tasks.Task.Run(() => {
FrostyMessageBox.Show("Error deleting Pack!\nTry running Frosty as Administrator.", "Frosty Mod Manager", MessageBoxButton.OK);
});
}
}
}

/// <summary>
/// Method <c>closeButton_Click</c> closes the window
/// </summary>
private void openModData_Click(object sender, RoutedEventArgs e)
{
Pack selectedPack = ((Button)sender).DataContext as Pack;
Process.Start(selectedPack.Path);
}

/// <summary>
/// Method <c>launchModData_Click</c> Attempts to launch game with existing ModData pack folder
/// </summary>
private void launchModData_Click(object sender, RoutedEventArgs e)
{
Pack selectedPack = ((Button)sender).DataContext as Pack;
FrostyModExecutor.ExecuteProcess($"{Path.GetDirectoryName(getModDataPath())}\\{ProfilesLibrary.ProfileName}.exe", $"-dataPath \"{selectedPack.Path.Trim('\\')}\"");
}
}
}