Пример #1
0
        /// <summary>
        /// 添加规则
        /// </summary>
        /// <param name="path">路径</param>
        /// <param name="rule">规则</param>
        /// <param name="suffix">后缀</param>
        public void AddRule(string path, EBundleType rule, SearchOption searchOption)
        {
            if (string.IsNullOrEmpty(path))
            {
                Debug.LogError("添加的规则路径不能为空!!");
                return;
            }

            if (!Directory.Exists(path))
            {
                Debug.LogError($"不存在路径:{path}!!");
                return;
            }

            if (GetBuildItem(path) != null)
            {
                Debug.LogError($"该规则已经存在:{path}!!");
                return;
            }

            BuildItem ruleEntry = new BuildItem {
                assetPath = path, bundleType = rule
            };

            items.Add(ruleEntry);

            Save();
        }
        protected void RegisterBundle(EBundleType bundleType, string virtualPath, string[] cdnPaths)
        {
            Bundle registerBundle = null;

            switch (bundleType)
            {
            case EBundleType.Style: registerBundle = new StyleBundle(virtualPath).Include(cdnPaths); break;

            case EBundleType.Script: registerBundle = new ScriptBundle(virtualPath).Include(cdnPaths); break;
            }
            Bundles.Add(registerBundle);
        }
Пример #3
0
        private Tuple <WitcherListViewItem, IWitcherFile>[] SearchFiles(IWitcherFile[] files, string searchkeyword, string bundletypestr, string extension)
        {
            if (bundletypestr == "Any")
            {
                bundletypestr = "ANY";
            }
            EBundleType bundletype = (EBundleType)Enum.Parse(typeof(EBundleType), bundletypestr);

            if (regexCheckbox.Checked)
            {
                try
                {
                    if (currentfolderCheckBox.Checked)
                    {
                        return(files.Where(item => item.Bundle.ArchiveAbsolutePath.Contains(ActiveNode.Name) && new Regex(searchkeyword).IsMatch(item.Name)).Select(x => new Tuple <WitcherListViewItem, IWitcherFile>(new WitcherListViewItem(x), x)).ToArray());
                    }

                    return(files.Where(item => new Regex(searchkeyword).IsMatch(item.Name)).Select(x => new Tuple <WitcherListViewItem, IWitcherFile>(new WitcherListViewItem(x), x)).ToArray());
                }
                catch
                {
                    //TODO: Log
                }
            }
            if (currentfolderCheckBox.Checked)
            {
                return(caseCheckBox.Checked
                    ? files.Where(item => item.Bundle.ArchiveAbsolutePath.Contains(ActiveNode.Name) &&
                                  item.Name.ToUpper().Contains(searchkeyword.ToUpper()) &&
                                  (item.Name.ToUpper().EndsWith(extension.ToUpper()) || extension.ToUpper() == "ANY") &&
                                  (item.Bundle.TypeName == bundletype || bundletype == EBundleType.ANY))
                       .Distinct().Select(x => new Tuple <WitcherListViewItem, IWitcherFile>(new WitcherListViewItem(x), x)).ToArray()
                    : files.Where(item => item.Bundle.ArchiveAbsolutePath.Contains(ActiveNode.Name) &&
                                  item.Name.Contains(searchkeyword) &&
                                  (item.Name.EndsWith(extension) || extension.ToUpper() == "ANY") &&
                                  (item.Bundle.TypeName == bundletype || bundletype == EBundleType.ANY))
                       .Distinct().Select(x => new Tuple <WitcherListViewItem, IWitcherFile>(new WitcherListViewItem(x), x)).ToArray());
            }
            return(caseCheckBox.Checked
                ? files.Where(item => item.Name.ToUpper().Contains(searchkeyword.ToUpper()) &&
                              (item.Name.ToUpper().EndsWith(extension.ToUpper()) || extension.ToUpper() == "ANY") &&
                              (item.Bundle.TypeName == bundletype || bundletype == EBundleType.ANY))
                   .Select(x => new Tuple <WitcherListViewItem, IWitcherFile>(new WitcherListViewItem(x), x)).ToArray()
                : files.Where(item => item.Name.Contains(searchkeyword) &&
                              (item.Name.EndsWith(extension) || extension.ToUpper() == "ANY") &&
                              (item.Bundle.TypeName == bundletype || bundletype == EBundleType.ANY))
                   .Select(x => new Tuple <WitcherListViewItem, IWitcherFile>(new WitcherListViewItem(x), x)).ToArray());
        }
 public WitcherTreeNode(EBundleType bundleType)
 {
     Directories = new Dictionary <string, WitcherTreeNode>();
     Files       = new Dictionary <string, List <IWitcherFile> >();
     Name        = "";
 }
Пример #5
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, EBundleType bundleType = EBundleType.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.Bundle)
            //{
            //    //var uncookTask = Task.Run(() => UncookFileToPath(relativePath, isDLC, alternateOutDirectory));
            //    //Task.WaitAll(uncookTask);
            //    //return relativePath;
            //    UnbundleFile(relativePath, isDLC, projectFolder, EBundleType.TextureCache, alternateOutDirectory,
            //        loadmods, silent);
            //}
            IWitcherArchiveManager 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, IWitcherFile>(y.Bundle.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:
                        default:
                            break;
                        }
                    }
                    else
                    {
                        newpath = Path.Combine(alternateOutDirectory, relativePath);
                    }

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

                    if (!(extension == ".xbm" && bundleType == EBundleType.Bundle) || !File.Exists(newpath))
                    {
                        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("");
        }
Пример #6
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(EBundleType 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 EBundleType.TextureCache:
            {
                cbuilder = cachebuilder.textures;
                filename = "texture.cache";
            }
            break;

            case EBundleType.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);
                }
            }
        }