zoukankan      html  css  js  c++  java
  • 转 这种方法可以免去自己计算大文件md5 的麻烦

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEditor;
    using System.IO;
    using System;
    using System.Text;

    public class Md5 : Editor
    {
    [MenuItem("Md5/Generate Md5")]
    public static void Generate_Md5()
    {
    //创建一个controller
    //AnimatorController mAnimatorController = AnimatorController.CreateAnimatorControllerAtPath("Assets/Resources/Animator/ani.controller");
    //EditorUtility.DisplayDialog("Select Texture", "You must select a texture first!", "OK");
    string path = EditorUtility.OpenFolderPanel("Choose Directory Path Plz!!!","","");
    RecursiveDirectory(path);
    }
    static void RecursiveDirectory(string path)
    {
    if (Directory.Exists(path))
    {
    DirectoryInfo dInfo = new DirectoryInfo(path);
    FileInfo[] files = dInfo.GetFiles("*", SearchOption.AllDirectories);
    Debug.Log("RecursiveDirectory file length " + files.Length);
    for (int i = 0; i < files.Length; ++i)
    {
    if (files[i].Name.EndsWith(".meta"))
    continue;
    Debug.Log("RecursiveDirectory Files Name " + files[i].Name + " Md5: "+ GetMd5(files[i].FullName));
    }
    }
    }
    static string GetMd5(string path)
    {
    try
    {
    FileStream fs = new FileStream(path, FileMode.Open);
    System.Security.Cryptography.MD5 md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
    byte[] retVal = md5.ComputeHash(fs);
    fs.Close();
    System.Text.StringBuilder sb = new StringBuilder();
    for (int i = 0; i < retVal.Length; ++i)
    {
    sb.Append(retVal[i].ToString("x2"));
    }
    return sb.ToString();
    }
    catch (Exception ex)
    {
    throw new Exception("GetMd5 Exception error: " + ex.Message);
    }
    }
    }

  • 相关阅读:
    【洛谷P1119】灾后重建
    【洛谷P1462】通往奥格瑞玛的道路
    【洛谷P1991】无线通讯网
    poj 2892(二分+树状数组)
    hdu 1541(树状数组)
    hdu 5059(模拟)
    hdu 5056(尺取法思路题)
    poj 2100(尺取法)
    hdu 2739(尺取法)
    poj 3320(尺取法)
  • 原文地址:https://www.cnblogs.com/rexzhao/p/7590526.html
Copyright © 2011-2022 走看看