private void PackBrowser_Shown(object sender, EventArgs e) { m_Tree.Enabled = false; // Insert File tree try { m_Pack = PackResourceSet.CreateFromFile(PackFile); if (m_Pack != null) { Status.Text = Properties.Resources.Str_Initialize; this.Text = this.PackFile + " - MabiPacker"; uint files = m_Pack.GetFileCount(); this.pd.Maximum = files; this.pd.Caption = Properties.Resources.Str_Loading; this.pd.Animation = 151; this.Update(); m_Tree.BeginUpdate(); m_Tree.Nodes.Clear(); m_Root = m_Tree.Nodes.Add("data", "data", 0, 0); for (uint i = 0; i < files; ++i) { InsertFileNode(i); string info = String.Format(Properties.Resources.Str_LoadingMsg, i, files); this.pd.Value = i; this.pd.Message = info; Status.Text = info; if (this.pd.HasUserCancelled) { m_Pack.Dispose(); this.Close(); this.pd.CloseDialog(); return; } this.Update(); } m_Root.Expand(); m_Tree.EndUpdate(); this.pd.CloseDialog(); this.Update(); this.pd.Animation = 150; this.pd.ShowDialog(ProgressDialog.PROGDLG.MarqueeProgress, ProgressDialog.PROGDLG.NoCancel); this.pd.Caption = Properties.Resources.Str_Sorting; this.pd.Message = Properties.Resources.Str_SortingMsg; m_Tree.Sort(); m_Tree.Refresh(); Status.Text = Properties.Resources.Str_Ready; this.Update(); } m_Tree.Enabled = true; } catch (Exception ex) { d.Error(ex, this.Name); } finally { this.pd.CloseDialog(); } }
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> /// 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."); }