Example #1
0
        private void replaceToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string currentDir = ME3Directory.cookedPath;

            // setting TexSelection Form to export images
            TexSelection texSelection = new TexSelection(tex2D, true);
            texSelection.FormTitle = "Select images to replace";
            texSelection.btnSelectionText = "Replace";
            if (tex2D.imgList.Count > 1)
            {
                texSelection.ShowDialog();
                texSelection.Dispose();
            }
            else
                texSelection.bOk = true;

            if (texSelection.bOk)
            {
                try
                {
                    // main replace loop
                    foreach (Object entry in texSelection.imageListBox.CheckedItems)
                    {
                        string imgSize = entry.ToString().Split(' ')[1]; // take imagesize (ex. 512x512) from checklist text: "Image 512x512 stored..."

                        OpenFileDialog openImage = openFileDialog;
                        openImage.Title = "Select the image to replace with size " + imgSize;
                        openImage.Filter = "Image file|*" + tex2D.getFileFormat() + "|All files|*.*";

                        if (openImage.ShowDialog() != DialogResult.OK)
                            return;

                        // replace function
                        tex2D.replaceImage(imgSize, openImage.FileName, currentDir);
                    }

                    //--------- update the pcc with the new replaced infos ----------
                    // select export index
                    ListViewItem item = listView1.SelectedItems[0];
                    int index = Convert.ToInt32(item.Name);
                    // copy export data
                    PCCObject.ExportEntry expEntry = pcc.Exports[index];
                    // change data with new tex data
                    expEntry.Data = tex2D.ToArray(expEntry.DataOffset);
                    // updating pcc file
                    //pcc.ChangeExportEntry(index, expEntry);
                    //pcc.UpdateAllOffsets();

                    // changing tfc size
                    // check that the image list has at least one image stored inside an external archive, if not it's useless to search the archive location
                    if (tex2D.imgList.Any(images => images.storageType == Texture2D.storage.arcCpr || images.storageType == Texture2D.storage.arcUnc))
                    {
                        TOCeditor tc = new TOCeditor();
                        uint arcSize;
                        string arcPath = currentDir + tex2D.arcName + ".tfc";
                        using (FileStream archiveStream = File.OpenRead(arcPath))
                            arcSize = (uint)archiveStream.Length;
                        string tocpath = pathBIOGame + "PCConsoleTOC.bin";
                        if (File.Exists(tocpath))
                            while (!tc.UpdateFile("\\" + tex2D.arcName + ".tfc", arcSize, tocpath))
                            {
                                OpenFileDialog openImage = openFileDialog;
                                openImage.Title = "Select the archive path";
                                openImage.Filter = tex2D.arcName + ".tfc|" + tex2D.arcName + ".tfc|All files|*.*";
                                openImage.ShowDialog();
                                arcPath = openImage.FileName;
                                using (FileStream archiveStream = File.OpenRead(arcPath))
                                    arcSize = (uint)archiveStream.Length;
                            }
                        else
                            while (!tc.UpdateFile("\\" + tex2D.arcName + ".tfc", arcSize))
                            {
                                OpenFileDialog openImage = openFileDialog;
                                openImage.Title = "Select the archive path";
                                openImage.Filter = tex2D.arcName + ".tfc|" + tex2D.arcName + ".tfc|All files|*.*";
                                openImage.ShowDialog();
                                arcPath = openImage.FileName;
                                using (FileStream archiveStream = File.OpenRead(arcPath))
                                    arcSize = (uint)archiveStream.Length;
                            }
                    }

                    //---------------- end of replace -------------------------------
                    MessageBox.Show("All images are replaced correctly.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (Exception exc)
                {
                    MessageBox.Show("An error occurred while replacing images: " + exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Example #2
0
        private void replaceToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string currentDir = ME3Directory.cookedPath;

            // setting TexSelection Form to export images
            TexSelection texSelection = new TexSelection(tex2D, true);

            texSelection.FormTitle        = "Select images to replace";
            texSelection.btnSelectionText = "Replace";
            if (tex2D.imgList.Count > 1)
            {
                texSelection.ShowDialog();
                texSelection.Dispose();
            }
            else
            {
                texSelection.bOk = true;
            }

            if (texSelection.bOk)
            {
                try
                {
                    // main replace loop
                    foreach (Object entry in texSelection.imageListBox.CheckedItems)
                    {
                        string imgSize = entry.ToString().Split(' ')[1]; // take imagesize (ex. 512x512) from checklist text: "Image 512x512 stored..."

                        OpenFileDialog openImage = openFileDialog;
                        openImage.Title  = "Select the image to replace with size " + imgSize;
                        openImage.Filter = "Image file|*" + tex2D.getFileFormat() + "|All files|*.*";

                        if (openImage.ShowDialog() != DialogResult.OK)
                        {
                            return;
                        }

                        // replace function
                        tex2D.replaceImage(imgSize, openImage.FileName, currentDir);
                    }

                    //--------- update the pcc with the new replaced infos ----------
                    // select export index
                    ListViewItem item  = listView1.SelectedItems[0];
                    int          index = Convert.ToInt32(item.Name);
                    // copy export data
                    PCCObject.ExportEntry expEntry = pcc.Exports[index];
                    // change data with new tex data
                    expEntry.Data = tex2D.ToArray(expEntry.DataOffset);
                    // updating pcc file
                    //pcc.ChangeExportEntry(index, expEntry);
                    //pcc.UpdateAllOffsets();

                    // changing tfc size
                    // check that the image list has at least one image stored inside an external archive, if not it's useless to search the archive location
                    if (tex2D.imgList.Any(images => images.storageType == Texture2D.storage.arcCpr || images.storageType == Texture2D.storage.arcUnc))
                    {
                        TOCeditor tc = new TOCeditor();
                        uint      arcSize;
                        string    arcPath = currentDir + tex2D.arcName + ".tfc";
                        using (FileStream archiveStream = File.OpenRead(arcPath))
                            arcSize = (uint)archiveStream.Length;
                        string tocpath = pathBIOGame + "PCConsoleTOC.bin";
                        if (File.Exists(tocpath))
                        {
                            while (!tc.UpdateFile("\\" + tex2D.arcName + ".tfc", arcSize, tocpath))
                            {
                                OpenFileDialog openImage = openFileDialog;
                                openImage.Title  = "Select the archive path";
                                openImage.Filter = tex2D.arcName + ".tfc|" + tex2D.arcName + ".tfc|All files|*.*";
                                openImage.ShowDialog();
                                arcPath = openImage.FileName;
                                using (FileStream archiveStream = File.OpenRead(arcPath))
                                    arcSize = (uint)archiveStream.Length;
                            }
                        }
                        else
                        {
                            while (!tc.UpdateFile("\\" + tex2D.arcName + ".tfc", arcSize))
                            {
                                OpenFileDialog openImage = openFileDialog;
                                openImage.Title  = "Select the archive path";
                                openImage.Filter = tex2D.arcName + ".tfc|" + tex2D.arcName + ".tfc|All files|*.*";
                                openImage.ShowDialog();
                                arcPath = openImage.FileName;
                                using (FileStream archiveStream = File.OpenRead(arcPath))
                                    arcSize = (uint)archiveStream.Length;
                            }
                        }
                    }

                    //---------------- end of replace -------------------------------
                    MessageBox.Show("All images are replaced correctly.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (Exception exc)
                {
                    MessageBox.Show("An error occurred while replacing images: " + exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Example #3
0
        private void extractToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string currentDir = ME3Directory.cookedPath;
            string imgFileName = null;
            string imgFileFolder = null;

            // setting TexSelection Form to export images
            TexSelection texSelection = new TexSelection(tex2D);
            texSelection.FormTitle = "Select images to extract";
            texSelection.btnSelectionText = "Extract";
            if (tex2D.imgList.Count > 1)
            {
                texSelection.ShowDialog();
                texSelection.Dispose();
            }
            else
                texSelection.bOk = true;

            if (texSelection.bOk)
            {
                try
                {
                    // check that the image list has at least one image stored inside an external archive, if not it's useless to search the archive location
                    if (tex2D.imgList.Any(images => images.storageType == Texture2D.storage.arcCpr || images.storageType == Texture2D.storage.arcUnc))
                    {
                        // check if archive file is present in the same pcc directory
                        string archivePath = currentDir + tex2D.arcName + ".tfc";
                        if (!File.Exists(archivePath))
                        {
                            OpenFileDialog openArchive = openFileDialog;
                            openArchive.Title = "Select the .tfc archive needed to extract images";
                            openArchive.Filter = tex2D.arcName + ".tfc|" + tex2D.arcName + ".tfc|All files|*.*";

                            // try to open the last opened directory
                            archivePath = openArchive.InitialDirectory + "\\" + tex2D.arcName + ".tfc";
                            if (File.Exists(archivePath)) // if the archive exists then use it directly
                            {
                                currentDir = openArchive.InitialDirectory;
                            }
                            else // if not then the user searches for it
                            {
                                DialogResult resultSelection;
                                do
                                {
                                    resultSelection = openArchive.ShowDialog();
                                } while (!File.Exists(openArchive.FileName) && resultSelection != DialogResult.Cancel);

                                if (resultSelection == DialogResult.Cancel)
                                    return; // exit if user press cancel (or undo)
                                else
                                {
                                    openArchive.InitialDirectory = Path.GetDirectoryName(openArchive.FileName);
                                    currentDir = Path.GetDirectoryName(openArchive.FileName);
                                }
                            }
                        }
                    }

                    if (texSelection.imageListBox.CheckedItems.Count == 1) // if user selected only one image to extract
                    {
                        string imgSize = texSelection.imageListBox.CheckedItems[0].ToString().Split(' ')[1]; // take imagesize (ex. 512x512) from checklist text: "Image 512x512 stored..."
                        SaveFileDialog saveFile = new SaveFileDialog();
                        saveFile.Title = "Select the location to save the image";
                        saveFile.FileName = tex2D.texName + "_" + imgSize + tex2D.getFileFormat();
                        saveFile.Filter = "Image file|*" + tex2D.getFileFormat() + "|All files|*.*";
                        //saveFile.RestoreDirectory = true;
                        DialogResult resultSelection = saveFile.ShowDialog();
                        if (resultSelection == DialogResult.OK)
                        {
                            imgFileName = Path.GetFileName(saveFile.FileName);
                            imgFileFolder = Path.GetDirectoryName(saveFile.FileName);
                        }
                        else
                            return;
                    }
                    else // if user selected multiple images to extract
                    {
                        FolderBrowserDialog saveFolder = new FolderBrowserDialog();
                        saveFolder.Description = "Select the folder location to save all the images";
                        DialogResult resultSelection = saveFolder.ShowDialog();
                        if (resultSelection == DialogResult.OK)
                        {
                            imgFileFolder = saveFolder.SelectedPath;
                        }
                        else
                            return;
                    }

                    // main extraction loop
                    foreach (Object entry in texSelection.imageListBox.CheckedItems)
                    {
                        string imgSize = entry.ToString().Split(' ')[1]; // take imagesize (ex. 512x512) from checklist text: "Image 512x512 stored..."
                        string imgFinalFileName;
                        if (imgFileName == null)
                            imgFinalFileName = tex2D.texName + "_" + imgSize + tex2D.getFileFormat();
                        else
                            imgFinalFileName = imgFileName;
                        string fullpath = imgFileFolder + "\\" + imgFinalFileName;

                        // extraction function
                        tex2D.extractImage(imgSize, currentDir, fullpath);
                    }

                    // update the pcc with the new replaced infos
                    ListViewItem item = listView1.SelectedItems[0];
                    int index = Convert.ToInt32(item.Name);
                    PCCObject.ExportEntry expEntry = pcc.Exports[index];
                    expEntry.Data = tex2D.ToArray(expEntry.DataOffset);
                    //pcc.ChangeExportEntry(index, expEntry);
                    //pcc.UpdateAllOffsets();

                    MessageBox.Show("All images are extracted correctly.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (Exception exc)
                {
                    MessageBox.Show("An error occurred while extracting images: " + exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Example #4
0
        private void extractToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string currentDir    = ME3Directory.cookedPath;
            string imgFileName   = null;
            string imgFileFolder = null;

            // setting TexSelection Form to export images
            TexSelection texSelection = new TexSelection(tex2D);

            texSelection.FormTitle        = "Select images to extract";
            texSelection.btnSelectionText = "Extract";
            if (tex2D.imgList.Count > 1)
            {
                texSelection.ShowDialog();
                texSelection.Dispose();
            }
            else
            {
                texSelection.bOk = true;
            }

            if (texSelection.bOk)
            {
                try
                {
                    // check that the image list has at least one image stored inside an external archive, if not it's useless to search the archive location
                    if (tex2D.imgList.Any(images => images.storageType == Texture2D.storage.arcCpr || images.storageType == Texture2D.storage.arcUnc))
                    {
                        // check if archive file is present in the same pcc directory
                        string archivePath = currentDir + tex2D.arcName + ".tfc";
                        if (!File.Exists(archivePath))
                        {
                            OpenFileDialog openArchive = openFileDialog;
                            openArchive.Title  = "Select the .tfc archive needed to extract images";
                            openArchive.Filter = tex2D.arcName + ".tfc|" + tex2D.arcName + ".tfc|All files|*.*";

                            // try to open the last opened directory
                            archivePath = openArchive.InitialDirectory + "\\" + tex2D.arcName + ".tfc";
                            if (File.Exists(archivePath)) // if the archive exists then use it directly
                            {
                                currentDir = openArchive.InitialDirectory;
                            }
                            else // if not then the user searches for it
                            {
                                DialogResult resultSelection;
                                do
                                {
                                    resultSelection = openArchive.ShowDialog();
                                } while (!File.Exists(openArchive.FileName) && resultSelection != DialogResult.Cancel);

                                if (resultSelection == DialogResult.Cancel)
                                {
                                    return; // exit if user press cancel (or undo)
                                }
                                else
                                {
                                    openArchive.InitialDirectory = Path.GetDirectoryName(openArchive.FileName);
                                    currentDir = Path.GetDirectoryName(openArchive.FileName);
                                }
                            }
                        }
                    }

                    if (texSelection.imageListBox.CheckedItems.Count == 1)                                            // if user selected only one image to extract
                    {
                        string         imgSize  = texSelection.imageListBox.CheckedItems[0].ToString().Split(' ')[1]; // take imagesize (ex. 512x512) from checklist text: "Image 512x512 stored..."
                        SaveFileDialog saveFile = new SaveFileDialog();
                        saveFile.Title    = "Select the location to save the image";
                        saveFile.FileName = tex2D.texName + "_" + imgSize + tex2D.getFileFormat();
                        saveFile.Filter   = "Image file|*" + tex2D.getFileFormat() + "|All files|*.*";
                        //saveFile.RestoreDirectory = true;
                        DialogResult resultSelection = saveFile.ShowDialog();
                        if (resultSelection == DialogResult.OK)
                        {
                            imgFileName   = Path.GetFileName(saveFile.FileName);
                            imgFileFolder = Path.GetDirectoryName(saveFile.FileName);
                        }
                        else
                        {
                            return;
                        }
                    }
                    else // if user selected multiple images to extract
                    {
                        FolderBrowserDialog saveFolder = new FolderBrowserDialog();
                        saveFolder.Description = "Select the folder location to save all the images";
                        DialogResult resultSelection = saveFolder.ShowDialog();
                        if (resultSelection == DialogResult.OK)
                        {
                            imgFileFolder = saveFolder.SelectedPath;
                        }
                        else
                        {
                            return;
                        }
                    }

                    // main extraction loop
                    foreach (Object entry in texSelection.imageListBox.CheckedItems)
                    {
                        string imgSize = entry.ToString().Split(' ')[1]; // take imagesize (ex. 512x512) from checklist text: "Image 512x512 stored..."
                        string imgFinalFileName;
                        if (imgFileName == null)
                        {
                            imgFinalFileName = tex2D.texName + "_" + imgSize + tex2D.getFileFormat();
                        }
                        else
                        {
                            imgFinalFileName = imgFileName;
                        }
                        string fullpath = imgFileFolder + "\\" + imgFinalFileName;

                        // extraction function
                        tex2D.extractImage(imgSize, currentDir, fullpath);
                    }

                    // update the pcc with the new replaced infos
                    ListViewItem          item     = listView1.SelectedItems[0];
                    int                   index    = Convert.ToInt32(item.Name);
                    PCCObject.ExportEntry expEntry = pcc.Exports[index];
                    expEntry.Data = tex2D.ToArray(expEntry.DataOffset);
                    //pcc.ChangeExportEntry(index, expEntry);
                    //pcc.UpdateAllOffsets();

                    MessageBox.Show("All images are extracted correctly.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (Exception exc)
                {
                    MessageBox.Show("An error occurred while extracting images: " + exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }