using System;
using System.IO;

using CommonHelpers;

namespace SqlCatPP {

//**************************************************************************************************
static class FileNameHlp {
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/// <exception cref="ArgumentNullException" />
/// <exception cref="OperationFailedException" />
public static bool CheckFileExists(string filePath)
{
   if ( HFile.TryCheckExistence( filePath, out Exception error ) )
      return true;
   if ( error is FileNotFoundException )
      return false;
   throw OpFailedExceptionCreator.Create(
      "Can not check existence of file \"{0}\".\n"+
      "{1}", filePath, error.Message );
}

/// <exception cref="ArgumentNullException" />
/// <exception cref="OperationFailedException" />
public static bool CheckFolderExists(string folderPath)
{
   if ( HDirectory.TryCheckExistence( folderPath, out Exception error ) )
      return true;
   if ( error is FileNotFoundException )
      return false;
   throw OpFailedExceptionCreator.Create(
      "Can not check existence of folder \"{0}\".\n"+
      "{1}", folderPath, error.Message );
}

//--------------------------------------------------------------------------------------------------

/// <exception cref="ArgumentNullException" />
/// <exception cref="OperationFailedException" />
public static void VerifyFileExists(string filePath)
{
   if ( !HFile.TryCheckExistence( filePath, out Exception error ) )
      throw error is FileNotFoundException ?
         OpFailedExceptionCreator.Create(
            "File not found: \"{0}\".",
            filePath ) :
         OpFailedExceptionCreator.Create(
            "Can not check existence of file \"{0}\".\n"+
            "{1}", filePath, error.Message );
}

/// <exception cref="ArgumentNullException" />
/// <exception cref="OperationFailedException" />
public static void VerifyFolderExists(string folderPath)
{
   if ( !HDirectory.TryCheckExistence( folderPath, out Exception error ) )
      throw error is FileNotFoundException ?
         OpFailedExceptionCreator.Create(
            "Folder not found: \"{0}\".",
            folderPath ) :
         OpFailedExceptionCreator.Create(
            "Can not check existence of folder \"{0}\".\n"+
            "{1}", folderPath, error.Message );
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
} // FileNameHlp
//**************************************************************************************************

} // SqlCatPP
