Beispiel #1
0
        private static void BuildTransform()
        {
            var destTransformFS = @"X:\m3modlibrary\ME3\Shorter Dreams";
            var inputExe        = @"B:\ExeMods\SD_v0_1_3.exe";

            // Build file info for transformFS
            var tfs = Directory.GetFiles(destTransformFS, "*.*", SearchOption.AllDirectories);
            Dictionary <string, string> md5Map = new Dictionary <string, string>();

            foreach (var tf in tfs)
            {
                md5Map[Utilities.CalculateMD5(tf)] = tf.Substring(destTransformFS.Length + 1);
            }


            SevenZipExtractor archive = new SevenZipExtractor(inputExe, InArchiveFormat.Nsis);

            foreach (var entry in archive.ArchiveFileData)
            {
                if (IsTrashFile(entry.FileName))
                {
                    Console.WriteLine($"<noextract index=\"{entry.Index}\"/> <!-- {entry.FileName} --> ");
                    continue;
                }
                var outStream = new MemoryStream();
                archive.ExtractFile(entry.Index, outStream);
                var amd5    = Utilities.CalculateMD5(outStream);
                var outName = $"<alternateredirect index=\"{entry.Index}\" outfile=\"{md5Map[amd5]}\"/>";
                Console.WriteLine(outName);
            }
        }
Beispiel #2
0
        //    foreach (var entry in archive.ArchiveFileData)
        //    {
        //        if (entry.FileName.Contains("BIOGame\\DLC"))
        //        {
        //            var outName = entry.FileName.Substring(entry.FileName.IndexOf("BIOGame\\DLC\\") + "BIOGame\\DLC\\".Length);
        //            outName = $"<alternateredirect index=\"{entry.Index}\" outfile=\"{outName}\"/>";
        //            Console.WriteLine(outName);
        //        }
        //    }
        //}

        private static void ParseSourceDir()
        {
            Console.WriteLine($@"Parsing directory {SourceDir}");
            var exe     = Directory.GetFiles(SourceDir, "*.exe").FirstOrDefault();
            var archive = new SevenZipExtractor(exe, InArchiveFormat.Nsis);

            PrintArchiveIndices(archive);

            var catalog = new List <M3FileInfo>();

            foreach (var e in archive.ArchiveFileData)
            {
                if (!IsTrashFile(e.FileName))
                {
                    Console.WriteLine($@"Cataloging archive file {e.FileName}");
                    var outStream = new MemoryStream();
                    archive.ExtractFile(e.Index, outStream);
                    catalog.Add(new M3FileInfo()
                    {
                        md5        = Utilities.CalculateMD5(outStream),
                        size       = outStream.Length,
                        dataStream = outStream,
                        path       = e.FileName,
                        entry      = e
                    });
                }
            }

            var optionDirectories = Directory.GetDirectories(SourceDir);

            // Get file lists of each directory
            var optionFileMapping = new Dictionary <string, List <M3FileInfo> >();

            foreach (var d in optionDirectories)
            {
                List <string>     files = Directory.GetFiles(d, "*.*", SearchOption.AllDirectories).Select(x => x.Substring(SourceDir.Length + 2 + Path.GetFileName(d).Length)).ToList();
                List <M3FileInfo> infos = new List <M3FileInfo>();

                foreach (var f in files)
                {
                    if (IsTrashFile(f))
                    {
                        continue;
                    }
                    Console.WriteLine($"Indexing {d}\\{f}");
                    var md5  = Utilities.CalculateMD5($"{d}\\{f}");
                    var info = catalog.FirstOrDefault(x => x.md5 == md5);
                    if (info == null)
                    {
                        Debugger.Break();
                    }
                    infos.Add(info);
                }

                optionFileMapping[Path.GetFileName(d)] = infos;
            }

            var allFiles = optionFileMapping[Path.GetFileName(optionDirectories[0])];

            for (int i = 1; i < optionDirectories.Length; i++)
            {
                allFiles = allFiles.Intersect(optionFileMapping[Path.GetFileName(optionDirectories[i])]).ToList();
            }

            Console.WriteLine(@"The following files are present in every directory:");
            //var mainOutDir = @"X:\m3modlibrary\ME3\Citadel Epiloge Mod - Lite";
            foreach (var f in allFiles)
            {
                Console.WriteLine($"{f.entry.Index}\t{f.path}");
                //var p = f.path.Substring(@"BIOGame\DLC\".Length);
                //var outP = Path.Combine(mainOutDir, p);
                //Directory.CreateDirectory(Directory.GetParent(outP).FullName);
                //f.dataStream.WriteToFile(outP);
            }

            Console.WriteLine("The following files are unique:");
            var nonUnique   = allFiles.Select(x => x.entry.Index).ToList();
            var items       = catalog.Select(x => x.entry.Index).Except(nonUnique).Select(x => catalog.FirstOrDefault(y => y.entry.Index == x));
            var longestName = items.MaxBy(x => x.path.Length).path.Length + 3;

            foreach (var f in items)
            {
                var folder = GetDiskPathForEntry(f, optionFileMapping);
                Console.WriteLine($"{f.entry.Index}\t{f.entry.FileName.PadRight(longestName)} | {folder}");
                // CEML SPECIFIC
                //if (!string.IsNullOrWhiteSpace(folder) && !folder.Contains(' '))
                //{
                //    var outP = Path.Combine(@"X:\m3modlibrary\ME3\Citadel Epiloge Mod - Lite\Alternates\Music", folder, Path.GetFileName(f.path));
                //    f.dataStream.WriteToFile(outP);
                //}
                //else if (f.entry.Index == 53 || f.entry.Index == 54)
                //{
                //    var outP = Path.Combine(@"X:\m3modlibrary\ME3\Citadel Epiloge Mod - Lite\Alternates\MiriJack", Path.GetFileName(f.path));
                //    f.dataStream.WriteToFile(outP);
                //}
                //else if (f.entry.Index >= 55)
                //{
                //    var outP = Path.Combine(@"X:\m3modlibrary\ME3\Citadel Epiloge Mod - Lite\Alternates\NoUltimateParty", Path.GetFileName(f.path));
                //    f.dataStream.WriteToFile(outP);
                //}
            }
        }