Przeglądaj źródła

Native dependency loader: improved message

Marcin Ziąbek 1 rok temu
rodzic
commit
25a0db6759

+ 11 - 13
Source/QuestPDF/Helpers/NativeDependencyCompatibilityChecker.cs

@@ -25,7 +25,6 @@ namespace QuestPDF.Helpers
             if (IsCompatibilityChecked)
                 return;
             
-            const string exceptionBaseMessage = "The QuestPDF library has encountered an issue while loading one of its dependencies.";
             const string paragraph = "\n\n";
                 
             // test with dotnet-based mechanism where native files are provided
@@ -52,21 +51,17 @@ namespace QuestPDF.Helpers
             {
                 var supportedRuntimes = string.Join(", ", NativeDependencyProvider.SupportedPlatforms);
                 var currentRuntime = NativeDependencyProvider.GetRuntimePlatform();
-                
-                var message = 
-                    $"{exceptionBaseMessage}{paragraph}" +
-                    "Your runtime is currently not supported by QuestPDF. " +
-                    $"Currently supported runtimes are: {supportedRuntimes}. ";
+                var isRuntimeSupported = NativeDependencyProvider.SupportedPlatforms.Contains(currentRuntime);
 
-                if (NativeDependencyProvider.SupportedPlatforms.Contains(currentRuntime))
-                {
-                    message += $"{paragraph}It appears that your current operating system distribution may be outdated. For optimal compatibility, please consider updating it to a more recent version.";
-                }
-                else
+                var message = $"The QuestPDF library has encountered an issue while loading one of its dependencies.";
+                
+                if (!isRuntimeSupported)
                 {
-                    message += $"{paragraph}Your current runtime is detected as '{currentRuntime}'.";
+                    message += $"{paragraph}Your runtime is not supported by QuestPDF. " +
+                                $"The following runtimes are supported: {supportedRuntimes}. " +
+                                $"Your current runtime is detected as '{currentRuntime}'. ";
                 }
-
+                
                 if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                     message += $"{paragraph}Please always set the 'Platform target' to either 'X86' or 'X64' in your startup project settings. Please do not use the 'Any CPU' option.";
                 
@@ -77,6 +72,9 @@ namespace QuestPDF.Helpers
                 
                 if (!string.IsNullOrEmpty(hint))
                     message += $"{paragraph}{hint}";
+
+                if (isRuntimeSupported)
+                    message += $"{paragraph}If the problem persists, it may mean that your current operating system distribution is outdated. For optimal compatibility, please consider updating it to a more recent version.";
                 
                 throw new Exception(message, innerException);
             }

+ 4 - 3
Source/QuestPDF/Qpdf/QpdfNativeDependencyCompatibilityChecker.cs

@@ -31,8 +31,6 @@ internal static class QpdfNativeDependencyCompatibilityChecker
         if (!platform.StartsWith("linux"))
             return string.Empty;
         
-        const string openSslHint = "Please also ensure that the OpenSSL library is installed on your system with version at least 3.0.0.";
-        
         var command = platform switch
         {
             "linux-x64" or "linux-arm64" => "apt install openssl-bin gnutls-bin libjpeg-dev",
@@ -40,6 +38,9 @@ internal static class QpdfNativeDependencyCompatibilityChecker
             _ => throw new NotSupportedException()
         };
         
-        return $"Installing additional dependencies may help. Likely command: '{command}'. {openSslHint}";
+        const string openSslHint = "Please also ensure that the OpenSSL library is installed on your system with version at least 3.0.0.";
+        const string qpdfHint = "Do NOT install the qpdf package.";
+        
+        return $"Installing additional dependencies may help. Please try the following command: '{command}'. {openSslHint} {qpdfHint}";
     }
 }