コード例 #1
0
        public static async Task ExtractFolder(TreeviewViewModel treeItem)
        {
            var    entriesToExtract = new List <ListBoxViewModel>();
            string fullPath         = treeItem.GetFullPath().Substring(1);

            foreach (var entry in DataGridVm.dataGridViewModel) // current loaded pak files
            {
                var m = Regex.Match(entry.Name, $"{fullPath}/*", RegexOptions.IgnoreCase);
                if (m.Success)
                {
                    foreach (var entries in Globals.CachedPakFiles.Values)
                    {
                        if (entries.TryGetValue("/" + entry.Name.Substring(0, entry.Name.LastIndexOf(".")), out var pakEntry)) // remove the extension to get the entry
                        {
                            entriesToExtract.Add(new ListBoxViewModel
                            {
                                Content  = pakEntry.GetNameWithExtension(),
                                PakEntry = pakEntry
                            });
                        }
                    }
                }
            }

            if (entriesToExtract.Any())
            {
                await Assets.GetUserSelection(entriesToExtract);
            }
        }
コード例 #2
0
        public static async Task ExportFolder(TreeviewViewModel treeItem)
        {
            string    fullPath = treeItem.GetFullPath().Substring(1);
            Stopwatch timer    = Stopwatch.StartNew();

            ExtractStopVm.stopViewModel.IsEnabled    = true;
            ExtractStopVm.extractViewModel.IsEnabled = false;
            StatusBarVm.statusBarViewModel.Set(string.Empty, Properties.Resources.Loading);
            Tasks.TokenSource = new CancellationTokenSource();

            await Task.Run(() =>
            {
                foreach (var entry in DataGridVm.dataGridViewModel) // current loaded pak files
                {
                    if (Tasks.TokenSource.IsCancellationRequested)
                    {
                        throw new TaskCanceledException(Properties.Resources.Canceled);
                    }

                    var m = Regex.Match(entry.Name, $"{fullPath}/*", RegexOptions.IgnoreCase);
                    if (m.Success)
                    {
                        if (Globals.CachedPakFiles.TryGetValue(entry.ContainerFile, out PakFileReader pak))
                        {
                            if (pak.TryGetValue("/" + entry.Name.Substring(0, entry.Name.LastIndexOf(".")), out var pakEntry)) // remove the extension to get the entry
                            {
                                Assets.Export(pakEntry, true);
                            }
                        }
                        else if (Globals.CachedIoStores.TryGetValue(entry.ContainerFile, out FFileIoStoreReader IoStore))
                        {
                            if (IoStore.TryGetValue("/" + entry.Name.Substring(0, entry.Name.LastIndexOf(".")), out var IoEntry)) // remove the extension to get the entry
                            {
                                Assets.Export(IoEntry, true);
                            }
                        }
                    }
                }
            }).ContinueWith(t =>
            {
                timer.Stop();
                ExtractStopVm.stopViewModel.IsEnabled    = false;
                ExtractStopVm.extractViewModel.IsEnabled = true;

                if (t.Exception != null)
                {
                    Tasks.TaskCompleted(t.Exception);
                }
                else
                {
                    StatusBarVm.statusBarViewModel.Set(string.Format(Properties.Resources.TimeElapsed, timer.ElapsedMilliseconds), Properties.Resources.Success);
                }
            },
                            TaskScheduler.FromCurrentSynchronizationContext());
        }