diff --git a/DebUOS/Packaging.DebUOS/DebUOSPackageFileStructCreator.cs b/DebUOS/Packaging.DebUOS/DebUOSPackageFileStructCreator.cs index c72cc03..1d62005 100644 --- a/DebUOS/Packaging.DebUOS/DebUOSPackageFileStructCreator.cs +++ b/DebUOS/Packaging.DebUOS/DebUOSPackageFileStructCreator.cs @@ -370,27 +370,43 @@ public void CreatePackagingFolder(DebUOSConfiguration configuration) File.WriteAllText(controlFile, stringBuilder.ToString(), encoding); } - if (File.Exists(configuration.DebPostinstFile)) + if (ExistsConfigurationFile(nameof(configuration.DebPostinstFile), configuration.DebPostinstFile)) { var postinstFile = Path.Join(packingFolder, "DEBIAN", "postinst"); File.Copy(configuration.DebPostinstFile, postinstFile); } - if (File.Exists(configuration.DebPrermFile)) + if (ExistsConfigurationFile(nameof(configuration.DebPrermFile), configuration.DebPrermFile)) { var prermFile = Path.Join(packingFolder, "DEBIAN", "prerm"); File.Copy(configuration.DebPrermFile, prermFile); } - if (File.Exists(configuration.DebPostrmFile)) + if (ExistsConfigurationFile(nameof(configuration.DebPostrmFile), configuration.DebPostrmFile)) { var postrmFile = Path.Join(packingFolder, "DEBIAN", "postrm"); File.Copy(configuration.DebPostrmFile, postrmFile); } - if (File.Exists(configuration.DebPreinstFile)) + if (ExistsConfigurationFile(nameof(configuration.DebPreinstFile), configuration.DebPreinstFile)) { var preinstFile = Path.Join(packingFolder, "DEBIAN", "preinst"); File.Copy(configuration.DebPreinstFile, preinstFile); } } + + private bool ExistsConfigurationFile(string fileName, string? configurationFile) + { + if (string.IsNullOrEmpty(configurationFile)) + { + return false; + } + + if (!File.Exists(configurationFile)) + { + Logger.LogWarning($"配置了 {fileName} 文件, 但是 '{configurationFile}' 不存在"); + return false; + } + + return true; + } static class FolderUtils {