OSDN Git Service

Some improvements to the Microsoft.NET bindings.
authorLoRd_MuldeR <mulder2@gmx.de>
Sun, 20 Mar 2016 22:33:42 +0000 (23:33 +0100)
committerLoRd_MuldeR <mulder2@gmx.de>
Sun, 20 Mar 2016 22:33:42 +0000 (23:33 +0100)
Make.cmd
bindings/Microsoft.NET/MHashDotNet384.Example/MHashDotNet384.Example.csproj
bindings/Microsoft.NET/MHashDotNet384.Example/src/App.xaml
bindings/Microsoft.NET/MHashDotNet384.Example/src/MainWindow.xaml
bindings/Microsoft.NET/MHashDotNet384.Example/src/MainWindow.xaml.cs
bindings/Microsoft.NET/MHashDotNet384.Wrapper/MHashDotNet384.Wrapper.vcxproj

index 3124948..93b57dc 100644 (file)
--- a/Make.cmd
+++ b/Make.cmd
@@ -35,6 +35,10 @@ for %%i in (bin,obj) do (
        del /Q /S /F "%~dp0\%%i\*.*"
 )
 
+for %%i in (bin,MHashDotNet384.Example\obj,MHashDotNet384.Wrapper\obj) do (
+       del /Q /S /F "%~dp0\bindings\Microsoft.NET\%%i\*.*"
+)
+
 
 REM ///////////////////////////////////////////////////////////////////////////
 REM // Build the binaries
@@ -43,11 +47,13 @@ REM ///////////////////////////////////////////////////////////////////////////
 "%~dp0\tools\cecho" YELLOW "\n========[ COMPILE ]========\n"
 call "%MSVC_PATH%\vcvarsall.bat"
 
-for %%p in (x86,x64) do (
-       MSBuild.exe /property:Platform=%%p /property:Configuration=Release /target:Clean   "%~dp0\MHashLib.sln"
-       if not "!ERRORLEVEL!"=="0" goto BuildHasFailed
-       MSBuild.exe /property:Platform=%%p /property:Configuration=Release /target:Rebuild "%~dp0\MHashLib.sln"
-       if not "!ERRORLEVEL!"=="0" goto BuildHasFailed
+for %%q in (MHashLib.sln,bindings\Microsoft.NET\MHashDotNet384.sln) do (
+       for %%p in (x86,x64) do (
+               MSBuild.exe /property:Platform=%%p /property:Configuration=Release /target:Clean   "%~dp0\%%~q"
+               if not "!ERRORLEVEL!"=="0" goto BuildHasFailed
+               MSBuild.exe /property:Platform=%%p /property:Configuration=Release /target:Rebuild "%~dp0\%%~q"
+               if not "!ERRORLEVEL!"=="0" goto BuildHasFailed
+       )
 )
 
 
@@ -69,16 +75,20 @@ set COUNTER=
 set REVISON=
 
 :GenerateOutfileNameNext
-set "OUT_PATH_X86=%~dp0\out\mhash_384.%ISO_DATE%%REVISON%.msvc-x86.zip"
-set "OUT_PATH_X64=%~dp0\out\mhash_384.%ISO_DATE%%REVISON%.msvc-x64.zip"
-set "OUT_PATH_SRC=%~dp0\out\mhash_384.%ISO_DATE%%REVISON%.src.tar.gz"
+set "OUT_PATH_BIN_X86=%~dp0\out\mhash_384.%ISO_DATE%%REVISON%.bin-msvc-x86.zip"
+set "OUT_PATH_BIN_X64=%~dp0\out\mhash_384.%ISO_DATE%%REVISON%.bin-msvc-x64.zip"
+set "OUT_PATH_NET_X86=%~dp0\out\mhash_384.%ISO_DATE%%REVISON%.dotnet-x86.zip"
+set "OUT_PATH_NET_X64=%~dp0\out\mhash_384.%ISO_DATE%%REVISON%.dotnet-x64.zip"
+set "OUT_PATH_SRC_GEN=%~dp0\out\mhash_384.%ISO_DATE%%REVISON%.src.tar.gz"
 
 set /a COUNTER=COUNTER+1
 set REVISON=.update-%COUNTER%
 
-if exist "%OUT_PATH_X86%" goto GenerateOutfileNameNext
-if exist "%OUT_PATH_X64%" goto GenerateOutfileNameNext
-if exist "%OUT_PATH_SRC%" goto GenerateOutfileNameNext
+if exist "%OUT_PATH_BIN_X86%" goto GenerateOutfileNameNext
+if exist "%OUT_PATH_BIN_X64%" goto GenerateOutfileNameNext
+if exist "%OUT_PATH_NET_X86%" goto GenerateOutfileNameNext
+if exist "%OUT_PATH_NET_X64%" goto GenerateOutfileNameNext
+if exist "%OUT_PATH_SRC_GEN%" goto GenerateOutfileNameNext
 
 
 REM ///////////////////////////////////////////////////////////////////////////
@@ -87,10 +97,13 @@ REM ///////////////////////////////////////////////////////////////////////////
 
 "%~dp0\tools\cecho" YELLOW "\n========[ PACKAGING ]========\n"
 
-"%~dp0\tools\zip.exe" -j -9 -z "%OUT_PATH_X86%" "%~dp0\bin\Win32\Release\mhash_384.x86.exe" "%~dp0\README.html" "%~dp0\COPYING.txt" < "%~dp0\COPYING.txt"
-"%~dp0\tools\zip.exe" -j -9 -z "%OUT_PATH_X64%" "%~dp0\bin\x64\.\Release\mhash_384.x64.exe" "%~dp0\README.html" "%~dp0\COPYING.txt" < "%~dp0\COPYING.txt"
+"%~dp0\tools\zip.exe" -j -9 -z "%OUT_PATH_BIN_X86%" "%~dp0\bin\Win32\Release\mhash_384.x86.exe" "%~dp0\README.html" "%~dp0\COPYING.txt" < "%~dp0\COPYING.txt"
+"%~dp0\tools\zip.exe" -j -9 -z "%OUT_PATH_BIN_X64%" "%~dp0\bin\x64\.\Release\mhash_384.x64.exe" "%~dp0\README.html" "%~dp0\COPYING.txt" < "%~dp0\COPYING.txt"
+
+"%~dp0\tools\zip.exe" -j -9 -z "%OUT_PATH_NET_X86%" "%~dp0\bindings\Microsoft.NET\bin\x86\Release\MHashDotNet384.x86.dll" "%~dp0\bindings\Microsoft.NET\bin\x86\Release\MHashDotNet384.Example.exe" "%~dp0\README.html" "%~dp0\COPYING.txt" < "%~dp0\COPYING.txt"
+"%~dp0\tools\zip.exe" -j -9 -z "%OUT_PATH_NET_X64%" "%~dp0\bindings\Microsoft.NET\bin\x64\Release\MHashDotNet384.x64.dll" "%~dp0\bindings\Microsoft.NET\bin\x64\Release\MHashDotNet384.Example.exe" "%~dp0\README.html" "%~dp0\COPYING.txt" < "%~dp0\COPYING.txt"
 
-"%GIT2_PATH%\git.exe" archive --format tar.gz -9 --verbose --output "%OUT_PATH_SRC%" HEAD
+"%GIT2_PATH%\git.exe" archive --format tar.gz -9 --verbose --output "%OUT_PATH_SRC_GEN%" HEAD
 
 
 REM ///////////////////////////////////////////////////////////////////////////
index c38a9c9..4f7f47e 100644 (file)
@@ -73,6 +73,9 @@
   <PropertyGroup>
     <ApplicationIcon>exe.ico</ApplicationIcon>
   </PropertyGroup>
+  <PropertyGroup>
+    <StartupObject>MHashDotNet384.Example.App</StartupObject>
+  </PropertyGroup>
   <ItemGroup>
     <Reference Include="System" />
     <Reference Include="System.Data" />
index 791d2d4..041b433 100644 (file)
@@ -2,7 +2,7 @@
              xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
              xmlns:local="clr-namespace:MHashDotNet384.Example"
-             StartupUri="MainWindow.xaml">
+             StartupUri="src/MainWindow.xaml">
     <Application.Resources>
          
     </Application.Resources>
index 9a15634..624b12e 100644 (file)
@@ -5,13 +5,15 @@
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
         xmlns:local="clr-namespace:MHashDotNet384.Example"
         mc:Ignorable="d"
-        Title="MHashDotNet384 - Example App" Height="192" Width="768"
-        WindowStartupLocation="CenterScreen" WindowStyle="ToolWindow" ResizeMode="CanMinimize" Loaded="Window_Loaded">
+        Title="MHashDotNet384 - Example App" Height="224" Width="768"
+        WindowStartupLocation="CenterScreen" WindowStyle="ToolWindow" ResizeMode="CanMinimize" 
+        Loaded="Window_Loaded" Closing="Window_Closing">
     <DockPanel Margin="8">
         <TextBlock DockPanel.Dock="Top" FontWeight="Bold">Input File:</TextBlock>
         <TextBox DockPanel.Dock="Top" IsReadOnly="True" Name="Edit_FileName"></TextBox>
         <TextBlock DockPanel.Dock="Top" FontWeight="Bold" Margin="0,12,0,0">Hash Value (Digest):</TextBlock>
         <TextBox DockPanel.Dock="Top"  Name="Edit_HashValue" FontFamily="Courier New" IsReadOnly="True"></TextBox>
+        <ProgressBar DockPanel.Dock="Top" Height="18" Name="ProgressIndicator" Margin="0,16,0,0" Minimum="0" Maximum="1"></ProgressBar>
         <Grid DockPanel.Dock="Bottom" Margin="0,16,0,0">
             <Grid.ColumnDefinitions>
                 <ColumnDefinition Width="*"/>
index 2b14f61..ad02662 100644 (file)
@@ -1,6 +1,7 @@
 using Microsoft.Win32;
 using System;
 using System.Collections.Generic;
+using System.ComponentModel;
 using System.IO;
 using System.Text;
 using System.Windows;
@@ -33,6 +34,14 @@ namespace MHashDotNet.Example
             Title += String.Format(" v{0:D}.{1:D}.{2:D}", major, minor, patch);
         }
 
+        private void Window_Closing(object sender, CancelEventArgs e)
+        {
+            if(!(Button_Browse.IsEnabled && Button_Compute.IsEnabled))
+            {
+                e.Cancel = true;
+            }
+        }
+
         private void Button_BrowseClick(object sender, RoutedEventArgs e)
         {
             OpenFileDialog dialog = new OpenFileDialog();
@@ -46,20 +55,31 @@ namespace MHashDotNet.Example
 
         private void Button_ComputeClick(object sender, RoutedEventArgs e)
         {
-            Edit_HashValue.Text = String.Empty;
-            Label_Working.Visibility = Visibility.Visible;
-            Button_Browse.IsEnabled = Button_Compute.IsEnabled = false;
-            Mouse.OverrideCursor = Cursors.Wait;
+            if(String.IsNullOrWhiteSpace(Edit_FileName.Text))
+            {
+                MessageBox.Show("Please select an input file first!", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
+                return;
+            }
             try
             {
-                byte[] buffer = new byte[4096];
-                using (FileStream fs = File.OpenRead(Edit_FileName.Text))
+                Edit_HashValue.Text = String.Empty;
+                ProgressIndicator.Value = 0.0;
+                Label_Working.Visibility = Visibility.Visible;
+                Button_Browse.IsEnabled = Button_Compute.IsEnabled = false;
+                Mouse.OverrideCursor = Cursors.Wait; FileInfo info = new FileInfo(Edit_FileName.Text);
+                using (FileStream fs = info.OpenRead())
                 {
                     using (MHashDotNet.MHash384 digest = new MHashDotNet.MHash384())
                     {
+                        short update = 0;
+                        byte[] buffer = new byte[4096];
                         while (true)
                         {
-                            Dispatcher.Invoke(new Action(() => {}), DispatcherPriority.ContextIdle, null);
+                            if((update++ & 0x3FF) == 0)
+                            {
+                                ProgressIndicator.Value = (double)fs.Position / (double)info.Length;
+                                DispatchPendingEvents();
+                            }
                             int count = fs.Read(buffer, 0, buffer.Length);
                             if (count > 0)
                             {
@@ -78,10 +98,18 @@ namespace MHashDotNet.Example
             }
             finally
             {
+                ProgressIndicator.Value = 1.0;
                 Label_Working.Visibility = Visibility.Hidden;
                 Button_Browse.IsEnabled = Button_Compute.IsEnabled = true;
                 Mouse.OverrideCursor = null;
             }
         }
+
+        private readonly Action dummyAction = new Action(() => { });
+
+        private void DispatchPendingEvents()
+        {
+            Dispatcher.Invoke(dummyAction, DispatcherPriority.ContextIdle, null);
+        }
     }
 }
index 367b830..979c104 100644 (file)
@@ -24,6 +24,7 @@
     <Keyword>ManagedCProj</Keyword>
     <RootNamespace>MHashDotNet384</RootNamespace>
     <ProjectName>MHashDotNet384.Wrapper</ProjectName>
+    <WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
   </PropertyGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
   <PropertyGroup Label="UserMacros" />
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
     <LinkIncremental>true</LinkIncremental>
-    <OutDir>$(SolutionDir)\bin\$(Platform)\$(Configuration)\</OutDir>
-    <IntDir>$(ProjectDir)\obj\$(Platform)\$(Configuration)\</IntDir>
-    <TargetName>MHashDotNet384.$(Platform)</TargetName>
+    <OutDir>$(SolutionDir)\bin\$(PlatformShortName)\$(Configuration)\</OutDir>
+    <IntDir>$(ProjectDir)\obj\$(PlatformShortName)\$(Configuration)\</IntDir>
+    <TargetName>MHashDotNet384.$(PlatformShortName)</TargetName>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
     <LinkIncremental>true</LinkIncremental>
-    <OutDir>$(SolutionDir)\bin\$(Platform)\$(Configuration)\</OutDir>
-    <IntDir>$(ProjectDir)\obj\$(Platform)\$(Configuration)\</IntDir>
-    <TargetName>MHashDotNet384.$(Platform)</TargetName>
+    <OutDir>$(SolutionDir)\bin\$(PlatformShortName)\$(Configuration)\</OutDir>
+    <IntDir>$(ProjectDir)\obj\$(PlatformShortName)\$(Configuration)\</IntDir>
+    <TargetName>MHashDotNet384.$(PlatformShortName)</TargetName>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
     <LinkIncremental>false</LinkIncremental>
-    <OutDir>$(SolutionDir)\bin\$(Platform)\$(Configuration)\</OutDir>
-    <IntDir>$(ProjectDir)\obj\$(Platform)\$(Configuration)\</IntDir>
-    <TargetName>MHashDotNet384.$(Platform)</TargetName>
+    <OutDir>$(SolutionDir)\bin\$(PlatformShortName)\$(Configuration)\</OutDir>
+    <IntDir>$(ProjectDir)\obj\$(PlatformShortName)\$(Configuration)\</IntDir>
+    <TargetName>MHashDotNet384.$(PlatformShortName)</TargetName>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
     <LinkIncremental>false</LinkIncremental>
-    <OutDir>$(SolutionDir)\bin\$(Platform)\$(Configuration)\</OutDir>
-    <IntDir>$(ProjectDir)\obj\$(Platform)\$(Configuration)\</IntDir>
-    <TargetName>MHashDotNet384.$(Platform)</TargetName>
+    <OutDir>$(SolutionDir)\bin\$(PlatformShortName)\$(Configuration)\</OutDir>
+    <IntDir>$(ProjectDir)\obj\$(PlatformShortName)\$(Configuration)\</IntDir>
+    <TargetName>MHashDotNet384.$(PlatformShortName)</TargetName>
   </PropertyGroup>
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
     <ClCompile>