Skip to content

Commit

Permalink
Commit inicial
Browse files Browse the repository at this point in the history
  • Loading branch information
matheusbach committed Jun 20, 2021
1 parent 51e7686 commit e92928d
Show file tree
Hide file tree
Showing 10 changed files with 212 additions and 24 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
obj/
bin/
.vs
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="get_files_hash_checksum.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:get_files_hash_checksum"
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 get_files_hash_checksum
{
/// <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)
)]
24 changes: 0 additions & 24 deletions LICENSE

This file was deleted.

27 changes: 27 additions & 0 deletions MainWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Window x:Class="get_files_hash_checksum.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Title="File hash checksum" Height="450" Width="800">

<Grid>
<DockPanel Margin="10">
<WrapPanel HorizontalAlignment="Center" Orientation="Horizontal" DockPanel.Dock="Top" Margin="0,0,0,10">
<Button Name="btnGetDirectory" Click="btnGetDirectory_Click" Width="145" Height="25" Margin="10">Select files/directories</Button>
<WrapPanel Orientation="Vertical">
<WrapPanel Orientation="Horizontal" VerticalAlignment="Center" Margin="5">
<CheckBox Content="Start Patch" Margin="5,0,0,0" VerticalContentAlignment="Center" VerticalAlignment="Center" IsChecked="{Binding startPathCkecked}"/>
<TextBox TextWrapping="Wrap" Width="365" Margin="5,0,0,0" VerticalContentAlignment="Center" VerticalAlignment="Center" Text="{Binding startPath}"/>
</WrapPanel>
<WrapPanel Orientation="Horizontal" VerticalAlignment="Center" Margin="5">
<CheckBox Content="Base Download Link" Margin="5,0,0,0" VerticalContentAlignment="Center" VerticalAlignment="Center" IsChecked="{Binding startDlLinkCkecked}"/>
<TextBox TextWrapping="Wrap" Width="315" Margin="5,0,0,0" VerticalContentAlignment="Center" VerticalAlignment="Center" Text="{Binding startDlLink}"/>
</WrapPanel>
</WrapPanel>
</WrapPanel>
<TextBox Name="textBoxResult" Text="{Binding stringResult}" />
</DockPanel>
</Grid>
</Window>
86 changes: 86 additions & 0 deletions MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
using Microsoft.Win32;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;


namespace get_files_hash_checksum
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
DataContext = this;
}

public bool startPathCkecked { get; set; } = false;
public bool startDlLinkCkecked { get; set; } = false;
public string startPath { get; set; } = @"C:\";
public string startDlLink { get; set; } = @"https://";
public OpenFileDialog selectedFiles { get; set; } = null;
public string stringResult { get; set; } = "Select files to show result";


private void btnGetDirectory_Click(object sender, RoutedEventArgs e)
{
ListOfFiles.Clear();

OpenFileDialog openFileDialog = new OpenFileDialog() { Multiselect = true, CheckFileExists = true, CheckPathExists = true, Title = "Select what you want to checksum", InitialDirectory = startPathCkecked && Directory.Exists(startPath) ? startPath : null};
if (openFileDialog.ShowDialog() == true)
{
selectedFiles = openFileDialog;

foreach(string filePath in openFileDialog.FileNames)
{
ListOfFiles.Add(new FileParameters() { DlLink = startDlLinkCkecked && Uri.IsWellFormedUriString(startDlLink, UriKind.Absolute) && File.Exists(filePath) && startPathCkecked && Directory.Exists(startPath) ? new Uri(new Uri(startDlLink, UriKind.Absolute), Path.GetRelativePath(startPath + '/', filePath), false).AbsoluteUri : null, FileName = Path.GetFileName(filePath), Path = startPathCkecked ? Directory.Exists(startPath) ? Path.GetRelativePath(startPath, filePath).Replace(@"//", @"/").Replace(@"\\", @"\").Replace(@"\", @"/") : null : Directory.Exists(startPath) ? Path.GetFullPath(filePath) : null, Sha256 = File.Exists(filePath) ? FileSHA256(filePath) : null }); ;
}

textBoxResult.Text = JsonConvert.SerializeObject(ListOfFiles, Formatting.Indented);
MessageBox.Show(JsonConvert.SerializeObject(ListOfFiles, Formatting.Indented));
}
}

public static string FileSHA256(string filePath)
{
using System.Security.Cryptography.SHA256 hashAlgorithm = System.Security.Cryptography.SHA256.Create();
using (FileStream stream = System.IO.File.OpenRead(filePath))
{
return BitConverter.ToString(hashAlgorithm.ComputeHash(stream)).Replace("-", "").ToUpper();
}
}


public static List<FileParameters> ListOfFiles { get; set; } = new();
public partial class FileParameters
{
[JsonProperty("dlLink", NullValueHandling = NullValueHandling.Ignore)]
public string DlLink { get; set; }

[JsonProperty("path", NullValueHandling = NullValueHandling.Ignore)]
public string Path { get; set; }

[JsonProperty("fileName", NullValueHandling = NullValueHandling.Ignore)]
public string FileName { get; set; }

[JsonProperty("sha256", NullValueHandling = NullValueHandling.Ignore)]
public string Sha256 { get; set; }
}
}
}
21 changes: 21 additions & 0 deletions get-files-hash-checksum.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net5.0-windows</TargetFramework>
<RootNamespace>get_files_hash_checksum</RootNamespace>
<UseWPF>true</UseWPF>

</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<PlatformTarget>x86</PlatformTarget>
<Prefer32Bit>true</Prefer32Bit>
<DefineConstants />
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>

</Project>
14 changes: 14 additions & 0 deletions get-files-hash-checksum.csproj.user
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
<ItemGroup>
<ApplicationDefinition Update="App.xaml">
<SubType>Designer</SubType>
</ApplicationDefinition>
</ItemGroup>
<ItemGroup>
<Page Update="MainWindow.xaml">
<SubType>Designer</SubType>
</Page>
</ItemGroup>
</Project>
25 changes: 25 additions & 0 deletions get-files-hash-checksum.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.31402.337
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "get-files-hash-checksum", "get-files-hash-checksum.csproj", "{75CBD968-A7D1-4789-9623-7211AA908147}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{75CBD968-A7D1-4789-9623-7211AA908147}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{75CBD968-A7D1-4789-9623-7211AA908147}.Debug|Any CPU.Build.0 = Debug|Any CPU
{75CBD968-A7D1-4789-9623-7211AA908147}.Release|Any CPU.ActiveCfg = Release|Any CPU
{75CBD968-A7D1-4789-9623-7211AA908147}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C152D84E-E966-4CCA-917A-4B4F7652A954}
EndGlobalSection
EndGlobal

0 comments on commit e92928d

Please sign in to comment.