Beispiel #1
0
        // result.Value:
        //      -1  出错
        //      0   不匹配
        //      1   匹配
        // exception:
        //      可能会抛出异常
        public static NormalResult CheckMD5(
            this LibraryChannel channel,
            Stop stop,
            string strServerFilePath,
            string strLocalFilePath)
        {
            // 检查 MD5
            // return:
            //      -1  出错
            //      0   文件没有找到
            //      1   文件找到
            int nRet = DynamicDownloader.GetServerFileMD5(
                channel,
                stop,   // this.Stop,
                strServerFilePath,
                out byte[] server_md5,
                out string strError);

            if (nRet != 1)
            {
                strError = "探测服务器端文件 '" + strServerFilePath + "' MD5 时出错: " + strError;
                return(new NormalResult(-1, strError));
            }

            using (FileStream stream = File.OpenRead(strLocalFilePath))
            {
                stream.Seek(0, SeekOrigin.Begin);
                byte[] local_md5 = DynamicDownloader.GetFileMd5(stream);
                if (ByteArray.Compare(server_md5, local_md5) != 0)
                {
                    strError = "服务器端文件 '" + strServerFilePath + "' 和本地文件 '" + strLocalFilePath + "' MD5 不匹配";
                    return(new NormalResult(0, strError));
                }
            }

            return(new NormalResult(1, null));
        }
Beispiel #2
0
        // result.Value:
        //      -1  出错
        //      0   不匹配
        //      1   匹配
        // exception:
        //      可能会抛出异常
        public static NormalResult CheckMD5(
            this LibraryChannel channel,
            Stop stop,
            string strServerFilePath,
            string strLocalFilePath,
            delegate_prompt prompt_func)
        {
            // stop 对中断 MD5 会起作用
            Debug.Assert(stop != null, "");

            // 2020/2/26 改为 ...ByTask()
            // 检查 MD5
            // return:
            //      -1  出错
            //      0   文件没有找到
            //      1   文件找到
            int nRet = DynamicDownloader.GetServerFileMD5ByTask(
                channel,
                stop,   // this.Stop,
                strServerFilePath,

                /*
                 * new MessagePromptEventHandler(delegate (object o1, MessagePromptEventArgs e1)
                 * {
                 *  //转换为 prompt_func 发生作用
                 * }),
                 */
                (o1, e1) =>
            {
                if (prompt_func == null)
                {
                    e1.ResultAction = "cancel";
                    return;
                }

                string[] buttons = e1.Actions.Split(new char[] { ',' });
                //转换为 prompt_func 发生作用
                e1.ResultAction = prompt_func(channel, e1.MessageText, buttons, 20);
            },
                new System.Threading.CancellationToken(),
                out byte[] server_md5,
                out string strError);;

            if (nRet != 1)
            {
                strError = "探测服务器端文件 '" + strServerFilePath + "' MD5 时出错: " + strError;
                return(new NormalResult(-1, strError));
            }

            using (FileStream stream = File.OpenRead(strLocalFilePath))
            {
                stream.Seek(0, SeekOrigin.Begin);
                byte[] local_md5 = DynamicDownloader.GetFileMd5(stream);
                if (ByteArray.Compare(server_md5, local_md5) != 0)
                {
                    strError = "服务器端文件 '" + strServerFilePath + "' 和本地文件 '" + strLocalFilePath + "' MD5 不匹配";
                    return(new NormalResult(0, strError));
                }
            }

            return(new NormalResult(1, null));
        }