Skip to content

Commit

Permalink
Added Archive options for Compression and Copy
Browse files Browse the repository at this point in the history
Added checkboxes to library cards of archives, allowing user to select
whether compression is desired and whether to copy games instead of
moving them when transferring in or out.
This option writes a small archiveOptions.txt file in the archive
directory to store these options, this way multiple Game Pipe clients
connecting to the source will have the same options (no live updates
though, it's only read at startup)
  • Loading branch information
DjScribbles committed Mar 8, 2016
1 parent 7dcd441 commit fbdae57
Show file tree
Hide file tree
Showing 8 changed files with 163 additions and 19 deletions.
5 changes: 5 additions & 0 deletions GamePipe/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@
<Setter Property="Margin" Value="4"/>
</Style>

<Style TargetType="CheckBox">
<Setter Property="Margin" Value="4"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
</Style>
<Style TargetType="TextBox">
<Setter Property="Margin" Value="4"/>
<Setter Property="Foreground" Value="{StaticResource TextColor}"/>
Expand Down
18 changes: 9 additions & 9 deletions GamePipe/GamePipe.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
<Compile Include="ViewModel\GameViewModel.cs" />
<Compile Include="ViewModel\RelayCommand.cs" />
<Compile Include="ViewModel\RootSteamViewModel.cs" />
<Compile Include="ViewModel\SteamArchiveViewModel.cs" />
<Compile Include="ViewModel\SteamLibraryViewModel.cs" />
<Compile Include="ViewModel\TransferManagerViewModel.cs" />
<Compile Include="ViewModel\TransferViewModel.cs" />
Expand Down Expand Up @@ -193,13 +194,12 @@
<Files Output="false" Required="true" ParameterType="Microsoft.Build.Framework.ITaskItem[]" />
</ParameterGroup>
<Task Evaluate="true">
<Reference xmlns="http://schemas.microsoft.com/developer/msbuild/2003" Include="System.Xml" />
<Reference xmlns="http://schemas.microsoft.com/developer/msbuild/2003" Include="System.Xml.Linq" />
<Using xmlns="http://schemas.microsoft.com/developer/msbuild/2003" Namespace="System" />
<Using xmlns="http://schemas.microsoft.com/developer/msbuild/2003" Namespace="System.IO" />
<Using xmlns="http://schemas.microsoft.com/developer/msbuild/2003" Namespace="System.Xml.Linq" />
<Code xmlns="http://schemas.microsoft.com/developer/msbuild/2003" Type="Fragment" Language="cs">
<![CDATA[
<Reference xmlns="http://schemas.microsoft.com/developer/msbuild/2003" Include="System.Xml" />
<Reference xmlns="http://schemas.microsoft.com/developer/msbuild/2003" Include="System.Xml.Linq" />
<Using xmlns="http://schemas.microsoft.com/developer/msbuild/2003" Namespace="System" />
<Using xmlns="http://schemas.microsoft.com/developer/msbuild/2003" Namespace="System.IO" />
<Using xmlns="http://schemas.microsoft.com/developer/msbuild/2003" Namespace="System.Xml.Linq" />
<Code xmlns="http://schemas.microsoft.com/developer/msbuild/2003" Type="Fragment" Language="cs"><![CDATA[
var config = XElement.Load(Config.ItemSpec).Elements("Costura").FirstOrDefault();
if (config == null) return true;
Expand All @@ -218,8 +218,8 @@ var filesToCleanup = Files.Select(f => f.ItemSpec).Where(f => !excludedAssemblie
foreach (var item in filesToCleanup)
File.Delete(item);
]]>
</Code></Task>
]]></Code>
</Task>
</UsingTask>
<Target Name="CleanReferenceCopyLocalPaths" AfterTargets="AfterBuild;NonWinFodyTarget">
<CosturaCleanup Config="FodyWeavers.xml" Files="@(ReferenceCopyLocalPaths->'$(OutDir)%(DestinationSubDirectory)%(Filename)%(Extension)')" />
Expand Down
13 changes: 11 additions & 2 deletions GamePipe/View/LibraryCardView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:GamePipe.View"
mc:Ignorable="d"
AllowDrop="True" MouseDoubleClick="LibraryCardView_MouseDoubleClick"
AllowDrop="True"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<Grid.ColumnDefinitions>
Expand All @@ -17,10 +17,11 @@
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>

<Button x:Name="LibraryMenuButton" Grid.Column="2" Grid.RowSpan="2" Background="{StaticResource Background}" BorderBrush="{StaticResource FeintBorder}" MinWidth="24"
ContextMenuService.Placement="Left" >
ContextMenuService.Placement="Left">
<Path StrokeThickness="4" Stroke="{StaticResource TextColor}" StrokeStartLineCap="Round" StrokeEndLineCap="Round"
Data="M 2,4 l 0,0 m 0,6 l 0,0 m 0,6 l 0,0"/>
<Button.ContextMenu>
Expand All @@ -35,5 +36,13 @@
<TextBlock Grid.Row="0" Grid.Column="1" Text="{Binding SteamDirectoryShortened}" HorizontalAlignment="Left" Margin="0,8,4,0" />
<TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding Path=DriveAvailableSpace, StringFormat=Available: {0}}" HorizontalAlignment="Right" Margin="8,0"/>
<ProgressBar Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="2" Value="{Binding DrivePercentFull, Mode=OneWay}" Margin="8,0,8,8" Height="4" />
<Grid Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="3" Visibility="{Binding IsArchive, Converter={StaticResource BooleanToVisibilityConverter}}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<CheckBox IsChecked="{Binding CompressNewGames}" Content="Compress New" HorizontalAlignment="Left" VerticalAlignment="Center"/>
<CheckBox Grid.Column="1" IsChecked="{Binding CopyInOut}" Content="Copy In/Out" HorizontalAlignment="Left" VerticalAlignment="Center"/>
</Grid>
</Grid>
</UserControl>
13 changes: 10 additions & 3 deletions GamePipe/View/SteamLibraryView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private void DisplayList_PreviewMouseLeftButtonDown(object sender, MouseButtonEv
}


private void DisplayList_PreviewMouseMove(object sender, MouseEventArgs e)
private void DisplayList_PreviewMouseMove(object sender, MouseEventArgs e)
{
//if the left mouse button is not pressed, then we can't be dragging anything
if (e.LeftButton != MouseButtonState.Pressed || !(sender is ListBox) || !(_mousePressOrigSource is DependencyObject))
Expand Down Expand Up @@ -104,9 +104,16 @@ private void DisplayList_Drop(object sender, DragEventArgs e)
{
var destination = (sender as FrameworkElement)?.DataContext as SteamLibraryViewModel;
var sourceInfo = e.Data.GetData(DRAG_DATA_NAME) as Transfer;
if (!object.ReferenceEquals(sourceInfo.SourceLibrary, destination))
var source = sourceInfo.SourceLibrary;
if (!object.ReferenceEquals(source, destination))
{
var transfer = new GamePipeLib.Model.LocalMove(sourceInfo.SourceLibrary.Model, destination.Model, sourceInfo.SourceGame.Model);
var shouldCopy = ((source is SteamArchiveViewModel && ((SteamArchiveViewModel)source).CopyInOut) ||
(destination is SteamArchiveViewModel && ((SteamArchiveViewModel)destination).CopyInOut));

var transfer = shouldCopy
? new GamePipeLib.Model.LocalCopy(source.Model, destination.Model, sourceInfo.SourceGame.Model)
: new GamePipeLib.Model.LocalMove(source.Model, destination.Model, sourceInfo.SourceGame.Model);

transfer.QueueTransfer();
}
}
Expand Down
8 changes: 6 additions & 2 deletions GamePipe/ViewModel/RootSteamViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ private void Libraries_CollectionChanged(object sender, NotifyCollectionChangedE
{
foreach (SteamLibrary addition in e.NewItems)
{
var newLib = new SteamLibraryViewModel(addition);
var newLib = (addition is SteamArchive)
? new SteamArchiveViewModel(addition as SteamArchive)
: new SteamLibraryViewModel(addition);
newLib.UpdateFilter(LocalListFilter);
Libraries.Add(newLib);
}
Expand Down Expand Up @@ -109,7 +111,9 @@ public ObservableCollection<SteamLibraryViewModel> Libraries
{
if (_Libraries == null)
{
_Libraries = new ObservableCollection<SteamLibraryViewModel>(_root.Libraries.Select(x => new SteamLibraryViewModel(x)));
_Libraries = new ObservableCollection<SteamLibraryViewModel>(_root.Libraries.Select(x => (x is SteamArchive)
? new SteamArchiveViewModel(x as SteamArchive)
: new SteamLibraryViewModel(x)));
}
return _Libraries;
}
Expand Down
43 changes: 43 additions & 0 deletions GamePipe/ViewModel/SteamArchiveViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GamePipeLib.Model.Steam;

namespace GamePipe.ViewModel
{
public class SteamArchiveViewModel : SteamLibraryViewModel
{
private SteamArchive _model;
public SteamArchiveViewModel(SteamArchive model) : base(model)
{
_model = model;
}

public bool CompressNewGames
{
get
{
return _model.CompressNewGames;
}
set
{
_model.CompressNewGames = value;
NotifyPropertyChanged("CompressNewGames");
}
}
public bool CopyInOut
{
get
{
return _model.CopyInOut;
}
set
{
_model.CopyInOut = value;
NotifyPropertyChanged("CopyInOut");
}
}
}
}
2 changes: 1 addition & 1 deletion GamePipe/ViewModel/SteamLibraryViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public class SteamLibraryViewModel : ViewModelBase
{
private string _listFilter = "";
private GameSortMode _sortMode = GameSortMode.AtoZ;
public readonly bool _isArchive;

private SteamLibrary _model;
public SteamLibraryViewModel(SteamLibrary model)
Expand Down Expand Up @@ -57,6 +56,7 @@ private void UpdateDriveInfo()
public double DrivePercentFull { get; private set; }
public string DriveAvailableSpace { get; private set; }
public string DriveTotalSpace { get; private set; }
public bool IsArchive { get { return Model is SteamArchive; } }

public string SteamDirectoryShortened
{
Expand Down
80 changes: 78 additions & 2 deletions GamePipeLib/Model/Steam/SteamArchive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.IO;
using GamePipeLib.Utils;
using System.IO.Compression;
using System.Text.RegularExpressions;

namespace GamePipeLib.Model.Steam
{
Expand All @@ -19,10 +20,38 @@ public class SteamArchive : SteamLibrary
private const string COMPRESSION_EXTENSION = ".gpdeflate";
public SteamArchive(string libraryDirectory) : base(libraryDirectory, true)
{
CompressNewGames = true;
InitializeArchiveOptions();
}

public bool CompressNewGames { get; set; }
private bool _CompressNewGames;
public bool CompressNewGames
{
get
{
return _CompressNewGames;
}
set
{
_CompressNewGames = value;
SaveArchiveOptions();
NotifyPropertyChanged("CompressNewGames");
}
}

private bool _CopyInOut;
public bool CopyInOut
{
get
{
return _CopyInOut;
}
set
{
_CopyInOut = value;
SaveArchiveOptions();
NotifyPropertyChanged("CopyInOut");
}
}

public override IEnumerable<string> GetFilesForApp(string appId, bool acceptCompressedFiles)
{
Expand Down Expand Up @@ -79,6 +108,53 @@ private string StripFileCompressionExtension(string path)
}
return path;
}

private void InitializeArchiveOptions()
{
var optionFilePath = Path.Combine(SteamDirectory, "archiveOptions.txt");
var searchString = new Regex(@"\s*(?'property'\w+)\s*=\s*(?'value'\w+)\s*", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
if (File.Exists(optionFilePath))
{
var contents = File.ReadAllText(optionFilePath);
foreach (Match match in searchString.Matches(contents))
{
try
{
var prop = match.Groups["property"].Value.ToLower();
var value = match.Groups["value"].Value.ToLower();
if (prop == "compressnewgames")
{
bool.TryParse(value, out _CompressNewGames);
}
else if (prop == "copyinout")
{
bool.TryParse(value, out _CopyInOut);
}
}
catch (Exception ex)
{
Logging.Logger.Error($"Exception parsing {optionFilePath} match '{match.Value}' into properties:", ex);
}
}
}
}


private void SaveArchiveOptions()
{
var optionFilePath = Path.Combine(SteamDirectory, "archiveOptions.txt");
var sb = new StringBuilder();
sb.AppendLine($"CompressNewGames={CompressNewGames}");
sb.AppendLine($"CopyInOut={CopyInOut}");
try
{
File.WriteAllText(optionFilePath, sb.ToString());
}
catch (Exception ex)
{
Logging.Logger.Error($"Exception writing archive options for {optionFilePath}:", ex);
}
}
}

}

0 comments on commit fbdae57

Please sign in to comment.