Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions AnimationLibrary/AnimationBundleReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,19 @@ private static Dictionary<int, string> ParseHashTable(BinaryReader reader)
return hashTable;
}

private void tryOpenStream(string bild_file, string anim_file)
{
try
{
if (bildStream == null)
bildStream = new FileStream(bild_file, FileMode.Open);
if (animStream == null)
animStream = new FileStream(anim_file, FileMode.Open);
}
catch (System.IO.FileNotFoundException)
{
}
}
public DataSet ReadFile(string path, int winth, int height)
{
DataSet data = new DataSet();
Expand All @@ -188,8 +201,17 @@ public DataSet ReadFile(string path, int winth, int height)
animTable = new DataTable();
animTable.TableName = nameof(animTable);

bildStream = new FileStream(path + "_build.txt", FileMode.Open);
animStream = new FileStream(path + "_anim.txt", FileMode.Open);
// open bildStream and animStream
string fileNamePrefix = Path.GetFileName(path);
string dirName = Path.GetDirectoryName(path);
string parentDirName = Path.GetDirectoryName(dirName);
string textAssetDir = Path.Combine(parentDirName, "TextAsset");
string textAssetPrefix = Path.Combine(textAssetDir, fileNamePrefix);
tryOpenStream(path + "_build.txt", path + "_anim.txt");
tryOpenStream(path + "_build.prefab", path + "_anim.prefab");
tryOpenStream(textAssetPrefix + "_build.txt", textAssetPrefix + "_anim.txt");
tryOpenStream(textAssetPrefix + "_build.prefab", textAssetPrefix + "_anim.prefab");
if (bildStream == null || animStream == null) throw new System.IO.FileNotFoundException("No build or anim file.");

bildReader = new BinaryReader(bildStream, Encoding.UTF8);
animReader = new BinaryReader(animStream, Encoding.UTF8);
Expand Down
20 changes: 18 additions & 2 deletions AnimationTools/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,29 @@ private void BtnUnPack_Click(object sender, RoutedEventArgs e)
{
bundles = new AnimationBundleReader();
file = ListBoxFileList.SelectedItem.ToString();
path = file.Remove(file.LastIndexOf('_'));
try
{
path = file.Remove(file.LastIndexOf('_'));
}
catch (System.ArgumentOutOfRangeException)
{
mVariableData.TipContents = "解包" + name + "失败:图片文件名格式错误";
return;
}
name = file.Replace("/", "\\");
name = name.Substring(name.LastIndexOf("\\") + 1, (name.LastIndexOf(".") - name.LastIndexOf("\\") - 1));
Directory.CreateDirectory(path);

System.Drawing.Image source = System.Drawing.Image.FromFile(file);
dataset = bundles.ReadFile(path, source.Width, source.Height);
try
{
dataset = bundles.ReadFile(path, source.Width, source.Height);
}
catch (System.IO.FileNotFoundException)
{
mVariableData.TipContents = "解包" + name + "失败:找不到对应 build/anim 文件";
return;
}
//dataGridView1.DataSource = ds.Tables["animTable"];

ExportTexture();
Expand Down