Skip to content

Commit 6d35a82

Browse files
authored
Merge pull request #440 from IridiumIO/RefactorMainVM
Update WatchedFolder view
2 parents a6d577b + b569c0e commit 6d35a82

File tree

4 files changed

+124
-40
lines changed

4 files changed

+124
-40
lines changed

CompactGUI.Watcher/Watcher.vb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ Public Class Watcher : Inherits ObservableObject
269269
End Function
270270

271271

272-
Public Async Function Analyse(folder As String, checkDiskModified As Boolean) As Task(Of Boolean)
272+
Public Async Function Analyse(folder As String, checkDiskModified As Boolean, Optional isManualAddition As Boolean = False) As Task(Of Boolean)
273273
Debug.WriteLine("Background Analysing: " & folder)
274274
Dim analyser As New Core.Analyser(folder)
275275

@@ -279,6 +279,8 @@ Public Class Watcher : Inherits ObservableObject
279279

280280
watched.LastCheckedDate = DateTime.Now
281281
watched.LastCheckedSize = analyser.CompressedBytes
282+
watched.LastUncompressedSize = analyser.UncompressedBytes
283+
282284
watched.LastSystemModifiedDate = FolderMonitors.First(Function(f) f.Folder = folder).LastChangedDate
283285
Dim mainCompressionLVL = analyser.FileCompressionDetailsList.Select(Function(f) f.CompressionMode).Max
284286
watched.CompressionLevel = mainCompressionLVL

CompactGUI/Components/Converters/IValueConverters.vb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ Public Class RelativeDateConverter : Implements IValueConverter
5959
Dim dt = CType(value, DateTime)
6060
Dim ts As TimeSpan = DateTime.Now - dt
6161

62+
If ts > TimeSpan.FromDays(19000) Then
63+
Return String.Format("Unknown")
64+
End If
6265
If ts > TimeSpan.FromDays(2) Then
6366
Return String.Format("{0:0} days ago", ts.TotalDays)
6467
ElseIf ts > TimeSpan.FromHours(2) Then

CompactGUI/ViewModels/MainViewModel.vb

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,49 @@ Public Class MainViewModel : Inherits ObservableObject
305305
)
306306
End Sub
307307

308+
Private Async Function ManuallyAddFolderToWatcher() As Task
309+
310+
Dim path As String = ""
311+
312+
Dim folderSelector As New VistaFolderBrowserDialog
313+
folderSelector.ShowDialog()
314+
If folderSelector.SelectedPath = "" Then Return
315+
path = folderSelector.SelectedPath
316+
317+
Dim validFolder = Core.verifyFolder(path)
318+
If Not validFolder.isValid Then
319+
Dim msgError As New ContentDialog With {.Title = "Invalid Folder", .Content = $"{validFolder.msg}", .CloseButtonText = "OK"}
320+
Await msgError.ShowAsync()
321+
Return
322+
End If
323+
324+
Dim newFolder = New ActiveFolder
325+
newFolder.FolderName = path
326+
327+
Dim SteamFolderData = GetSteamNameAndIDFromFolder(path)
328+
329+
newFolder.SteamAppID = SteamFolderData.appID
330+
newFolder.DisplayName = If(SteamFolderData.gameName, path)
331+
332+
333+
Dim newWatched = New Watcher.WatchedFolder With {
334+
.Folder = newFolder.FolderName,
335+
.DisplayName = newFolder.DisplayName,
336+
.IsSteamGame = newFolder.SteamAppID <> 0,
337+
.LastCompressedSize = 0,
338+
.LastUncompressedSize = 0,
339+
.LastCompressedDate = DateTime.UnixEpoch,
340+
.LastCheckedDate = DateTime.UnixEpoch,
341+
.LastCheckedSize = 0,
342+
.LastSystemModifiedDate = DateTime.UnixEpoch,
343+
.CompressionLevel = Core.CompressionAlgorithm.NO_COMPRESSION}
344+
345+
Watcher.AddOrUpdateWatched(newWatched)
346+
Await Watcher.Analyse(path, True, True)
347+
348+
End Function
349+
350+
308351

309352
#Region "Properties"
310353

@@ -362,6 +405,9 @@ Public Class MainViewModel : Inherits ObservableObject
362405
Public Property RemoveWatcherCommand As ICommand = New RelayCommand(Of Watcher.WatchedFolder)(Sub(f) Watcher.RemoveWatched(f))
363406
Public Property ReCompressWatchedCommand As ICommand = New RelayCommand(Of Watcher.WatchedFolder)(Sub(f) SelectFolder(f.Folder))
364407
Property RefreshWatchedCommand As ICommand = New RelayCommand(Sub() Task.Run(Function() Watcher.ParseWatchers(True)))
408+
409+
Public Property ManuallyAddFolderToWatcherCommand As ICommand = New AsyncRelayCommand(AddressOf ManuallyAddFolderToWatcher)
410+
365411
Public Property PauseCompressionCommand As RelayCommand = New RelayCommand(Sub()
366412

367413
If PauseResumeStatus = "Pause" Then

CompactGUI/Views/MainWindow.xaml

Lines changed: 72 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@
503503
</EasingThicknessKeyFrame>
504504
</ThicknessAnimationUsingKeyFrames>
505505
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="mainSection" Storyboard.TargetProperty="(FrameworkElement.Height)">
506-
<EasingDoubleKeyFrame KeyTime="00:00:00.5" Value="150">
506+
<EasingDoubleKeyFrame KeyTime="00:00:00.5" Value="800">
507507
<EasingDoubleKeyFrame.EasingFunction>
508508
<CubicEase EasingMode="EaseOut"/>
509509
</EasingDoubleKeyFrame.EasingFunction>
@@ -1144,76 +1144,109 @@
11441144

11451145

11461146
<!--Folder Watcher Region-->
1147-
<Grid x:Name="grid" VerticalAlignment="Bottom" Height="540" Margin="20,0,20,80" Visibility="Collapsed">
1148-
<Grid.Resources>
1149-
<CollectionViewSource x:Key='src' Source="{Binding Watcher.WatchedFolders}">
1150-
<CollectionViewSource.SortDescriptions>
1151-
<scm:SortDescription PropertyName="DisplayName" />
1152-
</CollectionViewSource.SortDescriptions>
1153-
1154-
</CollectionViewSource>
1155-
1156-
</Grid.Resources>
1157-
<TextBlock Text="watched folders" FontSize="20" Foreground="#73808C" VerticalAlignment="Top" Margin="0,-3,0,0" Visibility="Collapsed"/>
1158-
<TextBlock Text="{Binding Watcher.LastAnalysed, StringFormat=last analysed {0}, Converter={StaticResource RelativeDateConverter}}" FontSize="14" Foreground="#FFBFC7CE" HorizontalAlignment="Left" Margin="35,2,35,220"/>
1159-
<Button HorizontalAlignment="Left" VerticalAlignment="Top" Command="{Binding RefreshWatchedCommand}" Background="Transparent" Foreground="#FFBFC7CE">
1160-
<ui:FontIcon Glyph="&#xE9F3;" FontSize="14" />
1161-
</Button>
1162-
1163-
<TextBlock FontSize="14" Foreground="#FFBFC7CE" HorizontalAlignment="Right" Margin="0,2,0,220">
1164-
<Run Text="Disk space saved: " />
1165-
<Run Text="{Binding Watcher.TotalSaved, Mode=OneWay, Converter={StaticResource BytesToReadableConverter}}" />
1166-
</TextBlock>
1147+
<Grid x:Name="grid" VerticalAlignment="Bottom" Height="560" Margin="20,0,20,60" Visibility="Collapsed" Panel.ZIndex="1010">
1148+
1149+
<Grid.Resources>
1150+
<CollectionViewSource x:Key='src' Source="{Binding Watcher.WatchedFolders}">
1151+
<CollectionViewSource.SortDescriptions>
1152+
<scm:SortDescription PropertyName="DisplayName" />
1153+
</CollectionViewSource.SortDescriptions>
1154+
</CollectionViewSource>
1155+
</Grid.Resources>
1156+
1157+
<TextBlock Text="watched folders" FontSize="20" Foreground="#73808C" VerticalAlignment="Top" Margin="0,-3,0,0" Visibility="Collapsed"/>
1158+
<TextBlock Text="{Binding Watcher.LastAnalysed, StringFormat=last analysed {0}, Converter={StaticResource RelativeDateConverter}}" FontSize="14" Foreground="#FFBFC7CE" HorizontalAlignment="Left" Margin="35,-6,35,220"/>
1159+
<Button HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0,-8,0,0" Command="{Binding RefreshWatchedCommand}" Background="Transparent" Foreground="#FFBFC7CE">
1160+
<ui:FontIcon Glyph="&#xE9F3;" FontSize="14" />
1161+
</Button>
1162+
1163+
<TextBlock FontSize="14" Foreground="#FFBFC7CE" HorizontalAlignment="Left" Margin="35,-30,0,220">
1164+
<Run Text="{Binding Watcher.TotalSaved, Mode=OneWay, Converter={StaticResource BytesToReadableConverter}}" />
1165+
<Run Text="saved" />
1166+
</TextBlock>
11671167

1168-
<ui:ListView x:Name="uiWatcherListView" Margin="-10,60,0,0" Padding="0" Width="480" ItemsSource="{Binding Source = {StaticResource src}}" d:ItemsSource="{d:SampleData}" KeyboardNavigation.TabNavigation="None" ui:ScrollViewerHelper.AutoHideScrollBars="False">
1169-
<ui:ListView.ItemContainerStyle>
1168+
<Button VerticalAlignment="Top" Content="Add To Watchlist" Background="#A26B8399" Foreground="White" HorizontalAlignment="Right" Margin="0,-26,10,0" Command="{Binding ManuallyAddFolderToWatcherCommand}" />
1169+
1170+
<ui:ListView x:Name="uiWatcherListView" ScrollViewer.VerticalScrollBarVisibility="Hidden" Margin="-20,60,-20,0" Padding="10,0,10,0" ItemsSource="{Binding Source = {StaticResource src}}" d:ItemsSource="{d:SampleData}" KeyboardNavigation.TabNavigation="None" ui:ScrollViewerHelper.AutoHideScrollBars="False">
1171+
<ui:ListView.Background>
1172+
<LinearGradientBrush StartPoint="0.5, 0" EndPoint="0.5, 1">
1173+
<GradientStop Color="#00000000" Offset="0"/>
1174+
<GradientStop Color="#30000000" Offset="0.8"/>
1175+
<GradientStop Color="#10000000" Offset="0.95"/>
1176+
<GradientStop Color="#00000000" Offset="0.99"/>
1177+
1178+
</LinearGradientBrush>
1179+
</ui:ListView.Background>
1180+
<ui:ListView.ItemContainerStyle>
11701181
<Style TargetType="ui:ListViewItem">
11711182
<Setter Property="Margin" Value="0,0,0,10"/>
1183+
<Setter Property="Background" Value="Transparent" />
1184+
<Setter Property="BorderBrush" Value="Transparent"/>
1185+
<Setter Property="VerticalContentAlignment" Value="Center"/>
1186+
<Setter Property="Template">
1187+
<Setter.Value>
1188+
<ControlTemplate TargetType="{x:Type ui:ListViewItem}">
1189+
<Border Name="Border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}">
1190+
<ContentPresenter Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}" Margin="{TemplateBinding Padding}" />
1191+
</Border>
1192+
</ControlTemplate>
1193+
</Setter.Value>
1194+
</Setter>
1195+
1196+
<Style.Triggers>
1197+
<Trigger Property="IsMouseOver" Value="True">
1198+
<Setter Property="Background" Value="#20000000"/>
1199+
<Setter Property="BorderBrush" Value="Transparent"/>
1200+
</Trigger>
1201+
</Style.Triggers>
1202+
11721203
</Style>
1204+
11731205
</ui:ListView.ItemContainerStyle>
11741206
<ui:ListView.ItemTemplate >
11751207
<DataTemplate >
1176-
<Border Padding="6" Background="WhiteSmoke" d:Height="100" Height="50" Width="470" KeyboardNavigation.TabNavigation="None" MouseDown="ToggleBorderHeight" MouseEnter="ToggleBorderHeight">
1208+
<Border Padding="6" d:Height="100" Height="50" Width="480" KeyboardNavigation.TabNavigation="None" MouseDown="ToggleBorderHeight" MouseEnter="ToggleBorderHeight">
1209+
11771210

11781211
<Grid >
11791212
<Label>
11801213
<StackPanel Orientation="Horizontal" >
11811214
<Viewbox Grid.Column="1" Visibility="{Binding IsSteamGame, Converter={StaticResource BoolToVisConverter}}"
1182-
Width="12"
1183-
Height="12"
1184-
Margin="0,0,5,0"
1185-
HorizontalAlignment="Left">
1186-
<Path Data="M110.5,87.3c0,0.2,0,0.4,0,0.6L82,129.3c-4.6-0.2-9.3,0.6-13.6,2.4c-1.9,0.8-3.8,1.8-5.5,2.9L0.3,108.8 c0,0-1.4,23.8,4.6,41.6l44.3,18.3c2.2,9.9,9,18.6,19.1,22.8c16.4,6.9,35.4-1,42.2-17.4c1.8-4.3,2.6-8.8,2.5-13.3l40.8-29.1 c0.3,0,0.7,0,1,0c24.4,0,44.3-19.9,44.3-44.3c0-24.4-19.8-44.3-44.3-44.3C130.4,43,110.5,62.9,110.5,87.3z M103.7,171.2 c-5.3,12.7-19.9,18.7-32.6,13.4c-5.9-2.4-10.3-6.9-12.8-12.2l14.4,6c9.4,3.9,20.1-0.5,24-9.9c3.9-9.4-0.5-20.1-9.9-24l-14.9-6.2 c5.7-2.2,12.3-2.3,18.4,0.3c6.2,2.6,10.9,7.4,13.5,13.5S106.2,165.1,103.7,171.2 M154.8,116.9c-16.3,0-29.5-13.3-29.5-29.5 c0-16.3,13.2-29.5,29.5-29.5c16.3,0,29.5,13.3,29.5,29.5C184.2,103.6,171,116.9,154.8,116.9 M132.7,87.3c0-12.3,9.9-22.2,22.1-22.2 c12.2,0,22.1,9.9,22.1,22.2c0,12.3-9.9,22.2-22.1,22.2C142.6,109.5,132.7,99.5,132.7,87.3z M233,116.5c0,64.3-52.2,116.5-116.5,116.5S0,180.8,0,116.5c0-30.4,11-60.2,30.7-78.8C53.5,16.1,82.5,0,116.5,0 C180.8,0,233,52.2,233,116.5z" Fill="#73808C" />
1215+
Width="12"
1216+
Height="12"
1217+
Margin="0,0,5,0"
1218+
HorizontalAlignment="Left">
1219+
<Path Data="M110.5,87.3c0,0.2,0,0.4,0,0.6L82,129.3c-4.6-0.2-9.3,0.6-13.6,2.4c-1.9,0.8-3.8,1.8-5.5,2.9L0.3,108.8 c0,0-1.4,23.8,4.6,41.6l44.3,18.3c2.2,9.9,9,18.6,19.1,22.8c16.4,6.9,35.4-1,42.2-17.4c1.8-4.3,2.6-8.8,2.5-13.3l40.8-29.1 c0.3,0,0.7,0,1,0c24.4,0,44.3-19.9,44.3-44.3c0-24.4-19.8-44.3-44.3-44.3C130.4,43,110.5,62.9,110.5,87.3z M103.7,171.2 c-5.3,12.7-19.9,18.7-32.6,13.4c-5.9-2.4-10.3-6.9-12.8-12.2l14.4,6c9.4,3.9,20.1-0.5,24-9.9c3.9-9.4-0.5-20.1-9.9-24l-14.9-6.2 c5.7-2.2,12.3-2.3,18.4,0.3c6.2,2.6,10.9,7.4,13.5,13.5S106.2,165.1,103.7,171.2 M154.8,116.9c-16.3,0-29.5-13.3-29.5-29.5 c0-16.3,13.2-29.5,29.5-29.5c16.3,0,29.5,13.3,29.5,29.5C184.2,103.6,171,116.9,154.8,116.9 M132.7,87.3c0-12.3,9.9-22.2,22.1-22.2 c12.2,0,22.1,9.9,22.1,22.2c0,12.3-9.9,22.2-22.1,22.2C142.6,109.5,132.7,99.5,132.7,87.3z M233,116.5c0,64.3-52.2,116.5-116.5,116.5S0,180.8,0,116.5c0-30.4,11-60.2,30.7-78.8C53.5,16.1,82.5,0,116.5,0 C180.8,0,233,52.2,233,116.5z" Fill="#FFFFFF" />
11871220
</Viewbox>
1188-
<TextBlock MaxWidth="280" TextTrimming="CharacterEllipsis" Text="{Binding DisplayName, Converter={StaticResource StrippedFolderPathConverter}}" FontSize="16" Foreground="#73808C" FontWeight="SemiBold" VerticalAlignment="Top" Margin="0,-2,0,0"/>
1221+
<TextBlock MaxWidth="280" TextTrimming="CharacterEllipsis" Text="{Binding DisplayName, Converter={StaticResource StrippedFolderPathConverter}}" FontSize="15" Foreground="White" FontWeight="SemiBold" VerticalAlignment="Top" Margin="0,-2,0,0"/>
11891222

11901223
</StackPanel>
11911224

11921225
</Label>
1193-
<Border CornerRadius="5" Height="15" Width="40" Background="#3373808C" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0,22,0,0">
1194-
<TextBlock Text="{Binding CompressionLevel, Converter={StaticResource CompressionLevelAbbreviatedConverter}}" FontSize="11" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="#73808C" FontWeight="SemiBold" />
1226+
<Border CornerRadius="5" Height="15" Width="40" Background="#8373808C" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0,22,0,0">
1227+
<TextBlock Text="{Binding CompressionLevel, Converter={StaticResource CompressionLevelAbbreviatedConverter}}" d:Text="fds" FontSize="11" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="#FFF" FontWeight="SemiBold" />
11951228
</Border>
11961229

1197-
<TextBlock Width="250" Text="{Binding Folder}" TextTrimming="CharacterEllipsis" FontSize="12" Foreground="#73808C" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="50,20,0,0"/>
1198-
<TextBlock Text="{Binding DecayPercentage, StringFormat={}{0}% decayed, Mode=OneWay, Converter={StaticResource DecimalToPercentageConverter}}" FontSize="12" Foreground="#73808C" VerticalAlignment="Top" Margin="0,-2,30,0" HorizontalAlignment="Right"/>
1230+
<TextBlock Width="220" Text="{Binding Folder}" TextTrimming="CharacterEllipsis" FontSize="12" Foreground="#80FFFFFF" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="50,20,0,0"/>
1231+
<TextBlock Text="{Binding DecayPercentage, StringFormat={}{0}% decayed, Mode=OneWay, Converter={StaticResource DecimalToPercentageConverter}}" FontSize="12" Foreground="#FFF" VerticalAlignment="Top" Margin="0,-2,30,0" HorizontalAlignment="Right"/>
11991232

12001233
<ui:ProgressBar Height="6" Width="108" CornerRadius="3" Value="{Binding DecayPercentage, Mode=OneWay, Converter={StaticResource DecimalToPercentageConverter}, ConverterParameter='I'}" Foreground="#92F1AB" Background="#FF8B9FB3" VerticalAlignment="Top" HorizontalAlignment="Right" Margin="0,25,30,0" >
12011234
<ui:ProgressBar.Effect>
1202-
<DropShadowEffect Direction="-135" Opacity="0.2" ShadowDepth="3" BlurRadius="6"/>
1235+
<DropShadowEffect Direction="-135" Opacity="0.2" ShadowDepth="3" BlurRadius="4"/>
12031236
</ui:ProgressBar.Effect>
12041237

12051238
</ui:ProgressBar>
12061239

1207-
<Separator Background="#DDDDDD" VerticalAlignment="Top" Margin="0,40,30,0"/>
1240+
<Separator Background="#60FFFFFF" VerticalAlignment="Top" Margin="0,42,30,0"/>
12081241

12091242
<Grid Margin="0,45,30,0">
12101243
<StackPanel Orientation="Horizontal">
12111244
<TextBlock FontSize="12" Foreground="#FF8B9FB3" Text="last compressed:" Margin="0,0,10,0"/>
1212-
<TextBlock FontSize="12" Foreground="#FF8B9FB3" Text="{Binding LastCompressedDate, Converter={StaticResource RelativeDateConverter}}"/>
1245+
<TextBlock FontSize="12" Foreground="#FF8B9FB3" Text="{Binding LastCompressedDate, Converter={StaticResource RelativeDateConverter}}" d:Text="fds"/>
12131246
</StackPanel>
12141247
<StackPanel Orientation="Horizontal" Margin="0,20,0,0">
12151248
<TextBlock FontSize="12" Foreground="#FF8B9FB3" Text="last modified:" Margin="0,0,27,0"/>
1216-
<TextBlock FontSize="12" Foreground="#FF8B9FB3" Text="{Binding LastSystemModifiedDate, Converter={StaticResource RelativeDateConverter}}"/>
1249+
<TextBlock FontSize="12" Foreground="#FF8B9FB3" Text="{Binding LastSystemModifiedDate, Converter={StaticResource RelativeDateConverter}}" d:Text="fds"/>
12171250
</StackPanel>
12181251
<Button HorizontalAlignment="Right" Command="{Binding ElementName=uiWatcherListView, Path=DataContext.RemoveWatcherCommand}" CommandParameter="{Binding}" Background="#DD6B6B" Foreground="White">
12191252
<ui:FontIcon Glyph="&#xE74D;" FontSize="14"/>
@@ -1244,7 +1277,7 @@
12441277

12451278
</Grid>
12461279

1247-
<StackPanel Orientation="Horizontal" Panel.ZIndex="1" Background="#FF6B8399" VerticalAlignment="Bottom" Height="40" Opacity="0">
1280+
<StackPanel Orientation="Horizontal" Panel.ZIndex="2" Background="#304257" VerticalAlignment="Bottom" Height="40" Opacity="0">
12481281
<StackPanel.Effect>
12491282
<DropShadowEffect Direction="90" BlurRadius="9" Opacity="0.2"/>
12501283
</StackPanel.Effect>

0 commit comments

Comments
 (0)