/// <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); }
/// <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> /// 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."); }
/// <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; }