public GuidModuleItem AddData(Stream srm, string guid, string parent_guid, string f_name, byte[] file_data) { /* guid:(ascii) (crlf) parent-guid:(ascii) (crlf) f-name:(base64&utf8) (crlf) f-attributes:unimplementation (crlf) f-write-datetime:unimplementation (crlf) f-create-datetime:unimplementation (crlf) (crlf) (base64-76chars-each-crlf) (EOD-\0) */ // 現在は無条件でストリームの最後に追記する srm.Position = srm.Length; long lngLocation = srm.Position; string b64f_name = Base64EncodeText(f_name); GuidModuleKind mkKind = GuidModuleKind.File; // 追記する内容を準備する StringBuilder sbText = new StringBuilder(); sbText.Append(string.Format("{0}:{1}\r\n", "guid", guid)); sbText.Append(string.Format("{0}:{1}\r\n", "parent-guid", parent_guid)); sbText.Append(string.Format("{0}:{1}\r\n", "f-name", b64f_name)); sbText.Append("" + "\r\n"); if (file_data.Length == 0) { mkKind = GuidModuleKind.Folder; sbText.Append("" + "\r\n"); } else { mkKind = GuidModuleKind.File; Convert.ToBase64String(file_data, Base64FormattingOptions.InsertLineBreaks); } byte[] binary = System.Text.Encoding.UTF8.GetBytes(sbText.ToString()); // ストリームに追記する srm.Write(binary, 0, binary.Length); srm.WriteByte(0x00); // ヘッダを準備 GuidModuleItem gmiResult = new GuidModuleItem(); gmiResult.guid = guid; gmiResult.hash = ""; gmiResult.kind = mkKind; gmiResult.length = (UInt64)binary.Length; gmiResult.location = (UInt64)lngLocation; return gmiResult; }
void LoadGuid() { _guidList.Clear(); bool bFirst = true; if (System.IO.File.Exists(GUID_FILE) == false) return; string[] arLines = System.IO.File.ReadAllLines(GUID_FILE); string[] arHeader = null; foreach(string strLine in arLines) { string[] arFields = strLine.Split('\t'); if (bFirst) { bFirst = false; arHeader = arFields; } else { GuidModuleItem gmi = new GuidModuleItem(); for (int i = 0; i < arHeader.Length; i++) { string name = arHeader[i]; string value = arFields[i]; switch(name.ToUpper()) { case "GUID": gmi.guid = value; break; case "KIND": gmi.kind = ToModuleKind(value.ToUpper()); break; case "LOCATION": gmi.location = UInt64.Parse(value); break; case "LENGTH": gmi.length = UInt64.Parse(value); break; case "HASH": gmi.hash = value; break; } } _guidList.Add(gmi); } } }