private static async Task PopulateDataGrid() { Dictionary <string, string> IfExistChecker = new Dictionary <string, string>(); await Task.Run(() => { if (!string.IsNullOrEmpty(FWindow.FCurrentPAK)) { FillList(PAKEntries.PAKToDisplay[FWindow.FCurrentPAK], IfExistChecker); } else { foreach (FPakEntry[] PAKsFileInfos in PAKEntries.PAKToDisplay.Values) { FillList(PAKsFileInfos, IfExistChecker); } } }).ContinueWith(TheTask => { TasksUtility.TaskCompleted(TheTask.Exception); }); }
public static async Task LoadSelectedAsset() { new UpdateMyProcessEvents("", "").Update(); FWindow.FMain.Button_Extract.IsEnabled = false; FWindow.FMain.Button_Stop.IsEnabled = true; FWindow.FMain.AssetPropertiesBox_Main.Text = string.Empty; FWindow.FMain.AssetPropertiesBox_Main.SyntaxHighlighting = ResourceLoader.LoadHighlightingDefinition("Json.xshd"); FWindow.FMain.ImageBox_Main.Source = null; string[] selectedItems = FWindow.FMain.ListBox_Main.SelectedItems.OfType <string>().ToArray(); //store selected items, doesn't crash if user select another item while extracting string treePath = TreeViewUtility.GetFullPath(FWindow.TVItem); //never change in the loop, in case user wanna see other folders while extracting TasksUtility.CancellableTaskTokenSource = new CancellationTokenSource(); CancellationToken cToken = TasksUtility.CancellableTaskTokenSource.Token; await Task.Run(() => { isRunning = true; foreach (string item in selectedItems) { DebugHelper.WriteLine("Assets: User selected " + item); cToken.ThrowIfCancellationRequested(); //if clicked on 'Stop' it breaks at the following item while (!string.Equals(FWindow.FCurrentAsset, item)) { FWindow.FCurrentAsset = item; } LoadAsset(treePath + "/" + item); } }, cToken).ContinueWith(TheTask => { TasksUtility.TaskCompleted(TheTask.Exception); TasksUtility.CancellableTaskTokenSource.Dispose(); isRunning = false; }); FWindow.FMain.Button_Extract.IsEnabled = true; FWindow.FMain.Button_Stop.IsEnabled = false; }
private async Task UpdateImageWithWatermark() { bool watermarkEnabled = (bool)bWatermarkIcon.IsChecked; string rarityDesign = ((ComboBoxItem)ComboBox_Design.SelectedItem).Content.ToString(); bool isFeatured = (bool)bFeaturedIcon.IsChecked; int opacity = Convert.ToInt32(Opacity_Slider.Value); double scale = Scale_Slider.Value; double xPos = xPos_Slider.Value; double yPos = yPos_Slider.Value; await Task.Run(() => { DrawingVisual drawingVisual = new DrawingVisual(); using (DrawingContext drawingContext = drawingVisual.RenderOpen()) { //INITIALIZATION drawingContext.DrawRectangle(Brushes.Transparent, null, new Rect(new Point(0, 0), new Size(515, 515))); BitmapImage source = null; switch (rarityDesign) { case "Default": source = new BitmapImage(new Uri(isFeatured ? "pack://application:,,,/Resources/Template_D_F.png" : "pack://application:,,,/Resources/Template_D_N.png")); break; case "Flat": source = new BitmapImage(new Uri(isFeatured ? "pack://application:,,,/Resources/Template_F_F.png" : "pack://application:,,,/Resources/Template_F_N.png")); break; case "Minimalist": source = new BitmapImage(new Uri(isFeatured ? "pack://application:,,,/Resources/Template_M_F.png" : "pack://application:,,,/Resources/Template_M_N.png")); break; } drawingContext.DrawImage(source, new Rect(new Point(0, 0), new Size(515, 515))); if (!string.IsNullOrEmpty(FProp.Default.FWatermarkFilePath) && watermarkEnabled) { using (StreamReader image = new StreamReader(FProp.Default.FWatermarkFilePath)) { if (image != null) { BitmapImage bmp = new BitmapImage(); bmp.BeginInit(); bmp.CacheOption = BitmapCacheOption.OnLoad; bmp.StreamSource = image.BaseStream; bmp.EndInit(); drawingContext.DrawImage(ImagesUtility.CreateTransparency(bmp, opacity), new Rect(xPos, yPos, scale, scale)); } } } } if (drawingVisual != null) { RenderTargetBitmap RTB = new RenderTargetBitmap(515, 515, 96, 96, PixelFormats.Pbgra32); RTB.Render(drawingVisual); RTB.Freeze(); //We freeze to apply the RTB to our imagesource from the UI Thread FWindow.FMain.Dispatcher.InvokeAsync(() => { ImageBox_RarityPreview.Source = BitmapFrame.Create(RTB); //thread safe and fast af }); } }).ContinueWith(TheTask => { TasksUtility.TaskCompleted(TheTask.Exception); }); }
public static async Task ExtractFoldersAndSub(string path) { new UpdateMyProcessEvents("", "").Update(); FWindow.FMain.Button_Extract.IsEnabled = false; FWindow.FMain.Button_Stop.IsEnabled = true; FWindow.FMain.AssetPropertiesBox_Main.Text = string.Empty; FWindow.FMain.AssetPropertiesBox_Main.SyntaxHighlighting = ResourceLoader.LoadHighlightingDefinition("Json.xshd"); FWindow.FMain.ImageBox_Main.Source = null; List <IEnumerable <string> > assetList = new List <IEnumerable <string> >(); if (!string.IsNullOrEmpty(FWindow.FCurrentPAK)) { IEnumerable <string> files = PAKEntries.PAKToDisplay[FWindow.FCurrentPAK] .Where(x => x.Name.StartsWith(path + "/")) .Select(x => x.Name); if (files != null) { assetList.Add(files); } } else { foreach (FPakEntry[] PAKsFileInfos in PAKEntries.PAKToDisplay.Values) { IEnumerable <string> files = PAKsFileInfos .Where(x => x.Name.StartsWith(path + "/")) .Select(x => x.Name); if (files != null) { assetList.Add(files); } } } TasksUtility.CancellableTaskTokenSource = new CancellationTokenSource(); CancellationToken cToken = TasksUtility.CancellableTaskTokenSource.Token; await Task.Run(() => { isRunning = true; DebugHelper.WriteLine("Assets: User is extracting everything in " + path); foreach (IEnumerable <string> filesFromOnePak in assetList) { foreach (string asset in filesFromOnePak.OrderBy(s => s)) { cToken.ThrowIfCancellationRequested(); //if clicked on 'Stop' it breaks at the following item string target; if (asset.EndsWith(".uexp") || asset.EndsWith(".ubulk")) { continue; } else if (!asset.EndsWith(".uasset")) { target = asset; //ini uproject locres etc } else { target = asset.Substring(0, asset.LastIndexOf(".")); //uassets } while (!string.Equals(FWindow.FCurrentAsset, Path.GetFileName(target))) { FWindow.FCurrentAsset = Path.GetFileName(target); } LoadAsset(target); } } }, cToken).ContinueWith(TheTask => { TasksUtility.TaskCompleted(TheTask.Exception); TasksUtility.CancellableTaskTokenSource.Dispose(); isRunning = false; }); FWindow.FMain.Button_Extract.IsEnabled = true; FWindow.FMain.Button_Stop.IsEnabled = false; }
public static async Task ExtractUpdateMode() { new UpdateMyProcessEvents("", "").Update(); FWindow.FMain.Button_Extract.IsEnabled = false; FWindow.FMain.Button_Stop.IsEnabled = true; FWindow.FMain.AssetPropertiesBox_Main.Text = string.Empty; FWindow.FMain.AssetPropertiesBox_Main.SyntaxHighlighting = ResourceLoader.LoadHighlightingDefinition("Json.xshd"); FWindow.FMain.ImageBox_Main.Source = null; bool sound = FProp.Default.FOpenSounds; FProp.Default.FOpenSounds = false; List <IEnumerable <string> > assetList = new List <IEnumerable <string> >(); foreach (FPakEntry[] PAKsFileInfos in PAKEntries.PAKToDisplay.Values) { IEnumerable <string> files = PAKsFileInfos .Where(x => Forms.FModel_UpdateMode.AssetsEntriesDict.Any(c => bool.Parse(c.Value["isChecked"]) && x.Name.StartsWith(c.Value["Path"]))) .Select(x => x.Name); if (files != null) { assetList.Add(files); } } TasksUtility.CancellableTaskTokenSource = new CancellationTokenSource(); CancellationToken cToken = TasksUtility.CancellableTaskTokenSource.Token; await Task.Run(() => { isRunning = true; foreach (IEnumerable <string> filesFromOnePak in assetList) { foreach (string asset in filesFromOnePak.OrderBy(s => s)) { cToken.ThrowIfCancellationRequested(); //if clicked on 'Stop' it breaks at the following item string target; if (asset.EndsWith(".uexp") || asset.EndsWith(".ubulk")) { continue; } else if (!asset.EndsWith(".uasset")) { target = asset; //ini uproject locres etc } else { target = asset.Substring(0, asset.LastIndexOf(".")); //uassets } while (!string.Equals(FWindow.FCurrentAsset, Path.GetFileName(target))) { FWindow.FCurrentAsset = Path.GetFileName(target); } try { LoadAsset(target); } catch (System.Exception ex) { new UpdateMyConsole(ex.Message, CColors.Red, true).Append(); } } } }, cToken).ContinueWith(TheTask => { TasksUtility.TaskCompleted(TheTask.Exception); TasksUtility.CancellableTaskTokenSource.Dispose(); isRunning = false; }); FWindow.FMain.MI_Auto_Save_Images.IsChecked = false; FWindow.FMain.Button_Extract.IsEnabled = true; FWindow.FMain.Button_Stop.IsEnabled = false; FWindow.FMain.MI_Auto_Save_Images.IsChecked = false; FProp.Default.FOpenSounds = sound; new UpdateMyProcessEvents("All assets have been extracted successfully", "Success").Update(); }
private async Task UpdateMergerPreview() { AddImages_Button.IsEnabled = false; RemoveImage_Button.IsEnabled = false; ClearImages_Button.IsEnabled = false; ImagesPerRow_Slider.IsEnabled = false; OpenImage_Button.IsEnabled = false; SaveImage_Button.IsEnabled = false; if ((_imagePath != null && _imagePath.Count > 0) || ImagesListBox.Items.Count > 0) { _imagePath = new List <string>(); for (int i = 0; i < ImagesListBox.Items.Count; ++i) { _imagePath.Add(((ListBoxItem)ImagesListBox.Items[i]).ContentStringFormat); } } int imageCount = _imagePath.Count; int numperrow = Convert.ToInt32(ImagesPerRow_Slider.Value); await Task.Run(() => { DrawingVisual drawingVisual = new DrawingVisual(); using (DrawingContext drawingContext = drawingVisual.RenderOpen()) { //INITIALIZATION drawingContext.DrawRectangle(Brushes.Transparent, null, new Rect(new Point(0, 0), new Size(515, 515))); var w = 520 * numperrow; if (imageCount * 520 < 520 * numperrow) { w = imageCount * 520; } int h = int.Parse(Math.Ceiling(double.Parse(imageCount.ToString()) / numperrow).ToString(CultureInfo.InvariantCulture)) * 520; int num = 1; int curW = 0; int curH = 0; int maxHeight = 0; for (int i = 0; i < imageCount; i++) { int percentage = (i + 1) * 100 / imageCount; BitmapImage source = new BitmapImage(new Uri(_imagePath[i])); source.DecodePixelWidth = 515; double width = source.Width; double height = source.Height; if (height > maxHeight) { maxHeight = Convert.ToInt32(height); } drawingContext.DrawImage(source, new Rect(new Point(curW, curH), new Size(width, height))); if (num % numperrow == 0) { curW = 0; curH += maxHeight + 5; num += 1; maxHeight = 0; //reset max height for each new row } else { curW += Convert.ToInt32(width) + 5; num += 1; } } } if (drawingVisual != null) { RenderTargetBitmap RTB = new RenderTargetBitmap((int)Math.Floor(drawingVisual.DescendantBounds.Width), (int)Math.Floor(drawingVisual.DescendantBounds.Height), 96, 96, PixelFormats.Pbgra32); RTB.Render(drawingVisual); RTB.Freeze(); //We freeze to apply the RTB to our imagesource from the UI Thread this.Dispatcher.InvokeAsync(() => { MergerPreview_Image.Source = BitmapFrame.Create(RTB); //thread safe and fast af }); } }).ContinueWith(TheTask => { TasksUtility.TaskCompleted(TheTask.Exception); }); GC.Collect(); GC.WaitForPendingFinalizers(); AddImages_Button.IsEnabled = true; RemoveImage_Button.IsEnabled = true; ClearImages_Button.IsEnabled = true; ImagesPerRow_Slider.IsEnabled = true; OpenImage_Button.IsEnabled = true; SaveImage_Button.IsEnabled = true; }