From d71041bfcf3d4022dc2f8df4a1687fbe00f7b808 Mon Sep 17 00:00:00 2001 From: pauldyatlov Date: Sat, 1 Jul 2023 15:38:12 -0400 Subject: [PATCH] Directory exists, file exists checks separation --- Facepunch.Steamworks/Structs/UgcEditor.cs | 33 ++++++++++++++++------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/Facepunch.Steamworks/Structs/UgcEditor.cs b/Facepunch.Steamworks/Structs/UgcEditor.cs index ffd00f0..183edba 100644 --- a/Facepunch.Steamworks/Structs/UgcEditor.cs +++ b/Facepunch.Steamworks/Structs/UgcEditor.cs @@ -138,15 +138,7 @@ namespace Steamworks.Ugc // // Checks // - if ( ContentFolder != null ) - { - if ( !System.IO.Directory.Exists( ContentFolder.FullName ) ) - throw new System.Exception( $"UgcEditor - Content Folder doesn't exist ({ContentFolder.FullName})" ); - - if ( !ContentFolder.EnumerateFiles( "*", System.IO.SearchOption.AllDirectories ).Any() ) - throw new System.Exception( $"UgcEditor - Content Folder is empty" ); - } - + PerformValidityChecks(); // // Item Create @@ -283,6 +275,29 @@ namespace Steamworks.Ugc return result; } + + private void PerformValidityChecks() + { + if ( ContentFolder == null ) + return; + + var fileAttributes = System.IO.File.GetAttributes( ContentFolder.FullName ); + var isFolder = fileAttributes.HasFlag( System.IO.FileAttributes.Directory ); + + if ( isFolder ) + { + if ( !ContentFolder.Exists ) + throw new System.Exception( $"UgcEditor - Content Folder doesn't exist ({ContentFolder.FullName})" ); + + if ( !ContentFolder.EnumerateFiles( "*", System.IO.SearchOption.AllDirectories ).Any() ) + throw new System.Exception( $"UgcEditor - Content Folder is empty" ); + } + else + { + if ( !ContentFolder.Exists ) + throw new System.Exception( $"UgcEditor - Content Path for file doesn't exist ({ContentFolder.FullName})" ); + } + } } public struct PublishResult