Exemplo n.º 1
0
        public List <IGameFile> CollectFiles(string searchkeyword, IGameArchiveManager root)
        {
            var ret = new Dictionary <string, IGameFile>();

            foreach (var f in root.FileList)
            {
                if (f.Name.ToUpper().Contains(searchkeyword.ToUpper()))
                {
                    if (!ret.ContainsKey(f.Name))
                    {
                        ret.TryAdd(f.Name, f);
                    }
                }
            }
            return(ret.Values.ToList());
        }
Exemplo n.º 2
0
        /// <summary>
        /// Unbundles a file with the given relativepath from either the Game or the Mod BundleManager
        /// and adds it to the depot, optionally copying to the project
        /// </summary>
        /// <param name="relativePath"></param>
        /// <param name="isDLC"></param>
        /// <param name="projectFolder"></param>
        /// <param name="bundleType"></param>
        /// <param name="alternateOutDirectory"></param>
        /// <param name="loadmods"></param>
        /// <param name="silent"></param>
        /// <returns></returns>
        public static string UnbundleFile(string relativePath, bool isDlc, EProjectFolders projectFolder, EArchiveType bundleType = EArchiveType.Bundle, string alternateOutDirectory = "", bool loadmods = false, bool silent = false)
        {
            string extension = Path.GetExtension(relativePath);
            string filename  = Path.GetFileName(relativePath);

            // Jato said not to add textures to an fbx
            // so I am keeping meshes violet :)
            //if (extension == ".xbm" && bundleType == EBundleType.Archive)
            //{
            //    //var uncookTask = Task.Run(() => UncookFileToPath(relativePath, isDLC, alternateOutDirectory));
            //    //Task.WaitAll(uncookTask);
            //    //return relativePath;
            //    UnbundleFile(relativePath, isDLC, projectFolder, EBundleType.TextureCache, alternateOutDirectory,
            //        loadmods, silent);
            //}
            IGameArchiveManager manager = MainController.Get().GetManagers(loadmods).FirstOrDefault(_ => _.TypeName == bundleType);

            if (manager != null && manager.Items.Any(x => x.Value.Any(y => y.Name == relativePath)))
            {
                var archives = manager.FileList
                               .Where(x => x.Name == relativePath)
                               .Select(y => new KeyValuePair <string, IGameFile>(y.Archive.ArchiveAbsolutePath, y))
                               .ToList();


                // Extract
                try
                {
                    // if more than one archive get the last
                    var archive = archives.Last().Value;

                    string newpath = "";
                    if (string.IsNullOrWhiteSpace(alternateOutDirectory))
                    {
                        switch (projectFolder)
                        {
                        case EProjectFolders.Cooked:
                            newpath = Path.Combine(isDlc
                                    ? ActiveMod.DlcCookedDirectory
                                    : ActiveMod.ModCookedDirectory, relativePath);
                            break;

                        case EProjectFolders.Uncooked:
                            newpath = Path.Combine(isDlc
                                    ? ActiveMod.DlcUncookedDirectory
                                    : ActiveMod.ModUncookedDirectory, relativePath);
                            break;

                        case EProjectFolders.Raw:
                            newpath = Path.Combine(isDlc
                                    ? ActiveMod.RawDlcDirectory
                                    : ActiveMod.RawModDirectory, relativePath);
                            break;

                        default:
                            break;
                        }
                    }
                    else
                    {
                        newpath = Path.Combine(alternateOutDirectory, relativePath);
                    }

                    if (string.IsNullOrWhiteSpace(newpath))
                    {
                        return("");
                    }

                    // for xbms check if a file with the current export extensions exists
                    if (!File.Exists(newpath) && (extension != ".xbm" || !File.Exists(Path.ChangeExtension(newpath,
                                                                                                           MainController.Get().Configuration.UncookExtension.ToString()))))
                    {
                        string extractedfile = archive.Extract(new BundleFileExtractArgs(newpath,
                                                                                         MainController.Get().Configuration.UncookExtension));
                        if (!silent)
                        {
                            Logger.LogString($"Succesfully unbundled {filename}.", Logtype.Success);
                        }
                    }
                    //else
                    //    if (!silent) Logger.LogString($"File already exists in mod project: {filename}.", Logtype.Success);
                    return(newpath);
                }
                catch (Exception ex)
                {
                    Logger.LogString(ex.ToString(), Logtype.Error);
                    return("");
                }
            }

            return("");
        }