Skip to content

Commit 6550513

Browse files
committed
Refactor GsApiException methods
1 parent f6e9c75 commit 6550513

4 files changed

Lines changed: 36 additions & 44 deletions

File tree

Applications/Converter/Main/Sources/Message.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ public static OpenFileMessage ForUserProgram(SettingFolder src)
221221
CryptographicException => Surface.Texts.Error_Digest,
222222
EncryptionException => Surface.Texts.Error_MergePassword,
223223
PostProcessException => Surface.Texts.Error_PostProcess,
224-
GsApiException e => System.IO.File.ReadAllText(e.logPath),
224+
GsApiException e => string.Format(Surface.Texts.Error_Ghostscript, e.Status),
225225
ArgumentException => src.Message,
226226
_ => $"{src.Message} ({src.GetType().Name})",
227227
};

Libraries/Generating/Sources/Internal/GsApi.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ namespace Cube.Pdf.Ghostscript;
2020

2121
using System;
2222
using System.Collections.Generic;
23-
using System.Linq;
2423
using System.Runtime.InteropServices;
2524
using Cube.FileSystem;
2625
using Cube.Text.Extensions;
@@ -84,7 +83,7 @@ public static void Invoke(string[] raw, string tmp, string log) => SetTemp(tmp,
8483
foreach (var e in raw) args.Add(ToUtf8(e));
8584
NativeMethods.SetArgEncoding(core, 1 /*GS_ARG_ENCODING_UTF8*/ );
8685
var code = NativeMethods.InitWithArgs(core, args.Count, args.ToArray());
87-
if (code < 0 && code != (int)GsApiStatus.Quit && code != (int)GsApiStatus.Info) throw new GsApiException(code, log);
86+
if (code < 0 && code != (int)GsApiStatus.Quit && code != (int)GsApiStatus.Info) throw new GsApiException(code) { Log = log };
8887
}
8988
finally
9089
{

Libraries/Generating/Sources/Internal/GsApiException.cs

Lines changed: 4 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -46,31 +46,14 @@ public class GsApiException : Exception
4646
/// <param name="status">Status code.</param>
4747
///
4848
/* --------------------------------------------------------------------- */
49-
public GsApiException(int status) :
50-
this((GsApiStatus)Enum.ToObject(typeof(GsApiStatus), status)) { }
49+
public GsApiException(int status) : this((GsApiStatus)Enum.ToObject(typeof(GsApiStatus), status)) { }
5150

5251
/* --------------------------------------------------------------------- */
5352
///
5453
/// GsApiException
5554
///
5655
/// <summary>
5756
/// Initializes a new instance of the GsApiException class with
58-
/// the specified status and message, log.
59-
/// </summary>
60-
///
61-
/// <param name="status">Status code.</param>
62-
/// <param name="message">Message.</param>
63-
/// <param name="log"> Filepath of GS log.</param>
64-
///
65-
/* --------------------------------------------------------------------- */
66-
public GsApiException(int status, string log) :
67-
this((GsApiStatus)Enum.ToObject(typeof(GsApiStatus), status), $"{status} ({status:D})", log) { }
68-
/* --------------------------------------------------------------------- */
69-
///
70-
/// GsApiException
71-
///
72-
/// <summary>
73-
/// Initializes a new instance of the GsApiException class with
7457
/// the specified status.
7558
/// </summary>
7659
///
@@ -92,28 +75,7 @@ public GsApiException(GsApiStatus status) : this(status, $"{status} ({status:D})
9275
/// <param name="message">Message.</param>
9376
///
9477
/* --------------------------------------------------------------------- */
95-
public GsApiException(GsApiStatus status, string message) : this(status, message, null) { }
96-
97-
/* --------------------------------------------------------------------- */
98-
///
99-
/// GsApiException
100-
///
101-
/// <summary>
102-
/// Initializes a new instance of the GsApiException class with
103-
/// the specified status and message, log.
104-
/// </summary>
105-
///
106-
/// <param name="status">Status code.</param>
107-
/// <param name="message">Message.</param>
108-
/// <param name="log"> Filepath of GS log.</param>
109-
///
110-
/* --------------------------------------------------------------------- */
111-
public GsApiException(GsApiStatus status, string message, string log) :
112-
base(message)
113-
{
114-
Status = status;
115-
logPath = log;
116-
}
78+
public GsApiException(GsApiStatus status, string message) : base(message) => Status = status;
11779

11880
#endregion
11981

@@ -129,6 +91,7 @@ public GsApiException(GsApiStatus status, string message, string log) :
12991
///
13092
/* --------------------------------------------------------------------- */
13193
public GsApiStatus Status { get; }
94+
13295
/* --------------------------------------------------------------------- */
13396
///
13497
/// logPath
@@ -138,7 +101,7 @@ public GsApiException(GsApiStatus status, string message, string log) :
138101
/// </summary>
139102
///
140103
/* --------------------------------------------------------------------- */
141-
public string logPath { get; }
104+
public string Log { get; init; }
142105

143106
#endregion
144107
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/* ------------------------------------------------------------------------- */
2+
//
3+
// Copyright (c) 2010 CubeSoft, Inc.
4+
//
5+
// This program is free software: you can redistribute it and/or modify
6+
// it under the terms of the GNU Affero General Public License as published
7+
// by the Free Software Foundation, either version 3 of the License, or
8+
// (at your option) any later version.
9+
//
10+
// This program is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
// GNU Affero General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU Affero General Public License
16+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
//
18+
/* ------------------------------------------------------------------------- */
19+
namespace System.Runtime.CompilerServices;
20+
21+
/* ------------------------------------------------------------------------- */
22+
///
23+
/// IsExternalInit
24+
///
25+
/// <summary>
26+
/// Provides init accessor of properties.
27+
/// </summary>
28+
///
29+
/* ------------------------------------------------------------------------- */
30+
internal sealed class IsExternalInit { }

0 commit comments

Comments
 (0)