Ejemplo n.º 1
0
        private AssetEntry getEntryForFileName(string filename, RequestCategory requestCategory = RequestCategory.NONE)
        {
            //logger.Debug("get entry for filename:" + filename + " with request category " + requestCategory);
            List <ManifestEntry> entries = Manifest.getEntriesForFilenameHash(Util.hashFileName(filename));

            if (entries.Count() == 0)
            {
                // lets see if the filename is actually a hash (this shouldn't happen, but whatevers)
                entries = Manifest.getEntriesForFilenameHash(filename);
                if (entries.Count() == 0)
                {
                    throw new Exception("Filename hash not found in manifest: '" + filename + "'");
                }
                logger.Warn("Using filename[" + filename + "] as hash");
            }

            // strip out duplicate patch paks
            entries.RemoveAll(e => {
                return(Manifest.getPAKName(e.pakIndex).Contains("patch") && entries.Any(x => x != e && x.idStr.Equals(e.idStr)));
            });

            // logger.Debug("found " + entries.Count() + " entries in manifest that match");
            string id = "";

            if (entries.Count() == 1)
            {
                // if there was only one result, then use it
                id = entries.First().idStr;
            }
            else
            {
                ManifestEntry finalEntry = null;

                // work out which one we want based on the category
                string requestStr = requestCategory.ToString().ToLower();
                //logger.Debug("multiple ids found for " + filename + ", using request category " + requestStr);

                foreach (ManifestEntry entry in entries)
                {
                    //logger.Debug("[" + filename + "]: considering entry:" + entry + " :" + manifest.getPAKName(entry.pakIndex));
                    ManifestPAKFileEntry pak = Manifest.getPAK(entry.pakIndex);
                    string pakName           = pak.name;
                    if (pakName.Contains(requestStr))
                    {
                        finalEntry = entry;
                        break;
                    }
                }


                if (finalEntry == null)
                {
                    // if we were still unable to break the tie
                    logger.Error("tiebreak for " + filename + " no id match");

                    // one final check on the language, if an english one exists, use that over any other non-english one
                    IEnumerable <ManifestEntry> engUni = entries.Where(e => e.lang == 0 || e.lang == 1);
                    // if the number of english entries is different to the number of entries, then we should choose an english one and assume it is that one
                    if (engUni.Count() > 0 && engUni.Count() != entries.Count())
                    {
                        logger.Debug("tie broken with english language choice: " + finalEntry + " :" + Manifest.getPAKName(finalEntry.pakIndex));
                        finalEntry = engUni.First();
                    }
                    else
                    {
                        // fail?
                        String str = "";
                        foreach (ManifestEntry entry in entries)
                        {
                            str += "\t" + entry + " :" + Manifest.getPAKName(entry.pakIndex) + "\n";
                        }
                        string errStr = ("Multiple ids match the filename [" + filename + "] but no request category was given, unable to determine which to return.\n" + str);
                        throw new Exception(errStr);
                    }
                }
                id = finalEntry.idStr;
                //logger.Debug("settled on entry:" + finalEntry + " :" + manifest.getPAKName(finalEntry.pakIndex));
            }
            //logger.Debug("find asset file for id:" + id);
            AssetFile assetFile = FindAssetFileForId(id);

            //logger.Debug("result:" + assetFile);
            if (assetFile == null)
            {
                throw new Exception(
                          "Filename found in manifest but unable to locate ID[" + id + "] in assets: '" + filename
                          + "'");
            }
            //logger.Debug("found with id:" + id);
            return(assetFile.getEntry(id));
        }