예제 #1
0
        public string convert(List <IFormFile> file)
        {
            if (null == file || file.Count != 1)
            {
                throw new ArgumentException("目前只支持解析单个wad文件");
            }
            WADFile          wad        = new WADFile(file[0].OpenReadStream());
            List <WadResult> wadResults = new List <WadResult>();

            wadResults = WADHashGenerator.GenerateWADStrings(wad, wadResults);
            wad.Dispose();
            GC.Collect();
            return(ApiUtil.success(wadResults));
        }
예제 #2
0
        private void WriteModWADFiles(ModFile mod)
        {
            Action <KeyValuePair <string, WADFile> > writeWadFileDelegate = new Action <KeyValuePair <string, WADFile> >(WriteWadFile);

            if (Config.Get <bool>("ParallelWadInstallation"))
            {
                ParallelOptions parallelOptions = new ParallelOptions()
                {
                    MaxDegreeOfParallelism = Environment.ProcessorCount
                };

                Parallel.ForEach(mod.WadFiles, parallelOptions, (modWadFile) =>
                {
                    writeWadFileDelegate.Invoke(modWadFile);
                });
            }
            else
            {
                foreach (KeyValuePair <string, WADFile> modWadFile in mod.WadFiles)
                {
                    writeWadFileDelegate.Invoke(modWadFile);
                }
            }

            void WriteWadFile(KeyValuePair <string, WADFile> modWadFile)
            {
                string wadPath           = this.Index.FindWADPath(modWadFile.Key);
                string overlayModWadPath = string.Format(@"{0}\{1}", OVERLAY_FOLDER, wadPath);
                string gameModWadPath    = string.Format(@"{0}\{1}", this.LeagueFolder, wadPath);

                //Check if the WAD already exists, if it does, we need to merge the 2 WADs
                //if it doesnt, then we need to copy it from the game directory
                if (!File.Exists(overlayModWadPath))
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(overlayModWadPath));

                    WADFile baseWad           = new WADFile(gameModWadPath);
                    bool    returnedModdedWad = false;
                    using (WADFile mergedWad = WADMerger.Merge(baseWad, modWadFile.Value, out returnedModdedWad))
                    {
                        mergedWad.Write(overlayModWadPath);
                    }

                    if (returnedModdedWad)
                    {
                        baseWad.Dispose();
                    }
                    else
                    {
                        modWadFile.Value.Dispose();
                    }
                }
                else
                {
                    File.Move(overlayModWadPath, overlayModWadPath + ".temp");

                    using (WADFile mergedWad = WADMerger.Merge(new WADFile(overlayModWadPath + ".temp"), modWadFile.Value))
                    {
                        mergedWad.Write(overlayModWadPath);
                    }

                    //Delete temp wad file
                    File.Delete(overlayModWadPath + ".temp");
                    modWadFile.Value.Dispose();
                }
            }
        }