Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions FASTER/Models/ArmaMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ public void AddSteamMod(ArmaMod newMod)

public void DeleteSteamMod(uint workshopId)
{


try
{
var currentProfiles = ReloadMods();
Expand Down
50 changes: 43 additions & 7 deletions FASTER/ViewModel/ModsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public ModsViewModel()

internal void DisplayMessage(string msg)
{
MainWindow.Instance.IFlyout.IsOpen = true;
MainWindow.Instance.IFlyout.IsOpen = true;
MainWindow.Instance.IFlyoutMessage.Content = msg;
}

Expand Down Expand Up @@ -62,7 +62,7 @@ public async Task AddSteamMod()
var mod = new ArmaMod
{
WorkshopId = modIDOut,
Path = Path.Combine(Properties.Settings.Default.modStagingDirectory, modID),
Path = Path.Combine(Properties.Settings.Default.modStagingDirectory, modID),
IsLocal = false
};

Expand Down Expand Up @@ -107,7 +107,8 @@ public async Task AddLocalModAsync()
continue;
}

await Task.Factory.StartNew(() => {
await Task.Factory.StartNew(() =>
{
Directory.CreateSymbolicLink(newPath, oldPath);
var progressDone = oldPaths.IndexOf(oldPath);
progress.SetMessage($"Copying mod from {oldPath}\n{progressDone} / {progress.Maximum}");
Expand Down Expand Up @@ -164,6 +165,41 @@ internal async Task DeleteAllMods()
}
}

internal void PurgeAndReinstall(ArmaMod mod)
{
if (mod == null || mod.IsLocal)
return;

DeleteMod(mod);
ModsCollection.AddSteamMod(mod);

DisplayMessage($"Purged and reinstalled {mod.Name}");
}

internal async Task PurgeAndReinstallAll()
{
var answer = await DialogCoordinator.ShowInputAsync(this, "Are you sure you want to purge and reinstall all mods?", "Write \"yes\" and press OK if you wish to continue.");

if (string.IsNullOrEmpty(answer) || !answer.Equals("yes"))
return;

Analytics.TrackEvent("Mods - Clicked PurgeAndReinstallAll", new Dictionary<string, string>
{
{"Name", Properties.Settings.Default.steamUserName}
});

// Stores a copy of the mods that are not local so they can be readded
var copyArmaMods = new List<ArmaMod>(ModsCollection.ArmaMods.Where(x => !x.IsLocal));

foreach (var mod in copyArmaMods)
{
DeleteMod(mod);
ModsCollection.AddSteamMod(mod);
}

DisplayMessage("Purged and reinstalled all mods");
}

public void OpenModPage(ArmaMod mod)
{
if (mod == null)
Expand All @@ -178,7 +214,7 @@ public void OpenModPage(ArmaMod mod)
try
{
url = url.Replace("&", "^&");
Process.Start(new ProcessStartInfo("cmd", $"/c start {url}") {CreateNoWindow = true});
Process.Start(new ProcessStartInfo("cmd", $"/c start {url}") { CreateNoWindow = true });
}
catch
{ DisplayMessage($"Could not open \"{url}\""); }
Expand All @@ -205,7 +241,7 @@ internal async Task OpenLauncherFile()
continue;
}

if(!await Task.Run(() => extractedMod.IsOnWorkshop()))
if (!await Task.Run(() => extractedMod.IsOnWorkshop()))
continue;

ModsCollection.AddSteamMod(extractedMod);
Expand All @@ -223,7 +259,7 @@ public void OpenModFolder(ArmaMod mod)
ProcessStartInfo startInfo = new()
{
Arguments = mod.Path,
FileName = "explorer.exe"
FileName = "explorer.exe"
};

Process.Start(startInfo);
Expand Down Expand Up @@ -251,7 +287,7 @@ public async Task UpdateAll()

MainWindow.Instance.NavigateToConsole();
var ans = await MainWindow.Instance.SteamUpdaterViewModel.RunModsUpdater(ModsCollection.ArmaMods);
if(ans == UpdateState.LoginFailed)
if (ans == UpdateState.LoginFailed)
DisplayMessage("Steam Login Failed");
}
}
Expand Down
26 changes: 20 additions & 6 deletions FASTER/Views/Mods.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
<Button ToolTip="Delete All"
Style="{StaticResource MahApps.Styles.Button.MetroSquare.Accent}" BorderThickness="0" Padding="7,5"
Content="{iconPacks:Modern Kind=Delete}" Click="DeleteAll_Click" RenderTransformOrigin="0.258,42.716" />
<Button ToolTip="Purge and Reinstall All"
Style="{StaticResource MahApps.Styles.Button.MetroSquare.Accent}" BorderThickness="0" Padding="7,5"
Content="{iconPacks:Material Kind=Redo}" Click="PurgeAndReinstallAll_Click" RenderTransformOrigin="0.258,42.716" />
</StackPanel>
<Grid Grid.Row="0" Grid.Column="1">
<Grid.Effect>
Expand All @@ -67,11 +70,11 @@
ItemsSource="{Binding Path=ModsCollection.ArmaMods, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
CanUserReorderColumns="False" CanUserSortColumns="True" AutoGenerateColumns="False"
CanUserAddRows="False">
<DataGrid.RowStyle>
<DataGrid.RowStyle>
<Style TargetType="{x:Type DataGridRow}" BasedOn="{StaticResource MahApps.Styles.DataGridRow.Azure}">
<Setter Property="IsSelected" Value="{Binding Path=IsSelected, UpdateSourceTrigger=PropertyChanged}" />
</Style>
</DataGrid.RowStyle>
</DataGrid.RowStyle>
<DataGrid.ContextMenu>
<ContextMenu>
<MenuItem Tag="Update" Header="Update" Click="UpdateSelectedMods">
Expand All @@ -80,10 +83,10 @@
</MenuItem.Icon>
</MenuItem>
<MenuItem Tag="Delete" Header="Delete" Click="DeleteSelectedMods">
<MenuItem.Icon>
<iconPacks:PackIconMaterial Kind="Delete" Margin="5"/>
</MenuItem.Icon>
</MenuItem>
<MenuItem.Icon>
<iconPacks:PackIconMaterial Kind="Delete" Margin="5"/>
</MenuItem.Icon>
</MenuItem>
</ContextMenu>
</DataGrid.ContextMenu>
<DataGrid.Effect>
Expand Down Expand Up @@ -141,6 +144,17 @@
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="Actions" CanUserSort="false" Width="auto">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Height="25" Width="25" Padding="0" Margin="1" Click="PurgeAndReinstallMod" ToolTip="Purge and Reinstall"
Content="{iconPacks:Material Kind=Redo}"
Style="{StaticResource MahApps.Styles.Button.MetroSquare.Accent}"
BorderThickness="0" HorizontalAlignment="Center"
Visibility="{Binding Path=IsLocal, Converter={StaticResource BoolToHide}}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>

Expand Down
12 changes: 12 additions & 0 deletions FASTER/Views/Mods.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Windows;
using MahApps.Metro.Controls.Dialogs;
using System.Threading.Tasks;

namespace FASTER.Views
{
Expand Down Expand Up @@ -57,6 +58,12 @@ private void OpenModFolder(object sender, RoutedEventArgs e)
((ModsViewModel) DataContext)?.OpenModFolder(mod);
}

private void PurgeAndReinstallMod(object sender, RoutedEventArgs e)
{
var mod = ((FrameworkElement) sender).DataContext as ArmaMod;
((ModsViewModel) DataContext)?.PurgeAndReinstall(mod);
}

private async void AddSteamMod_Click(object sender, RoutedEventArgs e)
{
await ((ModsViewModel) DataContext)?.AddSteamMod();
Expand Down Expand Up @@ -86,5 +93,10 @@ private async void DeleteAll_Click(object sender, RoutedEventArgs e)
{
await ((ModsViewModel) DataContext)?.DeleteAllMods();
}

private async void PurgeAndReinstallAll_Click(object sender, RoutedEventArgs e)
{
await ((ModsViewModel) DataContext)?.PurgeAndReinstallAll();
}
}
}