Skip to content

Commit

Permalink
fixed a bug that prevented opening the Pack or Embed folder
Browse files Browse the repository at this point in the history
added support for exceptions in the Task runner
added Task thread naming
  • Loading branch information
DmitriySalnikov committed Oct 10, 2023
1 parent 0b1e2c7 commit 5542094
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
5 changes: 0 additions & 5 deletions GodotPCKExplorer.UI/Forms/AboutBox1.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace GodotPCKExplorer.UI
Expand Down
4 changes: 3 additions & 1 deletion GodotPCKExplorer.UI/Forms/CreatePCKFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ public CreatePCKFile()
public void SetFolderPath(string path)
{
List<PCKPacker.FileToPack> filesScan = new List<PCKPacker.FileToPack>();
Program.DoTaskWithProgressBar((t) => filesScan = PCKUtils.ScanFoldersForFiles(Path.GetFullPath(path), cancellationToken: t));

if (Directory.Exists(path))
Program.DoTaskWithProgressBar((t) => filesScan = PCKUtils.ScanFoldersForFiles(Path.GetFullPath(path), cancellationToken: t));

GC.Collect();
files = filesScan.ToDictionary((f) => f.OriginalPath);
Expand Down
14 changes: 12 additions & 2 deletions GodotPCKExplorer.UI/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Globalization;
using System.IO;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -215,15 +216,24 @@ public static void HideConsole()
ShowWindow(GetConsoleWindow(), SW_HIDE);
}

public static void DoTaskWithProgressBar(Action<CancellationToken> work)
public static void DoTaskWithProgressBar(Action<CancellationToken> work, [CallerFilePath] string _file = "", [CallerMemberName] string _func = "", [CallerLineNumber] int _line = 0)
{
var token = new CancellationTokenSource();
progressBar = new BackgroundProgress(token);

var task = Task.Run(() =>
{
Thread.CurrentThread.Name = $"{Path.GetFileName(_file)}::{_func}::{_line}";
// Do work
work(token.Token);
try
{
work(token.Token);
}
catch (Exception ex)
{
ShowMessage(ex, MessageType.Error);
}
// Force close window
token.Cancel();
Expand Down
4 changes: 2 additions & 2 deletions GodotPCKExplorer.UI/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.3.1.0")]
[assembly: AssemblyFileVersion("1.3.1.0")]
[assembly: AssemblyVersion("1.3.2.0")]
[assembly: AssemblyFileVersion("1.3.2.0")]
1 change: 0 additions & 1 deletion GodotPCKExplorer.UI/Utils.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.ComponentModel;
using System.IO;
using System.Text.RegularExpressions;

Expand Down

0 comments on commit 5542094

Please sign in to comment.