示例#1
0
        private static CheckBox MakeFilterCheckBox(UnpackFilter filter)
        {
            var cbx = new CheckBox {
                DataContext = filter
            };

            cbx.SetBinding(CheckBox.IsCheckedProperty, "Enabled");
            cbx.SetBinding(CheckBox.ContentProperty, "Name");
            return(cbx);
        }
示例#2
0
        public void Unpack(IProgress <ProgressReport> progress, IProgress <string> errors, CancellationToken cancelToken)
        {
            TPUtil.CopyOodle(Game.Type, Game.Settings.GameDirectory);

            progress.Report(new ProgressReport(0, "Scanning files..."));
            if (Game.Settings.UnpackSourceEbls)
            {
                VirtualFS.LoadEbls(Game);
            }
            if (Game.Settings.UnpackSourceUXM)
            {
                VirtualFS.LoadFiles(Game.Settings.GameDirectory);
            }
            if (Game.Settings.UnpackSourceModEngine)
            {
                VirtualFS.LoadFiles(TPUtil.ReadModEngineDirectory(Game.Settings.GameDirectory));
            }

            string[] paths = VirtualFS.Files.Keys
                             .Where(k => TPUtil.HasValidExtension(k) &&
                                    UnpackFilter.RunFilters(k, Game.Config.MapFilters.Concat(Game.Config.Filters)))
                             .OrderBy(k => k).ToArray();

            progress.Report(new ProgressReport(0, $"Unpacking files... (0/{paths.Length})"));
            var tasks = new Task <int> [paths.Length];

            for (int i = 0; i < paths.Length; i++)
            {
                VirtualFile vf = VirtualFS.Files[paths[i]];
                tasks[i] = Task.Run(() => UnpackVirtualFile(vf, cancelToken));
                tasks[i].ContinueWith(task =>
                {
                    Interlocked.Increment(ref FilesCompleted);
                    progress.Report(new ProgressReport((float)FilesCompleted / paths.Length,
                                                       $"Unpacking files... ({FilesCompleted}/{paths.Length})"));

                    if (task.IsFaulted)
                    {
                        errors.Report($"Error in file \"{vf.Path}\"\n{task.Exception}");
                    }
                });
            }

            Task.WaitAll(tasks);
            int textureCount = tasks.Where(t => t.IsCompleted).Sum(t => t.Result);

            if (cancelToken.IsCancellationRequested)
            {
                progress.Report(new ProgressReport(1, "Unpacking aborted successfully."));
            }
            else
            {
                progress.Report(new ProgressReport(1, $"Finished unpacking {textureCount} textures from {paths.Length} files!"));
            }
        }