From 86e30c5dc0bd61c1afc4024976b4950cad345a75 Mon Sep 17 00:00:00 2001 From: Perfare Date: Sat, 28 Jan 2017 19:17:31 +0800 Subject: [PATCH] Support file size greater than 2GB Support preview .otf type font --- Unity Studio/AssetPreloadData.cs | 2 +- Unity Studio/AssetsFile.cs | 5 +- Unity Studio/UnityStudioForm.cs | 88 ++++++++++++++++---------------- 3 files changed, 47 insertions(+), 48 deletions(-) diff --git a/Unity Studio/AssetPreloadData.cs b/Unity Studio/AssetPreloadData.cs index fea1d66..9acdeee 100644 --- a/Unity Studio/AssetPreloadData.cs +++ b/Unity Studio/AssetPreloadData.cs @@ -9,7 +9,7 @@ namespace Unity_Studio public class AssetPreloadData : ListViewItem { public long m_PathID; - public int Offset; + public uint Offset; public int Size; public int Type1; public ushort Type2; diff --git a/Unity Studio/AssetsFile.cs b/Unity Studio/AssetsFile.cs index 1233fa6..72f856c 100644 --- a/Unity Studio/AssetsFile.cs +++ b/Unity Studio/AssetsFile.cs @@ -49,7 +49,7 @@ namespace Unity_Studio int tableSize = a_Stream.ReadInt32(); int dataEnd = a_Stream.ReadInt32(); fileGen = a_Stream.ReadInt32(); - int dataOffset = a_Stream.ReadInt32(); + uint dataOffset = a_Stream.ReadUInt32(); sharedAssetsList[0].fileName = Path.GetFileName(fullName); //reference itself because sharedFileIDs start from 1 switch (fileGen) @@ -123,6 +123,7 @@ namespace Unity_Studio case 16: platformStr = "Google NaCl"; break; case 21: platformStr = "WP8"; break; case 25: platformStr = "Linux"; break; + default: platformStr = "Unknown Platform"; break; } int baseCount = a_Stream.ReadInt32(); @@ -161,7 +162,7 @@ namespace Unity_Studio AssetPreloadData asset = new AssetPreloadData(); if (fileGen < 14) { asset.m_PathID = a_Stream.ReadInt32(); } else { asset.m_PathID = a_Stream.ReadInt64(); } - asset.Offset = a_Stream.ReadInt32(); + asset.Offset = a_Stream.ReadUInt32(); asset.Offset += dataOffset; asset.Size = a_Stream.ReadInt32(); if (fileGen > 15) diff --git a/Unity Studio/UnityStudioForm.cs b/Unity Studio/UnityStudioForm.cs index f57440d..116ea37 100644 --- a/Unity Studio/UnityStudioForm.cs +++ b/Unity Studio/UnityStudioForm.cs @@ -655,7 +655,7 @@ namespace Unity_Studio //progressBar1.Value = 0; //progressBar1.Maximum = totalAssetCount; SetProgressBarValue(0); - SetProgressBarMaximum(assetsfileList.Count); + SetProgressBarMaximum(assetsfileList.Sum(x => x.preloadTable.Values.Count)); string fileIDfmt = "D" + assetsfileList.Count.ToString().Length.ToString(); @@ -775,11 +775,10 @@ namespace Unity_Studio } assetsFile.exportableAssets.Add(asset); } + ProgressBarPerformStep(); } - exportableAssets.AddRange(assetsFile.exportableAssets); //if (assetGroup.Items.Count > 0) { listView1.Groups.Add(assetGroup); } - ProgressBarPerformStep(); } visibleAssets = exportableAssets; @@ -799,7 +798,7 @@ namespace Unity_Studio //progressBar1.Value = 0; //progressBar1.Maximum = totalTreeNodes; SetProgressBarValue(0); - SetProgressBarMaximum(assetsfileList.Count); + SetProgressBarMaximum(assetsfileList.Sum(x => x.GameObjectList.Values.Count)); foreach (var assetsFile in assetsfileList) { StatusStripUpdate("Building tree structure from " + Path.GetFileName(assetsFile.filePath)); @@ -828,6 +827,7 @@ namespace Unity_Studio } parentNode.Nodes.Add(m_GameObject); + ProgressBarPerformStep(); } @@ -836,7 +836,6 @@ namespace Unity_Studio fileNode.Text += " (no children)"; } fileNodes.Add(fileNode); - ProgressBarPerformStep(); } //sceneTreeView.EndUpdate(); @@ -914,9 +913,8 @@ namespace Unity_Studio } StatusStripUpdate("Finished loading " + assetsfileList.Count.ToString() + " files with " + (assetListView.Items.Count + sceneTreeView.Nodes.Count).ToString() + " exportable assets."); treeSearch.Select(); + saveFolderDialog1.InitialDirectory = mainPath; })); - - saveFolderDialog1.InitialDirectory = mainPath; } private void assetListView_RetrieveVirtualItem(object sender, RetrieveVirtualItemEventArgs e) @@ -1327,53 +1325,53 @@ namespace Unity_Studio case 128: //Font { unityFont m_Font = new unityFont(asset, true); - - if (asset.extension != ".otf" && m_Font.m_FontData != null) + if (m_Font.m_FontData != null) { IntPtr data = Marshal.AllocCoTaskMem(m_Font.m_FontData.Length); Marshal.Copy(m_Font.m_FontData, 0, data, m_Font.m_FontData.Length); // We HAVE to do this to register the font to the system (Weird .NET bug !) uint cFonts = 0; - AddFontMemResourceEx(data, (uint)m_Font.m_FontData.Length, IntPtr.Zero, ref cFonts); - - pfc = new System.Drawing.Text.PrivateFontCollection(); - pfc.AddMemoryFont(data, m_Font.m_FontData.Length); - Marshal.FreeCoTaskMem(data); - - if (pfc.Families.Length > 0) + var re = AddFontMemResourceEx(data, (uint)m_Font.m_FontData.Length, IntPtr.Zero, ref cFonts); + if (re != IntPtr.Zero) { - //textPreviewBox.Font = new Font(pfc.Families[0], 16, FontStyle.Regular); - //textPreviewBox.Text = "abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWYZ\r\n1234567890.:,;'\"(!?)+-*/=\r\nThe quick brown fox jumps over the lazy dog. 1234567890"; - fontPreviewBox.SelectionStart = 0; - fontPreviewBox.SelectionLength = 80; - fontPreviewBox.SelectionFont = new Font(pfc.Families[0], 16, FontStyle.Regular); - fontPreviewBox.SelectionStart = 81; - fontPreviewBox.SelectionLength = 56; - fontPreviewBox.SelectionFont = new Font(pfc.Families[0], 12, FontStyle.Regular); - fontPreviewBox.SelectionStart = 138; - fontPreviewBox.SelectionLength = 56; - fontPreviewBox.SelectionFont = new Font(pfc.Families[0], 18, FontStyle.Regular); - fontPreviewBox.SelectionStart = 195; - fontPreviewBox.SelectionLength = 56; - fontPreviewBox.SelectionFont = new Font(pfc.Families[0], 24, FontStyle.Regular); - fontPreviewBox.SelectionStart = 252; - fontPreviewBox.SelectionLength = 56; - fontPreviewBox.SelectionFont = new Font(pfc.Families[0], 36, FontStyle.Regular); - fontPreviewBox.SelectionStart = 309; - fontPreviewBox.SelectionLength = 56; - fontPreviewBox.SelectionFont = new Font(pfc.Families[0], 48, FontStyle.Regular); - fontPreviewBox.SelectionStart = 366; - fontPreviewBox.SelectionLength = 56; - fontPreviewBox.SelectionFont = new Font(pfc.Families[0], 60, FontStyle.Regular); - fontPreviewBox.SelectionStart = 423; - fontPreviewBox.SelectionLength = 55; - fontPreviewBox.SelectionFont = new Font(pfc.Families[0], 72, FontStyle.Regular); - fontPreviewBox.Visible = true; + pfc = new PrivateFontCollection(); + pfc.AddMemoryFont(data, m_Font.m_FontData.Length); + Marshal.FreeCoTaskMem(data); + if (pfc.Families.Length > 0) + { + //textPreviewBox.Font = new Font(pfc.Families[0], 16, FontStyle.Regular); + //textPreviewBox.Text = "abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWYZ\r\n1234567890.:,;'\"(!?)+-*/=\r\nThe quick brown fox jumps over the lazy dog. 1234567890"; + fontPreviewBox.SelectionStart = 0; + fontPreviewBox.SelectionLength = 80; + fontPreviewBox.SelectionFont = new Font(pfc.Families[0], 16, FontStyle.Regular); + fontPreviewBox.SelectionStart = 81; + fontPreviewBox.SelectionLength = 56; + fontPreviewBox.SelectionFont = new Font(pfc.Families[0], 12, FontStyle.Regular); + fontPreviewBox.SelectionStart = 138; + fontPreviewBox.SelectionLength = 56; + fontPreviewBox.SelectionFont = new Font(pfc.Families[0], 18, FontStyle.Regular); + fontPreviewBox.SelectionStart = 195; + fontPreviewBox.SelectionLength = 56; + fontPreviewBox.SelectionFont = new Font(pfc.Families[0], 24, FontStyle.Regular); + fontPreviewBox.SelectionStart = 252; + fontPreviewBox.SelectionLength = 56; + fontPreviewBox.SelectionFont = new Font(pfc.Families[0], 36, FontStyle.Regular); + fontPreviewBox.SelectionStart = 309; + fontPreviewBox.SelectionLength = 56; + fontPreviewBox.SelectionFont = new Font(pfc.Families[0], 48, FontStyle.Regular); + fontPreviewBox.SelectionStart = 366; + fontPreviewBox.SelectionLength = 56; + fontPreviewBox.SelectionFont = new Font(pfc.Families[0], 60, FontStyle.Regular); + fontPreviewBox.SelectionStart = 423; + fontPreviewBox.SelectionLength = 55; + fontPreviewBox.SelectionFont = new Font(pfc.Families[0], 72, FontStyle.Regular); + fontPreviewBox.Visible = true; + } + break; } } - else { StatusStripUpdate("Unsupported font for preview. Try to export."); } - + StatusStripUpdate("Unsupported font for preview. Try to export."); break; } #endregion