Inheritance: System.Windows.Forms.Form
示例#1
0
        private void saveChangesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (pcc == null || currentPCC == "")
            {
                return;
            }
            pcc.altSaveToFile(currentPCC, true);
            FileStream fs   = new FileStream(currentPCC, FileMode.Open, FileAccess.Read);
            uint       size = (uint)fs.Length;
            string     name = Path.GetFileName(currentPCC);

            fs.Close();
            TOCeditor tc = new TOCeditor();

            tc.MdiParent = this.ParentForm;
            string tocpath = ME3Directory.tocFile;

            if (File.Exists(tocpath))
            {
                if (!tc.UpdateFile(name, size, tocpath))
                {
                    MessageBox.Show("Didn't found Entry");
                }
            }
            else
            {
                if (!tc.UpdateFile(name, size))
                {
                    MessageBox.Show("Didn't found Entry");
                }
            }
            tc.Close();
            MessageBox.Show("File " + Path.GetFileName(currentPCC) + " saved.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
示例#2
0
        private void tOCbinEditorToolStripMenuItem_Click_1(object sender, EventArgs e)
        {
            TOCeditor tocedit = new TOCeditor();

            lang.SetLang(tocedit);
            tocedit.MdiParent   = this;
            tocedit.WindowState = FormWindowState.Maximized;
            tocedit.Show();
            taskbar.AddTool(tocedit, Properties.Resources.TOCbin_editor_64x64);
        }
示例#3
0
        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string         path        = string.Empty;
            SaveFileDialog FileDialog1 = new SaveFileDialog();

            FileDialog1.Filter          = "*.cnd|*.cnd";
            BitConverter.IsLittleEndian = true;
            if (FileDialog1.ShowDialog() == DialogResult.OK)
            {
                path = FileDialog1.FileName;
                FileStream   fileStream = new FileStream(path, FileMode.Create, FileAccess.Write);
                MemoryStream m          = new MemoryStream();
                m.Write(BitConverter.GetBytes((uint)0x434F4E44), 0, 4);
                m.Write(BitConverter.GetBytes((int)1), 0, 4);
                m.Write(BitConverter.GetBytes((Int16)UnknownInt16), 0, 2);
                m.Write(BitConverter.GetBytes((Int16)Entry.Count), 0, 2);
                for (int i = 0; i < Entry.Count; i++)
                {
                    Entries en = Entry[i];
                    m.Write(BitConverter.GetBytes(en.id), 0, 4);
                    m.Write(BitConverter.GetBytes(en.off), 0, 4);
                }
                for (int i = 0; i < Entry.Count; i++)
                {
                    Entries en = Entry[i];
                    en.off   = (int)m.Position;
                    Entry[i] = en;
                    m.Write(en.data, 0, en.size);
                }
                int pos = 16;
                for (int i = 0; i < Entry.Count; i++)
                {
                    Entries en = Entry[i];
                    m.Seek(pos, SeekOrigin.Begin);
                    m.Write(BitConverter.GetBytes((uint)en.off), 0, 4);
                    pos += 8;
                }
                fileStream.Write(m.ToArray(), 0, (int)m.Length);
                fileStream.Close();

                TOCeditor tc = new TOCeditor();
                tc.MdiParent = this.ParentForm;
                tc.Show();
                string fname = Path.GetFileName(path);
                if (!tc.UpdateFile(fname, (uint)memsize))
                {
                    MessageBox.Show("Didn't found entry!");
                }
                tc.Close();
                LoadFile(path);
            }
        }
示例#4
0
        private void saveChangesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int size = Level.pcc.memsize;

            for (int i = 0; i < Level.UStatColl.Count; i++)
            {
                if (Level.UStatColl[i].CHANGED)
                {
                    Level.pcc.appendStream(Level.UStatColl[i].memory);
                    Level.pcc.RedirectEntry(Level.UStatColl[i].LP.sourceentry, size, Level.UStatColl[i].memsize);
                }
            }
            if (Level.pcc.memsize != size)
            {
                TOCeditor tc = new TOCeditor();
                if (!tc.UpdateFile(Level.pcc.loadedFilename, (uint)size))
                {
                    MessageBox.Show("Didn't found Entry");
                }
            }
        }
示例#5
0
        private void addBiggestImageToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //try
            {
                if (tex2D.imgList.Count <= 1)
                {
                    MessageBox.Show("You cannot upscale a texture that has only one image!", "Invalid operation", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                string currentDir = pathCooked;
                string texGroupToAdd;
                OpenFileDialog openImage = openFileDialog;
                openImage.Title = "Select the image to add";
                openImage.Filter = "Image file|*" + tex2D.getFileFormat() + "|All files|*.*";

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

                // add function
                int numTexBegin = tex2D.imgList.Count;
                tex2D.OneImageToRuleThemAll(openImage.FileName, currentDir, out texGroupToAdd);
                int numTexEnd = tex2D.imgList.Count;

                //--------- 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))
                        {
                            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))
                        {
                            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 -------------------------------
                if(texGroupToAdd != null)
                    MessageBox.Show("Texture replaced correctly. Make sure to add " + texGroupToAdd + " inside coalesced.bin", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                else
                    MessageBox.Show("Texture replaced correctly.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            /*catch (Exception exc)
            {
                MessageBox.Show("An error occurred while replacing texture: " + exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }*/
        }
示例#6
0
        private void upscaleToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                if (tex2D.imgList.Count <= 1)
                {
                    MessageBox.Show("You cannot upscale a texture that has only one image!", "Invalid operation", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                string currentDir = pathCooked;
                OpenFileDialog openImage = openFileDialog;
                openImage.Title = "Select the image to add";
                openImage.Filter = "Image file|*" + tex2D.getFileFormat() + "|All files|*.*";

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

                // add function
                tex2D.addBiggerImage(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))
                        {
                            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))
                        {
                            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 -------------------------------

                /*
                // code test to prove that tex2d works, just decomment it and comment precedent code
                byte[] pccFile = PCCHandler.Decompress(pcc.pccFileName);
                using (FileStream debugStr = File.OpenWrite(pcc.pccFileName))
                {
                    debugStr.Write(pccFile, 0, pccFile.Length);
                    debugStr.Seek(expEntry.DataOffset, SeekOrigin.Begin);
                    byte[] buffer = tex2D.ToArray(expEntry.DataOffset);
                    debugStr.Write(buffer, 0, buffer.Length);
                }*/
                MessageBox.Show("Image was added correctly.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception exc)
            {
                MessageBox.Show("An error occurred while adding image: " + exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#7
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);
                }
            }
        }
示例#8
0
 private void saveChangesToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (pcc == null || currentPCC == "")
         return;
     pcc.altSaveToFile(currentPCC, true);
     FileStream fs = new FileStream(currentPCC, FileMode.Open, FileAccess.Read);
     uint size = (uint)fs.Length;
     string name = Path.GetFileName(currentPCC);
     fs.Close();
     TOCeditor tc = new TOCeditor();
     tc.MdiParent = this.ParentForm;
     string tocpath = ME3Directory.tocFile;
     if (File.Exists(tocpath))
     {
         if (!tc.UpdateFile(name, size, tocpath))
             MessageBox.Show("Didn't found Entry");
     }
     else
     {
         if (!tc.UpdateFile(name, size))
             MessageBox.Show("Didn't found Entry");
     }
     tc.Close();
     MessageBox.Show("File " + Path.GetFileName(currentPCC) + " saved.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
 }
示例#9
0
        private void addBiggestImageToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //try
            {
                if (tex2D.imgList.Count <= 1)
                {
                    MessageBox.Show("You cannot upscale a texture that has only one image!", "Invalid operation", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                string         currentDir = pathCooked;
                string         texGroupToAdd;
                OpenFileDialog openImage = openFileDialog;
                openImage.Title  = "Select the image to add";
                openImage.Filter = "Image file|*" + tex2D.getFileFormat() + "|All files|*.*";

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

                // add function
                int numTexBegin = tex2D.imgList.Count;
                tex2D.OneImageToRuleThemAll(openImage.FileName, currentDir, out texGroupToAdd);
                int numTexEnd = tex2D.imgList.Count;

                //--------- 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))
                        {
                            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))
                        {
                            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 -------------------------------
                if (texGroupToAdd != null)
                {
                    MessageBox.Show("Texture replaced correctly. Make sure to add " + texGroupToAdd + " inside coalesced.bin", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("Texture replaced correctly.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }

            /*catch (Exception exc)
             * {
             *  MessageBox.Show("An error occurred while replacing texture: " + exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
             * }*/
        }
示例#10
0
        private void upscaleToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                if (tex2D.imgList.Count <= 1)
                {
                    MessageBox.Show("You cannot upscale a texture that has only one image!", "Invalid operation", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                string         currentDir = pathCooked;
                OpenFileDialog openImage  = openFileDialog;
                openImage.Title  = "Select the image to add";
                openImage.Filter = "Image file|*" + tex2D.getFileFormat() + "|All files|*.*";

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

                // add function
                tex2D.addBiggerImage(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))
                        {
                            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))
                        {
                            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 -------------------------------

                /*
                 * // code test to prove that tex2d works, just decomment it and comment precedent code
                 * byte[] pccFile = PCCHandler.Decompress(pcc.pccFileName);
                 * using (FileStream debugStr = File.OpenWrite(pcc.pccFileName))
                 * {
                 *  debugStr.Write(pccFile, 0, pccFile.Length);
                 *  debugStr.Seek(expEntry.DataOffset, SeekOrigin.Begin);
                 *  byte[] buffer = tex2D.ToArray(expEntry.DataOffset);
                 *  debugStr.Write(buffer, 0, buffer.Length);
                 * }*/
                MessageBox.Show("Image was added correctly.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception exc)
            {
                MessageBox.Show("An error occurred while adding image: " + exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#11
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);
                }
            }
        }
示例#12
0
 private void tOCbinEditorToolStripMenuItem_Click_1(object sender, EventArgs e)
 {
     TOCeditor tocedit = new TOCeditor();
     lang.SetLang(tocedit);
     tocedit.MdiParent = this;
     tocedit.WindowState = FormWindowState.Maximized;
     tocedit.Show();
     taskbar.AddTool(tocedit, Properties.Resources.TOCbin_editor_64x64);
 }
示例#13
0
 private void saveChangesToolStripMenuItem_Click(object sender, EventArgs e)
 {
     int size = Level.pcc.memsize;
     for (int i = 0; i < Level.UStatColl.Count; i++)
         if (Level.UStatColl[i].CHANGED)
         {
             Level.pcc.appendStream(Level.UStatColl[i].memory);
             Level.pcc.RedirectEntry(Level.UStatColl[i].LP.sourceentry, size, Level.UStatColl[i].memsize);
         }
     if (Level.pcc.memsize != size)
     {
         TOCeditor tc = new TOCeditor();
         if (!tc.UpdateFile(Level.pcc.loadedFilename, (uint)size))
             MessageBox.Show("Didn't found Entry");
     }
 }
示例#14
0
        private void Form1_Load(object sender, EventArgs e)
        {
            taskbar.strip = toolStrip1; //this be a toolstrip reference to class taskbar
            string loc = Path.GetDirectoryName(Application.ExecutablePath);

            lang = new Languages(loc + "\\exec\\languages.xml", 0);
            lang.SetLang(this);
            string[] args = Environment.GetCommandLineArgs();
            if (args.Length > 1)
            {
                AttachConsole(ATTACH_PARENT_PROCESS);
                if (args[1].Equals("-version-switch-from") && args.Length == 3)
                {
                    string version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
                    if (version.Equals(args[2]))
                    {
                        MessageBox.Show("Version switched to is the same as the one you had before the switch.");
                    }
                    else
                    {
                        MessageBox.Show("Version switched: " + args[2] + " => " + version);
                    }
                }
                else
                //automation
                if (args[1].Equals("-dlcinject") || args[1].Equals("-dlcextract") || args[1].Equals("-dlcaddfiles") || args[1].Equals("-dlcremovefiles") || args[1].Equals("-dlcunpack") || args[1].Equals("-dlcunpack-nodebug"))
                {
                    //autostart DLC editor 2 (used by FemShep's Mod Manager 3/3.1+)
                    //saves a little duplicate code
                    dLCEditor2ToolStripMenuItem.PerformClick();
                    return;
                }
                else
                if (args[1].Equals("-toceditorupdate"))
                {
                    //autostart the TOCEditor (used by FemShep's Mod Manager 3)
                    TOCeditor tocedit = new TOCeditor();
                    lang.SetLang(tocedit);
                    tocedit.MdiParent   = this;
                    tocedit.WindowState = FormWindowState.Maximized;
                    tocedit.Show();
                    taskbar.AddTool(tocedit, Properties.Resources.TOCbin_editor_64x64);
                    return;
                }
                if (args[1].Equals("-autotoc"))
                {
                    //autostart the AutoTOC Tool (uses a path) (used by FemShep's Mod Manager 3)
                    //saves a little duplicate code
                    autoTOCToolStripMenuItem.PerformClick();
                    return;
                }
                else
                if (args[1].Equals("-decompresspcc"))
                {
                    //autostart the TOCEditor (used by FemShep's Mod Manager 3.2)
                    //saves a little duplicate code
                    pCCRepackerToolStripMenuItem.PerformClick();
                    return;
                }
                else
                if (args[1].Equals("--help") || args[1].Equals("-h") || args[1].Equals("/?"))
                {
                    string version         = Assembly.GetExecutingAssembly().GetName().Version.ToString();
                    string commandLineHelp = "\nME3Explorer v" + version + " Command Line Options\n";
                    commandLineHelp += " -decompresspcc pccPath.pcc decompressedPath.pcc\n";
                    commandLineHelp += "     Automates PCCRepacker to decompress a pcc to the new location.\n\n";
                    commandLineHelp += " -dlcinject DLC.sfar SearchTerm PathToNewFile [SearchTerm2 PathToNewFile2]...\n";
                    commandLineHelp += "     Automates injecting pairs of files into a .sfar file using DLCEditor2. SearchTerm is a value you would type into the searchbox with the first result being the file that will be replaced.\n\n";
                    commandLineHelp += " -dlcextract DLC.sfar SearchTerm ExtractionPath\n";
                    commandLineHelp += "     Automates DLCEditor2 to extract the specified SearchTerm. SearchTerm is a value you would type into the searchbox with the first result being the file that will be extracted. The file is extracted to the specied ExtractionPath.\n\n";
                    commandLineHelp += " -dlcaddfiles DLC.sfar InternalPath NewFile [InternalPath2 NewFile2]...\n";
                    commandLineHelp += "     Automates DLCEditor2 to add the specified new files. InternalPath is the internal path in the SFAR the file NewFile will be placed at.\n\n";
                    commandLineHelp += " -dlcremovefiles DLC.sfar SearchTerm [SearchTerm2]...\n";
                    commandLineHelp += "     Automates removing a file or list of files from a DLC. SearchTerm is a value you would type into the Searchbox with the first result being the file that will be removed.\n\n";
                    commandLineHelp += " -dlcunpack DLC.sfar Unpackpath\n";
                    commandLineHelp += "     Automates unpacking an SFAR file to the specified directory. Shows the debug interface to show progress. To unpack a game DLC for use by the game, unpack to the Mass Effect 3 directory. Unpacking Patch_001.sfar will cause the game to crash at startup.\n\n";
                    commandLineHelp += " -dlcunpack-nodebug DLC.sfar Unpackpath\n";
                    commandLineHelp += "     Same as -dlcunpack but does not show the debugging interface.\n\n";
                    commandLineHelp += " -toceditorupdate PCConsoleTOCFile.bin SearchTerm size\n";
                    commandLineHelp += "     Automates DLCEditor2 to extract the specified SearchTerm. SearchTerm is a value you would type into the searchbox with the first result being the file that will be extracted. The file is extracted to the specied ExtractionPath.\n\n";
                    System.Console.WriteLine(commandLineHelp);
                    Environment.Exit(0);
                    Application.Exit();
                    return;
                }

                string ending = Path.GetExtension(args[1]).ToLower();
                switch (ending)
                {
                case ".pcc":
                    PCCEditor2 editor = new PCCEditor2();
                    editor.MdiParent = this;
                    editor.Show();
                    editor.WindowState = FormWindowState.Maximized;
                    editor.LoadFile(args[1]);
                    break;

                case ".txt":
                    ScriptCompiler sc = new ScriptCompiler();
                    sc.MdiParent = this;
                    sc.rtb1.LoadFile(args[1]);
                    sc.Compile();
                    sc.Show();
                    sc.WindowState = FormWindowState.Maximized;
                    break;

                    /*case ".mod":    // KFreon: Disabled for now due to the fact that it doesn't do the DLC check first
                     *  ModMaker m = new ModMaker();
                     *  m.Show();
                     *  string[] s = new string[1];
                     *  s[0] = args[1];
                     *  //m.LoadMods(s);
                     *  m.WindowState = FormWindowState.Maximized;
                     *  break;*/
                }
            }

            if (!String.IsNullOrEmpty(Properties.Settings.Default.ME3InstallDir))
            {
                ME3Directory.GamePath(Properties.Settings.Default.ME3InstallDir);
            }
            if (!String.IsNullOrEmpty(Properties.Settings.Default.ME2InstallDir))
            {
                ME2Directory.GamePath(Properties.Settings.Default.ME2InstallDir);
            }
            if (!String.IsNullOrEmpty(Properties.Settings.Default.ME1InstallDir))
            {
                ME1Directory.GamePath(Properties.Settings.Default.ME1InstallDir);
            }

            var vers = Assembly.GetExecutingAssembly().GetName().Version.ToString();

            versionToolStripMenuItem.Text += vers;
            versionToolStripMenuItem.Tag   = "versionItem";
            menuStrip1.Renderer            = new NoHighlightRenderer();

            if (!disableDLCCheckOnStartupToolStripMenuItem.Checked)
            {
                DoDLCCheck();
            }
        }
示例#15
0
        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string path = string.Empty;
            SaveFileDialog FileDialog1 = new SaveFileDialog();
            FileDialog1.Filter = "*.cnd|*.cnd";
            BitConverter.IsLittleEndian = true;
            if (FileDialog1.ShowDialog() == DialogResult.OK)
            {
                path = FileDialog1.FileName;
                FileStream fileStream = new FileStream(path, FileMode.Create, FileAccess.Write);
                MemoryStream m = new MemoryStream();
                m.Write(BitConverter.GetBytes((uint)0x434F4E44), 0, 4);
                m.Write(BitConverter.GetBytes((int)1), 0, 4);
                m.Write(BitConverter.GetBytes((Int16)UnknownInt16), 0, 2);
                m.Write(BitConverter.GetBytes((Int16)Entry.Count), 0, 2);
                for (int i = 0; i < Entry.Count; i++)
                {
                    Entries en = Entry[i];
                    m.Write(BitConverter.GetBytes(en.id), 0, 4);
                    m.Write(BitConverter.GetBytes(en.off), 0, 4);
                }
                for (int i = 0; i < Entry.Count; i++)
                {
                    Entries en = Entry[i];
                    en.off = (int)m.Position;
                    Entry[i] = en;
                    m.Write(en.data, 0, en.size);
                }
                int pos = 16;
                for (int i = 0; i < Entry.Count; i++)
                {
                    Entries en = Entry[i];
                    m.Seek(pos, SeekOrigin.Begin);
                    m.Write(BitConverter.GetBytes((uint)en.off), 0, 4);
                    pos += 8;
                }
                fileStream.Write(m.ToArray(), 0, (int)m.Length);
                fileStream.Close();

                TOCeditor tc = new TOCeditor();
                tc.MdiParent = this.ParentForm;
                tc.Show();
                string fname = Path.GetFileName(path);
                if (!tc.UpdateFile(fname, (uint)memsize))
                    MessageBox.Show("Didn't found entry!");
                tc.Close();
                LoadFile(path);
            }
        }
示例#16
0
        /// <summary>
        /// Will update PCConsoleTOC.bin for a particular filename s
        /// </summary>
        /// <param name="s">The filename of the file to be updated</param>
        private bool tocUpdater(string s)
        {
            FileInfo finfo = new FileInfo(s);
            if (!finfo.Exists)
                throw new FileNotFoundException("File: " + s + " not found");
            if (String.IsNullOrEmpty(tocpath))
                tocpath = Path.Combine(pathBIOGame, "PCConsoleTOC.bin");
            TOCeditor tc = new TOCeditor();
            if (!File.Exists(tocpath))
            {
                OpenFileDialog tocopen = new OpenFileDialog();
                tocopen.Title = "Select the PCConsoleTOC.bin file to use";
                tocopen.Filter = "TOC.bin|PCConsoleTOC.bin";
                if (tocopen.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                {
                    MessageBox.Show("Since you have elected not to select your TOC.bin file, you'll get harrassed every time the program wants to update it and the game will crash unless you run the TOCbinUpdater tool", "I hope you're happy", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return false;
                }
                tocpath = tocopen.FileName;
            }

            // KFreon: If normal TOC update fails, try with WV's
            if (!tc.UpdateFile(Path.GetFileName(s), (uint)finfo.Length, tocpath))
                return false;
            else
                return true;
        }
示例#17
0
 private void tOCbinEditorToolStripMenuItem_Click_1(object sender, EventArgs e)
 {
     TOCeditor tocedit = new TOCeditor();
     lang.SetLang(tocedit);
     tocedit.MdiParent = this;
     tocedit.WindowState = FormWindowState.Maximized;
     tocedit.Show();
     taskbar.AddTool(tocedit, imageList1.Images[3]);
 }
示例#18
0
        private bool HandleCommandLineArgs(string[] args, out int exitCode)
        {
            if (args.Length < 2)
            {
                exitCode = 0;
                return(false);
            }
            //automation
            try
            {
                if (args[1].Equals("-dlcinject"))
                {
                    if (args.Length % 2 != 1 || args.Length < 5)
                    {
                        MessageBox.Show("Wrong number of arguments for the -dlcinject switch.:\nSyntax is: <exe> -dlcinject SFARPATH SEARCHTERM NEWFILEPATH [SEARCHTERM2 NEWFILEPATH2]...", "ME3 DLCEditor2 Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        exitCode = 1;
                        return(true);
                    }
                    string dlcFileName = args[2];
                    int    numfiles    = (args.Length - 3) / 2;

                    string[] filesToReplace = new string[numfiles];
                    string[] newFiles       = new string[numfiles];

                    int argnum = 3; //starts at 3
                    for (int i = 0; i < filesToReplace.Length; i++)
                    {
                        filesToReplace[i] = args[argnum];
                        argnum++;
                        newFiles[i] = args[argnum];
                        argnum++;
                    }
                    if (File.Exists(dlcFileName))
                    {
                        DLCPackage dlc = new DLCPackage(dlcFileName);
                        for (int i = 0; i < numfiles; i++)
                        {
                            int idx = dlc.FindFileEntry(filesToReplace[i]);
                            if (idx == -1)
                            {
                                MessageBox.Show("DLCEditor2 automator encountered an error: the file to replace does not exist.", "ME3 DLCEditor2 Error", MessageBoxButton.OK, MessageBoxImage.Error);
                                exitCode = 1;
                                return(true);
                            }
                            dlc.ReplaceEntry(newFiles[i], idx);
                        }
                        exitCode = 0;
                        return(true);
                    }
                    MessageBox.Show("Failed to autoinject: DLC file does not exist: " + dlcFileName, "ME3Explorer DLCEditor2 Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    exitCode = 1;
                    return(true);
                }
                else if (args[1].Equals("-dlcextract"))
                {
                    if (args.Length != 5)
                    {
                        //-2 for me3explorer & -dlcextract
                        MessageBox.Show("Wrong number of arguments for the -dlcextract switch.:\nSyntax is: <exe> -dlcextract SFARPATH SEARCHTERM EXTRACTIONPATH", "ME3 DLCEditor2 Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        exitCode = 1;
                        return(true);
                    }
                    string dlcFileName    = args[2];
                    string searchTerm     = args[3];
                    string extractionPath = args[4];
                    if (File.Exists(dlcFileName))
                    {
                        DLCPackage dlc = new DLCPackage(dlcFileName);
                        int        idx = dlc.FindFileEntry(searchTerm);
                        if (idx == -1)
                        {
                            MessageBox.Show("DLCEditor2 extraction automator encountered an error:\nThe file to replace does not exist or the tree has not been initialized.", "DLCEditor2 Error", MessageBoxButton.OK, MessageBoxImage.Error);
                            exitCode = 1;
                            return(true);
                        }
                        using (FileStream fs = new FileStream(extractionPath, FileMode.Create, FileAccess.Write, FileShare.None, 4096, useAsync: true))
                        {
                            dlc.DecompressEntryAsync(idx, fs).Wait();
                        }
                        exitCode = 0;
                        return(true);
                    }
                    MessageBox.Show("Failed to autoextract: DLC file does not exist: " + dlcFileName, "ME3Explorer DLCEditor2 Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    exitCode = 1;
                    return(true);
                }
                else if (args[1].Equals("-dlcaddfiles"))
                {
                    if (args.Length % 2 != 1 || args.Length < 5)
                    {
                        MessageBox.Show("Wrong number of arguments for the -dlcaddfiles switch.:\nSyntax is: <exe> -dlcinject SFARPATH INTERNALPATH NEWFILEPATH [INTERNALPATH2 NEWFILEPATH2]...", "ME3 DLCEditor2 Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        exitCode = 1;
                        return(true);
                    }

                    string   dlcFileName   = args[2];
                    int      numfiles      = (args.Length - 3) / 2;
                    string[] internalPaths = new string[numfiles];
                    string[] sourcePaths   = new string[numfiles];

                    int argnum = 3; //starts at 3
                    for (int i = 0; i < internalPaths.Length; i++)
                    {
                        internalPaths[i] = args[argnum];
                        argnum++;
                        sourcePaths[i] = args[argnum];
                        argnum++;
                    }

                    if (File.Exists(dlcFileName))
                    {
                        DLCPackage dlc = new DLCPackage(dlcFileName);
                        for (int i = 0; i < internalPaths.Length; i++)
                        {
                            dlc.AddFileQuick(sourcePaths[i], internalPaths[i]);
                        }
                        exitCode = 0;
                        return(true);
                    }
                    MessageBox.Show("Failed to autoadd: DLC file does not exist: " + dlcFileName, "ME3Explorer DLCEditor2 Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    exitCode = 1;
                    return(true);
                }
                else if (args[1].Equals("-dlcremovefiles"))
                {
                    if (args.Length < 4)
                    {
                        //-2 for me3explorer & -dlcextract
                        MessageBox.Show("Wrong number of arguments for the -dlcremovefiles switch.:\nSyntax is: <exe> -dlcinject SFARPATH INTERNALPATH [INTERNALPATH2]...", "ME3 DLCEditor2 Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        exitCode = 1;
                        return(true);
                    }
                    string   dlcFileName   = args[2];
                    int      numfiles      = (args.Length - 3);
                    string[] filesToRemove = new string[numfiles];
                    int      argnum        = 3; //starts at 3
                    for (int i = 0; i < filesToRemove.Length; i++)
                    {
                        filesToRemove[i] = args[argnum];
                        argnum++;
                    }

                    if (File.Exists(dlcFileName))
                    {
                        DLCPackage dlc = new DLCPackage(dlcFileName);
                        for (int i = 0; i < filesToRemove.Length; i++)
                        {
                            int idx = dlc.FindFileEntry(filesToRemove[i]);
                            if (idx == -1)
                            {
                                MessageBox.Show("DLCEditor2 file removal automator encountered an error:\nThe file to remove does not exist or the tree has not been initialized.", "DLCEditor2 Error", MessageBoxButton.OK, MessageBoxImage.Error);
                                exitCode = 1;
                                return(true);
                            }
                            dlc.DeleteEntry(idx);
                        }
                        exitCode = 0;
                        return(true);
                    }
                    MessageBox.Show("Failed to autoremove: DLC file does not exist: " + dlcFileName, "ME3Explorer DLCEditor2 Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    exitCode = 1;
                    return(true);
                }
                else if (args[1].Equals("-dlcunpack") || args[1].Equals("-dlcunpack-nodebug"))
                {
                    if (args.Length != 4)
                    {
                        MessageBox.Show("Wrong number of arguments for automated DLC unpacking:\nSyntax is: <exe> -dlcunpack SFARPATH EXTRACTIONPATH", "ME3 DLCEditor2 Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        exitCode = 1;
                        return(true);
                    }

                    string sfarPath         = args[2];
                    string autoUnpackFolder = args[3];

                    if (File.Exists(sfarPath))
                    {
                        DLCPackage dlc = new DLCPackage(sfarPath);
                        if (args[1].Equals("-dlcunpack"))
                        {
                            //open debugging window since this operation takes a long time.
                            KFreonLib.Debugging.DebugOutput.StartDebugger("DLC Editor 2");
                        }
                        //Simulate Unpack operation click.
                        SFAREditor2.unpackSFAR(dlc);
                        exitCode = 0;
                        return(true);
                    }
                    else
                    {
                        MessageBox.Show("Failed to autounpack: DLC file does not exist: " + sfarPath, "ME3Explorer DLCEditor2 Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        exitCode = 1;
                        return(true);
                    }
                }
                else if (args[1].Equals("-toceditorupdate"))
                {
                    //Legacy command requested by FemShep
                    TOCeditor toc = new TOCeditor();
                    exitCode = toc.updateTOCFromCommandLine(args.Skip(2).ToList());
                    return(true);
                }
                else if (args[1].Equals("-autotoc"))
                {
                    if (args.Length == 2)
                    {
                        AutoTOC.GenerateAllTOCs();
                    }
                    else
                    {
                        AutoTOC.prepareToCreateTOC(args[2]);
                    }
                    exitCode = 0;
                    return(true);
                }
                else if (args[1].Equals("-sfarautotoc"))
                {
                    if (args.Length != 3)
                    {
                        MessageBox.Show("-sfarautotoc command line argument requires at least 1 parameter:\nSFARFILE.sfar", "Automated SFAR TOC Update Fail", MessageBoxButton.OK, MessageBoxImage.Error);
                        exitCode = 1;
                        return(true);
                    }

                    var result = Parallel.For(2, args.Length, i =>
                    {
                        if (args[i].EndsWith(".sfar") && File.Exists(args[i]))
                        {
                            DLCPackage DLC = new DLCPackage(args[2]);
                            DLC.UpdateTOCbin(true);
                        }
                    });
                    exitCode = result.IsCompleted ? 0 : 1;
                    return(true);
                }
                else if (args[1].Equals("-decompresspcc"))
                {
                    if (args.Length != 4)
                    {
                        MessageBox.Show("-decompresspcc command line argument requires 2 parameters:\ninputfile.pcc outputfile.pcc\nBoth arguments can be the same.", "Auto Decompression Error", MessageBoxButton.OK, MessageBoxImage.Error);

                        exitCode = 1;
                        return(true);
                    }
                    exitCode = PCCRepack.autoDecompressPcc(args[2], args[3]);
                    return(true);
                }
                else if (args[1].Equals("-compresspcc"))
                {
                    if (args.Length != 4)
                    {
                        MessageBox.Show("-compresspcc command line argument requires 2 parameters:\ninputfile.pcc outputfile.pcc\nBoth arguments can be the same.", "Auto Compression Error", MessageBoxButton.OK, MessageBoxImage.Error);

                        exitCode = 1;
                        return(true);
                    }
                    exitCode = PCCRepack.autoCompressPcc(args[2], args[3]);
                    return(true);
                }
            }
            catch
            {
                exitCode = 1;
                return(true);
            }

            string ending = Path.GetExtension(args[1]).ToLower();

            switch (ending)
            {
            case ".pcc":
                PackageEditor editor = new PackageEditor();
                editor.Show();
                editor.LoadFile(args[1]);
                break;
            }
            exitCode = 0;
            return(false);
        }
示例#19
0
        private bool HandleCommandLineArgs(string[] args, out int exitCode)
        {
            if (args.Length < 2)
            {
                exitCode = 0;
                return false;
            }
            //automation
            try
            {
                if (args[1].Equals("-dlcinject"))
                {
                    if (args.Length % 2 != 1 || args.Length < 5)
                    {
                        MessageBox.Show("Wrong number of arguments for the -dlcinject switch.:\nSyntax is: <exe> -dlcinject SFARPATH SEARCHTERM NEWFILEPATH [SEARCHTERM2 NEWFILEPATH2]...", "ME3 DLCEditor2 Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        exitCode = 1;
                        return true;
                    }
                    string dlcFileName = args[2];
                    int numfiles = (args.Length - 3) / 2;

                    string[] filesToReplace = new string[numfiles];
                    string[] newFiles = new string[numfiles];

                    int argnum = 3; //starts at 3
                    for (int i = 0; i < filesToReplace.Length; i++)
                    {
                        filesToReplace[i] = args[argnum];
                        argnum++;
                        newFiles[i] = args[argnum];
                        argnum++;
                    }
                    if (File.Exists(dlcFileName))
                    {
                        DLCPackage dlc = new DLCPackage(dlcFileName);
                        for (int i = 0; i < numfiles; i++)
                        {
                            int idx = dlc.FindFileEntry(filesToReplace[i]);
                            if (idx == -1)
                            {
                                MessageBox.Show("DLCEditor2 automator encountered an error: the file to replace does not exist.", "ME3 DLCEditor2 Error", MessageBoxButton.OK, MessageBoxImage.Error);
                                exitCode = 1;
                                return true;
                            }
                            dlc.ReplaceEntry(newFiles[i], idx);
                        }
                        exitCode = 0;
                        return true;
                    }
                    MessageBox.Show("Failed to autoinject: DLC file does not exist: " + dlcFileName, "ME3Explorer DLCEditor2 Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    exitCode = 1;
                    return true;
                }
                else if (args[1].Equals("-dlcextract"))
                {
                    if (args.Length != 5)
                    {
                        //-2 for me3explorer & -dlcextract
                        MessageBox.Show("Wrong number of arguments for the -dlcextract switch.:\nSyntax is: <exe> -dlcextract SFARPATH SEARCHTERM EXTRACTIONPATH", "ME3 DLCEditor2 Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        exitCode = 1;
                        return true;
                    }
                    string dlcFileName = args[2];
                    string searchTerm = args[3];
                    string extractionPath = args[4];
                    if (File.Exists(dlcFileName))
                    {
                        DLCPackage dlc = new DLCPackage(dlcFileName);
                        int idx = dlc.FindFileEntry(searchTerm);
                        if (idx == -1)
                        {
                            MessageBox.Show("DLCEditor2 extraction automator encountered an error:\nThe file to replace does not exist or the tree has not been initialized.", "DLCEditor2 Error", MessageBoxButton.OK, MessageBoxImage.Error);
                            exitCode = 1;
                            return true;
                        }
                        using (FileStream fs = new FileStream(extractionPath, FileMode.Create, FileAccess.Write, FileShare.None, 4096, useAsync: true))
                        {
                            dlc.DecompressEntryAsync(idx, fs).Wait();
                        }
                        exitCode = 0;
                        return true;
                    }
                    MessageBox.Show("Failed to autoextract: DLC file does not exist: " + dlcFileName, "ME3Explorer DLCEditor2 Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    exitCode = 1;
                    return true;

                }
                else if (args[1].Equals("-dlcaddfiles"))
                {
                    if (args.Length % 2 != 1 || args.Length < 5)
                    {
                        MessageBox.Show("Wrong number of arguments for the -dlcaddfiles switch.:\nSyntax is: <exe> -dlcinject SFARPATH INTERNALPATH NEWFILEPATH [INTERNALPATH2 NEWFILEPATH2]...", "ME3 DLCEditor2 Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        exitCode = 1;
                        return true;
                    }
                    
                    string dlcFileName = args[2];
                    int numfiles = (args.Length - 3) / 2;
                    string[] internalPaths = new string[numfiles];
                    string[] sourcePaths = new string[numfiles];

                    int argnum = 3; //starts at 3
                    for (int i = 0; i < internalPaths.Length; i++)
                    {
                        internalPaths[i] = args[argnum];
                        argnum++;
                        sourcePaths[i] = args[argnum];
                        argnum++;
                    }

                    if (File.Exists(dlcFileName))
                    {
                        DLCPackage dlc = new DLCPackage(dlcFileName);
                        for (int i = 0; i < internalPaths.Length; i++)
                        {
                            dlc.AddFileQuick(sourcePaths[i], internalPaths[i]);
                        }
                        exitCode = 0;
                        return true;
                    }
                    MessageBox.Show("Failed to autoadd: DLC file does not exist: " + dlcFileName, "ME3Explorer DLCEditor2 Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    exitCode = 1;
                    return true;
                }
                else if (args[1].Equals("-dlcremovefiles"))
                {
                    if (args.Length < 4)
                    {
                        //-2 for me3explorer & -dlcextract
                        MessageBox.Show("Wrong number of arguments for the -dlcremovefiles switch.:\nSyntax is: <exe> -dlcinject SFARPATH INTERNALPATH [INTERNALPATH2]...", "ME3 DLCEditor2 Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        exitCode = 1;
                        return true;
                    }
                    string dlcFileName = args[2];
                    int numfiles = (args.Length - 3);
                    string[] filesToRemove = new string[numfiles];
                    int argnum = 3; //starts at 3
                    for (int i = 0; i < filesToRemove.Length; i++)
                    {
                        filesToRemove[i] = args[argnum];
                        argnum++;
                    }

                    if (File.Exists(dlcFileName))
                    {
                        DLCPackage dlc = new DLCPackage(dlcFileName);
                        for (int i = 0; i < filesToRemove.Length; i++)
                        {
                            int idx = dlc.FindFileEntry(filesToRemove[i]);
                            if (idx == -1)
                            {
                                MessageBox.Show("DLCEditor2 file removal automator encountered an error:\nThe file to remove does not exist or the tree has not been initialized.", "DLCEditor2 Error", MessageBoxButton.OK, MessageBoxImage.Error);
                                exitCode = 1;
                                return true;
                            }
                            dlc.DeleteEntry(idx);
                        }
                        exitCode = 0;
                        return true;
                    }
                    MessageBox.Show("Failed to autoremove: DLC file does not exist: " + dlcFileName, "ME3Explorer DLCEditor2 Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    exitCode = 1;
                    return true;

                }
                else if (args[1].Equals("-dlcunpack") || args[1].Equals("-dlcunpack-nodebug"))
                {
                    if (args.Length != 4)
                    {
                        MessageBox.Show("Wrong number of arguments for automated DLC unpacking:\nSyntax is: <exe> -dlcunpack SFARPATH EXTRACTIONPATH", "ME3 DLCEditor2 Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        exitCode = 1;
                        return true;
                    }

                    string sfarPath = args[2];
                    string autoUnpackFolder = args[3];
                    
                    if (File.Exists(sfarPath))
                    {
                        DLCPackage dlc = new DLCPackage(sfarPath);
                        if (args[1].Equals("-dlcunpack"))
                        {
                            //open debugging window since this operation takes a long time.
                            KFreonLib.Debugging.DebugOutput.StartDebugger("DLC Editor 2");
                        }
                        //Simulate Unpack operation click.
                        SFAREditor2.unpackSFAR(dlc);
                        exitCode = 0;
                        return true;
                    }
                    else
                    {
                        MessageBox.Show("Failed to autounpack: DLC file does not exist: " + sfarPath, "ME3Explorer DLCEditor2 Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        exitCode = 1;
                        return true;
                    }
                }
                else if (args[1].Equals("-toceditorupdate"))
                {
                    //Legacy command requested by FemShep
                    TOCeditor toc = new TOCeditor();
                    exitCode = toc.updateTOCFromCommandLine(args.Skip(2).ToList());
                    return true;
                }
                else if (args[1].Equals("-autotoc"))
                {
                    if (args.Length == 2)
                    {
                        AutoTOC.GenerateAllTOCs();
                    }
                    else
                    {
                        AutoTOC.prepareToCreateTOC(args[2]);
                    }
                    exitCode = 0;
                    return true;
                }
                else if (args[1].Equals("-sfarautotoc"))
                {
                    if (args.Length != 3)
                    {
                        MessageBox.Show("-sfarautotoc command line argument requires at least 1 parameter:\nSFARFILE.sfar", "Automated SFAR TOC Update Fail", MessageBoxButton.OK, MessageBoxImage.Error);
                        exitCode = 1;
                        return true;
                    }
                    
                    var result = Parallel.For(2, args.Length, i =>
                    {
                        if (args[i].EndsWith(".sfar") && File.Exists(args[i]))
                        {
                            DLCPackage DLC = new DLCPackage(args[2]);
                            DLC.UpdateTOCbin(true); 
                        }
                    });
                    exitCode = result.IsCompleted ? 0 : 1;
                    return true;
                }
                else if (args[1].Equals("-decompresspcc"))
                {
                    if (args.Length != 4)
                    {
                        MessageBox.Show("-decompresspcc command line argument requires 2 parameters:\ninputfile.pcc outputfile.pcc\nBoth arguments can be the same.", "Auto Decompression Error", MessageBoxButton.OK, MessageBoxImage.Error);

                        exitCode = 1;
                        return true;
                    }
                    exitCode = PCCRepack.autoDecompressPcc(args[2], args[3]);
                    return true;
                }
                else if (args[1].Equals("-compresspcc"))
                {
                    if (args.Length != 4)
                    {
                        MessageBox.Show("-compresspcc command line argument requires 2 parameters:\ninputfile.pcc outputfile.pcc\nBoth arguments can be the same.", "Auto Compression Error", MessageBoxButton.OK, MessageBoxImage.Error);

                        exitCode = 1;
                        return true;
                    }
                    exitCode = PCCRepack.autoCompressPcc(args[2], args[3]);
                    return true;
                }
            }
            catch
            {
                exitCode = 1;
                return true;
            }

            string ending = Path.GetExtension(args[1]).ToLower();
            switch (ending)
            {
                case ".pcc":
                    PackageEditor editor = new PackageEditor();
                    editor.Show();
                    editor.LoadFile(args[1]);
                    break;
            }
            exitCode = 0;
            return false;
        }