/// <summary> /// 上传附件 /// </summary> /// <param name="header">上传的附件头</param> /// <param name="path">附件所在的路径</param> /// <returns></returns> public CommandResult Upload(AttachmentHeader header, string path) { try { if (!File.Exists(path)) { return(new CommandResult(ResultCode.Fail, string.Format("文件\"{0}\"不存在", path))); } byte[] bs = null; using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read)) { if (fs.Length <= MAXFILENAME) { bs = new byte[fs.Length]; fs.Position = 0; fs.Read(bs, 0, (int)fs.Length); IUnitWork unitWork = ProviderFactory.Create <IUnitWork>(_RepoUri); ProviderFactory.Create <IProvider <AttachmentHeader, Guid> >(_RepoUri).Insert(header, unitWork); //插入附件头 Attachment a = new Attachment(); a.ID = header.ID; a.Value = bs; ProviderFactory.Create <IProvider <Attachment, Guid> >(_RepoUri).Insert(a, unitWork); //插入附件内容 return(unitWork.Commit()); } else { return(new CommandResult(ResultCode.Fail, string.Format("文件\"{0}\" 太大,不能上传,如果要上传此文件,请先更改系统最大上传文件大小", path))); } } } catch (Exception ex) { return(new CommandResult(ResultCode.Fail, ex.Message)); } }
public async Task <Response <List <AttachmentHeader> > > DeleteDoc(AttachmentHeader model) { try { model.Is_Active = false; _context.Update(model); await _context.SaveChangesAsync(); var items = await _context.AttachmentHeader.Where(x => x.Attachment_Ref_ID == model.Attachment_Ref_ID && x.Is_Active == true).ToListAsync(); return(new Response <List <AttachmentHeader> >() { IsSuccess = true, Model = items }); } catch (Exception ex) { _log.Error(ex, _user.GetCurrentUser().User_Name); return(new Response <List <AttachmentHeader> >() { IsSuccess = false, Message = ex.Message }); } }
/// <summary> /// 下载附件 /// </summary> /// <param name="header">要下载的附件头部</param> /// <param name="path">附件保存的路径</param> /// <returns></returns> public CommandResult Download(AttachmentHeader header, string path) { QueryResult <Attachment> ret = ProviderFactory.Create <IProvider <Attachment, Guid> >(_RepoUri).GetByID(header.ID); Attachment a = ret.QueryObject; if (a != null && a.Value != null) { try { using (FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write)) { fs.Write(a.Value, 0, a.Value.Length); } return(new CommandResult(ResultCode.Successful, "ok")); } catch (Exception ex) { return(new CommandResult(ResultCode.Fail, ex.Message)); } } else { return(new CommandResult(ret.Result, ret.Message)); } }
protected virtual void PerformAttachOpen(DataGridView gridAttachment) { if (gridAttachment.SelectedRows.Count >= 1) { AttachmentHeader header = gridAttachment.SelectedRows[0].Tag as AttachmentHeader; string dir = LJH.GeneralLibrary.TempFolderManager.GetCurrentFolder(); string path = System.IO.Path.Combine(dir, header.FileName); CommandResult ret = (new AttachmentBLL(AppSettings.Current.ConnStr)).Download(header, path); if (ret.Result == ResultCode.Successful) { try { System.Diagnostics.Process.Start(path); } catch (Exception ex) { MessageBox.Show(ex.Message); } } else { MessageBox.Show(ret.Message); } } }
public async Task <Response <AttachmentDoc> > UploadDoc(AttachmentDoc model) { try { AttachmentHeader header = new AttachmentHeader(); header = model.AttachmentHeaderItem; header.Is_Active = true; _context.AttachmentHeader.Add(header); await _context.SaveChangesAsync(); AttachmentDetails details = new AttachmentDetails(); details = model.AttachmentDetailsItem; details.Is_Active = true; details.Attachment_Header_ID = header.Attachment_Header_ID; _context.AttachmentDetails.Add(details); await _context.SaveChangesAsync(); return(new Response <AttachmentDoc>() { IsSuccess = true, Model = model }); } catch (Exception ex) { _log.Error(ex, _user.GetCurrentUser().User_Name); return(new Response <AttachmentDoc>() { IsSuccess = false, Message = ex.Message }); } }
protected virtual void PerformDelAttach(DataGridView gridAttachment) { if (MessageBox.Show("确实要删除所选项?", "询问", MessageBoxButtons.YesNo) == DialogResult.Yes) { List <DataGridViewRow> deletingRows = new List <DataGridViewRow>(); foreach (DataGridViewRow row in gridAttachment.SelectedRows) { AttachmentHeader header = row.Tag as AttachmentHeader; CommandResult ret = (new AttachmentBLL(AppSettings.Current.ConnStr)).Delete(header); if (ret.Result == ResultCode.Successful) { deletingRows.Add(row); } else { MessageBox.Show(ret.Message); } } if (deletingRows != null && deletingRows.Count > 0) { foreach (DataGridViewRow row in deletingRows) { gridAttachment.Rows.Remove(row); } } } }
protected virtual void PerformAddAttach(string docID, string docType, DataGridView gridAttachment) { OpenFileDialog dig = new OpenFileDialog(); if (dig.ShowDialog() == DialogResult.OK) { AttachmentHeader header = new AttachmentHeader(); header.ID = Guid.NewGuid(); header.DocumentID = docID; header.DocumentType = docType; header.Owner = Operator.Current.Name; header.FileName = System.IO.Path.GetFileName(dig.FileName); header.UploadDateTime = DateTime.Now; FileInfo fi = new FileInfo(dig.FileName); header.FileSize = FileSizeFormat(fi.Length); CommandResult ret = (new AttachmentBLL(AppSettings.Current.ConnStr)).Upload(header, dig.FileName); if (ret.Result == ResultCode.Successful) { int row = gridAttachment.Rows.Add(); ShowAttachmentHeaderOnRow(header, gridAttachment.Rows[row]); } else { MessageBox.Show(ret.Message); } } }
protected virtual void ShowAttachmentHeaderOnRow(AttachmentHeader header, DataGridViewRow row) { row.Tag = header; row.Cells["colUploadDateTime"].Value = header.UploadDateTime; row.Cells["colOwner"].Value = header.Owner; row.Cells["colFileName"].Value = header.FileName; row.Cells["colSize"].Value = header.FileSize; }
public CommandResult Delete(AttachmentHeader header) { IUnitWork unitWork = ProviderFactory.Create <IUnitWork>(_RepoUri); ProviderFactory.Create <IProvider <AttachmentHeader, Guid> >(_RepoUri).Delete(header, unitWork); Attachment att = ProviderFactory.Create <IProvider <Attachment, Guid> >(_RepoUri).GetByID(header.ID).QueryObject; if (att != null) { ProviderFactory.Create <IProvider <Attachment, Guid> >(_RepoUri).Delete(att, unitWork); } return(unitWork.Commit()); }
public async Task <ActionResult> Delete([FromBody] AttachmentHeader model) { if (ModelState.IsValid) { try { await _repository.DeleteDoc(model); return(Ok(model)); } catch (Exception ex) { throw new JsonException(ex.Message, ex); } } return(BadRequest()); }
/// <summary> /// 保存图片 /// </summary> /// <param name="files">图片文件</param> /// <param name="slideShowId">轮播图ID</param> /// <param name="parentNodeId">父节点ID</param> /// <returns>图片地址</returns> private void SaveImage(HttpFileCollectionBase files, string slideShowId, string parentNodeId) { //保存用户头像图片 if (files.Count > 0) { string filePath = files[0].FileName; if (string.IsNullOrEmpty(filePath)) { return; } string fileName = TrimHtml(Path.GetFileName(filePath)).ToLowerInvariant(); //已经存在的图片 AttachmentHeader header = this.Engine.BizObjectManager.GetAttachmentHeader(SlideShow.TableName, parentNodeId, slideShowId); if (header != null) { try { this.Engine.BizObjectManager.UpdateAttachment(header.BizObjectSchemaCode, header.BizObjectId, header.AttachmentID, this.UserValidator.UserID, header.FileName, header.ContentType, GetBytesFromStream(files[0].InputStream), header.FileFlag); } catch { } } else { // 图片采用附件上传方式 Attachment attach = new Attachment() { ObjectID = slideShowId, BizObjectId = parentNodeId, BizObjectSchemaCode = SlideShow.TableName, FileName = fileName, Content = GetBytesFromStream(files[0].InputStream), ContentLength = (int)files[0].ContentLength, CreatedBy = this.UserValidator.UserID, ModifiedBy = this.UserValidator.UserID }; this.Engine.BizObjectManager.AddAttachment(attach); } } }
protected virtual void PerformAttachSaveAs(DataGridView gridAttachment) { if (gridAttachment.SelectedRows.Count >= 1) { AttachmentHeader header = gridAttachment.SelectedRows[0].Tag as AttachmentHeader; SaveFileDialog dig = new SaveFileDialog(); dig.FileName = header.FileName; dig.Filter = "所有文件(*.*)|*.*"; if (dig.ShowDialog() == DialogResult.OK) { CommandResult ret = (new AttachmentBLL(AppSettings.Current.ConnStr)).Download(header, dig.FileName); if (ret.Result == ResultCode.Successful) { } else { MessageBox.Show(ret.Message); } } } }
/// <summary> /// 上传文件到服务器 /// </summary> /// <param name="files">文件</param> /// <param name="bizObjectId">业务对象ID</param> /// <param name="attachmentId">附件ID</param> private void SaveImage(HttpFileCollectionBase files, string bizObjectId, string attachmentId) { //保存用户头像图片 if (files.Count > 0) { string filePath = files[0].FileName; string fileName = TrimHtml(Path.GetFileName(filePath)).ToLowerInvariant(); //已经存在的图片 AttachmentHeader header = this.Engine.BizObjectManager.GetAttachmentHeader(DingTalkAdapter.Param_DingTalkCode, attachmentId, bizObjectId); if (header != null) { try { this.Engine.BizObjectManager.UpdateAttachment(header.BizObjectSchemaCode, header.BizObjectId, header.AttachmentID, this.UserValidator.UserID, header.FileName, header.ContentType, GetBytesFromStream(files[0].InputStream), header.FileFlag); } catch { } } else { // 图片采用附件上传方式 Attachment attach = new Attachment() { ObjectID = bizObjectId, BizObjectId = attachmentId, BizObjectSchemaCode = DingTalkAdapter.Param_DingTalkCode, FileName = fileName, Content = GetBytesFromStream(files[0].InputStream), ContentLength = (int)files[0].ContentLength, CreatedBy = this.UserValidator.UserID, ModifiedBy = this.UserValidator.UserID, ContentType = files[0].ContentType }; this.Engine.BizObjectManager.AddAttachment(attach); } } }
/// <summary> /// 获取图片地址 /// </summary> /// <param name="bizObjectSchemaCode"></param> /// <param name="model"></param> /// <returns></returns> private string GetImageUrl(string userId, string bizObjectSchemaCode, SlideShow model) { string imagePath = ""; AttachmentHeader header = this.Engine.BizObjectManager.GetAttachmentHeader(SlideShow.TableName, model.ParentCode, model.ObjectID); if (header != null) { imagePath = this.PortalRoot + "/ReadAttachment/Read?SchemaCode=" + header.BizObjectSchemaCode + "&BizObjectID=" + header.BizObjectId + "&AttachmentID=" + header.AttachmentID + "&UserID=" + userId + "&IsMobile=true&OpenMethod=0"; try { string UserID = string.Empty; string BizObjectSchemaCode = string.Empty; string BizObjectID = string.Empty; string AttachmentID = string.Empty; string ImageUrl = "http://127.0.0.1:8010" + imagePath.Replace(" ", ""); Uri uri = new Uri(ImageUrl); string queryString = uri.Query.Replace("?", ""); if (!string.IsNullOrEmpty(queryString)) { string[] pars = queryString.Split('&'); for (int j = 0; j < pars.Count(); j++) { string[] p_v = pars[j].Split('='); if (p_v[0] == "UserID") { UserID = p_v[1]; } else if (p_v[0] == "SchemaCode") { BizObjectSchemaCode = p_v[1]; } else if (p_v[0] == "BizObjectID") { BizObjectID = p_v[1]; } else if (p_v[0] == "AttachmentID") { AttachmentID = p_v[1]; } } } Attachment attachment = this.Engine.BizObjectManager.GetAttachment( UserID, BizObjectSchemaCode, BizObjectID, AttachmentID); if (attachment == null || attachment.Content == null || attachment.Content.Length == 0) { } else { //保存文件到服务器 string fileName = attachment.ObjectID + Path.GetExtension(attachment.FileName) + ".jpg"; string imgUrl = this.PortalRoot + "/TempImages/AppSlides/" + Engine.EngineConfig.Code + "//" + fileName; string savePath = System.AppDomain.CurrentDomain.BaseDirectory + "TempImages//AppSlides//" + Engine.EngineConfig.Code + "//" + fileName; // 获取图片路径 if (System.IO.File.Exists(savePath)) { FileInfo file = new FileInfo(savePath); if (file.LastWriteTime > attachment.ModifiedTime) { imagePath = imgUrl; } else { try { file.Delete(); } catch { } } } try { if (!Directory.Exists(Path.GetDirectoryName(savePath))) { Directory.CreateDirectory(Path.GetDirectoryName(savePath)); } using (FileStream fs = new FileStream(savePath, FileMode.OpenOrCreate, FileAccess.ReadWrite)) { using (BinaryWriter bw = new BinaryWriter(fs)) { bw.Write(attachment.Content); bw.Close(); } } imagePath = imgUrl; } catch { } } } catch { } } return(imagePath); }
/// <summary> ///更新用户信息 /// </summary> /// <param name="unit"></param> /// <returns></returns> public JsonResult UpdateUserInfo(string UserID, string Mobile, string OfficePhone, string Email, string FacsimileTelephoneNumber, bool chkEmail, bool chkApp, bool chkWeChat, bool chkMobileMessage, bool chkDingTalk) { return(this.ExecuteFunctionRun(() => { ActionResult result = new ActionResult(true); #region add by chenghuashan 2018-02-24 if (!string.IsNullOrEmpty(Mobile)) { string sql = "SELECT Code,Name FROM OT_User WHERE Mobile='" + Mobile + "' and ObjectID <>'" + UserID + "'"; System.Data.DataTable dt = this.Engine.EngineConfig.CommandFactory.CreateCommand().ExecuteDataTable(sql); if (dt.Rows.Count > 0) { string msg = ""; foreach (System.Data.DataRow row in dt.Rows) { msg += "\n" + row["Name"] + "(" + row["Code"] + ")"; } result.Success = false; result.Message = "手机号码不允许重复,以下用户使用此手机号" + msg; return Json(result, "text/html"); } } #endregion //UserID修改人的ID Organization.User EditUnit = (OThinker.Organization.User)Engine.Organization.GetUnit(UserID); string dirPath = AppDomain.CurrentDomain.BaseDirectory + "TempImages//face//" + Engine.EngineConfig.Code + "//" + this.UserValidator.User.ParentID + "//"; string ID = this.UserValidator.UserID; System.Web.HttpFileCollectionBase files = HttpContext.Request.Files; if (files.Count > 0) { byte[] content = GetBytesFromStream(files[0].InputStream); if (content.Length > 0) { string Type = files[0].ContentType; string fileExt = ".jpg"; string savepath = dirPath + ID + fileExt; try { if (!Directory.Exists(Path.GetDirectoryName(savepath))) { Directory.CreateDirectory(Path.GetDirectoryName(savepath)); } using (FileStream fs = new FileStream(savepath, FileMode.OpenOrCreate, FileAccess.ReadWrite)) { using (BinaryWriter bw = new BinaryWriter(fs)) { bw.Write(content); bw.Close(); } } } catch (Exception ex) { // 这里如果直接输出异常,那么用户不能登录 Engine.LogWriter.Write("加载用户图片出现异常,UserValidator:" + ex.ToString()); } if (UserID == this.UserValidator.UserID) { this.UserValidator.ImagePath = ID + fileExt; } FileInfo file = GetFile(dirPath, ID + fileExt); if (file != null) { AttachmentHeader header = this.Engine.BizObjectManager.GetAttachmentHeader(OThinker.Organization.User.TableName, this.UserValidator.UserID, this.UserValidator.UserID); if (header != null) { Engine.BizObjectManager.UpdateAttachment(header.BizObjectSchemaCode, header.BizObjectId, header.AttachmentID, this.UserValidator.UserID, file.Name, Type, content, header.FileFlag); } else { // 用户头像采用附件上传方式 Attachment attach = new Attachment() { ObjectID = this.UserValidator.UserID, BizObjectId = this.UserValidator.UserID, BizObjectSchemaCode = OThinker.Organization.User.TableName, FileName = file.Name, Content = content, ContentType = Type, ContentLength = (int)file.Length }; Engine.BizObjectManager.AddAttachment(attach); } // 用户头像 EditUnit.ImageID = UserID; EditUnit.ImageUrl = "TempImages//face//" + Engine.EngineConfig.Code + "//" + this.UserValidator.User.ParentID + "//" + file.Name; result.Extend = new { ImageUrl = EditUnit.ImageUrl }; } } } EditUnit.Mobile = Mobile; EditUnit.OfficePhone = OfficePhone; EditUnit.Email = Email; EditUnit.FacsimileTelephoneNumber = FacsimileTelephoneNumber; EditUnit.ModifiedTime = DateTime.Now; //接收消息 EditUnit.SetNotifyType(Organization.NotifyType.App, chkApp); EditUnit.SetNotifyType(Organization.NotifyType.Email, chkEmail); EditUnit.SetNotifyType(Organization.NotifyType.MobileMessage, chkMobileMessage); EditUnit.SetNotifyType(Organization.NotifyType.WeChat, chkWeChat); EditUnit.SetNotifyType(Organization.NotifyType.DingTalk, chkDingTalk); // 写入服务器 Organization.HandleResult HandleResult = Engine.Organization.UpdateUnit(this.UserValidator.UserID, EditUnit); if (HandleResult == Organization.HandleResult.SUCCESS && EditUnit.ObjectID == this.UserValidator.UserID) { this.UserValidator.User = EditUnit as OThinker.Organization.User; } else { result.Success = false; result.Extend = null; } return Json(result, "text/html", JsonRequestBehavior.AllowGet); }, string.Empty)); }
private void ExtractTag(int index) { FileStream fsBitmap = OptionsManager.GetBitmapStream(m_MapVersion); FileStream fsSound = OptionsManager.GetSoundStream(m_MapVersion); //string TagClass = GetTagClass(BitConverter.GetBytes(HaloMap.IndexItems[index].Type1),0); //Loading Tag Long name and seting the map version folder //string ProcessTagFile = TagClass.Trim() + ".mag"; //string MagfilePathRoot = ""; string OutputPathRoot = ""; switch (m_MapVersion) { case MapfileVersion.HALOPC: //MagfilePathRoot = Application.StartupPath + @"\Tag Structures\PcHalo\"; OutputPathRoot = Application.StartupPath + @"\Games\Pc\Halo\"; break; case MapfileVersion.HALOCE: //MagfilePathRoot = Application.StartupPath + @"\Tag Structures\CeHalo\"; OutputPathRoot = Application.StartupPath + @"\Games\Pc\Halo\"; break; case MapfileVersion.XHALO1: //MagfilePathRoot = Application.StartupPath + @"\Tag Structures\XHalo\"; OutputPathRoot = Application.StartupPath + @"\Games\Xbox\Halo\"; break; } //Creating Directorys for extracted tags; string[] Directorys = new string[256]; string DirSep = @"\"; Directorys = HaloMap.IndexItemStringList[index].Split(DirSep.ToCharArray(), 256); uint Dircount = (uint)Directorys.Length - 1; string NewDirectoryStructure = ""; for (uint Count = 0; Count < Dircount; Count += 1) { if (Directory.Exists(OutputPathRoot + NewDirectoryStructure + Directorys[Count]) == false) { //Directory.CreateDirectory(OutputPathRoot + NewDirectoryStructure + Directorys[Count]); NewDirectoryStructure += Directorys[Count] + @"\"; } else { NewDirectoryStructure += Directorys[Count] + @"\"; } } MTSFReader mr; mr = new MTSFReader(); mr.MTSFRead("Core.Compiler.HALO_PC_SET.MTSF"); TSFReader STSF = new TSFReader(); STSF.TSF(ref mr, CompUtil.RevUInt(HaloMap.IndexItems[index].Type1)); //string ExtName = STSF.Name; //FileInfo fiout = new FileInfo(OutputPathRoot + HaloMap.IndexItemStringList[index]); MemoryStream msout = new MemoryStream(); //msout = fiout.Open(FileMode.Create,FileAccess.ReadWrite); //Grenadiac changed this to RW for archive hack TagHeader.SeekToTagDataStart(ref msout); fsin.Seek(HaloMap.IndexItems[index].MetaOffset, System.IO.SeekOrigin.Begin); byte TabByte = 0x09; string TabReplace = ""; TabReplace += (char)TabByte; Struct.StructInfo TagInfo = new Struct.StructInfo(); TagInfo.MapMagic = HaloMap.Map_Magic; TagInfo.MapVersion = HaloMap.MapHeader.Map_Version; TagInfo.SoundsFile = fsSound; TagInfo.BitmapsFile = fsBitmap; TagInfo.IndexItems = HaloMap.IndexItems; TagInfo.TagMagic = HaloMap.IndexItems[index].MetaMagic; TagInfo.IndicesOffset = HaloMap.IndexHeader.Index_Offset; TagInfo.VerticesOffset = HaloMap.IndexHeader.Verts_Offset; TagInfo.CurrentIndex = (uint)index; TagInfo.TagHeaderSize = 0x40; // Create a new struct processor Struct MainStruct = new Struct(); string[] Tags = null; MainStruct.DoProcessStruct(ref STSF, ref fsin, ref msout, 1, STSF.GetUName(), ref TagInfo, ref Tags, ref Tags); //******FIX ME ******// Structure2 MainStruct = new Structure2(); //******FIX ME ******// MainStruct.StructureCS(HaloMap.IndexItems[index].MetaOffset,(uint)MagIndex,HaloMap.IndexItems[index].MetaMagic,HaloMap.Map_Magic,MagArray,1,fsin,msout,fsBitmap,fsSound,HaloMap.IndexHeader.Verts_Offset,HaloMap.IndexHeader.Index_Offset,HaloMap.MapHeader.Map_Version); //public void StructureCS(uint MetaOffset,uint MagIndex,uint OffsetMagic,uint MapMagic,string[] StructureArray,uint ChunkCount,FileStream MapFile,FileStream TagFile,FileStream BitmapFile,FileStream SoundFile,uint VerticesOffset,uint IndicesOffset,StreamWriter ObjFile,uint MapVersion) // Initialize and write out the PROM tag header TagHeader tag_hdr = new TagHeader(); tag_hdr.TagClass0 = HaloMap.IndexItems[index].Type1; tag_hdr.TagClass1 = HaloMap.IndexItems[index].Type2; tag_hdr.TagClass2 = HaloMap.IndexItems[index].Type3; tag_hdr.GameVersion = m_MapVersion; tag_hdr.TagSize = (int)msout.Position - TagHeader.PROM_HEADER_SIZE; tag_hdr.Write(ref msout); //Write out a zero-attachment header tag_hdr.SeekToAttachStart(ref msout); AttachmentHeader attach_hdr = new AttachmentHeader(); attach_hdr.Write(ref msout); //GRENADIAC HACK to put tagfile into archive if (m_OutputArchive != null) { //m_OutputArchive.AddTagfileToArchive(HaloMap.IndexItemStringList[index], msout.GetBuffer(), (int)msout.Position); m_OutputArchive.AddFile(HaloMap.IndexItemStringList[index], GetSubArray(msout.GetBuffer(), 0, (int)msout.Position - 12)); } msout.Close(); fsBitmap.Close(); fsSound.Close(); }
private void ExtractH2Tag(int index) { //Load Shared Map streams FileStream fsShared = OptionsManager.GetHalo2SharedStream(); FileStream fsSinglePlayerShared = OptionsManager.GetHalo2SinglePlayerSharedStream(); FileStream fsMainMenu = OptionsManager.GetHalo2MainMenuStream(); //Tag Header loader start string TagClass = CompUtil.GetTagClass(BitConverter.GetBytes(Halo2Map.IndexItem[index].TagType), 0); if (TagClass == "<fx>") { TagClass = "FXFX"; } byte[] TagHeaderBuffer = new byte[64]; OptionsManager.GetGuerillaHeader(m_MapVersion, TagClass, TagHeaderBuffer); string MagfilePathRoot = Application.StartupPath + @"\Tag Structures\Halo2\"; string OutputPathRoot = Application.StartupPath + @"\Games\Xbox\Halo2\"; //Creating Directorys for extacted tag string[] Directorys = new string[256]; string DirSep = @"\"; Directorys = Halo2Map.StringTable.TagStrings[index].Split(DirSep.ToCharArray(), 256); uint Dircount = (uint)Directorys.Length - 1; string NewDirectoryStructure = ""; for (uint Count = 0; Count < Dircount; Count += 1) { if (Directory.Exists(OutputPathRoot + NewDirectoryStructure + Directorys[Count]) == false) { Directory.CreateDirectory(OutputPathRoot + NewDirectoryStructure + Directorys[Count]); NewDirectoryStructure += Directorys[Count] + @"\"; } else { NewDirectoryStructure += Directorys[Count] + @"\"; } } //Loading Tag Long name from mag file string ProcessTagFile = TagClass.Trim() + ".mag"; StreamReader MagReader = new StreamReader(MagfilePathRoot + ProcessTagFile); string InLine = MagReader.ReadLine(); //Create the Tag on disk string SplitChar = "."; string[] FixTagName = Halo2Map.StringTable.TagStrings[index].Split(SplitChar.ToCharArray(), 2); //FileInfo fiout = new FileInfo(OptionsManager.GetExtractPath(m_MapVersion) + FixTagName[0] + "." + InLine.Trim()); string FileName = FixTagName[0] + "." + InLine.Trim(); MemoryStream msout = new MemoryStream(); TagHeader.SeekToTagDataStart(ref msout); // Create a tag table for byte[] TagTable = new byte[TagCount * 16]; fsin.Seek(Halo2Map.IndexHeader.OffsetToTags, System.IO.SeekOrigin.Begin); fsin.Read(TagTable, 0, TagTable.Length); // Move File pointer to start of tag fsin.Seek(Halo2Map.IndexItem[index].TagOffset, System.IO.SeekOrigin.Begin); // Create the Tab char to provent errors byte TabByte = 0x09; string TabReplace = ""; TabReplace += (char)TabByte; // Read the Structure from the mag file string[] MagArray = new string[256]; int MagIndex = 0; do { InLine = MagReader.ReadLine(); MagArray[MagIndex] = InLine.Replace(TabReplace, "").ToLower().Trim(); MagIndex = MagIndex + 1; }while(MagReader.Peek() != -1); MagReader.Close(); // Create debug stream writer //StreamWriter DebugFile; //DebugFile = new StreamWriter(msout.Name + ".txt" ); // Start the Tags extraction Halo2Structure MainStruct = new Halo2Structure(); //if(TagClass == "sbsp") MainStruct.StructureCS((uint)MagIndex, Halo2Map.IndexItem[index].TagOffsetMagic, Halo2Map.IndexItem[index].TagMagic, MagArray, 1, fsin, msout, fsShared, 0, 0, Halo2Map.StringTable.StringBuffer, Halo2Map.StringTable.OffsetsBuffer, fsSinglePlayerShared, fsMainMenu, fsShared, Halo2Map.MapHeader.MetaStart, Halo2Map.MapHeader.FileSize, null, TagTable, Halo2Map.MapHeader.ScriptStringArray); //DebugFile.Flush(); //DebugFile.Close(); //For Refernce only //public void StructureCS(uint MagIndex,uint OffsetMagic,uint MapMagic,string[] StructureArray,uint ChunkCount,FileStream MapFile,FileStream TagFile,FileStream BitmapFile,uint VerticesOffset,uint IndicesOffset,byte[] StringTable,byte[] StringTableOffsetList,FileStream single_player_shared_map,FileStream mainmenu_map,FileStream shared_map,uint StartOfTags,uint MapSize,StreamWriter DebugFile,byte[] TagTable,string[] ScriptStringArray) // Initialize and write out the PROM tag header TagHeader tag_hdr = new TagHeader(); tag_hdr.TagClass0 = Halo2Map.IndexItem[index].TagType; tag_hdr.GameVersion = m_MapVersion; tag_hdr.TagSize = (int)msout.Position - TagHeader.PROM_HEADER_SIZE; tag_hdr.Write(ref msout); //Write out a zero-attachment header tag_hdr.SeekToAttachStart(ref msout); AttachmentHeader attach_hdr = new AttachmentHeader(); attach_hdr.Write(ref msout); if (m_OutputArchive != null) { //m_OutputArchive.AddTagfileToArchive(HaloMap.IndexItemStringList[index], msout.GetBuffer(), (int)msout.Position); m_OutputArchive.AddFile(FileName, GetSubArray(msout.GetBuffer(), 0, (int)msout.Position - 12)); } msout.Close(); fsShared.Close(); fsSinglePlayerShared.Close(); fsMainMenu.Close(); }
public RecipeAttachment(String docKey, AttachmentHeader header) { this.header = header; documentKey = docKey; contentCached = false; }
public BitmapAttachment(String docKey, AttachmentHeader header) : base(docKey, header) { bitmap = null; }
public VideoAttachment(String docKey, AttachmentHeader header) : base(docKey, header) { }
private void ExtractTag(int index) { FileStream fsBitmap = OptionsManager.GetBitmapStream(m_MapVersion); FileStream fsSound = OptionsManager.GetSoundStream(m_MapVersion); string TagClass = GetTagClass(BitConverter.GetBytes(HaloMap.IndexItems[index].Type1), 0); //Loading Tag Long name and seting the map version folder string ProcessTagFile = TagClass.Trim() + ".mag"; string MagfilePathRoot = ""; string OutputPathRoot = ""; switch (m_MapVersion) { case MapfileVersion.HALOPC: MagfilePathRoot = Application.StartupPath + @"\Tag Structures\PcHalo\"; OutputPathRoot = Application.StartupPath + @"\Games\Pc\Halo\"; break; case MapfileVersion.HALOCE: MagfilePathRoot = Application.StartupPath + @"\Tag Structures\CeHalo\"; OutputPathRoot = Application.StartupPath + @"\Games\Pc\Halo\"; break; case MapfileVersion.XHALO1: MagfilePathRoot = Application.StartupPath + @"\Tag Structures\XHalo\"; OutputPathRoot = Application.StartupPath + @"\Games\Xbox\Halo\"; break; } //Creating Directorys for extracted tags; string[] Directorys = new string[256]; string DirSep = @"\"; Directorys = HaloMap.IndexItemStringList[index].Split(DirSep.ToCharArray(), 256); uint Dircount = (uint)Directorys.Length - 1; string NewDirectoryStructure = ""; for (uint Count = 0; Count < Dircount; Count += 1) { if (Directory.Exists(OutputPathRoot + NewDirectoryStructure + Directorys[Count]) == false) { Directory.CreateDirectory(OutputPathRoot + NewDirectoryStructure + Directorys[Count]); NewDirectoryStructure += Directorys[Count] + @"\"; } else { NewDirectoryStructure += Directorys[Count] + @"\"; } } StreamReader MagReader = new StreamReader(MagfilePathRoot + ProcessTagFile); string InLine = MagReader.ReadLine(); FileInfo fiout = new FileInfo(OutputPathRoot + HaloMap.IndexItemStringList[index]); MemoryStream msout = new MemoryStream(); //msout = fiout.Open(FileMode.Create,FileAccess.ReadWrite); //Grenadiac changed this to RW for archive hack TagHeader.SeekToTagDataStart(ref msout); fsin.Seek(HaloMap.IndexItems[index].MetaOffset, System.IO.SeekOrigin.Begin); byte TabByte = 0x09; string TabReplace = ""; TabReplace += (char)TabByte; string[] MagArray = new string[256]; int MagIndex = 0; do { InLine = MagReader.ReadLine(); //MagArray[Count] = InLine.Split(new char[]{' '},256); MagArray[MagIndex] = InLine.Replace(TabReplace, "").ToLower().Trim(); MagIndex = MagIndex + 1; }while (MagReader.Peek() != -1); MagReader.Close(); Structure2 MainStruct = new Structure2(); MainStruct.StructureCS(HaloMap.IndexItems[index].MetaOffset, (uint)MagIndex, HaloMap.IndexItems[index].MetaMagic, HaloMap.Map_Magic, MagArray, 1, fsin, msout, fsBitmap, fsSound, HaloMap.IndexHeader.Verts_Offset, HaloMap.IndexHeader.Index_Offset, HaloMap.MapHeader.Map_Version); //public void StructureCS(uint MetaOffset,uint MagIndex,uint OffsetMagic,uint MapMagic,string[] StructureArray,uint ChunkCount,FileStream MapFile,FileStream TagFile,FileStream BitmapFile,FileStream SoundFile,uint VerticesOffset,uint IndicesOffset,StreamWriter ObjFile,uint MapVersion) // Initialize and write out the PROM tag header TagHeader tag_hdr = new TagHeader(); tag_hdr.TagClass0 = TagClass; tag_hdr.GameVersion = (MapfileVersion)m_MapVersion; tag_hdr.TagSize = (int)msout.Position - TagHeader.PROM_HEADER_SIZE; tag_hdr.Write(ref msout); //Write out a zero-attachment header tag_hdr.SeekToAttachStart(ref msout); AttachmentHeader attach_hdr = new AttachmentHeader(); attach_hdr.Write(ref msout); //GRENADIAC HACK to put tagfile into archive if (m_OutputArchive != null) { m_OutputArchive.AddTagfileToArchive(HaloMap.IndexItemStringList[index], msout.GetBuffer(), (int)msout.Position); } msout.Close(); fsBitmap.Close(); fsSound.Close(); }
private void CombinedExtractTag(int index) { FileStream fsBitmap = null; FileStream fsSound = null; FileStream fsShared = null; FileStream fsSinglePlayerShared = null; FileStream fsMainMenu = null; switch (m_MapVersion) { case MapfileVersion.HALOPC: case MapfileVersion.HALOCE: fsBitmap = OptionsManager.GetBitmapStream(m_MapVersion); fsSound = OptionsManager.GetSoundStream(m_MapVersion); break; case MapfileVersion.XHALO2: fsShared = OptionsManager.GetHalo2SharedStream(); fsSinglePlayerShared = OptionsManager.GetHalo2SinglePlayerSharedStream(); fsMainMenu = OptionsManager.GetHalo2MainMenuStream(); break; } string TagClass; if (m_MapVersion == MapfileVersion.XHALO2) { TagClass = GetTagClass(BitConverter.GetBytes(Halo2Map.IndexItem[index].TagType), 0); } else { TagClass = GetTagClass(BitConverter.GetBytes(HaloMap.IndexItems[index].Type1), 0); } if (TagClass == "<fx>") { TagClass = "FXFX"; } //byte[] TagHeaderBuffer = new byte[64]; //OptionsManager.GetGuerillaHeader(m_MapVersion, TagClass, TagHeaderBuffer); //Loading Tag Long name and seting the map version folder string MagfilePathRoot = OptionsManager.GetMagfilePath(m_MapVersion); string OutputPathRoot = OptionsManager.GetExtractPath(m_MapVersion); //Creating Directorys for extracted tags; string[] Directorys = new string[256]; string DirSep = @"\"; if (m_MapVersion == MapfileVersion.XHALO2) { Directorys = Halo2Map.StringTable.TagStrings[index].Split(DirSep.ToCharArray(), 256); } else { Directorys = HaloMap.IndexItemStringList[index].Split(DirSep.ToCharArray(), 256); } //Create tag directory if it doesn't exist uint Dircount = (uint)Directorys.Length - 1; string NewDirectoryStructure = ""; for (uint Count = 0; Count < Dircount; Count += 1) { if (Directory.Exists(OutputPathRoot + NewDirectoryStructure + Directorys[Count]) == false) { Directory.CreateDirectory(OutputPathRoot + NewDirectoryStructure + Directorys[Count]); NewDirectoryStructure += Directorys[Count] + @"\"; } else { NewDirectoryStructure += Directorys[Count] + @"\"; } } //Parse mag file string ProcessTagFile = TagClass.Trim() + ".mag"; StreamReader MagReader = new StreamReader(MagfilePathRoot + ProcessTagFile); string InLine = MagReader.ReadLine(); string TagExtension = InLine; byte TabByte = 0x09; string TabReplace = ""; TabReplace += (char)TabByte; string[] MagArray = new string[256]; int MagIndex = 0; do { InLine = MagReader.ReadLine(); MagArray[MagIndex] = InLine.Replace(TabReplace, "").ToLower().Trim(); MagIndex++; }while(MagReader.Peek() != -1); MagReader.Close(); //Create output tag stream/file FileInfo fiout; if (m_MapVersion == MapfileVersion.XHALO2) { string SplitChar = "."; string[] FixTagName = Halo2Map.StringTable.TagStrings[index].Split(SplitChar.ToCharArray(), 2); fiout = new FileInfo(OutputPathRoot + FixTagName[0] + "." + TagExtension.Trim()); } else { fiout = new FileInfo(OutputPathRoot + HaloMap.IndexItemStringList[index]); } MemoryStream msout = new MemoryStream(); //msout = fiout.Open(FileMode.Create,FileAccess.ReadWrite); //Grenadiac changed this to RW for archive hack //msout.Seek(0,System.IO.SeekOrigin.Begin); TagHeader.SeekToTagDataStart(ref msout); //msout.Write(TagHeaderBuffer,0,64); //Parse the meta and reformat output tag according to Magfile rules if (m_MapVersion == MapfileVersion.XHALO2) { // Create debug stream writer StreamWriter DebugFile; DebugFile = null;//new StreamWriter(Application.StartupPath + @"\TagDebug.txt"); byte[] TagTable = new byte[TagCount * 16]; fsin.Seek(Halo2Map.IndexHeader.OffsetToTags, System.IO.SeekOrigin.Begin); fsin.Read(TagTable, 0, TagTable.Length); Halo2Structure MainStruct = new Halo2Structure(); if (TagClass == "sbsp") { MainStruct.StructureCS((uint)MagIndex, Halo2Map.IndexItem[index].TagOffsetMagic, Halo2Map.IndexItem[index].TagMagic, MagArray, 1, fsin, msout, fsShared, 0, 0, Halo2Map.StringTable.StringBuffer, Halo2Map.StringTable.OffsetsBuffer, fsSinglePlayerShared, fsMainMenu, fsShared, Halo2Map.MapHeader.MetaStart, Halo2Map.MapHeader.FileSize, DebugFile, TagTable, Halo2Map.MapHeader.ScriptStringArray); } fsShared.Close(); fsSinglePlayerShared.Close(); fsMainMenu.Close(); } else { fsin.Seek(HaloMap.IndexItems[index].MetaOffset, System.IO.SeekOrigin.Begin); Structure2 MainStruct = new Structure2(); MainStruct.StructureCS(HaloMap.IndexItems[index].MetaOffset, (uint)MagIndex, HaloMap.IndexItems[index].MetaMagic, HaloMap.Map_Magic, MagArray, 1, fsin, msout, fsBitmap, fsSound, HaloMap.IndexHeader.Verts_Offset, HaloMap.IndexHeader.Index_Offset, HaloMap.MapHeader.Map_Version); fsBitmap.Close(); fsSound.Close(); } // Initialize and write out the PROM tag header TagHeader tag_hdr = new TagHeader(); tag_hdr.TagClass0 = TagClass; tag_hdr.GameVersion = (MapfileVersion)m_MapVersion; tag_hdr.TagSize = (int)msout.Position - TagHeader.PROM_HEADER_SIZE; tag_hdr.Write(ref msout); //Write out a zero-attachment header AttachmentHeader attach_hdr = new AttachmentHeader(); attach_hdr.Write(ref msout); if (m_OutputArchive != null) { m_OutputArchive.AddTagfileToArchive(HaloMap.IndexItemStringList[index], msout.GetBuffer(), (int)msout.Position); } msout.Close(); }