Skip to content

Commit 4513ce0

Browse files
committed
Finished duplicate files
1 parent 1caee6c commit 4513ce0

17 files changed

+193
-25
lines changed

FastCopy/CopyDialog.xaml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242

4343
<local:DoubleToStringConverter x:Key="NumberToStringConverter"/>
4444
<local:DateTimeToStringConverter x:Key="DateTimeToStringConverter"/>
45+
<local:ReadableSizeConverter x:Key="ReadableSizeConverter"/>
4546

4647
<Style x:Key="DuplicateFilenameTextStyle" TargetType="TextBlock">
4748
<Setter Property="FontSize" Value="14"/>
@@ -112,12 +113,14 @@
112113
<RowDefinition Height="Auto"/>
113114
</Grid.RowDefinitions>
114115

115-
<TextBlock Grid.Row="0" Grid.ColumnSpan="2" Height="55" Padding="0,25,0,20" LineHeight="42" VerticalAlignment="Center">
116+
<TextBlock Grid.Row="0" Grid.ColumnSpan="2" Height="55" Padding="0,25,0,20" LineHeight="42" VerticalAlignment="Center" FontSize="12">
116117
<Run Text="Destination folder contains 3 duplicates"/>
117118
</TextBlock>
118119

119-
<CheckBox Grid.Row="1" Content="Use source" Checked="CheckBox_Checked"/>
120-
<CheckBox Grid.Row="1" Grid.Column="1" Content="Use destination"/>
120+
<Line Margin="0,0,0,0" Grid.Row="1" Grid.ColumnSpan="2" X1="0" X2="500" Y1="0" Y2="0" Stroke="{StaticResource SeperatorLineColor}" Opacity="{StaticResource SeperatorLineOpacity}"/>
121+
<CheckBox Grid.Row="1" Content="Use source" Checked="CheckBox_Checked" IsThreeState="True" IsChecked="{x:Bind ViewModel.UseSource, Mode=TwoWay}"/>
122+
<CheckBox Grid.Row="1" Grid.Column="1" Content="Use destination" IsThreeState="True" IsChecked="{x:Bind ViewModel.UseDestination, Mode=TwoWay}"/>
123+
<Line Margin="0,0,0,0" Grid.Row="1" Grid.ColumnSpan="2" X1="0" X2="500" Y1="45" Y2="45" Stroke="{StaticResource SeperatorLineColor}" Opacity="{StaticResource SeperatorLineOpacity}"/>
121124
</Grid>
122125

123126
<ItemsRepeater Grid.Row="4" Margin="0,24,0,0" ItemsSource="{x:Bind ViewModel.DuplicateFiles}">
@@ -148,7 +151,7 @@
148151
<Image Source="{x:Bind File1.Bitmap}" Width="48" Height="48" Stretch="Uniform"/>
149152
<StackPanel Margin="10,0,0,0" Orientation="Vertical">
150153
<TextBlock Text="{x:Bind File1.CreationDate,Converter={StaticResource DateTimeToStringConverter}}"/>
151-
<TextBlock Text="{x:Bind File1.Bytes}"/>
154+
<TextBlock Text="{x:Bind File1.Bytes, Converter={StaticResource ReadableSizeConverter}}"/>
152155
</StackPanel>
153156
</StackPanel>
154157
</CheckBox>
@@ -158,7 +161,7 @@
158161
<Image Source="{x:Bind File2.Bitmap}" Width="48" Height="48" Stretch="Uniform"/>
159162
<StackPanel Margin="10,0,0,0" Orientation="Vertical">
160163
<TextBlock Text="{x:Bind File2.CreationDate, Converter={StaticResource DateTimeToStringConverter}}"/>
161-
<TextBlock Text="{x:Bind File2.Bytes}"/>
164+
<TextBlock Text="{x:Bind File2.Bytes,Converter={StaticResource ReadableSizeConverter}}"/>
162165
</StackPanel>
163166
</StackPanel>
164167
</CheckBox>

FastCopy/DateTimeToStringConverter.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,17 @@
77

88
namespace winrt::FastCopy::implementation
99
{
10-
1110
winrt::Windows::Foundation::IInspectable DateTimeToStringConverter::Convert(
1211
winrt::Windows::Foundation::IInspectable const& value,
1312
winrt::Windows::UI::Xaml::Interop::TypeName const& targetType,
1413
winrt::Windows::Foundation::IInspectable const& parameter,
1514
winrt::hstring const& language)
1615
{
1716
auto const p = winrt::unbox_value<winrt::Windows::Foundation::DateTime>(value);
18-
auto const t = winrt::clock::to_time_t(p);
19-
return winrt::box_value((std::wstringstream{} << t).str());
17+
auto p2 = std::chrono::clock_cast<std::chrono::system_clock>(p);
18+
auto result = (std::wstringstream{} << p2).str();
19+
result = result.substr(0, result.rfind(L"."));
20+
return winrt::box_value(result);
2021
}
2122

2223
winrt::Windows::Foundation::IInspectable DateTimeToStringConverter::ConvertBack(

FastCopy/FastCopy.vcxproj

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,10 @@
199199
<SubType>Code</SubType>
200200
</ClInclude>
201201
<ClInclude Include="PropertyChangeHelper.hpp" />
202+
<ClInclude Include="ReadableSizeConverter.h">
203+
<DependentUpon>ReadableSizeConverter.idl</DependentUpon>
204+
<SubType>Code</SubType>
205+
</ClInclude>
202206
<ClInclude Include="ReadableUnitConverter.h" />
203207
<ClInclude Include="resource.h" />
204208
<ClInclude Include="RobocopyArgs.h" />
@@ -326,6 +330,10 @@
326330
<DependentUpon>ProgressItem.xaml</DependentUpon>
327331
<SubType>Code</SubType>
328332
</ClCompile>
333+
<ClCompile Include="ReadableSizeConverter.cpp">
334+
<DependentUpon>ReadableSizeConverter.idl</DependentUpon>
335+
<SubType>Code</SubType>
336+
</ClCompile>
329337
<ClCompile Include="RobocopyArgs.cpp" />
330338
<ClCompile Include="RobocopyProcess.cpp" />
331339
<ClCompile Include="RobocopyViewModel.cpp">
@@ -409,6 +417,9 @@
409417
<DependentUpon>ProgressItem.xaml</DependentUpon>
410418
<SubType>Code</SubType>
411419
</Midl>
420+
<Midl Include="ReadableSizeConverter.idl">
421+
<SubType>Designer</SubType>
422+
</Midl>
412423
<Midl Include="RobocopyViewModel.idl">
413424
<SubType>Designer</SubType>
414425
</Midl>

FastCopy/FastCopy.vcxproj.filters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@
6666
<Midl Include="DateTimeToStringConverter.idl">
6767
<Filter>Views\Converters</Filter>
6868
</Midl>
69+
<Midl Include="ReadableSizeConverter.idl">
70+
<Filter>Views\Converters</Filter>
71+
</Midl>
6972
</ItemGroup>
7073
<ItemGroup>
7174
<ClCompile Include="pch.cpp" />

FastCopy/FileCompareViewModel.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,26 @@
44
#include "FileCompareViewModel.g.cpp"
55
#endif
66

7+
#include "ViewModelLocator.h"
8+
79
namespace winrt::FastCopy::implementation
810
{
11+
FileCompareViewModel::FileCompareViewModel(winrt::hstring path1, winrt::hstring path2) : m_file1{ path1 }, m_file2{ path2 }
12+
{
13+
m_file1.SelectionChanged([this](auto, bool selected) { setRobocopyViewModelDuplicateSelection(true, selected); });
14+
m_file2.SelectionChanged([this](auto, bool selected) {setRobocopyViewModelDuplicateSelection(false, selected); });
15+
}
916

17+
void FileCompareViewModel::setRobocopyViewModelDuplicateSelection(bool isFile1, bool isSelected)
18+
{
19+
auto robocopyViewModel = ViewModelLocator::GetInstance().RobocopyViewModel();
20+
if (isFile1)
21+
{
22+
isSelected ? robocopyViewModel.AddSource() : robocopyViewModel.RemoveSource();
23+
}
24+
else
25+
{
26+
isSelected ? robocopyViewModel.AddDestination() : robocopyViewModel.RemoveDestination();
27+
}
28+
}
1029
}

FastCopy/FileCompareViewModel.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ namespace winrt::FastCopy::implementation
77
{
88
struct FileCompareViewModel : FileCompareViewModelT<FileCompareViewModel>
99
{
10-
FileCompareViewModel(winrt::hstring path1, winrt::hstring path2) : m_file1{ path1 }, m_file2{ path2 } {}
10+
FileCompareViewModel(winrt::hstring path1, winrt::hstring path2);
1111

1212
winrt::FastCopy::FileInfoViewModel File1() { return m_file1; }
1313
winrt::FastCopy::FileInfoViewModel File2() { return m_file2; }
1414
private:
15+
void setRobocopyViewModelDuplicateSelection(bool isFile1, bool isSelected);
1516
winrt::FastCopy::FileInfoViewModel m_file1;
1617
winrt::FastCopy::FileInfoViewModel m_file2;
1718
};

FastCopy/FileInfoViewModel.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <filesystem>
1313

1414

15+
1516
static HICON GetImage(std::wstring_view path)
1617
{
1718
// Get the image list index of the icon
@@ -117,7 +118,7 @@ namespace winrt::FastCopy::implementation
117118

118119
winrt::Windows::Foundation::DateTime FileInfoViewModel::CreationDate()
119120
{
120-
return winrt::Windows::Foundation::DateTime();
121+
return std::chrono::clock_cast<winrt::clock>(std::filesystem::last_write_time(std::filesystem::path{ m_path.data()}));
121122
}
122123
uint64_t FileInfoViewModel::Bytes()
123124
{
@@ -130,13 +131,13 @@ namespace winrt::FastCopy::implementation
130131
{
131132
m_selected = value;
132133
raisePropertyChange(L"Selected");
134+
m_selectionChanged(*this, value);
133135
}
134136
}
135137

136138
winrt::Microsoft::UI::Xaml::Media::ImageSource FileInfoViewModel::Bitmap()
137139
{
138140
auto icon = GetImage(m_path.data());
139-
auto source = HIconToWriteableBitmap(icon);
140-
return source;
141+
return HIconToWriteableBitmap(icon);
141142
}
142143
}

FastCopy/FileInfoViewModel.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ namespace winrt::FastCopy::implementation
77
{
88
struct FileInfoViewModel : FileInfoViewModelT<FileInfoViewModel>, PropertyChangeHelper<FileInfoViewModel>
99
{
10-
FileInfoViewModel(winrt::hstring path) : m_path{ path } { }
10+
FileInfoViewModel(winrt::hstring path) : m_path{ path }
11+
{
12+
}
1113

1214
winrt::hstring Filename();
1315
winrt::Windows::Foundation::DateTime CreationDate();
@@ -17,7 +19,11 @@ namespace winrt::FastCopy::implementation
1719

1820
winrt::Microsoft::UI::Xaml::Media::ImageSource Bitmap();
1921

22+
winrt::event_token SelectionChanged(winrt::Windows::Foundation::EventHandler<bool> const& handler) { return m_selectionChanged.add(handler); }
23+
void SelectionChanged(winrt::event_token const& token) { m_selectionChanged.remove(token); }
2024
private:
25+
26+
winrt::event<Windows::Foundation::EventHandler<bool>> m_selectionChanged;
2127
winrt::hstring m_path;
2228
bool m_selected = false;
2329
};

FastCopy/FileInfoViewModel.idl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,7 @@ namespace FastCopy
1212
Boolean Selected;
1313

1414
Microsoft.UI.Xaml.Media.ImageSource Bitmap{ get; };
15+
16+
event Windows.Foundation.EventHandler<Boolean> SelectionChanged;
1517
}
1618
}

FastCopy/ReadableSizeConverter.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include "pch.h"
2+
#include "ReadableSizeConverter.h"
3+
#if __has_include("ReadableSizeConverter.g.cpp")
4+
#include "ReadableSizeConverter.g.cpp"
5+
#endif
6+
#include "ReadableUnitConverter.h"
7+
8+
namespace winrt::FastCopy::implementation
9+
{
10+
winrt::Windows::Foundation::IInspectable ReadableSizeConverter::Convert(
11+
winrt::Windows::Foundation::IInspectable const& value,
12+
winrt::Windows::UI::Xaml::Interop::TypeName const& targetType,
13+
winrt::Windows::Foundation::IInspectable const& parameter,
14+
winrt::hstring const& language)
15+
{
16+
return winrt::box_value(ReadableUnitConverter::Size::ToString<wchar_t>(winrt::unbox_value<uint64_t>(value)));
17+
}
18+
19+
winrt::Windows::Foundation::IInspectable ReadableSizeConverter::ConvertBack(
20+
winrt::Windows::Foundation::IInspectable const& value,
21+
winrt::Windows::UI::Xaml::Interop::TypeName const& targetType,
22+
winrt::Windows::Foundation::IInspectable const& parameter,
23+
winrt::hstring const& language)
24+
{
25+
throw std::exception{};
26+
}
27+
}

0 commit comments

Comments
 (0)