Skip to content

Commit f367c19

Browse files
committed
fix error dialog
1 parent 551ade5 commit f367c19

File tree

3 files changed

+63
-11
lines changed

3 files changed

+63
-11
lines changed

Applications/Ice/Main/Sources/Message.cs

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ namespace Cube.FileSystem.SevenZip.Ice;
1919

2020
using System;
2121
using System.Text;
22-
using System.Windows.Forms;
2322
using Cube.Text.Extensions;
2423

2524
/* ------------------------------------------------------------------------- */
@@ -35,6 +34,27 @@ public static class Message
3534
{
3635
#region Methods
3736

37+
/* --------------------------------------------------------------------- */
38+
///
39+
/// From
40+
///
41+
/// <summary>
42+
/// Create a message to show a DialogBox with an error icon and OK
43+
/// button.
44+
/// </summary>
45+
///
46+
/// <param name="src">Occurred exception.</param>
47+
///
48+
/// <returns>DialogMessage object.</returns>
49+
///
50+
/* --------------------------------------------------------------------- */
51+
public static DialogMessage From(Exception src) => new(GetMessage(src))
52+
{
53+
Title = "CubeICE",
54+
Icon = DialogIcon.Error,
55+
Buttons = DialogButtons.Ok,
56+
};
57+
3858
/* --------------------------------------------------------------------- */
3959
///
4060
/// Error
@@ -49,7 +69,7 @@ public static class Message
4969
/// <returns>DialogMessage object.</returns>
5070
///
5171
/* --------------------------------------------------------------------- */
52-
public static DialogMessage Error(Report src) => new(GetErrorText(src))
72+
public static DialogMessage Error(Report src) => new(GetMessage(src))
5373
{
5474
Title = "CubeICE",
5575
Icon = DialogIcon.Error,
@@ -127,19 +147,14 @@ public static OpenDirectoryMessage ForExtractLocation(SaveQuerySource src)
127147

128148
/* --------------------------------------------------------------------- */
129149
///
130-
/// Error
150+
/// GetMessage
131151
///
132152
/// <summary>
133-
/// Create a message to show a DialogBox with an error icon and YES/NO
134-
/// buttons.
153+
/// Gets the error text with specified arguments.
135154
/// </summary>
136155
///
137-
/// <param name="src">Source object.</param>
138-
///
139-
/// <returns>DialogMessage object.</returns>
140-
///
141156
/* --------------------------------------------------------------------- */
142-
private static string GetErrorText(Report src)
157+
private static string GetMessage(Report src)
143158
{
144159
var dest = new StringBuilder();
145160
var e = src.Exception is null ? "UnexpectedError" :
@@ -155,5 +170,21 @@ private static string GetErrorText(Report src)
155170
.ToString();
156171
}
157172

173+
/* --------------------------------------------------------------------- */
174+
///
175+
/// GetMessage
176+
///
177+
/// <summary>
178+
/// Gets the error text with specified arguments.
179+
/// </summary>
180+
///
181+
/* --------------------------------------------------------------------- */
182+
private static string GetMessage(Exception src)
183+
{
184+
var dest = new StringBuilder();
185+
if (src is AccessException ae) dest.Append($"{ae.FileName} ");
186+
return dest.AppendFormat(Properties.Resources.ErrorGeneric, src.GetType().Name).ToString();
187+
}
188+
158189
#endregion
159190
}

Applications/Ice/Main/Sources/Presenters/Base/ProgressViewModel.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,5 +247,26 @@ public int Value
247247
/* --------------------------------------------------------------------- */
248248
protected abstract string GetText();
249249

250+
/* --------------------------------------------------------------------- */
251+
///
252+
/// OnMessage
253+
///
254+
/// <summary>
255+
/// Converts the specified exception to a new instance of the
256+
/// DialogMessage class.
257+
/// </summary>
258+
///
259+
/// <param name="src">Source exception.</param>
260+
///
261+
/// <returns>DialogMessage object.</returns>
262+
///
263+
/// <remarks>
264+
/// The Method is called from the Track methods.
265+
/// </remarks>
266+
///
267+
/* --------------------------------------------------------------------- */
268+
protected override DialogMessage OnMessage(Exception src) =>
269+
src is OperationCanceledException ? null : Message.From(src);
270+
250271
#endregion
251272
}

Libraries/Core/Sources/ArchiveWriter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ private static void Verify(Entity src)
339339
}
340340
catch (Exception e)
341341
{
342-
Logger.Warn($"Path:{src.FullName.Quote()}, Error:{e.Message} ({e.GetType().Name})");
342+
Logger.Debug($"Path:{src.FullName.Quote()}, Error:{e.Message} ({e.GetType().Name})");
343343
throw new AccessException(src.RawName, e);
344344
}
345345
}

0 commit comments

Comments
 (0)