public static bool MakeEncodingList(String strPath) { RepositoryFile.Clear(); DirectoryInfo strDirectory = new DirectoryInfo(strPath); GetDirectory(strDirectory, RepositoryFile); if (RepositoryFile.Count < 1) { return(false); } m_nMaxCount = 0; m_nCurrentCount = 0; foreach (KeyValuePair <String, RepositoryList> _pair in RepositoryFile) { m_nMaxCount += _pair.Value.m_list_file.Count; } String strMakeFileName = strPath + "/" + FILENAME; FileStream fs = null; try { fs = new FileStream(strMakeFileName, FileMode.Create); StreamWriter writer = new StreamWriter(fs, Encoding.UTF8); writer.BaseStream.Seek(0, SeekOrigin.Begin); foreach (KeyValuePair <String, RepositoryList> _pair in RepositoryFile) { foreach (String strFile in _pair.Value.m_list_file) { if (FILENAME == strFile) { continue; } String strInsertPath = _pair.Key; strInsertPath = strInsertPath.Replace(strPath, ""); strInsertPath = strInsertPath.Replace('\\', '/'); if (strInsertPath.StartsWith("/")) { strInsertPath = strInsertPath.Substring(1, strInsertPath.Length - 1) + "/"; } writer.WriteLine(strInsertPath + strFile + "=" + ComputeMD5Hash(_pair.Key + "/" + strFile)); m_nCurrentCount++; } } writer.Flush(); writer.Close(); } catch { } finally { if (fs != null) { fs.Close(); } } return(true); }
public static bool MakeEncodingList(Dictionary <string, MyUpdateStruct> serverFile, String strPath, string mdfilename) { RepositoryFile.Clear(); DirectoryInfo strDirectory = new DirectoryInfo(strPath); GetDirectory(strDirectory, RepositoryFile); if (RepositoryFile.Count < 1) { return(false); } m_nMaxCount = serverFile.Count; m_nCurrentCount = 0; if (m_nMaxCount > 0) { string strMakeFileName = strPath + "/" + mdfilename; FileStream fs = null; try { fs = new FileStream(strMakeFileName, FileMode.Create); StreamWriter writer = new StreamWriter(fs, Encoding.UTF8); writer.BaseStream.Seek(0, SeekOrigin.Begin); int index = 0; foreach (var myUpdateStruct in serverFile) { var filename = myUpdateStruct.Key; String strInsertPath = strPath + filename; index++; //string text = string.Format("当前本地校验文件第{0}/{1}个", index, m_nMaxCount); if (File.Exists(strInsertPath)) { var format = filename + "=" + ComputeMD5Hash(strInsertPath); writer.WriteLine(format); } else { var format = filename + "=null"; writer.WriteLine(format); } m_nCurrentCount++; } writer.Flush(); writer.Close(); } catch (Exception e) { // ignored MessageBox.Show("客户端文件列表检查失败," + e.Message, "MD5Error", MessageBoxButtons.OK); } finally { if (fs != null) { fs.Close(); } } } else { return(false); } return(true); }