private void serializeImageInternal(WzImage img, string outPath) { FileStream stream = File.Create(outPath); WzBinaryWriter wzWriter = new WzBinaryWriter(stream, ((WzDirectory)img.parent).WzIv); img.SaveImage(wzWriter); wzWriter.Close(); }
private byte[] serializeImageInternal(WzImage img) { MemoryStream stream = new MemoryStream(); WzBinaryWriter wzWriter = new WzBinaryWriter(stream, ((WzDirectory)img.parent).WzIv); img.SaveImage(wzWriter); byte[] result = stream.ToArray(); wzWriter.Close(); return(result); }
public byte[] SerializeImage(WzImage img) { total = 1; curr = 0; using (MemoryStream stream = new MemoryStream()) { using (WzBinaryWriter wzWriter = new WzBinaryWriter(stream, ((WzDirectory)img.parent).WzIv)) { img.SaveImage(wzWriter); byte[] result = stream.ToArray(); return(result); } } }
public void SerializeImage(WzImage img, string outPath) { total = 1; curr = 0; if (Path.GetExtension(outPath) != ".img") { outPath += ".img"; } using (FileStream stream = File.Create(outPath)) { using (WzBinaryWriter wzWriter = new WzBinaryWriter(stream, ((WzDirectory)img.parent).WzIv)) { img.SaveImage(wzWriter); } } }
internal WzImage ParseXMLWzImg(XmlElement imgElement) { string name = imgElement.GetAttribute("name"); WzImage result = new WzImage(name); foreach (XmlElement subelement in imgElement) { result.WzProperties.Add(ParsePropertyFromXMLElement(subelement)); } result.Changed = true; if (this.useMemorySaving) { string path = Path.GetTempFileName(); WzBinaryWriter wzWriter = new WzBinaryWriter(File.Create(path), iv); result.SaveImage(wzWriter); wzWriter.Close(); result.Dispose(); result = imgDeserializer.WzImageFromIMGFile(path, iv, name); } return(result); }
private void SaveEtcData() { var dialog = new SaveFileDialog { FileName = "Commodity.img", Filter = Resources.FileSaveImgExt }; if (dialog.ShowDialog() != DialogResult.OK) { return; } if (File.Exists(dialog.FileName)) { try { File.Delete(dialog.FileName); } catch { MessageBox.Show($"Unable to delete the file located at {dialog.FileName}", Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } UpdateNodes(); var temp = Path.GetTempFileName(); using (var stream = File.Create(temp)) { using (var w = new WzBinaryWriter(stream, commodityImg.WzFileParent.MapleVersion, false)) { commodityImg.SaveImage(w); } } commodityImg.Dispose(); commodityImg = null; File.Move(temp, dialog.FileName); dialog.Dispose(); MessageBox.Show(Resources.MessageSuccess); ButtonLoad_Click(null, null); }
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(); }
internal WzImage ParseXMLWzImg(XmlElement imgElement) { string name = imgElement.GetAttribute("name"); WzImage result = new WzImage(name); foreach (XmlElement subelement in imgElement) result.WzProperties.Add(ParsePropertyFromXMLElement(subelement)); result.Changed = true; if (this.useMemorySaving) { string path = Path.GetTempFileName(); WzBinaryWriter wzWriter = new WzBinaryWriter(File.Create(path), iv); result.SaveImage(wzWriter); wzWriter.Close(); result.Dispose(); result = imgDeserializer.WzImageFromIMGFile(path, iv, name); } return result; }
private byte[] serializeImageInternal(WzImage img) { MemoryStream stream = new MemoryStream(); WzBinaryWriter wzWriter = new WzBinaryWriter(stream, ((WzDirectory)img.parent).WzIv); img.SaveImage(wzWriter); byte[] result = stream.ToArray(); wzWriter.Close(); return result; }
/// <summary> /// On save button clicked /// </summary> /// <param name="sender"></param> /// <param name="e"></param> 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, FileName = wzNode.Text, Filter = string.Format("{0}|*.wz", HaRepacker.Properties.Resources.WzFilter) }) { if (dialog.ShowDialog() != System.Windows.Forms.DialogResult.OK) { return; } WzMapleVersion wzMapleVersionSelected = MainForm.GetWzMapleVersionByWzEncryptionBoxSelection(encryptionBox.SelectedIndex); // new encryption selected if (this.IsRegularWzFile) { if (wzf is WzFile file && wzf.MapleVersion != wzMapleVersionSelected) { PrepareAllImgs(file.WzDirectory); } wzf.MapleVersion = wzMapleVersionSelected; if (wzf is WzFile file1) { file1.Version = (short)versionBox.Value; } if (wzf.FilePath != null && wzf.FilePath.ToLower() == dialog.FileName.ToLower()) { wzf.SaveToDisk(dialog.FileName + "$tmp", wzMapleVersionSelected); wzNode.DeleteWzNode(); try { File.Delete(dialog.FileName); File.Move(dialog.FileName + "$tmp", dialog.FileName); }catch (IOException ex) { MessageBox.Show("Handle error overwriting WZ file", HaRepacker.Properties.Resources.Error); } } else { wzf.SaveToDisk(dialog.FileName, wzMapleVersionSelected); wzNode.DeleteWzNode(); } // Reload the new file WzFile loadedWzFile = Program.WzFileManager.LoadWzFile(dialog.FileName, wzMapleVersionSelected); if (loadedWzFile != null) { Program.WzFileManager.AddLoadedWzFileToMainPanel(loadedWzFile, panel); } } else { byte[] WzIv = WzTool.GetIvByMapleVersion(wzMapleVersionSelected); // Save file string tmpFilePath = dialog.FileName + ".tmp"; string targetFilePath = dialog.FileName; bool error_noAdminPriviledge = false; try { 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.DeleteWzNode(); } catch (UnauthorizedAccessException) { error_noAdminPriviledge = true; } // Reload the new file WzImage img = Program.WzFileManager.LoadDataWzHotfixFile(dialog.FileName, wzMapleVersionSelected, panel); if (img == null || error_noAdminPriviledge) { MessageBox.Show(HaRepacker.Properties.Resources.MainFileOpenFail, HaRepacker.Properties.Resources.Error); } } } Close(); }