private void SaveFile_Click(object sender, EventArgs e) { using (MemoryStream memoryStream = new MemoryStream()) { using (BinaryWriter bw = new BinaryWriter(memoryStream)) { bw.Write("JNBL".ToCharArray()); bw.BaseStream.Position = 0x6; bw.BaseStream.WriteByte((byte)numberOfTouchObjs_UpDown.Value); if (numberOfTouchObjs_UpDown.Value == 0) { f.replace(memoryStream.ToArray(), this); return; } for (int i = 1; i <= numberOfTouchObjs_UpDown.Value; i++) { bw.BaseStream.Position = 0x8 - 0x6 + (i * 0x6); bw.BaseStream.WriteByte(objn_xPos[i]); bw.BaseStream.Position = 0xA - 0x6 + (i * 0x6); bw.BaseStream.WriteByte(objn_yPos[i]); bw.BaseStream.Position = 0xC - 0x6 + (i * 0x6); bw.BaseStream.WriteByte(objn_width[i]); bw.BaseStream.Position = 0xD - 0x6 + (i * 0x6); bw.BaseStream.WriteByte(objn_height[i]); } f.replace(memoryStream.ToArray(), this); } } }
private void SaveFile_Click(object sender, EventArgs e) { using (MemoryStream memoryStream = new MemoryStream()) { using (BinaryWriter bw = new BinaryWriter(memoryStream)) { bw.Write("JNCL".ToCharArray()); bw.BaseStream.Position = 0x6; bw.BaseStream.WriteByte((byte)numberOfObjs_UpDown.Value); if (numberOfObjs_UpDown.Value == 0) { f.replace(memoryStream.ToArray(), this); return; } for (int i = 1; i <= numberOfObjs_UpDown.Value; i++) { bw.BaseStream.Position = 0x8 - 0x8 + (i * 0x8); if (objn_xAlign[i] == 0) { bw.Write(objn_xPos[i]); } else if (objn_xAlign[i] == 1) { bw.Write((ushort)(objn_xPos[i] + 0x1000)); } else if (objn_xAlign[i] == 2) { bw.Write((ushort)(objn_xPos[i] + 0x2000)); } bw.BaseStream.Position = 0xA - 0x8 + (i * 0x8); if (objn_yAlign[i] == 0) { bw.Write(objn_yPos[i]); } else if (objn_yAlign[i] == 1) { bw.Write((ushort)(objn_yPos[i] + 0x1000)); } else if (objn_yAlign[i] == 2) { bw.Write((ushort)(objn_yPos[i] + 0x2000)); } bw.BaseStream.Position = 0xC - 0x8 + (i * 0x8); bw.BaseStream.WriteByte(objn_graphicID[i]); } bw.Write((ushort)0); //Padding bw.Write((byte)0); //Padding f.replace(memoryStream.ToArray(), this); } } }
private void replaceFile(File f, String inputFile) { // NOTE: f.beginEdit(this) must be called before this function FileStream rfs = new FileStream(inputFile, FileMode.Open, FileAccess.Read, FileShare.Read); byte[] tempFile = new byte[rfs.Length]; rfs.Read(tempFile, 0, (int)rfs.Length); rfs.Dispose(); f.replace(tempFile, this); }
private void NarcReplace(string NarcName, string f1) { NarcFilesystem fs = new NarcFilesystem(ROM.FS.getFileByName(NarcName)); NSMBe5.DSFileSystem.File f = fs.getFileByName(f1); f.beginEdit(this); f.replace(ROM.FS.getFileByName(f1).getContents(), this); f.endEdit(this); fs.close(); }
public override void save() { byte[] data = str.ToArray(); if (lz) { data = ROM.LZ77_Compress(data); } f.replace(data, this); }
public override void replace(byte[] newFile, object editor) { if (!isAGoodEditor(editor)) { throw new Exception("NOT CORRECT EDITOR " + name); } if (comp == CompressionType.LZ) { parentFile.replace(ROM.LZ77_Compress(newFile, false), this); } else if (comp == CompressionType.LZWithHeader) { parentFile.replace(ROM.LZ77_Compress(newFile, true), this); } else if (comp == CompressionType.Yaz0) { parentFile.replace(ROM.Yaz0_Compress(newFile), this); } else { parentFile.replace(newFile, this); } }
//WTF was this for?! //private void NarcReplace(string NarcName, string f1, string f2) { } private void NarcReplace(string NarcName, string f1, ushort f2) { NarcFilesystem fs = new NarcFilesystem(ROM.FS.getFileByName(NarcName)); NSMBe5.DSFileSystem.File f = fs.getFileByName(f1); if (f == null) { Console.Out.WriteLine("No File: " + NarcName + "/" + f1); } else { f.beginEdit(this); f.replace(ROM.FS.getFileById(f2).getContents(), this); f.endEdit(this); } fs.close(); }
private void compressWithHeaderButton_Click(object sender, EventArgs e) { File f = fileTreeView.SelectedNode.Tag as File; try { f.beginEdit(this); } catch (AlreadyEditingException) { MessageBox.Show(LanguageManager.Get("Errors", "File")); return; } byte[] RawFile = f.getContents(); byte[] CompFile = ROM.LZ77_Compress(RawFile, true); f.replace(CompFile, this); UpdateFileInfo(); f.endEdit(this); }
private void compressFileButton_Click(object sender, EventArgs e) { File f = fileTreeView.SelectedNode.Tag as File; try { f.beginEdit(this); } catch (AlreadyEditingException) { MessageBox.Show(LanguageManager.Get("Errors", "File")); return; } byte[] RawFile = f.getContents(); byte[] CompFile = RawFile; CompressFilePrompt compressFilePrompt = new CompressFilePrompt(); if (compressFilePrompt.Canceled) { f.endEdit(this); return; } if (compressFilePrompt.ChosenCompression == CompressedFile.CompressionType.LZ) { CompFile = ROM.LZ77_Compress(CompFile, false); } else if (compressFilePrompt.ChosenCompression == CompressedFile.CompressionType.LZWithHeader) { CompFile = ROM.LZ77_Compress(CompFile, true); } else if (compressFilePrompt.ChosenCompression == CompressedFile.CompressionType.Yaz0) { CompFile = ROM.Yaz0_Compress(CompFile); } f.replace(CompFile, this); UpdateFileInfo(); f.endEdit(this); }
private void decompressWithHeaderButton_Click(object sender, EventArgs e) { File f = fileTreeView.SelectedNode.Tag as File; try { try { f.beginEdit(this); } catch (AlreadyEditingException) { MessageBox.Show(LanguageManager.Get("Errors", "File")); return; } if (f.getUintAt(0) != 0x37375A4C) { MessageBox.Show(LanguageManager.Get("Errors", "NoLZHeader")); f.endEdit(this); return; } byte[] CompFile = f.getContents(); byte[] CompFileWithoutHeader = new byte[CompFile.Length - 4]; Array.Copy(CompFile, 4, CompFileWithoutHeader, 0, CompFileWithoutHeader.Length); byte[] RawFile = ROM.LZ77_Decompress(CompFileWithoutHeader, false); f.replace(RawFile, this); UpdateFileInfo(); f.endEdit(this); } catch (Exception) { MessageBox.Show(LanguageManager.Get("FilesystemBrowser", "DecompressionFail")); if (f.beingEditedBy(this)) { f.endEdit(this); } } }
public void SaveFile() { try { string text = string.Empty; //System.IO.StreamWriter s = new System.IO.StreamWriter(new System.IO.FileStream(FilePath, System.IO.FileMode.Create, System.IO.FileAccess.Write)); // Write lists foreach (KeyValuePair <string, Dictionary <int, string> > list in lists) { text += "[" + list.Key + "]\n"; foreach (KeyValuePair <int, string> item in list.Value) { text += item.Key.ToString() + "=" + item.Value + "\n"; } } // Write descriptions foreach (KeyValuePair <int, List <string> > item in descriptions) { int num = 0; text += "[" + item.Key.ToString() + "]\n"; foreach (string desc in item.Value) { if (desc != string.Empty) { text += num.ToString() + "=" + desc + "\n"; } num++; } } //DSFileSystem.File file = ROM.FS.getFileByName("00DUMMY"); DSFileSystem.File file = ROM.FS.getFileById(131); file.beginEdit(this); file.replace(System.Text.Encoding.ASCII.GetBytes(text), this); file.endEdit(this); } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(String.Format(LanguageManager.Get("ROMUserInfo", "ErrorWrite"), ex.Message)); } }
private void patchImport_Click(object sender, EventArgs e) { //output to show to the user bool differentRomsWarning = false; // tells if we have shown the warning int fileCount = 0; //open the input patch if (openPatchDialog.ShowDialog() == DialogResult.Cancel) { return; } FileStream fs = new FileStream(openPatchDialog.FileName, FileMode.Open, FileAccess.Read, FileShare.Read); BinaryReader br = new BinaryReader(fs); string header = br.ReadString(); if (!(header == patchHeader || header == oldPatchHeader)) { MessageBox.Show( LanguageManager.Get("Patch", "InvalidFile"), LanguageManager.Get("Patch", "Unreadable"), MessageBoxButtons.OK, MessageBoxIcon.Error); br.Close(); return; } ProgressWindow progress = new ProgressWindow(LanguageManager.Get("Patch", "ImportProgressTitle")); progress.Show(); byte filestartByte = br.ReadByte(); try { while (filestartByte == 1) { string fileName = br.ReadString(); progress.WriteLine(string.Format(LanguageManager.Get("Patch", "ReplacingFile"), fileName)); ushort origFileID = br.ReadUInt16(); NSMBe5.DSFileSystem.File f = ROM.FS.getFileByName(fileName); uint length = br.ReadUInt32(); byte[] newFile = new byte[length]; br.Read(newFile, 0, (int)length); filestartByte = br.ReadByte(); if (f != null) { ushort fileID = (ushort)f.id; if (!differentRomsWarning && origFileID != fileID) { MessageBox.Show(LanguageManager.Get("Patch", "ImportDiffVersions"), LanguageManager.Get("General", "Warning"), MessageBoxButtons.OK, MessageBoxIcon.Warning); differentRomsWarning = true; } if (!f.isSystemFile) { Console.Out.WriteLine("Replace " + fileName); f.beginEdit(this); f.replace(newFile, this); f.endEdit(this); } fileCount++; } } } catch (AlreadyEditingException) { MessageBox.Show(string.Format(LanguageManager.Get("Patch", "Error"), fileCount), LanguageManager.Get("General", "Completed"), MessageBoxButtons.OK, MessageBoxIcon.Error); } br.Close(); MessageBox.Show(string.Format(LanguageManager.Get("Patch", "ImportReady"), fileCount), LanguageManager.Get("General", "Completed"), MessageBoxButtons.OK, MessageBoxIcon.Information); // progress.Close(); }
public override void save(ExportedLevel level) { levelFile.replace(level.LevelFile, this); BGDatFile.replace(level.BGDatFile, this); }
private void saveButton_Click(object sender, EventArgs e) { byte[] data = ((DynamicByteProvider)hexBox1.ByteProvider).Bytes.ToArray(); f.replace(data, this); }