Skip to content

Commit

Permalink
获取 md5 工具
Browse files Browse the repository at this point in the history
  • Loading branch information
YukiCoco committed Jan 17, 2020
1 parent d5125b7 commit 8b6780c
Show file tree
Hide file tree
Showing 5 changed files with 150 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/GetMd5/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>
53 changes: 53 additions & 0 deletions src/GetMd5/GetMd5.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{3B11A3C8-F357-4CFC-92F3-A6D0F6E11C8D}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>GetMd5</RootNamespace>
<AssemblyName>GetMd5</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
49 changes: 49 additions & 0 deletions src/GetMd5/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace GetMd5
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("输入 mods 文件夹");
string directory = Console.ReadLine();
string md5 = GetDirectoryMd5(directory);
string[] filesPath = Directory.GetFiles(directory);
File.WriteAllText("md5.txt", md5);
Console.WriteLine("已在目录创建 md5.txt ,按任意键退出");
Console.ReadKey();
}

/// <summary>
/// 获取文件夹下所有文件的 md5
/// </summary>
/// <param name="dirPath"></param>
/// <returns></returns>
public static string GetDirectoryMd5(string dirPath)
{
string[] filesPath = Directory.GetFiles(dirPath);
List<string> filesMd5 = new List<string>();
for (int i = 0; i < filesPath.Length; i++)
{
//这里引用了作者在 MD5Checker 类里的方法
//获取 md5
FileStream file = new FileStream(filesPath[i], FileMode.Open);
MD5 md5 = new MD5CryptoServiceProvider();//创建SHA1对象
byte[] md5Bytes = md5.ComputeHash(file);//Hash运算
md5.Dispose();//释放当前实例使用的所有资源
file.Dispose();
string result = BitConverter.ToString(md5Bytes);//将运算结果转为string类型
result = result.Replace("-", "");
filesMd5.Add(result);
}
return String.Join(",", filesMd5.ToArray());
}
}
}
36 changes: 36 additions & 0 deletions src/GetMd5/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("GetMd5")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("GetMd5")]
[assembly: AssemblyCopyright("Copyright © 2020")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]

// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("3b11a3c8-f357-4cfc-92f3-a6d0f6e11c8d")]

// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
6 changes: 6 additions & 0 deletions src/NsisoLauncher.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "NsisoLauncherCore", "NsisoL
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NsisoLauncher.Test", "NsisoLauncher.Test\NsisoLauncher.Test.csproj", "{99AF489E-FD2D-4E64-B470-70ADA4E3E591}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GetMd5", "GetMd5\GetMd5.csproj", "{3B11A3C8-F357-4CFC-92F3-A6D0F6E11C8D}"
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
NsisoLauncherCore\NsisoLauncherCore.projitems*{14e2fa92-77f6-4bff-9654-38fa29034aa9}*SharedItemsImports = 13
Expand All @@ -28,6 +30,10 @@ Global
{99AF489E-FD2D-4E64-B470-70ADA4E3E591}.Debug|Any CPU.Build.0 = Debug|Any CPU
{99AF489E-FD2D-4E64-B470-70ADA4E3E591}.Release|Any CPU.ActiveCfg = Release|Any CPU
{99AF489E-FD2D-4E64-B470-70ADA4E3E591}.Release|Any CPU.Build.0 = Release|Any CPU
{3B11A3C8-F357-4CFC-92F3-A6D0F6E11C8D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3B11A3C8-F357-4CFC-92F3-A6D0F6E11C8D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3B11A3C8-F357-4CFC-92F3-A6D0F6E11C8D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3B11A3C8-F357-4CFC-92F3-A6D0F6E11C8D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down

0 comments on commit 8b6780c

Please sign in to comment.