/// <summary> /// Unpack selected file by Id /// </summary> /// <param name="id"></param> private void UnpackById(uint id) { Res = m_Pack.GetFileByIndex(id); if (Res != null) { w.UnpackFile(Res); } }
/// <summary> /// Unpack selected file by file name (unused) /// </summary> /// <param name="name"></param> private void UnpackByName(string name) { Res = m_Pack.GetFileByName(name); if (Res != null) { w.UnpackFile(Res); } }
/// <summary> /// Unpacking file /// </summary> /// <param name="Res">PackResource </param> public bool UnpackFile(PackResource Res) { Console.WriteLine("Unpack"); String InternalName = Res.GetName(); CommonSaveFileDialog dSaveAs = new CommonSaveFileDialog(); dSaveAs.DefaultFileName = Path.GetFileName(InternalName); if (dSaveAs.ShowDialog() == CommonFileDialogResult.Ok) { if (!isCLI) { this.pd.ShowDialog(ProgressDialog.PROGDLG.Normal); this.pd.Caption = Properties.Resources.Str_Unpack; } try { // loading file content. byte[] buffer = new byte[Res.GetSize()]; Res.GetData(buffer); Res.Close(); // Delete old if (File.Exists(dSaveAs.FileName)) { File.Delete(dSaveAs.FileName); } // Write to file. FileStream fs = new FileStream(dSaveAs.FileName, System.IO.FileMode.Create); fs.Write(buffer, 0, buffer.Length); fs.Close(); // Modify File time File.SetCreationTime(dSaveAs.FileName, Res.GetCreated()); File.SetLastAccessTime(dSaveAs.FileName, Res.GetAccessed()); File.SetLastWriteTime(dSaveAs.FileName, Res.GetModified()); } catch (Exception) { return(false); } finally { Res.Close(); this.pd.CloseDialog(); Console.WriteLine("Finish."); } return(true); } return(false); }
private void button1_Click(object sender, EventArgs e) { if (openFileDialog1.ShowDialog(this) == DialogResult.OK) { m_Pack = PackResourceSet.CreateFromFile(openFileDialog1.FileName); if (m_Pack != null) { m_Tree.BeginUpdate(); m_Tree.Nodes.Clear(); m_Root = m_Tree.Nodes.Add("data"); for (uint i = 0; i < m_Pack.GetFileCount(); ++i) { PackResource pr = m_Pack.GetFileByIndex(i); if (pr != null) { InsertFileNode(pr.GetName()); } } m_Root.Expand(); m_Tree.EndUpdate(); } } }
/// <summary> /// Open selected file to display right panel. /// </summary> /// <param name="id"></param> private void PreviewById(uint id) { PackResource Res = m_Pack.GetFileByIndex(id); Status.Text = Properties.Resources.Str_LoadingPreview; this.Update(); if (Res != null) { PicturePanel.Hide(); hexBox.ResetText(); TextView.Hide(); pPlay.Hide(); String InternalName = Res.GetName(); string Ext = Path.GetExtension(@InternalName); // loading file content. byte[] buffer = new byte[Res.GetSize()]; Res.GetData(buffer); Res.Close(); MemoryStream ms = new MemoryStream(buffer); switch (Ext) { case ".dds": case ".tga": case ".jpg": case ".gif": case ".png": case ".bmp": if (handle.IsAllocated) { handle.Free(); } string Info = ""; switch (Ext) { case ".dds": case ".tga": Info = "DDS (Direct Draw Surfice)"; break; case ".jpg": Info = "JPEG"; break; case ".gif": Info = "GIF"; break; case ".bmp": Info = "Bitmap"; break; case ".png": Info = "PNG (Portable Network Graphic)"; break; } if (Ext == ".tga" || Ext == ".dds") { PictureView.Image = DDS2Bitmap(ms); } else { PictureView.Image = Image.FromStream(ms); } PictureView.Update(); Status.Text = String.Format("{0} Image file. ({1} x {2})", Info, PictureView.Width, PictureView.Height); PictureView.SizeMode = PictureBoxSizeMode.AutoSize; PicturePanel.AutoScroll = true; PicturePanel.Update(); PicturePanel.Show(); break; case ".xml": case ".html": case ".txt": case ".trn": string text = Encoding.Unicode.GetString(buffer); TextView.Clear(); TextView.Text = text; TextView.Update(); TextView.Show(); Status.Text = String.Format("Ascii file."); break; case ".wav": case ".mp3": pPlay.Show(); // http://msdn.microsoft.com/en-us/library/ms143770%28v=VS.100%29.aspx this.wave = new WavePlayer(buffer); this.wave.Play(); Status.Text = "Sound file."; break; default: if (InternalName == "vf.dat") { TextView.Clear(); TextView.Text = Encoding.ASCII.GetString(buffer); TextView.Update(); TextView.Show(); Status.Text = "Version infomation."; } else { DynamicByteProvider d = new DynamicByteProvider(buffer); hexBox.ByteProvider = d; Status.Text = "Unknown file."; } break; } ms.Dispose(); } this.Update(); }
/***********************************************************************************************/ /// <summary> /// Draw file tree (Left panel) /// </summary> /// <param name="id"></param> private void InsertFileNode(uint id) { PackResource pr = m_Pack.GetFileByIndex(id); if (pr != null) { string filePath = pr.GetName(); this.pd.Detail = filePath; string[] paths = filePath.Split('\\'); TreeNode node = m_Root; for (uint i = 0; i < paths.Length; ++i) { int index = node.Nodes.IndexOfKey(paths[i]); if (index < 0) { // Add( name , text) string Ext = Path.GetExtension(@paths[i]); if (Ext != "") { switch (Ext) { case ".txt": node = node.Nodes.Add(paths[i], paths[i], 2, 2); if (@paths[i] == "!Readme.txt") { PreviewById(id); } break; case ".xml": case ".trn": node = node.Nodes.Add(paths[i], paths[i], 3, 3); break; case ".jpg": case ".psd": case ".bmp": case ".dds": case ".tga": case ".gif": case ".png": node = node.Nodes.Add(paths[i], paths[i], 4, 4); break; case ".ttf": case ".ttc": node = node.Nodes.Add(paths[i], paths[i], 5, 5); break; case ".wav": case ".mp3": node = node.Nodes.Add(paths[i], paths[i], 6, 6); break; default: if (@paths[i] == "vf.dat") { node = node.Nodes.Add(paths[i], paths[i], 3, 3); PreviewById(id); } else { node = node.Nodes.Add(paths[i], paths[i], 1, 1); } break; } } else { node = node.Nodes.Add(paths[i], paths[i]); } node.Tag = id; } else { node = node.Nodes[index]; } } } }
/// <summary> /// Unpacking Package file process. /// </summary> /// <param name="InputFile">Set filename of unpack file..</param> /// <param name="OutputDir">Set output distnation of Unpacked files.</param> public void Unpack(string InputFile, string OutputDir) { if (!isCLI) { this.pd.Caption = Properties.Resources.Str_Unpack; this.pd.ShowDialog(ProgressDialog.PROGDLG.Normal); } Console.WriteLine("Unpack"); m_Unpack = PackResourceSet.CreateFromFile(InputFile); uint packed_files = m_Unpack.GetFileCount(); if (!isCLI) { pd.Maximum = packed_files; if (this.pd.HasUserCancelled) { m_Unpack.Dispose(); this.pd.CloseDialog(); return; } } for (uint i = 0; i < packed_files; ++i) { PackResource Res = m_Unpack.GetFileByIndex(i); String InternalName = Res.GetName(); if (!isCLI) { this.pd.Message = String.Format(Properties.Resources.Str_Unpacking, i, packed_files); this.pd.Detail = "data\\" + InternalName; this.pd.Value = i; if (pd.HasUserCancelled) { m_Unpack.Dispose(); Interrupt(); return; } } Console.WriteLine(String.Format("{0}/{1} {2}", i, packed_files, InternalName)); // loading file content. byte[] buffer = new byte[Res.GetSize()]; Res.GetData(buffer); Res.Close(); // Get output Directory Name String outputPath = @OutputDir + "\\data\\" + InternalName; // Create directory String DirPath = Regex.Replace(outputPath, @"([^\\]*?)$", ""); if (!Directory.Exists(DirPath)) { Directory.CreateDirectory(DirPath); } // Delete old if (File.Exists(outputPath)) { //DateTime dtUpdate = System.IO.File.GetLastWriteTime(outputPath); //if (dtUpdate > Res.GetModified()){ File.Delete(@outputPath); //}else{ //Todo Overwrite confirm dialog //} } if (Directory.Exists(outputPath)) { Directory.Delete(@outputPath); } // Write to file. FileStream fs = new FileStream(outputPath, System.IO.FileMode.Create); fs.Write(buffer, 0, buffer.Length); fs.Close(); // Modify File time File.SetCreationTime(outputPath, Res.GetCreated()); File.SetLastAccessTime(outputPath, Res.GetAccessed()); File.SetLastWriteTime(outputPath, Res.GetModified()); } m_Unpack.Dispose(); if (!isCLI) { this.pd.CloseDialog(); } Console.WriteLine("Finish."); }
private void UnpackByName(string name) { Res = m_Pack.GetFileByName(name); if (Res != null) { w.UnpackFile(Res); } }
private void UnpackById(uint id) { Res = m_Pack.GetFileByIndex(id); if (Res != null) { w.UnpackFile(Res); } }
/// <summary> /// Unpacking file /// </summary> /// <param name="Res">PackResource </param> public bool UnpackFile(PackResource Res) { Console.WriteLine("Unpack"); String InternalName = Res.GetName(); CommonSaveFileDialog dSaveAs = new CommonSaveFileDialog(); dSaveAs.DefaultFileName = Path.GetFileName(InternalName); if (dSaveAs.ShowDialog() == CommonFileDialogResult.Ok) { if (!isCLI) { this.pd.ShowDialog(ProgressDialog.PROGDLG.Normal); this.pd.Caption = Properties.Resources.Str_Unpack; } try { // loading file content. byte[] buffer = new byte[Res.GetSize()]; Res.GetData(buffer); Res.Close(); // Delete old if (File.Exists(dSaveAs.FileName)) { File.Delete(dSaveAs.FileName); } // Write to file. FileStream fs = new FileStream(dSaveAs.FileName, System.IO.FileMode.Create); fs.Write(buffer, 0, buffer.Length); fs.Close(); // Modify File time File.SetCreationTime(dSaveAs.FileName, Res.GetCreated()); File.SetLastAccessTime(dSaveAs.FileName, Res.GetAccessed()); File.SetLastWriteTime(dSaveAs.FileName, Res.GetModified()); } catch (Exception) { return false; } finally { Res.Close(); this.pd.CloseDialog(); Console.WriteLine("Finish."); } return true; } return false; }