Example #1
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("");
        }
Example #2
0
 public GameFileTreeNode(EArchiveType bundleType)
 {
     Directories = new Dictionary <string, GameFileTreeNode>();
     Files       = new Dictionary <string, List <IGameFile> >();
     Name        = "";
 }
Example #3
0
        /// <summary>
        /// Call wcc buildcache over the uncooked directories
        /// IN: \\CollisionCache, cooked\\Mods\\mod\\cook.db, OUT: packed\\Mods\\mod
        /// </summary>
        /// <param name="cachetype"></param>
        /// <param name="packmod"></param>
        /// <param name="packdlc"></param>
        /// <returns></returns>
        public static async Task <int> GenerateCache(EArchiveType cachetype, bool packmod, bool packdlc)
        {
            //const string db_dlcfiles = "db_dlcfiles";
            //const string db_dlctextures = "db_dlctextures";
            //const string db_modfiles = "db_modfiles";
            //const string db_modtextures = "db_modtextures";

            string dlc_files_db = Path.Combine(Path.GetFullPath(MainController.Get().ActiveMod.ProjectDirectory), "db_dlcfiles");
            string mod_files_db = Path.Combine(Path.GetFullPath(MainController.Get().ActiveMod.ProjectDirectory), "db_modfiles");
            string moddbfile    = Path.Combine(mod_files_db, "cook.db");
            string dlcdbfile    = Path.Combine(dlc_files_db, "cook.db");
            string modbasedir   = ActiveMod.ModUncookedDirectory;
            string dlcbasedir   = MainController.Get().Configuration.DepotPath;


            cachebuilder cbuilder = cachebuilder.textures;
            string       filename = "";

            switch (cachetype)
            {
            case EArchiveType.TextureCache:
            {
                cbuilder = cachebuilder.textures;
                filename = "texture.cache";
            }
            break;

            case EArchiveType.CollisionCache:
            {
                cbuilder = cachebuilder.physics;
                filename = "collision.cache";
            }
            break;

            default:
                throw new NotImplementedException();
            }

            int finished = 1;

            if (packmod)
            {
                finished *= await Task.Run(() => GenerateCacheInternal(ActiveMod.PackedModDirectory, moddbfile, modbasedir));
            }
            if (packdlc)
            {
                finished *= await Task.Run(() => GenerateCacheInternal(ActiveMod.PackedDlcDirectory, dlcdbfile, dlcbasedir, true));
            }

            return(finished == 0 ? 0 : 1);

            async Task <int> GenerateCacheInternal(string packDir, string dbfile, string basedir, bool dlc = false)
            {
                string type = dlc ? "Dlc" : "Mod";

                try
                {
                    // check if a cook.db exists for that
                    if (File.Exists(dbfile))
                    {
                        Logger.LogString($"======== Generating {type} {cachetype} cache ======== \n", Logtype.Important);
                        //MainController.Get().ProjectStatus = $"Generating {type} {cachetype} cache";

                        var buildcache = new Wcc_lite.buildcache()
                        {
                            Platform = platform.pc,
                            builder  = cbuilder,
                            basedir  = basedir,
                            DataBase = dbfile,
                            Out      = $"{packDir}\\{filename}"
                        };
                        return(await Task.Run(() => MainController.Get().WccHelper.RunCommand(buildcache)));
                    }
                    else
                    {
                        return(-1);
                    }
                }
                catch (DirectoryNotFoundException)
                {
                    Logger.LogString($"{type} {cachetype} folder not found. {type} {cachetype} won't be generated. \n", Logtype.Important);
                    return(-1);
                }
                catch (Exception ex)
                {
                    Logger.LogString(ex.ToString() + "\n", Logtype.Error);
                    return(0);
                }
            }
        }