示例#1
0
        public List <string> BuildModListAndReturnMissing()
        {
            var modListPath     = Path.Combine(_transcompilerBase.ChosenProfilePath, _transcompilerBase.ModsListFileName);
            var missingArchives = new List <string>();

            var modPaths = File.ReadAllLines(modListPath)
                           .Where(x => x.StartsWith("+"))
                           .Select(x => x.Remove(0, 1))
                           .Select(x => Path.Combine(_transcompilerBase.ModsDirectoryPath, x));

            var intermediaryModObjects = new List <IntermediaryModObject>();

            foreach (var mod in modPaths)
            {
                var modIni = Path.Combine(mod, _transcompilerBase.ModMetaFileName);

                if (!File.Exists(modIni))
                {
                    _logger.Write($"meta.ini not found for modpath: {mod}\n");

                    continue;
                }

                var iniParser = new FileIniDataParser();
                var iniData   = iniParser.ReadFile(modIni);

                var intermediaryModObject = new IntermediaryModObject()
                {
                    ModPath = mod
                };

                var archivePath = GetSafeFilename(iniData["General"]["installationFile"]);

                // If the archive doesn't exist, initialize advanced archive search.
                if (!File.Exists(archivePath))
                {
                    archivePath = _archiveFilesystemSearch.FindArchive(archivePath);
                }

                if (archivePath == string.Empty)
                {
                    missingArchives.Add(Path.GetFileName(GetSafeFilename(iniData["General"]["installationFile"])));

                    intermediaryModObject.ArchivePath = Path.GetFileName(GetSafeFilename(iniData["General"]["installationFile"]));
                    intermediaryModObjects.Add(intermediaryModObject);
                }

                else
                {
                    intermediaryModObject.ArchivePath = archivePath;
                    intermediaryModObjects.Add(intermediaryModObject);
                }
            }

            _transcompilerBase.IntermediaryModObjects = intermediaryModObjects;

            return(missingArchives);
        }
示例#2
0
        private void CompileMod(IProgress <string> progressLog, IntermediaryModObject mod, IEnumerable <ArchiveContents> download_metadata)
        {
            var mod_name = Path.GetFileName(mod.ModPath);

            Update(progressLog, "[MOD] Compiling", mod_name);
            var matching_archive = download_metadata.Where(md => md.DiskName.Trim() == Path.GetFileName(mod.ArchivePath).Trim()).FirstOrDefault();

            if (matching_archive == null)
            {
                Update(progressLog, "[MOD] No match for", mod_name);
                return;
            }
            mod.Author          = matching_archive.Author;
            mod.IsNexusSource   = matching_archive.Repository == "Nexus";
            mod.TargetGame      = matching_archive.TargetGame;
            mod.Md5             = matching_archive.MD5;
            mod.ModId           = matching_archive.NexusModId;
            mod.FileId          = matching_archive.NexusFileId;
            mod.NexusFileName   = matching_archive.NexusFileName;
            mod.TrueArchiveName = matching_archive.DiskName;
            mod.Version         = matching_archive.Version;
            mod.Size            = matching_archive.FileSize;
            mod.Repository      = matching_archive.Repository;

            var indexed       = matching_archive.Contents.GroupBy(k => k.SHA256).ToDictionary(k => k.Key);
            var archive_pairs = new ConcurrentStack <ArchiveModFilePair>();

            Parallel.ForEach(Directory.EnumerateFiles(mod.ModPath, "*", SearchOption.AllDirectories),
                             file =>
            {
                if (Path.GetFileName(file) == "meta.ini")
                {
                    return;
                }
                var shortened_name = file.Substring(mod.ModPath.Length);
                var hash           = Extensions.SHA256(file);


                if (indexed.TryGetValue(hash, out var matches))
                {
                    //if (matches.Count() > 0)
                    //Update(progressLog, "[MOD] WARNING: multiple matches found for", shortened_name);
                    archive_pairs.Push(new ArchiveModFilePair("\\" + matches.First().FileName, shortened_name));
                }
                else
                {
                    //Update(progressLog, "[MOD] No Match found for", shortened_name);
                }
            });

            mod.ArchiveModFilePairs = archive_pairs.ToList();
        }