Exemplo n.º 1
0
        public void DebugPrint()
        {
            int count = 0;

            DebugOutput.PrintLn("Listing Files...(" + Entries.Count + ")");
            foreach (Entry e in Entries)
            {
                DebugOutput.PrintLn((count++) + " : " + e.name + " Size: " + DLCPackage.BytesToString(e.size), false);
            }
            //DebugOutput.Update();
        }
Exemplo n.º 2
0
 private void openSFAR(string filename)
 {
     try
     {
         
         DLC = new DLCPackage(filename);
         treeView1.Nodes.Clear();
         treeView1.Nodes.Add(DLC.ToTree());
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
Exemplo n.º 3
0
        private void unpackSFAR(DLCPackage DLC)
        {
            AutoTOC.AutoTOC toc = new AutoTOC.AutoTOC();
            if (DLC == null || DLC.Files == null)
                return;
            string result = "pcc; tfc; afc; cnd; tlk; bin; bik; dlc";
            if (result == "")
                return;
            result = result.Trim();
            if (result.EndsWith(";"))
                result = result.Substring(0, result.Length - 1);
            string[] patt = result.Split(';');
            string file = DLC.MyFileName;                   //full path
            string t1 = Path.GetDirectoryName(file);        //cooked
            string t2 = Path.GetDirectoryName(t1);          //DLC_Name
            string t3 = Path.GetDirectoryName(t2);          //DLC
            string t4 = Path.GetDirectoryName(t3);          //BioGame
            string gamebase = Path.GetDirectoryName(t4);    //Mass Effect3
            DebugOutput.PrintLn("Extracting DLC with gamebase : " + gamebase);
            DebugOutput.PrintLn("DLC name : " + t2);
            if (DLC.Files.Length > 1)
            {
                List<int> Indexes = new List<int>();
                for (int i = 0; i < DLC.Files.Length; i++)
                {
                    string DLCpath = DLC.Files[i].FileName;
                    for (int j = 0; j < patt.Length; j++)
                        if (DLCpath.ToLower().EndsWith(patt[j].Trim().ToLower()) && patt[j].Trim().ToLower() != "")
                        {
                            string relPath = GetRelativePath(DLCpath);
                            string outpath = gamebase + relPath;
                            DebugOutput.PrintLn("Extracting file #" + i.ToString("d4") + ": " + outpath);
                            if (!Directory.Exists(Path.GetDirectoryName(outpath)))
                                Directory.CreateDirectory(Path.GetDirectoryName(outpath));

                            if (!File.Exists(outpath))
                                using (FileStream fs = new FileStream(outpath, FileMode.Create))
                                    DLC.DecompressEntry(i).WriteTo(fs);
                            Indexes.Add(i);
                            Application.DoEvents();
                            break;
                        }
                }
                DLC.DeleteEntry(Indexes);
            }

            // AutoTOC
            DebugOutput.PrintLn("Updating DLC's PCConsoleTOC.bin");
            List<string> FileNames = toc.GetFiles(t2 + "\\");
            List<string> tet = new List<string>(t2.Split('\\'));
            string remov = String.Join("\\", tet.ToArray());
            for (int i = 0; i < FileNames.Count; i++)
                FileNames[i] = FileNames[i].Substring(remov.Length + 1);
            string[] ts = t2.Split('\\');
            tet.Clear();
            tet.AddRange(ts);
            string basepath = String.Join("\\", tet.ToArray()) + '\\';
            string tocfile = t2 + "\\PCConsoleTOC.bin";
            toc.CreateTOC(basepath, tocfile, FileNames.ToArray());
            DebugOutput.PrintLn("DLC Done.");
        }
Exemplo n.º 4
0
        private void replaceFile(String filename, int n)
        {
            DLC.ReplaceEntry(filename, n);

            DLC = new DLCPackage(DLC.MyFileName);
            treeView1.Nodes.Clear();
            treeView1.Nodes.Add(DLC.ToTree());
            SearchNode(filename, treeView1.Nodes[0]);
            if (!automated)
            {
                MessageBox.Show("File Replaced.");
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("Injection complete.");
            }
        }
Exemplo n.º 5
0
 private void rebuildSFARToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (DLC == null)
         return;
     DebugOutput.StartDebugger("DLCEditor2");
     DLC.ReBuild();
     DLC = new DLCPackage(DLC.MyFileName);
     treeView1.Nodes.Clear();
     treeView1.Nodes.Add(DLC.ToTree());
     MessageBox.Show("SFAR Rebuilt.");
 }
Exemplo n.º 6
0
 private DLCPackage openSFAR2(String filename)
 {
     try
     {
         BitConverter.IsLittleEndian = true;
         DLC = new DLCPackage(filename);
         treeView1.Nodes.Clear();
         treeView1.Nodes.Add(DLC.ToTree());
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
     return DLC;
 }
Exemplo n.º 7
0
 private void deleteSelectedToolStripMenuItem_Click(object sender, EventArgs e)
 {
     TreeNode t = treeView1.SelectedNode;
     if (DLC == null || t == null || t.Parent == null || t.Parent.Text != "FileEntries")
         return;
     if (MessageBox.Show("Are you sure to delete this File?", "DLCEditor2", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
     {
         int n = t.Index;
         DLC.DeleteEntry(n);
         DLC = new DLCPackage(DLC.MyFileName);
         treeView1.Nodes.Clear();
         treeView1.Nodes.Add(DLC.ToTree());
         MessageBox.Show("File Deleted.");
     }
 }
Exemplo n.º 8
0
        public DLCEditor2()
        {
            InitializeComponent();

            //FemShep's Mod Manager 3 automator for DLCEditor2.
            string[] arguments = Environment.GetCommandLineArgs();
            if (arguments.Length > 2)
            {
                try
                {
                    string cmdCommand = arguments[1];
                    if (cmdCommand.Equals("-dlcinject", StringComparison.Ordinal))
                    {
                        if (arguments.Length % 2 != 1 || arguments.Length < 5)
                        {
                            MessageBox.Show("Wrong number of arguments for the -dlcinject switch.:\nSyntax is: <exe> -dlcinject SFARPATH SEARCHTERM NEWFILEPATH [SEARCHTERM2 NEWFILEPATH2]...", "ME3 DLCEditor2 Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                        string dlcFileName = arguments[2];
                        int numfiles = (arguments.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] = arguments[argnum];
                            argnum++;
                            newFiles[i] = arguments[argnum];
                            argnum++;
                        }
                        automated = true;
                        if (File.Exists(dlcFileName))
                        {
                            openSFAR(dlcFileName);
                        }
                        else
                        {
                            System.Diagnostics.Debug.WriteLine("dlcFilename does not exist: " + dlcFileName);
                            MessageBox.Show("Failed to autoinject: DLC file does not exist: " + dlcFileName, "ME3Explorer DLCEditor2 Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            Application.Exit();
                            return;
                        }
                        //SFAR was opened.
                        //Now we search for the element to replace so it is selected...
                        for (int i = 0; i < numfiles; i++)
                        {
                            selectSearchedElement(filesToReplace[i]);
                            //the element is now selected, hopefully.
                            TreeNode t = treeView1.SelectedNode;
                            if (DLC == null || t == null || t.Parent == null || t.Parent.Text != "FileEntries")
                            {
                                MessageBox.Show("DLCEditor2 automator encountered an error: the file to replace does not exist or the tree has not been initialized.", "ME3 DLCEditor2 Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return;
                            }
                            replaceFile(newFiles[i], t.Index);
                        }
                    }
                    else if (cmdCommand.Equals("-dlcextract", StringComparison.Ordinal))
                    {
                        if (arguments.Length != 5)
                        {
                            //-2 for me3explorer & -dlcextract
                            MessageBox.Show("Wrong number of arguments for the -dlcinject switch.:\nSyntax is: <exe> -dlcextract SFARPATH SEARCHTERM EXTRACTIONPATH", "ME3 DLCEditor2 Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            Application.Exit();
                            return;
                        }
                        automated = true;
                        string dlcFileName = arguments[2];
                        string searchTerm = arguments[3];
                        string extractionPath = arguments[4];
                        if (File.Exists(dlcFileName))
                        {
                            openSFAR(dlcFileName);
                        }
                        else
                        {
                            System.Diagnostics.Debug.WriteLine("dlcFilename does not exist: " + dlcFileName);
                            MessageBox.Show("Failed to autoextract: DLC file does not exist: " + dlcFileName, "ME3Explorer DLCEditor2 Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            Application.Exit();
                            return;
                        }
                        //SFAR was opened.
                        //Now we search for the element to extract so it is selected...
                        selectSearchedElement(searchTerm);
                        //the element is now selected, hopefully.
                        TreeNode t = treeView1.SelectedNode;
                        if (DLC == null || t == null || t.Parent == null || t.Parent.Text != "FileEntries")
                        {
                            MessageBox.Show("DLCEditor2 extraction automator encountered an error:\nThe file to replace does not exist or the tree has not been initialized.", "DLCEditor2 Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            Application.Exit();
                            return;
                        }
                        extractFile(t.Index, extractionPath);
                    }
                    else if (cmdCommand.Equals("-dlcaddfiles", StringComparison.Ordinal))
                    {
                        if (arguments.Length % 2 != 1 || arguments.Length < 5)
                        {
                            MessageBox.Show("Wrong number of arguments for the -dlcaddfiles switch.:\nSyntax is: <exe> -dlcinject SFARPATH INTERNALPATH NEWFILEPATH [INTERNALPATH2 NEWFILEPATH2]...", "ME3 DLCEditor2 Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            Application.Exit();
                            return;
                        }

                        automated = true;
                        string dlcFileName = arguments[2];

                        int numfiles = (arguments.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] = arguments[argnum];
                            argnum++;
                            sourcePaths[i] = arguments[argnum];
                            argnum++;
                        }

                        if (File.Exists(dlcFileName))
                        {
                            openSFAR(dlcFileName);
                        }
                        else
                        {
                            System.Diagnostics.Debug.WriteLine("DLC does not exist: " + dlcFileName);
                            MessageBox.Show("Failed to autoadd: DLC file does not exist: " + dlcFileName, "ME3Explorer DLCEditor2 Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            Application.Exit();
                            return;
                        }
                        //SFAR was opened.
                        for (int i = 0; i < internalPaths.Length; i++)
                        {
                            System.Diagnostics.Debug.WriteLine("Adding file quick: " + sourcePaths[i] + " " + internalPaths[i]);
                            DLC.AddFileQuick(sourcePaths[i], internalPaths[i]);
                            DLC = new DLCPackage(DLC.MyFileName);
                            treeView1.Nodes.Clear();
                            treeView1.Nodes.Add(DLC.ToTree());
                        }
                    }
                    else if (cmdCommand.Equals("-dlcremovefiles", StringComparison.Ordinal))
                    {
                        if (arguments.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", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            Application.Exit();
                            return;
                        }
                        automated = true;
                        string dlcFileName = arguments[2];

                        int numfiles = (arguments.Length - 3);

                        string[] filesToRemove = new String[numfiles];

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

                        if (File.Exists(dlcFileName))
                        {
                            openSFAR(dlcFileName);
                        }
                        else
                        {
                            System.Diagnostics.Debug.WriteLine("DLC does not exist: " + dlcFileName);
                            MessageBox.Show("Failed to autoremove: DLC file does not exist: " + dlcFileName, "ME3Explorer DLCEditor2 Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            Application.Exit();
                            return;
                        }
                        //SFAR was opened.
                        for (int i = 0; i < filesToRemove.Length; i++)
                        {
                            selectSearchedElement(filesToRemove[i]);
                            //the element is now selected, hopefully.
                            TreeNode t = treeView1.SelectedNode;
                            if (DLC == null || t == null || t.Parent == null || t.Parent.Text != "FileEntries")
                            {
                                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", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                Application.Exit();
                                return;
                            }
                            DLC.DeleteEntry(t.Index);
                            DLC = new DLCPackage(DLC.MyFileName);
                            treeView1.Nodes.Clear();
                            treeView1.Nodes.Add(DLC.ToTree());
                        }
                    }
                    else if (cmdCommand.Equals("-dlcunpack", StringComparison.Ordinal) || cmdCommand.Equals("-dlcunpack-nodebug", StringComparison.Ordinal))
                    {
                        if (arguments.Length != 4)
                        {
                            MessageBox.Show("Wrong number of arguments for automated DLC unpacking:\nSyntax is: <exe> -dlcinject SFARPATH EXTRACTIONPATH", "ME3 DLCEditor2 Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }

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

                        automated = true;
                        if (File.Exists(sfarPath))
                        {
                            openSFAR(sfarPath);
                        }
                        else
                        {
                            System.Diagnostics.Debug.WriteLine("DLC does not exist: " + sfarPath);
                            MessageBox.Show("Failed to autounpack: DLC file does not exist: " + sfarPath, "ME3Explorer DLCEditor2 Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            Application.Exit();
                            return;
                        }
                        //SFAR was opened.
                        if (cmdCommand.Equals("-dlcunpack"))
                        {
                            DebugOutput.StartDebugger("DLC Editor 2"); //open debugging window since this operation takes a long time. The main debugger won't start as this will exit before that code can be reached
                        }
                        //Simulate Unpack operation click.
                        unpackSFARToolStripMenuItem.PerformClick();
                    }
                }
                catch (FileNotFoundException exc)
                {
                    MessageBox.Show("Failed to run DLCEditor2 Automator with the specified parameters.\n\nA file not found error occured while trying to automate a task.\n" + exc.Message, "DLC Editor2 Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Environment.Exit(1);
                    Application.Exit();
                }
                Environment.Exit(0);
                Application.Exit();
            }
            DebugOutput.StartDebugger("DLC Editor 2"); //open debugging window AFTER automation. Otherwise it pops up all weirdlike.
        }
Exemplo n.º 9
0
        private void addFileToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (DLC == null)
                return;
            OpenFileDialog d = new OpenFileDialog();
            d.Filter = "*.*|*.*";
            string p = Path.GetDirectoryName(DLC.Files[0].FileName) + "\\";
            if (d.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string path = p + Path.GetFileName(d.FileName);
                path = path.Replace('\\', '/');
                string result = Microsoft.VisualBasic.Interaction.InputBox("Please enter the path with name that the file will have inside the DLC", "ME3 Explorer", path, 0, 0);
                if (result == "")
                    return;
                path = result;
                System.Diagnostics.Debug.WriteLine("Adding file quick: " + d.FileName + " " + path);

                DLC.AddFileQuick(d.FileName, path);
                DLC = new DLCPackage(DLC.MyFileName);
                treeView1.Nodes.Clear();
                treeView1.Nodes.Add(DLC.ToTree());
                SearchNode(result, treeView1.Nodes[0]);
                MessageBox.Show("File added.");
            }
        }
Exemplo n.º 10
0
 public void ScanDLCfolder2()
 {
     DebugOutput.PrintLn("\n\nDLC Scan for packed files...\n", true);
     string dir = ME3Directory.DLCPath;
     string[] files = Directory.GetFiles(dir, "*.sfar", SearchOption.AllDirectories);
     if (files.Length == 0)
         return;
     pbar1.Maximum = files.Length - 1;
     int count = 0;
     foreach (string file in files)
         if (!file.ToLower().Contains("patch"))
         {
             DebugOutput.PrintLn("Scan file #" + count + " : " + file, count % 10 == 0);
             try
             {
                 DLCPackage dlc = new DLCPackage(file);
                 DebugOutput.PrintLn("found " + dlc.Files.Length + " files : " + file);
                 for (int j = 0; j < dlc.Files.Length; j++)
                 {
                     if (dlc.Files[j].FileName.ToLower().EndsWith(".pcc"))
                     {
                         string filename = dlc.Files[j].FileName;
                         DebugOutput.PrintLn(" " + j.ToString("d4") + " / " + dlc.Files.Length.ToString("d4") + " : opening " + Path.GetFileName(filename),true);
                         MemoryStream mem = dlc.DecompressEntry(j);
                         File.WriteAllBytes("temp.pcc", mem.ToArray());
                         PCCObject pcc = new PCCObject("temp.pcc");
                         for (int i = 0; i < pcc.Exports.Count; i++)
                             if (pcc.Exports[i].ClassName == "BioConversation")
                             {
                                 DebugOutput.PrintLn("Found dialog \"" + pcc.Exports[i].ObjectName + "\"", false);
                                 BioConversation Dialog = new BioConversation(pcc, i);
                                 foreach (BioConversation.EntryListStuct e in Dialog.EntryList)
                                 {
                                     string text = talkFile.findDataById(e.refText);
                                     if (text.Length != 7 && text != "No Data")
                                     {
                                         EntryStruct t = new EntryStruct();
                                         t.inDLC = true;
                                         t.text = text;
                                         t.ID = e.refText;
                                         t.indexpcc = i;
                                         t.pathafc = "";//Todo
                                         t.pathdlc = file;
                                         t.pathpcc = filename;
                                         t.convname = pcc.Exports[i].ObjectName;
                                         if (e.SpeakerIndex >= 0 && e.SpeakerIndex < Dialog.SpeakerList.Count)
                                             t.speaker = pcc.getNameEntry(Dialog.SpeakerList[e.SpeakerIndex]);
                                         else
                                             t.speaker = "unknown";
                                         if (t.speaker == null || t.speaker == "")
                                             t.speaker = "unknown";
                                         Entries.Add(t);
                                         DebugOutput.PrintLn("Requ.: (" + t.speaker + ") " + t.text, false);
                                     }
                                 }
                                 foreach (BioConversation.ReplyListStruct e in Dialog.ReplyList)
                                 {
                                     string text = talkFile.findDataById(e.refText);
                                     if (text.Length != 7 && text != "No Data")
                                     {
                                         EntryStruct t = new EntryStruct();
                                         t.inDLC = true;
                                         t.text = text;
                                         t.ID = e.refText;
                                         t.indexpcc = i;
                                         t.pathafc = "";//Todo
                                         t.pathdlc = file;
                                         t.pathpcc = filename;
                                         t.convname = pcc.Exports[i].ObjectName;
                                         Entries.Add(t);
                                         DebugOutput.PrintLn("Reply: " + t.text, false);
                                     }
                                 }
                             }
                     }
                 }
                 if (count % 10 == 0)
                 {
                     Application.DoEvents();
                     pbar1.Value = count;
                 }
                 count++;
             }
             catch (Exception ex)
             {
                 DebugOutput.PrintLn("=====ERROR=====\n" + ex.ToString() + "\n=====ERROR=====");
             }
         }
     if (File.Exists("temp.pcc"))
         File.Delete("temp.pcc");
 }
Exemplo n.º 11
0
        public static void unpackSFAR(DLCPackage dlc)
        {
            if (dlc == null || dlc.Files == null)
                return;
            string[] patt = { "pcc", "bik", "tfc", "afc", "cnd", "tlk", "bin", "dlc" };
            string file = dlc.FileName;                   //full path
            string t1 = Path.GetDirectoryName(file);        //cooked
            string t2 = Path.GetDirectoryName(t1);          //DLC_Name
            string t3 = Path.GetDirectoryName(t2);          //DLC
            string t4 = Path.GetDirectoryName(t3);          //BioGame
            string gamebase = Path.GetDirectoryName(t4);    //Mass Effect3
            DebugOutput.PrintLn("Extracting DLC with gamebase : " + gamebase);
            DebugOutput.PrintLn("DLC name : " + t2);
            if (dlc.Files.Length > 1)
            {
                List<int> Indexes = new List<int>();
                for (int i = 0; i < dlc.Files.Length; i++)
                {
                    string DLCpath = dlc.Files[i].FileName;
                    for (int j = 0; j < patt.Length; j++)
                        if (DLCpath.ToLower().EndsWith(patt[j].Trim().ToLower()) && patt[j].Trim().ToLower() != "")
                        {
                            string relPath = GetRelativePath(DLCpath);
                            string outpath = gamebase + relPath;
                            DebugOutput.PrintLn("Extracting file #" + i.ToString("d4") + ": " + outpath);
                            if (!Directory.Exists(Path.GetDirectoryName(outpath)))
                                Directory.CreateDirectory(Path.GetDirectoryName(outpath));

                            if (!File.Exists(outpath))
                                using (FileStream fs = new FileStream(outpath, FileMode.Create))
                                    dlc.DecompressEntryAsync(i, fs).Wait();
                            Indexes.Add(i);
                            Application.DoEvents();
                            break;
                        }
                }
                dlc.DeleteEntries(Indexes);
            }

            // AutoTOC
            AutoTOC.prepareToCreateTOC(t2 + "\\PCConsoleTOC.bin");
            DebugOutput.PrintLn("DLC Done.");
        }
Exemplo n.º 12
0
        private void replaceFile(string filename, int n)
        {
            DLC.ReplaceEntry(filename, n);

            DLC = new DLCPackage(DLC.FileName);
            treeView1.Nodes.Clear();
            treeView1.Nodes.Add(DLC.ToTree());
            SearchNode(filename, treeView1.Nodes[0]);
        }
        public static List<string> DLCExtractHelper(string file)
        {
            // KFreon: Ditching this stuff for Fobs ExtractAllDLC function in Texplorer2.cs
            // NOTE that the files are normally collected here, now done in Texplorer2.cs
            return new List<string>();




            List<string> ExtractedFiles = new List<string>();
            string[] dlcname = file.Split('\\');
            DebugOutput.PrintLn("Temp extracting DLC: " + dlcname[dlcname.Length - 3]);
            DLCPackage dlc = new DLCPackage(file);
            List<string> dlcpath = new List<string>(dlc.MyFileName.Split('\\'));
            dlcpath.RemoveRange(dlcpath.Count - 5, 5);
            string dlcExtractionPath = String.Join("\\", dlcpath.ToArray());

            List<int> Indicies = new List<int>();
            for (int i = 0; i < dlc.Files.Count(); i++)
            {
                DLCPackage.FileEntryStruct entry = dlc.Files[i];
                if (Path.GetExtension(entry.FileName).ToLower() == ".pcc" || Path.GetExtension(entry.FileName).ToLower() == ".tfc")
                {
                    DebugOutput.PrintLn("Extracting: " + dlc.Files[i].FileName);
                    try
                    {
                        Directory.CreateDirectory(Path.GetDirectoryName(dlcExtractionPath + dlc.Files[i].FileName));
                        using (FileStream fs = new FileStream(dlcExtractionPath + dlc.Files[i].FileName, FileMode.CreateNew))
                            dlc.DecompressEntry(i).WriteTo(fs);

                        Indicies.Add(i);
                    }
                    catch (Exception e)
                    {
                        DebugOutput.PrintLn("File " + dlcExtractionPath + entry.FileName + " already exists.  Extra: " + e.Message);
                        Console.WriteLine(e.Message);
                    }
                    ExtractedFiles.Add(dlcExtractionPath + entry.FileName);
                }
            }
            dlc.DeleteEntry(Indicies);
            return ExtractedFiles;
        }
Exemplo n.º 14
0
        private double GetRequiredSize()
        {
            var folders = Directory.EnumerateDirectories(ME3Directory.DLCPath);
            var extracted = folders.Where(folder => Directory.EnumerateFiles(folder, "*", SearchOption.AllDirectories).Any(file => file.EndsWith("pcconsoletoc.bin", StringComparison.OrdinalIgnoreCase)));
            var unextracted = folders.Except(extracted);

            double compressedSize = 0;
            double uncompressedSize = 0;
            double largestUncompressedSize = 0;
            double temp;
            foreach (var folder in unextracted)
            {
                if (folder.Contains("__metadata"))
                    continue;

                try
                {
                    FileInfo info = new FileInfo(Directory.EnumerateFiles(folder, "*", SearchOption.AllDirectories).Where(file => file.EndsWith(".sfar", StringComparison.OrdinalIgnoreCase)).First());
                    compressedSize += info.Length;

                    DLCPackage sfar = new DLCPackage(info.FullName);
                    sfarsToUnpack.Add(sfar);

                    temp = sfar.UncompressedSize;
                    uncompressedSize += temp;
                    if (temp > largestUncompressedSize)
                    {
                        largestUncompressedSize = temp;
                    }
                }
                catch (Exception)
                {
                    return -1;
                }
            }
            totalUncompressedSize = uncompressedSize;
            //each SFAR is stripped of all its files after unpacking, so the maximum space needed on the drive is 
            //the difference between the uncompressed size and compressed size of all SFARS, plus the compressed size
            //of the largest SFAR. I'm using the uncompressed size instead as a fudge factor.
            return (uncompressedSize - compressedSize) + largestUncompressedSize;
        }
Exemplo n.º 15
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;
        }