@@ -19,7 +19,6 @@ namespace Cube.FileSystem.SevenZip.Ice;
1919
2020using System ;
2121using System . Text ;
22- using System . Windows . Forms ;
2322using 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}
0 commit comments