-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ModManager] Added manage ModData functionality (#271)
- Loading branch information
1 parent
b7fce43
commit 521cc32
Showing
6 changed files
with
224 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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('\\')}\""); | ||
} | ||
} | ||
} |