/// <summary> /// д��һ������ /// </summary> /// <returns></returns> public bool SaveData(string url, string dat) { nSearch.DebugShow.ClassDebugShow.WriteLine(" FileSystem SaveData--> " + url); if (FS_URL.Contains(url) == true) { return false; //�Ѿ����� } //�õ����ݵ�MD5�� string MD5_IT = getMD5name(dat).ToUpper(); // if (FS_D_MD5.Contains(MD5_IT) == true) int id_one = -1; FS_D_MD5.BinarySearch(MD5_IT); for(int iii =0;iii<FS_D_MD5.Count ;iii++) { if (MD5_IT == (string)FS_D_MD5[iii]) { id_one = iii; break; } } if (id_one > -1) { //�Ѿ����� oneFS one = (oneFS)FS_D_D[id_one]; one.url = url; FS_URL.Add(url); FS_D_D.Add(one); FS_D_MD5.Add(one.md5); if (one.file == NowFileName) { //�����ڵ�ǰ��δд�������� ֱ���������� //�ҵ� NowFile.Add(one); } else { //������д����������� //д���ļ����� ��ʼ + ���� + Md5 + Url StreamWriter writer = null; try { writer = new StreamWriter(mDirPath + one.file +".IDX", true, System.Text.Encoding.GetEncoding("gb2312")); writer.WriteLine(one.str.ToString() + "\t" + one.len.ToString() + "\t" + one.md5 + "\t" + url); writer.Close(); } catch (IOException e) { if (writer != null) writer.Close(); } } return true; } else { //����д�� ���� oneFS one3 = new oneFS(); byte[] uuD = fs_nCode.dbsCompress(dat); if (uuD.Length + p_fs_mCache > mSize) { //���ݳ������� ������д�� SaveCache(); NowFileName = GetOneName(); } one3.file = NowFileName; one3.len = uuD.Length; one3.md5 = getMD5name(dat); one3.url = url; one3.str = p_fs_mCache; //ѹ�뻺�� for (int ipp = 0; ipp < uuD.Length; ipp++) { fs_mCache[p_fs_mCache + ipp] = uuD[ipp]; } p_fs_mCache = p_fs_mCache + uuD.Length; FS_URL.Add(url); FS_D_D.Add(one3); FS_D_MD5.Add(one3.md5); NowFile.Add(one3); return true; } }
/// <summary> /// ����ԭʼ���� /// </summary> public void InitData(string path) { if (path[path.Length - 1] != '\\') { mDirPath = path + "\\"; } else { mDirPath = path; } NowFileName = GetOneName(); p_fs_mCache = 0; NowFile.Clear(); fs_mCache = new byte[mSize]; fs_mCacheREAD = new byte[mSize]; /// <summary> /// ���Ƽ��� /// </summary> FS_URL.Clear(); /// <summary> /// �ļ�����MD5���� /// </summary> FS_D_MD5.Clear(); /// <summary> /// ���������������� /// </summary> FS_D_D.Clear(); DirectoryInfo dir = new DirectoryInfo(path); foreach (FileInfo f in dir.GetFiles("*.IDX")) //���������xmlΪ��չ�����ļ� { String namepath = f.FullName;//nameΪ���ļ����µ��ļ����ƣ���f.FullNameΪȫ�� string name2 = f.Name; // ��ʼ + ���� + Md5 + Url name2 = name2.Substring(0, name2.Length - 4); StreamReader reader = null; try { reader = new StreamReader(namepath, System.Text.Encoding.GetEncoding("gb2312")); for (string line = reader.ReadLine(); line != null; line = reader.ReadLine()) { line = line.Trim(); if (line.IndexOf('\t') > 0) { string[] nTmp = line.Split('\t');// ��ʼ + ���� + Md5 + Url string t_1 = nTmp[0];// ��ʼ string t_2 = nTmp[1];// ���� string t_3 = nTmp[2];// Md5 string t_4 = nTmp[3].Trim();// Url oneFS oneTmp = new oneFS(); oneTmp.file = name2; oneTmp.str = Int32.Parse(t_1); oneTmp.len = Int32.Parse(t_2); oneTmp.md5 = t_3; oneTmp.url = t_4; /// <summary> /// ���Ƽ��� /// </summary> FS_URL.Add(t_4); /// <summary> /// �ļ�����MD5���� /// </summary> FS_D_MD5.Add(t_3); /// <summary> /// ���������������� /// </summary> FS_D_D.Add(oneTmp); //ID URL ��Ӧ�� UrlNameIndex.Add(t_4); //�ļ����� FileNum = FileNum + 1; } } reader.Close(); } catch (IOException e) { nSearch.DebugShow.ClassDebugShow.WriteLineF(e.Message); } finally { if (reader != null) reader.Close(); } } }