Skip to content

Commit

Permalink
Add project files.
Browse files Browse the repository at this point in the history
  • Loading branch information
Patryk Kościk authored and Patryk Kościk committed Aug 20, 2021
1 parent 3d2d595 commit bfa2efd
Show file tree
Hide file tree
Showing 8 changed files with 270 additions and 0 deletions.
9 changes: 9 additions & 0 deletions App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Application x:Class="iCloud_Duplicate_Remover.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:iCloud_Duplicate_Remover"
StartupUri="MainWindow.xaml">
<Application.Resources>

</Application.Resources>
</Application>
17 changes: 17 additions & 0 deletions App.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;

namespace iCloud_Duplicate_Remover
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}
}
10 changes: 10 additions & 0 deletions AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Windows;

[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]
41 changes: 41 additions & 0 deletions MainWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<Window x:Class="ImageViewerFolder.MainWindow"
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:ImageViewerFolder"
mc:Ignorable="d"
Title="iCloud Live Photos Remover" Height="470" Width="800"
ResizeMode="CanMinimize">
<Grid Margin="10">

<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>

<StackPanel Grid.Column="0">
<!--Folder browse button-->
<StackPanel Margin="5,5,5,5" Orientation="Horizontal" Height="40" Background="White">
<Label Height="auto" Content="Choose folder:" VerticalAlignment="Center"/>
<Label x:Name="FolderDir" Height="auto" VerticalAlignment="Center"/>
<Button x:Name="BrowseButton" Height="25" Width="50" Content="Browse" Click="BrowseButton_Click"/>
<Button x:Name="RemoveButton" Height="25" Width="50" Content="Remove" Click="RemoveButton_Click" Margin="5,0,0,0" Visibility="Hidden"/>
</StackPanel>

<!--Folder items list-->

<ListBox Margin="5,5,5,5" Height="330" x:Name="DirBox" SelectionChanged="DirBox_SelectionChanged"/>

<StackPanel Orientation="Horizontal" Margin="5,0,0,0">
<Label Content="Search in: "/>
<RadioButton Content="Root folder only" VerticalAlignment="Center" Margin="5,5,5,5" IsChecked="True" x:Name="RootOnly" Click="RootOnly_Click"/>
<RadioButton Content="Root and subfolders" VerticalAlignment="Center" Margin="5,5,5,5" x:Name="RootSub" Click="RootSub_Click"/>
</StackPanel>

</StackPanel>

<Image Grid.Column="1" Margin="5,5,5,5" x:Name="ImgBox"/>

</Grid>
</Window>
153 changes: 153 additions & 0 deletions MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Imaging;
using Ookii.Dialogs.Wpf;

namespace ImageViewerFolder
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private string folderPath;
private bool searchSubs;

private static readonly string ImageExtension = ".JPG";
private static readonly string MovieExtension = ".MOV";

private List<string> intersection = new();

public MainWindow()
{
InitializeComponent();
searchSubs = false;
folderPath = "TEMP_PLACEHOLDER_NULL";
}

private void BrowseButton_Click(object sender, RoutedEventArgs e)
{
VistaFolderBrowserDialog folderDialog = new VistaFolderBrowserDialog();

bool? result = folderDialog.ShowDialog();

if (result.HasValue && result.Value)
{
folderPath = folderDialog.SelectedPath;
FolderDir.Content = folderPath;
UpdateList();
}

}

private void RootOnly_Click(object sender, RoutedEventArgs e)
{
searchSubs = false;
if (folderPath != "TEMP_PLACEHOLDER_NULL")
{
UpdateList();
}
}

private void RootSub_Click(object sender, RoutedEventArgs e)
{
searchSubs = true;
if (folderPath != "TEMP_PLACEHOLDER_NULL")
{
UpdateList();
}
}

private void RemoveButton_Click(object sender, RoutedEventArgs e)
{
int count = 0;

foreach (string f in intersection)
{
System.IO.File.Delete(f + MovieExtension);
count++;
UpdateList();
}

string info = "Removed: " + count.ToString() + " movies.";
_ = MessageBox.Show(info);
}

private void DirBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
ImgBox.Source = null;
if (DirBox.Items.Count > 0)
{
string imgPath = e.AddedItems[0].ToString();

BitmapImage bitmap = new();
bitmap.BeginInit();
bitmap.UriSource = new Uri(imgPath);
bitmap.EndInit();

ImgBox.Source = bitmap;
}
}

private void UpdateList()
{
DirBox.Items.Clear();

List<string> imgList = new List<string>();
List<string> movList = new List<string>();

List<string> files = new List<string>();

try
{

if (!searchSubs)
{
files = Directory.GetFiles(folderPath).ToList();
}

if (searchSubs)
{
files = Directory.GetFiles(folderPath, "*", SearchOption.AllDirectories).ToList();
}

foreach (string f in files.ToList())
{

if (ImageExtension.Contains(System.IO.Path.GetExtension(f).ToUpperInvariant()))
{
imgList.Add(f.Split('.')[0]);
}
else if (MovieExtension.Contains(System.IO.Path.GetExtension(f).ToUpperInvariant()))
{
movList.Add(f.Split('.')[0]);
}
}

intersection = imgList.Select(i => i.ToString()).Intersect(movList).ToList();


foreach (var f in intersection)
{
_ = DirBox.Items.Add(f + ".JPG");
}

if (DirBox.Items.Count > 0)
RemoveButton.Visibility = Visibility.Visible;
else
RemoveButton.Visibility = Visibility.Hidden;


}
catch (UnauthorizedAccessException)
{
_ = MessageBox.Show($"UnauthorizedAccessException");
}

}
}
}
15 changes: 15 additions & 0 deletions iCloud Duplicate Remover.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net5.0-windows</TargetFramework>
<RootNamespace>iCloud_Duplicate_Remover</RootNamespace>
<UseWPF>true</UseWPF>
<ApplicationIcon>iCloud.ico</ApplicationIcon>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Ookii.Dialogs.Wpf" Version="3.1.0" />
</ItemGroup>

</Project>
25 changes: 25 additions & 0 deletions iCloud Duplicate Remover.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31424.327
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "iCloud Duplicate Remover", "iCloud Duplicate Remover.csproj", "{2685835E-839D-491E-BE05-574A897717A2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{2685835E-839D-491E-BE05-574A897717A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2685835E-839D-491E-BE05-574A897717A2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2685835E-839D-491E-BE05-574A897717A2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2685835E-839D-491E-BE05-574A897717A2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {70EBD273-8551-45E7-A645-46B4B334BE70}
EndGlobalSection
EndGlobal
Binary file added iCloud.ico
Binary file not shown.

0 comments on commit bfa2efd

Please sign in to comment.