Esempio n. 1
0
        private void decompressFileButton_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;
                }

                CompressedFile RawFile = new CompressedFile(f, CompressedFile.CompressionType.MaybeCompressed);

                f.replace(RawFile.getContents(), this);
                UpdateFileInfo();
                f.endEdit(this);
            }
            catch (Exception)
            {
                MessageBox.Show(LanguageManager.Get("FilesystemBrowser", "DecompressionFail"));
                if (f.beingEditedBy(this))
                {
                    f.endEdit(this);
                }
            }
        }
Esempio n. 2
0
 public override void enableWrite()
 {
     if (editing)
     {
         return;
     }
     levelFile.beginEdit(this);
     BGDatFile.beginEdit(this);
     editing = true;
 }
Esempio n. 3
0
        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();
        }
Esempio n. 4
0
        public BNBL(DSFileSystem.File f)
        {
            this.f = f;
            f.beginEdit(this);

            InitializeComponent();

            Text += " - " + f.name;

            LoadBNBL();
            Show();
        }
        public override Stream load()
        {
            f.beginEdit(this);
            str = new MemoryStream();
            byte[] data = f.getContents();
            if (lz)
            {
                data = ROM.LZ77_Decompress(data, false);
            }

            str.Write(data, 0, data.Length);

            return(str);
        }
Esempio n. 6
0
        public FileHexEditor(File f)
        {
            InitializeComponent();

            this.MdiParent = MdiParentForm.instance;

            this.f = f;
            f.beginEdit(this);

            LanguageManager.ApplyToContainer(this, "FileHexEditor");
            this.Text = string.Format(LanguageManager.Get("FileHexEditor", "_TITLE"), f.name);

            hexBox1.ByteProvider = new DynamicByteProvider(f.getContents());
            this.Icon            = Properties.Resources.nsmbe;
        }
Esempio n. 7
0
        private void replaceFileButton_Click(object sender, EventArgs e)
        {
            if (fileTreeView.SelectedNode.Tag is File)
            {
                File f = fileTreeView.SelectedNode.Tag as File;

                try {
                    f.beginEdit(this);
                } catch (AlreadyEditingException) {
                    MessageBox.Show(LanguageManager.Get("Errors", "File"));
                    return;
                }

                string FileName = f.name;
                replaceFileDialog.FileName = FileName;
                if (replaceFileDialog.ShowDialog() != DialogResult.OK)
                {
                    UpdateFileInfo();
                    f.endEdit(this);
                    return;
                }

                //if (f.id >= 0 && f.id <= ROM.OverlayCount)
                //{
                //    DialogResult r = MessageBox.Show(LanguageManager.Get("FilesystemBrowser", "ImportOverlay"), LanguageManager.Get("FilesystemBrowser", "ImportOverlayTitle"), MessageBoxButtons.YesNoCancel);
                //    if(r == DialogResult.Cancel)
                //    {
                //        UpdateFileInfo();
                //        f.endEdit(this);
                //        return;
                //    }

                //    f.isCompressed = r == DialogResult.Yes;
                //}
                replaceFile(f, replaceFileDialog.FileName);

                UpdateFileInfo();
                f.endEdit(this);
            }
            else
            {
                if (extractDirectoryDialog.ShowDialog() == DialogResult.OK)
                {
                    Directory d = fileTreeView.SelectedNode.Tag as Directory;
                    replaceDirectory(d, extractDirectoryDialog.SelectedPath);
                }
            }
        }
Esempio n. 8
0
        //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();
        }
Esempio n. 9
0
        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);
        }
Esempio n. 10
0
        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);
        }
Esempio n. 11
0
        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);
                }
            }
        }
Esempio n. 12
0
 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));
     }
 }
Esempio n. 13
0
        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();
        }
Esempio n. 14
0
 public override void startEdition()
 {
     parentFile.beginEdit(this);
 }