Exemple #1
0
            /// <summary>
            /// Loads a loose virtual file
            /// </summary>
            /// <param name="virtualPath"></param>
            public void AddLoadFileTask(string virtualPath, AccessLevel al)
            {
                string bndout;
                var    path = Locator.VirtualToRealPath(virtualPath, out bndout);

                IResourceHandle handle;

                if (path == null || virtualPath == "null")
                {
                    return;
                }
                if (virtualPath.EndsWith(".hkx"))
                {
                    handle = GetResource <HavokCollisionResource>(virtualPath);
                }
                else if (path.ToUpper().EndsWith(".TPF") || path.ToUpper().EndsWith(".TPF.DCX"))
                {
                    string virt = virtualPath;
                    if (virt.StartsWith($@"map/tex"))
                    {
                        var regex = new Regex(@"\d{4}$");
                        if (regex.IsMatch(virt))
                        {
                            virt = virt.Substring(0, virt.Length - 5);
                        }
                        else if (virt.EndsWith("tex"))
                        {
                            virt = virt.Substring(0, virt.Length - 4);
                        }
                    }
                    var ttask = new LoadTPFResourcesTask(virt, TPF.Read(path), al, Locator.Type);
                    Tasks.Add(ttask);
                    return;
                }
                else
                {
                    handle = GetResource <FlverResource>(virtualPath);
                }
                var task = new LoadResourceFromFileTask(handle, path, al, Locator.Type);

                Tasks.Add(task);
            }
Exemple #2
0
 /// <summary>
 /// Attempts to load unloaded resources (with active references) via UDSFM textures
 /// </summary>
 public void AddLoadUDSFMTexturesTask()
 {
     foreach (var r in ResourceDatabase)
     {
         if (r.Value is TextureResourceHande t && t.AccessLevel == AccessLevel.AccessUnloaded &&
             t.GetReferenceCounts() > 0)
         {
             var    texpath = r.Key;
             string path    = null;
             if (texpath.StartsWith("map/tex"))
             {
                 path = $@"{Locator.GameRootDirectory}\map\tx\{Path.GetFileName(texpath)}.tpf";
             }
             if (path != null && File.Exists(path))
             {
                 var task = new LoadTPFResourcesTask(Path.GetDirectoryName(r.Key).Replace('\\', '/'), TPF.Read(path), AccessLevel.AccessGPUOptimizedOnly, Locator.Type);
                 Tasks.Add(task);
             }
         }
     }
 }
Exemple #3
0
            public void Run()
            {
                ProcessBinder();
                if (!PopulateResourcesOnly)
                {
                    foreach (var p in PendingResources)
                    {
                        var f    = Binder.ReadFile(p.Item3);
                        var task = new LoadResourceFromBytesTask(p.Item1, f, AccessLevel, ResourceManager.Locator.Type);
                        task.Run();
                    }

                    foreach (var t in PendingTPFs)
                    {
                        var f    = TPF.Read(Binder.ReadFile(t.Item2));
                        var task = new LoadTPFResourcesTask(t.Item1, f, AccessLevel, ResourceManager.Locator.Type);
                        task.Run();
                    }
                }
                PendingResources.Clear();
                Binder = null;
            }
Exemple #4
0
            public Task RunAsync(IProgress <int> progress)
            {
                return(BinderTaskFactory.StartNew(() =>
                {
                    ProcessBinder();
                    if (!PopulateResourcesOnly)
                    {
                        bool doasync = (PendingResources.Count() + PendingTPFs.Count()) > 1;
                        int i = 0;
                        foreach (var p in PendingResources)
                        {
                            var f = Binder.ReadFile(p.Item3);
                            var task = new LoadResourceFromBytesTask(p.Item1, f, AccessLevel, ResourceManager.Locator.Type);
                            var size = task.GetEstimateTaskSize();
                            TotalSize += size;
                            if (doasync)
                            {
                                var progress1 = new Progress <int>();
                                TaskSizes.Add(size);
                                lock (ProgressLock)
                                {
                                    TaskProgress.Add(0);
                                }
                                int bindi = i;
                                progress1.ProgressChanged += (x, e) =>
                                {
                                    lock (ProgressLock)
                                    {
                                        TaskProgress[bindi] = e;
                                    }
                                    UpdateProgress(progress);
                                };
                                LoadingTasks.Add(task.RunAsync(progress1));
                                i++;
                            }
                            else
                            {
                                task.Run();
                                i++;
                                progress.Report(i);
                            }
                        }

                        foreach (var t in PendingTPFs)
                        {
                            var f = TPF.Read(Binder.ReadFile(t.Item2));
                            var task = new LoadTPFResourcesTask(t.Item1, f, AccessLevel, ResourceManager.Locator.Type);
                            var size = task.GetEstimateTaskSize();
                            TotalSize += size;
                            if (doasync)
                            {
                                var progress1 = new Progress <int>();
                                TaskSizes.Add(size);
                                lock (ProgressLock)
                                {
                                    TaskProgress.Add(0);
                                }
                                int bindi = i;
                                progress1.ProgressChanged += (x, e) =>
                                {
                                    lock (ProgressLock)
                                    {
                                        TaskProgress[bindi] = e;
                                    }
                                    UpdateProgress(progress);
                                };
                                LoadingTasks.Add(task.RunAsync(progress1));
                                i++;
                            }
                            else
                            {
                                task.Run();
                                i++;
                                progress.Report(i);
                            }
                        }
                    }
                    PendingResources.Clear();

                    // Wait for all the tasks to complete
                    while (LoadingTasks.Count() > 0)
                    {
                        int idx = Task.WaitAny(LoadingTasks.ToArray());
                        LoadingTasks.RemoveAt(idx);
                    }
                    Binder = null;
                }));
            }