Beispiel #1
0
        private void GenerateFileList_BackgroundThread(object sender, DoWorkEventArgs e)
        {
            TOCTasks.ClearEx();
            string[] extensions = { ".sfm", ".upk", ".bik", ".u", ".isb" };

            //remove trailing slash
            string      dlcCookedDir = Path.GetFullPath(e.Argument as string); //standardize
            ListBoxTask task         = new ListBoxTask($"Generating file index for {dlcCookedDir}");

            TOCTasks.Add(task);
            int rootLength = dlcCookedDir.Length + 1; //trailing slash path separator. This is used to strip off the absolute part of the path and leave only relative

            //Where first as not all files need to be selected and then filtered, they should be filtered and then selected
            var files = (Directory.EnumerateFiles(dlcCookedDir, "*.*", SearchOption.AllDirectories)
                         .Where(s => extensions.Any(ext => ext == Path.GetExtension(s).ToLower()))
                         .Select(p => p.Remove(0, rootLength))).ToList();

            string fileName = Path.Combine(dlcCookedDir, "FileIndex.txt");

            File.WriteAllLines(fileName, files);
            task.Complete($"Generated file index for {dlcCookedDir}");
            TOCTasks.Add(new ListBoxTask
            {
                Header     = "Done",
                Icon       = FontAwesomeIcon.Check,
                Foreground = Brushes.Green,
                Spinning   = false
            });
        }
Beispiel #2
0
        /// <summary>
        /// Prepares to create the indexed TOC file by gathering data and then passing it to the TOC creation function
        /// </summary>
        /// <param name="consoletocFile"></param>
        public void prepareToCreateTOC(string consoletocFile)
        {
            if (!consoletocFile.EndsWith("\\"))
            {
                consoletocFile += "\\";
            }
            List <string> files = GetFiles(consoletocFile);

            if (files.Count != 0)
            {
                //These variable names.......
                ListBoxTask task = new ListBoxTask($"Creating TOC in {consoletocFile}");
                TOCTasks.Add(task);
                string t = files[0];
                int    n = t.IndexOf("DLC_");
                if (n > 0)
                {
                    for (int i = 0; i < files.Count; i++)
                    {
                        files[i] = files[i].Substring(n);
                    }
                    string t2 = files[0];
                    n = t2.IndexOf("\\");
                    for (int i = 0; i < files.Count; i++)
                    {
                        files[i] = files[i].Substring(n + 1);
                    }
                }
                else
                {
                    n = t.IndexOf("BIOGame");
                    if (n > 0)
                    {
                        for (int i = 0; i < files.Count; i++)
                        {
                            files[i] = files[i].Substring(n);
                        }
                    }
                }
                string pathbase;
                string t3 = files[0];
                int    n2 = t3.IndexOf("BIOGame");
                if (n2 >= 0)
                {
                    pathbase = Path.GetDirectoryName(Path.GetDirectoryName(consoletocFile)) + "\\";
                }
                else
                {
                    pathbase = consoletocFile;
                }
                CreateTOC(pathbase, consoletocFile + "PCConsoleTOC.bin", files.ToArray());
                task.Complete($"Created TOC for {consoletocFile}");
            }
        }
Beispiel #3
0
 private void GenerateAllTOCs_BackgroundThread(object sender, DoWorkEventArgs e)
 {
     TOCTasks.ClearEx();
     GenerateAllTOCs();
     TOCTasks.Add(new ListBoxTask
     {
         Header     = "AutoTOC complete",
         Icon       = EFontAwesomeIcon.Solid_Check,
         Foreground = Brushes.Green,
         Spinning   = false
     });
 }
Beispiel #4
0
 private void GenerateSingleTOC_BackgroundThread(object sender, DoWorkEventArgs e)
 {
     TOCTasks.ClearEx();
     prepareToCreateTOC(e.Argument as string);
     TOCTasks.Add(new ListBoxTask
     {
         Header     = "TOC created",
         Icon       = EFontAwesomeIcon.Solid_Check,
         Foreground = Brushes.Green,
         Spinning   = false
     });
 }
Beispiel #5
0
        /// <summary>
        /// Generates new items to the FileIndex.txt (ME1) removing duplicate references contained in masterList
        /// </summary>
        /// <param name="CookedPath"></param>
        /// <param name="masterList"></param>
        private void GenerateFileList(string CookedPath, List <string> masterList)
        {
            string[] extensions = { ".sfm", ".upk", ".bik", ".u", ".isb" };

            //remove trailing slash
            string      dlcCookedDir = Path.GetFullPath(CookedPath); //standardize
            ListBoxTask task         = new ListBoxTask($"Generating file index for {dlcCookedDir}");

            TOCTasks.Add(task);
            int rootLength = dlcCookedDir.Length + 1; //trailing slash path separator. This is used to strip off the absolute part of the path and leave only relative

            //Where first as not all files need to be selected and then filtered, they should be filtered and then selected
            List <string> files = (Directory.EnumerateFiles(dlcCookedDir, "*.*", SearchOption.AllDirectories)
                                   .Where(s => extensions.Any(ext => ext == Path.GetExtension(s).ToLower()))
                                   .Select(p => p.Remove(0, rootLength))).ToList();

            var addressedFiles = new List <string>();  //sub list of files that actually are addressed by the game (not duplicated at higher levels)

            foreach (string file in files)
            {
                Debug.WriteLine(file);
                if (!masterList.Contains(file))
                {
                    //Only add items that are not already done.
                    masterList.Add(file);
                    addressedFiles.Add(file);
                }
            }

            string fileName = Path.Combine(dlcCookedDir, "FileIndex.txt");

            File.WriteAllLines(fileName, addressedFiles);
            task.Complete($"Generated file index for {dlcCookedDir}");
            TOCTasks.Add(new ListBoxTask
            {
                Header     = "Done",
                Icon       = EFontAwesomeIcon.Solid_Check,
                Foreground = Brushes.Green,
                Spinning   = false
            });
        }
Beispiel #6
0
        private void GenerateME1FileList()
        {
            // AUTO DLC MOUNTING

            // 1. GET LIST OF DLC DIRECTORIES, SET MAIN VARIABLES
            //IList() me1DLCs; // set list of directorys
            string DLCDirectory = ME1Directory.DLCPath;

            string[] dlcList = Directory.GetDirectories(DLCDirectory, "*.*", SearchOption.TopDirectoryOnly);

            var dlcTable = new Dictionary <int, string>();


            // 2. READ AUTOLOAD.INI FROM EACH DLC.  BUILD TABLE OF DIRECTORIES & MOUNTS
            foreach (string dlcDir in dlcList)
            {
                if (dlcDir.EndsWith("DLC_UNC", StringComparison.InvariantCultureIgnoreCase))
                {
                    dlcTable.Add(1, "DLC_UNC");
                }
                else if (dlcDir.EndsWith("DLC_VEGAS", StringComparison.InvariantCultureIgnoreCase))
                {
                    dlcTable.Add(2, "DLC_VEGAS");
                }
                else
                {
                    string autoLoadPath = Path.Combine(dlcDir, "autoload.ini");  //CHECK IF FILE EXISTS?
                    if (File.Exists(autoLoadPath))
                    {
                        IniFile dlcAutoload = new IniFile(autoLoadPath);
                        string  name        = Path.GetFileName(dlcDir);
                        int     mount       = Convert.ToInt32(dlcAutoload.ReadValue("ME1DLCMOUNT", "ModMount"));
                        dlcTable.Add(mount, name);
                    }
                }
            }
            // ADD BASEGAME = 0
            dlcTable.Add(0, "BioGame");


            // 3. REMOVE ALL SEEKFREEPCPATHs/DLCMOVIEPATHS FROM $DOCUMENTS$\BIOWARE\MASS EFFECT\CONFIG\BIOENGINE.ini
            string userDocs      = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            var    bioEnginePath = Path.Combine(userDocs, "BioWare", "Mass Effect", "Config", "BIOEngine.ini");

            try
            {
                File.SetAttributes(bioEnginePath, File.GetAttributes(bioEnginePath) & ~FileAttributes.ReadOnly);
            }
            catch (IOException e)
            {
                MessageBox.Show($"BioEngine not found. Run config or game to set it up. {ExceptionHandlerDialogWPF.FlattenException(e)}");
                return;
            }


            var BioEngine = new IniFile(bioEnginePath);

            //Clean out seekfreepaths and moviepaths
            while (BioEngine.ReadValue("Core.System", "SeekFreePCPaths") != "")
            {
                BioEngine.RemoveKey("Core.System", "SeekFreePCPaths");
            }

            while (BioEngine.ReadValue("Core.System", "DLC_MoviePaths") != "")
            {
                BioEngine.RemoveKey("Core.System", "DLC_MoviePaths");
            }

            // 4. ADD SEEKFREE PATHS IN REVERSE ORDER (HIGHEST= BIOGAME, ETC).
            //SORT INTO REVERSE ORDER 0 => HIGHEST FOR BIOENGINE
            foreach (KeyValuePair <int, string> item in dlcTable.OrderBy(k => k.Key))
            {
                if (item.Key == 0)
                {
                    //The @"string\thing" allows you to use \ instead of \\. Very good if you are using paths. Though most times you should use Path.Combine() as it will prevent you missing one by accident
                    BioEngine.WriteNewValue("Core.System", "SeekFreePCPaths", @"..\BioGame\CookedPC");
                }
                else
                {
                    BioEngine.WriteNewValue("Core.System", "SeekFreePCPaths", $@"..\DLC\{item.Value}\CookedPC");
                    if (Directory.Exists(Path.Combine(ME1Directory.DLCPath, item.Value, "Movies")))
                    {
                        BioEngine.WriteNewValue("Core.System", "DLC_MoviePaths", $@"..\DLC\{item.Value}\Movies"); //Add MoviePath if present
                    }
                }
            }



            // 5. BUILD FILEINDEX.TXT FILE FOR EACH DLC AND BASEGAME
            // BACKUP BASEGAME Fileindex.txt => Fileindex.bak if not done already.
            var fileIndexBackupFile = Path.Combine(ME1Directory.cookedPath, "FileIndex.bak");

            if (!File.Exists(fileIndexBackupFile))
            {
                //This might fail as the game will be installed into a write-protected directory for most users by default
                try
                {
                    File.Copy(Path.Combine(ME1Directory.cookedPath, "FileIndex.txt"), fileIndexBackupFile);
                }
                catch (IOException e)
                {
                    MessageBox.Show($"Error backup up FileIndex.txt:\n{ExceptionHandlerDialogWPF.FlattenException((e))}");
                    return;
                }
            }

            // CALL FUNCTION TO BUILD EACH FILEINDEX.  START WITH HIGHEST DLC MOUNT -> ADD TO MASTER FILE LIST
            // DO NOT ADD DUPLICATES
            TOCTasks.ClearEx();

            var masterList = new List <string>();

            foreach (KeyValuePair <int, string> fileListStem in dlcTable.OrderByDescending(k => k.Key))
            {
                if (fileListStem.Value == "BioGame")
                {
                    //Using a list is pass by reference so our copy and the function's copy will be the same.
                    //Note this does not work with primitive types like int (unless using the ref keyword), or immutable types like string.
                    //(Immutable in c# = they can't be changed. modifying a string will return a new string instead)
                    GenerateFileList(Path.Combine(ME1Directory.BioGamePath, "CookedPC"), masterList);
                }
                else
                {
                    GenerateFileList(Path.Combine(ME1Directory.DLCPath, fileListStem.Value, "CookedPC"), masterList);
                }
            }



            //7. FINAL MESSAGE ON TOC TASKS
            TOCTasks.Add(new ListBoxTask
            {
                Header     = "Done",
                Icon       = EFontAwesomeIcon.Solid_Check,
                Foreground = Brushes.Green,
                Spinning   = false
            });
        }