Example #1
0
        private void saveButton_Click(object sender, EventArgs e)
        {
            if (versionBox.Value < 0)
            {
                Warning.Error(HaRepacker.Properties.Resources.SaveVersionError); return;
            }
            SaveFileDialog dialog = new SaveFileDialog()
            {
                Title = HaRepacker.Properties.Resources.SelectOutWz, Filter = string.Format("{0}|*.wz", HaRepacker.Properties.Resources.WzFilter)
            };

            if (dialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
            {
                return;
            }
            if (wzf is WzFile && wzf.MapleVersion != (WzMapleVersion)encryptionBox.SelectedIndex)
            {
                PrepareAllImgs(((WzFile)wzf).WzDirectory);
            }
            wzf.MapleVersion = (WzMapleVersion)encryptionBox.SelectedIndex;
            if (wzf is WzFile)
            {
                ((WzFile)wzf).Version = (short)versionBox.Value;
            }
            if (wzf.FilePath != null && wzf.FilePath.ToLower() == dialog.FileName.ToLower())
            {
                wzf.SaveToDisk(dialog.FileName + "$tmp");
                wzNode.Delete();
                File.Delete(dialog.FileName);
                File.Move(dialog.FileName + "$tmp", dialog.FileName);
            }
            else
            {
                wzf.SaveToDisk(dialog.FileName);
                wzNode.Delete();
            }
            Program.WzMan.LoadWzFile(dialog.FileName, (WzMapleVersion)encryptionBox.SelectedIndex, panel);
            Close();
        }
Example #2
0
        private void saveButton_Click(object sender, EventArgs e)
        {
            if (versionBox.Value < 0)
            {
                Warning.Error("Version must be above 0"); return;
            }
            SaveFileDialog dialog = new SaveFileDialog()
            {
                Title = "Select where to save the file", Filter = "WZ Files(*.wz)|*.wz"
            };

            if (dialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
            {
                return;
            }
            if (wzf is WzFile && wzf.MapleVersion != (WzMapleVersion)encryptionBox.SelectedIndex)
            {
                PrepareAllImgs(((WzFile)wzf).WzDirectory);
            }
            wzf.MapleVersion = (WzMapleVersion)encryptionBox.SelectedIndex;
            if (wzf is WzFile)
            {
                ((WzFile)wzf).Version = (short)versionBox.Value;
            }
            if (wzf.FilePath != null && wzf.FilePath.ToLower() == dialog.FileName.ToLower())
            {
                wzf.SaveToDisk(dialog.FileName + "$tmp");
                wzNode.Delete();
                File.Delete(dialog.FileName);
                File.Move(dialog.FileName + "$tmp", dialog.FileName);
            }
            else
            {
                wzf.SaveToDisk(dialog.FileName);
                wzNode.Delete();
            }
            Program.WzMan.LoadWzFile(dialog.FileName, (WzMapleVersion)encryptionBox.SelectedIndex, panel);
            Close();
        }
Example #3
0
        public void DoPaste()
        {
            if (!Warning.Warn(Properties.Resources.MainConfirmPaste))
            {
                return;
            }

            yesToAll = false;
            noToAll  = false;
            WzNode   parent    = (WzNode)DataTree.SelectedNode;
            WzObject parentObj = (WzObject)parent.Tag;

            if (parent != null && parent.Tag is WzImage && parent.Nodes.Count == 0)
            {
                ParseOnDataTreeSelectedItem(parent);
            }

            if (parentObj is WzFile)
            {
                parentObj = ((WzFile)parentObj).WzDirectory;
            }

            foreach (WzObject obj in clipboard)
            {
                if (((obj is WzDirectory || obj is WzImage) && parentObj is WzDirectory) || (obj is WzImageProperty && parentObj is IPropertyContainer))
                {
                    WzObject clone = CloneWzObject(obj);
                    if (clone == null)
                    {
                        continue;
                    }
                    WzNode node  = new WzNode(clone);
                    WzNode child = WzNode.GetChildNode(parent, node.Text);
                    if (child != null)
                    {
                        if (ShowReplaceDialog(node.Text))
                        {
                            child.Delete();
                        }
                        else
                        {
                            return;
                        }
                    }
                    parent.AddNode(node);
                }
            }
        }
Example #4
0
        private void InsertWzNodeCallback(WzNode node, WzNode parent)
        {
            WzNode child = WzNode.GetChildNode(parent, node.Text);

            if (child != null)
            {
                if (ShowReplaceDialog(node.Text))
                {
                    child.Delete();
                }
                else
                {
                    return;
                }
            }
            parent.AddNode(node);
        }
Example #5
0
        public void DoPaste()
        {
            if (!Warning.Warn("Paste WZ nodes from clipboard? (warning - can take a lot of time if many nodes are pasted)"))
            {
                return;
            }
            yesToAll = false;
            noToAll  = false;
            WzNode    parent    = (WzNode)DataTree.SelectedNode;
            IWzObject parentObj = (IWzObject)parent.Tag;

            if (parentObj is WzFile)
            {
                parentObj = ((WzFile)parentObj).WzDirectory;
            }

            foreach (IWzObject obj in clipboard)
            {
                if (((obj is WzDirectory || obj is WzImage) && parentObj is WzDirectory) || (obj is IWzImageProperty && parentObj is IPropertyContainer))
                {
                    WzNode node  = new WzNode(obj);
                    WzNode child = WzNode.GetChildNode(parent, node.Text);
                    if (child != null)
                    {
                        if (ShowReplaceDialog(node.Text))
                        {
                            child.Delete();
                        }
                        else
                        {
                            return;
                        }
                    }
                    parent.AddNode(node);
                }
            }
        }
Example #6
0
        private void saveButton_Click(object sender, EventArgs e)
        {
            if (versionBox.Value < 0)
            {
                Warning.Error(HaRepacker.Properties.Resources.SaveVersionError);
                return;
            }

            using (SaveFileDialog dialog = new SaveFileDialog()
            {
                Title = HaRepacker.Properties.Resources.SelectOutWz,
                Filter = string.Format("{0}|*.wz",
                                       HaRepacker.Properties.Resources.WzFilter)
            })
            {
                if (dialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                {
                    return;
                }

                WzMapleVersion wzMapleVersionSelected = (WzMapleVersion)encryptionBox.SelectedIndex;
                if (this.IsRegularWzFile)
                {
                    if (wzf is WzFile && wzf.MapleVersion != wzMapleVersionSelected)
                    {
                        PrepareAllImgs(((WzFile)wzf).WzDirectory);
                    }

                    wzf.MapleVersion = (WzMapleVersion)encryptionBox.SelectedIndex;
                    if (wzf is WzFile)
                    {
                        ((WzFile)wzf).Version = (short)versionBox.Value;
                    }
                    if (wzf.FilePath != null && wzf.FilePath.ToLower() == dialog.FileName.ToLower())
                    {
                        wzf.SaveToDisk(dialog.FileName + "$tmp");
                        wzNode.Delete();
                        File.Delete(dialog.FileName);
                        File.Move(dialog.FileName + "$tmp", dialog.FileName);
                    }
                    else
                    {
                        wzf.SaveToDisk(dialog.FileName);
                        wzNode.Delete();
                    }

                    // Reload the new file
                    Program.WzMan.LoadWzFile(dialog.FileName, (WzMapleVersion)encryptionBox.SelectedIndex, panel);
                }
                else
                {
                    byte[] WzIv = WzTool.GetIvByMapleVersion(wzMapleVersionSelected);

                    // Save file
                    string tmpFilePath    = dialog.FileName + ".tmp";
                    string targetFilePath = dialog.FileName;

                    using (FileStream oldfs = File.Open(tmpFilePath, FileMode.OpenOrCreate))
                    {
                        using (WzBinaryWriter wzWriter = new WzBinaryWriter(oldfs, WzIv))
                        {
                            wzImg.SaveImage(wzWriter, true); // Write to temp folder
                        }
                    }
                    try
                    {
                        File.Copy(tmpFilePath, targetFilePath, true);
                        File.Delete(tmpFilePath);
                    }
                    catch (Exception exp)
                    {
                        Debug.WriteLine(exp); // nvm, dont show to user
                    }
                    wzNode.Delete();

                    // Reload the new file
                    WzImage img = Program.WzMan.LoadDataWzHotfixFile(dialog.FileName, wzMapleVersionSelected, panel);
                }
            }
            Close();
        }