From 31251c402de6a48f1ca74e688feb1a2f4eeb9afd Mon Sep 17 00:00:00 2001 From: Dion Date: Sat, 16 Nov 2024 18:23:30 +0100 Subject: [PATCH 01/73] ffmpeg init --- starsky-tools/build-tools/.gitignore | 1 + starsky-tools/build-tools/ffmpeg-download.sh | 24 ++++++++ starsky-tools/build-tools/ffmpeg-download1.sh | 43 ++++++++++++++ .../Models/AppSettings.cs | 7 +++ starsky/starsky.foundation.video/Class1.cs | 5 ++ .../GetDependencies/FFMpegDownload.cs | 59 +++++++++++++++++++ .../GetDependencies/GetVersionString.cs | 53 +++++++++++++++++ .../Interfaces/IFFMpegDownload.cs | 6 ++ .../OperationSystemPlatforms.cs | 27 +++++++++ .../starsky.foundation.video.csproj | 13 ++++ starsky/starsky.sln | 7 +++ 11 files changed, 245 insertions(+) create mode 100644 starsky-tools/build-tools/ffmpeg-download.sh create mode 100644 starsky-tools/build-tools/ffmpeg-download1.sh create mode 100644 starsky/starsky.foundation.video/Class1.cs create mode 100644 starsky/starsky.foundation.video/GetDependencies/FFMpegDownload.cs create mode 100644 starsky/starsky.foundation.video/GetDependencies/GetVersionString.cs create mode 100644 starsky/starsky.foundation.video/GetDependencies/Interfaces/IFFMpegDownload.cs create mode 100644 starsky/starsky.foundation.video/GetDependencies/OperationSystemPlatforms.cs create mode 100644 starsky/starsky.foundation.video/starsky.foundation.video.csproj diff --git a/starsky-tools/build-tools/.gitignore b/starsky-tools/build-tools/.gitignore index e7bf2596f8..5689d498c0 100644 --- a/starsky-tools/build-tools/.gitignore +++ b/starsky-tools/build-tools/.gitignore @@ -1 +1,2 @@ create-docusaurus-tmp-folder/** +ffmpeg_binaries/** diff --git a/starsky-tools/build-tools/ffmpeg-download.sh b/starsky-tools/build-tools/ffmpeg-download.sh new file mode 100644 index 0000000000..bdee9bc68e --- /dev/null +++ b/starsky-tools/build-tools/ffmpeg-download.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +FFBINARIES_API="https://ffbinaries.com/api/v1/version/6.1" +OSX_ARM64="https://www.osxexperts.net/ffmpeg71arm.zip" + +# Fetch the JSON data +json=$(curl -s $FFBINARIES_API) + +# Extract URLs for ffmpeg binaries +urls=$(echo "$json" | grep -o '"ffmpeg":"[^"]*"' | sed 's/"ffmpeg":"//;s/"//') + +# Create a directory to store the binaries +mkdir -p ffmpeg_binaries +cd ffmpeg_binaries + +# Download each ffmpeg binary +for url in $urls; do + echo "Downloading $url" + curl -L -O "$url" +done + +curl -O $OSX_ARM64 + +echo "All ffmpeg binaries downloaded successfully." diff --git a/starsky-tools/build-tools/ffmpeg-download1.sh b/starsky-tools/build-tools/ffmpeg-download1.sh new file mode 100644 index 0000000000..8208dbe973 --- /dev/null +++ b/starsky-tools/build-tools/ffmpeg-download1.sh @@ -0,0 +1,43 @@ +#!/bin/bash + +# Fetch the JSON data +json=$(curl -s https://ffbinaries.com/api/v1/version/6.1) + +# Create a directory to store the binaries +mkdir -p ffmpeg_binaries +cd ffmpeg_binaries + +# Initialize JSON output +output_json="{\"binaries\":[" + +urls=$(echo "$json" | grep -o '"ffmpeg":"[^"]*"' | sed 's/"ffmpeg":"//;s/"//') + +for url in $urls; do + # Extract architecture and URL +# architecture=$(echo "$line" | grep -oP '"[^"]+(?=":)') + architecture=$(echo "$url" | sed -n 's/.*-\([a-z0-9-]*-[a-z0-9]*\)\.zip/\1/p') + + # Download the binary + echo "Downloading $url for $architecture ..." + curl -L -O "$url" + + # Add to output JSON + output_json="${output_json}{\"architecture\":\"$architecture\",\"url\":\"$url\"}," +done + + +# Add osx-arm64 explicitly +custom_arch="osx-arm64" +custom_url="https://www.osxexperts.net/ffmpeg71arm.zip" +echo "Adding custom architecture $custom_arch with URL $custom_url..." +curl -L -O "$custom_url" +output_json="${output_json}{\"architecture\":\"$custom_arch\",\"url\":\"$custom_url\"}," + +# Finalize JSON +output_json="${output_json%,}]}" # Remove trailing comma and close the JSON array + +# Write JSON to file +echo "$output_json" > ffmpeg_urls.json + +echo "All ffmpeg binaries downloaded successfully." +echo "URLs with architectures saved to ffmpeg_binaries/ffmpeg_urls.json" diff --git a/starsky/starsky.foundation.platform/Models/AppSettings.cs b/starsky/starsky.foundation.platform/Models/AppSettings.cs index 9c9c854d30..0d4e2fbf4f 100644 --- a/starsky/starsky.foundation.platform/Models/AppSettings.cs +++ b/starsky/starsky.foundation.platform/Models/AppSettings.cs @@ -778,6 +778,13 @@ public bool? EnablePackageTelemetry /// Recommended to keep false /// public bool? ExiftoolSkipDownloadOnStartup { get; set; } = false; + + /// + /// Skip download Ffmpeg on startup + /// Recommended to keep false + /// + public bool? FfmpegSkipDownloadOnStartup { get; set; } = false; + public OpenTelemetrySettings? OpenTelemetry { get; set; } = new(); diff --git a/starsky/starsky.foundation.video/Class1.cs b/starsky/starsky.foundation.video/Class1.cs new file mode 100644 index 0000000000..aa05872559 --- /dev/null +++ b/starsky/starsky.foundation.video/Class1.cs @@ -0,0 +1,5 @@ +namespace starsky.foundation.video; + +public class Class1 +{ +} diff --git a/starsky/starsky.foundation.video/GetDependencies/FFMpegDownload.cs b/starsky/starsky.foundation.video/GetDependencies/FFMpegDownload.cs new file mode 100644 index 0000000000..33f86b32ae --- /dev/null +++ b/starsky/starsky.foundation.video/GetDependencies/FFMpegDownload.cs @@ -0,0 +1,59 @@ +using starsky.foundation.http.Interfaces; +using starsky.foundation.platform.Interfaces; +using starsky.foundation.platform.Models; +using starsky.foundation.storage.Interfaces; +using starsky.foundation.storage.Storage; +using starsky.foundation.video.GetDependencies.Interfaces; + +namespace starsky.foundation.video.GetDependencies; + +public class FfMpegDownload : IFfMpegDownload +{ + private const string FFMpegDownloadBasePath = + "https://qdraw.nl/special/mirror/ffmpeg/"; // with slash at the end + + private readonly AppSettings _appSettings; + private readonly IStorage _hostFileSystemStorage; + private readonly IHttpClientHelper _httpClientHelper; + private readonly IWebLogger _logger; + + public FfMpegDownload(IHttpClientHelper httpClientHelper, AppSettings appSettings, + IWebLogger logger) + { + _httpClientHelper = httpClientHelper; + _appSettings = appSettings; + _hostFileSystemStorage = new StorageHostFullPathFilesystem(logger); + _logger = logger; + } + + public async Task DownloadFFMpeg(OperatingSystem) + { + var currentPlatform = OperatingSystemHelper.GetPlatform(); + + + if ( _appSettings.ExiftoolSkipDownloadOnStartup == true || _appSettings is + { AddSwaggerExport: true, AddSwaggerExportExitAfter: true } ) + { + var name = _appSettings.FfmpegSkipDownloadOnStartup == true + ? "FFMpegSkipDownloadOnStartup" + : "AddSwaggerExport and AddSwaggerExportExitAfter"; + _logger.LogInformation($"[DownloadFFMpeg] Skipped due true of {name} setting"); + return false; + } + + CreateDirectoryDependenciesFolderIfNotExists(); + } + + private void CreateDirectoryDependenciesFolderIfNotExists() + { + if ( _hostFileSystemStorage.ExistFolder( + _appSettings.DependenciesFolder) ) + { + return; + } + + _logger.LogInformation("[FfMpegDownload] Create Directory: " + + _appSettings.DependenciesFolder); + _hostFileSystemStorage.CreateDirectory(_appSettings.DependenciesFolder); + } +} diff --git a/starsky/starsky.foundation.video/GetDependencies/GetVersionString.cs b/starsky/starsky.foundation.video/GetDependencies/GetVersionString.cs new file mode 100644 index 0000000000..304489f11a --- /dev/null +++ b/starsky/starsky.foundation.video/GetDependencies/GetVersionString.cs @@ -0,0 +1,53 @@ +using starsky.foundation.http.Interfaces; + +namespace starsky.foundation.video.GetDependencies; + +public class GetVersionString +{ + private readonly IHttpClientHelper _httpClientHelper; + + public GetVersionString(IHttpClientHelper httpClientHelper) + { + _httpClientHelper = httpClientHelper; + } + + /// + /// https://www.osxexperts.net/ + /// + private const string OsxArm64 = "https://www.osxexperts.net/ffmpeg71arm.zip"; + + private const string FfBinariesApi = "https://ffbinaries.com/api/v1/version/6.1"; + + public string GetVersion( + OperationSystemPlatforms.OSPlatformAndArchitecture osPlatformAndArchitecture) + { + switch ( osPlatformAndArchitecture ) + { + case OperationSystemPlatforms.OSPlatformAndArchitecture.WinX86: + break; + case OperationSystemPlatforms.OSPlatformAndArchitecture.WinX64: + break; + case OperationSystemPlatforms.OSPlatformAndArchitecture.WinArm64: + break; + case OperationSystemPlatforms.OSPlatformAndArchitecture.LinuxX64: + break; + case OperationSystemPlatforms.OSPlatformAndArchitecture.LinuxArm: + break; + case OperationSystemPlatforms.OSPlatformAndArchitecture.LinuxArm64: + break; + case OperationSystemPlatforms.OSPlatformAndArchitecture.OsxX64: + break; + case OperationSystemPlatforms.OSPlatformAndArchitecture.OsxArm64: + return OsxArm64; + default: + throw new ArgumentOutOfRangeException(nameof(osPlatformAndArchitecture), + osPlatformAndArchitecture, null); + } + } + + private void GetApi() + { + await _httpClientHelper.ReadString(FfBinariesApi); + + } +} diff --git a/starsky/starsky.foundation.video/GetDependencies/Interfaces/IFFMpegDownload.cs b/starsky/starsky.foundation.video/GetDependencies/Interfaces/IFFMpegDownload.cs new file mode 100644 index 0000000000..12dc234180 --- /dev/null +++ b/starsky/starsky.foundation.video/GetDependencies/Interfaces/IFFMpegDownload.cs @@ -0,0 +1,6 @@ +namespace starsky.foundation.video.GetDependencies.Interfaces; + +public interface IFfMpegDownload +{ + +} diff --git a/starsky/starsky.foundation.video/GetDependencies/OperationSystemPlatforms.cs b/starsky/starsky.foundation.video/GetDependencies/OperationSystemPlatforms.cs new file mode 100644 index 0000000000..345bc32294 --- /dev/null +++ b/starsky/starsky.foundation.video/GetDependencies/OperationSystemPlatforms.cs @@ -0,0 +1,27 @@ +using System.ComponentModel.DataAnnotations; + +namespace starsky.foundation.video.GetDependencies; + +public class OperationSystemPlatforms +{ + public enum OSPlatformAndArchitecture + { + Unknown, + [Display(Name = "win-x86")] + WinX86, + [Display(Name = "win-x64")] + WinX64, + [Display(Name = "win-arm64")] + WinArm64, + [Display(Name = "linux-x64")] + LinuxX64, + [Display(Name = "linux-arm")] + LinuxArm, + [Display(Name = "linux-arm64")] + LinuxArm64, + [Display(Name = "osx-x64")] + OsxX64, + [Display(Name = "osx-arm64")] + OsxArm64 + } +} diff --git a/starsky/starsky.foundation.video/starsky.foundation.video.csproj b/starsky/starsky.foundation.video/starsky.foundation.video.csproj new file mode 100644 index 0000000000..1179d60406 --- /dev/null +++ b/starsky/starsky.foundation.video/starsky.foundation.video.csproj @@ -0,0 +1,13 @@ + + + + net8.0 + enable + enable + + + + + + + diff --git a/starsky/starsky.sln b/starsky/starsky.sln index 729c69552f..98c73e9e37 100644 --- a/starsky/starsky.sln +++ b/starsky/starsky.sln @@ -166,6 +166,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "starsky.feature.settings", EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "starsky.feature.desktop", "starsky.feature.desktop\starsky.feature.desktop.csproj", "{B88C2815-D154-4C6D-AE37-2E150AEBF73D}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "starsky.foundation.video", "starsky.foundation.video\starsky.foundation.video.csproj", "{8E902599-146E-4C70-994E-EE24AF04D051}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -368,6 +370,10 @@ Global {B88C2815-D154-4C6D-AE37-2E150AEBF73D}.Debug|Any CPU.Build.0 = Debug|Any CPU {B88C2815-D154-4C6D-AE37-2E150AEBF73D}.Release|Any CPU.ActiveCfg = Release|Any CPU {B88C2815-D154-4C6D-AE37-2E150AEBF73D}.Release|Any CPU.Build.0 = Release|Any CPU + {8E902599-146E-4C70-994E-EE24AF04D051}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8E902599-146E-4C70-994E-EE24AF04D051}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8E902599-146E-4C70-994E-EE24AF04D051}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8E902599-146E-4C70-994E-EE24AF04D051}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -428,5 +434,6 @@ Global {A62C129C-5D0C-4A0A-B5AA-261E041FF55D} = {4B9276C3-651E-48D3-B3A7-3F4D74F3D01A} {F2C4C9DE-22A1-4B34-AC1D-0F08353E0742} = {4B9276C3-651E-48D3-B3A7-3F4D74F3D01A} {B88C2815-D154-4C6D-AE37-2E150AEBF73D} = {4B9276C3-651E-48D3-B3A7-3F4D74F3D01A} + {8E902599-146E-4C70-994E-EE24AF04D051} = {1C1EB4A5-08D0-4014-AE1F-962642A4E5D3} EndGlobalSection EndGlobal From 8700012e11881256a838586fccb446ff4e2f0212 Mon Sep 17 00:00:00 2001 From: Dion Date: Sat, 16 Nov 2024 22:25:00 +0100 Subject: [PATCH 02/73] WIP --- starsky-tools/build-tools/ffmpeg-download1.sh | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/starsky-tools/build-tools/ffmpeg-download1.sh b/starsky-tools/build-tools/ffmpeg-download1.sh index 8208dbe973..6900aa0255 100644 --- a/starsky-tools/build-tools/ffmpeg-download1.sh +++ b/starsky-tools/build-tools/ffmpeg-download1.sh @@ -1,7 +1,9 @@ #!/bin/bash +FFBINARIES_API="https://ffbinaries.com/api/v1/version/6.1" +OSX_ARM64="https://www.osxexperts.net/ffmpeg71arm.zip" # Fetch the JSON data -json=$(curl -s https://ffbinaries.com/api/v1/version/6.1) +json=$(curl -s $FFBINARIES_API) # Create a directory to store the binaries mkdir -p ffmpeg_binaries @@ -14,23 +16,22 @@ urls=$(echo "$json" | grep -o '"ffmpeg":"[^"]*"' | sed 's/"ffmpeg":"//;s/"//') for url in $urls; do # Extract architecture and URL -# architecture=$(echo "$line" | grep -oP '"[^"]+(?=":)') architecture=$(echo "$url" | sed -n 's/.*-\([a-z0-9-]*-[a-z0-9]*\)\.zip/\1/p') + filename=$(basename "$url") # Download the binary - echo "Downloading $url for $architecture ..." + echo "Downloading $url for $architecture $filename..." curl -L -O "$url" # Add to output JSON - output_json="${output_json}{\"architecture\":\"$architecture\",\"url\":\"$url\"}," + output_json="${output_json}{\"architecture\":\"$architecture\",\"url\":\"$filename\"}," done # Add osx-arm64 explicitly custom_arch="osx-arm64" -custom_url="https://www.osxexperts.net/ffmpeg71arm.zip" echo "Adding custom architecture $custom_arch with URL $custom_url..." -curl -L -O "$custom_url" +curl -L -O "$FFBINARIES_API" output_json="${output_json}{\"architecture\":\"$custom_arch\",\"url\":\"$custom_url\"}," # Finalize JSON From 81ed601bd5a191d5e89c57c60617511f06fc2eb3 Mon Sep 17 00:00:00 2001 From: Dion Date: Sun, 17 Nov 2024 18:16:28 +0100 Subject: [PATCH 03/73] add downloader --- starsky-tools/build-tools/.gitignore | 4 +- starsky-tools/build-tools/ffmpeg-download.sh | 97 ++++++++++++++++--- starsky-tools/build-tools/ffmpeg-download1.sh | 44 --------- starsky-tools/build-tools/ffmpeg/index.json | 34 +++++++ 4 files changed, 120 insertions(+), 59 deletions(-) delete mode 100644 starsky-tools/build-tools/ffmpeg-download1.sh create mode 100644 starsky-tools/build-tools/ffmpeg/index.json diff --git a/starsky-tools/build-tools/.gitignore b/starsky-tools/build-tools/.gitignore index 5689d498c0..5c6e5a9bca 100644 --- a/starsky-tools/build-tools/.gitignore +++ b/starsky-tools/build-tools/.gitignore @@ -1,2 +1,4 @@ create-docusaurus-tmp-folder/** -ffmpeg_binaries/** + +ffmpeg/*.zip +!ffmpeg/index.json diff --git a/starsky-tools/build-tools/ffmpeg-download.sh b/starsky-tools/build-tools/ffmpeg-download.sh index bdee9bc68e..ed8a219e37 100644 --- a/starsky-tools/build-tools/ffmpeg-download.sh +++ b/starsky-tools/build-tools/ffmpeg-download.sh @@ -1,24 +1,93 @@ #!/bin/bash - FFBINARIES_API="https://ffbinaries.com/api/v1/version/6.1" -OSX_ARM64="https://www.osxexperts.net/ffmpeg71arm.zip" +OSX_ARM64_URL="https://www.osxexperts.net/ffmpeg71arm.zip" +OSX_ARM64_NAME="osx-arm64" +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" +BINARY_FOLDERNAME="ffmpeg" +INDEX_FILE="index.json" -# Fetch the JSON data -json=$(curl -s $FFBINARIES_API) +LAST_CHAR_SCRIPT_DIR=${SCRIPT_DIR:length-1:1} +[[ $LAST_CHAR_SCRIPT_DIR != "/" ]] && SCRIPT_DIR="$SCRIPT_DIR/"; : + +LAST_CHAR_BINARY_FOLDERNAME=${BINARY_FOLDERNAME:length-1:1} +[[ $LAST_CHAR_BINARY_FOLDERNAME != "/" ]] && BINARY_FOLDERNAME="$BINARY_FOLDERNAME/"; : -# Extract URLs for ffmpeg binaries -urls=$(echo "$json" | grep -o '"ffmpeg":"[^"]*"' | sed 's/"ffmpeg":"//;s/"//') +INDEX_FILE_PATH=$SCRIPT_DIR$BINARY_FOLDERNAME$INDEX_FILE + +echo "Cleaning up previous binaries... $SCRIPT_DIR$BINARY_FOLDERNAME" +rm -rf $SCRIPT_DIR$BINARY_FOLDERNAME + +# Fetch the JSON data +FFBINARIES_JSON=$(curl -s $FFBINARIES_API) # Create a directory to store the binaries -mkdir -p ffmpeg_binaries -cd ffmpeg_binaries +mkdir -p $SCRIPT_DIR$BINARY_FOLDERNAME +cd $SCRIPT_DIR$BINARY_FOLDERNAME + +# Initialize JSON output +OUTPUT_JSON="{\"binaries\":[" + +ARCHITECTURES=$(echo "$FFBINARIES_JSON" | grep -o '"[^"]\+":{"ffmpeg"' | sed 's/"\([^"]\+\)".*/\1/') +BINARY_URLS=$(echo "$FFBINARIES_JSON" | grep -o '"ffmpeg":"[^"]*"' | sed 's/"ffmpeg":"//;s/"//') + +MAP_ARCHITECTURE_NAME () { + if [ "$1" == "windows-64" ]; then + echo "windows-x64" + elif [ "$1" == "linux-64" ]; then + echo "linux-x64" + elif [ "$1" == "linux-armhf" ]; then + echo "linux-arm" + elif [ "$1" == "osx-64" ]; then + echo "osx-x64" + else + echo $1 + fi +} + + + +while read -r ARCHITECTURE && read -r URL <&3; do -# Download each ffmpeg binary -for url in $urls; do - echo "Downloading $url" - curl -L -O "$url" -done + # Extract architecture and URL + FILENAME=$(basename "$URL") + CURRENT_ARCHITECTURE=$(echo "$ARCHITECTURE" | sed -n 's/.*"\([^"]*\)":{.*ffmpeg.*/\1/p') -curl -O $OSX_ARM64 + # skip if linux-armel or linux-32 + if [ "$CURRENT_ARCHITECTURE" == "linux-32" ] || [ "$CURRENT_ARCHITECTURE" == "linux-armel" ]; then + continue + fi + + + CURRENT_ARCHITECTURE="$(MAP_ARCHITECTURE_NAME $CURRENT_ARCHITECTURE)" + + # Download the binary + echo "Downloading $URL for $CURRENT_ARCHITECTURE $FILENAME..." + curl -L -O "$URL" + + FILE_HASH=$(openssl dgst -sha512 "$FILENAME" | awk '{print $2}') + + # Add to output JSON + OUTPUT_JSON="${OUTPUT_JSON}{\"architecture\":\"$CURRENT_ARCHITECTURE\",\"url\":\"$FILENAME\",\"sha512\":\"$FILE_HASH\"}," +done < <(echo "$ARCHITECTURES") 3< <(echo "$BINARY_URLS") + +# Add osx-arm64 explicitly +echo "Adding custom architecture $OSX_ARM64_NAME with URL $OSX_ARM64_URL..." +curl -L -O "$OSX_ARM64_URL" + +OSX_ARM64_FILENAME=$(basename "$OSX_ARM64_URL") +OSX_ARM64_HASH=$(openssl dgst -sha512 "$OSX_ARM64_FILENAME" | awk '{print $2}') +OUTPUT_JSON="${OUTPUT_JSON}{\"architecture\":\"$OSX_ARM64_NAME\",\"url\":\"$OSX_ARM64_FILENAME\",\"sha512\":\"$OSX_ARM64_HASH\"}," + +# Finalize JSON +OUTPUT_JSON="${OUTPUT_JSON%,}]}" # Remove trailing comma and close the JSON array + +# Write JSON to file +echo "$OUTPUT_JSON" > $INDEX_FILE_PATH echo "All ffmpeg binaries downloaded successfully." + +node -e "console.log(JSON.stringify(JSON.parse(require('fs') \ + .readFileSync(process.argv[1])), null, 4));" $INDEX_FILE_PATH > $INDEX_FILE_PATH.bak +mv $INDEX_FILE_PATH.bak $INDEX_FILE_PATH + +echo "URLs with architectures saved to $INDEX_FILE_PATH" diff --git a/starsky-tools/build-tools/ffmpeg-download1.sh b/starsky-tools/build-tools/ffmpeg-download1.sh deleted file mode 100644 index 6900aa0255..0000000000 --- a/starsky-tools/build-tools/ffmpeg-download1.sh +++ /dev/null @@ -1,44 +0,0 @@ -#!/bin/bash -FFBINARIES_API="https://ffbinaries.com/api/v1/version/6.1" -OSX_ARM64="https://www.osxexperts.net/ffmpeg71arm.zip" - -# Fetch the JSON data -json=$(curl -s $FFBINARIES_API) - -# Create a directory to store the binaries -mkdir -p ffmpeg_binaries -cd ffmpeg_binaries - -# Initialize JSON output -output_json="{\"binaries\":[" - -urls=$(echo "$json" | grep -o '"ffmpeg":"[^"]*"' | sed 's/"ffmpeg":"//;s/"//') - -for url in $urls; do - # Extract architecture and URL - architecture=$(echo "$url" | sed -n 's/.*-\([a-z0-9-]*-[a-z0-9]*\)\.zip/\1/p') - filename=$(basename "$url") - - # Download the binary - echo "Downloading $url for $architecture $filename..." - curl -L -O "$url" - - # Add to output JSON - output_json="${output_json}{\"architecture\":\"$architecture\",\"url\":\"$filename\"}," -done - - -# Add osx-arm64 explicitly -custom_arch="osx-arm64" -echo "Adding custom architecture $custom_arch with URL $custom_url..." -curl -L -O "$FFBINARIES_API" -output_json="${output_json}{\"architecture\":\"$custom_arch\",\"url\":\"$custom_url\"}," - -# Finalize JSON -output_json="${output_json%,}]}" # Remove trailing comma and close the JSON array - -# Write JSON to file -echo "$output_json" > ffmpeg_urls.json - -echo "All ffmpeg binaries downloaded successfully." -echo "URLs with architectures saved to ffmpeg_binaries/ffmpeg_urls.json" diff --git a/starsky-tools/build-tools/ffmpeg/index.json b/starsky-tools/build-tools/ffmpeg/index.json new file mode 100644 index 0000000000..c6438ac29d --- /dev/null +++ b/starsky-tools/build-tools/ffmpeg/index.json @@ -0,0 +1,34 @@ +{ + "binaries": [ + { + "architecture": "windows-x64", + "url": "ffmpeg-6.1-win-64.zip", + "sha512": "5702ef34f69c3d8113e3c7133b19c63c1b7fe2d95c6b58e306cea69ab1fbbbf4f223454081fe88e47e02caac2c1370ff22fde749b9cb3f86493b37d3e245737b" + }, + { + "architecture": "linux-x64", + "url": "ffmpeg-6.1-linux-64.zip", + "sha512": "f5c54c9eb9aa249fa3a51a33e90f028dd00b87de8f3068a1619dd916d9e7e33e2ba05ccade5c26227223094c5446c5a20a70a2b2d8acd882685fa0b13fa90324" + }, + { + "architecture": "linux-arm", + "url": "ffmpeg-6.1-linux-armhf-32.zip", + "sha512": "e28e97b6fce3be34f2fd133e65e33fcf5b83cf3b11626cdff7576e2e19dbbaf31465f9f434cf8a6e243226f9d77db777799974f6750251c7b7132a42ada53e15" + }, + { + "architecture": "linux-arm64", + "url": "ffmpeg-6.1-linux-arm-64.zip", + "sha512": "ac8522caae603a3e4bd16c2a7a8fab0e0dbf323d60cab3f87796d50ab56537ae3b0d110c0c02658b60a16106c8db3240ebc52a7d829af7067cd2ee3634822b81" + }, + { + "architecture": "osx-x64", + "url": "ffmpeg-6.1-macos-64.zip", + "sha512": "b4b0a48b5f7a41ee93dafd05ffe86e8083b2ead51de96daa31df31d5bff79295468f32f95dd8b20f12e063d26c7b5843214879b0b672b2c032f53bdc3229d9e1" + }, + { + "architecture": "osx-arm64", + "url": "ffmpeg71arm.zip", + "sha512": "5968c8eb48f6fcfb67cfcc77edf9656c46cff058227d997101c242ed0f1d4a69a814a79a1999897dbde2454b3f2b811328c063a48ae30890a8fdeffabf1ce620" + } + ] +} From 69028dc121586bb7aed14f40c67a352a5823be1b Mon Sep 17 00:00:00 2001 From: Dion Date: Sun, 17 Nov 2024 18:42:02 +0100 Subject: [PATCH 04/73] #1833 download scripts --- starsky-tools/build-tools/.gitignore | 5 +-- .../build-tools/exiftool-download.sh | 33 +++++++++++++++++++ starsky-tools/build-tools/ffmpeg-download.sh | 7 ++-- .../build-tools/mirror/exiftool/checksums.txt | 12 +++++++ .../{ => mirror}/ffmpeg/index.json | 0 5 files changed, 51 insertions(+), 6 deletions(-) create mode 100644 starsky-tools/build-tools/exiftool-download.sh create mode 100644 starsky-tools/build-tools/mirror/exiftool/checksums.txt rename starsky-tools/build-tools/{ => mirror}/ffmpeg/index.json (100%) diff --git a/starsky-tools/build-tools/.gitignore b/starsky-tools/build-tools/.gitignore index 5c6e5a9bca..98549e4592 100644 --- a/starsky-tools/build-tools/.gitignore +++ b/starsky-tools/build-tools/.gitignore @@ -1,4 +1,5 @@ create-docusaurus-tmp-folder/** -ffmpeg/*.zip -!ffmpeg/index.json +mirror/ffmpeg/*.zip +mirror/exiftool/*.zip +mirror/exiftool/*.tar.gz diff --git a/starsky-tools/build-tools/exiftool-download.sh b/starsky-tools/build-tools/exiftool-download.sh new file mode 100644 index 0000000000..7589f16651 --- /dev/null +++ b/starsky-tools/build-tools/exiftool-download.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +EXIFTOOL_DOMAIN="https://exiftool.org" +EXIFTOOL_CHECKSUMS_API=$EXIFTOOL_DOMAIN"/checksums.txt" +BINARY_FOLDERNAME="mirror/exiftool" +INDEX_FILE="checksums.txt" + +LAST_CHAR_EXIFTOOL_DOMAIN=${EXIFTOOL_DOMAIN:length-1:1} +[[ $LAST_CHAR_EXIFTOOL_DOMAIN != "/" ]] && EXIFTOOL_DOMAIN="$EXIFTOOL_DOMAIN/"; : +USER_AGENT="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3" + +EXIFTOOL_JSON=$(curl -s $EXIFTOOL_CHECKSUMS_API) + +# Extract the latest version +LATEST_EXIFTOOL_VERSION=$(echo "$EXIFTOOL_JSON" | grep -o '\b[0-9]\+\.[0-9]\+\b' | head -n 1) + + +# Extract the Linux tar.gz filename using the dynamically fetched version +LINUX_EXIFTOOL=$(echo "$EXIFTOOL_JSON" | grep -o "Image-ExifTool-${LATEST_EXIFTOOL_VERSION}.tar.gz" | head -n 1) +WINDOWS_EXIFTOOL=$(echo "$EXIFTOOL_JSON" | grep -o "exiftool-${LATEST_EXIFTOOL_VERSION}_64.zip" | head -n 1) + + +rm -rf $SCRIPT_DIR$BINARY_FOLDERNAME +mkdir -p $SCRIPT_DIR$BINARY_FOLDERNAME +cd $SCRIPT_DIR$BINARY_FOLDERNAME + +curl -L -A "$USER_AGENT" -O "$EXIFTOOL_DOMAIN$LINUX_EXIFTOOL" +curl -L -A "$USER_AGENT" -O "$EXIFTOOL_DOMAIN$WINDOWS_EXIFTOOL" +curl -L -A "$USER_AGENT" -O "$EXIFTOOL_CHECKSUMS_API" + + +echo "Linux tar.gz filename: $LINUX_EXIFTOOL" +echo "Windows zip filename: $WINDOWS_EXIFTOOL" \ No newline at end of file diff --git a/starsky-tools/build-tools/ffmpeg-download.sh b/starsky-tools/build-tools/ffmpeg-download.sh index ed8a219e37..68d2440156 100644 --- a/starsky-tools/build-tools/ffmpeg-download.sh +++ b/starsky-tools/build-tools/ffmpeg-download.sh @@ -3,7 +3,7 @@ FFBINARIES_API="https://ffbinaries.com/api/v1/version/6.1" OSX_ARM64_URL="https://www.osxexperts.net/ffmpeg71arm.zip" OSX_ARM64_NAME="osx-arm64" SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" -BINARY_FOLDERNAME="ffmpeg" +BINARY_FOLDERNAME="mirror/ffmpeg" INDEX_FILE="index.json" LAST_CHAR_SCRIPT_DIR=${SCRIPT_DIR:length-1:1} @@ -14,13 +14,13 @@ LAST_CHAR_BINARY_FOLDERNAME=${BINARY_FOLDERNAME:length-1:1} INDEX_FILE_PATH=$SCRIPT_DIR$BINARY_FOLDERNAME$INDEX_FILE -echo "Cleaning up previous binaries... $SCRIPT_DIR$BINARY_FOLDERNAME" -rm -rf $SCRIPT_DIR$BINARY_FOLDERNAME # Fetch the JSON data FFBINARIES_JSON=$(curl -s $FFBINARIES_API) # Create a directory to store the binaries +echo "Cleaning up previous binaries... $SCRIPT_DIR$BINARY_FOLDERNAME" +rm -rf $SCRIPT_DIR$BINARY_FOLDERNAME mkdir -p $SCRIPT_DIR$BINARY_FOLDERNAME cd $SCRIPT_DIR$BINARY_FOLDERNAME @@ -57,7 +57,6 @@ while read -r ARCHITECTURE && read -r URL <&3; do continue fi - CURRENT_ARCHITECTURE="$(MAP_ARCHITECTURE_NAME $CURRENT_ARCHITECTURE)" # Download the binary diff --git a/starsky-tools/build-tools/mirror/exiftool/checksums.txt b/starsky-tools/build-tools/mirror/exiftool/checksums.txt new file mode 100644 index 0000000000..51fecaaae1 --- /dev/null +++ b/starsky-tools/build-tools/mirror/exiftool/checksums.txt @@ -0,0 +1,12 @@ +SHA256(Image-ExifTool-13.03.tar.gz)= 0912e1315318889574f355e5832340632c556a14d30711e94d801085ad0a8e4f +SHA256(exiftool-13.03_32.zip)= 81bcca6523a2b129f914f0aed6c3f26538d412922c148ed89ee9973d99578633 +SHA256(exiftool-13.03_64.zip)= a867b062e544e712a677378e4f05710d8a22cc20db46d1d331a1470bb6d7026d +SHA256(ExifTool-13.03.pkg)= 5f3fdd5b6db5c49a0b41e284d1a60e596052cd4a2806da26f86eee560a316b3e +SHA1(Image-ExifTool-13.03.tar.gz)= 29e219b06421e9716e76084dd2a607a952dd3530 +SHA1(exiftool-13.03_32.zip)= 7a16cf2cab574ecfb6467144f1c34ab06fc387be +SHA1(exiftool-13.03_64.zip)= b91ffb49bd2957e944feaef3104ff66e6a7fb6b3 +SHA1(ExifTool-13.03.pkg)= 7d7b81c1d36586c30462056c80550eb507cca367 +MD5 (Image-ExifTool-13.03.tar.gz) = b49fc81a05b0024a6063491195e3cf09 +MD5 (exiftool-13.03_32.zip) = 0f07ff79a3f383cab1b1cfefd72ca5c9 +MD5 (exiftool-13.03_64.zip) = 1eeddb0b206c47e1a5d09d9ae8073737 +MD5 (ExifTool-13.03.pkg) = e931219c986b4bf7af75e3d9ca440d24 diff --git a/starsky-tools/build-tools/ffmpeg/index.json b/starsky-tools/build-tools/mirror/ffmpeg/index.json similarity index 100% rename from starsky-tools/build-tools/ffmpeg/index.json rename to starsky-tools/build-tools/mirror/ffmpeg/index.json From ae4ef7af82610b26885637474207b4963363835c Mon Sep 17 00:00:00 2001 From: Dion Date: Sun, 17 Nov 2024 20:31:39 +0100 Subject: [PATCH 05/73] #1833 rename && add scripts --- starsky-tools/build-tools/.gitignore | 1 + ...download.sh => download-mirror-exiftool.sh} | 0 ...g-download.sh => download-mirror-ffmpeg.sh} | 0 .../build-tools/download-mirror-geonames.sh | 18 ++++++++++++++++++ 4 files changed, 19 insertions(+) rename starsky-tools/build-tools/{exiftool-download.sh => download-mirror-exiftool.sh} (100%) rename starsky-tools/build-tools/{ffmpeg-download.sh => download-mirror-ffmpeg.sh} (100%) create mode 100644 starsky-tools/build-tools/download-mirror-geonames.sh diff --git a/starsky-tools/build-tools/.gitignore b/starsky-tools/build-tools/.gitignore index 98549e4592..26d0b077da 100644 --- a/starsky-tools/build-tools/.gitignore +++ b/starsky-tools/build-tools/.gitignore @@ -3,3 +3,4 @@ create-docusaurus-tmp-folder/** mirror/ffmpeg/*.zip mirror/exiftool/*.zip mirror/exiftool/*.tar.gz +mirror/geonames/** diff --git a/starsky-tools/build-tools/exiftool-download.sh b/starsky-tools/build-tools/download-mirror-exiftool.sh similarity index 100% rename from starsky-tools/build-tools/exiftool-download.sh rename to starsky-tools/build-tools/download-mirror-exiftool.sh diff --git a/starsky-tools/build-tools/ffmpeg-download.sh b/starsky-tools/build-tools/download-mirror-ffmpeg.sh similarity index 100% rename from starsky-tools/build-tools/ffmpeg-download.sh rename to starsky-tools/build-tools/download-mirror-ffmpeg.sh diff --git a/starsky-tools/build-tools/download-mirror-geonames.sh b/starsky-tools/build-tools/download-mirror-geonames.sh new file mode 100644 index 0000000000..12748b6749 --- /dev/null +++ b/starsky-tools/build-tools/download-mirror-geonames.sh @@ -0,0 +1,18 @@ +#!/bin/bash +GEONAMES_DUMP="https://download.geonames.org/export/dump/" +BINARY_FOLDERNAME="mirror/exiftool" +ADMIN1_CODES="admin1CodesASCII.txt" +CITIES1000="cities1000.zip" + +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" + +LAST_CHAR_GEONAMES_DUMP=${GEONAMES_DUMP:length-1:1} +[[ $LAST_CHAR_GEONAMES_DUMP != "/" ]] && GEONAMES_DUMP="$GEONAMES_DUMP/"; : + +rm -rf $SCRIPT_DIR$BINARY_FOLDERNAME +mkdir -p $SCRIPT_DIR$BINARY_FOLDERNAME +cd $SCRIPT_DIR$BINARY_FOLDERNAME + + +curl -L -O "$GEONAMES_DUMP$ADMIN1_CODES" +curl -L -O "$GEONAMES_DUMP$CITIES1000" \ No newline at end of file From be49b905e3328d110a412b4cec28bb2798ca7de1 Mon Sep 17 00:00:00 2001 From: Dion Date: Sun, 17 Nov 2024 21:59:49 +0100 Subject: [PATCH 06/73] #1833 compatiblity ffmpeg --- .../build-tools/download-mirror-ffmpeg.sh | 30 +++++++++++++++++-- starsky-tools/build-tools/download-mirror.sh | 21 +++++++++++++ 2 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 starsky-tools/build-tools/download-mirror.sh diff --git a/starsky-tools/build-tools/download-mirror-ffmpeg.sh b/starsky-tools/build-tools/download-mirror-ffmpeg.sh index 68d2440156..9077e69fcb 100644 --- a/starsky-tools/build-tools/download-mirror-ffmpeg.sh +++ b/starsky-tools/build-tools/download-mirror-ffmpeg.sh @@ -44,12 +44,34 @@ MAP_ARCHITECTURE_NAME () { fi } +populate_array_from_variable() { + local variable_content="$1" + local array_name="$2" + + while IFS= read -r line; do + eval "$array_name+=(\"\$line\")" + done < <(echo "$variable_content") +} + +# Initialize arrays +ARCHITECTURES_ARRAY=() +BINARY_URLS_ARRAY=() + +# Populate arrays using the function +populate_array_from_variable "$ARCHITECTURES" ARCHITECTURES_ARRAY +populate_array_from_variable "$BINARY_URLS" BINARY_URLS_ARRAY -while read -r ARCHITECTURE && read -r URL <&3; do +for i in "${!ARCHITECTURES_ARRAY[@]}"; do + + ARCHITECTURE="${ARCHITECTURES_ARRAY[$i]}" + URL="${BINARY_URLS_ARRAY[$i]}" # Extract architecture and URL FILENAME=$(basename "$URL") + NEW_VERSION="" + FILENAME_UPDATED=$(echo "$FILENAME" | sed -E "s/(-|\.)([0-9]+\.[0-9]+)(-|\.|$)/\1$NEW_VERSION\3/") + CURRENT_ARCHITECTURE=$(echo "$ARCHITECTURE" | sed -n 's/.*"\([^"]*\)":{.*ffmpeg.*/\1/p') # skip if linux-armel or linux-32 @@ -65,9 +87,11 @@ while read -r ARCHITECTURE && read -r URL <&3; do FILE_HASH=$(openssl dgst -sha512 "$FILENAME" | awk '{print $2}') + mv "$FILENAME" "$FILENAME_UPDATED" + # Add to output JSON - OUTPUT_JSON="${OUTPUT_JSON}{\"architecture\":\"$CURRENT_ARCHITECTURE\",\"url\":\"$FILENAME\",\"sha512\":\"$FILE_HASH\"}," -done < <(echo "$ARCHITECTURES") 3< <(echo "$BINARY_URLS") + OUTPUT_JSON="${OUTPUT_JSON}{\"architecture\":\"$CURRENT_ARCHITECTURE\",\"url\":\"$FILENAME_UPDATED\",\"sha512\":\"$FILE_HASH\"}," +done # Add osx-arm64 explicitly echo "Adding custom architecture $OSX_ARM64_NAME with URL $OSX_ARM64_URL..." diff --git a/starsky-tools/build-tools/download-mirror.sh b/starsky-tools/build-tools/download-mirror.sh new file mode 100644 index 0000000000..b2383e9631 --- /dev/null +++ b/starsky-tools/build-tools/download-mirror.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +GH_SCRIPT_DIR="https://raw.githubusercontent.com/qdraw/starsky/refs/heads/feature/202411_ffmpeg/starsky-tools/build-tools/" + +LAST_CHAR_GH_SCRIPT_DIR=${GH_SCRIPT_DIR:length-1:1} +[[ $LAST_CHAR_GH_SCRIPT_DIR != "/" ]] && GH_SCRIPT_DIR="$GH_SCRIPT_DIR/"; : + +SCRIPT_FILES=("download-mirror-exiftool.sh" "download-mirror-ffmpeg.sh" "download-mirror-geonames.sh") + +# Loop through the array +for SCRIPT_FILE in "${SCRIPT_FILES[@]}"; do + echo "Processing $item..." + # Example action: Check if the file exists + if [ -f "$SCRIPT_FILE" ]; then + echo "$SCRIPT_FILE exists." + else + echo "$SCRIPT_FILE does not exist." + curl -o "$SCRIPT_FILE" "$GH_SCRIPT_DIR$SCRIPT_FILE" + fi + bash $SCRIPT_FILE +done From 5a02fb3d431f5902e4ac62876d221c25692fd54b Mon Sep 17 00:00:00 2001 From: Dion Date: Sun, 17 Nov 2024 22:05:07 +0100 Subject: [PATCH 07/73] #1833 update script --- .../build-tools/download-mirror-ffmpeg.sh | 14 +++++++++++--- starsky-tools/build-tools/mirror/ffmpeg/index.json | 10 +++++----- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/starsky-tools/build-tools/download-mirror-ffmpeg.sh b/starsky-tools/build-tools/download-mirror-ffmpeg.sh index 9077e69fcb..eddea491f5 100644 --- a/starsky-tools/build-tools/download-mirror-ffmpeg.sh +++ b/starsky-tools/build-tools/download-mirror-ffmpeg.sh @@ -44,13 +44,21 @@ MAP_ARCHITECTURE_NAME () { fi } +# populate_array_from_variable() { +# local variable_content="$1" +# local array_name="$2" + +# while IFS= read -r line; do +# eval "$array_name+=(\"\$line\")" +# done < <(echo "$variable_content") +# } + populate_array_from_variable() { local variable_content="$1" local array_name="$2" - while IFS= read -r line; do - eval "$array_name+=(\"\$line\")" - done < <(echo "$variable_content") + IFS=$'\n' read -rd '' -a temp_array <<< "$variable_content" + eval "$array_name=(\"\${temp_array[@]}\")" } # Initialize arrays diff --git a/starsky-tools/build-tools/mirror/ffmpeg/index.json b/starsky-tools/build-tools/mirror/ffmpeg/index.json index c6438ac29d..7a0ac9b950 100644 --- a/starsky-tools/build-tools/mirror/ffmpeg/index.json +++ b/starsky-tools/build-tools/mirror/ffmpeg/index.json @@ -2,27 +2,27 @@ "binaries": [ { "architecture": "windows-x64", - "url": "ffmpeg-6.1-win-64.zip", + "url": "ffmpeg--win-64.zip", "sha512": "5702ef34f69c3d8113e3c7133b19c63c1b7fe2d95c6b58e306cea69ab1fbbbf4f223454081fe88e47e02caac2c1370ff22fde749b9cb3f86493b37d3e245737b" }, { "architecture": "linux-x64", - "url": "ffmpeg-6.1-linux-64.zip", + "url": "ffmpeg--linux-64.zip", "sha512": "f5c54c9eb9aa249fa3a51a33e90f028dd00b87de8f3068a1619dd916d9e7e33e2ba05ccade5c26227223094c5446c5a20a70a2b2d8acd882685fa0b13fa90324" }, { "architecture": "linux-arm", - "url": "ffmpeg-6.1-linux-armhf-32.zip", + "url": "ffmpeg--linux-armhf-32.zip", "sha512": "e28e97b6fce3be34f2fd133e65e33fcf5b83cf3b11626cdff7576e2e19dbbaf31465f9f434cf8a6e243226f9d77db777799974f6750251c7b7132a42ada53e15" }, { "architecture": "linux-arm64", - "url": "ffmpeg-6.1-linux-arm-64.zip", + "url": "ffmpeg--linux-arm-64.zip", "sha512": "ac8522caae603a3e4bd16c2a7a8fab0e0dbf323d60cab3f87796d50ab56537ae3b0d110c0c02658b60a16106c8db3240ebc52a7d829af7067cd2ee3634822b81" }, { "architecture": "osx-x64", - "url": "ffmpeg-6.1-macos-64.zip", + "url": "ffmpeg--macos-64.zip", "sha512": "b4b0a48b5f7a41ee93dafd05ffe86e8083b2ead51de96daa31df31d5bff79295468f32f95dd8b20f12e063d26c7b5843214879b0b672b2c032f53bdc3229d9e1" }, { From 3993b5e92e25a3624f349a719b3566a72736d4ad Mon Sep 17 00:00:00 2001 From: Dion Date: Sun, 17 Nov 2024 22:55:25 +0100 Subject: [PATCH 08/73] #1833 add checks to avoid wrong downloads --- .../build-tools/download-mirror-exiftool.sh | 32 +++++++++++++++-- .../build-tools/download-mirror-ffmpeg.sh | 29 ++++++++------- .../build-tools/download-mirror-geonames.sh | 36 +++++++++++++++++-- .../build-tools/mirror/ffmpeg/index.json | 10 +++--- 4 files changed, 84 insertions(+), 23 deletions(-) diff --git a/starsky-tools/build-tools/download-mirror-exiftool.sh b/starsky-tools/build-tools/download-mirror-exiftool.sh index 7589f16651..1b341cd3d5 100644 --- a/starsky-tools/build-tools/download-mirror-exiftool.sh +++ b/starsky-tools/build-tools/download-mirror-exiftool.sh @@ -9,16 +9,27 @@ LAST_CHAR_EXIFTOOL_DOMAIN=${EXIFTOOL_DOMAIN:length-1:1} [[ $LAST_CHAR_EXIFTOOL_DOMAIN != "/" ]] && EXIFTOOL_DOMAIN="$EXIFTOOL_DOMAIN/"; : USER_AGENT="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3" +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" +LAST_CHAR_SCRIPT_DIR=${SCRIPT_DIR:length-1:1} +[[ $LAST_CHAR_SCRIPT_DIR != "/" ]] && SCRIPT_DIR="$SCRIPT_DIR/"; : + +LAST_CHAR_SCRIPT_DIR=${SCRIPT_DIR:length-1:1} +[[ $LAST_CHAR_SCRIPT_DIR != "/" ]] && SCRIPT_DIR="$SCRIPT_DIR/"; : + +LAST_CHAR_BINARY_FOLDERNAME=${BINARY_FOLDERNAME:length-1:1} +[[ $LAST_CHAR_BINARY_FOLDERNAME != "/" ]] && BINARY_FOLDERNAME="$BINARY_FOLDERNAME/"; : + +# Fetch the JSON data EXIFTOOL_JSON=$(curl -s $EXIFTOOL_CHECKSUMS_API) # Extract the latest version LATEST_EXIFTOOL_VERSION=$(echo "$EXIFTOOL_JSON" | grep -o '\b[0-9]\+\.[0-9]\+\b' | head -n 1) - # Extract the Linux tar.gz filename using the dynamically fetched version LINUX_EXIFTOOL=$(echo "$EXIFTOOL_JSON" | grep -o "Image-ExifTool-${LATEST_EXIFTOOL_VERSION}.tar.gz" | head -n 1) WINDOWS_EXIFTOOL=$(echo "$EXIFTOOL_JSON" | grep -o "exiftool-${LATEST_EXIFTOOL_VERSION}_64.zip" | head -n 1) +CHECK_FILES=($LINUX_EXIFTOOL $WINDOWS_EXIFTOOL) rm -rf $SCRIPT_DIR$BINARY_FOLDERNAME mkdir -p $SCRIPT_DIR$BINARY_FOLDERNAME @@ -29,5 +40,20 @@ curl -L -A "$USER_AGENT" -O "$EXIFTOOL_DOMAIN$WINDOWS_EXIFTOOL" curl -L -A "$USER_AGENT" -O "$EXIFTOOL_CHECKSUMS_API" -echo "Linux tar.gz filename: $LINUX_EXIFTOOL" -echo "Windows zip filename: $WINDOWS_EXIFTOOL" \ No newline at end of file +if [ ${#CHECK_FILES[@]} -ne 2 ]; then + echo "⛌ FAIL CHECK_FILES does not contain exactly two items. Exiting..." + exit 1 +fi + +for CHECK_FILE in "${CHECK_FILES[@]}"; do + if [ -f "$SCRIPT_DIR$BINARY_FOLDERNAME$CHECK_FILE" ] && [ "$(stat -c%s "$SCRIPT_DIR$BINARY_FOLDERNAME$CHECK_FILE" 2>/dev/null || stat -f%z "$SCRIPT_DIR$BINARY_FOLDERNAME$CHECK_FILE")" -gt 6300000 ]; then + echo "✅ $CHECK_FILE exists and is larger than 7 MB." + elif [ -f "$SCRIPT_DIR$BINARY_FOLDERNAME$CHECK_FILE" ]; then + echo "⛌ FAIL -> $CHECK_FILE exists but is 7 MB or smaller." + exit 1 + else + echo "⛌ FAIL -> $CHECK_FILE does not exist." + echo " $SCRIPT_DIR$BINARY_FOLDERNAME$CHECK_FILE is missing." + exit 1 + fi +done \ No newline at end of file diff --git a/starsky-tools/build-tools/download-mirror-ffmpeg.sh b/starsky-tools/build-tools/download-mirror-ffmpeg.sh index eddea491f5..b2b737a604 100644 --- a/starsky-tools/build-tools/download-mirror-ffmpeg.sh +++ b/starsky-tools/build-tools/download-mirror-ffmpeg.sh @@ -5,6 +5,7 @@ OSX_ARM64_NAME="osx-arm64" SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" BINARY_FOLDERNAME="mirror/ffmpeg" INDEX_FILE="index.json" +CHECK_FILES=("ffmpeg-linux-64.zip" "ffmpeg-linux-arm-64.zip" "ffmpeg-linux-armhf-32.zip" "ffmpeg-macos-64.zip" "ffmpeg-win-64.zip" "ffmpeg71arm.zip") LAST_CHAR_SCRIPT_DIR=${SCRIPT_DIR:length-1:1} [[ $LAST_CHAR_SCRIPT_DIR != "/" ]] && SCRIPT_DIR="$SCRIPT_DIR/"; : @@ -44,15 +45,6 @@ MAP_ARCHITECTURE_NAME () { fi } -# populate_array_from_variable() { -# local variable_content="$1" -# local array_name="$2" - -# while IFS= read -r line; do -# eval "$array_name+=(\"\$line\")" -# done < <(echo "$variable_content") -# } - populate_array_from_variable() { local variable_content="$1" local array_name="$2" @@ -77,8 +69,7 @@ for i in "${!ARCHITECTURES_ARRAY[@]}"; do # Extract architecture and URL FILENAME=$(basename "$URL") - NEW_VERSION="" - FILENAME_UPDATED=$(echo "$FILENAME" | sed -E "s/(-|\.)([0-9]+\.[0-9]+)(-|\.|$)/\1$NEW_VERSION\3/") + FILENAME_UPDATED=$(echo "$FILENAME" | sed -E "s/[-.]([0-9]+\.[0-9]+)[-.]/-/") CURRENT_ARCHITECTURE=$(echo "$ARCHITECTURE" | sed -n 's/.*"\([^"]*\)":{.*ffmpeg.*/\1/p') @@ -90,7 +81,7 @@ for i in "${!ARCHITECTURES_ARRAY[@]}"; do CURRENT_ARCHITECTURE="$(MAP_ARCHITECTURE_NAME $CURRENT_ARCHITECTURE)" # Download the binary - echo "Downloading $URL for $CURRENT_ARCHITECTURE $FILENAME..." + echo "Downloading $URL for $CURRENT_ARCHITECTURE [$FILENAME] $FILENAME_UPDATED..." curl -L -O "$URL" FILE_HASH=$(openssl dgst -sha512 "$FILENAME" | awk '{print $2}') @@ -121,4 +112,18 @@ node -e "console.log(JSON.stringify(JSON.parse(require('fs') \ .readFileSync(process.argv[1])), null, 4));" $INDEX_FILE_PATH > $INDEX_FILE_PATH.bak mv $INDEX_FILE_PATH.bak $INDEX_FILE_PATH + +for CHECK_FILE in "${CHECK_FILES[@]}"; do + if [ -f "$SCRIPT_DIR$BINARY_FOLDERNAME$CHECK_FILE" ] && [ "$(stat -c%s "$SCRIPT_DIR$BINARY_FOLDERNAME$CHECK_FILE" 2>/dev/null || stat -f%z "$SCRIPT_DIR$BINARY_FOLDERNAME$CHECK_FILE")" -gt 17874368 ]; then + echo "✅ $CHECK_FILE exists and is larger than 17 MB." + elif [ -f "$SCRIPT_DIR$BINARY_FOLDERNAME$CHECK_FILE" ]; then + echo "⛌ FAIL -> $CHECK_FILE exists but is 17 MB or smaller." + exit 1 + else + echo "⛌ FAIL -> $CHECK_FILE does not exist." + exit 1 + fi +done + + echo "URLs with architectures saved to $INDEX_FILE_PATH" diff --git a/starsky-tools/build-tools/download-mirror-geonames.sh b/starsky-tools/build-tools/download-mirror-geonames.sh index 12748b6749..31bd336f17 100644 --- a/starsky-tools/build-tools/download-mirror-geonames.sh +++ b/starsky-tools/build-tools/download-mirror-geonames.sh @@ -1,18 +1,48 @@ #!/bin/bash GEONAMES_DUMP="https://download.geonames.org/export/dump/" -BINARY_FOLDERNAME="mirror/exiftool" +BINARY_FOLDERNAME="mirror/geonames" ADMIN1_CODES="admin1CodesASCII.txt" CITIES1000="cities1000.zip" +CHECK_FILES=($ADMIN1_CODES $CITIES1000) + SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" +LAST_CHAR_SCRIPT_DIR=${SCRIPT_DIR:length-1:1} +[[ $LAST_CHAR_SCRIPT_DIR != "/" ]] && SCRIPT_DIR="$SCRIPT_DIR/"; : LAST_CHAR_GEONAMES_DUMP=${GEONAMES_DUMP:length-1:1} [[ $LAST_CHAR_GEONAMES_DUMP != "/" ]] && GEONAMES_DUMP="$GEONAMES_DUMP/"; : +LAST_CHAR_BINARY_FOLDERNAME=${BINARY_FOLDERNAME:length-1:1} +[[ $LAST_CHAR_BINARY_FOLDERNAME != "/" ]] && BINARY_FOLDERNAME="$BINARY_FOLDERNAME/"; : rm -rf $SCRIPT_DIR$BINARY_FOLDERNAME mkdir -p $SCRIPT_DIR$BINARY_FOLDERNAME cd $SCRIPT_DIR$BINARY_FOLDERNAME - curl -L -O "$GEONAMES_DUMP$ADMIN1_CODES" -curl -L -O "$GEONAMES_DUMP$CITIES1000" \ No newline at end of file +curl -L -O "$GEONAMES_DUMP$CITIES1000" + +for CHECK_FILE in "${CHECK_FILES[@]}"; do + # Construct the full file path + FULL_PATH="${SCRIPT_DIR}${BINARY_FOLDERNAME}${CHECK_FILE}" + + # Check if the file exists + if [ ! -f "$FULL_PATH" ]; then + echo "$CHECK_FILE does not exist." + echo " $FULL_PATH is missing." + exit 1 + fi + + # Get file size + FILE_SIZE=$(stat -c%s "$FULL_PATH" 2>/dev/null || stat -f%z "$FULL_PATH") + + # Check conditions + if [ "$FILE_SIZE" -gt 147000 ] && [ "$CHECK_FILE" == "$ADMIN1_CODES" ]; then + echo "✅ $CHECK_FILE contains $ADMIN1_CODES and is at least 150 KB /0.14mb." + elif [ "$FILE_SIZE" -gt 9300000 ]; then + echo "✅ $CHECK_FILE exists and is larger than 8 MB." + else + echo "$CHECK_FILE exists but does not meet size requirements." + exit 1 + fi +done diff --git a/starsky-tools/build-tools/mirror/ffmpeg/index.json b/starsky-tools/build-tools/mirror/ffmpeg/index.json index 7a0ac9b950..eb90ff0416 100644 --- a/starsky-tools/build-tools/mirror/ffmpeg/index.json +++ b/starsky-tools/build-tools/mirror/ffmpeg/index.json @@ -2,27 +2,27 @@ "binaries": [ { "architecture": "windows-x64", - "url": "ffmpeg--win-64.zip", + "url": "ffmpeg-win-64.zip", "sha512": "5702ef34f69c3d8113e3c7133b19c63c1b7fe2d95c6b58e306cea69ab1fbbbf4f223454081fe88e47e02caac2c1370ff22fde749b9cb3f86493b37d3e245737b" }, { "architecture": "linux-x64", - "url": "ffmpeg--linux-64.zip", + "url": "ffmpeg-linux-64.zip", "sha512": "f5c54c9eb9aa249fa3a51a33e90f028dd00b87de8f3068a1619dd916d9e7e33e2ba05ccade5c26227223094c5446c5a20a70a2b2d8acd882685fa0b13fa90324" }, { "architecture": "linux-arm", - "url": "ffmpeg--linux-armhf-32.zip", + "url": "ffmpeg-linux-armhf-32.zip", "sha512": "e28e97b6fce3be34f2fd133e65e33fcf5b83cf3b11626cdff7576e2e19dbbaf31465f9f434cf8a6e243226f9d77db777799974f6750251c7b7132a42ada53e15" }, { "architecture": "linux-arm64", - "url": "ffmpeg--linux-arm-64.zip", + "url": "ffmpeg-linux-arm-64.zip", "sha512": "ac8522caae603a3e4bd16c2a7a8fab0e0dbf323d60cab3f87796d50ab56537ae3b0d110c0c02658b60a16106c8db3240ebc52a7d829af7067cd2ee3634822b81" }, { "architecture": "osx-x64", - "url": "ffmpeg--macos-64.zip", + "url": "ffmpeg-macos-64.zip", "sha512": "b4b0a48b5f7a41ee93dafd05ffe86e8083b2ead51de96daa31df31d5bff79295468f32f95dd8b20f12e063d26c7b5843214879b0b672b2c032f53bdc3229d9e1" }, { From 1673b24c5d911f14387a09944eeaa04fa6ab06b1 Mon Sep 17 00:00:00 2001 From: Dion Date: Mon, 18 Nov 2024 12:14:09 +0100 Subject: [PATCH 09/73] #1833 add debug --- starsky-tools/build-tools/download-mirror-ffmpeg.sh | 2 ++ starsky/starsky.sln | 1 + 2 files changed, 3 insertions(+) diff --git a/starsky-tools/build-tools/download-mirror-ffmpeg.sh b/starsky-tools/build-tools/download-mirror-ffmpeg.sh index b2b737a604..db083f4ea9 100644 --- a/starsky-tools/build-tools/download-mirror-ffmpeg.sh +++ b/starsky-tools/build-tools/download-mirror-ffmpeg.sh @@ -65,6 +65,8 @@ populate_array_from_variable "$BINARY_URLS" BINARY_URLS_ARRAY for i in "${!ARCHITECTURES_ARRAY[@]}"; do ARCHITECTURE="${ARCHITECTURES_ARRAY[$i]}" + echo "Processing architecture: $ARCHITECTURE..." + URL="${BINARY_URLS_ARRAY[$i]}" # Extract architecture and URL diff --git a/starsky/starsky.sln b/starsky/starsky.sln index 98c73e9e37..ad57d51bed 100644 --- a/starsky/starsky.sln +++ b/starsky/starsky.sln @@ -125,6 +125,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build-tools", "Build-tools" ..\starsky-tools\build-tools\app-version-test.js = ..\starsky-tools\build-tools\app-version-test.js ..\starsky-tools\build-tools\clientapp-vite-update.js = ..\starsky-tools\build-tools\clientapp-vite-update.js ..\starsky-tools\build-tools\package.json = ..\starsky-tools\build-tools\package.json + ..\starsky-tools\build-tools\download-mirror-ffmpeg.sh = ..\starsky-tools\build-tools\download-mirror-ffmpeg.sh EndProjectSection EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "starsky.feature.packagetelemetry", "starsky.feature.packagetelemetry\starsky.feature.packagetelemetry.csproj", "{7AB42607-88DF-427C-823B-033A224A73A6}" From e524d1e2333aa039cc45339f204bf39a8aaf871d Mon Sep 17 00:00:00 2001 From: Dion Date: Mon, 18 Nov 2024 12:19:22 +0100 Subject: [PATCH 10/73] #1833 add debug --- .../build-tools/download-mirror-ffmpeg.sh | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/starsky-tools/build-tools/download-mirror-ffmpeg.sh b/starsky-tools/build-tools/download-mirror-ffmpeg.sh index db083f4ea9..7610f7d161 100644 --- a/starsky-tools/build-tools/download-mirror-ffmpeg.sh +++ b/starsky-tools/build-tools/download-mirror-ffmpeg.sh @@ -73,25 +73,23 @@ for i in "${!ARCHITECTURES_ARRAY[@]}"; do FILENAME=$(basename "$URL") FILENAME_UPDATED=$(echo "$FILENAME" | sed -E "s/[-.]([0-9]+\.[0-9]+)[-.]/-/") - CURRENT_ARCHITECTURE=$(echo "$ARCHITECTURE" | sed -n 's/.*"\([^"]*\)":{.*ffmpeg.*/\1/p') - # skip if linux-armel or linux-32 - if [ "$CURRENT_ARCHITECTURE" == "linux-32" ] || [ "$CURRENT_ARCHITECTURE" == "linux-armel" ]; then + if [ "ARCHITECTURE" == "linux-32" ] || [ "ARCHITECTURE" == "linux-armel" ]; then continue fi - CURRENT_ARCHITECTURE="$(MAP_ARCHITECTURE_NAME $CURRENT_ARCHITECTURE)" + CURRENT_ARCHITECTURE="$(MAP_ARCHITECTURE_NAME $ARCHITECTURE)" # Download the binary echo "Downloading $URL for $CURRENT_ARCHITECTURE [$FILENAME] $FILENAME_UPDATED..." curl -L -O "$URL" - FILE_HASH=$(openssl dgst -sha512 "$FILENAME" | awk '{print $2}') + FILE_HASH=$(openssl dgst -sha256 "$FILENAME" | awk '{print $2}') mv "$FILENAME" "$FILENAME_UPDATED" # Add to output JSON - OUTPUT_JSON="${OUTPUT_JSON}{\"architecture\":\"$CURRENT_ARCHITECTURE\",\"url\":\"$FILENAME_UPDATED\",\"sha512\":\"$FILE_HASH\"}," + OUTPUT_JSON="${OUTPUT_JSON}{\"architecture\":\"$CURRENT_ARCHITECTURE\",\"url\":\"$FILENAME_UPDATED\",\"sha256\":\"$FILE_HASH\"}," done # Add osx-arm64 explicitly @@ -99,8 +97,8 @@ echo "Adding custom architecture $OSX_ARM64_NAME with URL $OSX_ARM64_URL..." curl -L -O "$OSX_ARM64_URL" OSX_ARM64_FILENAME=$(basename "$OSX_ARM64_URL") -OSX_ARM64_HASH=$(openssl dgst -sha512 "$OSX_ARM64_FILENAME" | awk '{print $2}') -OUTPUT_JSON="${OUTPUT_JSON}{\"architecture\":\"$OSX_ARM64_NAME\",\"url\":\"$OSX_ARM64_FILENAME\",\"sha512\":\"$OSX_ARM64_HASH\"}," +OSX_ARM64_HASH=$(openssl dgst -sha256 "$OSX_ARM64_FILENAME" | awk '{print $2}') +OUTPUT_JSON="${OUTPUT_JSON}{\"architecture\":\"$OSX_ARM64_NAME\",\"url\":\"$OSX_ARM64_FILENAME\",\"sha256\":\"$OSX_ARM64_HASH\"}," # Finalize JSON OUTPUT_JSON="${OUTPUT_JSON%,}]}" # Remove trailing comma and close the JSON array From b0c3b4852bf59e8eae799df7b341e6eccaf18414 Mon Sep 17 00:00:00 2001 From: Dion Date: Mon, 18 Nov 2024 12:24:28 +0100 Subject: [PATCH 11/73] #1833 work --- starsky-tools/build-tools/download-mirror-ffmpeg.sh | 12 +++++------- starsky/starsky.sln | 3 +++ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/starsky-tools/build-tools/download-mirror-ffmpeg.sh b/starsky-tools/build-tools/download-mirror-ffmpeg.sh index 7610f7d161..e3e06dc56e 100644 --- a/starsky-tools/build-tools/download-mirror-ffmpeg.sh +++ b/starsky-tools/build-tools/download-mirror-ffmpeg.sh @@ -65,6 +65,11 @@ populate_array_from_variable "$BINARY_URLS" BINARY_URLS_ARRAY for i in "${!ARCHITECTURES_ARRAY[@]}"; do ARCHITECTURE="${ARCHITECTURES_ARRAY[$i]}" + # skip if linux-armel or linux-32 + if [ "$ARCHITECTURE" == "linux-32" ] || [ "$ARCHITECTURE" == "linux-armel" ]; then + continue + fi + echo "Processing architecture: $ARCHITECTURE..." URL="${BINARY_URLS_ARRAY[$i]}" @@ -73,11 +78,6 @@ for i in "${!ARCHITECTURES_ARRAY[@]}"; do FILENAME=$(basename "$URL") FILENAME_UPDATED=$(echo "$FILENAME" | sed -E "s/[-.]([0-9]+\.[0-9]+)[-.]/-/") - # skip if linux-armel or linux-32 - if [ "ARCHITECTURE" == "linux-32" ] || [ "ARCHITECTURE" == "linux-armel" ]; then - continue - fi - CURRENT_ARCHITECTURE="$(MAP_ARCHITECTURE_NAME $ARCHITECTURE)" # Download the binary @@ -112,7 +112,6 @@ node -e "console.log(JSON.stringify(JSON.parse(require('fs') \ .readFileSync(process.argv[1])), null, 4));" $INDEX_FILE_PATH > $INDEX_FILE_PATH.bak mv $INDEX_FILE_PATH.bak $INDEX_FILE_PATH - for CHECK_FILE in "${CHECK_FILES[@]}"; do if [ -f "$SCRIPT_DIR$BINARY_FOLDERNAME$CHECK_FILE" ] && [ "$(stat -c%s "$SCRIPT_DIR$BINARY_FOLDERNAME$CHECK_FILE" 2>/dev/null || stat -f%z "$SCRIPT_DIR$BINARY_FOLDERNAME$CHECK_FILE")" -gt 17874368 ]; then echo "✅ $CHECK_FILE exists and is larger than 17 MB." @@ -125,5 +124,4 @@ for CHECK_FILE in "${CHECK_FILES[@]}"; do fi done - echo "URLs with architectures saved to $INDEX_FILE_PATH" diff --git a/starsky/starsky.sln b/starsky/starsky.sln index ad57d51bed..b71637e313 100644 --- a/starsky/starsky.sln +++ b/starsky/starsky.sln @@ -126,6 +126,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build-tools", "Build-tools" ..\starsky-tools\build-tools\clientapp-vite-update.js = ..\starsky-tools\build-tools\clientapp-vite-update.js ..\starsky-tools\build-tools\package.json = ..\starsky-tools\build-tools\package.json ..\starsky-tools\build-tools\download-mirror-ffmpeg.sh = ..\starsky-tools\build-tools\download-mirror-ffmpeg.sh + ..\starsky-tools\build-tools\download-mirror-exiftool.sh = ..\starsky-tools\build-tools\download-mirror-exiftool.sh + ..\starsky-tools\build-tools\download-mirror-geonames.sh = ..\starsky-tools\build-tools\download-mirror-geonames.sh + ..\starsky-tools\build-tools\download-mirror.sh = ..\starsky-tools\build-tools\download-mirror.sh EndProjectSection EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "starsky.feature.packagetelemetry", "starsky.feature.packagetelemetry\starsky.feature.packagetelemetry.csproj", "{7AB42607-88DF-427C-823B-033A224A73A6}" From c8983cdc4b522d8a6ce8706b82b7d620ded8fc78 Mon Sep 17 00:00:00 2001 From: Dion Date: Mon, 18 Nov 2024 14:38:31 +0100 Subject: [PATCH 12/73] #1833 reformat --- .../Interfaces/IHttpClientHelper.cs | 18 +- .../Services/HttpClientHelper.cs | 284 +++++++++--------- .../GetDependencies/FFMpegDownload.cs | 39 ++- .../FakeMocks/FakeIHttpClientHelper.cs | 89 +++--- 4 files changed, 235 insertions(+), 195 deletions(-) diff --git a/starsky/starsky.foundation.http/Interfaces/IHttpClientHelper.cs b/starsky/starsky.foundation.http/Interfaces/IHttpClientHelper.cs index d62aa1d4d8..9d54105364 100644 --- a/starsky/starsky.foundation.http/Interfaces/IHttpClientHelper.cs +++ b/starsky/starsky.foundation.http/Interfaces/IHttpClientHelper.cs @@ -1,14 +1,16 @@ +using System; using System.Collections.Generic; using System.Net.Http; using System.Threading.Tasks; -namespace starsky.foundation.http.Interfaces +namespace starsky.foundation.http.Interfaces; + +public interface IHttpClientHelper { - public interface IHttpClientHelper - { - Task Download(string sourceHttpUrl, string fullLocalPath, int retryAfterInSeconds = 15); - Task> ReadString(string sourceHttpUrl); - Task> PostString(string sourceHttpUrl, - HttpContent? httpContent, bool verbose = true); - } + Task Download(string sourceHttpUrl, string fullLocalPath, int retryAfterInSeconds = 15); + Task> ReadString(string sourceHttpUrl); + Task> ReadString(Uri sourceHttpUrl); + + Task> PostString(string sourceHttpUrl, + HttpContent? httpContent, bool verbose = true); } diff --git a/starsky/starsky.foundation.http/Services/HttpClientHelper.cs b/starsky/starsky.foundation.http/Services/HttpClientHelper.cs index b726add91a..28278ca7d0 100644 --- a/starsky/starsky.foundation.http/Services/HttpClientHelper.cs +++ b/starsky/starsky.foundation.http/Services/HttpClientHelper.cs @@ -13,180 +13,184 @@ using starsky.foundation.storage.Interfaces; using starsky.foundation.storage.Storage; -namespace starsky.foundation.http.Services +namespace starsky.foundation.http.Services; + +[Service(typeof(IHttpClientHelper), InjectionLifetime = InjectionLifetime.Singleton)] +public sealed class HttpClientHelper : IHttpClientHelper { - [Service(typeof(IHttpClientHelper), InjectionLifetime = InjectionLifetime.Singleton)] - public sealed class HttpClientHelper : IHttpClientHelper + /// + /// These domains are only allowed domains to download from (and https only) + /// + private readonly List _allowedDomains = + [ + "dl.dropboxusercontent.com", + "qdraw.nl", // < used by test + "media.qdraw.nl", // < used by demo + "locker.ifttt.com", + "download.geonames.org", + "exiftool.org", + "api.github.com" + ]; + + /// + /// Http Provider + /// + private readonly IHttpProvider _httpProvider; + + private readonly IWebLogger _logger; + private readonly IStorage? _storage; + + /// + /// Set Http Provider + /// + /// IHttpProvider + /// ScopeFactory contains a IStorageSelector + /// WebLogger + public HttpClientHelper(IHttpProvider httpProvider, + IServiceScopeFactory? serviceScopeFactory, IWebLogger logger) { - private readonly IStorage? _storage; - - /// - /// Set Http Provider - /// - /// IHttpProvider - /// ScopeFactory contains a IStorageSelector - /// WebLogger - public HttpClientHelper(IHttpProvider httpProvider, - IServiceScopeFactory? serviceScopeFactory, IWebLogger logger) + _httpProvider = httpProvider; + _logger = logger; + if ( serviceScopeFactory == null ) { - _httpProvider = httpProvider; - _logger = logger; - if ( serviceScopeFactory == null ) - { - return; - } - - using ( var scope = serviceScopeFactory.CreateScope() ) - { - // ISelectorStorage is a scoped service - var selectorStorage = scope.ServiceProvider.GetRequiredService(); - _storage = selectorStorage.Get(SelectorStorage.StorageServices.HostFilesystem); - } + return; } - /// - /// Http Provider - /// - private readonly IHttpProvider _httpProvider; - - private readonly IWebLogger _logger; - - /// - /// These domains are only allowed domains to download from (and https only) - /// - private readonly List _allowedDomains = - [ - "dl.dropboxusercontent.com", - "qdraw.nl", // < used by test - "media.qdraw.nl", // < used by demo - "locker.ifttt.com", - "download.geonames.org", - "exiftool.org", - "api.github.com" - ]; - - public async Task> ReadString(string sourceHttpUrl) + using ( var scope = serviceScopeFactory.CreateScope() ) { - var sourceUri = new Uri(sourceHttpUrl); + // ISelectorStorage is a scoped service + var selectorStorage = scope.ServiceProvider.GetRequiredService(); + _storage = selectorStorage.Get(SelectorStorage.StorageServices.HostFilesystem); + } + } - _logger.LogInformation("[ReadString] HttpClientHelper > " - + sourceUri.Host + " ~ " + sourceHttpUrl); + public async Task> ReadString(string sourceHttpUrl) + { + var sourceUri = new Uri(sourceHttpUrl); + return await ReadString(sourceUri); + } - // allow whitelist and https only - if ( !_allowedDomains.Contains(sourceUri.Host) || sourceUri.Scheme != "https" ) - { - return + public async Task> ReadString(Uri sourceHttpUrl) + { + _logger.LogInformation("[ReadString] HttpClientHelper > " + + sourceHttpUrl); + // allow whitelist and https only + if ( !_allowedDomains.Contains(sourceHttpUrl.Host) || sourceHttpUrl.Scheme != "https" ) + { + return new KeyValuePair(false, string.Empty); - } + } - try - { - using ( HttpResponseMessage response = await _httpProvider.GetAsync(sourceHttpUrl) ) - using ( Stream streamToReadFrom = await response.Content.ReadAsStreamAsync() ) - { - var reader = new StreamReader(streamToReadFrom, Encoding.UTF8); - var result = await reader.ReadToEndAsync(); - return new KeyValuePair(response.StatusCode == HttpStatusCode.OK, result); - } - } - catch ( HttpRequestException exception ) + try + { + using ( var response = await _httpProvider.GetAsync(sourceHttpUrl.ToString()) ) + using ( var streamToReadFrom = await response.Content.ReadAsStreamAsync() ) { - return new KeyValuePair(false, exception.Message); + var reader = new StreamReader(streamToReadFrom, Encoding.UTF8); + var result = await reader.ReadToEndAsync(); + return new KeyValuePair(response.StatusCode == HttpStatusCode.OK, + result); } } - - public async Task> PostString(string sourceHttpUrl, - HttpContent? httpContent, bool verbose = true) + catch ( HttpRequestException exception ) { - var sourceUri = new Uri(sourceHttpUrl); + return new KeyValuePair(false, exception.Message); + } + } - if ( verbose ) - { - _logger.LogInformation("[PostString] HttpClientHelper > " - + sourceUri.Host + " ~ " + sourceHttpUrl); - } + public async Task> PostString(string sourceHttpUrl, + HttpContent? httpContent, bool verbose = true) + { + var sourceUri = new Uri(sourceHttpUrl); - // // allow whitelist and https only - if ( !_allowedDomains.Contains(sourceUri.Host) || sourceUri.Scheme != "https" ) - { - return + if ( verbose ) + { + _logger.LogInformation("[PostString] HttpClientHelper > " + + sourceUri.Host + " ~ " + sourceHttpUrl); + } + + // // allow whitelist and https only + if ( !_allowedDomains.Contains(sourceUri.Host) || sourceUri.Scheme != "https" ) + { + return new KeyValuePair(false, string.Empty); - } + } - try - { - using ( HttpResponseMessage response = await _httpProvider.PostAsync(sourceHttpUrl, httpContent) ) - using ( Stream streamToReadFrom = await response.Content.ReadAsStreamAsync() ) - { - var reader = new StreamReader(streamToReadFrom, Encoding.UTF8); - var result = await reader.ReadToEndAsync(); - return new KeyValuePair(response.StatusCode == HttpStatusCode.OK, result); - } - } - catch ( HttpRequestException exception ) + try + { + using ( var response = await _httpProvider.PostAsync(sourceHttpUrl, httpContent) ) + using ( var streamToReadFrom = await response.Content.ReadAsStreamAsync() ) { - return new KeyValuePair(false, exception.Message); + var reader = new StreamReader(streamToReadFrom, Encoding.UTF8); + var result = await reader.ReadToEndAsync(); + return new KeyValuePair(response.StatusCode == HttpStatusCode.OK, + result); } } + catch ( HttpRequestException exception ) + { + return new KeyValuePair(false, exception.Message); + } + } - /// - /// Downloads the specified source HTTPS URL. - /// - /// The source HTTPS URL. - /// The full local path. - /// Retry after number of seconds - /// - public async Task Download(string sourceHttpUrl, string fullLocalPath, int retryAfterInSeconds = 15) + /// + /// Downloads the specified source HTTPS URL. + /// + /// The source HTTPS URL. + /// The full local path. + /// Retry after number of seconds + /// + public async Task Download(string sourceHttpUrl, string fullLocalPath, + int retryAfterInSeconds = 15) + { + if ( _storage == null ) { - if ( _storage == null ) - { - throw new EndOfStreamException("is null " + nameof(_storage)); - } + throw new EndOfStreamException("is null " + nameof(_storage)); + } + + var sourceUri = new Uri(sourceHttpUrl); - Uri sourceUri = new Uri(sourceHttpUrl); + _logger.LogInformation("[Download] HttpClientHelper > " + + sourceUri.Host + " ~ " + sourceHttpUrl); + // allow whitelist and https only + if ( !_allowedDomains.Contains(sourceUri.Host) || + sourceUri.Scheme != "https" ) + { _logger.LogInformation("[Download] HttpClientHelper > " - + sourceUri.Host + " ~ " + sourceHttpUrl); + + "skip: domain not whitelisted " + " ~ " + sourceHttpUrl); + return false; + } - // allow whitelist and https only - if ( !_allowedDomains.Contains(sourceUri.Host) || - sourceUri.Scheme != "https" ) + async Task DownloadAsync() + { + using var response = await _httpProvider.GetAsync(sourceHttpUrl); + await using var streamToReadFrom = await response.Content.ReadAsStreamAsync(); + if ( response.StatusCode != HttpStatusCode.OK ) { - _logger.LogInformation("[Download] HttpClientHelper > " - + "skip: domain not whitelisted " + " ~ " + sourceHttpUrl); + _logger.LogInformation("[Download] HttpClientHelper > " + + response.StatusCode + " ~ " + sourceHttpUrl); return false; } - async Task DownloadAsync() - { - using var response = await _httpProvider.GetAsync(sourceHttpUrl); - await using var streamToReadFrom = await response.Content.ReadAsStreamAsync(); - if ( response.StatusCode != HttpStatusCode.OK ) - { - _logger.LogInformation("[Download] HttpClientHelper > " + - response.StatusCode + " ~ " + sourceHttpUrl); - return false; - } - - await _storage!.WriteStreamAsync(streamToReadFrom, fullLocalPath); - return true; - } + await _storage!.WriteStreamAsync(streamToReadFrom, fullLocalPath); + return true; + } - try - { - return await RetryHelper.DoAsync(DownloadAsync, - TimeSpan.FromSeconds(retryAfterInSeconds), 2); - } - catch ( AggregateException exception ) + try + { + return await RetryHelper.DoAsync(DownloadAsync, + TimeSpan.FromSeconds(retryAfterInSeconds), 2); + } + catch ( AggregateException exception ) + { + foreach ( var innerException in exception.InnerExceptions ) { - foreach ( var innerException in exception.InnerExceptions ) - { - _logger.LogError(innerException, $"[Download] InnerException: {exception.Message}"); - } - _logger.LogError(exception, $"[Download] Exception: {exception.Message}"); - return false; + _logger.LogError(innerException, $"[Download] InnerException: {exception.Message}"); } + + _logger.LogError(exception, $"[Download] Exception: {exception.Message}"); + return false; } } - } diff --git a/starsky/starsky.foundation.video/GetDependencies/FFMpegDownload.cs b/starsky/starsky.foundation.video/GetDependencies/FFMpegDownload.cs index 33f86b32ae..c545f39032 100644 --- a/starsky/starsky.foundation.video/GetDependencies/FFMpegDownload.cs +++ b/starsky/starsky.foundation.video/GetDependencies/FFMpegDownload.cs @@ -9,13 +9,14 @@ namespace starsky.foundation.video.GetDependencies; public class FfMpegDownload : IFfMpegDownload { - private const string FFMpegDownloadBasePath = - "https://qdraw.nl/special/mirror/ffmpeg/"; // with slash at the end - private readonly AppSettings _appSettings; private readonly IStorage _hostFileSystemStorage; private readonly IHttpClientHelper _httpClientHelper; private readonly IWebLogger _logger; + private readonly Uri FFMpegApiBasePath = new("https://starsky-dependencies.netlify.app/ffmpeg"); + + private readonly Uri FFMpegApiIndex = + new("https://starsky-dependencies.netlify.app/ffmpeg/index.json"); public FfMpegDownload(IHttpClientHelper httpClientHelper, AppSettings appSettings, IWebLogger logger) @@ -26,11 +27,8 @@ public FfMpegDownload(IHttpClientHelper httpClientHelper, AppSettings appSetting _logger = logger; } - public async Task DownloadFFMpeg(OperatingSystem) + public async Task DownloadFFMpeg() { - var currentPlatform = OperatingSystemHelper.GetPlatform(); - - if ( _appSettings.ExiftoolSkipDownloadOnStartup == true || _appSettings is { AddSwaggerExport: true, AddSwaggerExportExitAfter: true } ) { @@ -42,6 +40,33 @@ public async Task DownloadFFMpeg(OperatingSystem) } CreateDirectoryDependenciesFolderIfNotExists(); + + return true; + } + + private async Task DownloadIndex() + { + await _httpClientHelper.ReadString(FFMpegApiIndex); + } + + private async Task Download(Uri FFMpegDownloadBasePath) + { + // if ( !_hostFileSystemStorage.ExistFile( + // Path.Combine(_appSettings.DependenciesFolder, CountryName + ".txt")) ) + // { + // var outputZip = Path.Combine(_appSettings.DependenciesFolder, + // CountryName + ".zip"); + // var baseResult = + // await _httpClientHelper.Download(https + BaseUrl + CountryName + ".zip", + // outputZip); + // if ( !baseResult ) + // { + // await _httpClientHelper.Download(https + MirrorUrl + CountryName + ".zip", + // outputZip); + // } + // + // new Zipper(_logger).ExtractZip(outputZip, _appSettings.DependenciesFolder); + // } } private void CreateDirectoryDependenciesFolderIfNotExists() diff --git a/starsky/starskytest/FakeMocks/FakeIHttpClientHelper.cs b/starsky/starskytest/FakeMocks/FakeIHttpClientHelper.cs index 2572530ac9..267ff0b455 100644 --- a/starsky/starskytest/FakeMocks/FakeIHttpClientHelper.cs +++ b/starsky/starskytest/FakeMocks/FakeIHttpClientHelper.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -7,53 +8,61 @@ using starsky.foundation.platform.Helpers; using starsky.foundation.storage.Interfaces; -namespace starskytest.FakeMocks +namespace starskytest.FakeMocks; + +public class FakeIHttpClientHelper : IHttpClientHelper { - public class FakeIHttpClientHelper : IHttpClientHelper + private readonly Dictionary> _inputDictionary; + private readonly IStorage _storage; + + public FakeIHttpClientHelper(IStorage storage, + Dictionary> inputDictionary) { - private readonly Dictionary> _inputDictionary; - private readonly IStorage _storage; + _storage = storage; + _inputDictionary = inputDictionary; + } - public FakeIHttpClientHelper(IStorage storage, Dictionary> inputDictionary) - { - _storage = storage; - _inputDictionary = inputDictionary; - } + public List UrlsCalled { get; set; } = new(); - public List UrlsCalled { get; set; } = new List(); - - public async Task Download(string sourceHttpUrl, string fullLocalPath, - int retryAfterInSeconds = 15) - { - UrlsCalled.Add(sourceHttpUrl); - - var result = - _inputDictionary.FirstOrDefault(p => p.Key == sourceHttpUrl); - - if ( result.Value.Value == null ) - { - return false; - } - - var fileByteArray = Base64Helper.TryParse(result.Value.Value); - var stream = new MemoryStream(fileByteArray); - await _storage.WriteStreamAsync(stream, fullLocalPath); - await stream.DisposeAsync(); - - return result.Value.Key; - } + public async Task Download(string sourceHttpUrl, string fullLocalPath, + int retryAfterInSeconds = 15) + { + UrlsCalled.Add(sourceHttpUrl); - public Task> ReadString(string sourceHttpUrl) - { - UrlsCalled.Add(sourceHttpUrl); - return Task.FromResult(_inputDictionary.FirstOrDefault(p => p.Key == sourceHttpUrl).Value); - } + var result = + _inputDictionary.FirstOrDefault(p => p.Key == sourceHttpUrl); - public Task> PostString(string sourceHttpUrl, HttpContent? httpContent, - bool verbose = true) + if ( result.Value.Value == null ) { - UrlsCalled.Add(sourceHttpUrl); - return Task.FromResult(_inputDictionary.FirstOrDefault(p => p.Key == sourceHttpUrl).Value); + return false; } + + var fileByteArray = Base64Helper.TryParse(result.Value.Value); + var stream = new MemoryStream(fileByteArray); + await _storage.WriteStreamAsync(stream, fullLocalPath); + await stream.DisposeAsync(); + + return result.Value.Key; + } + + public Task> ReadString(string sourceHttpUrl) + { + UrlsCalled.Add(sourceHttpUrl); + return Task.FromResult(_inputDictionary.FirstOrDefault(p => p.Key == sourceHttpUrl).Value); + } + + public Task> ReadString(Uri sourceHttpUrl) + { + UrlsCalled.Add(sourceHttpUrl.ToString()); + return Task.FromResult(_inputDictionary + .FirstOrDefault(p => p.Key == sourceHttpUrl.ToString()).Value); + } + + public Task> PostString(string sourceHttpUrl, + HttpContent? httpContent, + bool verbose = true) + { + UrlsCalled.Add(sourceHttpUrl); + return Task.FromResult(_inputDictionary.FirstOrDefault(p => p.Key == sourceHttpUrl).Value); } } From cfadfb3b8bbd63d46c46a2e6e1c5171b6a496dac Mon Sep 17 00:00:00 2001 From: Dion Date: Mon, 18 Nov 2024 17:01:17 +0100 Subject: [PATCH 13/73] #1833 ffmpeg index --- .../GetDependencies/FFMpegDownload.cs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/starsky/starsky.foundation.video/GetDependencies/FFMpegDownload.cs b/starsky/starsky.foundation.video/GetDependencies/FFMpegDownload.cs index c545f39032..8b5f6d765d 100644 --- a/starsky/starsky.foundation.video/GetDependencies/FFMpegDownload.cs +++ b/starsky/starsky.foundation.video/GetDependencies/FFMpegDownload.cs @@ -15,9 +15,10 @@ public class FfMpegDownload : IFfMpegDownload private readonly IWebLogger _logger; private readonly Uri FFMpegApiBasePath = new("https://starsky-dependencies.netlify.app/ffmpeg"); - private readonly Uri FFMpegApiIndex = + private readonly Uri _ffMpegApiIndex = new("https://starsky-dependencies.netlify.app/ffmpeg/index.json"); - + private readonly Uri _ffMpegApiIndex = + new("https://qdraw.nl/special/mirror/ffmpeg/index.json"); public FfMpegDownload(IHttpClientHelper httpClientHelper, AppSettings appSettings, IWebLogger logger) { @@ -46,7 +47,12 @@ public async Task DownloadFFMpeg() private async Task DownloadIndex() { - await _httpClientHelper.ReadString(FFMpegApiIndex); + var result = await _httpClientHelper.ReadString(_ffMpegApiIndex); + if ( !result.Key ) + { + _logger.LogError("[FfMpegDownload] Index not found"); + return; + } } private async Task Download(Uri FFMpegDownloadBasePath) From c63455979442971b417617c6d1ad8d19d2db2542 Mon Sep 17 00:00:00 2001 From: Dion Date: Tue, 19 Nov 2024 11:23:05 +0100 Subject: [PATCH 14/73] #1833 current os implementenation --- .../OpenApplicationNativeService.cs | 98 +++++++++---------- .../Trash/TrashService.cs | 46 ++++----- .../Architecture/CurrentArchitecture.cs | 45 +++++++++ .../Architecture}/OperatingSystemHelper.cs | 8 +- .../Helpers/DeserializeJson.cs | 49 +++++----- .../GetDependencies/FFMpegDownload.cs | 40 ++++++-- .../GetDependencies/GetVersionString.cs | 41 ++------ .../Models/FfmpegBinariesIndex.cs | 14 +++ .../OperationSystemPlatforms.cs | 2 +- .../starsky.foundation.video.csproj | 4 + .../Helpers/MacOsOpenUrlTests.cs | 2 +- .../OpenApplicationNativeServiceTest.cs | 15 +-- .../Helpers/MacOsTrashBindingHelperTest.cs | 2 +- .../Trash/TrashServiceTest.cs | 40 ++++---- .../Architecture/CurrentArchitectureTests.cs | 80 +++++++++++++++ .../Architecture}/FakeOsOverwrite.cs | 4 +- .../OperatingSystemHelperTest.cs | 16 +-- 17 files changed, 323 insertions(+), 183 deletions(-) create mode 100644 starsky/starsky.foundation.platform/Architecture/CurrentArchitecture.cs rename starsky/{starsky.foundation.native/Helpers => starsky.foundation.platform/Architecture}/OperatingSystemHelper.cs (90%) create mode 100644 starsky/starsky.foundation.video/GetDependencies/Models/FfmpegBinariesIndex.cs create mode 100644 starsky/starskytest/starsky.foundation.platform/Architecture/CurrentArchitectureTests.cs rename starsky/starskytest/{starsky.foundation.native/Helpers => starsky.foundation.platform/Architecture}/FakeOsOverwrite.cs (90%) rename starsky/starskytest/{starsky.foundation.native/Helpers => starsky.foundation.platform/Architecture}/OperatingSystemHelperTest.cs (91%) diff --git a/starsky/starsky.foundation.native/OpenApplicationNative/OpenApplicationNativeService.cs b/starsky/starsky.foundation.native/OpenApplicationNative/OpenApplicationNativeService.cs index 184d46cc59..d4b5f4b704 100644 --- a/starsky/starsky.foundation.native/OpenApplicationNative/OpenApplicationNativeService.cs +++ b/starsky/starsky.foundation.native/OpenApplicationNative/OpenApplicationNativeService.cs @@ -1,8 +1,8 @@ using System.Runtime.InteropServices; using starsky.foundation.injection; -using starsky.foundation.native.Helpers; using starsky.foundation.native.OpenApplicationNative.Helpers; using starsky.foundation.native.OpenApplicationNative.Interfaces; +using starsky.foundation.platform.Architecture; namespace starsky.foundation.native.OpenApplicationNative; @@ -10,7 +10,7 @@ namespace starsky.foundation.native.OpenApplicationNative; public class OpenApplicationNativeService : IOpenApplicationNativeService { /// - /// Is Open File supported on this configuration + /// Is Open File supported on this configuration /// /// true if supported, false if not supported public bool DetectToUseOpenApplication() @@ -19,41 +19,9 @@ public bool DetectToUseOpenApplication() Environment.UserInteractive); } - /// - /// Use to overwrite the RuntimeInformation.IsOSPlatform - /// - internal delegate bool IsOsPlatformDelegate(OSPlatform osPlatform); - - /// - /// Is Open File supported on this configuration - /// - /// RuntimeInformation.IsOSPlatform - /// Environment.UserInteractive - /// true if supported, false if not supported - internal static bool DetectToUseOpenApplicationInternal( - IsOsPlatformDelegate runtimeInformationIsOsPlatform, - bool environmentUserInteractive) - { - // Linux is not supported yet - if ( runtimeInformationIsOsPlatform(OSPlatform.Linux) || - runtimeInformationIsOsPlatform(OSPlatform.FreeBSD) ) - { - return false; - } - - // When running in Windows as Service it does not open the application - // On Mac OS it does open the application - if ( !environmentUserInteractive && runtimeInformationIsOsPlatform(OSPlatform.Windows) ) - { - return false; - } - - return true; - } - /// - /// Open file with specified application + /// Open file with specified application /// /// List first item is fullFilePath, second is ApplicationUrl /// true is operation succeed, false failed | null is platform unsupported @@ -82,7 +50,49 @@ internal static bool DetectToUseOpenApplicationInternal( } /// - /// Open file with specified application + /// Open file with default application + /// + /// full path style + /// true is operation succeed, false failed | null is platform unsupported + public bool? OpenDefault(List fullPaths) + { + var currentPlatform = OperatingSystemHelper.GetPlatform(); + var macOsOpenResult = MacOsOpenUrl.OpenDefault(fullPaths, currentPlatform); + var windowsOpenResult = WindowsOpenDesktopApp.OpenDefault(fullPaths, + currentPlatform); + + return macOsOpenResult ?? windowsOpenResult; + } + + /// + /// Is Open File supported on this configuration + /// + /// RuntimeInformation.IsOSPlatform + /// Environment.UserInteractive + /// true if supported, false if not supported + internal static bool DetectToUseOpenApplicationInternal( + IsOsPlatformDelegate runtimeInformationIsOsPlatform, + bool environmentUserInteractive) + { + // Linux is not supported yet + if ( runtimeInformationIsOsPlatform(OSPlatform.Linux) || + runtimeInformationIsOsPlatform(OSPlatform.FreeBSD) ) + { + return false; + } + + // When running in Windows as Service it does not open the application + // On Mac OS it does open the application + if ( !environmentUserInteractive && runtimeInformationIsOsPlatform(OSPlatform.Windows) ) + { + return false; + } + + return true; + } + + /// + /// Open file with specified application /// /// full path style /// applicationUrl @@ -111,24 +121,14 @@ internal static bool DetectToUseOpenApplicationInternal( { var fullPaths = group.Select(item => item.Item1).ToList(); var applicationUrl = group.Key; - results.Add((fullPaths, applicationUrl)); + results.Add(( fullPaths, applicationUrl )); } return results; } /// - /// Open file with default application + /// Use to overwrite the RuntimeInformation.IsOSPlatform /// - /// full path style - /// true is operation succeed, false failed | null is platform unsupported - public bool? OpenDefault(List fullPaths) - { - var currentPlatform = OperatingSystemHelper.GetPlatform(); - var macOsOpenResult = MacOsOpenUrl.OpenDefault(fullPaths, currentPlatform); - var windowsOpenResult = WindowsOpenDesktopApp.OpenDefault(fullPaths, - currentPlatform); - - return macOsOpenResult ?? windowsOpenResult; - } + internal delegate bool IsOsPlatformDelegate(OSPlatform osPlatform); } diff --git a/starsky/starsky.foundation.native/Trash/TrashService.cs b/starsky/starsky.foundation.native/Trash/TrashService.cs index ccbe6ca765..ceaeef67a9 100644 --- a/starsky/starsky.foundation.native/Trash/TrashService.cs +++ b/starsky/starsky.foundation.native/Trash/TrashService.cs @@ -1,8 +1,8 @@ using System.Runtime.InteropServices; using starsky.foundation.injection; -using starsky.foundation.native.Helpers; using starsky.foundation.native.Trash.Helpers; using starsky.foundation.native.Trash.Interfaces; +using starsky.foundation.platform.Architecture; namespace starsky.foundation.native.Trash; @@ -10,7 +10,7 @@ namespace starsky.foundation.native.Trash; public class TrashService : ITrashService { /// - /// Is the system trash supported + /// Is the system trash supported /// /// true if supported, false if not supported public bool DetectToUseSystemTrash() @@ -21,12 +21,26 @@ public bool DetectToUseSystemTrash() } /// - /// Use to overwrite the RuntimeInformation.IsOSPlatform + /// Does not check if the file exists + /// Trash file for Mac OS and Windows /// - internal delegate bool IsOsPlatformDelegate(OSPlatform osPlatform); + /// system path + /// operation succeed (NOT if file is gone) + public bool? Trash(string fullPath) + { + return Trash([fullPath]); + } + + public bool? Trash(List fullPaths) + { + var currentPlatform = OperatingSystemHelper.GetPlatform(); + var macOsTrash = MacOsTrashBindingHelper.Trash(fullPaths, currentPlatform); + var (windowsTrash, _) = WindowsShellTrashBindingHelper.Trash(fullPaths, currentPlatform); + return macOsTrash ?? windowsTrash; + } /// - /// Is the system trash supported + /// Is the system trash supported /// /// RuntimeInformation.IsOSPlatform /// Environment.UserInteractive @@ -39,8 +53,8 @@ internal static bool DetectToUseSystemTrashInternal( { // ReSharper disable once ConvertIfStatementToReturnStatement if ( runtimeInformationIsOsPlatform(OSPlatform.Linux) || - runtimeInformationIsOsPlatform(OSPlatform.FreeBSD) || - environmentUserName == "root" || !environmentUserInteractive ) + runtimeInformationIsOsPlatform(OSPlatform.FreeBSD) || + environmentUserName == "root" || !environmentUserInteractive ) { return false; } @@ -56,21 +70,7 @@ internal static bool DetectToUseSystemTrashInternal( } /// - /// Does not check if the file exists - /// Trash file for Mac OS and Windows + /// Use to overwrite the RuntimeInformation.IsOSPlatform /// - /// system path - /// operation succeed (NOT if file is gone) - public bool? Trash(string fullPath) - { - return Trash([fullPath]); - } - - public bool? Trash(List fullPaths) - { - var currentPlatform = OperatingSystemHelper.GetPlatform(); - var macOsTrash = MacOsTrashBindingHelper.Trash(fullPaths, currentPlatform); - var (windowsTrash, _) = WindowsShellTrashBindingHelper.Trash(fullPaths, currentPlatform); - return macOsTrash ?? windowsTrash; - } + internal delegate bool IsOsPlatformDelegate(OSPlatform osPlatform); } diff --git a/starsky/starsky.foundation.platform/Architecture/CurrentArchitecture.cs b/starsky/starsky.foundation.platform/Architecture/CurrentArchitecture.cs new file mode 100644 index 0000000000..a6bb51d039 --- /dev/null +++ b/starsky/starsky.foundation.platform/Architecture/CurrentArchitecture.cs @@ -0,0 +1,45 @@ +using System.Runtime.InteropServices; + +namespace starsky.foundation.platform.Architecture; + +public static class CurrentArchitecture +{ + public delegate bool IsOsPlatformDelegate(OSPlatform osPlatform); + + public delegate System.Runtime.InteropServices.Architecture OsArchitectureDelegate(); + + public static string GetCurrentRuntimeIdentifier() + { + return GetCurrentRuntimeIdentifier(RuntimeInformation.IsOSPlatform, + GetOsArchitecture); + } + + public static string GetCurrentRuntimeIdentifier(IsOsPlatformDelegate isOsPlatformDelegate, + OsArchitectureDelegate architectureDelegate) + { + var os = string.Empty; + if ( isOsPlatformDelegate(OSPlatform.Windows) ) + { + os = "win"; + } + + if ( isOsPlatformDelegate(OSPlatform.Linux) || isOsPlatformDelegate(OSPlatform.FreeBSD) ) + { + os = "linux"; + } + + if ( isOsPlatformDelegate(OSPlatform.OSX) ) + { + os = "osx"; + } + + var architecture = architectureDelegate().ToString().ToLowerInvariant(); + + return $"{os}-{architecture}"; + } + + private static System.Runtime.InteropServices.Architecture GetOsArchitecture() + { + return RuntimeInformation.OSArchitecture; + } +} diff --git a/starsky/starsky.foundation.native/Helpers/OperatingSystemHelper.cs b/starsky/starsky.foundation.platform/Architecture/OperatingSystemHelper.cs similarity index 90% rename from starsky/starsky.foundation.native/Helpers/OperatingSystemHelper.cs rename to starsky/starsky.foundation.platform/Architecture/OperatingSystemHelper.cs index 7bbf979784..13a4d73dd4 100644 --- a/starsky/starsky.foundation.native/Helpers/OperatingSystemHelper.cs +++ b/starsky/starsky.foundation.platform/Architecture/OperatingSystemHelper.cs @@ -1,6 +1,6 @@ using System.Runtime.InteropServices; -namespace starsky.foundation.native.Helpers; +namespace starsky.foundation.platform.Architecture; public static class OperatingSystemHelper { @@ -9,10 +9,8 @@ public static OSPlatform GetPlatform() return GetPlatformInternal(RuntimeInformation.IsOSPlatform); } - internal delegate bool IsOsPlatformDelegate(OSPlatform osPlatform); - /// - /// Used to make the function testable + /// Used to make the function testable /// /// Delegate to know what the OS is /// Runtime OS @@ -37,4 +35,6 @@ internal static OSPlatform GetPlatformInternal(IsOsPlatformDelegate isOsPlatform ? OSPlatform.FreeBSD : OSPlatform.Create("Unknown"); } + + internal delegate bool IsOsPlatformDelegate(OSPlatform osPlatform); } diff --git a/starsky/starsky.foundation.storage/Helpers/DeserializeJson.cs b/starsky/starsky.foundation.storage/Helpers/DeserializeJson.cs index 2652073b48..02cac2a273 100644 --- a/starsky/starsky.foundation.storage/Helpers/DeserializeJson.cs +++ b/starsky/starsky.foundation.storage/Helpers/DeserializeJson.cs @@ -4,35 +4,36 @@ using starsky.foundation.platform.JsonConverter; using starsky.foundation.storage.Interfaces; -namespace starsky.foundation.storage.Helpers +namespace starsky.foundation.storage.Helpers; + +public sealed class DeserializeJson { - public sealed class DeserializeJson + private readonly IStorage _iStorage; + + public DeserializeJson(IStorage iStorage) { - private readonly IStorage _iStorage; + _iStorage = iStorage; + } - public DeserializeJson(IStorage iStorage) + /// + /// Read Json + /// + /// location on disk + /// Typed + /// Data + /// when file is not found + public async Task ReadAsync(string jsonSubPath) + { + if ( !_iStorage.ExistFile(jsonSubPath) ) { - _iStorage = iStorage; + throw new FileNotFoundException(jsonSubPath); } - /// - /// Read Json - /// - /// location on disk - /// Typed - /// Data - /// when file is not found - public async Task ReadAsync(string jsonSubPath) - { - if ( !_iStorage.ExistFile(jsonSubPath) ) - { - throw new FileNotFoundException(jsonSubPath); - } - - var stream = _iStorage.ReadStream(jsonSubPath); - var jsonAsString = await StreamToStringHelper.StreamToStringAsync(stream); - var returnFileIndexItem = JsonSerializer.Deserialize(jsonAsString, DefaultJsonSerializer.CamelCase); - return returnFileIndexItem; - } + var stream = _iStorage.ReadStream(jsonSubPath); + var jsonAsString = await StreamToStringHelper.StreamToStringAsync(stream); + // JsonConverter + var returnFileIndexItem = + JsonSerializer.Deserialize(jsonAsString, DefaultJsonSerializer.CamelCase); + return returnFileIndexItem; } } diff --git a/starsky/starsky.foundation.video/GetDependencies/FFMpegDownload.cs b/starsky/starsky.foundation.video/GetDependencies/FFMpegDownload.cs index 8b5f6d765d..5b9c350d93 100644 --- a/starsky/starsky.foundation.video/GetDependencies/FFMpegDownload.cs +++ b/starsky/starsky.foundation.video/GetDependencies/FFMpegDownload.cs @@ -1,24 +1,30 @@ +using System.Text.Json; using starsky.foundation.http.Interfaces; using starsky.foundation.platform.Interfaces; +using starsky.foundation.platform.JsonConverter; using starsky.foundation.platform.Models; using starsky.foundation.storage.Interfaces; using starsky.foundation.storage.Storage; using starsky.foundation.video.GetDependencies.Interfaces; +using starsky.foundation.video.GetDependencies.Models; namespace starsky.foundation.video.GetDependencies; public class FfMpegDownload : IFfMpegDownload { private readonly AppSettings _appSettings; + + private readonly Uri _ffMpegApiIndex = + new("https://starsky-dependencies.netlify.app/ffmpeg/index.json"); + + private readonly Uri _ffMpegApiIndexMirror = + new("https://qdraw.nl/special/mirror/ffmpeg/index.json"); + private readonly IStorage _hostFileSystemStorage; private readonly IHttpClientHelper _httpClientHelper; private readonly IWebLogger _logger; private readonly Uri FFMpegApiBasePath = new("https://starsky-dependencies.netlify.app/ffmpeg"); - private readonly Uri _ffMpegApiIndex = - new("https://starsky-dependencies.netlify.app/ffmpeg/index.json"); - private readonly Uri _ffMpegApiIndex = - new("https://qdraw.nl/special/mirror/ffmpeg/index.json"); public FfMpegDownload(IHttpClientHelper httpClientHelper, AppSettings appSettings, IWebLogger logger) { @@ -42,17 +48,35 @@ public async Task DownloadFFMpeg() CreateDirectoryDependenciesFolderIfNotExists(); + var index = await DownloadIndex(); + await GetUrlFromIndex(index); + return true; } - private async Task DownloadIndex() + private async Task GetUrlFromIndex(FfmpegBinariesIndex? index) + { + return index?.Binaries.Find(p => p.Architecture == "win64"); + } + + private async Task DownloadIndex() { var result = await _httpClientHelper.ReadString(_ffMpegApiIndex); - if ( !result.Key ) + if ( result.Key ) { - _logger.LogError("[FfMpegDownload] Index not found"); - return; + return JsonSerializer.Deserialize(result.Value, + DefaultJsonSerializer.CamelCase); } + + result = await _httpClientHelper.ReadString(_ffMpegApiIndexMirror); + if ( result.Key ) + { + return JsonSerializer.Deserialize(result.Value, + DefaultJsonSerializer.CamelCase); + } + + _logger.LogError("[FfMpegDownload] Index not found"); + return new FfmpegBinariesIndex { Success = false }; } private async Task Download(Uri FFMpegDownloadBasePath) diff --git a/starsky/starsky.foundation.video/GetDependencies/GetVersionString.cs b/starsky/starsky.foundation.video/GetDependencies/GetVersionString.cs index 304489f11a..bf834b8cb4 100644 --- a/starsky/starsky.foundation.video/GetDependencies/GetVersionString.cs +++ b/starsky/starsky.foundation.video/GetDependencies/GetVersionString.cs @@ -4,50 +4,21 @@ namespace starsky.foundation.video.GetDependencies; public class GetVersionString { - private readonly IHttpClientHelper _httpClientHelper; - - public GetVersionString(IHttpClientHelper httpClientHelper) - { - _httpClientHelper = httpClientHelper; - } - /// - /// https://www.osxexperts.net/ + /// https://www.osxexperts.net/ /// private const string OsxArm64 = "https://www.osxexperts.net/ffmpeg71arm.zip"; private const string FfBinariesApi = "https://ffbinaries.com/api/v1/version/6.1"; - - public string GetVersion( - OperationSystemPlatforms.OSPlatformAndArchitecture osPlatformAndArchitecture) + private readonly IHttpClientHelper _httpClientHelper; + + public GetVersionString(IHttpClientHelper httpClientHelper) { - switch ( osPlatformAndArchitecture ) - { - case OperationSystemPlatforms.OSPlatformAndArchitecture.WinX86: - break; - case OperationSystemPlatforms.OSPlatformAndArchitecture.WinX64: - break; - case OperationSystemPlatforms.OSPlatformAndArchitecture.WinArm64: - break; - case OperationSystemPlatforms.OSPlatformAndArchitecture.LinuxX64: - break; - case OperationSystemPlatforms.OSPlatformAndArchitecture.LinuxArm: - break; - case OperationSystemPlatforms.OSPlatformAndArchitecture.LinuxArm64: - break; - case OperationSystemPlatforms.OSPlatformAndArchitecture.OsxX64: - break; - case OperationSystemPlatforms.OSPlatformAndArchitecture.OsxArm64: - return OsxArm64; - default: - throw new ArgumentOutOfRangeException(nameof(osPlatformAndArchitecture), - osPlatformAndArchitecture, null); - } + _httpClientHelper = httpClientHelper; } - private void GetApi() + private async Task GetApi() { await _httpClientHelper.ReadString(FfBinariesApi); - } } diff --git a/starsky/starsky.foundation.video/GetDependencies/Models/FfmpegBinariesIndex.cs b/starsky/starsky.foundation.video/GetDependencies/Models/FfmpegBinariesIndex.cs new file mode 100644 index 0000000000..6c450ff281 --- /dev/null +++ b/starsky/starsky.foundation.video/GetDependencies/Models/FfmpegBinariesIndex.cs @@ -0,0 +1,14 @@ +namespace starsky.foundation.video.GetDependencies.Models; + +public class BinaryIndex +{ + public string Architecture { get; set; } + public string Url { get; set; } + public string Sha256 { get; set; } +} + +public class FfmpegBinariesIndex +{ + public bool Success { get; set; } = true; + public List Binaries { get; set; } +} diff --git a/starsky/starsky.foundation.video/GetDependencies/OperationSystemPlatforms.cs b/starsky/starsky.foundation.video/GetDependencies/OperationSystemPlatforms.cs index 345bc32294..7f145d455f 100644 --- a/starsky/starsky.foundation.video/GetDependencies/OperationSystemPlatforms.cs +++ b/starsky/starsky.foundation.video/GetDependencies/OperationSystemPlatforms.cs @@ -4,7 +4,7 @@ namespace starsky.foundation.video.GetDependencies; public class OperationSystemPlatforms { - public enum OSPlatformAndArchitecture + public enum OsPlatformAndArchitecture { Unknown, [Display(Name = "win-x86")] diff --git a/starsky/starsky.foundation.video/starsky.foundation.video.csproj b/starsky/starsky.foundation.video/starsky.foundation.video.csproj index 1179d60406..5a7c1c3373 100644 --- a/starsky/starsky.foundation.video/starsky.foundation.video.csproj +++ b/starsky/starsky.foundation.video/starsky.foundation.video.csproj @@ -2,6 +2,10 @@ net8.0 + + {c6f6b684-f8eb-4dfd-9143-33f0262153fe} + 0.6.3 + starsky.foundation.sync enable enable diff --git a/starsky/starskytest/starsky.foundation.native/OpenApplicationNative/Helpers/MacOsOpenUrlTests.cs b/starsky/starskytest/starsky.foundation.native/OpenApplicationNative/Helpers/MacOsOpenUrlTests.cs index e0b1e94d41..d859ae4d93 100644 --- a/starsky/starskytest/starsky.foundation.native/OpenApplicationNative/Helpers/MacOsOpenUrlTests.cs +++ b/starsky/starskytest/starsky.foundation.native/OpenApplicationNative/Helpers/MacOsOpenUrlTests.cs @@ -6,8 +6,8 @@ using System.Threading.Tasks; using Medallion.Shell; using Microsoft.VisualStudio.TestTools.UnitTesting; -using starsky.foundation.native.Helpers; using starsky.foundation.native.OpenApplicationNative.Helpers; +using starsky.foundation.platform.Architecture; using starskytest.FakeCreateAn; namespace starskytest.starsky.foundation.native.OpenApplicationNative.Helpers; diff --git a/starsky/starskytest/starsky.foundation.native/OpenApplicationNative/OpenApplicationNativeServiceTest.cs b/starsky/starskytest/starsky.foundation.native/OpenApplicationNative/OpenApplicationNativeServiceTest.cs index ab923e2288..ec1e1f0fbe 100644 --- a/starsky/starskytest/starsky.foundation.native/OpenApplicationNative/OpenApplicationNativeServiceTest.cs +++ b/starsky/starskytest/starsky.foundation.native/OpenApplicationNative/OpenApplicationNativeServiceTest.cs @@ -1,16 +1,17 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.IO; using System.Runtime.InteropServices; using System.Threading.Tasks; using Microsoft.VisualStudio.TestTools.UnitTesting; using Microsoft.Win32; -using starsky.foundation.native.Helpers; using starsky.foundation.native.OpenApplicationNative; using starsky.foundation.native.OpenApplicationNative.Helpers; +using starsky.foundation.platform.Architecture; using starsky.foundation.platform.Models; using starskytest.FakeCreateAn.CreateFakeStarskyExe; -using starskytest.starsky.foundation.native.Helpers; +using starskytest.starsky.foundation.platform.Architecture; namespace starskytest.starsky.foundation.native.OpenApplicationNative; @@ -53,7 +54,7 @@ public void TestCleanup() CleanSetup(); } - [System.Diagnostics.CodeAnalysis.SuppressMessage("Interoperability", + [SuppressMessage("Interoperability", "CA1416:Validate platform compatibility", Justification = "Check does exists")] private static void CleanSetup() { @@ -69,15 +70,15 @@ private static void CleanSetup() Registry.CurrentUser.DeleteSubKeyTree($"Software\\Classes\\{Extension}", false); Registry.CurrentUser.DeleteSubKeyTree($"Software\\Classes\\{ProgramId}", false); } - catch ( IOException exception) + catch ( IOException exception ) { Console.WriteLine($"[CleanSetup] Skip due IOException {exception.Message}"); } - catch ( UnauthorizedAccessException exception) + catch ( UnauthorizedAccessException exception ) { - Console.WriteLine($"[CleanSetup] Skip due UnauthorizedAccessException {exception.Message}"); + Console.WriteLine( + $"[CleanSetup] Skip due UnauthorizedAccessException {exception.Message}"); } - } [TestMethod] diff --git a/starsky/starskytest/starsky.foundation.native/Trash/Helpers/MacOsTrashBindingHelperTest.cs b/starsky/starskytest/starsky.foundation.native/Trash/Helpers/MacOsTrashBindingHelperTest.cs index 94b2e03bd5..120e690986 100644 --- a/starsky/starskytest/starsky.foundation.native/Trash/Helpers/MacOsTrashBindingHelperTest.cs +++ b/starsky/starskytest/starsky.foundation.native/Trash/Helpers/MacOsTrashBindingHelperTest.cs @@ -5,8 +5,8 @@ using System.Runtime.InteropServices; using System.Threading.Tasks; using Microsoft.VisualStudio.TestTools.UnitTesting; -using starsky.foundation.native.Helpers; using starsky.foundation.native.Trash.Helpers; +using starsky.foundation.platform.Architecture; using starskytest.FakeCreateAn; namespace starskytest.starsky.foundation.native.Trash.Helpers; diff --git a/starsky/starskytest/starsky.foundation.native/Trash/TrashServiceTest.cs b/starsky/starskytest/starsky.foundation.native/Trash/TrashServiceTest.cs index e4255cd5f2..82460ee470 100644 --- a/starsky/starskytest/starsky.foundation.native/Trash/TrashServiceTest.cs +++ b/starsky/starskytest/starsky.foundation.native/Trash/TrashServiceTest.cs @@ -1,10 +1,10 @@ using System.Collections.Generic; using System.Runtime.InteropServices; using Microsoft.VisualStudio.TestTools.UnitTesting; -using starsky.foundation.native.Helpers; using starsky.foundation.native.Trash; using starsky.foundation.native.Trash.Helpers; -using starskytest.starsky.foundation.native.Helpers; +using starsky.foundation.platform.Architecture; +using starskytest.starsky.foundation.platform.Architecture; namespace starskytest.starsky.foundation.native.Trash; @@ -17,39 +17,39 @@ public void TrashService_CanUseSystemTrash1() var result = new TrashService().DetectToUseSystemTrash(); Assert.IsNotNull(result); } - + [TestMethod] public void TrashService_SingleItem_Trash() { var result = new TrashService().Trash("test"); - + // This feature is not working on Linux and FreeBSD - if ( OperatingSystemHelper.GetPlatform() == OSPlatform.Linux || + if ( OperatingSystemHelper.GetPlatform() == OSPlatform.Linux || OperatingSystemHelper.GetPlatform() == OSPlatform.FreeBSD ) { Assert.IsNull(result); return; } - + Assert.IsTrue(result); } - + [TestMethod] public void TrashService_List_Trash() { - var result = new TrashService().Trash(new List{"test"}); - + var result = new TrashService().Trash(new List { "test" }); + // This feature is not working on Linux and FreeBSD - if ( OperatingSystemHelper.GetPlatform() == OSPlatform.Linux || + if ( OperatingSystemHelper.GetPlatform() == OSPlatform.Linux || OperatingSystemHelper.GetPlatform() == OSPlatform.FreeBSD ) { Assert.IsNull(result); return; } - + Assert.IsTrue(result); } - + [TestMethod] public void DetectToUseSystemTrashInternal_Root_MacOs() { @@ -58,7 +58,7 @@ public void DetectToUseSystemTrashInternal_Root_MacOs() true, "root"); Assert.IsFalse(result); } - + [TestMethod] public void DetectToUseSystemTrashInternal_InteractiveFalse_MacOs() { @@ -67,8 +67,8 @@ public void DetectToUseSystemTrashInternal_InteractiveFalse_MacOs() false, "test"); Assert.IsFalse(result); } - - + + [TestMethod] public void DetectToUseSystemTrashInternal_Linux() { @@ -77,7 +77,7 @@ public void DetectToUseSystemTrashInternal_Linux() true, "test"); Assert.IsFalse(result); } - + [TestMethod] public void DetectToUseSystemTrashInternal_Windows_AsWindowsService_InteractiveFalse() { @@ -86,16 +86,16 @@ public void DetectToUseSystemTrashInternal_Windows_AsWindowsService_InteractiveF false, "test"); Assert.IsFalse(result); } - + [TestMethod] public void DetectToUseSystemTrashInternal_Windows_User() { - var (driveHasBin,_,_) = WindowsShellTrashBindingHelper.DriveHasRecycleBin(); - + var (driveHasBin, _, _) = WindowsShellTrashBindingHelper.DriveHasRecycleBin(); + var result = TrashService.DetectToUseSystemTrashInternal(FakeOsOverwrite.IsWindows, true, "test"); - + // output should be the same, different as WindowsShellTrashBindingHelper DriveHasRecycleBin Assert.AreEqual(driveHasBin, result); } diff --git a/starsky/starskytest/starsky.foundation.platform/Architecture/CurrentArchitectureTests.cs b/starsky/starskytest/starsky.foundation.platform/Architecture/CurrentArchitectureTests.cs new file mode 100644 index 0000000000..92672d524a --- /dev/null +++ b/starsky/starskytest/starsky.foundation.platform/Architecture/CurrentArchitectureTests.cs @@ -0,0 +1,80 @@ +using System; +using System.Runtime.InteropServices; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using starsky.foundation.platform.Architecture; + +namespace starskytest.starsky.foundation.platform.Architecture; + +[TestClass] +public class CurrentArchitectureTests +{ + [DataTestMethod] + [DataRow("Windows", "X86", "win-x86")] + [DataRow("Windows", "X64", "win-x64")] + [DataRow("Windows", "Arm", "win-arm")] + [DataRow("Windows", "Arm64", "win-arm64")] + [DataRow("Linux", "X86", "linux-x86")] + [DataRow("Linux", "X64", "linux-x64")] + [DataRow("Linux", "Arm", "linux-arm")] + [DataRow("Linux", "Arm64", "linux-arm64")] + [DataRow("OSX", "X86", "osx-x86")] + [DataRow("OSX", "X64", "osx-x64")] + [DataRow("OSX", "Arm", "osx-arm")] + [DataRow("OSX", "Arm64", "osx-arm64")] + public void GetCurrentRuntimeIdentifier_ShouldReturnExpectedIdentifier(string osPlatformString, + string architectureString, string expected) + { + // Arrange + var osPlatform = OSPlatform.Create(osPlatformString); + var architecture = + Enum.Parse(architectureString); + + // Act + var result = + CurrentArchitecture.GetCurrentRuntimeIdentifier(IsOsPlatformDelegate, + OsArchitectureDelegate); + + // Assert + Assert.AreEqual(expected, result); + + bool IsOsPlatformDelegate(OSPlatform platform) + { + return platform == osPlatform; + } + + System.Runtime.InteropServices.Architecture OsArchitectureDelegate() + { + return architecture; + } + } + + [TestMethod] + public void GetCurrentRuntimeIdentifier_CurrentOs() + { + var result = CurrentArchitecture.GetCurrentRuntimeIdentifier(); + + Assert.IsNotNull(result); + + Assert.IsTrue( + result.EndsWith(RuntimeInformation.OSArchitecture.ToString().ToLowerInvariant())); + + var platform = OperatingSystemHelper.GetPlatform(); + + if ( platform == OSPlatform.Windows ) + { + Assert.IsTrue(result.StartsWith("win")); + } + else if ( platform == OSPlatform.Linux || platform == OSPlatform.FreeBSD ) + { + Assert.IsTrue(result.StartsWith("linux")); + } + else if ( platform == OSPlatform.OSX ) + { + Assert.IsTrue(result.StartsWith("osx")); + } + else + { + Assert.IsTrue(result.StartsWith("unknown")); + } + } +} diff --git a/starsky/starskytest/starsky.foundation.native/Helpers/FakeOsOverwrite.cs b/starsky/starskytest/starsky.foundation.platform/Architecture/FakeOsOverwrite.cs similarity index 90% rename from starsky/starskytest/starsky.foundation.native/Helpers/FakeOsOverwrite.cs rename to starsky/starskytest/starsky.foundation.platform/Architecture/FakeOsOverwrite.cs index 5ce2eee945..8f2645adae 100644 --- a/starsky/starskytest/starsky.foundation.native/Helpers/FakeOsOverwrite.cs +++ b/starsky/starskytest/starsky.foundation.platform/Architecture/FakeOsOverwrite.cs @@ -1,6 +1,6 @@ using System.Runtime.InteropServices; -namespace starskytest.starsky.foundation.native.Helpers; +namespace starskytest.starsky.foundation.platform.Architecture; internal static class FakeOsOverwrite { @@ -23,7 +23,7 @@ internal static bool IsFreeBsd(OSPlatform osPlatform) { return osPlatform == OSPlatform.FreeBSD; } - + internal static bool IsUnknown(OSPlatform osPlatform) { return osPlatform == OSPlatform.Create("Unknown"); diff --git a/starsky/starskytest/starsky.foundation.native/Helpers/OperatingSystemHelperTest.cs b/starsky/starskytest/starsky.foundation.platform/Architecture/OperatingSystemHelperTest.cs similarity index 91% rename from starsky/starskytest/starsky.foundation.native/Helpers/OperatingSystemHelperTest.cs rename to starsky/starskytest/starsky.foundation.platform/Architecture/OperatingSystemHelperTest.cs index a90020a17a..5f5b606e9d 100644 --- a/starsky/starskytest/starsky.foundation.native/Helpers/OperatingSystemHelperTest.cs +++ b/starsky/starskytest/starsky.foundation.platform/Architecture/OperatingSystemHelperTest.cs @@ -1,8 +1,8 @@ using System.Runtime.InteropServices; using Microsoft.VisualStudio.TestTools.UnitTesting; -using starsky.foundation.native.Helpers; +using starsky.foundation.platform.Architecture; -namespace starskytest.starsky.foundation.native.Helpers; +namespace starskytest.starsky.foundation.platform.Architecture; [TestClass] public class OperatingSystemHelperTest @@ -13,36 +13,36 @@ public void OperatingSystemHelper1() var result = OperatingSystemHelper.GetPlatform(); Assert.IsNotNull(result); } - + [TestMethod] public void OperatingSystemHelper_Windows() { var result = OperatingSystemHelper.GetPlatformInternal(FakeOsOverwrite.IsWindows); Assert.AreEqual(OSPlatform.Windows, result); } - + [TestMethod] public void OperatingSystemHelper_MacOs() { var result = OperatingSystemHelper.GetPlatformInternal(FakeOsOverwrite.IsMacOs); Assert.AreEqual(OSPlatform.OSX, result); } - + [TestMethod] public void OperatingSystemHelper_Linux() { var result = OperatingSystemHelper.GetPlatformInternal(FakeOsOverwrite.IsLinux); Assert.AreEqual(OSPlatform.Linux, result); } - + [TestMethod] public void OperatingSystemHelper_FreeBsd() { var result = OperatingSystemHelper.GetPlatformInternal(FakeOsOverwrite.IsFreeBsd); Assert.AreEqual(OSPlatform.FreeBSD, result); } - - + + [TestMethod] public void OperatingSystemHelper_Other() { From 648ea20990783df51521cf4f4def65b1bec9dd6f Mon Sep 17 00:00:00 2001 From: Dion Date: Fri, 22 Nov 2024 22:14:09 +0100 Subject: [PATCH 15/73] #1833 removve --- .../GetDependencies/GetVersionString.cs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/starsky/starsky.foundation.video/GetDependencies/GetVersionString.cs b/starsky/starsky.foundation.video/GetDependencies/GetVersionString.cs index bf834b8cb4..ed1dee42b0 100644 --- a/starsky/starsky.foundation.video/GetDependencies/GetVersionString.cs +++ b/starsky/starsky.foundation.video/GetDependencies/GetVersionString.cs @@ -4,12 +4,6 @@ namespace starsky.foundation.video.GetDependencies; public class GetVersionString { - /// - /// https://www.osxexperts.net/ - /// - private const string OsxArm64 = "https://www.osxexperts.net/ffmpeg71arm.zip"; - - private const string FfBinariesApi = "https://ffbinaries.com/api/v1/version/6.1"; private readonly IHttpClientHelper _httpClientHelper; public GetVersionString(IHttpClientHelper httpClientHelper) @@ -19,6 +13,6 @@ public GetVersionString(IHttpClientHelper httpClientHelper) private async Task GetApi() { - await _httpClientHelper.ReadString(FfBinariesApi); + await _httpClientHelper.ReadString(""); } } From a47e20c6ebe20af2b700a552dd0dc128cf2f3830 Mon Sep 17 00:00:00 2001 From: Dion Date: Sun, 1 Dec 2024 19:36:19 +0100 Subject: [PATCH 16/73] #1833 add wrapper --- .../GetDependencies/FFMpegDownload.cs | 27 +++++++++++-------- .../Models/FfmpegBinariesIndex.cs | 15 ++++++++++- .../OperationSystemPlatforms.bak | 27 +++++++++++++++++++ 3 files changed, 57 insertions(+), 12 deletions(-) create mode 100644 starsky/starsky.foundation.video/GetDependencies/OperationSystemPlatforms.bak diff --git a/starsky/starsky.foundation.video/GetDependencies/FFMpegDownload.cs b/starsky/starsky.foundation.video/GetDependencies/FFMpegDownload.cs index 5b9c350d93..c146ad2fb1 100644 --- a/starsky/starsky.foundation.video/GetDependencies/FFMpegDownload.cs +++ b/starsky/starsky.foundation.video/GetDependencies/FFMpegDownload.cs @@ -1,5 +1,6 @@ using System.Text.Json; using starsky.foundation.http.Interfaces; +using starsky.foundation.platform.Architecture; using starsky.foundation.platform.Interfaces; using starsky.foundation.platform.JsonConverter; using starsky.foundation.platform.Models; @@ -34,9 +35,9 @@ public FfMpegDownload(IHttpClientHelper httpClientHelper, AppSettings appSetting _logger = logger; } - public async Task DownloadFFMpeg() + public async Task DownloadFfMpeg() { - if ( _appSettings.ExiftoolSkipDownloadOnStartup == true || _appSettings is + if ( _appSettings.FfmpegSkipDownloadOnStartup == true || _appSettings is { AddSwaggerExport: true, AddSwaggerExportExitAfter: true } ) { var name = _appSettings.FfmpegSkipDownloadOnStartup == true @@ -48,29 +49,33 @@ public async Task DownloadFFMpeg() CreateDirectoryDependenciesFolderIfNotExists(); + var currentArchitecture = CurrentArchitecture.GetCurrentRuntimeIdentifier(); + var index = await DownloadIndex(); - await GetUrlFromIndex(index); + var data = GetUrlFromIndex(index, currentArchitecture); return true; } - private async Task GetUrlFromIndex(FfmpegBinariesIndex? index) + private BinaryIndex? GetUrlFromIndex(FfmpegBinariesIndex? index, + string currentArchitecture) { - return index?.Binaries.Find(p => p.Architecture == "win64"); + return index?.Binaries.Find(p => p.Architecture == currentArchitecture); } - private async Task DownloadIndex() + private async Task DownloadIndex() { - var result = await _httpClientHelper.ReadString(_ffMpegApiIndex); - if ( result.Key ) + var result = new FfmpegBinariesContainer(null, false, null); + var apiResult = await _httpClientHelper.ReadString(_ffMpegApiIndex); + if ( apiResult.Key ) { - return JsonSerializer.Deserialize(result.Value, - DefaultJsonSerializer.CamelCase); + return ; } - result = await _httpClientHelper.ReadString(_ffMpegApiIndexMirror); + apiResult = await _httpClientHelper.ReadString(_ffMpegApiIndexMirror); if ( result.Key ) { + result. return JsonSerializer.Deserialize(result.Value, DefaultJsonSerializer.CamelCase); } diff --git a/starsky/starsky.foundation.video/GetDependencies/Models/FfmpegBinariesIndex.cs b/starsky/starsky.foundation.video/GetDependencies/Models/FfmpegBinariesIndex.cs index 6c450ff281..8b92876372 100644 --- a/starsky/starsky.foundation.video/GetDependencies/Models/FfmpegBinariesIndex.cs +++ b/starsky/starsky.foundation.video/GetDependencies/Models/FfmpegBinariesIndex.cs @@ -9,6 +9,19 @@ public class BinaryIndex public class FfmpegBinariesIndex { - public bool Success { get; set; } = true; public List Binaries { get; set; } } + +public class FfmpegBinariesContainer { + + public FfmpegBinariesContainer(Uri? indexUrl, bool success, FfmpegBinariesIndex? data) + { + Data = data; + IndexUrl = indexUrl; + Success = success; + } + + public bool Success { get; set; } + public Uri? IndexUrl { get; set; } + public FfmpegBinariesIndex? Data { get; set; } +} diff --git a/starsky/starsky.foundation.video/GetDependencies/OperationSystemPlatforms.bak b/starsky/starsky.foundation.video/GetDependencies/OperationSystemPlatforms.bak new file mode 100644 index 0000000000..7f145d455f --- /dev/null +++ b/starsky/starsky.foundation.video/GetDependencies/OperationSystemPlatforms.bak @@ -0,0 +1,27 @@ +using System.ComponentModel.DataAnnotations; + +namespace starsky.foundation.video.GetDependencies; + +public class OperationSystemPlatforms +{ + public enum OsPlatformAndArchitecture + { + Unknown, + [Display(Name = "win-x86")] + WinX86, + [Display(Name = "win-x64")] + WinX64, + [Display(Name = "win-arm64")] + WinArm64, + [Display(Name = "linux-x64")] + LinuxX64, + [Display(Name = "linux-arm")] + LinuxArm, + [Display(Name = "linux-arm64")] + LinuxArm64, + [Display(Name = "osx-x64")] + OsxX64, + [Display(Name = "osx-arm64")] + OsxArm64 + } +} From 5978ec92d6bcdcea6f043881dd0f4a21c10cd080 Mon Sep 17 00:00:00 2001 From: Dion Date: Tue, 3 Dec 2024 08:38:36 +0100 Subject: [PATCH 17/73] #1833 add parsing data --- .../GetDependencies/FFMpegDownload.cs | 56 ++++++++----------- .../GetDependencies/FfMpegDownloadIndex.cs | 38 +++++++++++++ .../Models/FfmpegBinariesIndex.cs | 38 +++++++++---- .../starsky.foundation.video.csproj | 2 +- 4 files changed, 90 insertions(+), 44 deletions(-) create mode 100644 starsky/starsky.foundation.video/GetDependencies/FfMpegDownloadIndex.cs diff --git a/starsky/starsky.foundation.video/GetDependencies/FFMpegDownload.cs b/starsky/starsky.foundation.video/GetDependencies/FFMpegDownload.cs index c146ad2fb1..9a89e0af3a 100644 --- a/starsky/starsky.foundation.video/GetDependencies/FFMpegDownload.cs +++ b/starsky/starsky.foundation.video/GetDependencies/FFMpegDownload.cs @@ -1,8 +1,6 @@ -using System.Text.Json; using starsky.foundation.http.Interfaces; using starsky.foundation.platform.Architecture; using starsky.foundation.platform.Interfaces; -using starsky.foundation.platform.JsonConverter; using starsky.foundation.platform.Models; using starsky.foundation.storage.Interfaces; using starsky.foundation.storage.Storage; @@ -14,17 +12,9 @@ namespace starsky.foundation.video.GetDependencies; public class FfMpegDownload : IFfMpegDownload { private readonly AppSettings _appSettings; - - private readonly Uri _ffMpegApiIndex = - new("https://starsky-dependencies.netlify.app/ffmpeg/index.json"); - - private readonly Uri _ffMpegApiIndexMirror = - new("https://qdraw.nl/special/mirror/ffmpeg/index.json"); - private readonly IStorage _hostFileSystemStorage; private readonly IHttpClientHelper _httpClientHelper; private readonly IWebLogger _logger; - private readonly Uri FFMpegApiBasePath = new("https://starsky-dependencies.netlify.app/ffmpeg"); public FfMpegDownload(IHttpClientHelper httpClientHelper, AppSettings appSettings, IWebLogger logger) @@ -50,42 +40,42 @@ public async Task DownloadFfMpeg() CreateDirectoryDependenciesFolderIfNotExists(); var currentArchitecture = CurrentArchitecture.GetCurrentRuntimeIdentifier(); - - var index = await DownloadIndex(); - var data = GetUrlFromIndex(index, currentArchitecture); + var container = await new FfMpegDownloadIndex(_httpClientHelper, _logger).DownloadIndex(); + var binaryIndexBaseUrls = GetCurrentArchitectureIndexUrls(container, + currentArchitecture); + + await Download(binaryIndexBaseUrls); + return true; } - private BinaryIndex? GetUrlFromIndex(FfmpegBinariesIndex? index, + private static KeyValuePair> GetCurrentArchitectureIndexUrls( + FfmpegBinariesContainer container, string currentArchitecture) { - return index?.Binaries.Find(p => p.Architecture == currentArchitecture); + var sortedData = container.Data?.Binaries.Find(p => + p.Architecture == currentArchitecture); + + return new KeyValuePair>(sortedData, container.BaseUrls); } - private async Task DownloadIndex() + private async Task Download(KeyValuePair> binaryIndexKeyValuePair) { - var result = new FfmpegBinariesContainer(null, false, null); - var apiResult = await _httpClientHelper.ReadString(_ffMpegApiIndex); - if ( apiResult.Key ) - { - return ; - } + var ( binaryIndex, baseUrls ) = binaryIndexKeyValuePair; - apiResult = await _httpClientHelper.ReadString(_ffMpegApiIndexMirror); - if ( result.Key ) + if ( !_hostFileSystemStorage.ExistFile( + Path.Combine(_appSettings.DependenciesFolder, binaryIndex.Url)) ) { - result. - return JsonSerializer.Deserialize(result.Value, - DefaultJsonSerializer.CamelCase); - } - _logger.LogError("[FfMpegDownload] Index not found"); - return new FfmpegBinariesIndex { Success = false }; - } + foreach ( var baseUrl in baseUrls ) + { - private async Task Download(Uri FFMpegDownloadBasePath) - { + + var uri = new Uri(baseUrl + binaryIndex.Url); + + } + // if ( !_hostFileSystemStorage.ExistFile( // Path.Combine(_appSettings.DependenciesFolder, CountryName + ".txt")) ) // { diff --git a/starsky/starsky.foundation.video/GetDependencies/FfMpegDownloadIndex.cs b/starsky/starsky.foundation.video/GetDependencies/FfMpegDownloadIndex.cs new file mode 100644 index 0000000000..373a41857d --- /dev/null +++ b/starsky/starsky.foundation.video/GetDependencies/FfMpegDownloadIndex.cs @@ -0,0 +1,38 @@ +using starsky.foundation.http.Interfaces; +using starsky.foundation.platform.Interfaces; +using starsky.foundation.video.GetDependencies.Models; + +namespace starsky.foundation.video.GetDependencies; + +public class FfMpegDownloadIndex(IHttpClientHelper httpClientHelper, IWebLogger logger) +{ + private const string QdrawMirrorDomain = "qdraw.nl/special/mirror/ffmpeg"; + private const string NetlifyMirrorDomain = "starsky-dependencies.netlify.app/ffmpeg"; + + private static readonly Uri FfMpegApiBasePath = new($"https://{NetlifyMirrorDomain}"); + private static readonly Uri FfMpegApiBasePathMirror = new($"https://{NetlifyMirrorDomain}"); + private static readonly List BaseUris = [FfMpegApiBasePath, FfMpegApiBasePathMirror]; + + private readonly Uri _ffMpegApiIndex = new($"https://{NetlifyMirrorDomain}/index.json"); + private readonly Uri _ffMpegApiIndexMirror = new($"https://{QdrawMirrorDomain}/index.json"); + + public async Task DownloadIndex() + { + var apiResult = await httpClientHelper.ReadString(_ffMpegApiIndex); + if ( apiResult.Key ) + { + return new FfmpegBinariesContainer(apiResult.Value, _ffMpegApiIndex, BaseUris, + true); + } + + apiResult = await httpClientHelper.ReadString(_ffMpegApiIndexMirror); + if ( apiResult.Key ) + { + return new FfmpegBinariesContainer(apiResult.Value, _ffMpegApiIndexMirror, + BaseUris, true); + } + + logger.LogError("[FfMpegDownload] Index not found"); + return new FfmpegBinariesContainer(string.Empty, null, [], false); + } +} diff --git a/starsky/starsky.foundation.video/GetDependencies/Models/FfmpegBinariesIndex.cs b/starsky/starsky.foundation.video/GetDependencies/Models/FfmpegBinariesIndex.cs index 8b92876372..b026aac434 100644 --- a/starsky/starsky.foundation.video/GetDependencies/Models/FfmpegBinariesIndex.cs +++ b/starsky/starsky.foundation.video/GetDependencies/Models/FfmpegBinariesIndex.cs @@ -1,27 +1,45 @@ +using System.Text.Json; +using starsky.foundation.platform.JsonConverter; + namespace starsky.foundation.video.GetDependencies.Models; public class BinaryIndex { - public string Architecture { get; set; } - public string Url { get; set; } - public string Sha256 { get; set; } + public string Architecture { get; set; } + public string Url { get; set; } + public string Sha256 { get; set; } } public class FfmpegBinariesIndex { - public List Binaries { get; set; } + public List Binaries { get; set; } } -public class FfmpegBinariesContainer { - - public FfmpegBinariesContainer(Uri? indexUrl, bool success, FfmpegBinariesIndex? data) +public class FfmpegBinariesContainer +{ + public FfmpegBinariesContainer(string apiResultValue, Uri? indexUrl, List baseUrls, + bool success) { - Data = data; + Data = ParseIndex(apiResultValue); IndexUrl = indexUrl; + BaseUrls = baseUrls; Success = success; } - + + public List BaseUrls { get; set; } + public bool Success { get; set; } public Uri? IndexUrl { get; set; } - public FfmpegBinariesIndex? Data { get; set; } + public FfmpegBinariesIndex? Data { get; set; } + + private static FfmpegBinariesIndex? ParseIndex(string apiResultValue) + { + if ( string.IsNullOrEmpty(apiResultValue) ) + { + return null; + } + + return JsonSerializer.Deserialize(apiResultValue, + DefaultJsonSerializer.CamelCase); + } } diff --git a/starsky/starsky.foundation.video/starsky.foundation.video.csproj b/starsky/starsky.foundation.video/starsky.foundation.video.csproj index 5a7c1c3373..a4f6bd5b99 100644 --- a/starsky/starsky.foundation.video/starsky.foundation.video.csproj +++ b/starsky/starsky.foundation.video/starsky.foundation.video.csproj @@ -5,7 +5,7 @@ {c6f6b684-f8eb-4dfd-9143-33f0262153fe} 0.6.3 - starsky.foundation.sync + starsky.foundation.video enable enable From eb97643247b1f1e12a2017fe349c3a6961e387a2 Mon Sep 17 00:00:00 2001 From: Dion Date: Sun, 8 Dec 2024 10:51:32 +0100 Subject: [PATCH 18/73] code signing, http client extensions, xttr mac os, cleanup folders test, fix for MACOS zip files --- .../Interfaces/IHttpClientHelper.cs | 1 + .../Services/HttpClientHelper.cs | 37 +- .../ArchiveFormats/Zipper.cs | 180 +- .../Helpers/CheckSha256Helper.cs | 28 + starsky/starsky.foundation.video/Class1.cs | 5 - .../GetDependencies/FFMpegDownload.cs | 188 +- .../GetDependencies/FfMpegDownloadIndex.cs | 6 +- .../GetDependencies/MacCodeSign.cs | 62 + .../Models/FfmpegBinariesIndex.cs | 2 +- .../OperationSystemPlatforms.bak | 27 - .../OperationSystemPlatforms.cs | 27 - .../starsky.foundation.video.csproj | 4 + .../Services/ExifToolDownload.cs | 42 +- starsky/starsky.sln | 7 + .../Controllers/AppSettingsControllerTest.cs | 11 +- .../starskytest/FakeCreateAn/CreateAnGpx.cs | 309 +-- .../CreateAnZipFileMacOs.cs | 26 + .../CreateAnZipFileMacOs/macOsSubfolder.zip | Bin 0 -> 288 bytes .../FakeMocks/FakeIHttpClientHelper.cs | 6 + .../Helpers/FileStreamingHelperTest.cs | 28 +- .../Services/CleanDemoDataServiceTest.cs | 2 +- .../Services/GeoIndexGpxTest.cs | 6 + .../SpecificVersionReleaseInfoTest.cs | 41 +- .../Helpers/PackageTelemetryTest.cs | 501 ++--- .../Services/RenameServiceTest.cs | 1795 ++++++++--------- .../Services/UpdateAppSettingsByPathTest.cs | 374 ++-- .../Helpers/HttpClientHelperTest.cs | 646 +++--- .../Extensions/MemoryCacheExtensionsTest.cs | 4 +- .../ArchiveFormats/ZipperTest.cs | 68 +- .../Helpers/CheckSha256HelperTest.cs | 33 + .../Storage/StorageThumbnailFilesystemTest.cs | 333 ++- .../GetDependencies/FfMpegDownloadTest.cs | 28 + .../Helpers/ExifToolDownloadTest.cs | 1184 ++++++----- .../Services/ExifToolServiceTest.cs | 33 +- starsky/starskytest/starskytest.csproj | 19 +- 35 files changed, 3210 insertions(+), 2853 deletions(-) create mode 100644 starsky/starsky.foundation.storage/Helpers/CheckSha256Helper.cs delete mode 100644 starsky/starsky.foundation.video/Class1.cs create mode 100644 starsky/starsky.foundation.video/GetDependencies/MacCodeSign.cs delete mode 100644 starsky/starsky.foundation.video/GetDependencies/OperationSystemPlatforms.bak delete mode 100644 starsky/starsky.foundation.video/GetDependencies/OperationSystemPlatforms.cs create mode 100644 starsky/starskytest/FakeCreateAn/CreateAnZipFileMacOs/CreateAnZipFileMacOs.cs create mode 100644 starsky/starskytest/FakeCreateAn/CreateAnZipFileMacOs/macOsSubfolder.zip create mode 100644 starsky/starskytest/starsky.foundation.storage/Helpers/CheckSha256HelperTest.cs create mode 100644 starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadTest.cs diff --git a/starsky/starsky.foundation.http/Interfaces/IHttpClientHelper.cs b/starsky/starsky.foundation.http/Interfaces/IHttpClientHelper.cs index 9d54105364..604f2edf3e 100644 --- a/starsky/starsky.foundation.http/Interfaces/IHttpClientHelper.cs +++ b/starsky/starsky.foundation.http/Interfaces/IHttpClientHelper.cs @@ -7,6 +7,7 @@ namespace starsky.foundation.http.Interfaces; public interface IHttpClientHelper { + Task Download(Uri sourceUri, string fullLocalPath, int retryAfterInSeconds = 15); Task Download(string sourceHttpUrl, string fullLocalPath, int retryAfterInSeconds = 15); Task> ReadString(string sourceHttpUrl); Task> ReadString(Uri sourceHttpUrl); diff --git a/starsky/starsky.foundation.http/Services/HttpClientHelper.cs b/starsky/starsky.foundation.http/Services/HttpClientHelper.cs index 28278ca7d0..1c1ff56063 100644 --- a/starsky/starsky.foundation.http/Services/HttpClientHelper.cs +++ b/starsky/starsky.foundation.http/Services/HttpClientHelper.cs @@ -3,6 +3,7 @@ using System.IO; using System.Net; using System.Net.Http; +using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; @@ -13,6 +14,8 @@ using starsky.foundation.storage.Interfaces; using starsky.foundation.storage.Storage; +[assembly: InternalsVisibleTo("starskytest")] + namespace starsky.foundation.http.Services; [Service(typeof(IHttpClientHelper), InjectionLifetime = InjectionLifetime.Singleton)] @@ -24,12 +27,13 @@ public sealed class HttpClientHelper : IHttpClientHelper private readonly List _allowedDomains = [ "dl.dropboxusercontent.com", - "qdraw.nl", // < used by test + "qdraw.nl", // < used by test and dependencies "media.qdraw.nl", // < used by demo "locker.ifttt.com", "download.geonames.org", "exiftool.org", - "api.github.com" + "api.github.com", + "starsky-dependencies.netlify.app" ]; /// @@ -40,6 +44,14 @@ public sealed class HttpClientHelper : IHttpClientHelper private readonly IWebLogger _logger; private readonly IStorage? _storage; + internal HttpClientHelper(IHttpProvider httpProvider, + IStorage? storage, IWebLogger logger) + { + _httpProvider = httpProvider; + _logger = logger; + _storage = storage; + } + /// /// Set Http Provider /// @@ -133,14 +145,21 @@ public async Task> PostString(string sourceHttpUrl, } } + public async Task Download(string sourceHttpUrl, string fullLocalPath, + int retryAfterInSeconds = 15) + { + var sourceUri = new Uri(sourceHttpUrl); + return await Download(sourceUri, fullLocalPath, retryAfterInSeconds); + } + /// /// Downloads the specified source HTTPS URL. /// - /// The source HTTPS URL. + /// The source HTTPS URL. /// The full local path. /// Retry after number of seconds /// - public async Task Download(string sourceHttpUrl, string fullLocalPath, + public async Task Download(Uri sourceUri, string fullLocalPath, int retryAfterInSeconds = 15) { if ( _storage == null ) @@ -148,28 +167,26 @@ public async Task Download(string sourceHttpUrl, string fullLocalPath, throw new EndOfStreamException("is null " + nameof(_storage)); } - var sourceUri = new Uri(sourceHttpUrl); - _logger.LogInformation("[Download] HttpClientHelper > " - + sourceUri.Host + " ~ " + sourceHttpUrl); + + " ~ " + sourceUri); // allow whitelist and https only if ( !_allowedDomains.Contains(sourceUri.Host) || sourceUri.Scheme != "https" ) { _logger.LogInformation("[Download] HttpClientHelper > " - + "skip: domain not whitelisted " + " ~ " + sourceHttpUrl); + + "skip: domain not whitelisted " + " ~ " + sourceUri); return false; } async Task DownloadAsync() { - using var response = await _httpProvider.GetAsync(sourceHttpUrl); + using var response = await _httpProvider.GetAsync(sourceUri.ToString()); await using var streamToReadFrom = await response.Content.ReadAsStreamAsync(); if ( response.StatusCode != HttpStatusCode.OK ) { _logger.LogInformation("[Download] HttpClientHelper > " + - response.StatusCode + " ~ " + sourceHttpUrl); + response.StatusCode + " ~ " + sourceUri); return false; } diff --git a/starsky/starsky.foundation.storage/ArchiveFormats/Zipper.cs b/starsky/starsky.foundation.storage/ArchiveFormats/Zipper.cs index eed6e94462..d396ddf456 100644 --- a/starsky/starsky.foundation.storage/ArchiveFormats/Zipper.cs +++ b/starsky/starsky.foundation.storage/ArchiveFormats/Zipper.cs @@ -7,119 +7,131 @@ using starsky.foundation.platform.Interfaces; using starsky.foundation.storage.Storage; -namespace starsky.foundation.storage.ArchiveFormats +namespace starsky.foundation.storage.ArchiveFormats; + +[SuppressMessage("Performance", "CA1822:Mark members as static")] +[SuppressMessage("ReSharper", "MemberCanBeMadeStatic.Global")] +public sealed class Zipper { - [SuppressMessage("Performance", "CA1822:Mark members as static")] - [SuppressMessage("ReSharper", "MemberCanBeMadeStatic.Global")] - public sealed class Zipper + private readonly StorageHostFullPathFilesystem _hostStorage; + + public Zipper(IWebLogger logger) { - private readonly StorageHostFullPathFilesystem _hostStorage; + _hostStorage = new StorageHostFullPathFilesystem(logger); + } - public Zipper(IWebLogger logger) + /// + /// Extract zip file to a folder + /// + /// input e.g: /path/file.zip + /// output e.g. /folder/ + /// + [SuppressMessage("Usage", "S5042:Make sure that decompressing this archive file is safe")] + public bool ExtractZip(string zipInputFullPath, string storeZipFolderFullPath) + { + if ( !File.Exists(zipInputFullPath) ) { - _hostStorage = new StorageHostFullPathFilesystem(logger); + return false; } - /// - /// Extract zip file to a folder - /// - /// input e.g: /path/file.zip - /// output e.g. /folder/ - /// - [SuppressMessage("Usage", "S5042:Make sure that decompressing this archive file is safe")] - public bool ExtractZip(string zipInputFullPath, string storeZipFolderFullPath) + // Ensures that the last character on the extraction path + // is the directory separator char. + // Without this, a malicious zip file could try to traverse outside of the expected + // extraction path. + storeZipFolderFullPath = PathHelper.AddBackslash(storeZipFolderFullPath); + using ( var archive = ZipFile.OpenRead(zipInputFullPath) ) { - if ( !File.Exists(zipInputFullPath) ) - { - return false; - } - // Ensures that the last character on the extraction path - // is the directory separator char. - // Without this, a malicious zip file could try to traverse outside of the expected - // extraction path. - storeZipFolderFullPath = PathHelper.AddBackslash(storeZipFolderFullPath); - using ( var archive = ZipFile.OpenRead(zipInputFullPath) ) + foreach ( var entry in archive.Entries ) { - foreach ( var entry in archive.Entries ) + // Gets the full path to ensure that relative segments are removed. + var destinationPath = + Path.GetFullPath(Path.Combine(storeZipFolderFullPath, entry.FullName)); + + // Ordinal match is safest, case-sensitive volumes can be mounted within volumes that + // are case-insensitive. + if ( !destinationPath.StartsWith(storeZipFolderFullPath, + StringComparison.Ordinal) ) { - // Gets the full path to ensure that relative segments are removed. - var destinationPath = Path.GetFullPath(Path.Combine(storeZipFolderFullPath, entry.FullName)); + continue; + } - // Ordinal match is safest, case-sensitive volumes can be mounted within volumes that - // are case-insensitive. - if ( !destinationPath.StartsWith(storeZipFolderFullPath, - StringComparison.Ordinal) ) + // Folders inside zips give sometimes issues + if ( entry.FullName.EndsWith('/') ) + { + if ( !_hostStorage.ExistFolder(destinationPath) ) { - continue; + _hostStorage.CreateDirectory(destinationPath); } - // Folders inside zips give sometimes issues - if ( entry.FullName.EndsWith('/') ) - { - if ( !_hostStorage.ExistFolder(destinationPath) ) - { - _hostStorage.CreateDirectory(destinationPath); - } - continue; - } + continue; + } + try + { + entry.ExtractToFile(destinationPath, true); + } + catch ( DirectoryNotFoundException ) + { + Console.WriteLine("Directory not found: " + destinationPath); + Directory.GetParent(destinationPath)?.Create(); entry.ExtractToFile(destinationPath, true); } } - - return true; } - public static Dictionary ExtractZip(byte[] zipped) + return true; + } + + public static Dictionary ExtractZip(byte[] zipped) + { + using var memoryStream = new MemoryStream(zipped); + using var archive = new ZipArchive(memoryStream); + var result = new Dictionary(); + foreach ( var entry in archive.Entries ) { - using var memoryStream = new MemoryStream(zipped); - using var archive = new ZipArchive(memoryStream); - var result = new Dictionary(); - foreach ( var entry in archive.Entries ) - { - // only the first item - using var entryStream = entry.Open(); - using var reader = new BinaryReader(entryStream); - result.Add(entry.FullName, reader.ReadBytes(( int ) entry.Length)); - } - return result; + // only the first item + using var entryStream = entry.Open(); + using var reader = new BinaryReader(entryStream); + result.Add(entry.FullName, reader.ReadBytes(( int ) entry.Length)); } + return result; + } - /// - /// To Create the zip file in the storeZipFolderFullPath folder - /// Skip if zip file already exist - /// - /// folder to create zip in - /// list of full file paths - /// list of filenames - /// to name of the zip file (zipHash) - /// a zip in the temp folder - [SuppressMessage("Usage", "S2325:Make CreateZip a static method")] - public string CreateZip(string storeZipFolderFullPath, List filePaths, - List fileNames, string zipOutputFilename) - { - var tempFileFullPath = Path.Combine(storeZipFolderFullPath, zipOutputFilename) + ".zip"; + /// + /// To Create the zip file in the storeZipFolderFullPath folder + /// Skip if zip file already exist + /// + /// folder to create zip in + /// list of full file paths + /// list of filenames + /// to name of the zip file (zipHash) + /// a zip in the temp folder + [SuppressMessage("Usage", "S2325:Make CreateZip a static method")] + public string CreateZip(string storeZipFolderFullPath, List filePaths, + List fileNames, string zipOutputFilename) + { + var tempFileFullPath = Path.Combine(storeZipFolderFullPath, zipOutputFilename) + ".zip"; - // Has a direct dependency on the filesystem to avoid large content in memory - if ( File.Exists(tempFileFullPath) ) - { - return tempFileFullPath; - } + // Has a direct dependency on the filesystem to avoid large content in memory + if ( File.Exists(tempFileFullPath) ) + { + return tempFileFullPath; + } - ZipArchive zip = ZipFile.Open(tempFileFullPath, ZipArchiveMode.Create); + var zip = ZipFile.Open(tempFileFullPath, ZipArchiveMode.Create); - for ( int i = 0; i < filePaths.Count; i++ ) + for ( var i = 0; i < filePaths.Count; i++ ) + { + if ( File.Exists(filePaths[i]) ) { - if ( File.Exists(filePaths[i]) ) - { - var fileName = fileNames[i]; - zip.CreateEntryFromFile(filePaths[i], fileName); - } + var fileName = fileNames[i]; + zip.CreateEntryFromFile(filePaths[i], fileName); } - zip.Dispose(); // no flush - return tempFileFullPath; } + + zip.Dispose(); // no flush + return tempFileFullPath; } } diff --git a/starsky/starsky.foundation.storage/Helpers/CheckSha256Helper.cs b/starsky/starsky.foundation.storage/Helpers/CheckSha256Helper.cs new file mode 100644 index 0000000000..8c00e83316 --- /dev/null +++ b/starsky/starsky.foundation.storage/Helpers/CheckSha256Helper.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Security.Cryptography; +using starsky.foundation.storage.Interfaces; + +namespace starsky.foundation.storage.Helpers; + +public class CheckSha256Helper(IStorage hostFileSystemStorage) +{ + /// + /// Check if SHA256 hash is valid + /// Instead of SHA1CryptoServiceProvider, we use SHA256.Create + /// + /// path of exiftool.exe + /// list of SHA256 hashes + /// + public bool CheckSha256(string fullFilePath, IEnumerable checkSumOptions) + { + using var buffer = hostFileSystemStorage.ReadStream(fullFilePath); + using var hashAlgorithm = SHA256.Create(); + + var byteHash = hashAlgorithm.ComputeHash(buffer); + var hash = BitConverter.ToString(byteHash).Replace("-", string.Empty).ToLowerInvariant(); + return checkSumOptions.AsEnumerable() + .Any(p => p.Equals(hash, StringComparison.InvariantCultureIgnoreCase)); + } +} diff --git a/starsky/starsky.foundation.video/Class1.cs b/starsky/starsky.foundation.video/Class1.cs deleted file mode 100644 index aa05872559..0000000000 --- a/starsky/starsky.foundation.video/Class1.cs +++ /dev/null @@ -1,5 +0,0 @@ -namespace starsky.foundation.video; - -public class Class1 -{ -} diff --git a/starsky/starsky.foundation.video/GetDependencies/FFMpegDownload.cs b/starsky/starsky.foundation.video/GetDependencies/FFMpegDownload.cs index 9a89e0af3a..11ce7d6c87 100644 --- a/starsky/starsky.foundation.video/GetDependencies/FFMpegDownload.cs +++ b/starsky/starsky.foundation.video/GetDependencies/FFMpegDownload.cs @@ -1,7 +1,10 @@ +using Medallion.Shell; using starsky.foundation.http.Interfaces; using starsky.foundation.platform.Architecture; using starsky.foundation.platform.Interfaces; using starsky.foundation.platform.Models; +using starsky.foundation.storage.ArchiveFormats; +using starsky.foundation.storage.Helpers; using starsky.foundation.storage.Interfaces; using starsky.foundation.storage.Storage; using starsky.foundation.video.GetDependencies.Interfaces; @@ -11,10 +14,13 @@ namespace starsky.foundation.video.GetDependencies; public class FfMpegDownload : IFfMpegDownload { + private const string FfmpegDependenciesFolder = "ffmpeg"; private readonly AppSettings _appSettings; + private readonly FfMpegDownloadIndex _downloadIndex; private readonly IStorage _hostFileSystemStorage; private readonly IHttpClientHelper _httpClientHelper; private readonly IWebLogger _logger; + private readonly MacCodeSign _macCodeSign; public FfMpegDownload(IHttpClientHelper httpClientHelper, AppSettings appSettings, IWebLogger logger) @@ -23,6 +29,8 @@ public FfMpegDownload(IHttpClientHelper httpClientHelper, AppSettings appSetting _appSettings = appSettings; _hostFileSystemStorage = new StorageHostFullPathFilesystem(logger); _logger = logger; + _downloadIndex = new FfMpegDownloadIndex(_httpClientHelper, _logger); + _macCodeSign = new MacCodeSign(_hostFileSystemStorage, _logger); } public async Task DownloadFfMpeg() @@ -40,13 +48,22 @@ public async Task DownloadFfMpeg() CreateDirectoryDependenciesFolderIfNotExists(); var currentArchitecture = CurrentArchitecture.GetCurrentRuntimeIdentifier(); + // var currentArchitecture = "osx-x64"; + + if ( _hostFileSystemStorage.ExistFile(GetExePath(currentArchitecture)) ) + { + return true; + } + + var container = await _downloadIndex.DownloadIndex(); - var container = await new FfMpegDownloadIndex(_httpClientHelper, _logger).DownloadIndex(); var binaryIndexBaseUrls = GetCurrentArchitectureIndexUrls(container, currentArchitecture); - await Download(binaryIndexBaseUrls); - + await Download(binaryIndexBaseUrls, currentArchitecture); + + await PrepareBeforeRunning(currentArchitecture); + return true; } @@ -60,50 +77,139 @@ public async Task DownloadFfMpeg() return new KeyValuePair>(sortedData, container.BaseUrls); } - private async Task Download(KeyValuePair> binaryIndexKeyValuePair) + private async Task Download( + KeyValuePair> binaryIndexKeyValuePair, string currentArchitecture, + int retryInSeconds = 15) + { + var (binaryIndex, baseUrls) = binaryIndexKeyValuePair; + if ( binaryIndex?.FileName == null ) + { + return null; + } + + if ( _hostFileSystemStorage.ExistFile(GetExePath(currentArchitecture)) ) + { + return true; + } + + var zipFullFilePath = + Path.Combine(_appSettings.DependenciesFolder, binaryIndex.FileName); + + if ( !await DownloadMirror(baseUrls, zipFullFilePath, binaryIndex, retryInSeconds) ) + { + _logger.LogError("Download failed"); + return null; + } + + if ( !new CheckSha256Helper(_hostFileSystemStorage).CheckSha256(zipFullFilePath, + [binaryIndex.Sha256]) ) + { + _logger.LogError("Sha256 check failed"); + return null; + } + + new Zipper(_logger).ExtractZip(zipFullFilePath, + Path.Combine(_appSettings.DependenciesFolder, FfmpegDependenciesFolder)); + + if ( !_hostFileSystemStorage.ExistFile(GetExePath(currentArchitecture)) ) + { + return false; + } + + _hostFileSystemStorage.FileDelete(zipFullFilePath); + return true; + } + + private string GetExePath(string currentArchitecture) { - var ( binaryIndex, baseUrls ) = binaryIndexKeyValuePair; - - if ( !_hostFileSystemStorage.ExistFile( - Path.Combine(_appSettings.DependenciesFolder, binaryIndex.Url)) ) - { - - foreach ( var baseUrl in baseUrls ) - { - - - var uri = new Uri(baseUrl + binaryIndex.Url); - - } - - // if ( !_hostFileSystemStorage.ExistFile( - // Path.Combine(_appSettings.DependenciesFolder, CountryName + ".txt")) ) - // { - // var outputZip = Path.Combine(_appSettings.DependenciesFolder, - // CountryName + ".zip"); - // var baseResult = - // await _httpClientHelper.Download(https + BaseUrl + CountryName + ".zip", - // outputZip); - // if ( !baseResult ) - // { - // await _httpClientHelper.Download(https + MirrorUrl + CountryName + ".zip", - // outputZip); - // } - // - // new Zipper(_logger).ExtractZip(outputZip, _appSettings.DependenciesFolder); - // } + var exeFile = Path.Combine(_appSettings.DependenciesFolder, FfmpegDependenciesFolder, + "ffmpeg"); + if ( currentArchitecture is "win-x64" or "win-arm64" ) + { + exeFile += ".exe"; + } + + return exeFile; } - private void CreateDirectoryDependenciesFolderIfNotExists() + private async Task PrepareBeforeRunning(string currentArchitecture) { - if ( _hostFileSystemStorage.ExistFolder( - _appSettings.DependenciesFolder) ) + var exeFile = GetExePath(currentArchitecture); + + if ( !_hostFileSystemStorage.ExistFile(Path.Combine(exeFile)) ) { - return; + return false; } - _logger.LogInformation("[FfMpegDownload] Create Directory: " + - _appSettings.DependenciesFolder); - _hostFileSystemStorage.CreateDirectory(_appSettings.DependenciesFolder); + if ( currentArchitecture is "win-arm64" or "win-x64" ) + { + return true; + } + + if ( !await Chmod(exeFile) ) + { + return false; + } + + if ( currentArchitecture is "osx-x64" or "osx-arm64" ) + { + return await _macCodeSign.MacCodeSignAndXattrExecutable(exeFile); + } + + return true; + } + + private async Task Chmod(string exeFile) + { + if ( !_hostFileSystemStorage.ExistFile("/bin/chmod") ) + { + _logger.LogError("[RunChmodOnFfmpegExe] WARNING: /bin/chmod does not exist"); + return true; + } + + // command.run does not care about the $PATH + var result = await Command.Run("/bin/chmod", "0755", exeFile).Task; + if ( result.Success ) + { + return true; + } + + _logger.LogError( + $"command failed with exit code {result.ExitCode}: {result.StandardError}"); + return false; + } + + + private async Task DownloadMirror(List baseUrls, string zipFullFilePath, + BinaryIndex binaryIndex, int retryInSeconds = 15) + { + foreach ( var uri in baseUrls.Select(baseUrl => new Uri(baseUrl + binaryIndex.FileName)) ) + { + if ( await _httpClientHelper.Download(uri, zipFullFilePath, retryInSeconds) ) + { + return true; + } + } + + return false; + } + + private void CreateDirectoryDependenciesFolderIfNotExists() + { + foreach ( var path in new List + { + _appSettings.DependenciesFolder, + Path.Combine(_appSettings.DependenciesFolder, FfmpegDependenciesFolder) + } ) + { + if ( _hostFileSystemStorage.ExistFolder(path) ) + { + continue; + } + + _logger.LogInformation("[FfMpegDownload] Create Directory: " + + path); + _hostFileSystemStorage.CreateDirectory(path); + } } } diff --git a/starsky/starsky.foundation.video/GetDependencies/FfMpegDownloadIndex.cs b/starsky/starsky.foundation.video/GetDependencies/FfMpegDownloadIndex.cs index 373a41857d..ae238e2eb1 100644 --- a/starsky/starsky.foundation.video/GetDependencies/FfMpegDownloadIndex.cs +++ b/starsky/starsky.foundation.video/GetDependencies/FfMpegDownloadIndex.cs @@ -7,10 +7,10 @@ namespace starsky.foundation.video.GetDependencies; public class FfMpegDownloadIndex(IHttpClientHelper httpClientHelper, IWebLogger logger) { private const string QdrawMirrorDomain = "qdraw.nl/special/mirror/ffmpeg"; - private const string NetlifyMirrorDomain = "starsky-dependencies.netlify.app/ffmpeg"; + private const string NetlifyMirrorDomain = "_____starsky-dependencies.netlify.app/ffmpeg"; - private static readonly Uri FfMpegApiBasePath = new($"https://{NetlifyMirrorDomain}"); - private static readonly Uri FfMpegApiBasePathMirror = new($"https://{NetlifyMirrorDomain}"); + private static readonly Uri FfMpegApiBasePath = new($"https://{NetlifyMirrorDomain}/"); + private static readonly Uri FfMpegApiBasePathMirror = new($"https://{QdrawMirrorDomain}/"); private static readonly List BaseUris = [FfMpegApiBasePath, FfMpegApiBasePathMirror]; private readonly Uri _ffMpegApiIndex = new($"https://{NetlifyMirrorDomain}/index.json"); diff --git a/starsky/starsky.foundation.video/GetDependencies/MacCodeSign.cs b/starsky/starsky.foundation.video/GetDependencies/MacCodeSign.cs new file mode 100644 index 0000000000..035ab3b347 --- /dev/null +++ b/starsky/starsky.foundation.video/GetDependencies/MacCodeSign.cs @@ -0,0 +1,62 @@ +using Medallion.Shell; +using starsky.foundation.platform.Interfaces; +using starsky.foundation.storage.Interfaces; + +namespace starsky.foundation.video.GetDependencies; + +public class MacCodeSign(IStorage hostFileSystemStorage, IWebLogger logger) +{ + public string CodeSignPath { get; set; } = "/usr/bin/codesign"; + public string XattrPath { get; set; } = "/usr/bin/xattr"; + + public async Task MacCodeSignAndXattrExecutable(string exeFile) + { + var result = await MacCodeSignExecutable(exeFile); + if ( !result ) + { + return false; + } + + return await MacXattrExecutable(exeFile); + } + + private async Task MacCodeSignExecutable(string exeFile) + { + if ( !hostFileSystemStorage.ExistFile(CodeSignPath) ) + { + logger.LogError("[RunChmodOnFfmpegExe] WARNING: /usr/bin/codesign does not exist"); + return true; + } + + // command.run does not care about the $PATH + var result = await Command.Run(CodeSignPath, "--force", "--deep", "-s", "-", exeFile).Task; + if ( result.Success ) + { + return true; + } + + logger.LogError( + $"codesign Command failed with exit code {result.ExitCode}: {result.StandardError}"); + return false; + } + + private async Task MacXattrExecutable(string exeFile) + { + if ( !hostFileSystemStorage.ExistFile(XattrPath) ) + { + logger.LogError("[RunChmodOnFfmpegExe] WARNING: /usr/bin/xattr does not exist"); + return true; + } + + // command.run does not care about the $PATH + var result = await Command.Run(XattrPath, "-rd", "com.apple.quarantine", exeFile).Task; + if ( result.Success ) + { + return true; + } + + logger.LogError( + $"xattr Command failed with exit code {result.ExitCode}: {result.StandardError}"); + return false; + } +} diff --git a/starsky/starsky.foundation.video/GetDependencies/Models/FfmpegBinariesIndex.cs b/starsky/starsky.foundation.video/GetDependencies/Models/FfmpegBinariesIndex.cs index b026aac434..920e1633f1 100644 --- a/starsky/starsky.foundation.video/GetDependencies/Models/FfmpegBinariesIndex.cs +++ b/starsky/starsky.foundation.video/GetDependencies/Models/FfmpegBinariesIndex.cs @@ -6,7 +6,7 @@ namespace starsky.foundation.video.GetDependencies.Models; public class BinaryIndex { public string Architecture { get; set; } - public string Url { get; set; } + public string FileName { get; set; } public string Sha256 { get; set; } } diff --git a/starsky/starsky.foundation.video/GetDependencies/OperationSystemPlatforms.bak b/starsky/starsky.foundation.video/GetDependencies/OperationSystemPlatforms.bak deleted file mode 100644 index 7f145d455f..0000000000 --- a/starsky/starsky.foundation.video/GetDependencies/OperationSystemPlatforms.bak +++ /dev/null @@ -1,27 +0,0 @@ -using System.ComponentModel.DataAnnotations; - -namespace starsky.foundation.video.GetDependencies; - -public class OperationSystemPlatforms -{ - public enum OsPlatformAndArchitecture - { - Unknown, - [Display(Name = "win-x86")] - WinX86, - [Display(Name = "win-x64")] - WinX64, - [Display(Name = "win-arm64")] - WinArm64, - [Display(Name = "linux-x64")] - LinuxX64, - [Display(Name = "linux-arm")] - LinuxArm, - [Display(Name = "linux-arm64")] - LinuxArm64, - [Display(Name = "osx-x64")] - OsxX64, - [Display(Name = "osx-arm64")] - OsxArm64 - } -} diff --git a/starsky/starsky.foundation.video/GetDependencies/OperationSystemPlatforms.cs b/starsky/starsky.foundation.video/GetDependencies/OperationSystemPlatforms.cs deleted file mode 100644 index 7f145d455f..0000000000 --- a/starsky/starsky.foundation.video/GetDependencies/OperationSystemPlatforms.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System.ComponentModel.DataAnnotations; - -namespace starsky.foundation.video.GetDependencies; - -public class OperationSystemPlatforms -{ - public enum OsPlatformAndArchitecture - { - Unknown, - [Display(Name = "win-x86")] - WinX86, - [Display(Name = "win-x64")] - WinX64, - [Display(Name = "win-arm64")] - WinArm64, - [Display(Name = "linux-x64")] - LinuxX64, - [Display(Name = "linux-arm")] - LinuxArm, - [Display(Name = "linux-arm64")] - LinuxArm64, - [Display(Name = "osx-x64")] - OsxX64, - [Display(Name = "osx-arm64")] - OsxArm64 - } -} diff --git a/starsky/starsky.foundation.video/starsky.foundation.video.csproj b/starsky/starsky.foundation.video/starsky.foundation.video.csproj index a4f6bd5b99..516ba96c43 100644 --- a/starsky/starsky.foundation.video/starsky.foundation.video.csproj +++ b/starsky/starsky.foundation.video/starsky.foundation.video.csproj @@ -14,4 +14,8 @@ + + + + diff --git a/starsky/starsky.foundation.writemeta/Services/ExifToolDownload.cs b/starsky/starsky.foundation.writemeta/Services/ExifToolDownload.cs index 7276097f3b..f31bef2fe8 100644 --- a/starsky/starsky.foundation.writemeta/Services/ExifToolDownload.cs +++ b/starsky/starsky.foundation.writemeta/Services/ExifToolDownload.cs @@ -4,7 +4,6 @@ using System.IO; using System.Linq; using System.Runtime.CompilerServices; -using System.Security.Cryptography; using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; @@ -14,6 +13,7 @@ using starsky.foundation.platform.Interfaces; using starsky.foundation.platform.Models; using starsky.foundation.storage.ArchiveFormats; +using starsky.foundation.storage.Helpers; using starsky.foundation.storage.Interfaces; using starsky.foundation.storage.Models; using starsky.foundation.storage.Storage; @@ -71,7 +71,7 @@ internal ExifToolDownload(IHttpClientHelper httpClientHelper, AppSettings appSet public async Task DownloadExifTool(bool isWindows, int minimumSize = 30) { if ( _appSettings.ExiftoolSkipDownloadOnStartup == true || _appSettings is - { AddSwaggerExport: true, AddSwaggerExportExitAfter: true } ) + { AddSwaggerExport: true, AddSwaggerExportExitAfter: true } ) { var name = _appSettings.ExiftoolSkipDownloadOnStartup == true ? "ExiftoolSkipDownloadOnStartup" @@ -83,15 +83,15 @@ public async Task DownloadExifTool(bool isWindows, int minimumSize = 30) CreateDirectoryDependenciesFolderIfNotExists(); if ( isWindows && - ( !_hostFileSystemStorage.ExistFile(ExeExifToolWindowsFullFilePath()) || - _hostFileSystemStorage.Info(ExeExifToolWindowsFullFilePath()).Size <= minimumSize ) ) + ( !_hostFileSystemStorage.ExistFile(ExeExifToolWindowsFullFilePath()) || + _hostFileSystemStorage.Info(ExeExifToolWindowsFullFilePath()).Size <= minimumSize ) ) { return await StartDownloadForWindows(); } if ( !isWindows && - ( !_hostFileSystemStorage.ExistFile(ExeExifToolUnixFullFilePath()) || - _hostFileSystemStorage.Info(ExeExifToolUnixFullFilePath()).Size <= minimumSize ) ) + ( !_hostFileSystemStorage.ExistFile(ExeExifToolUnixFullFilePath()) || + _hostFileSystemStorage.Info(ExeExifToolUnixFullFilePath()).Size <= minimumSize ) ) { return await StartDownloadForUnix(); } @@ -116,13 +116,13 @@ public async Task DownloadExifTool(bool isWindows, int minimumSize = 30) private void CreateDirectoryDependenciesFolderIfNotExists() { if ( _hostFileSystemStorage.ExistFolder( - _appSettings.DependenciesFolder) ) + _appSettings.DependenciesFolder) ) { return; } _logger.LogInformation("[DownloadExifTool] Create Directory: " + - _appSettings.DependenciesFolder); + _appSettings.DependenciesFolder); _hostFileSystemStorage.CreateDirectory(_appSettings.DependenciesFolder); } @@ -217,7 +217,8 @@ private async Task DownloadForUnix(string exiftoolDownloadBasePath, return false; } - if ( !CheckSha256(tarGzArchiveFullFilePath, getChecksumsFromTextFile) ) + if ( !new CheckSha256Helper(_hostFileSystemStorage).CheckSha256(tarGzArchiveFullFilePath, + getChecksumsFromTextFile) ) { _logger.LogError($"Checksum for {tarGzArchiveFullFilePath} is not valid"); _hostFileSystemStorage.FileDelete(tarGzArchiveFullFilePath); @@ -336,24 +337,6 @@ internal string[] GetChecksumsFromTextFile(string checksumsValue, int max = 20) return []; } - /// - /// Check if SHA256 hash is valid - /// Instead of SHA1CryptoServiceProvider, we use SHA256.Create - /// - /// path of exiftool.exe - /// list of SHA256 hashes - /// - internal bool CheckSha256(string fullFilePath, IEnumerable checkSumOptions) - { - using var buffer = _hostFileSystemStorage.ReadStream(fullFilePath); - using var hashAlgorithm = SHA256.Create(); - - var byteHash = hashAlgorithm.ComputeHash(buffer); - var hash = BitConverter.ToString(byteHash).Replace("-", string.Empty).ToLowerInvariant(); - return checkSumOptions.AsEnumerable() - .Any(p => p.Equals(hash, StringComparison.InvariantCultureIgnoreCase)); - } - private string ExeExifToolWindowsFullFilePath() { return Path.Combine(Path.Combine(_appSettings.DependenciesFolder, "exiftool-windows"), @@ -380,7 +363,7 @@ private async Task DownloadForWindows(string exiftoolDownloadBasePath, string[] getChecksumsFromTextFile) { if ( _hostFileSystemStorage.ExistFile( - ExeExifToolWindowsFullFilePath()) ) + ExeExifToolWindowsFullFilePath()) ) { return true; } @@ -397,7 +380,8 @@ private async Task DownloadForWindows(string exiftoolDownloadBasePath, return false; } - if ( !CheckSha256(zipArchiveFullFilePath, getChecksumsFromTextFile) ) + if ( !new CheckSha256Helper(_hostFileSystemStorage).CheckSha256(zipArchiveFullFilePath, + getChecksumsFromTextFile) ) { _logger.LogError($"Checksum for {zipArchiveFullFilePath} is not valid"); return false; diff --git a/starsky/starsky.sln b/starsky/starsky.sln index 40801e12c5..1329368711 100644 --- a/starsky/starsky.sln +++ b/starsky/starsky.sln @@ -170,6 +170,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "starsky.feature.settings", EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "starsky.feature.desktop", "starsky.feature.desktop\starsky.feature.desktop.csproj", "{B88C2815-D154-4C6D-AE37-2E150AEBF73D}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "starsky.foundation.video", "starsky.foundation.video\starsky.foundation.video.csproj", "{C6F6B684-F8EB-4DFD-9143-33F0262153FE}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -372,6 +374,10 @@ Global {B88C2815-D154-4C6D-AE37-2E150AEBF73D}.Debug|Any CPU.Build.0 = Debug|Any CPU {B88C2815-D154-4C6D-AE37-2E150AEBF73D}.Release|Any CPU.ActiveCfg = Release|Any CPU {B88C2815-D154-4C6D-AE37-2E150AEBF73D}.Release|Any CPU.Build.0 = Release|Any CPU + {C6F6B684-F8EB-4DFD-9143-33F0262153FE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C6F6B684-F8EB-4DFD-9143-33F0262153FE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C6F6B684-F8EB-4DFD-9143-33F0262153FE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C6F6B684-F8EB-4DFD-9143-33F0262153FE}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -432,5 +438,6 @@ Global {A62C129C-5D0C-4A0A-B5AA-261E041FF55D} = {4B9276C3-651E-48D3-B3A7-3F4D74F3D01A} {F2C4C9DE-22A1-4B34-AC1D-0F08353E0742} = {4B9276C3-651E-48D3-B3A7-3F4D74F3D01A} {B88C2815-D154-4C6D-AE37-2E150AEBF73D} = {4B9276C3-651E-48D3-B3A7-3F4D74F3D01A} + {C6F6B684-F8EB-4DFD-9143-33F0262153FE} = {1C1EB4A5-08D0-4014-AE1F-962642A4E5D3} EndGlobalSection EndGlobal diff --git a/starsky/starskytest/Controllers/AppSettingsControllerTest.cs b/starsky/starskytest/Controllers/AppSettingsControllerTest.cs index 7f6b488097..ee7bc734f4 100644 --- a/starsky/starskytest/Controllers/AppSettingsControllerTest.cs +++ b/starsky/starskytest/Controllers/AppSettingsControllerTest.cs @@ -60,22 +60,27 @@ await controller.UpdateAppSettings(new AppSettingsTransferObject { Verbose = tru [TestMethod] public async Task UpdateAppSettings_StorageFolder() { + const string testFolder = "test-update-settings-storage"; var appSettings = new AppSettings(); var controller = new AppSettingsController(appSettings, new UpdateAppSettingsByPath( appSettings, new FakeSelectorStorage( - new FakeIStorage(new List { $"{Path.DirectorySeparatorChar}test" })))); + new FakeIStorage(new List + { + $"{Path.DirectorySeparatorChar}{testFolder}" + })))); controller.ControllerContext.HttpContext = new DefaultHttpContext(); var actionResult = await controller.UpdateAppSettings(new AppSettingsTransferObject { - Verbose = true, StorageFolder = $"{Path.DirectorySeparatorChar}test" + Verbose = true, StorageFolder = $"{Path.DirectorySeparatorChar}{testFolder}" }) as JsonResult; var result = actionResult?.Value as AppSettings; Assert.IsTrue(result?.Verbose); - Assert.AreEqual(Path.DirectorySeparatorChar + PathHelper.AddBackslash("test"), + + Assert.AreEqual(Path.DirectorySeparatorChar + PathHelper.AddBackslash(testFolder), result?.StorageFolder); } diff --git a/starsky/starskytest/FakeCreateAn/CreateAnGpx.cs b/starsky/starskytest/FakeCreateAn/CreateAnGpx.cs index bc93e809ee..8616547a27 100644 --- a/starsky/starskytest/FakeCreateAn/CreateAnGpx.cs +++ b/starsky/starskytest/FakeCreateAn/CreateAnGpx.cs @@ -5,165 +5,172 @@ using System.Reflection; using starsky.foundation.platform.Helpers; -namespace starskytest.FakeCreateAn +namespace starskytest.FakeCreateAn; + +public class CreateAnGpx { - public class CreateAnGpx - { - public readonly string FullFileGpxPath = - Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location) + - Path.DirectorySeparatorChar + FileNameGpx; + private const string FileNameGpx = "zz__test.gpx"; - [SuppressMessage("Performance", "CA1822:Mark members as static")] - [SuppressMessage("ReSharper", "MemberCanBeMadeStatic.Global")] - public string FileName => FileNameGpx; + public static readonly string FullFileGpxPath = + Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location) + + Path.DirectorySeparatorChar + FileNameGpx; - private const string FileNameGpx = "zz__test.gpx"; + private static readonly string Base64GpxString = + "CjxncHggeG1sbnM9Imh0dHA6Ly93d3cudG9wb2dyYWZpeC5jb20vR1BYLzEvMSIg" + + "eG1sbnM6Z3B4eD0iaHR0cDovL3d3dy5nYXJtaW4uY29tL3htbHNjaGVtYXMvR3B4" + + "RXh0ZW5zaW9ucy92MyIgeG1sbnM6Z3B4dHB4PSJodHRwOi8vd3d3OC5nYXJtaW4u" + + "Y29tL3htbHNjaGVtYXMvVHJhY2tQb2ludEV4dGVuc2lvbnYyLnhzZCIgeG1sbnM6" + + "dHJhaWxzaW89Imh0dHA6Ly90cmFpbHMuaW8vR1BYLzEvMCIgeG1sbnM6eHNpPSJo" + + "dHRwOi8vd3d3LnczLm9yZy8yMDAxL1hNTFNjaGVtYS1pbnN0YW5jZSIgdmVyc2lv" + + "bj0iMS4xIiBjcmVhdG9yPSJBZHplIC0gaHR0cDovL2tvYm90c3cuY29tL2FwcHMv" + + "YWR6ZSIgeHNpOnNjaGVtYUxvY2F0aW9uPSJodHRwOi8vd3d3LnRvcG9ncmFmaXgu" + + "Y29tL0dQWC8xLzEgaHR0cDovL3d3dy50b3BvZ3JhZml4LmNvbS9HUFgvMS8xL2dw" + + "eC54c2QgaHR0cDovL3d3dy5nYXJtaW4uY29tL3htbHNjaGVtYXMvR3B4RXh0ZW5z" + + "aW9ucy92MyBodHRwOi8vd3d3Lmdhcm1pbi5jb20veG1sc2NoZW1hcy9HcHhFeHRl" + + "bnNpb25zdjMueHNkIGh0dHA6Ly90cmFpbHMuaW8vR1BYLzEvMCBodHRwczovL3Ry" + + "YWlscy5pby9HUFgvMS8wL3RyYWlsc18xLjAueHNkIj4KICAgIDxtZXRhZGF0YT4K" + + "ICAgICAgICA8bmFtZT5VbnRpdGxlZCBEb2N1bWVudDwvbmFtZT4KICAgICAgICA8" + + "dGltZT4yMDE4LTA5LTExVDE5OjQxOjEwLjQ4Mlo8L3RpbWU+CiAgICA8L21ldGFk" + + "YXRhPgogICAgPHRyaz4KICAgICAgICA8bmFtZT5fMjAxODA5MDUtZmlldHNlbi1v" + + "c3M8L25hbWU+CiAgICAgICAgPGV4dGVuc2lvbnM+CiAgICAgICAgICAgIDx0cmFp" + + "bHNpbzpUcmFja0V4dGVuc2lvbj4KICAgICAgICAgICAgICAgIDx0cmFpbHNpbzph" + + "Y3Rpdml0eT5iaWtpbmc8L3RyYWlsc2lvOmFjdGl2aXR5PgogICAgICAgICAgICA8" + + "L3RyYWlsc2lvOlRyYWNrRXh0ZW5zaW9uPgogICAgICAgICAgICA8Z3B4eDpUcmFj" + + "a0V4dGVuc2lvbj4KICAgICAgICAgICAgICAgIDxncHh4OkRpc3BsYXlDb2xvcj5E" + + "YXJrUmVkPC9ncHh4OkRpc3BsYXlDb2xvcj4KICAgICAgICAgICAgPC9ncHh4OlRy" + + "YWNrRXh0ZW5zaW9uPgogICAgICAgIDwvZXh0ZW5zaW9ucz4KICAgICAgICA8dHJr" + + "c2VnPgogICAgICAgICAgICA8dHJrcHQgbG9uPSI1LjQ4NTk0MSIgbGF0PSI1MS44" + + "MDkzNjAiPgogICAgICAgICAgICAgICAgPGVsZT43LjI2MzAwMDwvZWxlPgogICAg" + + "ICAgICAgICAgICAgPHRpbWU+MjAxOC0wOS0wNVQxNzozMTo1M1o8L3RpbWU+CiAg" + + "ICAgICAgICAgICAgICA8ZXh0ZW5zaW9ucz4KICAgICAgICAgICAgICAgICAgICA8" + + "Z3B4dHB4OlRyYWNrUG9pbnRFeHRlbnNpb24+CiAgICAgICAgICAgICAgICAgICAg" + + "ICAgIDxncHh0cHg6c3BlZWQ+NS40OTwvZ3B4dHB4OnNwZWVkPgogICAgICAgICAg" + + "ICAgICAgICAgICAgICA8Z3B4dHB4OmNvdXJzZT4xODkuNDk8L2dweHRweDpjb3Vy" + + "c2U+CiAgICAgICAgICAgICAgICAgICAgPC9ncHh0cHg6VHJhY2tQb2ludEV4dGVu" + + "c2lvbj4KICAgICAgICAgICAgICAgICAgICA8dHJhaWxzaW86VHJhY2tQb2ludEV4" + + "dGVuc2lvbj4KICAgICAgICAgICAgICAgICAgICAgICAgPHRyYWlsc2lvOmhhY2M+" + + "NS4wMDwvdHJhaWxzaW86aGFjYz4KICAgICAgICAgICAgICAgICAgICAgICAgPHRy" + + "YWlsc2lvOnZhY2M+NC4wMDwvdHJhaWxzaW86dmFjYz4KICAgICAgICAgICAgICAg" + + "ICAgICAgICAgPHRyYWlsc2lvOnN0ZXBzPjU1MTE8L3RyYWlsc2lvOnN0ZXBzPgog" + + "ICAgICAgICAgICAgICAgICAgIDwvdHJhaWxzaW86VHJhY2tQb2ludEV4dGVuc2lv" + + "bj4KICAgICAgICAgICAgICAgIDwvZXh0ZW5zaW9ucz4KICAgICAgICAgICAgPC90" + + "cmtwdD4KICAgICAgICAgICAgPHRya3B0IGxvbj0iNS40ODU3MjQiIGxhdD0iNTEu" + + "ODA3OTY4Ij4KICAgICAgICAgICAgICAgIDxlbGU+Ny43NzIwMDA8L2VsZT4KICAg" + + "ICAgICAgICAgICAgIDx0aW1lPjIwMTgtMDktMDVUMTc6MzI6MjFaPC90aW1lPgog" + + "ICAgICAgICAgICAgICAgPGV4dGVuc2lvbnM+CiAgICAgICAgICAgICAgICAgICAg" + + "PGdweHRweDpUcmFja1BvaW50RXh0ZW5zaW9uPgogICAgICAgICAgICAgICAgICAg" + + "ICAgICA8Z3B4dHB4OnNwZWVkPjQuNTk8L2dweHRweDpzcGVlZD4KICAgICAgICAg" + + "ICAgICAgICAgICAgICAgPGdweHRweDpjb3Vyc2U+MTg1LjYyPC9ncHh0cHg6Y291" + + "cnNlPgogICAgICAgICAgICAgICAgICAgIDwvZ3B4dHB4OlRyYWNrUG9pbnRFeHRl" + + "bnNpb24+CiAgICAgICAgICAgICAgICAgICAgPHRyYWlsc2lvOlRyYWNrUG9pbnRF" + + "eHRlbnNpb24+CiAgICAgICAgICAgICAgICAgICAgICAgIDx0cmFpbHNpbzpoYWNj" + + "PjUuMDA8L3RyYWlsc2lvOmhhY2M+CiAgICAgICAgICAgICAgICAgICAgICAgIDx0" + + "cmFpbHNpbzp2YWNjPjQuMDA8L3RyYWlsc2lvOnZhY2M+CiAgICAgICAgICAgICAg" + + "ICAgICAgICAgIDx0cmFpbHNpbzpzdGVwcz41NTUyPC90cmFpbHNpbzpzdGVwcz4K" + + "ICAgICAgICAgICAgICAgICAgICA8L3RyYWlsc2lvOlRyYWNrUG9pbnRFeHRlbnNp" + + "b24+CiAgICAgICAgICAgICAgICA8L2V4dGVuc2lvbnM+CiAgICAgICAgICAgIDwv" + + "dHJrcHQ+CiAgICAgICAgICAgIDx0cmtwdCBsb249IjUuNDg1NjMxIiBsYXQ9IjUx" + + "LjgwNzAxOSI+CiAgICAgICAgICAgICAgICA8ZWxlPjkuOTU3MDAwPC9lbGU+CiAg" + + "ICAgICAgICAgICAgICA8dGltZT4yMDE4LTA5LTA1VDE3OjMyOjQzWjwvdGltZT4K" + + "ICAgICAgICAgICAgICAgIDxleHRlbnNpb25zPgogICAgICAgICAgICAgICAgICAg" + + "IDxncHh0cHg6VHJhY2tQb2ludEV4dGVuc2lvbj4KICAgICAgICAgICAgICAgICAg" + + "ICAgICAgPGdweHRweDpzcGVlZD40LjYzPC9ncHh0cHg6c3BlZWQ+CiAgICAgICAg" + + "ICAgICAgICAgICAgICAgIDxncHh0cHg6Y291cnNlPjE4MC43MDwvZ3B4dHB4OmNv" + + "dXJzZT4KICAgICAgICAgICAgICAgICAgICA8L2dweHRweDpUcmFja1BvaW50RXh0" + + "ZW5zaW9uPgogICAgICAgICAgICAgICAgICAgIDx0cmFpbHNpbzpUcmFja1BvaW50" + + "RXh0ZW5zaW9uPgogICAgICAgICAgICAgICAgICAgICAgICA8dHJhaWxzaW86aGFj" + + "Yz41LjAwPC90cmFpbHNpbzpoYWNjPgogICAgICAgICAgICAgICAgICAgICAgICA8" + + "dHJhaWxzaW86dmFjYz4zLjAwPC90cmFpbHNpbzp2YWNjPgogICAgICAgICAgICAg" + + "ICAgICAgICAgICA8dHJhaWxzaW86c3RlcHM+NTU1NjwvdHJhaWxzaW86c3RlcHM+" + + "CiAgICAgICAgICAgICAgICAgICAgPC90cmFpbHNpbzpUcmFja1BvaW50RXh0ZW5z" + + "aW9uPgogICAgICAgICAgICAgICAgPC9leHRlbnNpb25zPgogICAgICAgICAgICA8" + + "L3Rya3B0PgogICAgICAgICAgICA8dHJrcHQgbG9uPSI1LjQ4NTYxMCIgbGF0PSI1" + + "MS44MDY3MDIiPgogICAgICAgICAgICAgICAgPGVsZT4xMC44MDgwMDA8L2VsZT4K" + + "ICAgICAgICAgICAgICAgIDx0aW1lPjIwMTgtMDktMDVUMTc6MzI6NTBaPC90aW1l" + + "PgogICAgICAgICAgICAgICAgPGV4dGVuc2lvbnM+CiAgICAgICAgICAgICAgICAg" + + "ICAgPGdweHRweDpUcmFja1BvaW50RXh0ZW5zaW9uPgogICAgICAgICAgICAgICAg" + + "ICAgICAgICA8Z3B4dHB4OnNwZWVkPjUuNjQ8L2dweHRweDpzcGVlZD4KICAgICAg" + + "ICAgICAgICAgICAgICAgICAgPGdweHRweDpjb3Vyc2U+MTg2LjMzPC9ncHh0cHg6" + + "Y291cnNlPgogICAgICAgICAgICAgICAgICAgIDwvZ3B4dHB4OlRyYWNrUG9pbnRF" + + "eHRlbnNpb24+CiAgICAgICAgICAgICAgICAgICAgPHRyYWlsc2lvOlRyYWNrUG9p" + + "bnRFeHRlbnNpb24+CiAgICAgICAgICAgICAgICAgICAgICAgIDx0cmFpbHNpbzpo" + + "YWNjPjUuMDA8L3RyYWlsc2lvOmhhY2M+CiAgICAgICAgICAgICAgICAgICAgICAg" + + "IDx0cmFpbHNpbzp2YWNjPjMuMDA8L3RyYWlsc2lvOnZhY2M+CiAgICAgICAgICAg" + + "ICAgICAgICAgICAgIDx0cmFpbHNpbzpzdGVwcz41NTY2PC90cmFpbHNpbzpzdGVw" + + "cz4KICAgICAgICAgICAgICAgICAgICA8L3RyYWlsc2lvOlRyYWNrUG9pbnRFeHRl" + + "bnNpb24+CiAgICAgICAgICAgICAgICA8L2V4dGVuc2lvbnM+CiAgICAgICAgICAg" + + "IDwvdHJrcHQ+CiAgICAgICAgICAgIDx0cmtwdCBsb249IjUuNDg1NjMzIiBsYXQ9" + + "IjUxLjgwNTY2MyI+CiAgICAgICAgICAgICAgICA8ZWxlPjEwLjg2NjAwMDwvZWxl" + + "PgogICAgICAgICAgICAgICAgPHRpbWU+MjAxOC0wOS0wNVQxNzozMzoxMVo8L3Rp" + + "bWU+CiAgICAgICAgICAgICAgICA8ZXh0ZW5zaW9ucz4KICAgICAgICAgICAgICAg" + + "ICAgICA8Z3B4dHB4OlRyYWNrUG9pbnRFeHRlbnNpb24+CiAgICAgICAgICAgICAg" + + "ICAgICAgICAgIDxncHh0cHg6c3BlZWQ+NS41ODwvZ3B4dHB4OnNwZWVkPgogICAg" + + "ICAgICAgICAgICAgICAgICAgICA8Z3B4dHB4OmNvdXJzZT4xNjkuMTA8L2dweHRw" + + "eDpjb3Vyc2U+CiAgICAgICAgICAgICAgICAgICAgPC9ncHh0cHg6VHJhY2tQb2lu" + + "dEV4dGVuc2lvbj4KICAgICAgICAgICAgICAgICAgICA8dHJhaWxzaW86VHJhY2tQ" + + "b2ludEV4dGVuc2lvbj4KICAgICAgICAgICAgICAgICAgICAgICAgPHRyYWlsc2lv" + + "OmhhY2M+NS4wMDwvdHJhaWxzaW86aGFjYz4KICAgICAgICAgICAgICAgICAgICAg" + + "ICAgPHRyYWlsc2lvOnZhY2M+My4wMDwvdHJhaWxzaW86dmFjYz4KICAgICAgICAg" + + "ICAgICAgICAgICAgICAgPHRyYWlsc2lvOnN0ZXBzPjU2MDc8L3RyYWlsc2lvOnN0" + + "ZXBzPgogICAgICAgICAgICAgICAgICAgIDwvdHJhaWxzaW86VHJhY2tQb2ludEV4" + + "dGVuc2lvbj4KICAgICAgICAgICAgICAgIDwvZXh0ZW5zaW9ucz4KICAgICAgICAg" + + "ICAgPC90cmtwdD4KICAgICAgICAgICAgPHRya3B0IGxvbj0iNS40ODU3MzgiIGxh" + + "dD0iNTEuODA1NTAwIj4KICAgICAgICAgICAgICAgIDxlbGU+OS4yNDIwMDA8L2Vs" + + "ZT4KICAgICAgICAgICAgICAgIDx0aW1lPjIwMTgtMDktMDVUMTc6MzM6MTVaPC90" + + "aW1lPgogICAgICAgICAgICAgICAgPGV4dGVuc2lvbnM+CiAgICAgICAgICAgICAg" + + "ICAgICAgPGdweHRweDpUcmFja1BvaW50RXh0ZW5zaW9uPgogICAgICAgICAgICAg" + + "ICAgICAgICAgICA8Z3B4dHB4OnNwZWVkPjUuNjY8L2dweHRweDpzcGVlZD4KICAg" + + "ICAgICAgICAgICAgICAgICAgICAgPGdweHRweDpjb3Vyc2U+MTUxLjg4PC9ncHh0" + + "cHg6Y291cnNlPgogICAgICAgICAgICAgICAgICAgIDwvZ3B4dHB4OlRyYWNrUG9p" + + "bnRFeHRlbnNpb24+CiAgICAgICAgICAgICAgICAgICAgPHRyYWlsc2lvOlRyYWNr" + + "UG9pbnRFeHRlbnNpb24+CiAgICAgICAgICAgICAgICAgICAgICAgIDx0cmFpbHNp" + + "bzpoYWNjPjUuMDA8L3RyYWlsc2lvOmhhY2M+CiAgICAgICAgICAgICAgICAgICAg" + + "ICAgIDx0cmFpbHNpbzp2YWNjPjMuMDA8L3RyYWlsc2lvOnZhY2M+CiAgICAgICAg" + + "ICAgICAgICAgICAgICAgIDx0cmFpbHNpbzpzdGVwcz41NjEyPC90cmFpbHNpbzpz" + + "dGVwcz4KICAgICAgICAgICAgICAgICAgICA8L3RyYWlsc2lvOlRyYWNrUG9pbnRF" + + "eHRlbnNpb24+CiAgICAgICAgICAgICAgICA8L2V4dGVuc2lvbnM+CiAgICAgICAg" + + "ICAgIDwvdHJrcHQ+CiAgICAgICAgICAgIDx0cmtwdCBsb249IjUuNDg2MDU2IiBs" + + "YXQ9IjUxLjgwNTExNSI+CiAgICAgICAgICAgICAgICA8ZWxlPjkuMTIyMDAwPC9l" + + "bGU+CiAgICAgICAgICAgICAgICA8dGltZT4yMDE4LTA5LTA1VDE3OjMzOjI0Wjwv" + + "dGltZT4KICAgICAgICAgICAgICAgIDxleHRlbnNpb25zPgogICAgICAgICAgICAg" + + "ICAgICAgIDxncHh0cHg6VHJhY2tQb2ludEV4dGVuc2lvbj4KICAgICAgICAgICAg" + + "ICAgICAgICAgICAgPGdweHRweDpzcGVlZD40Ljc2PC9ncHh0cHg6c3BlZWQ+CiAg" + + "ICAgICAgICAgICAgICAgICAgICAgIDxncHh0cHg6Y291cnNlPjE1NC4zNDwvZ3B4" + + "dHB4OmNvdXJzZT4KICAgICAgICAgICAgICAgICAgICA8L2dweHRweDpUcmFja1Bv" + + "aW50RXh0ZW5zaW9uPgogICAgICAgICAgICAgICAgICAgIDx0cmFpbHNpbzpUcmFj" + + "a1BvaW50RXh0ZW5zaW9uPgogICAgICAgICAgICAgICAgICAgICAgICA8dHJhaWxz" + + "aW86aGFjYz41LjAwPC90cmFpbHNpbzpoYWNjPgogICAgICAgICAgICAgICAgICAg" + + "ICAgICA8dHJhaWxzaW86dmFjYz4zLjAwPC90cmFpbHNpbzp2YWNjPgogICAgICAg" + + "ICAgICAgICAgICAgICAgICA8dHJhaWxzaW86c3RlcHM+NTYyMTwvdHJhaWxzaW86" + + "c3RlcHM+CiAgICAgICAgICAgICAgICAgICAgPC90cmFpbHNpbzpUcmFja1BvaW50" + + "RXh0ZW5zaW9uPgogICAgICAgICAgICAgICAgPC9leHRlbnNpb25zPgogICAgICAg" + + "ICAgICA8L3Rya3B0PgogICAgICAgIDwvdHJrc2VnPgogICAgPC90cms+CjwvZ3B4" + + "Pg=="; - public readonly string BasePath = - Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location) + - Path.DirectorySeparatorChar; + public static readonly ImmutableArray Bytes = + [..Base64Helper.TryParse(Base64GpxString)]; - private static readonly string Base64GpxString = - "CjxncHggeG1sbnM9Imh0dHA6Ly93d3cudG9wb2dyYWZpeC5jb20vR1BYLzEvMSIg" + - "eG1sbnM6Z3B4eD0iaHR0cDovL3d3dy5nYXJtaW4uY29tL3htbHNjaGVtYXMvR3B4" + - "RXh0ZW5zaW9ucy92MyIgeG1sbnM6Z3B4dHB4PSJodHRwOi8vd3d3OC5nYXJtaW4u" + - "Y29tL3htbHNjaGVtYXMvVHJhY2tQb2ludEV4dGVuc2lvbnYyLnhzZCIgeG1sbnM6" + - "dHJhaWxzaW89Imh0dHA6Ly90cmFpbHMuaW8vR1BYLzEvMCIgeG1sbnM6eHNpPSJo" + - "dHRwOi8vd3d3LnczLm9yZy8yMDAxL1hNTFNjaGVtYS1pbnN0YW5jZSIgdmVyc2lv" + - "bj0iMS4xIiBjcmVhdG9yPSJBZHplIC0gaHR0cDovL2tvYm90c3cuY29tL2FwcHMv" + - "YWR6ZSIgeHNpOnNjaGVtYUxvY2F0aW9uPSJodHRwOi8vd3d3LnRvcG9ncmFmaXgu" + - "Y29tL0dQWC8xLzEgaHR0cDovL3d3dy50b3BvZ3JhZml4LmNvbS9HUFgvMS8xL2dw" + - "eC54c2QgaHR0cDovL3d3dy5nYXJtaW4uY29tL3htbHNjaGVtYXMvR3B4RXh0ZW5z" + - "aW9ucy92MyBodHRwOi8vd3d3Lmdhcm1pbi5jb20veG1sc2NoZW1hcy9HcHhFeHRl" + - "bnNpb25zdjMueHNkIGh0dHA6Ly90cmFpbHMuaW8vR1BYLzEvMCBodHRwczovL3Ry" + - "YWlscy5pby9HUFgvMS8wL3RyYWlsc18xLjAueHNkIj4KICAgIDxtZXRhZGF0YT4K" + - "ICAgICAgICA8bmFtZT5VbnRpdGxlZCBEb2N1bWVudDwvbmFtZT4KICAgICAgICA8" + - "dGltZT4yMDE4LTA5LTExVDE5OjQxOjEwLjQ4Mlo8L3RpbWU+CiAgICA8L21ldGFk" + - "YXRhPgogICAgPHRyaz4KICAgICAgICA8bmFtZT5fMjAxODA5MDUtZmlldHNlbi1v" + - "c3M8L25hbWU+CiAgICAgICAgPGV4dGVuc2lvbnM+CiAgICAgICAgICAgIDx0cmFp" + - "bHNpbzpUcmFja0V4dGVuc2lvbj4KICAgICAgICAgICAgICAgIDx0cmFpbHNpbzph" + - "Y3Rpdml0eT5iaWtpbmc8L3RyYWlsc2lvOmFjdGl2aXR5PgogICAgICAgICAgICA8" + - "L3RyYWlsc2lvOlRyYWNrRXh0ZW5zaW9uPgogICAgICAgICAgICA8Z3B4eDpUcmFj" + - "a0V4dGVuc2lvbj4KICAgICAgICAgICAgICAgIDxncHh4OkRpc3BsYXlDb2xvcj5E" + - "YXJrUmVkPC9ncHh4OkRpc3BsYXlDb2xvcj4KICAgICAgICAgICAgPC9ncHh4OlRy" + - "YWNrRXh0ZW5zaW9uPgogICAgICAgIDwvZXh0ZW5zaW9ucz4KICAgICAgICA8dHJr" + - "c2VnPgogICAgICAgICAgICA8dHJrcHQgbG9uPSI1LjQ4NTk0MSIgbGF0PSI1MS44" + - "MDkzNjAiPgogICAgICAgICAgICAgICAgPGVsZT43LjI2MzAwMDwvZWxlPgogICAg" + - "ICAgICAgICAgICAgPHRpbWU+MjAxOC0wOS0wNVQxNzozMTo1M1o8L3RpbWU+CiAg" + - "ICAgICAgICAgICAgICA8ZXh0ZW5zaW9ucz4KICAgICAgICAgICAgICAgICAgICA8" + - "Z3B4dHB4OlRyYWNrUG9pbnRFeHRlbnNpb24+CiAgICAgICAgICAgICAgICAgICAg" + - "ICAgIDxncHh0cHg6c3BlZWQ+NS40OTwvZ3B4dHB4OnNwZWVkPgogICAgICAgICAg" + - "ICAgICAgICAgICAgICA8Z3B4dHB4OmNvdXJzZT4xODkuNDk8L2dweHRweDpjb3Vy" + - "c2U+CiAgICAgICAgICAgICAgICAgICAgPC9ncHh0cHg6VHJhY2tQb2ludEV4dGVu" + - "c2lvbj4KICAgICAgICAgICAgICAgICAgICA8dHJhaWxzaW86VHJhY2tQb2ludEV4" + - "dGVuc2lvbj4KICAgICAgICAgICAgICAgICAgICAgICAgPHRyYWlsc2lvOmhhY2M+" + - "NS4wMDwvdHJhaWxzaW86aGFjYz4KICAgICAgICAgICAgICAgICAgICAgICAgPHRy" + - "YWlsc2lvOnZhY2M+NC4wMDwvdHJhaWxzaW86dmFjYz4KICAgICAgICAgICAgICAg" + - "ICAgICAgICAgPHRyYWlsc2lvOnN0ZXBzPjU1MTE8L3RyYWlsc2lvOnN0ZXBzPgog" + - "ICAgICAgICAgICAgICAgICAgIDwvdHJhaWxzaW86VHJhY2tQb2ludEV4dGVuc2lv" + - "bj4KICAgICAgICAgICAgICAgIDwvZXh0ZW5zaW9ucz4KICAgICAgICAgICAgPC90" + - "cmtwdD4KICAgICAgICAgICAgPHRya3B0IGxvbj0iNS40ODU3MjQiIGxhdD0iNTEu" + - "ODA3OTY4Ij4KICAgICAgICAgICAgICAgIDxlbGU+Ny43NzIwMDA8L2VsZT4KICAg" + - "ICAgICAgICAgICAgIDx0aW1lPjIwMTgtMDktMDVUMTc6MzI6MjFaPC90aW1lPgog" + - "ICAgICAgICAgICAgICAgPGV4dGVuc2lvbnM+CiAgICAgICAgICAgICAgICAgICAg" + - "PGdweHRweDpUcmFja1BvaW50RXh0ZW5zaW9uPgogICAgICAgICAgICAgICAgICAg" + - "ICAgICA8Z3B4dHB4OnNwZWVkPjQuNTk8L2dweHRweDpzcGVlZD4KICAgICAgICAg" + - "ICAgICAgICAgICAgICAgPGdweHRweDpjb3Vyc2U+MTg1LjYyPC9ncHh0cHg6Y291" + - "cnNlPgogICAgICAgICAgICAgICAgICAgIDwvZ3B4dHB4OlRyYWNrUG9pbnRFeHRl" + - "bnNpb24+CiAgICAgICAgICAgICAgICAgICAgPHRyYWlsc2lvOlRyYWNrUG9pbnRF" + - "eHRlbnNpb24+CiAgICAgICAgICAgICAgICAgICAgICAgIDx0cmFpbHNpbzpoYWNj" + - "PjUuMDA8L3RyYWlsc2lvOmhhY2M+CiAgICAgICAgICAgICAgICAgICAgICAgIDx0" + - "cmFpbHNpbzp2YWNjPjQuMDA8L3RyYWlsc2lvOnZhY2M+CiAgICAgICAgICAgICAg" + - "ICAgICAgICAgIDx0cmFpbHNpbzpzdGVwcz41NTUyPC90cmFpbHNpbzpzdGVwcz4K" + - "ICAgICAgICAgICAgICAgICAgICA8L3RyYWlsc2lvOlRyYWNrUG9pbnRFeHRlbnNp" + - "b24+CiAgICAgICAgICAgICAgICA8L2V4dGVuc2lvbnM+CiAgICAgICAgICAgIDwv" + - "dHJrcHQ+CiAgICAgICAgICAgIDx0cmtwdCBsb249IjUuNDg1NjMxIiBsYXQ9IjUx" + - "LjgwNzAxOSI+CiAgICAgICAgICAgICAgICA8ZWxlPjkuOTU3MDAwPC9lbGU+CiAg" + - "ICAgICAgICAgICAgICA8dGltZT4yMDE4LTA5LTA1VDE3OjMyOjQzWjwvdGltZT4K" + - "ICAgICAgICAgICAgICAgIDxleHRlbnNpb25zPgogICAgICAgICAgICAgICAgICAg" + - "IDxncHh0cHg6VHJhY2tQb2ludEV4dGVuc2lvbj4KICAgICAgICAgICAgICAgICAg" + - "ICAgICAgPGdweHRweDpzcGVlZD40LjYzPC9ncHh0cHg6c3BlZWQ+CiAgICAgICAg" + - "ICAgICAgICAgICAgICAgIDxncHh0cHg6Y291cnNlPjE4MC43MDwvZ3B4dHB4OmNv" + - "dXJzZT4KICAgICAgICAgICAgICAgICAgICA8L2dweHRweDpUcmFja1BvaW50RXh0" + - "ZW5zaW9uPgogICAgICAgICAgICAgICAgICAgIDx0cmFpbHNpbzpUcmFja1BvaW50" + - "RXh0ZW5zaW9uPgogICAgICAgICAgICAgICAgICAgICAgICA8dHJhaWxzaW86aGFj" + - "Yz41LjAwPC90cmFpbHNpbzpoYWNjPgogICAgICAgICAgICAgICAgICAgICAgICA8" + - "dHJhaWxzaW86dmFjYz4zLjAwPC90cmFpbHNpbzp2YWNjPgogICAgICAgICAgICAg" + - "ICAgICAgICAgICA8dHJhaWxzaW86c3RlcHM+NTU1NjwvdHJhaWxzaW86c3RlcHM+" + - "CiAgICAgICAgICAgICAgICAgICAgPC90cmFpbHNpbzpUcmFja1BvaW50RXh0ZW5z" + - "aW9uPgogICAgICAgICAgICAgICAgPC9leHRlbnNpb25zPgogICAgICAgICAgICA8" + - "L3Rya3B0PgogICAgICAgICAgICA8dHJrcHQgbG9uPSI1LjQ4NTYxMCIgbGF0PSI1" + - "MS44MDY3MDIiPgogICAgICAgICAgICAgICAgPGVsZT4xMC44MDgwMDA8L2VsZT4K" + - "ICAgICAgICAgICAgICAgIDx0aW1lPjIwMTgtMDktMDVUMTc6MzI6NTBaPC90aW1l" + - "PgogICAgICAgICAgICAgICAgPGV4dGVuc2lvbnM+CiAgICAgICAgICAgICAgICAg" + - "ICAgPGdweHRweDpUcmFja1BvaW50RXh0ZW5zaW9uPgogICAgICAgICAgICAgICAg" + - "ICAgICAgICA8Z3B4dHB4OnNwZWVkPjUuNjQ8L2dweHRweDpzcGVlZD4KICAgICAg" + - "ICAgICAgICAgICAgICAgICAgPGdweHRweDpjb3Vyc2U+MTg2LjMzPC9ncHh0cHg6" + - "Y291cnNlPgogICAgICAgICAgICAgICAgICAgIDwvZ3B4dHB4OlRyYWNrUG9pbnRF" + - "eHRlbnNpb24+CiAgICAgICAgICAgICAgICAgICAgPHRyYWlsc2lvOlRyYWNrUG9p" + - "bnRFeHRlbnNpb24+CiAgICAgICAgICAgICAgICAgICAgICAgIDx0cmFpbHNpbzpo" + - "YWNjPjUuMDA8L3RyYWlsc2lvOmhhY2M+CiAgICAgICAgICAgICAgICAgICAgICAg" + - "IDx0cmFpbHNpbzp2YWNjPjMuMDA8L3RyYWlsc2lvOnZhY2M+CiAgICAgICAgICAg" + - "ICAgICAgICAgICAgIDx0cmFpbHNpbzpzdGVwcz41NTY2PC90cmFpbHNpbzpzdGVw" + - "cz4KICAgICAgICAgICAgICAgICAgICA8L3RyYWlsc2lvOlRyYWNrUG9pbnRFeHRl" + - "bnNpb24+CiAgICAgICAgICAgICAgICA8L2V4dGVuc2lvbnM+CiAgICAgICAgICAg" + - "IDwvdHJrcHQ+CiAgICAgICAgICAgIDx0cmtwdCBsb249IjUuNDg1NjMzIiBsYXQ9" + - "IjUxLjgwNTY2MyI+CiAgICAgICAgICAgICAgICA8ZWxlPjEwLjg2NjAwMDwvZWxl" + - "PgogICAgICAgICAgICAgICAgPHRpbWU+MjAxOC0wOS0wNVQxNzozMzoxMVo8L3Rp" + - "bWU+CiAgICAgICAgICAgICAgICA8ZXh0ZW5zaW9ucz4KICAgICAgICAgICAgICAg" + - "ICAgICA8Z3B4dHB4OlRyYWNrUG9pbnRFeHRlbnNpb24+CiAgICAgICAgICAgICAg" + - "ICAgICAgICAgIDxncHh0cHg6c3BlZWQ+NS41ODwvZ3B4dHB4OnNwZWVkPgogICAg" + - "ICAgICAgICAgICAgICAgICAgICA8Z3B4dHB4OmNvdXJzZT4xNjkuMTA8L2dweHRw" + - "eDpjb3Vyc2U+CiAgICAgICAgICAgICAgICAgICAgPC9ncHh0cHg6VHJhY2tQb2lu" + - "dEV4dGVuc2lvbj4KICAgICAgICAgICAgICAgICAgICA8dHJhaWxzaW86VHJhY2tQ" + - "b2ludEV4dGVuc2lvbj4KICAgICAgICAgICAgICAgICAgICAgICAgPHRyYWlsc2lv" + - "OmhhY2M+NS4wMDwvdHJhaWxzaW86aGFjYz4KICAgICAgICAgICAgICAgICAgICAg" + - "ICAgPHRyYWlsc2lvOnZhY2M+My4wMDwvdHJhaWxzaW86dmFjYz4KICAgICAgICAg" + - "ICAgICAgICAgICAgICAgPHRyYWlsc2lvOnN0ZXBzPjU2MDc8L3RyYWlsc2lvOnN0" + - "ZXBzPgogICAgICAgICAgICAgICAgICAgIDwvdHJhaWxzaW86VHJhY2tQb2ludEV4" + - "dGVuc2lvbj4KICAgICAgICAgICAgICAgIDwvZXh0ZW5zaW9ucz4KICAgICAgICAg" + - "ICAgPC90cmtwdD4KICAgICAgICAgICAgPHRya3B0IGxvbj0iNS40ODU3MzgiIGxh" + - "dD0iNTEuODA1NTAwIj4KICAgICAgICAgICAgICAgIDxlbGU+OS4yNDIwMDA8L2Vs" + - "ZT4KICAgICAgICAgICAgICAgIDx0aW1lPjIwMTgtMDktMDVUMTc6MzM6MTVaPC90" + - "aW1lPgogICAgICAgICAgICAgICAgPGV4dGVuc2lvbnM+CiAgICAgICAgICAgICAg" + - "ICAgICAgPGdweHRweDpUcmFja1BvaW50RXh0ZW5zaW9uPgogICAgICAgICAgICAg" + - "ICAgICAgICAgICA8Z3B4dHB4OnNwZWVkPjUuNjY8L2dweHRweDpzcGVlZD4KICAg" + - "ICAgICAgICAgICAgICAgICAgICAgPGdweHRweDpjb3Vyc2U+MTUxLjg4PC9ncHh0" + - "cHg6Y291cnNlPgogICAgICAgICAgICAgICAgICAgIDwvZ3B4dHB4OlRyYWNrUG9p" + - "bnRFeHRlbnNpb24+CiAgICAgICAgICAgICAgICAgICAgPHRyYWlsc2lvOlRyYWNr" + - "UG9pbnRFeHRlbnNpb24+CiAgICAgICAgICAgICAgICAgICAgICAgIDx0cmFpbHNp" + - "bzpoYWNjPjUuMDA8L3RyYWlsc2lvOmhhY2M+CiAgICAgICAgICAgICAgICAgICAg" + - "ICAgIDx0cmFpbHNpbzp2YWNjPjMuMDA8L3RyYWlsc2lvOnZhY2M+CiAgICAgICAg" + - "ICAgICAgICAgICAgICAgIDx0cmFpbHNpbzpzdGVwcz41NjEyPC90cmFpbHNpbzpz" + - "dGVwcz4KICAgICAgICAgICAgICAgICAgICA8L3RyYWlsc2lvOlRyYWNrUG9pbnRF" + - "eHRlbnNpb24+CiAgICAgICAgICAgICAgICA8L2V4dGVuc2lvbnM+CiAgICAgICAg" + - "ICAgIDwvdHJrcHQ+CiAgICAgICAgICAgIDx0cmtwdCBsb249IjUuNDg2MDU2IiBs" + - "YXQ9IjUxLjgwNTExNSI+CiAgICAgICAgICAgICAgICA8ZWxlPjkuMTIyMDAwPC9l" + - "bGU+CiAgICAgICAgICAgICAgICA8dGltZT4yMDE4LTA5LTA1VDE3OjMzOjI0Wjwv" + - "dGltZT4KICAgICAgICAgICAgICAgIDxleHRlbnNpb25zPgogICAgICAgICAgICAg" + - "ICAgICAgIDxncHh0cHg6VHJhY2tQb2ludEV4dGVuc2lvbj4KICAgICAgICAgICAg" + - "ICAgICAgICAgICAgPGdweHRweDpzcGVlZD40Ljc2PC9ncHh0cHg6c3BlZWQ+CiAg" + - "ICAgICAgICAgICAgICAgICAgICAgIDxncHh0cHg6Y291cnNlPjE1NC4zNDwvZ3B4" + - "dHB4OmNvdXJzZT4KICAgICAgICAgICAgICAgICAgICA8L2dweHRweDpUcmFja1Bv" + - "aW50RXh0ZW5zaW9uPgogICAgICAgICAgICAgICAgICAgIDx0cmFpbHNpbzpUcmFj" + - "a1BvaW50RXh0ZW5zaW9uPgogICAgICAgICAgICAgICAgICAgICAgICA8dHJhaWxz" + - "aW86aGFjYz41LjAwPC90cmFpbHNpbzpoYWNjPgogICAgICAgICAgICAgICAgICAg" + - "ICAgICA8dHJhaWxzaW86dmFjYz4zLjAwPC90cmFpbHNpbzp2YWNjPgogICAgICAg" + - "ICAgICAgICAgICAgICAgICA8dHJhaWxzaW86c3RlcHM+NTYyMTwvdHJhaWxzaW86" + - "c3RlcHM+CiAgICAgICAgICAgICAgICAgICAgPC90cmFpbHNpbzpUcmFja1BvaW50" + - "RXh0ZW5zaW9uPgogICAgICAgICAgICAgICAgPC9leHRlbnNpb25zPgogICAgICAg" + - "ICAgICA8L3Rya3B0PgogICAgICAgIDwvdHJrc2VnPgogICAgPC90cms+CjwvZ3B4" + - "Pg=="; + public readonly string BasePath = + Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location) + + Path.DirectorySeparatorChar; + + public CreateAnGpx(bool writeFile = false) + { + if ( writeFile && !File.Exists(FullFileGpxPath) ) + { + File.WriteAllBytes(FullFileGpxPath, Convert.FromBase64String(Base64GpxString)); + } + } - public static readonly ImmutableArray Bytes = - Base64Helper.TryParse(Base64GpxString).ToImmutableArray(); + [SuppressMessage("Performance", "CA1822:Mark members as static")] + [SuppressMessage("ReSharper", "MemberCanBeMadeStatic.Global")] + public string FileName => FileNameGpx; - public CreateAnGpx() + public static void Dispose() + { + if ( File.Exists(FullFileGpxPath) ) { - if ( !File.Exists(FullFileGpxPath) ) - { - File.WriteAllBytes(FullFileGpxPath, Convert.FromBase64String(Base64GpxString)); - } + File.Delete(FullFileGpxPath); } } } diff --git a/starsky/starskytest/FakeCreateAn/CreateAnZipFileMacOs/CreateAnZipFileMacOs.cs b/starsky/starskytest/FakeCreateAn/CreateAnZipFileMacOs/CreateAnZipFileMacOs.cs new file mode 100644 index 0000000000..e9b3e364f6 --- /dev/null +++ b/starsky/starskytest/FakeCreateAn/CreateAnZipFileMacOs/CreateAnZipFileMacOs.cs @@ -0,0 +1,26 @@ +using System.Collections.Generic; +using System.IO; +using System.Reflection; + +namespace starskytest.FakeCreateAn.CreateAnZipFileMacOs; + +public class CreateAnZipFileMacOs +{ + public CreateAnZipFileMacOs() + { + var dirName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); + if ( string.IsNullOrEmpty(dirName) ) + { + return; + } + + var path = Path.Combine(dirName, "FakeCreateAn", + "CreateAnZipFileMacOs", "macOsSubfolder.zip"); + FilePath = path; + } + + public string FilePath { get; set; } = string.Empty; + + public static IEnumerable Content { get; set; } = + new List { "__MACOSX/._ffmpeg" }; +} diff --git a/starsky/starskytest/FakeCreateAn/CreateAnZipFileMacOs/macOsSubfolder.zip b/starsky/starskytest/FakeCreateAn/CreateAnZipFileMacOs/macOsSubfolder.zip new file mode 100644 index 0000000000000000000000000000000000000000..6ae1c74a0ad092e6e4ead76695cb19c7ae5b06ec GIT binary patch literal 288 zcmWIWW@Zs#U|`^2@N{>M+`J@MDF(>91H^(13Jme_zK+iR!4dj;@o8zf1*z$wA-oLi zT@L@!-U0C!r+;as72FJrEMFNJ7{JCPCx|AeCnP0&@bwA%z#rBT(7-f7f>~Wan(?ES z0^7&;1_G=y&Q47Wd?xg1I=pFI)*`5QZvLG4tEWc UrlsCalled { get; set; } = new(); + public async Task Download(Uri sourceUri, string fullLocalPath, + int retryAfterInSeconds = 15) + { + return await Download(sourceUri.ToString(), fullLocalPath, retryAfterInSeconds); + } + public async Task Download(string sourceHttpUrl, string fullLocalPath, int retryAfterInSeconds = 15) { diff --git a/starsky/starskytest/Helpers/FileStreamingHelperTest.cs b/starsky/starskytest/Helpers/FileStreamingHelperTest.cs index c25a3c56c4..b3a3be9e81 100644 --- a/starsky/starskytest/Helpers/FileStreamingHelperTest.cs +++ b/starsky/starskytest/Helpers/FileStreamingHelperTest.cs @@ -92,7 +92,7 @@ await httpContext.Request.StreamFile(_appSettings, } [TestMethod] - public async Task FileStreamingHelperTest_FileStreamingHelper_StreamFile_imagejpeg() + public async Task FileStreamingHelperTest_FileStreamingHelper_StreamFile_imageJpeg() { var createAnImage = new CreateAnImage(); @@ -112,6 +112,8 @@ public async Task FileStreamingHelperTest_FileStreamingHelper_StreamFile_imagejp // Clean streamSelector.Get(SelectorStorage.StorageServices.HostFilesystem) .FileDelete(formValueProvider.FirstOrDefault()!); + + CleanParentFolder(formValueProvider.FirstOrDefault()); } [TestMethod] @@ -160,7 +162,7 @@ private static MemoryStream MakeStream(string text) [TestMethod] public async Task FileStreamingHelper_MultipartRequestHelper() { - var contentType = $"multipart/form-data; boundary=\"{Boundary}\""; + const string contentType = $"multipart/form-data; boundary=\"{Boundary}\""; // string contentType, Stream requestBody, AppSettings appSettings, // ISelectorStorage selectorStorage, string headerFileName = null @@ -172,8 +174,24 @@ public async Task FileStreamingHelper_MultipartRequestHelper() await FileStreamingHelper.StreamFile(contentType, stream, _appSettings, streamSelector); - var tempPath = storage.GetAllFilesInDirectoryRecursive(_appSettings.TempFolder) - .FirstOrDefault(); - Assert.IsTrue(tempPath?.EndsWith("a.txt")); + var tempPath = storage.GetAllFilesInDirectoryRecursive(_appSettings.TempFolder).ToList()[0]; + + Assert.IsTrue(tempPath.EndsWith("a.txt")); + + CleanParentFolder(tempPath); + } + + private static void CleanParentFolder(string? tempPath) + { + if ( tempPath == null ) + { + return; + } + + var parentFolder = Directory.GetParent(tempPath); + if ( parentFolder?.Exists == true ) + { + parentFolder.Delete(); + } } } diff --git a/starsky/starskytest/starsky.feature.demo/Services/CleanDemoDataServiceTest.cs b/starsky/starskytest/starsky.feature.demo/Services/CleanDemoDataServiceTest.cs index b843799ebf..2963913238 100644 --- a/starsky/starskytest/starsky.feature.demo/Services/CleanDemoDataServiceTest.cs +++ b/starsky/starskytest/starsky.feature.demo/Services/CleanDemoDataServiceTest.cs @@ -126,7 +126,7 @@ public async Task RunAsync_ShouldTrigger() _appSettings.DemoData = new List { - new() { Key = "https://qdraw.nl", Value = "1" } + new() { Key = "https://qdraw.nl/", Value = "1" } }; Environment.SetEnvironmentVariable("app__storageFolder", "/tmp"); diff --git a/starsky/starskytest/starsky.feature.geolookup/Services/GeoIndexGpxTest.cs b/starsky/starskytest/starsky.feature.geolookup/Services/GeoIndexGpxTest.cs index f8574dbefd..54f93f80b7 100644 --- a/starsky/starskytest/starsky.feature.geolookup/Services/GeoIndexGpxTest.cs +++ b/starsky/starskytest/starsky.feature.geolookup/Services/GeoIndexGpxTest.cs @@ -36,6 +36,12 @@ public GeoIndexGpxTest() }; } + [ClassCleanup] + public static void CleanUpGeoIndexGpxTest() + { + CreateAnGpx.Dispose(); + } + [TestMethod] public void GeoIndexGpx_ConvertTimeZone_EuropeAmsterdam() { diff --git a/starsky/starskytest/starsky.feature.health/Services/SpecificVersionReleaseInfoTest.cs b/starsky/starskytest/starsky.feature.health/Services/SpecificVersionReleaseInfoTest.cs index d27cf109c5..2a2f22c09f 100644 --- a/starsky/starskytest/starsky.feature.health/Services/SpecificVersionReleaseInfoTest.cs +++ b/starsky/starskytest/starsky.feature.health/Services/SpecificVersionReleaseInfoTest.cs @@ -14,6 +14,8 @@ namespace starskytest.starsky.feature.health.Services; [TestClass] public class SpecificVersionReleaseInfoTests { + private readonly IServiceScopeFactory? _nullServiceScopeFactory = null; + [TestMethod] public async Task SpecificVersionMessage_NoCache() { @@ -36,7 +38,8 @@ public async Task SpecificVersionMessage_NoCache() } }); - var httpClientHelper = new HttpClientHelper(fakeIHttpProvider, null, new FakeIWebLogger()); + var httpClientHelper = new HttpClientHelper(fakeIHttpProvider, null as IServiceScopeFactory, + new FakeIWebLogger()); var specificVersionReleaseInfo = new SpecificVersionReleaseInfo(httpClientHelper, null, memoryCache, @@ -66,7 +69,8 @@ public async Task SpecificVersionMessage_Cache() var fakeIHttpProvider = new FakeIHttpProvider(); // return not found if not in cache - var httpClientHelper = new HttpClientHelper(fakeIHttpProvider, null, new FakeIWebLogger()); + var httpClientHelper = new HttpClientHelper(fakeIHttpProvider, _nullServiceScopeFactory, + new FakeIWebLogger()); var specificVersionReleaseInfo = new SpecificVersionReleaseInfo(httpClientHelper, @@ -102,7 +106,8 @@ public async Task SpecificVersionMessage_CacheEnabledGetValue() } }); - var httpClientHelper = new HttpClientHelper(fakeIHttpProvider, null, new FakeIWebLogger()); + var httpClientHelper = new HttpClientHelper(fakeIHttpProvider, _nullServiceScopeFactory, + new FakeIWebLogger()); var specificVersionReleaseInfo = // memory cache enabled new SpecificVersionReleaseInfo(httpClientHelper, @@ -139,7 +144,8 @@ public async Task SpecificVersionMessage_CacheEnabledGetValue_SetInCache() } }); - var httpClientHelper = new HttpClientHelper(fakeIHttpProvider, null, new FakeIWebLogger()); + var httpClientHelper = new HttpClientHelper(fakeIHttpProvider, _nullServiceScopeFactory, + new FakeIWebLogger()); var specificVersionReleaseInfo = new SpecificVersionReleaseInfo(httpClientHelper, @@ -193,7 +199,8 @@ public void ParseTest_String_Empty() { var fakeIHttpProvider = new FakeIHttpProvider(); - var httpClientHelper = new HttpClientHelper(fakeIHttpProvider, null, new FakeIWebLogger()); + var httpClientHelper = new HttpClientHelper(fakeIHttpProvider, _nullServiceScopeFactory, + new FakeIWebLogger()); var specificVersionReleaseInfo = new SpecificVersionReleaseInfo(httpClientHelper, @@ -209,7 +216,8 @@ public void ParseTest_VersionNotFound() { var fakeIHttpProvider = new FakeIHttpProvider(); - var httpClientHelper = new HttpClientHelper(fakeIHttpProvider, null, new FakeIWebLogger()); + var httpClientHelper = new HttpClientHelper(fakeIHttpProvider, _nullServiceScopeFactory, + new FakeIWebLogger()); const string example = "{\n \"0.6.0\" : {\n \"en\": \"Content\"\n },\n \"0.6.0-beta.0\" : {\n \"en\": \"Content\"\n }\n}"; @@ -228,7 +236,8 @@ public void ParseTest_VersionFound() { var fakeIHttpProvider = new FakeIHttpProvider(); - var httpClientHelper = new HttpClientHelper(fakeIHttpProvider, null, new FakeIWebLogger()); + var httpClientHelper = new HttpClientHelper(fakeIHttpProvider, _nullServiceScopeFactory, + new FakeIWebLogger()); const string example = "{\n \"0.6.0\" : {\n \"en\": \"Content\"\n },\n \"0.6.0-beta.0\" : {\n \"en\": \"Content\"\n }\n}"; @@ -247,7 +256,8 @@ public void ParseTest_InvalidJson() { var fakeIHttpProvider = new FakeIHttpProvider(); - var httpClientHelper = new HttpClientHelper(fakeIHttpProvider, null, new FakeIWebLogger()); + var httpClientHelper = new HttpClientHelper(fakeIHttpProvider, _nullServiceScopeFactory, + new FakeIWebLogger()); const string example = "{\n \"0.6.0\" : {\n --"; @@ -266,7 +276,8 @@ public void ParseTest_LanguageKeyNotFound() { var fakeIHttpProvider = new FakeIHttpProvider(); - var httpClientHelper = new HttpClientHelper(fakeIHttpProvider, null, new FakeIWebLogger()); + var httpClientHelper = new HttpClientHelper(fakeIHttpProvider, _nullServiceScopeFactory, + new FakeIWebLogger()); const string example = "{\n \"0.6.0\" : {\n }\n}"; @@ -284,7 +295,8 @@ public void ParseTest_VersionFound_HtmlLink() { var fakeIHttpProvider = new FakeIHttpProvider(); - var httpClientHelper = new HttpClientHelper(fakeIHttpProvider, null, new FakeIWebLogger()); + var httpClientHelper = new HttpClientHelper(fakeIHttpProvider, _nullServiceScopeFactory, + new FakeIWebLogger()); const string example = "{\n \"0.6.0\" : {\n \"en\": \"[Link text Here](https://link-url-here.org)\"\n },\n \"0.6.0-beta.0\" : {\n \"en\": \"Content\"\n }\n}"; @@ -328,7 +340,8 @@ public async Task QuerySpecificVersionInfo_GetResult() } }); - var httpClientHelper = new HttpClientHelper(fakeIHttpProvider, null, new FakeIWebLogger()); + var httpClientHelper = new HttpClientHelper(fakeIHttpProvider, _nullServiceScopeFactory, + new FakeIWebLogger()); var specificVersionReleaseInfo = new SpecificVersionReleaseInfo(httpClientHelper, null, null, new FakeIWebLogger()); @@ -343,7 +356,8 @@ public async Task QuerySpecificVersionInfo_NotFound() { var fakeIHttpProvider = new FakeIHttpProvider(); - var httpClientHelper = new HttpClientHelper(fakeIHttpProvider, null, new FakeIWebLogger()); + var httpClientHelper = new HttpClientHelper(fakeIHttpProvider, _nullServiceScopeFactory, + new FakeIWebLogger()); var specificVersionReleaseInfo = new SpecificVersionReleaseInfo(httpClientHelper, null, null, new FakeIWebLogger()); @@ -358,7 +372,8 @@ public void Parse_NullVersion() { var fakeIHttpProvider = new FakeIHttpProvider(); - var httpClientHelper = new HttpClientHelper(fakeIHttpProvider, null, new FakeIWebLogger()); + var httpClientHelper = new HttpClientHelper(fakeIHttpProvider, _nullServiceScopeFactory, + new FakeIWebLogger()); var specificVersionReleaseInfo = new SpecificVersionReleaseInfo(httpClientHelper, null, null, new FakeIWebLogger()); diff --git a/starsky/starskytest/starsky.feature.packagetelemetry/Helpers/PackageTelemetryTest.cs b/starsky/starskytest/starsky.feature.packagetelemetry/Helpers/PackageTelemetryTest.cs index 53525e69e0..0d4e3237ee 100644 --- a/starsky/starskytest/starsky.feature.packagetelemetry/Helpers/PackageTelemetryTest.cs +++ b/starsky/starskytest/starsky.feature.packagetelemetry/Helpers/PackageTelemetryTest.cs @@ -5,6 +5,7 @@ using System.Net.Http; using System.Runtime.InteropServices; using System.Threading.Tasks; +using Microsoft.Extensions.DependencyInjection; using Microsoft.VisualStudio.TestTools.UnitTesting; using starsky.feature.packagetelemetry.Services; using starsky.foundation.database.Models; @@ -12,293 +13,299 @@ using starsky.foundation.platform.Models; using starskytest.FakeMocks; -namespace starskytest.starsky.feature.packagetelemetry.Helpers +namespace starskytest.starsky.feature.packagetelemetry.Helpers; + +[TestClass] +public sealed class PackageTelemetryTest { - [TestClass] - public sealed class PackageTelemetryTest + private readonly IServiceScopeFactory? _nullServiceScopeFactory = null; + + [TestMethod] + public void GetCurrentOsPlatformTest() { - [TestMethod] - public void GetCurrentOsPlatformTest() + var content = PackageTelemetry.GetCurrentOsPlatform(); + Assert.IsNotNull(content); + + var allOsPlatforms = new List { - var content = PackageTelemetry.GetCurrentOsPlatform(); - Assert.IsNotNull(content); + OSPlatform.Linux, OSPlatform.Windows, OSPlatform.OSX, OSPlatform.FreeBSD + }; + Assert.IsTrue(allOsPlatforms.Contains(content.Value)); + } - var allOsPlatforms = new List - { - OSPlatform.Linux, OSPlatform.Windows, OSPlatform.OSX, OSPlatform.FreeBSD - }; - Assert.IsTrue(allOsPlatforms.Contains(content.Value)); - } + [TestMethod] + public void GetSystemDataTest() + { + var httpProvider = new FakeIHttpProvider(); + var appSettings = new AppSettings(); + var httpClientHelper = + new HttpClientHelper(httpProvider, _nullServiceScopeFactory, new FakeIWebLogger()); + var packageTelemetry = new PackageTelemetry(httpClientHelper, new AppSettings(), + new FakeIWebLogger(), new FakeIQuery(), new FakeIDeviceIdService()); + + var systemData = packageTelemetry.GetSystemData(); + Assert.IsTrue(systemData.Exists(p => p.Key == "AppVersion")); + Assert.AreEqual(systemData.Find(p => p.Key == "AppVersion").Value, + appSettings.AppVersion); + Assert.IsTrue(systemData.Exists(p => p.Key == "NetVersion")); + Assert.AreEqual(systemData.Find(p => p.Key == "NetVersion").Value, + RuntimeInformation.FrameworkDescription); + Assert.IsTrue(systemData.Exists(p => p.Key == "OSArchitecture")); + Assert.AreEqual(systemData.Find(p => p.Key == "OSArchitecture").Value, + RuntimeInformation.OSArchitecture.ToString()); + Assert.IsTrue(systemData.Exists(p => p.Key == "OSVersion")); + Assert.IsTrue(systemData.Exists(p => p.Key == "OSDescriptionLong")); + Assert.IsTrue(systemData.Exists(p => p.Key == "OSPlatform")); + Assert.IsTrue(systemData.Exists(p => p.Key == "DockerContainer")); + Assert.IsTrue(systemData.Exists(p => p.Key == "CurrentCulture")); + Assert.IsTrue(systemData.Exists(p => p.Key == "AspNetCoreEnvironment")); + } - [TestMethod] - public void GetSystemDataTest() - { - var httpProvider = new FakeIHttpProvider(); - var appSettings = new AppSettings(); - var httpClientHelper = new HttpClientHelper(httpProvider, null!, new FakeIWebLogger()); - var packageTelemetry = new PackageTelemetry(httpClientHelper, new AppSettings(), - new FakeIWebLogger(), new FakeIQuery(), new FakeIDeviceIdService()); - - var systemData = packageTelemetry.GetSystemData(); - Assert.IsTrue(systemData.Exists(p => p.Key == "AppVersion")); - Assert.AreEqual(systemData.Find(p => p.Key == "AppVersion").Value, - appSettings.AppVersion); - Assert.IsTrue(systemData.Exists(p => p.Key == "NetVersion")); - Assert.AreEqual(systemData.Find(p => p.Key == "NetVersion").Value, - RuntimeInformation.FrameworkDescription); - Assert.IsTrue(systemData.Exists(p => p.Key == "OSArchitecture")); - Assert.AreEqual(systemData.Find(p => p.Key == "OSArchitecture").Value, - RuntimeInformation.OSArchitecture.ToString()); - Assert.IsTrue(systemData.Exists(p => p.Key == "OSVersion")); - Assert.IsTrue(systemData.Exists(p => p.Key == "OSDescriptionLong")); - Assert.IsTrue(systemData.Exists(p => p.Key == "OSPlatform")); - Assert.IsTrue(systemData.Exists(p => p.Key == "DockerContainer")); - Assert.IsTrue(systemData.Exists(p => p.Key == "CurrentCulture")); - Assert.IsTrue(systemData.Exists(p => p.Key == "AspNetCoreEnvironment")); - } - - [TestMethod] - public void GetSystemDataTestDocker() - { - var httpProvider = new FakeIHttpProvider(); - var httpClientHelper = new HttpClientHelper(httpProvider, null!, new FakeIWebLogger()); - var packageTelemetry = new PackageTelemetry(httpClientHelper, new AppSettings(), - new FakeIWebLogger(), new FakeIQuery(), new FakeIDeviceIdService()); + [TestMethod] + public void GetSystemDataTestDocker() + { + var httpProvider = new FakeIHttpProvider(); + var httpClientHelper = + new HttpClientHelper(httpProvider, _nullServiceScopeFactory, new FakeIWebLogger()); + var packageTelemetry = new PackageTelemetry(httpClientHelper, new AppSettings(), + new FakeIWebLogger(), new FakeIQuery(), new FakeIDeviceIdService()); - var sourceValue = Environment.GetEnvironmentVariable("DOTNET_RUNNING_IN_CONTAINER"); - Environment.SetEnvironmentVariable("DOTNET_RUNNING_IN_CONTAINER", "true"); + var sourceValue = Environment.GetEnvironmentVariable("DOTNET_RUNNING_IN_CONTAINER"); + Environment.SetEnvironmentVariable("DOTNET_RUNNING_IN_CONTAINER", "true"); - var systemData = packageTelemetry.GetSystemData(OSPlatform.Linux); + var systemData = packageTelemetry.GetSystemData(OSPlatform.Linux); - Assert.AreEqual("True", systemData.Find(p => p.Key == "DockerContainer").Value); + Assert.AreEqual("True", systemData.Find(p => p.Key == "DockerContainer").Value); - // undo - Environment.SetEnvironmentVariable("DOTNET_RUNNING_IN_CONTAINER", "false"); + // undo + Environment.SetEnvironmentVariable("DOTNET_RUNNING_IN_CONTAINER", "false"); - var systemDataFalse = packageTelemetry.GetSystemData(OSPlatform.Linux); + var systemDataFalse = packageTelemetry.GetSystemData(OSPlatform.Linux); - Assert.AreEqual("False", systemDataFalse.Find(p => p.Key == "DockerContainer").Value); + Assert.AreEqual("False", systemDataFalse.Find(p => p.Key == "DockerContainer").Value); - Environment.SetEnvironmentVariable("DOTNET_RUNNING_IN_CONTAINER", sourceValue); - } + Environment.SetEnvironmentVariable("DOTNET_RUNNING_IN_CONTAINER", sourceValue); + } - [TestMethod] - public void GetSystemDataTestDocker_NonLinux_soFalse() - { - var httpProvider = new FakeIHttpProvider(); - var httpClientHelper = new HttpClientHelper(httpProvider, null!, new FakeIWebLogger()); - var packageTelemetry = new PackageTelemetry(httpClientHelper, new AppSettings(), - new FakeIWebLogger(), new FakeIQuery(), new FakeIDeviceIdService()); + [TestMethod] + public void GetSystemDataTestDocker_NonLinux_soFalse() + { + var httpProvider = new FakeIHttpProvider(); + var httpClientHelper = + new HttpClientHelper(httpProvider, _nullServiceScopeFactory, new FakeIWebLogger()); + var packageTelemetry = new PackageTelemetry(httpClientHelper, new AppSettings(), + new FakeIWebLogger(), new FakeIQuery(), new FakeIDeviceIdService()); - var sourceValue = Environment.GetEnvironmentVariable("DOTNET_RUNNING_IN_CONTAINER"); - Environment.SetEnvironmentVariable("DOTNET_RUNNING_IN_CONTAINER", "true"); + var sourceValue = Environment.GetEnvironmentVariable("DOTNET_RUNNING_IN_CONTAINER"); + Environment.SetEnvironmentVariable("DOTNET_RUNNING_IN_CONTAINER", "true"); - var systemData = packageTelemetry.GetSystemData(OSPlatform.Windows); + var systemData = packageTelemetry.GetSystemData(OSPlatform.Windows); - // so False - Assert.AreEqual("False", systemData.Find(p => p.Key == "DockerContainer").Value); + // so False + Assert.AreEqual("False", systemData.Find(p => p.Key == "DockerContainer").Value); - // undo - Environment.SetEnvironmentVariable("DOTNET_RUNNING_IN_CONTAINER", "false"); + // undo + Environment.SetEnvironmentVariable("DOTNET_RUNNING_IN_CONTAINER", "false"); - var systemDataFalse = packageTelemetry.GetSystemData(OSPlatform.Linux); + var systemDataFalse = packageTelemetry.GetSystemData(OSPlatform.Linux); - Assert.AreEqual("False", systemDataFalse.Find(p => p.Key == "DockerContainer").Value); + Assert.AreEqual("False", systemDataFalse.Find(p => p.Key == "DockerContainer").Value); - Environment.SetEnvironmentVariable("DOTNET_RUNNING_IN_CONTAINER", sourceValue); - } + Environment.SetEnvironmentVariable("DOTNET_RUNNING_IN_CONTAINER", sourceValue); + } - [TestMethod] - public void GetSystemDataTestDocker_WebSiteName() - { - var httpProvider = new FakeIHttpProvider(); - var httpClientHelper = new HttpClientHelper(httpProvider, null!, new FakeIWebLogger()); - var packageTelemetry = new PackageTelemetry(httpClientHelper, new AppSettings(), - new FakeIWebLogger(), new FakeIQuery(), new FakeIDeviceIdService()); + [TestMethod] + public void GetSystemDataTestDocker_WebSiteName() + { + var httpProvider = new FakeIHttpProvider(); + var httpClientHelper = + new HttpClientHelper(httpProvider, _nullServiceScopeFactory, new FakeIWebLogger()); + var packageTelemetry = new PackageTelemetry(httpClientHelper, new AppSettings(), + new FakeIWebLogger(), new FakeIQuery(), new FakeIDeviceIdService()); - var sourceValue = Environment.GetEnvironmentVariable("WEBSITE_SITE_NAME"); - Environment.SetEnvironmentVariable("WEBSITE_SITE_NAME", "test"); + var sourceValue = Environment.GetEnvironmentVariable("WEBSITE_SITE_NAME"); + Environment.SetEnvironmentVariable("WEBSITE_SITE_NAME", "test"); - var systemData = packageTelemetry.GetSystemData(OSPlatform.Windows); + var systemData = packageTelemetry.GetSystemData(OSPlatform.Windows); - // so False - Assert.AreEqual("9F86D081884C7D659A2FEAA0C55AD015A3BF4F1B2B0B822CD15D6C15B0F00A08", - systemData.Find(p => p.Key == "WebsiteName").Value); + // so False + Assert.AreEqual("9F86D081884C7D659A2FEAA0C55AD015A3BF4F1B2B0B822CD15D6C15B0F00A08", + systemData.Find(p => p.Key == "WebsiteName").Value); - // undo - Environment.SetEnvironmentVariable("WEBSITE_SITE_NAME", ""); + // undo + Environment.SetEnvironmentVariable("WEBSITE_SITE_NAME", ""); - var systemDataFalse = packageTelemetry.GetSystemData(OSPlatform.Linux); + var systemDataFalse = packageTelemetry.GetSystemData(OSPlatform.Linux); - Assert.AreEqual("not set", - systemDataFalse.Find(p => p.Key == "WebsiteName").Value.ToLowerInvariant()); + Assert.AreEqual("not set", + systemDataFalse.Find(p => p.Key == "WebsiteName").Value.ToLowerInvariant()); - Environment.SetEnvironmentVariable("WEBSITE_SITE_NAME", sourceValue); - } + Environment.SetEnvironmentVariable("WEBSITE_SITE_NAME", sourceValue); + } - [TestMethod] - public void ParseContent_Null() - { - var result = PackageTelemetry.ParseContent(null!); - Assert.AreEqual("null", result); - } + [TestMethod] + public void ParseContent_Null() + { + var result = PackageTelemetry.ParseContent(null!); + Assert.AreEqual("null", result); + } - [TestMethod] - public void GetPropValue_Null() - { - var result = PackageTelemetry.GetPropValue(null, "test"); - Assert.AreEqual(null, result); - } + [TestMethod] + public void GetPropValue_Null() + { + var result = PackageTelemetry.GetPropValue(null, "test"); + Assert.AreEqual(null, result); + } - [TestMethod] - public void GetPropValue_Null_Null() - { - var result = PackageTelemetry.GetPropValue(null, null!); - Assert.AreEqual(null, result); - } + [TestMethod] + public void GetPropValue_Null_Null() + { + var result = PackageTelemetry.GetPropValue(null, null!); + Assert.AreEqual(null, result); + } - private class TestClass - { - public bool Test { get; set; } = true; - } + [TestMethod] + public void GetPropValue_Object_TestClass() + { + var result = PackageTelemetry.GetPropValue(new TestClass(), "Test") as bool?; + Assert.IsTrue(result); + Assert.IsTrue(new TestClass().Test); + } - [TestMethod] - public void GetPropValue_Object_TestClass() - { - var result = PackageTelemetry.GetPropValue(new TestClass(), "Test") as bool?; - Assert.IsTrue(result); - Assert.IsTrue(new TestClass().Test); - } + [TestMethod] + public void GetPropValue_ReadValue() + { + var result = + PackageTelemetry.GetPropValue(new PropValueTestClass { Test = "1" }, "Test"); + Assert.AreEqual("1", result); + } - private class PropValueTestClass - { - [SuppressMessage("ReSharper", "UnusedAutoPropertyAccessor.Local")] - public string Test { get; set; } = string.Empty; - } + [TestMethod] + public void AddAppSettingsData() + { + var httpProvider = new FakeIHttpProvider(); + var appSettings = new AppSettings(); + var httpClientHelper = + new HttpClientHelper(httpProvider, _nullServiceScopeFactory, new FakeIWebLogger()); + var packageTelemetry = new PackageTelemetry(httpClientHelper, appSettings, + new FakeIWebLogger(), new FakeIQuery(), new FakeIDeviceIdService()); + var result = + packageTelemetry.AddAppSettingsData(new List>()); + + Assert.IsTrue(result.Exists(p => p.Key == "AppSettingsName")); + } - [TestMethod] - public void GetPropValue_ReadValue() - { - var result = - PackageTelemetry.GetPropValue(new PropValueTestClass { Test = "1" }, "Test"); - Assert.AreEqual("1", result); - } + [TestMethod] + public async Task PackageTelemetrySend_Disabled() + { + var httpProvider = new FakeIHttpProvider(); + var appSettings = new AppSettings { EnablePackageTelemetry = false }; + var httpClientHelper = + new HttpClientHelper(httpProvider, _nullServiceScopeFactory, new FakeIWebLogger()); + var packageTelemetry = new PackageTelemetry(httpClientHelper, appSettings, + new FakeIWebLogger(), new FakeIQuery(), new FakeIDeviceIdService()); + var result = await packageTelemetry.PackageTelemetrySend(); + Assert.IsNull(result); + } - [TestMethod] - public void AddAppSettingsData() - { - var httpProvider = new FakeIHttpProvider(); - var appSettings = new AppSettings(); - var httpClientHelper = new HttpClientHelper(httpProvider, null!, new FakeIWebLogger()); - var packageTelemetry = new PackageTelemetry(httpClientHelper, appSettings, - new FakeIWebLogger(), new FakeIQuery(), new FakeIDeviceIdService()); - var result = - packageTelemetry.AddAppSettingsData(new List>()); - - Assert.IsTrue(result.Exists(p => p.Key == "AppSettingsName")); - } - - [TestMethod] - public async Task PackageTelemetrySend_Disabled() - { - var httpProvider = new FakeIHttpProvider(); - var appSettings = new AppSettings { EnablePackageTelemetry = false }; - var httpClientHelper = new HttpClientHelper(httpProvider, null!, new FakeIWebLogger()); - var packageTelemetry = new PackageTelemetry(httpClientHelper, appSettings, - new FakeIWebLogger(), new FakeIQuery(), new FakeIDeviceIdService()); - var result = await packageTelemetry.PackageTelemetrySend(); - Assert.IsNull(result); - } - - - [TestMethod] - public async Task PackageTelemetrySend_HasSend() + + [TestMethod] + public async Task PackageTelemetrySend_HasSend() + { + var httpProvider = new FakeIHttpProvider(new Dictionary { - var httpProvider = new FakeIHttpProvider(new Dictionary { - { - "https://" + PackageTelemetry.PackageTelemetryUrl, - new StringContent(string.Empty) - } - }); - var appSettings = new AppSettings { EnablePackageTelemetry = true }; - var httpClientHelper = new HttpClientHelper(httpProvider, null!, new FakeIWebLogger()); - var packageTelemetry = new PackageTelemetry(httpClientHelper, appSettings, - new FakeIWebLogger(), new FakeIQuery(), new FakeIDeviceIdService()); - var result = await packageTelemetry.PackageTelemetrySend(); - Assert.IsTrue(result); - } - - - [TestMethod] - public async Task PackageTelemetrySend_False_EnablePackageTelemetryDebug() + "https://" + PackageTelemetry.PackageTelemetryUrl, new StringContent(string.Empty) + } + }); + var appSettings = new AppSettings { EnablePackageTelemetry = true }; + var httpClientHelper = + new HttpClientHelper(httpProvider, _nullServiceScopeFactory, new FakeIWebLogger()); + var packageTelemetry = new PackageTelemetry(httpClientHelper, appSettings, + new FakeIWebLogger(), new FakeIQuery(), new FakeIDeviceIdService()); + var result = await packageTelemetry.PackageTelemetrySend(); + Assert.IsTrue(result); + } + + + [TestMethod] + public async Task PackageTelemetrySend_False_EnablePackageTelemetryDebug() + { + var httpProvider = new FakeIHttpProvider(new Dictionary { - var httpProvider = new FakeIHttpProvider(new Dictionary - { - { - "https://" + PackageTelemetry.PackageTelemetryUrl, - new StringContent(string.Empty) - } - }); - var appSettings = new AppSettings { - EnablePackageTelemetry = true, EnablePackageTelemetryDebug = true - }; - var httpClientHelper = new HttpClientHelper(httpProvider, null!, new FakeIWebLogger()); - var packageTelemetry = new PackageTelemetry(httpClientHelper, appSettings, - new FakeIWebLogger(), new FakeIQuery(), new FakeIDeviceIdService()); - var result = await packageTelemetry.PackageTelemetrySend(); - Assert.IsNull(result); - } - - [TestMethod] - public async Task AddDatabaseData() + "https://" + PackageTelemetry.PackageTelemetryUrl, new StringContent(string.Empty) + } + }); + var appSettings = new AppSettings { - var appSettings = new AppSettings { EnablePackageTelemetry = true }; - var packageTelemetry = new PackageTelemetry(null!, appSettings, new FakeIWebLogger(), - new FakeIQuery(new List - { - new FileIndexItem("/test.jpg"), - new FileIndexItem("/test") { IsDirectory = true }, - }), new FakeIDeviceIdService()); - - var result = - await packageTelemetry.AddDatabaseData(new List>()); - - var res1 = - result.Find(p => p.Key == "FileIndexItemTotalCount"); - Assert.AreEqual("2", res1.Value); - - var res2 = - result.Find(p => p.Key == "FileIndexItemDirectoryCount"); - Assert.AreEqual("1", res2.Value); - - var res3 = - result.Find(p => p.Key == "FileIndexItemCount"); - Assert.AreEqual("1", res3.Value); - } - - [TestMethod] - public async Task AddDatabaseData_Exception() - { - var appSettings = new AppSettings { EnablePackageTelemetry = true }; - var packageTelemetry = new PackageTelemetry(null!, appSettings, - new FakeIWebLogger(), - new FakeIQueryException(new WebException("test")), new FakeIDeviceIdService()); - var result = - await packageTelemetry.AddDatabaseData(new List>()); - - var res1 = - result.Find(p => p.Key == "FileIndexItemTotalCount"); - Assert.AreEqual("-1", res1.Value); - - var res2 = - result.Find(p => p.Key == "FileIndexItemDirectoryCount"); - Assert.AreEqual("-1", res2.Value); - - var res3 = - result.Find(p => p.Key == "FileIndexItemCount"); - Assert.AreEqual("-1", res3.Value); - } + EnablePackageTelemetry = true, EnablePackageTelemetryDebug = true + }; + var httpClientHelper = + new HttpClientHelper(httpProvider, _nullServiceScopeFactory, new FakeIWebLogger()); + var packageTelemetry = new PackageTelemetry(httpClientHelper, appSettings, + new FakeIWebLogger(), new FakeIQuery(), new FakeIDeviceIdService()); + var result = await packageTelemetry.PackageTelemetrySend(); + Assert.IsNull(result); + } + + [TestMethod] + public async Task AddDatabaseData() + { + var appSettings = new AppSettings { EnablePackageTelemetry = true }; + var packageTelemetry = new PackageTelemetry(null!, appSettings, new FakeIWebLogger(), + new FakeIQuery(new List + { + new("/test.jpg"), new("/test") { IsDirectory = true } + }), new FakeIDeviceIdService()); + + var result = + await packageTelemetry.AddDatabaseData(new List>()); + + var res1 = + result.Find(p => p.Key == "FileIndexItemTotalCount"); + Assert.AreEqual("2", res1.Value); + + var res2 = + result.Find(p => p.Key == "FileIndexItemDirectoryCount"); + Assert.AreEqual("1", res2.Value); + + var res3 = + result.Find(p => p.Key == "FileIndexItemCount"); + Assert.AreEqual("1", res3.Value); + } + + [TestMethod] + public async Task AddDatabaseData_Exception() + { + var appSettings = new AppSettings { EnablePackageTelemetry = true }; + var packageTelemetry = new PackageTelemetry(null!, appSettings, + new FakeIWebLogger(), + new FakeIQueryException(new WebException("test")), new FakeIDeviceIdService()); + var result = + await packageTelemetry.AddDatabaseData(new List>()); + + var res1 = + result.Find(p => p.Key == "FileIndexItemTotalCount"); + Assert.AreEqual("-1", res1.Value); + + var res2 = + result.Find(p => p.Key == "FileIndexItemDirectoryCount"); + Assert.AreEqual("-1", res2.Value); + + var res3 = + result.Find(p => p.Key == "FileIndexItemCount"); + Assert.AreEqual("-1", res3.Value); + } + + private class TestClass + { + public bool Test { get; } = true; + } + + private class PropValueTestClass + { + [SuppressMessage("ReSharper", "UnusedAutoPropertyAccessor.Local")] + public string Test { get; set; } = string.Empty; } } diff --git a/starsky/starskytest/starsky.feature.rename/Services/RenameServiceTest.cs b/starsky/starskytest/starsky.feature.rename/Services/RenameServiceTest.cs index d012201496..91a2f6075c 100644 --- a/starsky/starskytest/starsky.feature.rename/Services/RenameServiceTest.cs +++ b/starsky/starskytest/starsky.feature.rename/Services/RenameServiceTest.cs @@ -17,1079 +17,1078 @@ using starskytest.FakeCreateAn; using starskytest.FakeMocks; -namespace starskytest.starsky.feature.rename.Services +namespace starskytest.starsky.feature.rename.Services; + +[TestClass] +public sealed class RenameServiceTest { - [TestClass] - public sealed class RenameServiceTest - { - private readonly Query _query; - private readonly CreateAnImage _newImage; - private readonly StorageSubPathFilesystem _iStorageSubPath; + private readonly StorageSubPathFilesystem _iStorageSubPath; + private readonly CreateAnImage _newImage; + private readonly Query _query; + private FileIndexItem _fileInExist = new(); + private FileIndexItem _folder1Exist = new(); - public RenameServiceTest() - { - var provider = new ServiceCollection() - .AddMemoryCache() - .BuildServiceProvider(); - var memoryCache = provider.GetService(); + private FileIndexItem _folderExist = new(); + private FileIndexItem _parentFolder = new(); - var builder = new DbContextOptionsBuilder(); - builder.UseInMemoryDatabase(nameof(RenameServiceTest)); - var options = builder.Options; - var context = new ApplicationDbContext(options); + public RenameServiceTest() + { + var provider = new ServiceCollection() + .AddMemoryCache() + .BuildServiceProvider(); + var memoryCache = provider.GetService(); - _newImage = new CreateAnImage(); + var builder = new DbContextOptionsBuilder(); + builder.UseInMemoryDatabase(nameof(RenameServiceTest)); + var options = builder.Options; + var context = new ApplicationDbContext(options); - var appSettings = new AppSettings - { - StorageFolder = PathHelper.AddBackslash(_newImage.BasePath), - ThumbnailTempFolder = _newImage.BasePath - }; - _query = new Query(context, appSettings, null, - new FakeIWebLogger(), memoryCache); + _newImage = new CreateAnImage(); + + var appSettings = new AppSettings + { + StorageFolder = PathHelper.AddBackslash(_newImage.BasePath), + ThumbnailTempFolder = _newImage.BasePath + }; + _query = new Query(context, appSettings, null, + new FakeIWebLogger(), memoryCache); - if ( _query.GetAllFiles("/").TrueForAll(p => p.FileName != _newImage.FileName) ) + if ( _query.GetAllFiles("/").TrueForAll(p => p.FileName != _newImage.FileName) ) + { + context.FileIndex.Add(new FileIndexItem { - context.FileIndex.Add(new FileIndexItem - { - FileName = _newImage.FileName, - ParentDirectory = "/", - AddToDatabase = DateTime.UtcNow, - }); - context.SaveChanges(); - } - - _iStorageSubPath = new StorageSubPathFilesystem(appSettings, new FakeIWebLogger()); + FileName = _newImage.FileName, + ParentDirectory = "/", + AddToDatabase = DateTime.UtcNow + }); + context.SaveChanges(); } - [TestMethod] - public async Task RenameFsTest_DuplicateFile() - { - var fileAlreadyExistSubPath = "/already_8758.txt"; - _iStorageSubPath.ExistFile(fileAlreadyExistSubPath); + _iStorageSubPath = new StorageSubPathFilesystem(appSettings, new FakeIWebLogger()); + } - if ( !_iStorageSubPath.ExistFile(fileAlreadyExistSubPath) ) - { - await _iStorageSubPath.WriteStreamAsync(StringToStreamHelper.StringToStream("test"), - fileAlreadyExistSubPath); - } + [TestMethod] + public async Task RenameFsTest_DuplicateFile() + { + var fileAlreadyExistSubPath = "/already_8758.txt"; + _iStorageSubPath.ExistFile(fileAlreadyExistSubPath); - var renameFs = await new RenameService(_query, _iStorageSubPath).Rename( - _newImage.DbPath, + if ( !_iStorageSubPath.ExistFile(fileAlreadyExistSubPath) ) + { + await _iStorageSubPath.WriteStreamAsync( + StringToStreamHelper.StringToStream("test-content-rename-fs"), fileAlreadyExistSubPath); + } - var result = await StreamToStringHelper.StreamToStringAsync( - _iStorageSubPath.ReadStream(fileAlreadyExistSubPath)); + var renameFs = await new RenameService(_query, _iStorageSubPath).Rename( + _newImage.DbPath, + fileAlreadyExistSubPath); - // it should not overwrite the target file - Assert.IsTrue(result.Contains("test")); - Assert.AreEqual(FileIndexItem.ExifStatus.OperationNotSupported, - renameFs.FirstOrDefault()?.Status); + var result = await StreamToStringHelper.StreamToStringAsync( + _iStorageSubPath.ReadStream(fileAlreadyExistSubPath)); - // and there are no more files with a name that looks like already_8758 - // should only have one file with filename: already_8758 - var count = _iStorageSubPath.GetAllFilesInDirectory("/") - .Count(p => p.StartsWith(fileAlreadyExistSubPath)); - Assert.AreEqual(1, count); + // it should not overwrite the target file + Assert.IsTrue(result.Contains("test")); + Assert.AreEqual(FileIndexItem.ExifStatus.OperationNotSupported, + renameFs.FirstOrDefault()?.Status); - // and remove the file afterwards - _iStorageSubPath.FileDelete(fileAlreadyExistSubPath); - } + // and there are no more files with a name that looks like already_8758 + // should only have one file with filename: already_8758 + var count = _iStorageSubPath.GetAllFilesInDirectory("/") + .Count(p => p.StartsWith(fileAlreadyExistSubPath)); + Assert.AreEqual(1, count); - [TestMethod] - public async Task RenameFsTest_MoveFileWithoutAnyItems() + // and remove the file afterwards + _iStorageSubPath.FileDelete(fileAlreadyExistSubPath); + } + + [TestMethod] + public async Task RenameFsTest_MoveFileWithoutAnyItems() + { + var renameFs = + await new RenameService(_query, _iStorageSubPath).Rename("/non-exist.jpg", + "/non-exist2.jpg"); + Assert.AreEqual(FileIndexItem.ExifStatus.NotFoundNotInIndex, + renameFs.FirstOrDefault()?.Status); + } + + private async Task CreateFoldersAndFilesInDatabase() + { + _folderExist = await _query.AddItemAsync(new FileIndexItem { - var renameFs = - await new RenameService(_query, _iStorageSubPath).Rename("/non-exist.jpg", - "/non-exist2.jpg"); - Assert.AreEqual(FileIndexItem.ExifStatus.NotFoundNotInIndex, - renameFs.FirstOrDefault()?.Status); - } + FileName = "exist", + ParentDirectory = "/", + AddToDatabase = DateTime.UtcNow, + FileHash = "34567898765434567487984785487", + IsDirectory = true + }); + + _fileInExist = await _query.AddItemAsync(new FileIndexItem + { + FileName = "file.jpg", ParentDirectory = "/exist", IsDirectory = false + }); - private FileIndexItem _folderExist = new FileIndexItem(); - private FileIndexItem _folder1Exist = new FileIndexItem(); - private FileIndexItem _fileInExist = new FileIndexItem(); - private FileIndexItem _parentFolder = new FileIndexItem(); + _folder1Exist = await _query.AddItemAsync(new FileIndexItem + { + FileName = "folder1", + ParentDirectory = "/", + IsDirectory = true, + FileHash = "3497867df894587" + }); - private async Task CreateFoldersAndFilesInDatabase() + _parentFolder = await _query.AddItemAsync(new FileIndexItem { - _folderExist = await _query.AddItemAsync(new FileIndexItem - { - FileName = "exist", - ParentDirectory = "/", - AddToDatabase = DateTime.UtcNow, - FileHash = "34567898765434567487984785487", - IsDirectory = true - }); + FileName = "/", ParentDirectory = "/", IsDirectory = true + }); + } - _fileInExist = await _query.AddItemAsync(new FileIndexItem - { - FileName = "file.jpg", ParentDirectory = "/exist", IsDirectory = false - }); + private async Task RemoveFoldersAndFilesInDatabase() + { + Assert.IsNotNull(_folderExist); + Assert.IsNotNull(_folder1Exist); + Assert.IsNotNull(_fileInExist); + Assert.IsNotNull(_parentFolder); + + await _query.RemoveItemAsync(_folderExist); + await _query.RemoveItemAsync(_folder1Exist); + await _query.RemoveItemAsync(_fileInExist); + await _query.RemoveItemAsync(_parentFolder); + } - _folder1Exist = await _query.AddItemAsync(new FileIndexItem - { - FileName = "folder1", - ParentDirectory = "/", - IsDirectory = true, - FileHash = "3497867df894587", - }); + [TestMethod] + public async Task RenameFsTest_FakeIStorage_RenameOneFile() + { + // RenameFsTest_MoveFileToSameFolder_Items + + await CreateFoldersAndFilesInDatabase(); + Assert.IsNotNull(_folderExist); + Assert.IsNotNull(_folder1Exist); + Assert.IsNotNull(_fileInExist); + Assert.IsNotNull(_parentFolder); + + var iStorage = new FakeIStorage(new List { _folderExist.FilePath! }, + new List { _fileInExist.FilePath! }); + + var renameFs1 = await new RenameService(_query, iStorage) + .Rename(_fileInExist.FilePath!, _folderExist.FilePath + "/test2.jpg"); + var renameFs = renameFs1 + .Where(p => p.Status != FileIndexItem.ExifStatus.NotFoundSourceMissing).ToList(); - _parentFolder = await _query.AddItemAsync(new FileIndexItem + // query database + var all = await _query.GetAllRecursiveAsync(); + Assert.AreEqual("test2.jpg", all.Find(p => p.FileName == "test2.jpg")?.FileName); + + // old item is not in db + Assert.AreEqual(null, all.Find(p => p.FileName == "test.jpg")?.FileName); + + // use cached view + var singleItem = _query.SingleItem(_folderExist.FilePath + "/test2.jpg"); + Assert.AreEqual("test2.jpg", singleItem?.FileIndexItem?.FileName); + + Assert.AreEqual(1, renameFs.Count); + + await RemoveFoldersAndFilesInDatabase(); + } + + [TestMethod] + public async Task RenameFsTest_RenameOneFile_JsonSidecarFile() + { + await CreateFoldersAndFilesInDatabase(); + + var iStorage = new FakeIStorage(new List { _folderExist.FilePath! }, + new List { - FileName = "/", ParentDirectory = "/", IsDirectory = true, + _fileInExist.FilePath!, JsonSidecarLocation.JsonLocation(_fileInExist.FilePath!) }); - } - private async Task RemoveFoldersAndFilesInDatabase() - { - Assert.IsNotNull(_folderExist); - Assert.IsNotNull(_folder1Exist); - Assert.IsNotNull(_fileInExist); - Assert.IsNotNull(_parentFolder); - - await _query.RemoveItemAsync(_folderExist); - await _query.RemoveItemAsync(_folder1Exist); - await _query.RemoveItemAsync(_fileInExist); - await _query.RemoveItemAsync(_parentFolder); - } + var renameFs = await new RenameService(_query, iStorage) + .Rename(_fileInExist.FilePath!, _folderExist.FilePath + "/test2.jpg"); - [TestMethod] - public async Task RenameFsTest_FakeIStorage_RenameOneFile() - { - // RenameFsTest_MoveFileToSameFolder_Items + // check if sidecar json are moved (on fake Filesystem) + var values = iStorage.GetAllFilesInDirectoryRecursive("/").ToList(); + Assert.AreEqual("/exist/.starsky.test2.jpg.json", + values.Find(p => p == "/exist/.starsky.test2.jpg.json")); + Assert.AreEqual(FileIndexItem.ExifStatus.Ok, + renameFs.Find(p => p.FilePath == "/exist/test2.jpg")?.Status); + Assert.AreEqual(FileIndexItem.ExifStatus.NotFoundSourceMissing, + renameFs.Find(p => p.FilePath == "/exist/file.jpg")?.Status); - await CreateFoldersAndFilesInDatabase(); - Assert.IsNotNull(_folderExist); - Assert.IsNotNull(_folder1Exist); - Assert.IsNotNull(_fileInExist); - Assert.IsNotNull(_parentFolder); + await RemoveFoldersAndFilesInDatabase(); + } - var iStorage = new FakeIStorage(new List { _folderExist.FilePath! }, - new List { _fileInExist.FilePath! }); + [TestMethod] + public async Task RenameFsTest_FakeIStorage_RenameOneFile_ToWrongNewFileName() + { + await CreateFoldersAndFilesInDatabase(); - var renameFs1 = await new RenameService(_query, iStorage) - .Rename(_fileInExist.FilePath!, _folderExist.FilePath + "/test2.jpg"); - var renameFs = renameFs1 - .Where(p => p.Status != FileIndexItem.ExifStatus.NotFoundSourceMissing).ToList(); + var iStorage = new FakeIStorage(new List { _folderExist.FilePath! }, + new List { _fileInExist.FilePath! }); - // query database - var all = await _query.GetAllRecursiveAsync(); - Assert.AreEqual("test2.jpg", all.Find(p => p.FileName == "test2.jpg")?.FileName); + var renameFs = await new RenameService(_query, iStorage) + .Rename(_fileInExist.FilePath!, _folderExist.FilePath + "/test2___"); - // old item is not in db - Assert.AreEqual(null, all.Find(p => p.FileName == "test.jpg")?.FileName); + // so this operation is not supported - // use cached view - var singleItem = _query.SingleItem(_folderExist.FilePath + "/test2.jpg"); - Assert.AreEqual("test2.jpg", singleItem?.FileIndexItem?.FileName); + Assert.AreEqual(FileIndexItem.ExifStatus.OperationNotSupported, + renameFs.FirstOrDefault()?.Status); - Assert.AreEqual(1, renameFs.Count); + await RemoveFoldersAndFilesInDatabase(); + } - await RemoveFoldersAndFilesInDatabase(); - } + [TestMethod] + public async Task RenameFsTest_FakeIStorage_FileToNonExistFolder_Items() + { + await CreateFoldersAndFilesInDatabase(); + + var initFolderList = new List { "/" }; + var initFileList = new List { _fileInExist.FilePath! }; + var iStorage = new FakeIStorage(initFolderList, initFileList); + var renameFs1 = await new RenameService(_query, iStorage) + .Rename(initFileList.FirstOrDefault()!, "/nonExist/test5.jpg"); + var renameFs = renameFs1.Where(p => p.Status != FileIndexItem.ExifStatus.Deleted) + .ToList(); + + var all2 = await _query.GetAllRecursiveAsync(); + var selectFile3 = all2.Find(p => p.FileName == "test5.jpg"); + Assert.AreEqual("test5.jpg", selectFile3?.FileName); + Assert.AreEqual("/nonExist", selectFile3?.ParentDirectory); + + // check if files are moved + var values = iStorage.GetAllFilesInDirectory("/nonExist").ToList(); + Assert.AreEqual("/nonExist/test5.jpg", values.Find(p => p == "/nonExist/test5.jpg")); + + var initFileListFirst = renameFs.Find(p => + p.FilePath == initFileList.FirstOrDefault()); + Assert.AreEqual(initFileList.FirstOrDefault(), initFileListFirst!.FilePath); + Assert.AreEqual(FileIndexItem.ExifStatus.NotFoundSourceMissing, + initFileListFirst.Status); + + var nonExistTest5 = renameFs.Find(p => + p.FilePath == "/nonExist/test5.jpg"); + Assert.AreEqual("/nonExist/test5.jpg", nonExistTest5?.FilePath); + Assert.AreEqual(FileIndexItem.ExifStatus.Ok, nonExistTest5?.Status); + + var nonExist = renameFs.Find(p => + p.FilePath == "/nonExist"); + Assert.AreEqual("/nonExist", nonExist?.FilePath); + Assert.AreEqual(FileIndexItem.ExifStatus.Ok, nonExist?.Status); + + await RemoveFoldersAndFilesInDatabase(); + } - [TestMethod] - public async Task RenameFsTest_RenameOneFile_JsonSidecarFile() - { - await CreateFoldersAndFilesInDatabase(); - - var iStorage = new FakeIStorage(new List { _folderExist.FilePath! }, - new List - { - _fileInExist.FilePath!, - JsonSidecarLocation.JsonLocation(_fileInExist.FilePath!) - }); - - var renameFs = await new RenameService(_query, iStorage) - .Rename(_fileInExist.FilePath!, _folderExist.FilePath + "/test2.jpg"); - - // check if sidecar json are moved (on fake Filesystem) - var values = iStorage.GetAllFilesInDirectoryRecursive("/").ToList(); - Assert.AreEqual("/exist/.starsky.test2.jpg.json", - values.Find(p => p == "/exist/.starsky.test2.jpg.json")); - Assert.AreEqual(FileIndexItem.ExifStatus.Ok, - renameFs.Find(p => p.FilePath == "/exist/test2.jpg")?.Status); - Assert.AreEqual(FileIndexItem.ExifStatus.NotFoundSourceMissing, - renameFs.Find(p => p.FilePath == "/exist/file.jpg")?.Status); - - await RemoveFoldersAndFilesInDatabase(); - } + [TestMethod] + public async Task RenameFsTest_FakeIStorage_File_To_ExistFolder_MoveToTheSamePath() + { + await CreateFoldersAndFilesInDatabase(); - [TestMethod] - public async Task RenameFsTest_FakeIStorage_RenameOneFile_ToWrongNewFileName() - { - await CreateFoldersAndFilesInDatabase(); + var initFolderList = new List { "/", "/exist" }; + var initFileList = new List { _fileInExist.FilePath! }; + var iStorage = new FakeIStorage(initFolderList, initFileList); + var renameFs = await new RenameService(_query, iStorage) + .Rename(initFileList.FirstOrDefault()!, "/exist/"); + Assert.AreEqual(FileIndexItem.ExifStatus.OperationNotSupported, + renameFs.FirstOrDefault()?.Status); - var iStorage = new FakeIStorage(new List { _folderExist.FilePath! }, - new List { _fileInExist.FilePath! }); + await RemoveFoldersAndFilesInDatabase(); + } - var renameFs = await new RenameService(_query, iStorage) - .Rename(_fileInExist.FilePath!, _folderExist.FilePath + "/test2___"); + [TestMethod] + public async Task + RenameFsTest_FakeIStorage_File_To_ExistFolder() // there is a separate sidecar json test + { + await CreateFoldersAndFilesInDatabase(); - // so this operation is not supported + var initFolderList = new List { "/", "/test" }; + var initFileList = new List { _fileInExist.FilePath! }; + var fakeIStorage = new FakeIStorage(initFolderList, initFileList); - Assert.AreEqual(FileIndexItem.ExifStatus.OperationNotSupported, - renameFs.FirstOrDefault()?.Status); + var renameFsResult = + await new RenameService(_query, fakeIStorage).Rename(initFileList.FirstOrDefault()!, + "/test/"); - await RemoveFoldersAndFilesInDatabase(); - } + var oldItem = await _query.GetObjectByFilePathAsync("/exist/file.jpg"); + Assert.IsNull(oldItem); - [TestMethod] - public async Task RenameFsTest_FakeIStorage_FileToNonExistFolder_Items() - { - await CreateFoldersAndFilesInDatabase(); - - var initFolderList = new List { "/" }; - var initFileList = new List { _fileInExist.FilePath! }; - var iStorage = new FakeIStorage(initFolderList, initFileList); - var renameFs1 = await new RenameService(_query, iStorage) - .Rename(initFileList.FirstOrDefault()!, "/nonExist/test5.jpg"); - var renameFs = renameFs1.Where(p => p.Status != FileIndexItem.ExifStatus.Deleted) - .ToList(); - - var all2 = await _query.GetAllRecursiveAsync(); - var selectFile3 = all2.Find(p => p.FileName == "test5.jpg"); - Assert.AreEqual("test5.jpg", selectFile3?.FileName); - Assert.AreEqual("/nonExist", selectFile3?.ParentDirectory); - - // check if files are moved - var values = iStorage.GetAllFilesInDirectory("/nonExist").ToList(); - Assert.AreEqual("/nonExist/test5.jpg", values.Find(p => p == "/nonExist/test5.jpg")); - - var initFileListFirst = renameFs.Find(p => - p.FilePath == initFileList.FirstOrDefault()); - Assert.AreEqual(initFileList.FirstOrDefault(), initFileListFirst!.FilePath); - Assert.AreEqual(FileIndexItem.ExifStatus.NotFoundSourceMissing, - initFileListFirst.Status); - - var nonExistTest5 = renameFs.Find(p => - p.FilePath == "/nonExist/test5.jpg"); - Assert.AreEqual("/nonExist/test5.jpg", nonExistTest5?.FilePath); - Assert.AreEqual(FileIndexItem.ExifStatus.Ok, nonExistTest5?.Status); - - var nonExist = renameFs.Find(p => - p.FilePath == "/nonExist"); - Assert.AreEqual("/nonExist", nonExist?.FilePath); - Assert.AreEqual(FileIndexItem.ExifStatus.Ok, nonExist?.Status); - - await RemoveFoldersAndFilesInDatabase(); - } + // to file: (in database) + var all2 = ( await _query.GetAllRecursiveAsync() ) + .Where(p => p.ParentDirectory?.Contains("/test") == true); + var selectFile3 = all2.FirstOrDefault(p => p.FilePath == "/test/file.jpg"); + Assert.AreEqual("file.jpg", selectFile3?.FileName); + Assert.AreEqual("/test", selectFile3?.ParentDirectory); - [TestMethod] - public async Task RenameFsTest_FakeIStorage_File_To_ExistFolder_MoveToTheSamePath() - { - await CreateFoldersAndFilesInDatabase(); + // check if files are moved (on fake Filesystem) + var values = fakeIStorage.GetAllFilesInDirectory("/test").ToList(); + Assert.AreEqual("/test/file.jpg", values.Find(p => p == "/test/file.jpg")); - var initFolderList = new List { "/", "/exist" }; - var initFileList = new List { _fileInExist.FilePath! }; - var iStorage = new FakeIStorage(initFolderList, initFileList); - var renameFs = await new RenameService(_query, iStorage) - .Rename(initFileList.FirstOrDefault()!, "/exist/"); - Assert.AreEqual(FileIndexItem.ExifStatus.OperationNotSupported, - renameFs.FirstOrDefault()?.Status); + Assert.AreEqual(FileIndexItem.ExifStatus.NotFoundSourceMissing, + renameFsResult.FirstOrDefault()?.Status); + Assert.AreEqual(FileIndexItem.ExifStatus.Ok, renameFsResult[1].Status); - await RemoveFoldersAndFilesInDatabase(); - } + await RemoveFoldersAndFilesInDatabase(); + } - [TestMethod] - public async Task - RenameFsTest_FakeIStorage_File_To_ExistFolder() // there is a separate sidecar json test + [TestMethod] + public async Task RenameFsTest_FakeIStorage_File_To_ExistFolder_Json_SidecarFile() + { + await CreateFoldersAndFilesInDatabase(); + + var initFolderList = new List { "/", "/test" }; + var initFileList = new List { - await CreateFoldersAndFilesInDatabase(); + _fileInExist.FilePath!, JsonSidecarLocation.JsonLocation(_fileInExist.FilePath!) + }; - var initFolderList = new List { "/", "/test" }; - var initFileList = new List { _fileInExist.FilePath! }; - var fakeIStorage = new FakeIStorage(initFolderList, initFileList); + var iStorage = new FakeIStorage(initFolderList, initFileList); - var renameFsResult = - await new RenameService(_query, fakeIStorage).Rename(initFileList.FirstOrDefault()!, - "/test/"); + // the input is still FileName = "file.jpg", ParentDirectory = "/exist", + var renameFs = await new RenameService(_query, iStorage) + .Rename(initFileList.FirstOrDefault()!, "/test/"); - var oldItem = await _query.GetObjectByFilePathAsync("/exist/file.jpg"); - Assert.IsNull(oldItem); + // to file: (in database) + var all2 = await _query.GetAllRecursiveAsync(); + var selectFile3 = all2.Find(p => p.FileName == "file.jpg"); + Assert.AreEqual("file.jpg", selectFile3?.FileName); + Assert.AreEqual("/test", selectFile3?.ParentDirectory); - // to file: (in database) - var all2 = ( await _query.GetAllRecursiveAsync() ) - .Where(p => p.ParentDirectory?.Contains("/test") == true); - var selectFile3 = all2.FirstOrDefault(p => p.FilePath == "/test/file.jpg"); - Assert.AreEqual("file.jpg", selectFile3?.FileName); - Assert.AreEqual("/test", selectFile3?.ParentDirectory); + // check if sidecar json are moved (on fake Filesystem) + var values = iStorage.GetAllFilesInDirectoryRecursive("/test").ToList(); - // check if files are moved (on fake Filesystem) - var values = fakeIStorage.GetAllFilesInDirectory("/test").ToList(); - Assert.AreEqual("/test/file.jpg", values.Find(p => p == "/test/file.jpg")); + Assert.AreEqual("/test/.starsky.file.jpg.json", + values.Find(p => p == "/test/.starsky.file.jpg.json")); + Assert.AreEqual(FileIndexItem.ExifStatus.NotFoundSourceMissing, + renameFs.FirstOrDefault()?.Status); + Assert.AreEqual(FileIndexItem.ExifStatus.Ok, renameFs[1].Status); - Assert.AreEqual(FileIndexItem.ExifStatus.NotFoundSourceMissing, - renameFsResult.FirstOrDefault()?.Status); - Assert.AreEqual(FileIndexItem.ExifStatus.Ok, renameFsResult[1].Status); + await RemoveFoldersAndFilesInDatabase(); + } - await RemoveFoldersAndFilesInDatabase(); - } + [TestMethod] + public async Task RenameFsTest_FakeIStorage_mergeTwoFolders() + { + await CreateFoldersAndFilesInDatabase(); - [TestMethod] - public async Task RenameFsTest_FakeIStorage_File_To_ExistFolder_Json_SidecarFile() + var existSubFolder = await _query.AddItemAsync(new FileIndexItem { - await CreateFoldersAndFilesInDatabase(); + FileName = "subfolder", + ParentDirectory = _folder1Exist.FilePath, + IsDirectory = true, + FileHash = "InjectedAsExistSubFolder" + }); - var initFolderList = new List { "/", "/test" }; - var initFileList = new List - { - _fileInExist.FilePath!, JsonSidecarLocation.JsonLocation(_fileInExist.FilePath!) - }; + var existSubFolderChildJpg = await _query.AddItemAsync(new FileIndexItem + { + FileName = "child.jpg", + ParentDirectory = _folder1Exist.FilePath + "/subfolder", + FileHash = "InjectedAsExistSubFolderChildJpg" + }); - var iStorage = new FakeIStorage(initFolderList, initFileList); - // the input is still FileName = "file.jpg", ParentDirectory = "/exist", - var renameFs = await new RenameService(_query, iStorage) - .Rename(initFileList.FirstOrDefault()!, "/test/"); + var initFolderList = new List + { + "/", + _folderExist.FilePath + "/subfolder", + _folder1Exist.FilePath!, + _folderExist.FilePath! + }; - // to file: (in database) - var all2 = await _query.GetAllRecursiveAsync(); - var selectFile3 = all2.Find(p => p.FileName == "file.jpg"); - Assert.AreEqual("file.jpg", selectFile3?.FileName); - Assert.AreEqual("/test", selectFile3?.ParentDirectory); + var initFileList = new List + { + _fileInExist.FilePath!, + _folder1Exist.FilePath + "/subfolder/child.jpg", + _folder1Exist.FilePath + "/subfolder/not_synced_item.jpg" + }; + var iStorage = new FakeIStorage(initFolderList, initFileList); + + // the call + var renameFs = await new RenameService(_query, iStorage) + .Rename("/exist", "/folder1"); + + // First check if fakeDisk is changed + var folder1Files = iStorage.GetAllFilesInDirectory("/folder1").ToList(); + var folder1Dir = iStorage.GetDirectoryRecursive("/folder1").Select(p => p.Key).ToList(); + + Assert.AreEqual("/folder1/file.jpg", folder1Files[0]); + Assert.AreEqual("/folder1/subfolder", folder1Dir[0]); + + var existDirContent = + iStorage.GetDirectoryRecursive("/exist").Select(p => p.Key).ToList(); + var existFolder = iStorage.GetAllFilesInDirectory("/exist").ToList(); + + Assert.AreEqual(0, existDirContent.Count); + Assert.AreEqual(0, existFolder.Count); + + // Now check if FakeDb is changed + var all2 = await _query.GetAllRecursiveAsync(); + + Assert.AreEqual("/folder1/file.jpg", + all2.Find(p => + p.FileName == "file.jpg" && + p.Status != FileIndexItem.ExifStatus.NotFoundSourceMissing)?.FilePath); + Assert.AreEqual("/folder1/subfolder", + all2.Find(p => + p.FileName == "subfolder" && + p.Status != FileIndexItem.ExifStatus.NotFoundSourceMissing)?.FilePath); + Assert.AreEqual("/folder1/subfolder/child.jpg", + all2.Find(p => + p.FileName == "child.jpg" && + p.Status != FileIndexItem.ExifStatus.NotFoundSourceMissing)?.FilePath); + + // FileIndexItem.ExifStatus.Ok, /folder1/file.jpg - + // FileIndexItem.ExifStatus.Ok, /folder1 + // NotFoundSourceMissing /exist + + var file = renameFs + .Find(p => p.FilePath == "/folder1/file.jpg"); + var folder1 = renameFs + .Find(p => p.FilePath == "/folder1"); + var exist = renameFs + .Find(p => p.FilePath == "/exist"); + + Assert.AreEqual("/folder1/file.jpg", file?.FilePath); + Assert.AreEqual("/folder1", folder1?.FilePath); + Assert.AreEqual("/exist", exist?.FilePath); + + Assert.AreEqual(FileIndexItem.ExifStatus.Ok, file?.Status); + Assert.AreEqual(FileIndexItem.ExifStatus.Ok, folder1?.Status); + Assert.AreEqual(FileIndexItem.ExifStatus.NotFoundSourceMissing, exist?.Status); + + await _query.RemoveItemAsync(existSubFolder); + await _query.RemoveItemAsync(existSubFolderChildJpg); + + await RemoveFoldersAndFilesInDatabase(); + } - // check if sidecar json are moved (on fake Filesystem) - var values = iStorage.GetAllFilesInDirectoryRecursive("/test").ToList(); + [TestMethod] + public async Task RenameFsTest_TheSameInput() + { + var initFolderList = new List(); + var initFileList = new List(); + var fakeIStorage = new FakeIStorage(initFolderList, initFileList); + var renameFs = await new RenameService(_query, fakeIStorage).Rename("/same", "/same"); + Assert.AreEqual(1, renameFs.Count); + Assert.AreEqual(FileIndexItem.ExifStatus.OperationNotSupported, + renameFs.FirstOrDefault()?.Status); + } - Assert.AreEqual("/test/.starsky.file.jpg.json", - values.Find(p => p == "/test/.starsky.file.jpg.json")); - Assert.AreEqual(FileIndexItem.ExifStatus.NotFoundSourceMissing, - renameFs.FirstOrDefault()?.Status); - Assert.AreEqual(FileIndexItem.ExifStatus.Ok, renameFs[1].Status); + [TestMethod] + public void RenameFsTest_FakeIStorage_UnderstandTest() + { + // used to test the GetAllFilesInDirectory() fake class + var initFolderList = + new List { "/", "/test/subfolder", "/test", "/otherfolder" }; + var initFileList = new List + { + "/test/test.jpg", "/test/subfolder/t.jpg", "/test/subfolder/child.jpg" + }; + var iStorage = new FakeIStorage(initFolderList, + initFileList).GetAllFilesInDirectory("/test").ToList(); + Assert.AreEqual(1, iStorage.Count); + } - await RemoveFoldersAndFilesInDatabase(); - } + [TestMethod] + public async Task RenameFsTest_MoveAFolderIntoAFile() + { + await CreateFoldersAndFilesInDatabase(); + var iStorage = new FakeIStorage(); + var renameFs = + await new RenameService(_query, iStorage).Rename(_folderExist.FilePath!, + _fileInExist.FilePath!); + Assert.AreEqual(FileIndexItem.ExifStatus.NotFoundNotInIndex, renameFs[0].Status); + } - [TestMethod] - public async Task RenameFsTest_FakeIStorage_mergeTwoFolders() - { - await CreateFoldersAndFilesInDatabase(); + [TestMethod] + public async Task Rename_MoveFileToRootFolder() + { + var itemInChildFolderPath = "/child_folder/test_01.jpg"; + await _query.AddItemAsync(new FileIndexItem(itemInChildFolderPath)); + await _query.AddParentItemsAsync(itemInChildFolderPath); + var iStorage = new FakeIStorage(new List { "/", "/child_folder" }, + new List { "/child_folder/test_01.jpg" }); - var existSubFolder = await _query.AddItemAsync(new FileIndexItem - { - FileName = "subfolder", - ParentDirectory = _folder1Exist.FilePath, - IsDirectory = true, - FileHash = "InjectedAsExistSubFolder" - }); + var renameFs = + await new RenameService(_query, iStorage).Rename(itemInChildFolderPath, "/"); - var existSubFolderChildJpg = await _query.AddItemAsync(new FileIndexItem - { - FileName = "child.jpg", - ParentDirectory = _folder1Exist.FilePath + "/subfolder", - FileHash = "InjectedAsExistSubFolderChildJpg" - }); + // where its from + Assert.AreEqual("/child_folder", renameFs.FirstOrDefault()?.ParentDirectory); + Assert.AreEqual("/child_folder/test_01.jpg", renameFs.FirstOrDefault()?.FilePath); + Assert.AreEqual("/", renameFs[1].ParentDirectory); + Assert.AreEqual("/test_01.jpg", renameFs[1].FilePath); - var initFolderList = new List - { - "/", - _folderExist.FilePath + "/subfolder", - _folder1Exist.FilePath!, - _folderExist.FilePath! - }; + Assert.AreEqual("/test_01.jpg", + _query.SingleItem("/test_01.jpg")?.FileIndexItem?.FilePath); + Assert.AreEqual(null, _query.SingleItem(itemInChildFolderPath)); + } - var initFileList = new List - { - _fileInExist.FilePath!, - _folder1Exist.FilePath + "/subfolder/child.jpg", - _folder1Exist.FilePath + "/subfolder/not_synced_item.jpg" - }; - var iStorage = new FakeIStorage(initFolderList, initFileList); - - // the call - var renameFs = await new RenameService(_query, iStorage) - .Rename("/exist", "/folder1"); - - // First check if fakeDisk is changed - var folder1Files = iStorage.GetAllFilesInDirectory("/folder1").ToList(); - var folder1Dir = iStorage.GetDirectoryRecursive("/folder1").Select(p => p.Key).ToList(); - - Assert.AreEqual("/folder1/file.jpg", folder1Files[0]); - Assert.AreEqual("/folder1/subfolder", folder1Dir[0]); - - var existDirContent = - iStorage.GetDirectoryRecursive("/exist").Select(p => p.Key).ToList(); - var existFolder = iStorage.GetAllFilesInDirectory("/exist").ToList(); - - Assert.AreEqual(0, existDirContent.Count); - Assert.AreEqual(0, existFolder.Count); - - // Now check if FakeDb is changed - var all2 = await _query.GetAllRecursiveAsync(); - - Assert.AreEqual("/folder1/file.jpg", - all2.Find(p => - p.FileName == "file.jpg" && - p.Status != FileIndexItem.ExifStatus.NotFoundSourceMissing)?.FilePath); - Assert.AreEqual("/folder1/subfolder", - all2.Find(p => - p.FileName == "subfolder" && - p.Status != FileIndexItem.ExifStatus.NotFoundSourceMissing)?.FilePath); - Assert.AreEqual("/folder1/subfolder/child.jpg", - all2.Find(p => - p.FileName == "child.jpg" && - p.Status != FileIndexItem.ExifStatus.NotFoundSourceMissing)?.FilePath); - - // FileIndexItem.ExifStatus.Ok, /folder1/file.jpg - - // FileIndexItem.ExifStatus.Ok, /folder1 - // NotFoundSourceMissing /exist - - var file = renameFs - .Find(p => p.FilePath == "/folder1/file.jpg"); - var folder1 = renameFs - .Find(p => p.FilePath == "/folder1"); - var exist = renameFs - .Find(p => p.FilePath == "/exist"); - - Assert.AreEqual("/folder1/file.jpg", file?.FilePath); - Assert.AreEqual("/folder1", folder1?.FilePath); - Assert.AreEqual("/exist", exist?.FilePath); - - Assert.AreEqual(FileIndexItem.ExifStatus.Ok, file?.Status); - Assert.AreEqual(FileIndexItem.ExifStatus.Ok, folder1?.Status); - Assert.AreEqual(FileIndexItem.ExifStatus.NotFoundSourceMissing, exist?.Status); - - await _query.RemoveItemAsync(existSubFolder); - await _query.RemoveItemAsync(existSubFolderChildJpg); - - await RemoveFoldersAndFilesInDatabase(); - } + [TestMethod] + public async Task Rename_Move_FileToFolder_Collections() + { + var itemInChildFolderPath = "/child_folder/test_10.jpg"; + await _query.AddItemAsync(new FileIndexItem(itemInChildFolderPath)); + await _query.AddItemAsync(new FileIndexItem("/child_folder/test_10.png")); + await _query.AddParentItemsAsync(itemInChildFolderPath); - [TestMethod] - public async Task RenameFsTest_TheSameInput() - { - var initFolderList = new List(); - var initFileList = new List(); - var fakeIStorage = new FakeIStorage(initFolderList, initFileList); - var renameFs = await new RenameService(_query, fakeIStorage).Rename("/same", "/same"); - Assert.AreEqual(1, renameFs.Count); - Assert.AreEqual(FileIndexItem.ExifStatus.OperationNotSupported, - renameFs.FirstOrDefault()?.Status); - } + var iStorage = new FakeIStorage( + new List { "/", "/child_folder", "/child_folder2" }, + new List { "/child_folder/test_10.jpg", "/child_folder/test_10.png" }); - [TestMethod] - public void RenameFsTest_FakeIStorage_UnderstandTest() - { - // used to test the GetAllFilesInDirectory() fake class - var initFolderList = - new List { "/", "/test/subfolder", "/test", "/otherfolder" }; - var initFileList = new List - { - "/test/test.jpg", "/test/subfolder/t.jpg", "/test/subfolder/child.jpg" - }; - var iStorage = new FakeIStorage(initFolderList, - initFileList).GetAllFilesInDirectory("/test").ToList(); - Assert.AreEqual(1, iStorage.Count); - } + var renameFs = await new RenameService(_query, iStorage) + .Rename(itemInChildFolderPath, "/child_folder2"); - [TestMethod] - public async Task RenameFsTest_MoveAFolderIntoAFile() - { - await CreateFoldersAndFilesInDatabase(); - var iStorage = new FakeIStorage(); - var renameFs = - await new RenameService(_query, iStorage).Rename(_folderExist.FilePath!, - _fileInExist.FilePath!); - Assert.AreEqual(FileIndexItem.ExifStatus.NotFoundNotInIndex, renameFs[0].Status); - } + // the first one is the deleted item + Assert.AreEqual("/child_folder2", renameFs[1].ParentDirectory); + Assert.AreEqual("/child_folder2/test_10.jpg", renameFs[1].FilePath); - [TestMethod] - public async Task Rename_MoveFileToRootFolder() - { - var itemInChildFolderPath = "/child_folder/test_01.jpg"; - await _query.AddItemAsync(new FileIndexItem(itemInChildFolderPath)); - await _query.AddParentItemsAsync(itemInChildFolderPath); - var iStorage = new FakeIStorage(new List { "/", "/child_folder" }, - new List { "/child_folder/test_01.jpg" }); + Assert.AreEqual("/child_folder2/test_10.jpg", + _query.SingleItem("/child_folder2/test_10.jpg")?.FileIndexItem?.FilePath); + Assert.AreEqual("/child_folder2/test_10.png", + _query.SingleItem("/child_folder2/test_10.png")?.FileIndexItem?.FilePath); - var renameFs = - await new RenameService(_query, iStorage).Rename(itemInChildFolderPath, "/"); + Assert.AreEqual(null, _query.SingleItem(itemInChildFolderPath)); + Assert.AreEqual(null, _query.SingleItem("/child_folder/test_10.png")); + } - // where its from - Assert.AreEqual("/child_folder", renameFs.FirstOrDefault()?.ParentDirectory); - Assert.AreEqual("/child_folder/test_01.jpg", renameFs.FirstOrDefault()?.FilePath); + [TestMethod] + public async Task Rename_Move_FileToDeleted_Collections() + { + var fromItemJpg = "/child_folder/test_21.jpg"; + var fromItemDng = "/child_folder/test_21.dng"; + var toItemJpg = "/child_folder/test_21_edit.jpg"; + var toItemDng = "/child_folder/test_21_edit.dng"; + + await _query.AddItemAsync(new FileIndexItem(fromItemJpg)); + await _query.AddItemAsync(new FileIndexItem(fromItemDng)); + await _query.AddParentItemsAsync(fromItemDng); + + var iStorage = new FakeIStorage( + new List { "/", "/child_folder", "/child_folder2" }, + new List { fromItemJpg, fromItemDng }); + + // only say: fromItemJpg > toItemJpg + var renameFs1 = await new RenameService(_query, iStorage) + .Rename(fromItemJpg, toItemJpg); + var renameFs = renameFs1 + .Where(p => p.Status != FileIndexItem.ExifStatus.NotFoundSourceMissing).ToList(); + + // it has moved the files + Assert.IsFalse(iStorage.ExistFile(fromItemJpg)); + Assert.IsFalse(iStorage.ExistFile(fromItemDng)); + + Assert.IsTrue(iStorage.ExistFile(toItemJpg)); + Assert.IsTrue(iStorage.ExistFile(toItemDng)); + + var toItemJpgItem = renameFs + .Find(p => p.FilePath == toItemJpg); + var toItemDngItem = renameFs + .Find(p => p.FilePath == toItemDng); + + Assert.AreEqual(toItemJpg, toItemJpgItem?.FilePath); + Assert.AreEqual(toItemDng, toItemDngItem?.FilePath); + + Assert.AreEqual(FileIndexItem.ExifStatus.Ok, toItemJpgItem?.Status); + Assert.AreEqual(FileIndexItem.ExifStatus.Ok, toItemDngItem?.Status); + + // // and the database is ok + Assert.AreEqual(toItemJpg, + _query.SingleItem(toItemJpg)?.FileIndexItem?.FilePath); + Assert.AreEqual(toItemDng, + _query.SingleItem(toItemDng)?.FileIndexItem?.FilePath); + } - Assert.AreEqual("/", renameFs[1].ParentDirectory); - Assert.AreEqual("/test_01.jpg", renameFs[1].FilePath); + [TestMethod] + public async Task + InputOutputSubPathsPreflight_FileToDeleted_SingleItem_WithCollectionsEnabled() + { + var itemInChildFolderPath1 = "/child_folder/test_22.jpg"; + var collectionItemPath1 = "/child_folder/test_22.dng"; - Assert.AreEqual("/test_01.jpg", - _query.SingleItem("/test_01.jpg")?.FileIndexItem?.FilePath); - Assert.AreEqual(null, _query.SingleItem(itemInChildFolderPath)); - } + await _query.AddItemAsync(new FileIndexItem(itemInChildFolderPath1)); + await _query.AddItemAsync(new FileIndexItem(collectionItemPath1)); - [TestMethod] - public async Task Rename_Move_FileToFolder_Collections() - { - var itemInChildFolderPath = "/child_folder/test_10.jpg"; - await _query.AddItemAsync(new FileIndexItem(itemInChildFolderPath)); - await _query.AddItemAsync(new FileIndexItem("/child_folder/test_10.png")); - await _query.AddParentItemsAsync(itemInChildFolderPath); + await _query.AddParentItemsAsync(itemInChildFolderPath1); + var iStorage = new FakeIStorage( + new List { "/", "/child_folder", "/child_folder2" }, + new List { itemInChildFolderPath1, collectionItemPath1 }); - var iStorage = new FakeIStorage( - new List { "/", "/child_folder", "/child_folder2" }, - new List { "/child_folder/test_10.jpg", "/child_folder/test_10.png" }); + var ((inputFileSubPaths, toFileSubPaths), fileIndexResultsList) = + new RenameService(_query, iStorage) + .InputOutputSubPathsPreflight($"{itemInChildFolderPath1}", + "/child_folder2/test_22_edit.jpg", true); - var renameFs = await new RenameService(_query, iStorage) - .Rename(itemInChildFolderPath, "/child_folder2"); + Assert.AreEqual(itemInChildFolderPath1, inputFileSubPaths[0]); + Assert.AreEqual(collectionItemPath1, inputFileSubPaths[1]); - // the first one is the deleted item - Assert.AreEqual("/child_folder2", renameFs[1].ParentDirectory); - Assert.AreEqual("/child_folder2/test_10.jpg", renameFs[1].FilePath); + Assert.AreEqual("/child_folder2/test_22_edit.jpg", toFileSubPaths[0]); + Assert.AreEqual("/child_folder2/test_22_edit.dng", toFileSubPaths[1]); - Assert.AreEqual("/child_folder2/test_10.jpg", - _query.SingleItem("/child_folder2/test_10.jpg")?.FileIndexItem?.FilePath); - Assert.AreEqual("/child_folder2/test_10.png", - _query.SingleItem("/child_folder2/test_10.png")?.FileIndexItem?.FilePath); + Assert.AreEqual(0, fileIndexResultsList.Count); - Assert.AreEqual(null, _query.SingleItem(itemInChildFolderPath)); - Assert.AreEqual(null, _query.SingleItem("/child_folder/test_10.png")); - } + // this does only preflight - [TestMethod] - public async Task Rename_Move_FileToDeleted_Collections() - { - var fromItemJpg = "/child_folder/test_21.jpg"; - var fromItemDng = "/child_folder/test_21.dng"; - var toItemJpg = "/child_folder/test_21_edit.jpg"; - var toItemDng = "/child_folder/test_21_edit.dng"; - - await _query.AddItemAsync(new FileIndexItem(fromItemJpg)); - await _query.AddItemAsync(new FileIndexItem(fromItemDng)); - await _query.AddParentItemsAsync(fromItemDng); - - var iStorage = new FakeIStorage( - new List { "/", "/child_folder", "/child_folder2" }, - new List { fromItemJpg, fromItemDng }); - - // only say: fromItemJpg > toItemJpg - var renameFs1 = await new RenameService(_query, iStorage) - .Rename(fromItemJpg, toItemJpg); - var renameFs = renameFs1 - .Where(p => p.Status != FileIndexItem.ExifStatus.NotFoundSourceMissing).ToList(); - - // it has moved the files - Assert.IsFalse(iStorage.ExistFile(fromItemJpg)); - Assert.IsFalse(iStorage.ExistFile(fromItemDng)); - - Assert.IsTrue(iStorage.ExistFile(toItemJpg)); - Assert.IsTrue(iStorage.ExistFile(toItemDng)); - - var toItemJpgItem = renameFs - .Find(p => p.FilePath == toItemJpg); - var toItemDngItem = renameFs - .Find(p => p.FilePath == toItemDng); - - Assert.AreEqual(toItemJpg, toItemJpgItem?.FilePath); - Assert.AreEqual(toItemDng, toItemDngItem?.FilePath); - - Assert.AreEqual(FileIndexItem.ExifStatus.Ok, toItemJpgItem?.Status); - Assert.AreEqual(FileIndexItem.ExifStatus.Ok, toItemDngItem?.Status); - - // // and the database is ok - Assert.AreEqual(toItemJpg, - _query.SingleItem(toItemJpg)?.FileIndexItem?.FilePath); - Assert.AreEqual(toItemDng, - _query.SingleItem(toItemDng)?.FileIndexItem?.FilePath); - } + var item1 = _query.SingleItem(itemInChildFolderPath1) + ?.FileIndexItem; + Assert.IsNotNull(item1); + await _query.RemoveItemAsync(item1); - [TestMethod] - public async Task - InputOutputSubPathsPreflight_FileToDeleted_SingleItem_WithCollectionsEnabled() - { - var itemInChildFolderPath1 = "/child_folder/test_22.jpg"; - var collectionItemPath1 = "/child_folder/test_22.dng"; + var item2 = _query.SingleItem(collectionItemPath1)?.FileIndexItem; + Assert.IsNotNull(item2); + await _query.RemoveItemAsync(item2); + } - await _query.AddItemAsync(new FileIndexItem(itemInChildFolderPath1)); - await _query.AddItemAsync(new FileIndexItem(collectionItemPath1)); + [TestMethod] + public async Task + InputOutputSubPathsPreflight_FileToDeleted_SingleItem_Change_FileName_And_Extension_WithCollections() + { + var itemInChildFolderPath1 = "/child_folder/test_23.jpg"; + var collectionItemPath1 = "/child_folder/test_23.dng"; - await _query.AddParentItemsAsync(itemInChildFolderPath1); - var iStorage = new FakeIStorage( - new List { "/", "/child_folder", "/child_folder2" }, - new List { itemInChildFolderPath1, collectionItemPath1 }); + await _query.AddItemAsync(new FileIndexItem(itemInChildFolderPath1)); + await _query.AddItemAsync(new FileIndexItem(collectionItemPath1)); - var ((inputFileSubPaths, toFileSubPaths), fileIndexResultsList) = - new RenameService(_query, iStorage) - .InputOutputSubPathsPreflight($"{itemInChildFolderPath1}", - "/child_folder2/test_22_edit.jpg", true); + await _query.AddParentItemsAsync(itemInChildFolderPath1); + var iStorage = new FakeIStorage( + new List { "/", "/child_folder", "/child_folder2" }, + new List { itemInChildFolderPath1, collectionItemPath1 }); - Assert.AreEqual(itemInChildFolderPath1, inputFileSubPaths[0]); - Assert.AreEqual(collectionItemPath1, inputFileSubPaths[1]); + var ((inputFileSubPaths, toFileSubPaths), fileIndexResultsList) = + new RenameService(_query, iStorage) + .InputOutputSubPathsPreflight($"{itemInChildFolderPath1}", + // Change to .jpeg + "/child_folder2/test_23_edit.jpeg", true); - Assert.AreEqual("/child_folder2/test_22_edit.jpg", toFileSubPaths[0]); - Assert.AreEqual("/child_folder2/test_22_edit.dng", toFileSubPaths[1]); + Assert.AreEqual(itemInChildFolderPath1, inputFileSubPaths[0]); + Assert.AreEqual(collectionItemPath1, inputFileSubPaths[1]); - Assert.AreEqual(0, fileIndexResultsList.Count); + Assert.AreEqual("/child_folder2/test_23_edit.jpeg", toFileSubPaths[0]); + Assert.AreEqual("/child_folder2/test_23_edit.dng", toFileSubPaths[1]); - // this does only preflight + Assert.AreEqual(0, fileIndexResultsList.Count); - var item1 = _query.SingleItem(itemInChildFolderPath1) - ?.FileIndexItem; - Assert.IsNotNull(item1); - await _query.RemoveItemAsync(item1); + // this does only preflight + var item1 = _query.SingleItem(itemInChildFolderPath1) + ?.FileIndexItem; + Assert.IsNotNull(item1); + await _query.RemoveItemAsync(item1); - var item2 = _query.SingleItem(collectionItemPath1)?.FileIndexItem; - Assert.IsNotNull(item2); - await _query.RemoveItemAsync(item2); - } + var item2 = _query.SingleItem(collectionItemPath1)?.FileIndexItem; + Assert.IsNotNull(item2); + await _query.RemoveItemAsync(item2); + } - [TestMethod] - public async Task - InputOutputSubPathsPreflight_FileToDeleted_SingleItem_Change_FileName_And_Extension_WithCollections() - { - var itemInChildFolderPath1 = "/child_folder/test_23.jpg"; - var collectionItemPath1 = "/child_folder/test_23.dng"; + [TestMethod] + public async Task + InputOutputSubPathsPreflight_FileToDeleted_SingleItem_Change_Extension_WithCollections() + { + var itemInChildFolderPath1 = "/child_folder/test_24.jpg"; + var collectionItemPath1 = "/child_folder/test_24.dng"; - await _query.AddItemAsync(new FileIndexItem(itemInChildFolderPath1)); - await _query.AddItemAsync(new FileIndexItem(collectionItemPath1)); + await _query.AddItemAsync(new FileIndexItem(itemInChildFolderPath1)); + await _query.AddItemAsync(new FileIndexItem(collectionItemPath1)); - await _query.AddParentItemsAsync(itemInChildFolderPath1); - var iStorage = new FakeIStorage( - new List { "/", "/child_folder", "/child_folder2" }, - new List { itemInChildFolderPath1, collectionItemPath1 }); + await _query.AddParentItemsAsync(itemInChildFolderPath1).ConfigureAwait(false); + var iStorage = new FakeIStorage( + new List { "/", "/child_folder", "/child_folder2" }, + new List { itemInChildFolderPath1, collectionItemPath1 }); - var ((inputFileSubPaths, toFileSubPaths), fileIndexResultsList) = - new RenameService(_query, iStorage) - .InputOutputSubPathsPreflight($"{itemInChildFolderPath1}", - // Change to .jpeg - "/child_folder2/test_23_edit.jpeg", true); + var ((inputFileSubPaths, toFileSubPaths), fileIndexResultsList) = + new RenameService(_query, iStorage) + .InputOutputSubPathsPreflight($"{itemInChildFolderPath1}", + // Change to .jpeg + "/child_folder2/test_24.jpeg", true); - Assert.AreEqual(itemInChildFolderPath1, inputFileSubPaths[0]); - Assert.AreEqual(collectionItemPath1, inputFileSubPaths[1]); + Assert.AreEqual(itemInChildFolderPath1, inputFileSubPaths[0]); + Assert.AreEqual(collectionItemPath1, inputFileSubPaths[1]); - Assert.AreEqual("/child_folder2/test_23_edit.jpeg", toFileSubPaths[0]); - Assert.AreEqual("/child_folder2/test_23_edit.dng", toFileSubPaths[1]); + Assert.AreEqual("/child_folder2/test_24.jpeg", toFileSubPaths[0]); + Assert.AreEqual("/child_folder2/test_24.dng", toFileSubPaths[1]); - Assert.AreEqual(0, fileIndexResultsList.Count); + Assert.AreEqual(0, fileIndexResultsList.Count); - // this does only preflight - var item1 = _query.SingleItem(itemInChildFolderPath1) - ?.FileIndexItem; - Assert.IsNotNull(item1); - await _query.RemoveItemAsync(item1); + // this does only preflight + var item1 = _query.SingleItem(itemInChildFolderPath1) + ?.FileIndexItem; + Assert.IsNotNull(item1); + await _query.RemoveItemAsync(item1); - var item2 = _query.SingleItem(collectionItemPath1)?.FileIndexItem; - Assert.IsNotNull(item2); - await _query.RemoveItemAsync(item2); - } + var item2 = _query.SingleItem(collectionItemPath1)?.FileIndexItem; + Assert.IsNotNull(item2); + await _query.RemoveItemAsync(item2); + } - [TestMethod] - public async Task - InputOutputSubPathsPreflight_FileToDeleted_SingleItem_Change_Extension_WithCollections() - { - var itemInChildFolderPath1 = "/child_folder/test_24.jpg"; - var collectionItemPath1 = "/child_folder/test_24.dng"; + [TestMethod] + public async Task Rename_Move_SidecarFile_ShouldMove_FileToFolder() + { + const string item1dng = "/child_folder/test_20.dng"; + const string item1SideCar = "/child_folder/test_20.xmp"; - await _query.AddItemAsync(new FileIndexItem(itemInChildFolderPath1)); - await _query.AddItemAsync(new FileIndexItem(collectionItemPath1)); + await _query.AddItemAsync(new FileIndexItem(item1dng)); + await _query.AddParentItemsAsync(item1dng); - await _query.AddParentItemsAsync(itemInChildFolderPath1).ConfigureAwait(false); - var iStorage = new FakeIStorage( - new List { "/", "/child_folder", "/child_folder2" }, - new List { itemInChildFolderPath1, collectionItemPath1 }); + var iStorage = new FakeIStorage( + new List { "/", "/child_folder", "/child_folder2" }, + new List { item1dng, item1SideCar }); // item1 - var ((inputFileSubPaths, toFileSubPaths), fileIndexResultsList) = - new RenameService(_query, iStorage) - .InputOutputSubPathsPreflight($"{itemInChildFolderPath1}", - // Change to .jpeg - "/child_folder2/test_24.jpeg", true); + // Move DNG to different folder + var renameFs = await new RenameService(_query, iStorage) + .Rename(item1dng, "/child_folder2"); - Assert.AreEqual(itemInChildFolderPath1, inputFileSubPaths[0]); - Assert.AreEqual(collectionItemPath1, inputFileSubPaths[1]); + Assert.AreEqual(item1dng, renameFs[0].FilePath); + Assert.AreEqual(item1dng.Replace("child_folder", "child_folder2"), + renameFs[1].FilePath); - Assert.AreEqual("/child_folder2/test_24.jpeg", toFileSubPaths[0]); - Assert.AreEqual("/child_folder2/test_24.dng", toFileSubPaths[1]); + // did move the side car file + Assert.IsTrue( + iStorage.ExistFile(item1SideCar.Replace("child_folder", "child_folder2"))); + } - Assert.AreEqual(0, fileIndexResultsList.Count); + [TestMethod] + public async Task Rename_Move_SidecarFile_ShouldNotMove_FileToFolder_ItsAJpeg() + { + var item1 = "/child_folder/test_20.jpg"; + var item1SideCar = "/child_folder/test_20.xmp"; - // this does only preflight - var item1 = _query.SingleItem(itemInChildFolderPath1) - ?.FileIndexItem; - Assert.IsNotNull(item1); - await _query.RemoveItemAsync(item1); + await _query.AddItemAsync(new FileIndexItem(item1)); + await _query.AddParentItemsAsync(item1); - var item2 = _query.SingleItem(collectionItemPath1)?.FileIndexItem; - Assert.IsNotNull(item2); - await _query.RemoveItemAsync(item2); - } + var iStorage = new FakeIStorage( + new List { "/", "/child_folder", "/child_folder2" }, + new List { item1, item1SideCar }); - [TestMethod] - public async Task Rename_Move_SidecarFile_ShouldMove_FileToFolder() - { - const string item1dng = "/child_folder/test_20.dng"; - const string item1SideCar = "/child_folder/test_20.xmp"; + // Move Jpg to different folder but the xmp should be ignored + var renameFs = await new RenameService(_query, iStorage) + .Rename(item1, "/child_folder2"); + + Assert.AreEqual(item1, renameFs.FirstOrDefault()?.FilePath); + Assert.AreEqual(item1.Replace("child_folder", "child_folder2"), + renameFs[1].FilePath); + + // it should not move the sidecar file + Assert.IsFalse( + iStorage.ExistFile(item1SideCar.Replace("child_folder", "child_folder2"))); + } - await _query.AddItemAsync(new FileIndexItem(item1dng)); - await _query.AddParentItemsAsync(item1dng); + [TestMethod] + public async Task + InputOutputSubPathsPreflight_FileToFolder_SingleItemWithCollectionsEnabled() + { + var itemInChildFolderPath1 = "/child_folder/test_07.jpg"; + var collectionItemPath1 = "/child_folder/test_07.png"; - var iStorage = new FakeIStorage( - new List { "/", "/child_folder", "/child_folder2" }, - new List { item1dng, item1SideCar }); // item1 + await _query.AddItemAsync(new FileIndexItem(itemInChildFolderPath1)); + await _query.AddItemAsync(new FileIndexItem(collectionItemPath1)); - // Move DNG to different folder - var renameFs = await new RenameService(_query, iStorage) - .Rename(item1dng, "/child_folder2"); + await _query.AddParentItemsAsync(itemInChildFolderPath1).ConfigureAwait(false); + var iStorage = new FakeIStorage( + new List { "/", "/child_folder", "/child_folder2" }, + new List { itemInChildFolderPath1, collectionItemPath1 }); - Assert.AreEqual(item1dng, renameFs[0].FilePath); - Assert.AreEqual(item1dng.Replace("child_folder", "child_folder2"), - renameFs[1].FilePath); + var ((inputFileSubPaths, toFileSubPaths), fileIndexResultsList) = + new RenameService(_query, iStorage) + .InputOutputSubPathsPreflight($"{itemInChildFolderPath1}", + "/child_folder2", true); - // did move the side car file - Assert.IsTrue( - iStorage.ExistFile(item1SideCar.Replace("child_folder", "child_folder2"))); - } + Assert.AreEqual(itemInChildFolderPath1, inputFileSubPaths[0]); + Assert.AreEqual(collectionItemPath1, inputFileSubPaths[1]); - [TestMethod] - public async Task Rename_Move_SidecarFile_ShouldNotMove_FileToFolder_ItsAJpeg() - { - var item1 = "/child_folder/test_20.jpg"; - var item1SideCar = "/child_folder/test_20.xmp"; + Assert.AreEqual("/child_folder2", toFileSubPaths[0]); + Assert.AreEqual("/child_folder2", toFileSubPaths[1]); - await _query.AddItemAsync(new FileIndexItem(item1)); - await _query.AddParentItemsAsync(item1); + Assert.AreEqual(0, fileIndexResultsList.Count); - var iStorage = new FakeIStorage( - new List { "/", "/child_folder", "/child_folder2" }, - new List { item1, item1SideCar }); + // CLEAN + var item1 = _query.SingleItem(itemInChildFolderPath1) + ?.FileIndexItem; + Assert.IsNotNull(item1); + await _query.RemoveItemAsync(item1); - // Move Jpg to different folder but the xmp should be ignored - var renameFs = await new RenameService(_query, iStorage) - .Rename(item1, "/child_folder2"); + var item2 = _query.SingleItem(collectionItemPath1)?.FileIndexItem; + Assert.IsNotNull(item2); + await _query.RemoveItemAsync(item2); + } - Assert.AreEqual(item1, renameFs.FirstOrDefault()?.FilePath); - Assert.AreEqual(item1.Replace("child_folder", "child_folder2"), - renameFs[1].FilePath); + [TestMethod] + public async Task InputOutputSubPathsPreflight_FileToFolder_MultipleFiles_CollectionsTrue() + { + // write test that has input /test.jpg;/test2.jpg > /test;/test2 and both has 2 or 3 collection files + // the other should be ok - // it should not move the sidecar file - Assert.IsFalse( - iStorage.ExistFile(item1SideCar.Replace("child_folder", "child_folder2"))); - } + var itemInChildFolderPath1 = "/child_folder/test_01.jpg"; + var collectionItemPath1 = "/child_folder/test_01.png"; - [TestMethod] - public async Task - InputOutputSubPathsPreflight_FileToFolder_SingleItemWithCollectionsEnabled() - { - var itemInChildFolderPath1 = "/child_folder/test_07.jpg"; - var collectionItemPath1 = "/child_folder/test_07.png"; + var itemInChildFolderPath2 = "/child_folder/test_02.jpg"; + var collectionItemPath2 = "/child_folder/test_02.png"; - await _query.AddItemAsync(new FileIndexItem(itemInChildFolderPath1)); - await _query.AddItemAsync(new FileIndexItem(collectionItemPath1)); + await _query.AddItemAsync(new FileIndexItem(itemInChildFolderPath1)); + await _query.AddItemAsync(new FileIndexItem(collectionItemPath1)); + await _query.AddItemAsync(new FileIndexItem(itemInChildFolderPath2)); + await _query.AddItemAsync(new FileIndexItem(collectionItemPath2)); - await _query.AddParentItemsAsync(itemInChildFolderPath1).ConfigureAwait(false); - var iStorage = new FakeIStorage( - new List { "/", "/child_folder", "/child_folder2" }, - new List { itemInChildFolderPath1, collectionItemPath1 }); + await _query.AddParentItemsAsync(itemInChildFolderPath1).ConfigureAwait(false); + var iStorage = new FakeIStorage( + new List { "/", "/child_folder", "/child_folder2", "/other" }, + new List + { + itemInChildFolderPath1, + collectionItemPath1, + itemInChildFolderPath2, + collectionItemPath2 + }); - var ((inputFileSubPaths, toFileSubPaths), fileIndexResultsList) = - new RenameService(_query, iStorage) - .InputOutputSubPathsPreflight($"{itemInChildFolderPath1}", - "/child_folder2", true); + var ((inputFileSubPaths, toFileSubPaths), fileIndexResultsList) = + new RenameService(_query, iStorage) + .InputOutputSubPathsPreflight( + $"{itemInChildFolderPath1};{itemInChildFolderPath2}", + "/child_folder2;/other", true); + + Assert.AreEqual(itemInChildFolderPath1, inputFileSubPaths[0]); + Assert.AreEqual(collectionItemPath1, inputFileSubPaths[1]); + Assert.AreEqual(itemInChildFolderPath2, inputFileSubPaths[2]); + Assert.AreEqual(collectionItemPath2, inputFileSubPaths[3]); + + Assert.AreEqual("/child_folder2", toFileSubPaths[0]); + Assert.AreEqual("/child_folder2", toFileSubPaths[1]); + Assert.AreEqual("/other", toFileSubPaths[2]); + Assert.AreEqual("/other", toFileSubPaths[3]); + + Assert.AreEqual(0, fileIndexResultsList.Count); + + // CLEAN + var item1 = _query.SingleItem(itemInChildFolderPath1) + ?.FileIndexItem; + Assert.IsNotNull(item1); + await _query.RemoveItemAsync(item1); + + var item2 = _query.SingleItem(collectionItemPath1)?.FileIndexItem; + Assert.IsNotNull(item2); + await _query.RemoveItemAsync(item2); + + // CLEAN + var item3 = _query.SingleItem(itemInChildFolderPath2) + ?.FileIndexItem; + Assert.IsNotNull(item3); + await _query.RemoveItemAsync(item3); + + var item4 = _query.SingleItem(collectionItemPath2)?.FileIndexItem; + Assert.IsNotNull(item4); + await _query.RemoveItemAsync(item4); + } - Assert.AreEqual(itemInChildFolderPath1, inputFileSubPaths[0]); - Assert.AreEqual(collectionItemPath1, inputFileSubPaths[1]); + [TestMethod] + public async Task + InputOutputSubPathsPreflight_FileToFolder_MultipleFiles_CollectionsFalse_Aka_Disabled() + { + // write test that has input /test.jpg;/test2.jpg > /test;/test2 and both has 2 or 3 collection files + // But this one's are not used + // the other should be ok - Assert.AreEqual("/child_folder2", toFileSubPaths[0]); - Assert.AreEqual("/child_folder2", toFileSubPaths[1]); + var itemInChildFolderPath1 = "/child_folder/test_05.jpg"; + var collectionItemPath1 = "/child_folder/test_05.png"; - Assert.AreEqual(0, fileIndexResultsList.Count); + var itemInChildFolderPath2 = "/child_folder/test_06.jpg"; + var collectionItemPath2 = "/child_folder/test_06.png"; - // CLEAN - var item1 = _query.SingleItem(itemInChildFolderPath1) - ?.FileIndexItem; - Assert.IsNotNull(item1); - await _query.RemoveItemAsync(item1); + await _query.AddItemAsync(new FileIndexItem(itemInChildFolderPath1)); + await _query.AddItemAsync(new FileIndexItem(collectionItemPath1)); + await _query.AddItemAsync(new FileIndexItem(itemInChildFolderPath2)); + await _query.AddItemAsync(new FileIndexItem(collectionItemPath2)); - var item2 = _query.SingleItem(collectionItemPath1)?.FileIndexItem; - Assert.IsNotNull(item2); - await _query.RemoveItemAsync(item2); - } + await _query.AddParentItemsAsync(itemInChildFolderPath1); + var iStorage = new FakeIStorage( + new List { "/", "/child_folder", "/child_folder2", "/other" }, + new List + { + itemInChildFolderPath1, + collectionItemPath1, + itemInChildFolderPath2, + collectionItemPath2 + }); - [TestMethod] - public async Task InputOutputSubPathsPreflight_FileToFolder_MultipleFiles_CollectionsTrue() - { - // write test that has input /test.jpg;/test2.jpg > /test;/test2 and both has 2 or 3 collection files - // the other should be ok - - var itemInChildFolderPath1 = "/child_folder/test_01.jpg"; - var collectionItemPath1 = "/child_folder/test_01.png"; - - var itemInChildFolderPath2 = "/child_folder/test_02.jpg"; - var collectionItemPath2 = "/child_folder/test_02.png"; - - await _query.AddItemAsync(new FileIndexItem(itemInChildFolderPath1)); - await _query.AddItemAsync(new FileIndexItem(collectionItemPath1)); - await _query.AddItemAsync(new FileIndexItem(itemInChildFolderPath2)); - await _query.AddItemAsync(new FileIndexItem(collectionItemPath2)); - - await _query.AddParentItemsAsync(itemInChildFolderPath1).ConfigureAwait(false); - var iStorage = new FakeIStorage( - new List { "/", "/child_folder", "/child_folder2", "/other" }, - new List - { - itemInChildFolderPath1, - collectionItemPath1, - itemInChildFolderPath2, - collectionItemPath2 - }); - - var ((inputFileSubPaths, toFileSubPaths), fileIndexResultsList) = - new RenameService(_query, iStorage) - .InputOutputSubPathsPreflight( - $"{itemInChildFolderPath1};{itemInChildFolderPath2}", - "/child_folder2;/other", true); - - Assert.AreEqual(itemInChildFolderPath1, inputFileSubPaths[0]); - Assert.AreEqual(collectionItemPath1, inputFileSubPaths[1]); - Assert.AreEqual(itemInChildFolderPath2, inputFileSubPaths[2]); - Assert.AreEqual(collectionItemPath2, inputFileSubPaths[3]); - - Assert.AreEqual("/child_folder2", toFileSubPaths[0]); - Assert.AreEqual("/child_folder2", toFileSubPaths[1]); - Assert.AreEqual("/other", toFileSubPaths[2]); - Assert.AreEqual("/other", toFileSubPaths[3]); - - Assert.AreEqual(0, fileIndexResultsList.Count); - - // CLEAN - var item1 = _query.SingleItem(itemInChildFolderPath1) - ?.FileIndexItem; - Assert.IsNotNull(item1); - await _query.RemoveItemAsync(item1); - - var item2 = _query.SingleItem(collectionItemPath1)?.FileIndexItem; - Assert.IsNotNull(item2); - await _query.RemoveItemAsync(item2); - - // CLEAN - var item3 = _query.SingleItem(itemInChildFolderPath2) - ?.FileIndexItem; - Assert.IsNotNull(item3); - await _query.RemoveItemAsync(item3); - - var item4 = _query.SingleItem(collectionItemPath2)?.FileIndexItem; - Assert.IsNotNull(item4); - await _query.RemoveItemAsync(item4); - } + // Collections disabled! + var ((inputFileSubPaths, toFileSubPaths), fileIndexResultsList) = + new RenameService(_query, iStorage) + .InputOutputSubPathsPreflight( + $"{itemInChildFolderPath1};{itemInChildFolderPath2}", + "/child_folder2;/other", false); - [TestMethod] - public async Task - InputOutputSubPathsPreflight_FileToFolder_MultipleFiles_CollectionsFalse_Aka_Disabled() - { - // write test that has input /test.jpg;/test2.jpg > /test;/test2 and both has 2 or 3 collection files - // But this one's are not used - // the other should be ok - - var itemInChildFolderPath1 = "/child_folder/test_05.jpg"; - var collectionItemPath1 = "/child_folder/test_05.png"; - - var itemInChildFolderPath2 = "/child_folder/test_06.jpg"; - var collectionItemPath2 = "/child_folder/test_06.png"; - - await _query.AddItemAsync(new FileIndexItem(itemInChildFolderPath1)); - await _query.AddItemAsync(new FileIndexItem(collectionItemPath1)); - await _query.AddItemAsync(new FileIndexItem(itemInChildFolderPath2)); - await _query.AddItemAsync(new FileIndexItem(collectionItemPath2)); - - await _query.AddParentItemsAsync(itemInChildFolderPath1); - var iStorage = new FakeIStorage( - new List { "/", "/child_folder", "/child_folder2", "/other" }, - new List - { - itemInChildFolderPath1, - collectionItemPath1, - itemInChildFolderPath2, - collectionItemPath2 - }); - - // Collections disabled! - var ((inputFileSubPaths, toFileSubPaths), fileIndexResultsList) = - new RenameService(_query, iStorage) - .InputOutputSubPathsPreflight( - $"{itemInChildFolderPath1};{itemInChildFolderPath2}", - "/child_folder2;/other", false); - - Assert.AreEqual(itemInChildFolderPath1, inputFileSubPaths[0]); - Assert.AreEqual(itemInChildFolderPath2, inputFileSubPaths[1]); - - Assert.AreEqual("/child_folder2", toFileSubPaths[0]); - Assert.AreEqual("/other", toFileSubPaths[1]); - - Assert.AreEqual(0, fileIndexResultsList.Count); - - // CLEAN - var item1 = _query.SingleItem(itemInChildFolderPath1) - ?.FileIndexItem; - Assert.IsNotNull(item1); - await _query.RemoveItemAsync(item1); - - var item2 = _query.SingleItem(collectionItemPath1)?.FileIndexItem; - Assert.IsNotNull(item2); - await _query.RemoveItemAsync(item2); - - // CLEAN - var item3 = _query.SingleItem(itemInChildFolderPath2) - ?.FileIndexItem; - Assert.IsNotNull(item3); - await _query.RemoveItemAsync(item3); - - var item4 = _query.SingleItem(collectionItemPath2)?.FileIndexItem; - Assert.IsNotNull(item4); - await _query.RemoveItemAsync(item4); - } + Assert.AreEqual(itemInChildFolderPath1, inputFileSubPaths[0]); + Assert.AreEqual(itemInChildFolderPath2, inputFileSubPaths[1]); - [TestMethod] - public async Task InputOutputSubPathsPreflight_FileToFolder_MultipleFiles_PartlyNotFound() - { - var itemInChildFolderPath1 = "/child_folder/test_03.jpg"; - var collectionItemPath1 = "/child_folder/test_03.png"; + Assert.AreEqual("/child_folder2", toFileSubPaths[0]); + Assert.AreEqual("/other", toFileSubPaths[1]); - var itemInChildFolderPath2 = "/child_folder/test_04.jpg"; + Assert.AreEqual(0, fileIndexResultsList.Count); - await _query.AddItemAsync(new FileIndexItem(itemInChildFolderPath1)); - await _query.AddItemAsync(new FileIndexItem(collectionItemPath1)); + // CLEAN + var item1 = _query.SingleItem(itemInChildFolderPath1) + ?.FileIndexItem; + Assert.IsNotNull(item1); + await _query.RemoveItemAsync(item1); - await _query.AddParentItemsAsync(itemInChildFolderPath1); + var item2 = _query.SingleItem(collectionItemPath1)?.FileIndexItem; + Assert.IsNotNull(item2); + await _query.RemoveItemAsync(item2); - var iStorage = new FakeIStorage( - new List { "/", "/child_folder", "/child_folder2", "/other" }, - new List { itemInChildFolderPath1, collectionItemPath1 }); + // CLEAN + var item3 = _query.SingleItem(itemInChildFolderPath2) + ?.FileIndexItem; + Assert.IsNotNull(item3); + await _query.RemoveItemAsync(item3); - // nr 2 is does not exist in the database - var ((inputFileSubPaths, toFileSubPaths), fileIndexResultsList) = - new RenameService(_query, iStorage) - .InputOutputSubPathsPreflight( - $"{itemInChildFolderPath1};{itemInChildFolderPath2}", - "/child_folder2;/other", true); + var item4 = _query.SingleItem(collectionItemPath2)?.FileIndexItem; + Assert.IsNotNull(item4); + await _query.RemoveItemAsync(item4); + } - Assert.AreEqual(itemInChildFolderPath1, inputFileSubPaths[0]); - Assert.AreEqual(collectionItemPath1, inputFileSubPaths[1]); + [TestMethod] + public async Task InputOutputSubPathsPreflight_FileToFolder_MultipleFiles_PartlyNotFound() + { + var itemInChildFolderPath1 = "/child_folder/test_03.jpg"; + var collectionItemPath1 = "/child_folder/test_03.png"; - Assert.AreEqual("/child_folder2", toFileSubPaths[0]); - Assert.AreEqual("/child_folder2", toFileSubPaths[1]); + var itemInChildFolderPath2 = "/child_folder/test_04.jpg"; - Assert.AreEqual(1, fileIndexResultsList.Count); - Assert.AreEqual(FileIndexItem.ExifStatus.NotFoundNotInIndex, - fileIndexResultsList[0].Status); + await _query.AddItemAsync(new FileIndexItem(itemInChildFolderPath1)); + await _query.AddItemAsync(new FileIndexItem(collectionItemPath1)); - await _query.RemoveItemAsync(_query.SingleItem(itemInChildFolderPath1)?.FileIndexItem!); - await _query.RemoveItemAsync(_query.SingleItem(collectionItemPath1)?.FileIndexItem!); - } + await _query.AddParentItemsAsync(itemInChildFolderPath1); - [TestMethod] - public async Task Rename_FolderToExistingFolderInDatabaseButNotOnDisk() - { - var iStorage = new FakeIStorage(new List { "/", "/source_folder" }); + var iStorage = new FakeIStorage( + new List { "/", "/child_folder", "/child_folder2", "/other" }, + new List { itemInChildFolderPath1, collectionItemPath1 }); - await _query.AddItemAsync( - new FileIndexItem("/source_folder") { IsDirectory = true }); - await _query.AddItemAsync( - new FileIndexItem("/target_folder_3") { IsDirectory = true }); + // nr 2 is does not exist in the database + var ((inputFileSubPaths, toFileSubPaths), fileIndexResultsList) = + new RenameService(_query, iStorage) + .InputOutputSubPathsPreflight( + $"{itemInChildFolderPath1};{itemInChildFolderPath2}", + "/child_folder2;/other", true); - // Move Jpg to different folder but the xmp should be ignored - var renameFs = await new RenameService(_query, iStorage) - .Rename("/source_folder", "/target_folder_3"); + Assert.AreEqual(itemInChildFolderPath1, inputFileSubPaths[0]); + Assert.AreEqual(collectionItemPath1, inputFileSubPaths[1]); + Assert.AreEqual("/child_folder2", toFileSubPaths[0]); + Assert.AreEqual("/child_folder2", toFileSubPaths[1]); - var countTargetFolder = ( await _query.GetAllRecursiveAsync() ) - .Where(p => p.FilePath == "/target_folder_3").ToList(); + Assert.AreEqual(1, fileIndexResultsList.Count); + Assert.AreEqual(FileIndexItem.ExifStatus.NotFoundNotInIndex, + fileIndexResultsList[0].Status); - Assert.AreEqual(1, countTargetFolder.Count); + await _query.RemoveItemAsync(_query.SingleItem(itemInChildFolderPath1)?.FileIndexItem!); + await _query.RemoveItemAsync(_query.SingleItem(collectionItemPath1)?.FileIndexItem!); + } - Assert.AreEqual("/source_folder", renameFs[1].FilePath); - Assert.AreEqual("/target_folder_3", renameFs[0].FilePath); + [TestMethod] + public async Task Rename_FolderToExistingFolderInDatabaseButNotOnDisk() + { + var iStorage = new FakeIStorage(new List { "/", "/source_folder" }); - var sourceFolder = renameFs - .Find(p => p.FilePath == "/source_folder"); - var targetFolder = renameFs - .Find(p => p.FilePath == "/target_folder_3"); + await _query.AddItemAsync( + new FileIndexItem("/source_folder") { IsDirectory = true }); + await _query.AddItemAsync( + new FileIndexItem("/target_folder_3") { IsDirectory = true }); - Assert.AreEqual("/source_folder", sourceFolder?.FilePath); - Assert.AreEqual("/target_folder_3", targetFolder?.FilePath); + // Move Jpg to different folder but the xmp should be ignored + var renameFs = await new RenameService(_query, iStorage) + .Rename("/source_folder", "/target_folder_3"); - Assert.AreEqual(FileIndexItem.ExifStatus.NotFoundSourceMissing, sourceFolder?.Status); - Assert.AreEqual(FileIndexItem.ExifStatus.Ok, targetFolder?.Status); - } - [TestMethod] - public async Task Rename_FolderToExistingFolder_With_Child_Items_InDatabaseButNotOnDisk() - { - var iStorage = new FakeIStorage( - new List { "/", "/source_folder_2" }, - new List { "/source_folder_2/test.jpg" } - ); + var countTargetFolder = ( await _query.GetAllRecursiveAsync() ) + .Where(p => p.FilePath == "/target_folder_3").ToList(); - await _query.AddItemAsync( - new FileIndexItem("/source_folder_2") { IsDirectory = true }); - await _query.AddItemAsync( - new FileIndexItem("/source_folder_2/test.jpg")); - await _query.AddItemAsync( - new FileIndexItem("/target_folder_4") { IsDirectory = true }); - await _query.AddItemAsync( - new FileIndexItem("/target_folder_4/test.jpg")); + Assert.AreEqual(1, countTargetFolder.Count); + Assert.AreEqual("/source_folder", renameFs[1].FilePath); + Assert.AreEqual("/target_folder_3", renameFs[0].FilePath); - var renameFs = await new RenameService(_query, iStorage) - .Rename("/source_folder_2", "/target_folder_4"); + var sourceFolder = renameFs + .Find(p => p.FilePath == "/source_folder"); + var targetFolder = renameFs + .Find(p => p.FilePath == "/target_folder_3"); - var countTargetChildItem = ( await _query.GetAllRecursiveAsync() ) - .Where(p => p.FilePath == "/target_folder_4/test.jpg").ToList(); + Assert.AreEqual("/source_folder", sourceFolder?.FilePath); + Assert.AreEqual("/target_folder_3", targetFolder?.FilePath); - Assert.AreEqual(1, countTargetChildItem.Count); + Assert.AreEqual(FileIndexItem.ExifStatus.NotFoundSourceMissing, sourceFolder?.Status); + Assert.AreEqual(FileIndexItem.ExifStatus.Ok, targetFolder?.Status); + } - var countTargetFolder = ( await _query.GetAllRecursiveAsync() ) - .Where(p => p.FilePath == "/target_folder_4").ToList(); + [TestMethod] + public async Task Rename_FolderToExistingFolder_With_Child_Items_InDatabaseButNotOnDisk() + { + var iStorage = new FakeIStorage( + new List { "/", "/source_folder_2" }, + new List { "/source_folder_2/test.jpg" } + ); - Assert.AreEqual(1, countTargetFolder.Count); + await _query.AddItemAsync( + new FileIndexItem("/source_folder_2") { IsDirectory = true }); + await _query.AddItemAsync( + new FileIndexItem("/source_folder_2/test.jpg")); + await _query.AddItemAsync( + new FileIndexItem("/target_folder_4") { IsDirectory = true }); + await _query.AddItemAsync( + new FileIndexItem("/target_folder_4/test.jpg")); - var sourceFolder = renameFs - .Find(p => p.FilePath == "/source_folder_2"); - var targetFile = renameFs - .Find(p => p.FilePath == "/target_folder_4/test.jpg"); - var targetFolder = renameFs - .Find(p => p.FilePath == "/target_folder_4"); - Assert.AreEqual("/source_folder_2", sourceFolder?.FilePath); - Assert.AreEqual("/target_folder_4/test.jpg", targetFile?.FilePath); - Assert.AreEqual("/target_folder_4", targetFolder?.FilePath); + var renameFs = await new RenameService(_query, iStorage) + .Rename("/source_folder_2", "/target_folder_4"); - Assert.AreEqual(FileIndexItem.ExifStatus.NotFoundSourceMissing, sourceFolder?.Status); - Assert.AreEqual(FileIndexItem.ExifStatus.Ok, targetFile?.Status); - Assert.AreEqual(FileIndexItem.ExifStatus.Ok, targetFolder?.Status); - } + var countTargetChildItem = ( await _query.GetAllRecursiveAsync() ) + .Where(p => p.FilePath == "/target_folder_4/test.jpg").ToList(); - [TestMethod] - [ExpectedException(typeof(ArgumentNullException))] - public async Task FromFolderToFolder_Null_exception() - { - await new RenameService(null!, null!).FromFolderToFolder(null!, - null!, null!, null!); - // expect exception - } + Assert.AreEqual(1, countTargetChildItem.Count); - [TestMethod] - public async Task RenameFsTest_MergeToLowerPath() - { - // At the moment there is no check for case sensitive file or filenames + var countTargetFolder = ( await _query.GetAllRecursiveAsync() ) + .Where(p => p.FilePath == "/target_folder_4").ToList(); - const string beforePath = "/test/case_sensitive.jpg"; - const string afterPath = "/test/Case_Sensitive.jpg"; + Assert.AreEqual(1, countTargetFolder.Count); - var storage = new FakeIStorage(new List { "/exist", beforePath }); - var query = - new FakeIQuery( - new List { new FileIndexItem(beforePath) }); + var sourceFolder = renameFs + .Find(p => p.FilePath == "/source_folder_2"); + var targetFile = renameFs + .Find(p => p.FilePath == "/target_folder_4/test.jpg"); + var targetFolder = renameFs + .Find(p => p.FilePath == "/target_folder_4"); - var renameService = new RenameService(query, storage); + Assert.AreEqual("/source_folder_2", sourceFolder?.FilePath); + Assert.AreEqual("/target_folder_4/test.jpg", targetFile?.FilePath); + Assert.AreEqual("/target_folder_4", targetFolder?.FilePath); - await renameService.Rename(beforePath, afterPath); + Assert.AreEqual(FileIndexItem.ExifStatus.NotFoundSourceMissing, sourceFolder?.Status); + Assert.AreEqual(FileIndexItem.ExifStatus.Ok, targetFile?.Status); + Assert.AreEqual(FileIndexItem.ExifStatus.Ok, targetFolder?.Status); + } + + [TestMethod] + [ExpectedException(typeof(ArgumentNullException))] + public async Task FromFolderToFolder_Null_exception() + { + await new RenameService(null!, null!).FromFolderToFolder(null!, + null!, null!, null!); + // expect exception + } - var beforeItem = await query.GetObjectByFilePathAsync(beforePath); - Assert.IsNull(beforeItem); + [TestMethod] + public async Task RenameFsTest_MergeToLowerPath() + { + // At the moment there is no check for case sensitive file or filenames - var after = await query.GetObjectByFilePathAsync(afterPath); - Assert.AreEqual(afterPath, after!.FilePath); - } + const string beforePath = "/test/case_sensitive.jpg"; + const string afterPath = "/test/Case_Sensitive.jpg"; + + var storage = new FakeIStorage(new List { "/exist", beforePath }); + var query = + new FakeIQuery( + new List { new(beforePath) }); + + var renameService = new RenameService(query, storage); + + await renameService.Rename(beforePath, afterPath); + + var beforeItem = await query.GetObjectByFilePathAsync(beforePath); + Assert.IsNull(beforeItem); + + var after = await query.GetObjectByFilePathAsync(afterPath); + Assert.AreEqual(afterPath, after!.FilePath); } } diff --git a/starsky/starskytest/starsky.feature.settings/Services/UpdateAppSettingsByPathTest.cs b/starsky/starskytest/starsky.feature.settings/Services/UpdateAppSettingsByPathTest.cs index 7d1c50036c..7062c5bedb 100644 --- a/starsky/starskytest/starsky.feature.settings/Services/UpdateAppSettingsByPathTest.cs +++ b/starsky/starskytest/starsky.feature.settings/Services/UpdateAppSettingsByPathTest.cs @@ -12,231 +12,231 @@ using starsky.foundation.storage.Helpers; using starskytest.FakeMocks; -namespace starskytest.starsky.feature.settings.Services +namespace starskytest.starsky.feature.settings.Services; + +[TestClass] +public class UpdateAppSettingsByPathTests { - [TestClass] - public class UpdateAppSettingsByPathTests + [TestMethod] + public async Task UpdateAppSettingsAsync_ValidInput_Success() { - [TestMethod] - public async Task UpdateAppSettingsAsync_ValidInput_Success() - { - var before = Environment.GetEnvironmentVariable("app__storageFolder"); - Environment.SetEnvironmentVariable("app__storageFolder", string.Empty); - - // Arrange - var testFolderPath = Path.DirectorySeparatorChar.ToString() + "test" + - Path.DirectorySeparatorChar.ToString(); - - var storage = new FakeIStorage(new List { "/", testFolderPath }); - var selectorStorage = new FakeSelectorStorage(storage); - var updateAppSettingsByPath = - new UpdateAppSettingsByPath(new AppSettings(), selectorStorage); - var appSettingTransferObject = new AppSettingsTransferObject - { - StorageFolder = testFolderPath, Verbose = true - }; - - // Act - var result = - await updateAppSettingsByPath.UpdateAppSettingsAsync(appSettingTransferObject); - - Environment.SetEnvironmentVariable("app__storageFolder", before); - - // Assert - Assert.AreEqual(200, result.StatusCode); - Assert.AreEqual("Updated", result.Message); - } - - [TestMethod] - public async Task UpdateAppSettingsAsync_ValidInput_Success_CompareJson() + var before = Environment.GetEnvironmentVariable("app__storageFolder"); + Environment.SetEnvironmentVariable("app__storageFolder", string.Empty); + + // Arrange + var testFolderPath = Path.DirectorySeparatorChar + "test-update-appSettings-by-path" + + Path.DirectorySeparatorChar; + + var storage = new FakeIStorage(new List { "/", testFolderPath }); + var selectorStorage = new FakeSelectorStorage(storage); + var updateAppSettingsByPath = + new UpdateAppSettingsByPath(new AppSettings(), selectorStorage); + var appSettingTransferObject = new AppSettingsTransferObject { - // Arrange - - var before = Environment.GetEnvironmentVariable("app__storageFolder"); - Environment.SetEnvironmentVariable("app__storageFolder", string.Empty); - - var testFolderPath = Path.DirectorySeparatorChar + "test" + - Path.DirectorySeparatorChar; + StorageFolder = testFolderPath, Verbose = true + }; - var storage = new FakeIStorage(new List { "/", testFolderPath }); - var selectorStorage = new FakeSelectorStorage(storage); - var appSettings = new AppSettings(); - var updateAppSettingsByPath = new UpdateAppSettingsByPath(appSettings, selectorStorage); - var appSettingTransferObject = new AppSettingsTransferObject - { - StorageFolder = testFolderPath, Verbose = true, - }; - - // Act + // Act + var result = await updateAppSettingsByPath.UpdateAppSettingsAsync(appSettingTransferObject); - var result = - ( await StreamToStringHelper.StreamToStringAsync( - storage.ReadStream(appSettings.AppSettingsPath)) ).Replace("\r\n", "\n"); + Environment.SetEnvironmentVariable("app__storageFolder", before); - Environment.SetEnvironmentVariable("app__storageFolder", before); + // Assert + Assert.AreEqual(200, result.StatusCode); + Assert.AreEqual("Updated", result.Message); + } + [TestMethod] + public async Task UpdateAppSettingsAsync_ValidInput_Success_CompareJson() + { + // Arrange - var storageFolderJson = JsonSerializer.Serialize(testFolderPath, - DefaultJsonSerializer.NoNamingPolicyBoolAsString); + var before = Environment.GetEnvironmentVariable("app__storageFolder"); + Environment.SetEnvironmentVariable("app__storageFolder", string.Empty); + var testFolderPath = Path.DirectorySeparatorChar + "test-update-appSettings-by-path" + + Path.DirectorySeparatorChar; - // Assert - var expectedResult = - "{\n \"app\": {\n \"Verbose\": \"true\",\n \"StorageFolder\": " + // rm quotes - storageFolderJson + ",\n"; + var storage = new FakeIStorage(new List { "/", testFolderPath }); + var selectorStorage = new FakeSelectorStorage(storage); + var appSettings = new AppSettings(); + var updateAppSettingsByPath = new UpdateAppSettingsByPath(appSettings, selectorStorage); + var appSettingTransferObject = new AppSettingsTransferObject + { + StorageFolder = testFolderPath, Verbose = true + }; + // Act + await updateAppSettingsByPath.UpdateAppSettingsAsync(appSettingTransferObject); - Assert.IsTrue(result.Contains(expectedResult)); - } + var result = + ( await StreamToStringHelper.StreamToStringAsync( + storage.ReadStream(appSettings.AppSettingsPath)) ).Replace("\r\n", "\n"); + + Environment.SetEnvironmentVariable("app__storageFolder", before); - [TestMethod] - public async Task UpdateAppSettingsAsync_InvalidStorageFolder_Returns404() - { - var before = Environment.GetEnvironmentVariable("app__storageFolder"); - Environment.SetEnvironmentVariable("app__storageFolder", string.Empty); - // Arrange - var selectorStorage = new FakeSelectorStorage(); - var updateAppSettingsByPath = - new UpdateAppSettingsByPath(new AppSettings(), selectorStorage); - var appSettingTransferObject = new AppSettingsTransferObject - { - StorageFolder = "NonExistentFolder" - }; + var storageFolderJson = JsonSerializer.Serialize(testFolderPath, + DefaultJsonSerializer.NoNamingPolicyBoolAsString); - // Act - var result = - await updateAppSettingsByPath.UpdateAppSettingsAsync(appSettingTransferObject); - Environment.SetEnvironmentVariable("app__storageFolder", before); + // Assert + var expectedResult = + "{\n \"app\": {\n \"Verbose\": \"true\",\n \"StorageFolder\": " + // rm quotes + storageFolderJson + ",\n"; - // Assert - Assert.AreEqual(404, result.StatusCode); - Assert.AreEqual("Location of StorageFolder on disk not found", result.Message); - } + Assert.IsTrue(result.Contains(expectedResult)); + } - [TestMethod] - public async Task UpdateAppSettingsAsync_InvalidStorageFolder_Returns403() + [TestMethod] + public async Task UpdateAppSettingsAsync_InvalidStorageFolder_Returns404() + { + var before = Environment.GetEnvironmentVariable("app__storageFolder"); + Environment.SetEnvironmentVariable("app__storageFolder", string.Empty); + + // Arrange + var selectorStorage = new FakeSelectorStorage(); + var updateAppSettingsByPath = + new UpdateAppSettingsByPath(new AppSettings(), selectorStorage); + var appSettingTransferObject = new AppSettingsTransferObject { - var before = Environment.GetEnvironmentVariable("app__storageFolder"); - Environment.SetEnvironmentVariable("app__storageFolder", "test"); + StorageFolder = "NonExistentFolder" + }; + + // Act + var result = + await updateAppSettingsByPath.UpdateAppSettingsAsync(appSettingTransferObject); - // Arrange - var selectorStorage = - new FakeSelectorStorage(new FakeIStorage(new List { "/" })); - var updateAppSettingsByPath = - new UpdateAppSettingsByPath(new AppSettings(), selectorStorage); - var appSettingTransferObject = new AppSettingsTransferObject { StorageFolder = "/" }; + Environment.SetEnvironmentVariable("app__storageFolder", before); - // Act - var result = - await updateAppSettingsByPath.UpdateAppSettingsAsync(appSettingTransferObject); - // Set back to what is was before - Environment.SetEnvironmentVariable("app__storageFolder", before); + // Assert + Assert.AreEqual(404, result.StatusCode); + Assert.AreEqual("Location of StorageFolder on disk not found", result.Message); + } - // Assert - Assert.AreEqual(403, result.StatusCode); - Assert.AreEqual("There is an Environment variable set so you can't update it here", - result.Message); - } + [TestMethod] + public async Task UpdateAppSettingsAsync_InvalidStorageFolder_Returns403() + { + var before = Environment.GetEnvironmentVariable("app__storageFolder"); + Environment.SetEnvironmentVariable("app__storageFolder", "test-update-appSettings-by-path"); + + // Arrange + var selectorStorage = + new FakeSelectorStorage(new FakeIStorage(new List { "/" })); + var updateAppSettingsByPath = + new UpdateAppSettingsByPath(new AppSettings(), selectorStorage); + var appSettingTransferObject = new AppSettingsTransferObject { StorageFolder = "/" }; + + // Act + var result = + await updateAppSettingsByPath.UpdateAppSettingsAsync(appSettingTransferObject); + // Set back to what is was before + Environment.SetEnvironmentVariable("app__storageFolder", before); - [TestMethod] - public async Task UpdateAppSettingsAsync_ValidInput_TwoTimes_Success() - { - var before = Environment.GetEnvironmentVariable("app__storageFolder"); - Environment.SetEnvironmentVariable("app__storageFolder", string.Empty); + // Assert + Assert.AreEqual(403, result.StatusCode); + Assert.AreEqual("There is an Environment variable set so you can't update it here", + result.Message); + } - // Arrange - var testFolderPath = Path.DirectorySeparatorChar + "test" + Path.DirectorySeparatorChar; - var storage = new FakeIStorage(new List { "/", testFolderPath }); - var appSettings = new AppSettings(); - var selectorStorage = new FakeSelectorStorage(storage); - var updateAppSettingsByPath = new UpdateAppSettingsByPath(appSettings, selectorStorage); - var appSettingTransferObject1 = new AppSettingsTransferObject { Verbose = true }; + [TestMethod] + public async Task UpdateAppSettingsAsync_ValidInput_TwoTimes_Success() + { + var before = Environment.GetEnvironmentVariable("app__storageFolder"); + Environment.SetEnvironmentVariable("app__storageFolder", string.Empty); + + // Arrange + var testFolderPath = Path.DirectorySeparatorChar + "test-update-appSettings-by-path" + + Path.DirectorySeparatorChar; + + var storage = new FakeIStorage(new List { "/", testFolderPath }); + var appSettings = new AppSettings(); + var selectorStorage = new FakeSelectorStorage(storage); + var updateAppSettingsByPath = new UpdateAppSettingsByPath(appSettings, selectorStorage); + var appSettingTransferObject1 = new AppSettingsTransferObject { Verbose = true }; + + // Act + var re1 = + await updateAppSettingsByPath.UpdateAppSettingsAsync(appSettingTransferObject1); + Assert.IsFalse(re1.IsError); + + var fileResultString1 = + await StreamToStringHelper.StreamToStringAsync( + storage.ReadStream(appSettings.AppSettingsPath)); + var fileResult1 = JsonSerializer.Deserialize(fileResultString1, + DefaultJsonSerializer.NoNamingPolicyBoolAsString); + + Assert.IsNotNull(fileResult1); + Assert.IsTrue(fileResult1.App.Verbose); + + var appSettingTransferObject2 = new AppSettingsTransferObject + { + StorageFolder = testFolderPath + }; - // Act - var re1 = - await updateAppSettingsByPath.UpdateAppSettingsAsync(appSettingTransferObject1); - Assert.IsFalse(re1.IsError); + await updateAppSettingsByPath.UpdateAppSettingsAsync(appSettingTransferObject2); - var fileResultString1 = - await StreamToStringHelper.StreamToStringAsync( - storage.ReadStream(appSettings.AppSettingsPath)); - var fileResult1 = JsonSerializer.Deserialize(fileResultString1, - DefaultJsonSerializer.NoNamingPolicyBoolAsString); + var fileResultString2 = + await StreamToStringHelper.StreamToStringAsync( + storage.ReadStream(appSettings.AppSettingsPath)); + var fileResult2 = JsonSerializer.Deserialize(fileResultString2, + DefaultJsonSerializer.NoNamingPolicyBoolAsString); - Assert.IsNotNull(fileResult1); - Assert.IsTrue(fileResult1.App.Verbose); + Assert.IsNotNull(fileResult2); - var appSettingTransferObject2 = new AppSettingsTransferObject - { - StorageFolder = testFolderPath - }; + // Set back to what is was before + Environment.SetEnvironmentVariable("app__storageFolder", before); - await updateAppSettingsByPath.UpdateAppSettingsAsync(appSettingTransferObject2); + Assert.AreEqual(testFolderPath, fileResult2.App.StorageFolder); + Assert.IsTrue(fileResult2.App.Verbose); + } - var fileResultString2 = - await StreamToStringHelper.StreamToStringAsync( - storage.ReadStream(appSettings.AppSettingsPath)); - var fileResult2 = JsonSerializer.Deserialize(fileResultString2, - DefaultJsonSerializer.NoNamingPolicyBoolAsString); + [TestMethod] + public async Task UpdateAppSettingsAsync_ValidInput_Success_Desktop() + { + var storage = new FakeIStorage(); + var selectorStorage = new FakeSelectorStorage(storage); + var updateAppSettingsByPath = + new UpdateAppSettingsByPath(new AppSettings(), selectorStorage); + var appSettingTransferObject = new AppSettingsTransferObject + { + DesktopCollectionsOpen = CollectionsOpenType.RawJpegMode.Raw, + DefaultDesktopEditor = + [ + new AppSettingsDefaultEditorApplication + { + ApplicationPath = "/test", + ImageFormats = + [ExtensionRolesHelper.ImageFormat.jpg] + } + ] + }; + + // Act + var result = + await updateAppSettingsByPath.UpdateAppSettingsAsync(appSettingTransferObject); - Assert.IsNotNull(fileResult2); - // Set back to what is was before - Environment.SetEnvironmentVariable("app__storageFolder", before); + // Assert + Assert.AreEqual(200, result.StatusCode); + Assert.AreEqual("Updated", result.Message); - Assert.AreEqual(testFolderPath, fileResult2.App.StorageFolder); - Assert.IsTrue(fileResult2.App.Verbose); - } + var fileResultString2 = + await StreamToStringHelper.StreamToStringAsync( + storage.ReadStream(new AppSettings().AppSettingsPath)); + var fileResult2 = JsonSerializer.Deserialize(fileResultString2, + DefaultJsonSerializer.NoNamingPolicyBoolAsString); - [TestMethod] - public async Task UpdateAppSettingsAsync_ValidInput_Success_Desktop() - { - var storage = new FakeIStorage(); - var selectorStorage = new FakeSelectorStorage(storage); - var updateAppSettingsByPath = - new UpdateAppSettingsByPath(new AppSettings(), selectorStorage); - var appSettingTransferObject = new AppSettingsTransferObject - { - DesktopCollectionsOpen = CollectionsOpenType.RawJpegMode.Raw, - DefaultDesktopEditor = - [ - new AppSettingsDefaultEditorApplication - { - ApplicationPath = "/test", - ImageFormats = - [ExtensionRolesHelper.ImageFormat.jpg] - } - ] - }; - - // Act - var result = - await updateAppSettingsByPath.UpdateAppSettingsAsync(appSettingTransferObject); - - - // Assert - Assert.AreEqual(200, result.StatusCode); - Assert.AreEqual("Updated", result.Message); - - var fileResultString2 = - await StreamToStringHelper.StreamToStringAsync( - storage.ReadStream(new AppSettings().AppSettingsPath)); - var fileResult2 = JsonSerializer.Deserialize(fileResultString2, - DefaultJsonSerializer.NoNamingPolicyBoolAsString); - - Assert.IsNotNull(fileResult2); - Assert.AreEqual(CollectionsOpenType.RawJpegMode.Raw, - fileResult2.App.DesktopCollectionsOpen); - Assert.AreEqual("/test", fileResult2.App.DefaultDesktopEditor[0].ApplicationPath); - Assert.AreEqual(ExtensionRolesHelper.ImageFormat.jpg, - fileResult2.App.DefaultDesktopEditor[0].ImageFormats[0]); - } + Assert.IsNotNull(fileResult2); + Assert.AreEqual(CollectionsOpenType.RawJpegMode.Raw, + fileResult2.App.DesktopCollectionsOpen); + Assert.AreEqual("/test", fileResult2.App.DefaultDesktopEditor[0].ApplicationPath); + Assert.AreEqual(ExtensionRolesHelper.ImageFormat.jpg, + fileResult2.App.DefaultDesktopEditor[0].ImageFormats[0]); } } diff --git a/starsky/starskytest/starsky.foundation.http/Helpers/HttpClientHelperTest.cs b/starsky/starskytest/starsky.foundation.http/Helpers/HttpClientHelperTest.cs index a46e224b21..bcb1131c4a 100644 --- a/starsky/starskytest/starsky.foundation.http/Helpers/HttpClientHelperTest.cs +++ b/starsky/starskytest/starsky.foundation.http/Helpers/HttpClientHelperTest.cs @@ -1,3 +1,4 @@ +using System; using System.IO; using System.Net.Http; using System.Threading.Tasks; @@ -10,329 +11,330 @@ using starskytest.FakeCreateAn; using starskytest.FakeMocks; -namespace starskytest.starsky.foundation.http.Helpers +namespace starskytest.starsky.foundation.http.Helpers; + +[TestClass] +public sealed class HttpClientHelperTest { - [TestClass] - public sealed class HttpClientHelperTest + [TestMethod] + public async Task Download_HttpClientHelperBadDomainDownload() + { + var fakeHttpMessageHandler = new FakeHttpMessageHandler(); + var httpClient = new HttpClient(fakeHttpMessageHandler); + var httpProvider = new HttpProvider(httpClient); + + var services = new ServiceCollection(); + services.AddSingleton(); + services.AddSingleton(); + var serviceProvider = services.BuildServiceProvider(); + var scopeFactory = serviceProvider.GetRequiredService(); + + var httpClientHelper = + new HttpClientHelper(httpProvider, scopeFactory, new FakeIWebLogger()); + + // use only whitelisted domains + var path = Path.Combine(new AppSettings().TempFolder, "pathToNOT_download.txt"); + var output = await httpClientHelper.Download("https://mybadurl.cn", path); + Assert.IsFalse(output); + } + + [TestMethod] + public async Task Download_HttpClientHelper_404NotFoundTest() + { + var fakeHttpMessageHandler = new FakeHttpMessageHandler(); + var httpClient = new HttpClient(fakeHttpMessageHandler); + var httpProvider = new HttpProvider(httpClient); + + var services = new ServiceCollection(); + services.AddSingleton(); + services.AddSingleton(); + var serviceProvider = services.BuildServiceProvider(); + var scopeFactory = serviceProvider.GetRequiredService(); + + var httpClientHelper = + new HttpClientHelper(httpProvider, scopeFactory, new FakeIWebLogger()); + + // there is a file written + var path = Path.Combine(new CreateAnImage().BasePath, "file.txt"); + var output = await httpClientHelper.Download("https://download.geonames.org/404", path); + Assert.IsFalse(output); + } + + [TestMethod] + public async Task Download_HttpClientHelper_HTTP_Not_Download() + { + var fakeHttpMessageHandler = new FakeHttpMessageHandler(); + var httpClient = new HttpClient(fakeHttpMessageHandler); + var httpProvider = new HttpProvider(httpClient); + + var services = new ServiceCollection(); + services.AddSingleton(); + services.AddSingleton(); + var serviceProvider = services.BuildServiceProvider(); + var scopeFactory = serviceProvider.GetRequiredService(); + + var httpClientHelper = + new HttpClientHelper(httpProvider, scopeFactory, new FakeIWebLogger()); + + // http is not used anymore + var path = Path.Combine(new AppSettings().TempFolder, "pathToNOT_download.txt"); + var output = await httpClientHelper.Download("http://qdraw.nl", path); + Assert.IsFalse(output); + } + + [TestMethod] + public async Task Download_HttpClientHelper_Download() + { + var fakeHttpMessageHandler = new FakeHttpMessageHandler(); + var httpClient = new HttpClient(fakeHttpMessageHandler); + var httpProvider = new HttpProvider(httpClient); + + var services = new ServiceCollection(); + services.AddSingleton(); + services.AddSingleton(); + var serviceProvider = services.BuildServiceProvider(); + var scopeFactory = serviceProvider.GetRequiredService(); + var storageProvider = serviceProvider.GetRequiredService(); + + var httpClientHelper = + new HttpClientHelper(httpProvider, scopeFactory, new FakeIWebLogger()); + + // there is a file written + var path = Path.Combine(new CreateAnImage().BasePath, "file.txt"); + var output = await httpClientHelper.Download("https://qdraw.nl/test", path); + + Assert.IsTrue(output); + + Assert.AreEqual(FolderOrFileModel.FolderOrFileTypeList.File, + storageProvider.IsFolderOrFile(path)); + storageProvider.FileDelete(path); + } + + [TestMethod] + [Timeout(5000)] + public async Task Download_HttpClientHelper_Download_HttpRequestException() + { + // > next HttpRequestException + var fakeHttpMessageHandler = + new FakeHttpMessageHandler(new HttpRequestException("should fail")); + var httpClient = new HttpClient(fakeHttpMessageHandler); + var httpProvider = new HttpProvider(httpClient); + + var services = new ServiceCollection(); + services.AddSingleton(); + services.AddSingleton(); + var serviceProvider = services.BuildServiceProvider(); + var scopeFactory = serviceProvider.GetRequiredService(); + + var httpClientHelper = + new HttpClientHelper(httpProvider, scopeFactory, new FakeIWebLogger()); + var output = await httpClientHelper.Download("https://qdraw.nl/test", "/random_path", 1); + Assert.IsFalse(output); + } + + [TestMethod] + public async Task Download_HttpClientHelper_Download_NoStorage() + { + var sut = new HttpClientHelper(new FakeIHttpProvider(), null as IServiceScopeFactory, + new FakeIWebLogger()); + + await Assert.ThrowsExceptionAsync(() => sut + .Download("t", "T")); + } + + [TestMethod] + public async Task ReadString_HttpClientHelper_ReadString() + { + var fakeHttpMessageHandler = new FakeHttpMessageHandler(); + var httpClient = new HttpClient(fakeHttpMessageHandler); + var httpProvider = new HttpProvider(httpClient); + + var services = new ServiceCollection(); + services.AddSingleton(); + services.AddSingleton(); + var serviceProvider = services.BuildServiceProvider(); + var scopeFactory = serviceProvider.GetRequiredService(); + + var httpClientHelper = + new HttpClientHelper(httpProvider, scopeFactory, new FakeIWebLogger()); + + var output = await httpClientHelper.ReadString("https://qdraw.nl/test"); + + Assert.IsTrue(output.Key); + } + + + [TestMethod] + public async Task ReadString_HttpClientHelper_ReadString_HttpRequestException() + { + // > next HttpRequestException + var fakeHttpMessageHandler = + new FakeHttpMessageHandler(new HttpRequestException("should fail")); + var httpClient = new HttpClient(fakeHttpMessageHandler); + var httpProvider = new HttpProvider(httpClient); + + var services = new ServiceCollection(); + services.AddSingleton(); + services.AddSingleton(); + var serviceProvider = services.BuildServiceProvider(); + var scopeFactory = serviceProvider.GetRequiredService(); + + var httpClientHelper = + new HttpClientHelper(httpProvider, scopeFactory, new FakeIWebLogger()); + var output = await httpClientHelper.ReadString("https://qdraw.nl/test"); + Assert.IsFalse(output.Key); + } + + [TestMethod] + public async Task ReadString_HttpClientHelper_HTTP_Not_ReadString() + { + var fakeHttpMessageHandler = new FakeHttpMessageHandler(); + var httpClient = new HttpClient(fakeHttpMessageHandler); + var httpProvider = new HttpProvider(httpClient); + + var services = new ServiceCollection(); + services.AddSingleton(); + services.AddSingleton(); + var serviceProvider = services.BuildServiceProvider(); + var scopeFactory = serviceProvider.GetRequiredService(); + + var httpClientHelper = + new HttpClientHelper(httpProvider, scopeFactory, new FakeIWebLogger()); + + // http is not used anymore + var output = await httpClientHelper.ReadString("http://qdraw.nl"); + Assert.IsFalse(output.Key); + } + + [TestMethod] + public async Task ReadString_HttpClientHelper_404NotFound_ReadString_Test() + { + var fakeHttpMessageHandler = new FakeHttpMessageHandler(); + var httpClient = new HttpClient(fakeHttpMessageHandler); + var httpProvider = new HttpProvider(httpClient); + + var services = new ServiceCollection(); + services.AddSingleton(); + services.AddSingleton(); + var serviceProvider = services.BuildServiceProvider(); + var scopeFactory = serviceProvider.GetRequiredService(); + + var httpClientHelper = + new HttpClientHelper(httpProvider, scopeFactory, new FakeIWebLogger()); + + var output = await httpClientHelper.ReadString("https://download.geonames.org/404"); + Assert.IsFalse(output.Key); + } + + [TestMethod] + public async Task PostString_HttpClientHelper() + { + var fakeHttpMessageHandler = new FakeHttpMessageHandler(); + var httpClient = new HttpClient(fakeHttpMessageHandler); + var httpProvider = new HttpProvider(httpClient); + + var services = new ServiceCollection(); + services.AddSingleton(); + services.AddSingleton(); + var serviceProvider = services.BuildServiceProvider(); + var scopeFactory = serviceProvider.GetRequiredService(); + + var httpClientHelper = + new HttpClientHelper(httpProvider, scopeFactory, new FakeIWebLogger()); + + var output = await httpClientHelper + .PostString("https://qdraw.nl/test", new StringContent(string.Empty)); + + Assert.IsTrue(output.Key); + } + + [TestMethod] + public async Task PostString_HttpClientHelper_VerboseFalse() + { + var fakeHttpMessageHandler = new FakeHttpMessageHandler(); + var httpClient = new HttpClient(fakeHttpMessageHandler); + var httpProvider = new HttpProvider(httpClient); + + var services = new ServiceCollection(); + services.AddSingleton(); + services.AddSingleton(); + var serviceProvider = services.BuildServiceProvider(); + var scopeFactory = serviceProvider.GetRequiredService(); + + var fakeLogger = new FakeIWebLogger(); + var httpClientHelper = new HttpClientHelper(httpProvider, scopeFactory, fakeLogger); + + await httpClientHelper + .PostString("https://qdraw.nl/test", new StringContent(string.Empty), false); + + Assert.IsFalse( + fakeLogger.TrackedInformation.Exists(p => p.Item2?.Contains("PostString") == true)); + Assert.IsFalse(fakeLogger.TrackedInformation.Exists(p => + p.Item2?.Contains("HttpClientHelper") == true)); + } + + [TestMethod] + public async Task PostString_HttpRequestException() + { + // > next HttpRequestException + var fakeHttpMessageHandler = + new FakeHttpMessageHandler(new HttpRequestException("should fail")); + var httpClient = new HttpClient(fakeHttpMessageHandler); + var httpProvider = new HttpProvider(httpClient); + + var services = new ServiceCollection(); + services.AddSingleton(); + services.AddSingleton(); + var serviceProvider = services.BuildServiceProvider(); + var scopeFactory = serviceProvider.GetRequiredService(); + + var httpClientHelper = + new HttpClientHelper(httpProvider, scopeFactory, new FakeIWebLogger()); + var output = await httpClientHelper + .PostString("https://qdraw.nl/test", new StringContent(string.Empty)); + Assert.IsFalse(output.Key); + } + + [TestMethod] + public async Task PostString_HTTP_Not_ReadString() + { + var fakeHttpMessageHandler = new FakeHttpMessageHandler(); + var httpClient = new HttpClient(fakeHttpMessageHandler); + var httpProvider = new HttpProvider(httpClient); + + var services = new ServiceCollection(); + services.AddSingleton(); + services.AddSingleton(); + var serviceProvider = services.BuildServiceProvider(); + var scopeFactory = serviceProvider.GetRequiredService(); + + var httpClientHelper = + new HttpClientHelper(httpProvider, scopeFactory, new FakeIWebLogger()); + + // http is not used anymore + var output = await httpClientHelper + .PostString("http://qdraw.nl", new StringContent(string.Empty)); + Assert.IsFalse(output.Key); + } + + [TestMethod] + public async Task PostString_404NotFound_Test() { - [TestMethod] - public async Task Download_HttpClientHelperBadDomainDownload() - { - var fakeHttpMessageHandler = new FakeHttpMessageHandler(); - var httpClient = new HttpClient(fakeHttpMessageHandler); - var httpProvider = new HttpProvider(httpClient); - - var services = new ServiceCollection(); - services.AddSingleton(); - services.AddSingleton(); - var serviceProvider = services.BuildServiceProvider(); - var scopeFactory = serviceProvider.GetRequiredService(); - - var httpClientHelper = - new HttpClientHelper(httpProvider, scopeFactory, new FakeIWebLogger()); - - // use only whitelisted domains - var path = Path.Combine(new AppSettings().TempFolder, "pathToNOTdownload.txt"); - var output = await httpClientHelper.Download("http://mybadurl.cn", path); - Assert.IsFalse(output); - } - - [TestMethod] - public async Task Download_HttpClientHelper_404NotFoundTest() - { - var fakeHttpMessageHandler = new FakeHttpMessageHandler(); - var httpClient = new HttpClient(fakeHttpMessageHandler); - var httpProvider = new HttpProvider(httpClient); - - var services = new ServiceCollection(); - services.AddSingleton(); - services.AddSingleton(); - var serviceProvider = services.BuildServiceProvider(); - var scopeFactory = serviceProvider.GetRequiredService(); - - var httpClientHelper = - new HttpClientHelper(httpProvider, scopeFactory, new FakeIWebLogger()); - - // there is an file written - var path = Path.Combine(new CreateAnImage().BasePath, "file.txt"); - var output = await httpClientHelper.Download("https://download.geonames.org/404", path); - Assert.IsFalse(output); - } - - [TestMethod] - public async Task Download_HttpClientHelper_HTTP_Not_Download() - { - var fakeHttpMessageHandler = new FakeHttpMessageHandler(); - var httpClient = new HttpClient(fakeHttpMessageHandler); - var httpProvider = new HttpProvider(httpClient); - - var services = new ServiceCollection(); - services.AddSingleton(); - services.AddSingleton(); - var serviceProvider = services.BuildServiceProvider(); - var scopeFactory = serviceProvider.GetRequiredService(); - - var httpClientHelper = - new HttpClientHelper(httpProvider, scopeFactory, new FakeIWebLogger()); - - // http is not used anymore - var path = Path.Combine(new AppSettings().TempFolder, "pathToNOTdownload.txt"); - var output = await httpClientHelper.Download("http://qdraw.nl", path); - Assert.IsFalse(output); - } - - [TestMethod] - public async Task Download_HttpClientHelper_Download() - { - var fakeHttpMessageHandler = new FakeHttpMessageHandler(); - var httpClient = new HttpClient(fakeHttpMessageHandler); - var httpProvider = new HttpProvider(httpClient); - - var services = new ServiceCollection(); - services.AddSingleton(); - services.AddSingleton(); - var serviceProvider = services.BuildServiceProvider(); - var scopeFactory = serviceProvider.GetRequiredService(); - var storageProvider = serviceProvider.GetRequiredService(); - - var httpClientHelper = - new HttpClientHelper(httpProvider, scopeFactory, new FakeIWebLogger()); - - // there is an file written - var path = Path.Combine(new CreateAnImage().BasePath, "file.txt"); - var output = await httpClientHelper.Download("https://qdraw.nl/test", path); - - Assert.IsTrue(output); - - Assert.AreEqual(FolderOrFileModel.FolderOrFileTypeList.File, - storageProvider.IsFolderOrFile(path)); - storageProvider.FileDelete(path); - } - - [TestMethod] - [Timeout(5000)] - public async Task Download_HttpClientHelper_Download_HttpRequestException() - { - // > next HttpRequestException - var fakeHttpMessageHandler = - new FakeHttpMessageHandler(new HttpRequestException("should fail")); - var httpClient = new HttpClient(fakeHttpMessageHandler); - var httpProvider = new HttpProvider(httpClient); - - var services = new ServiceCollection(); - services.AddSingleton(); - services.AddSingleton(); - var serviceProvider = services.BuildServiceProvider(); - var scopeFactory = serviceProvider.GetRequiredService(); - - var httpClientHelper = - new HttpClientHelper(httpProvider, scopeFactory, new FakeIWebLogger()); - var output = await httpClientHelper.Download("https://qdraw.nl/test", "/sdkflndf", 1); - Assert.IsFalse(output); - } - - [TestMethod] - [ExpectedException(typeof(EndOfStreamException))] - public async Task Download_HttpClientHelper_Download_NoStorage() - { - await new HttpClientHelper(new FakeIHttpProvider(), null, new FakeIWebLogger()) - .Download("t", "T"); - } - - [TestMethod] - public async Task ReadString_HttpClientHelper_ReadString() - { - var fakeHttpMessageHandler = new FakeHttpMessageHandler(); - var httpClient = new HttpClient(fakeHttpMessageHandler); - var httpProvider = new HttpProvider(httpClient); - - var services = new ServiceCollection(); - services.AddSingleton(); - services.AddSingleton(); - var serviceProvider = services.BuildServiceProvider(); - var scopeFactory = serviceProvider.GetRequiredService(); - - var httpClientHelper = - new HttpClientHelper(httpProvider, scopeFactory, new FakeIWebLogger()); - - var output = await httpClientHelper.ReadString("https://qdraw.nl/test"); - - Assert.IsTrue(output.Key); - } - - - [TestMethod] - public async Task ReadString_HttpClientHelper_ReadString_HttpRequestException() - { - // > next HttpRequestException - var fakeHttpMessageHandler = - new FakeHttpMessageHandler(new HttpRequestException("should fail")); - var httpClient = new HttpClient(fakeHttpMessageHandler); - var httpProvider = new HttpProvider(httpClient); - - var services = new ServiceCollection(); - services.AddSingleton(); - services.AddSingleton(); - var serviceProvider = services.BuildServiceProvider(); - var scopeFactory = serviceProvider.GetRequiredService(); - - var httpClientHelper = - new HttpClientHelper(httpProvider, scopeFactory, new FakeIWebLogger()); - var output = await httpClientHelper.ReadString("https://qdraw.nl/test"); - Assert.IsFalse(output.Key); - } - - [TestMethod] - public async Task ReadString_HttpClientHelper_HTTP_Not_ReadString() - { - var fakeHttpMessageHandler = new FakeHttpMessageHandler(); - var httpClient = new HttpClient(fakeHttpMessageHandler); - var httpProvider = new HttpProvider(httpClient); - - var services = new ServiceCollection(); - services.AddSingleton(); - services.AddSingleton(); - var serviceProvider = services.BuildServiceProvider(); - var scopeFactory = serviceProvider.GetRequiredService(); - - var httpClientHelper = - new HttpClientHelper(httpProvider, scopeFactory, new FakeIWebLogger()); - - // http is not used anymore - var output = await httpClientHelper.ReadString("http://qdraw.nl"); - Assert.IsFalse(output.Key); - } - - [TestMethod] - public async Task ReadString_HttpClientHelper_404NotFound_ReadString_Test() - { - var fakeHttpMessageHandler = new FakeHttpMessageHandler(); - var httpClient = new HttpClient(fakeHttpMessageHandler); - var httpProvider = new HttpProvider(httpClient); - - var services = new ServiceCollection(); - services.AddSingleton(); - services.AddSingleton(); - var serviceProvider = services.BuildServiceProvider(); - var scopeFactory = serviceProvider.GetRequiredService(); - - var httpClientHelper = - new HttpClientHelper(httpProvider, scopeFactory, new FakeIWebLogger()); - - var output = await httpClientHelper.ReadString("https://download.geonames.org/404"); - Assert.IsFalse(output.Key); - } - - [TestMethod] - public async Task PostString_HttpClientHelper() - { - var fakeHttpMessageHandler = new FakeHttpMessageHandler(); - var httpClient = new HttpClient(fakeHttpMessageHandler); - var httpProvider = new HttpProvider(httpClient); - - var services = new ServiceCollection(); - services.AddSingleton(); - services.AddSingleton(); - var serviceProvider = services.BuildServiceProvider(); - var scopeFactory = serviceProvider.GetRequiredService(); - - var httpClientHelper = - new HttpClientHelper(httpProvider, scopeFactory, new FakeIWebLogger()); - - var output = await httpClientHelper - .PostString("https://qdraw.nl/test", new StringContent(string.Empty)); - - Assert.IsTrue(output.Key); - } - - [TestMethod] - public async Task PostString_HttpClientHelper_VerboseFalse() - { - var fakeHttpMessageHandler = new FakeHttpMessageHandler(); - var httpClient = new HttpClient(fakeHttpMessageHandler); - var httpProvider = new HttpProvider(httpClient); - - var services = new ServiceCollection(); - services.AddSingleton(); - services.AddSingleton(); - var serviceProvider = services.BuildServiceProvider(); - var scopeFactory = serviceProvider.GetRequiredService(); - - var fakeLogger = new FakeIWebLogger(); - var httpClientHelper = new HttpClientHelper(httpProvider, scopeFactory, fakeLogger); - - await httpClientHelper - .PostString("https://qdraw.nl/test", new StringContent(string.Empty), false); - - Assert.IsFalse( - fakeLogger.TrackedInformation.Exists(p => p.Item2?.Contains("PostString") == true)); - Assert.IsFalse(fakeLogger.TrackedInformation.Exists(p => - p.Item2?.Contains("HttpClientHelper") == true)); - } - - [TestMethod] - public async Task PostString_HttpRequestException() - { - // > next HttpRequestException - var fakeHttpMessageHandler = - new FakeHttpMessageHandler(new HttpRequestException("should fail")); - var httpClient = new HttpClient(fakeHttpMessageHandler); - var httpProvider = new HttpProvider(httpClient); - - var services = new ServiceCollection(); - services.AddSingleton(); - services.AddSingleton(); - var serviceProvider = services.BuildServiceProvider(); - var scopeFactory = serviceProvider.GetRequiredService(); - - var httpClientHelper = - new HttpClientHelper(httpProvider, scopeFactory, new FakeIWebLogger()); - var output = await httpClientHelper - .PostString("https://qdraw.nl/test", new StringContent(string.Empty)); - Assert.IsFalse(output.Key); - } - - [TestMethod] - public async Task PostString_HTTP_Not_ReadString() - { - var fakeHttpMessageHandler = new FakeHttpMessageHandler(); - var httpClient = new HttpClient(fakeHttpMessageHandler); - var httpProvider = new HttpProvider(httpClient); - - var services = new ServiceCollection(); - services.AddSingleton(); - services.AddSingleton(); - var serviceProvider = services.BuildServiceProvider(); - var scopeFactory = serviceProvider.GetRequiredService(); - - var httpClientHelper = - new HttpClientHelper(httpProvider, scopeFactory, new FakeIWebLogger()); - - // http is not used anymore - var output = await httpClientHelper - .PostString("http://qdraw.nl", new StringContent(string.Empty)); - Assert.IsFalse(output.Key); - } - - [TestMethod] - public async Task PostString_404NotFound_Test() - { - var fakeHttpMessageHandler = new FakeHttpMessageHandler(); - var httpClient = new HttpClient(fakeHttpMessageHandler); - var httpProvider = new HttpProvider(httpClient); - - var services = new ServiceCollection(); - services.AddSingleton(); - services.AddSingleton(); - var serviceProvider = services.BuildServiceProvider(); - var scopeFactory = serviceProvider.GetRequiredService(); - - var httpClientHelper = - new HttpClientHelper(httpProvider, scopeFactory, new FakeIWebLogger()); - - var output = await httpClientHelper - .PostString("https://download.geonames.org/404", new StringContent(string.Empty)); - Assert.IsFalse(output.Key); - } + var fakeHttpMessageHandler = new FakeHttpMessageHandler(); + var httpClient = new HttpClient(fakeHttpMessageHandler); + var httpProvider = new HttpProvider(httpClient); + + var services = new ServiceCollection(); + services.AddSingleton(); + services.AddSingleton(); + var serviceProvider = services.BuildServiceProvider(); + var scopeFactory = serviceProvider.GetRequiredService(); + + var httpClientHelper = + new HttpClientHelper(httpProvider, scopeFactory, new FakeIWebLogger()); + + var output = await httpClientHelper + .PostString("https://download.geonames.org/404", new StringContent(string.Empty)); + Assert.IsFalse(output.Key); } } diff --git a/starsky/starskytest/starsky.foundation.platform/Extensions/MemoryCacheExtensionsTest.cs b/starsky/starskytest/starsky.foundation.platform/Extensions/MemoryCacheExtensionsTest.cs index e54d380df5..ee390ec757 100644 --- a/starsky/starskytest/starsky.foundation.platform/Extensions/MemoryCacheExtensionsTest.cs +++ b/starsky/starskytest/starsky.foundation.platform/Extensions/MemoryCacheExtensionsTest.cs @@ -30,10 +30,10 @@ public void MemoryCacheExtensions_OneItemInCache() var buildServiceProvider = provider.BuildServiceProvider(); var memoryCache = buildServiceProvider.GetService(); - memoryCache?.Set("test", ""); + memoryCache?.Set("test-memory-cache", ""); var keys = memoryCache?.GetKeys().ToList(); Assert.AreEqual(1, keys?.Count); - Assert.AreEqual("test", keys?[0]); + Assert.AreEqual("test-memory-cache", keys?[0]); } [TestMethod] diff --git a/starsky/starskytest/starsky.foundation.storage/ArchiveFormats/ZipperTest.cs b/starsky/starskytest/starsky.foundation.storage/ArchiveFormats/ZipperTest.cs index 968a1c55a3..68e80df1d8 100644 --- a/starsky/starskytest/starsky.foundation.storage/ArchiveFormats/ZipperTest.cs +++ b/starsky/starskytest/starsky.foundation.storage/ArchiveFormats/ZipperTest.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.IO; using System.IO.Compression; @@ -8,6 +9,7 @@ using starskytest.FakeCreateAn; using starskytest.FakeCreateAn.CreateAnZipFile12; using starskytest.FakeCreateAn.CreateAnZipFileChildFolders; +using starskytest.FakeCreateAn.CreateAnZipFileMacOs; using starskytest.FakeMocks; namespace starskytest.starsky.foundation.storage.ArchiveFormats; @@ -18,10 +20,10 @@ public sealed class ZipperTest [TestMethod] public void NotFound() { - var result = new Zipper(new FakeIWebLogger()).ExtractZip("not-found","t"); + var result = new Zipper(new FakeIWebLogger()).ExtractZip("not-found", "t"); Assert.IsFalse(result); } - + [TestMethod] public void TestExtractZip() { @@ -35,20 +37,46 @@ public void TestExtractZip() Assert.IsNotNull(result); Assert.AreEqual(CreateAnZipFile12.Content.Count, result.Count); - foreach (var entry in CreateAnZipFile12.Content) + foreach ( var entry in CreateAnZipFile12.Content ) { Assert.IsTrue(result.ContainsKey(entry.Key)); var resultText = Encoding.UTF8.GetString(result[entry.Key]); Assert.AreEqual(entry.Value, resultText); } } + + [TestMethod] + public void TestExtractZipMacOs() + { + // Arrange + var zipped = new CreateAnZipFileMacOs().FilePath; + var testOutputFolder = + Path.Combine(new CreateAnImage().BasePath, "test-folder-zip-folders-mac-os"); + + var hostService = new StorageHostFullPathFilesystem(new FakeIWebLogger()); + hostService.FolderDelete(testOutputFolder); + + // Act + var result = new Zipper(new FakeIWebLogger()).ExtractZip(zipped, testOutputFolder); + + // Assert + Assert.IsNotNull(result); + foreach ( var entry in CreateAnZipFileMacOs.Content ) + { + Assert.IsTrue(hostService.ExistFile(Path.Combine(testOutputFolder, entry))); + } + + hostService.FolderDelete(testOutputFolder); + } + [TestMethod] public void TestExtractZipFolders() { // Arrange var zipped = CreateAnZipFileChildFolders.Bytes; - var testOutputFolder = Path.Combine(new CreateAnImage().BasePath, "test-folder-zip-folders"); + var testOutputFolder = + Path.Combine(new CreateAnImage().BasePath, "test-folder-zip-folders"); var inputZipPath = testOutputFolder + ".zip"; var hostService = new StorageHostFullPathFilesystem(new FakeIWebLogger()); hostService.WriteStream(new MemoryStream([..zipped]), inputZipPath); @@ -62,21 +90,22 @@ public void TestExtractZipFolders() foreach ( var contentItem in CreateAnZipFileChildFolders.Content ) { - var path = Path.Combine(testOutputFolder, contentItem.Key.Replace("/", Path.DirectorySeparatorChar.ToString())); - + var path = Path.Combine(testOutputFolder, + contentItem.Key.Replace("/", Path.DirectorySeparatorChar.ToString())); + if ( contentItem.Value ) { Assert.IsTrue(hostService.ExistFolder(path)); continue; } - + Assert.IsTrue(hostService.ExistFile(path)); } hostService.FolderDelete(testOutputFolder); hostService.FileDelete(inputZipPath); } - + [TestMethod] public void CreateZip_Returns_Valid_Path_When_File_Exists() { @@ -84,11 +113,13 @@ public void CreateZip_Returns_Valid_Path_When_File_Exists() var filePaths = new List { "C:\\temp\\file1.txt", "C:\\temp\\file2.txt" }; var fileNames = new List { "file1.txt", "file2.txt" }; const string zipOutputFilename = "CreateZip_Returns_Valid_Path_When_File_Exists"; - var tempFileFullPath = Path.Combine(new CreateAnImage().BasePath, zipOutputFilename) + ".zip"; + var tempFileFullPath = + Path.Combine(new CreateAnImage().BasePath, zipOutputFilename) + ".zip"; File.Create(tempFileFullPath).Close(); // Create a temporary zip file - + // Act - var result = new Zipper(new FakeIWebLogger()).CreateZip(new CreateAnImage().BasePath, filePaths, fileNames, zipOutputFilename); + var result = new Zipper(new FakeIWebLogger()).CreateZip(new CreateAnImage().BasePath, + filePaths, fileNames, zipOutputFilename); // Assert File.Delete(tempFileFullPath); @@ -101,7 +132,7 @@ public void CreateZip_Creates_Valid_Zip_File() // Arrange var fileNames = new List { - "CreateZip_Creates_Valid_Zip_File___file1.txt", + "CreateZip_Creates_Valid_Zip_File___file1.txt", "CreateZip_Creates_Valid_Zip_File___file2.txt" }; var filePaths = new List(); @@ -111,12 +142,14 @@ public void CreateZip_Creates_Valid_Zip_File() File.Create(tempFileFullPath1).Close(); // Create a temporary zip file filePaths.Add(tempFileFullPath1); } - + const string zipOutputFilename = "CreateZip_Creates_Valid_Zip_File"; - var tempFileFullPath = Path.Combine(new CreateAnImage().BasePath, zipOutputFilename) + ".zip"; + var tempFileFullPath = + Path.Combine(new CreateAnImage().BasePath, zipOutputFilename) + ".zip"; // Act - var result = new Zipper(new FakeIWebLogger()).CreateZip(new CreateAnImage().BasePath, filePaths, fileNames, zipOutputFilename); + var result = new Zipper(new FakeIWebLogger()).CreateZip(new CreateAnImage().BasePath, + filePaths, fileNames, zipOutputFilename); // Assert Assert.IsTrue(File.Exists(result)); @@ -129,14 +162,15 @@ public void CreateZip_Creates_Valid_Zip_File() var archive = ZipFile.OpenRead(result); Assert.AreEqual(filePaths.Count, archive.Entries.Count); - for (var i = 0; i < filePaths.Count; i++) + for ( var i = 0; i < filePaths.Count; i++ ) { var entry = archive.Entries[i]; Assert.AreEqual(fileNames[i], entry.Name); Assert.AreEqual(0, entry.Length); } + archive.Dispose(); - + File.Delete(tempFileFullPath); } } diff --git a/starsky/starskytest/starsky.foundation.storage/Helpers/CheckSha256HelperTest.cs b/starsky/starskytest/starsky.foundation.storage/Helpers/CheckSha256HelperTest.cs new file mode 100644 index 0000000000..6bf0dde21e --- /dev/null +++ b/starsky/starskytest/starsky.foundation.storage/Helpers/CheckSha256HelperTest.cs @@ -0,0 +1,33 @@ +using System.Collections.Generic; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using starsky.foundation.storage.Helpers; +using starskytest.FakeCreateAn; +using starskytest.FakeMocks; + +namespace starskytest.starsky.foundation.storage.Helpers; + +[TestClass] +public class CheckSha256HelperTest +{ + private readonly FakeIStorage _fakeIStorage = new(new List { "/" }, + ["/exiftool.exe"], + [[.. CreateAnExifToolTarGz.Bytes]]); + + [TestMethod] + public void CheckSha256_Good() + { + var sut = new CheckSha256Helper(_fakeIStorage); + var result2 = sut.CheckSha256("/exiftool.exe", + [CreateAnExifToolTarGz.Sha256]); + Assert.IsTrue(result2); + } + + [TestMethod] + public void CheckSha1_Bad() + { + var sut = new CheckSha256Helper(_fakeIStorage); + var result2 = sut.CheckSha256("/exiftool.exe", + ["random_value"]); + Assert.IsFalse(result2); + } +} diff --git a/starsky/starskytest/starsky.foundation.storage/Storage/StorageThumbnailFilesystemTest.cs b/starsky/starskytest/starsky.foundation.storage/Storage/StorageThumbnailFilesystemTest.cs index a31286e1fb..4ebf6eb15e 100644 --- a/starsky/starskytest/starsky.foundation.storage/Storage/StorageThumbnailFilesystemTest.cs +++ b/starsky/starskytest/starsky.foundation.storage/Storage/StorageThumbnailFilesystemTest.cs @@ -8,185 +8,184 @@ using starskytest.FakeCreateAn; using starskytest.FakeMocks; -namespace starskytest.starsky.foundation.storage.Storage +namespace starskytest.starsky.foundation.storage.Storage; + +[TestClass] +public sealed class StorageThumbnailFilesystemTest { - [TestClass] - public sealed class StorageThumbnailFilesystemTest + private readonly string _fileNameWithoutExtension; + private readonly StorageThumbnailFilesystem _thumbnailStorage; + + public StorageThumbnailFilesystemTest() + { + var createNewImage = new CreateAnImage(); + var appSettings = new AppSettings { ThumbnailTempFolder = createNewImage.BasePath }; + _thumbnailStorage = new StorageThumbnailFilesystem(appSettings, new FakeIWebLogger()); + _fileNameWithoutExtension = + FilenamesHelper.GetFileNameWithoutExtension(createNewImage.FileName); + } + + [TestMethod] + public void CombinePathShouldEndWithTestJpg() + { + var result = _thumbnailStorage.CombinePath("test.jpg"); + Assert.IsTrue(result.EndsWith("test.jpg")); + } + + [TestMethod] + public void CombinePathShouldEndWithTestJpg2() + { + var result = _thumbnailStorage.CombinePath("test"); + Assert.IsTrue(result.EndsWith("test.jpg")); + } + + [TestMethod] + public void FileMove_Test() + { + var createNewImage = new CreateAnImage(); + + // first copy for parallel test + _thumbnailStorage.FileCopy(_fileNameWithoutExtension, "start_move_file"); + + _thumbnailStorage.FileMove("start_move_file", + "StorageThumbnailFilesystemTest_FileMove"); + + var path = Path.Combine(createNewImage.BasePath, "start_move_file" + ".jpg"); + Assert.IsFalse(File.Exists(path)); + var path2 = Path.Combine(createNewImage.BasePath, + "StorageThumbnailFilesystemTest_FileMove.jpg"); + Assert.IsTrue(File.Exists(path2)); + + File.Delete(Path.Combine(createNewImage.BasePath, "start_move_file.jpg")); + File.Delete(Path.Combine(createNewImage.BasePath, + "StorageThumbnailFilesystemTest_FileMove.jpg")); + + var createAnImage = new CreateAnImage(); + Assert.IsNotNull(createAnImage); + } + + [TestMethod] + public void FileCopy_success() + { + var createNewImage = new CreateAnImage(); + + _thumbnailStorage.FileCopy(_fileNameWithoutExtension, + "StorageThumbnailFilesystemTest_FileCopy"); + + var path = Path.Combine(createNewImage.BasePath, _fileNameWithoutExtension + ".jpg"); + Assert.IsTrue(File.Exists(path)); + var path2 = Path.Combine(createNewImage.BasePath, + "StorageThumbnailFilesystemTest_FileCopy.jpg"); + Assert.IsTrue(File.Exists(path2)); + + File.Delete(_fileNameWithoutExtension); + File.Delete(Path.Combine(createNewImage.BasePath, + "StorageThumbnailFilesystemTest_FileCopy.jpg")); + + var createAnImage = new CreateAnImage(); + Assert.IsNotNull(createAnImage); + } + + [TestMethod] + public void FileCopy_source_notFound() { - private readonly StorageThumbnailFilesystem _thumbnailStorage; - private readonly string _fileNameWithoutExtension; - - public StorageThumbnailFilesystemTest() - { - var createNewImage = new CreateAnImage(); - var appSettings = new AppSettings { ThumbnailTempFolder = createNewImage.BasePath }; - _thumbnailStorage = new StorageThumbnailFilesystem(appSettings, new FakeIWebLogger()); - _fileNameWithoutExtension = - FilenamesHelper.GetFileNameWithoutExtension(createNewImage.FileName); - } - - [TestMethod] - public void CombinePathShouldEndWithTestJpg() - { - var result = _thumbnailStorage.CombinePath("test.jpg"); - Assert.IsTrue(result.EndsWith("test.jpg")); - } - - [TestMethod] - public void CombinePathShouldEndWithTestJpg2() - { - var result = _thumbnailStorage.CombinePath("test"); - Assert.IsTrue(result.EndsWith("test.jpg")); - } - - [TestMethod] - public void FileMove_Test() - { - var createNewImage = new CreateAnImage(); - - // first copy for parallel test - _thumbnailStorage.FileCopy(_fileNameWithoutExtension, "start_move_file"); - - _thumbnailStorage.FileMove("start_move_file", - "StorageThumbnailFilesystemTest_FileMove"); - - var path = Path.Combine(createNewImage.BasePath, "start_move_file" + ".jpg"); - Assert.IsFalse(File.Exists(path)); - var path2 = Path.Combine(createNewImage.BasePath, - "StorageThumbnailFilesystemTest_FileMove.jpg"); - Assert.IsTrue(File.Exists(path2)); - - File.Delete(Path.Combine(createNewImage.BasePath, "start_move_file.jpg")); - File.Delete(Path.Combine(createNewImage.BasePath, - "StorageThumbnailFilesystemTest_FileMove.jpg")); - - var createAnImage = new CreateAnImage(); - Assert.IsNotNull(createAnImage); - } - - [TestMethod] - public void FileCopy_success() - { - var createNewImage = new CreateAnImage(); - - _thumbnailStorage.FileCopy(_fileNameWithoutExtension, - "StorageThumbnailFilesystemTest_FileCopy"); - - var path = Path.Combine(createNewImage.BasePath, _fileNameWithoutExtension + ".jpg"); - Assert.IsTrue(File.Exists(path)); - var path2 = Path.Combine(createNewImage.BasePath, - "StorageThumbnailFilesystemTest_FileCopy.jpg"); - Assert.IsTrue(File.Exists(path2)); - - File.Delete(_fileNameWithoutExtension); - File.Delete(Path.Combine(createNewImage.BasePath, - "StorageThumbnailFilesystemTest_FileCopy.jpg")); - - var createAnImage = new CreateAnImage(); - Assert.IsNotNull(createAnImage); - } - - [TestMethod] - public void FileCopy_source_notFound() - { - var createNewImage = new CreateAnImage(); - - _thumbnailStorage.FileCopy("not_found", "StorageThumbnailFilesystemTest_FileCopy2"); - - var path2 = Path.Combine(createNewImage.BasePath, - "StorageThumbnailFilesystemTest_FileCopy2.jpg"); - Assert.IsFalse(File.Exists(path2)); - } - - [TestMethod] - public void FileDelete_NotExist() - { - Assert.IsFalse(_thumbnailStorage.FileDelete("NotFound")); - } - - [TestMethod] - public void ReadStream() - { - var createAnImage = new CreateAnImage(); - Assert.IsNotNull(createAnImage); - - var stream = _thumbnailStorage.ReadStream(_fileNameWithoutExtension); - Assert.AreEqual(CreateAnImage.Bytes.Length, stream.Length); - - stream.Dispose(); - } - - [TestMethod] - public void ReadStream_MaxLength() - { - var createAnImage = new CreateAnImage(); - Assert.IsNotNull(createAnImage); - - var stream = _thumbnailStorage.ReadStream(_fileNameWithoutExtension, 100); - Assert.AreEqual(100, stream.Length); - - stream.Dispose(); - } - - [TestMethod] - public void WriteStream() - { - var createNewImage = new CreateAnImage(); - - _thumbnailStorage.WriteStream(new MemoryStream(CreateAnImage.Bytes.ToArray()), - "StorageThumbnailFilesystemTest_WriteStream"); - - var readStream = - _thumbnailStorage.ReadStream("StorageThumbnailFilesystemTest_WriteStream"); - Assert.AreEqual(CreateAnImage.Bytes.Length, readStream.Length); - readStream.Dispose(); - - File.Delete(Path.Combine(createNewImage.BasePath, - "StorageThumbnailFilesystemTest_FileMove.jpg")); - } - - [TestMethod] - public async Task WriteStreamAsync() - { - var createNewImage = new CreateAnImage(); + var createNewImage = new CreateAnImage(); - await _thumbnailStorage.WriteStreamAsync( - new MemoryStream(CreateAnImage.Bytes.ToArray()), - "StorageThumbnailFilesystemTest_WriteStreamAsync"); + _thumbnailStorage.FileCopy("not_found", "StorageThumbnailFilesystemTest_FileCopy2"); - var readStream = - _thumbnailStorage.ReadStream("StorageThumbnailFilesystemTest_WriteStreamAsync"); - Assert.AreEqual(CreateAnImage.Bytes.Length, readStream.Length); - await readStream.DisposeAsync(); + var path2 = Path.Combine(createNewImage.BasePath, + "StorageThumbnailFilesystemTest_FileCopy2.jpg"); + Assert.IsFalse(File.Exists(path2)); + } + + [TestMethod] + public void FileDelete_NotExist() + { + Assert.IsFalse(_thumbnailStorage.FileDelete("NotFound")); + } + + [TestMethod] + public void ReadStream() + { + var createAnImage = new CreateAnImage(); + Assert.IsNotNull(createAnImage); + + var stream = _thumbnailStorage.ReadStream(_fileNameWithoutExtension); + Assert.AreEqual(CreateAnImage.Bytes.Length, stream.Length); + + stream.Dispose(); + } + + [TestMethod] + public void ReadStream_MaxLength() + { + var createAnImage = new CreateAnImage(); + Assert.IsNotNull(createAnImage); + + var stream = _thumbnailStorage.ReadStream(_fileNameWithoutExtension, 100); + Assert.AreEqual(100, stream.Length); + + stream.Dispose(); + } + + [TestMethod] + public void WriteStream() + { + var createNewImage = new CreateAnImage(); + + _thumbnailStorage.WriteStream(new MemoryStream(CreateAnImage.Bytes.ToArray()), + "StorageThumbnailFilesystemTest_WriteStream"); - File.Delete(Path.Combine(createNewImage.BasePath, - "StorageThumbnailFilesystemTest_WriteStreamAsync.jpg")); - } + var readStream = + _thumbnailStorage.ReadStream("StorageThumbnailFilesystemTest_WriteStream"); + Assert.AreEqual(CreateAnImage.Bytes.Length, readStream.Length); + readStream.Dispose(); - [TestMethod] - public void IsFileReady_thumbnailStorage() - { - var createNewImage = new CreateAnImage(); + File.Delete(Path.Combine(createNewImage.BasePath, + "StorageThumbnailFilesystemTest_WriteStream.jpg")); + } + + [TestMethod] + public async Task WriteStreamAsync() + { + var createNewImage = new CreateAnImage(); + + await _thumbnailStorage.WriteStreamAsync( + new MemoryStream(CreateAnImage.Bytes.ToArray()), + "StorageThumbnailFilesystemTest_WriteStreamAsync"); + + var readStream = + _thumbnailStorage.ReadStream("StorageThumbnailFilesystemTest_WriteStreamAsync"); + Assert.AreEqual(CreateAnImage.Bytes.Length, readStream.Length); + await readStream.DisposeAsync(); + + File.Delete(Path.Combine(createNewImage.BasePath, + "StorageThumbnailFilesystemTest_WriteStreamAsync.jpg")); + } + + [TestMethod] + public void IsFileReady_thumbnailStorage() + { + var createNewImage = new CreateAnImage(); - const string thumbnailId = "IsFileReady_thumbnailStorage"; - // first copy for parallel test - _thumbnailStorage.FileCopy(_fileNameWithoutExtension, thumbnailId); + const string thumbnailId = "IsFileReady_thumbnailStorage"; + // first copy for parallel test + _thumbnailStorage.FileCopy(_fileNameWithoutExtension, thumbnailId); - var stream = _thumbnailStorage.ReadStream(thumbnailId); + var stream = _thumbnailStorage.ReadStream(thumbnailId); - var result = _thumbnailStorage.IsFileReady(thumbnailId); - Assert.IsFalse(result); + var result = _thumbnailStorage.IsFileReady(thumbnailId); + Assert.IsFalse(result); - // is disposed to late (as designed) - stream.Dispose(); + // is disposed to late (as designed) + stream.Dispose(); - var result2 = _thumbnailStorage.IsFileReady(thumbnailId); - Assert.IsTrue(result2); + var result2 = _thumbnailStorage.IsFileReady(thumbnailId); + Assert.IsTrue(result2); - File.Delete(Path.Combine(createNewImage.BasePath, - $"{thumbnailId}.jpg")); + File.Delete(Path.Combine(createNewImage.BasePath, + $"{thumbnailId}.jpg")); - Assert.IsFalse(_thumbnailStorage.ExistFile(thumbnailId)); - } + Assert.IsFalse(_thumbnailStorage.ExistFile(thumbnailId)); } } diff --git a/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadTest.cs b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadTest.cs new file mode 100644 index 0000000000..2cdde112f1 --- /dev/null +++ b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadTest.cs @@ -0,0 +1,28 @@ +using System.Net.Http; +using System.Threading.Tasks; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using starsky.foundation.http.Services; +using starsky.foundation.platform.Models; +using starsky.foundation.platform.Services; +using starsky.foundation.storage.Storage; +using starsky.foundation.video.GetDependencies; +using starskytest.FakeMocks; + +namespace starskytest.starsky.foundation.video.GetDependencies; + +[TestClass] +public class FfMpegDownloadTest +{ + [TestMethod] + public async Task DownloadFfMpegTest() + { + var sut = new FfMpegDownload( + new HttpClientHelper(new HttpProvider(new HttpClient()), + new StorageHostFullPathFilesystem(new FakeIWebLogger()), new FakeIWebLogger()), + new AppSettings(), new FakeIWebLogger()); + + await sut.DownloadFfMpeg(); + + Assert.Fail(); + } +} diff --git a/starsky/starskytest/starsky.foundation.writemeta/Helpers/ExifToolDownloadTest.cs b/starsky/starskytest/starsky.foundation.writemeta/Helpers/ExifToolDownloadTest.cs index e8b42c797d..21394d99c0 100644 --- a/starsky/starskytest/starsky.foundation.writemeta/Helpers/ExifToolDownloadTest.cs +++ b/starsky/starskytest/starsky.foundation.writemeta/Helpers/ExifToolDownloadTest.cs @@ -17,698 +17,686 @@ using starskytest.FakeCreateAn; using starskytest.FakeMocks; -namespace starskytest.starsky.foundation.writemeta.Helpers +namespace starskytest.starsky.foundation.writemeta.Helpers; + +[TestClass] +public sealed class ExifToolDownloadTest { - [TestClass] - public sealed class ExifToolDownloadTest + /// + /// shasum -a 1 file.zip + /// + private static readonly string ExampleCheckSum = + "SHA256(Image-ExifTool-11.99.tar.gz)= " + CreateAnExifToolTarGz.Sha256 + "\n" + + "SHA256(exiftool-12.94_32.zip)= e0521db2115b3ee07f531ed7e3f686c57fca23b742c8f88b387aef6b682a12fe\n" + + $"SHA256(exiftool-11.99_64.zip)= {CreateAnExifToolWindows.Sha256}\n" + + "SHA256(exiftool-11.99.zip)= " + CreateAnExifToolWindows.Sha1 + "\n" + + "SHA256(ExifTool-11.99.dmg)= e0521db2115b3ee07f531ed7e3f686c57fca23b742c8f88b387aef6b682a12fe\n" + + "SHA1(Image-ExifTool-11.99.tar.gz)= " + CreateAnExifToolTarGz.Sha1 + "\n" + + "SHA1(exiftool-11.99.zip)= " + CreateAnExifToolWindows.Sha1 + "\n" + + "SHA1(ExifTool-11.99.dmg)= 3d30a4846eab278387be51b91ef4121916375ded\n" + + "MD5 (Image-ExifTool-11.99.tar.gz) = 06b97602e0d71dc413863a905708f0c9\n" + + "MD5 (exiftool-11.99.zip) = 19b53eede582e809c115b69e83dbac5e\n" + + "MD5 (ExifTool-11.99.dmg) = d063809eb7ac35e0d6c6cea6e829f75a"; + + private readonly AppSettings _appSettings; + private readonly CreateAnImage _createAnImage; + + private readonly string _exifToolUnixTempFolderPath; + + private readonly string _exifToolWindowsTempFolderPath; + private readonly StorageHostFullPathFilesystem _hostFileSystem; + private readonly IServiceScopeFactory _serviceScopeFactory; + + public ExifToolDownloadTest() { - private readonly IServiceScopeFactory _serviceScopeFactory; - private readonly AppSettings _appSettings; - private readonly StorageHostFullPathFilesystem _hostFileSystem; - - /// - /// shasum -a 1 file.zip - /// - private static readonly string ExampleCheckSum = - "SHA256(Image-ExifTool-11.99.tar.gz)= " + CreateAnExifToolTarGz.Sha256 + "\n" + - "SHA256(exiftool-12.94_32.zip)= e0521db2115b3ee07f531ed7e3f686c57fca23b742c8f88b387aef6b682a12fe\n" + - $"SHA256(exiftool-11.99_64.zip)= {CreateAnExifToolWindows.Sha256}\n" + - "SHA256(exiftool-11.99.zip)= " + CreateAnExifToolWindows.Sha1 + "\n" + - "SHA256(ExifTool-11.99.dmg)= e0521db2115b3ee07f531ed7e3f686c57fca23b742c8f88b387aef6b682a12fe\n" + - "SHA1(Image-ExifTool-11.99.tar.gz)= " + CreateAnExifToolTarGz.Sha1 + "\n" + - "SHA1(exiftool-11.99.zip)= " + CreateAnExifToolWindows.Sha1 + "\n" + - "SHA1(ExifTool-11.99.dmg)= 3d30a4846eab278387be51b91ef4121916375ded\n" + - "MD5 (Image-ExifTool-11.99.tar.gz) = 06b97602e0d71dc413863a905708f0c9\n" + - "MD5 (exiftool-11.99.zip) = 19b53eede582e809c115b69e83dbac5e\n" + - "MD5 (ExifTool-11.99.dmg) = d063809eb7ac35e0d6c6cea6e829f75a"; - - private readonly string _exifToolUnixTempFolderPath; - - private readonly string _exifToolWindowsTempFolderPath; - private readonly CreateAnImage _createAnImage; - - public ExifToolDownloadTest() + var services = new ServiceCollection(); + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + + var serviceProvider = services.BuildServiceProvider(); + _serviceScopeFactory = serviceProvider.GetRequiredService(); + _createAnImage = new CreateAnImage(); + _appSettings = new AppSettings { - var services = new ServiceCollection(); - services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); - - var serviceProvider = services.BuildServiceProvider(); - _serviceScopeFactory = serviceProvider.GetRequiredService(); - _createAnImage = new CreateAnImage(); - _appSettings = new AppSettings - { - DependenciesFolder = - Path.Combine(_createAnImage.BasePath, "starsky-tmp-dependencies-4835793"), - Verbose = true - }; - _exifToolUnixTempFolderPath = Path.Combine(_createAnImage.BasePath, - "starsky-tmp-dependencies-4835793", "exiftool-unix"); - _exifToolWindowsTempFolderPath = Path.Combine(_createAnImage.BasePath, - "starsky-tmp-dependencies-4835793", "exiftool-windows"); - - _hostFileSystem = new StorageHostFullPathFilesystem(new FakeIWebLogger()); - _hostFileSystem.CreateDirectory(_appSettings.DependenciesFolder); - } + DependenciesFolder = + Path.Combine(_createAnImage.BasePath, "starsky-tmp-dependencies-4835793"), + Verbose = true + }; + _exifToolUnixTempFolderPath = Path.Combine(_createAnImage.BasePath, + "starsky-tmp-dependencies-4835793", "exiftool-unix"); + _exifToolWindowsTempFolderPath = Path.Combine(_createAnImage.BasePath, + "starsky-tmp-dependencies-4835793", "exiftool-windows"); + + _hostFileSystem = new StorageHostFullPathFilesystem(new FakeIWebLogger()); + _hostFileSystem.CreateDirectory(_appSettings.DependenciesFolder); + } - [TestMethod] - public void GetUnixTarGzFromChecksum() - { - var result = ExifToolDownload.GetUnixTarGzFromChecksum(ExampleCheckSum); - Assert.AreEqual("Image-ExifTool-11.99.tar.gz", result); - } + [ClassCleanup] + public static void CleanExifToolDownloadTest() + { + var host = new StorageHostFullPathFilesystem(new FakeIWebLogger()); + host.FolderDelete(Path.Combine(new CreateAnImage().BasePath, + "starsky-tmp-dependencies-4835793")); + } - [TestMethod] - public void GetWindowsZipFromChecksum() - { - var result = ExifToolDownload.GetWindowsZipFromChecksum(ExampleCheckSum); - Assert.AreEqual("exiftool-11.99_64.zip", result); - } + [TestMethod] + public void GetUnixTarGzFromChecksum() + { + var result = ExifToolDownload.GetUnixTarGzFromChecksum(ExampleCheckSum); + Assert.AreEqual("Image-ExifTool-11.99.tar.gz", result); + } + + [TestMethod] + public void GetWindowsZipFromChecksum() + { + var result = ExifToolDownload.GetWindowsZipFromChecksum(ExampleCheckSum); + Assert.AreEqual("exiftool-11.99_64.zip", result); + } - [TestMethod] - public async Task DownloadCheckSums_BaseChecksumDoesExist() + [TestMethod] + public async Task DownloadCheckSums_BaseChecksumDoesExist() + { + var checkSumUrl = "https://exiftool.org/checksums.txt"; + var fakeIHttpProvider = new FakeIHttpProvider(new Dictionary { - var checkSumUrl = "https://exiftool.org/checksums.txt"; - var fakeIHttpProvider = new FakeIHttpProvider(new Dictionary - { - {checkSumUrl , new StringContent(ExampleCheckSum) }, - }); - var httpClientHelper = new HttpClientHelper(fakeIHttpProvider, _serviceScopeFactory, - new FakeIWebLogger()); - - // Happy flow - var result = - await new ExifToolDownload(httpClientHelper, _appSettings, new FakeIWebLogger()) - .DownloadCheckSums(checkSumUrl); - - Assert.AreEqual(ExampleCheckSum, result?.Value); - Assert.IsTrue(result?.Key); - } + { checkSumUrl, new StringContent(ExampleCheckSum) } + }); + var httpClientHelper = new HttpClientHelper(fakeIHttpProvider, _serviceScopeFactory, + new FakeIWebLogger()); + + // Happy flow + var result = + await new ExifToolDownload(httpClientHelper, _appSettings, new FakeIWebLogger()) + .DownloadCheckSums(checkSumUrl); + + Assert.AreEqual(ExampleCheckSum, result?.Value); + Assert.IsTrue(result?.Key); + } - [TestMethod] - public async Task DownloadCheckSums_BaseChecksumDoesNotExist() + [TestMethod] + public async Task DownloadCheckSums_BaseChecksumDoesNotExist() + { + // Main source is down, but mirror is up + var fakeIHttpProvider = new FakeIHttpProvider(new Dictionary { - // Main source is down, but mirror is up - var fakeIHttpProvider = new FakeIHttpProvider(new Dictionary { - { - "https://qdraw.nl/special/mirror/exiftool/checksums.txt", - new StringContent(ExampleCheckSum) - }, - }); - var httpClientHelper = new HttpClientHelper(fakeIHttpProvider, _serviceScopeFactory, - new FakeIWebLogger()); - - // Main source is down, but mirror is up - var result = - await new ExifToolDownload(httpClientHelper, _appSettings, new FakeIWebLogger()) - .DownloadCheckSums(); - - Assert.AreEqual(ExampleCheckSum, result?.Value); - Assert.IsTrue(result?.Key); - } + "https://qdraw.nl/special/mirror/exiftool/checksums.txt", + new StringContent(ExampleCheckSum) + } + }); + var httpClientHelper = new HttpClientHelper(fakeIHttpProvider, _serviceScopeFactory, + new FakeIWebLogger()); - [TestMethod] - public async Task DownloadCheckSums_BothServicesAreDown() - { - // Main & Mirror source are down - var fakeIHttpProvider = new FakeIHttpProvider(); - var httpClientHelper = new HttpClientHelper(fakeIHttpProvider, _serviceScopeFactory, - new FakeIWebLogger()); + // Main source is down, but mirror is up + var result = + await new ExifToolDownload(httpClientHelper, _appSettings, new FakeIWebLogger()) + .DownloadCheckSums(); + + Assert.AreEqual(ExampleCheckSum, result?.Value); + Assert.IsTrue(result?.Key); + } - // Main & Mirror source are down - var result = - await new ExifToolDownload(httpClientHelper, _appSettings, new FakeIWebLogger()) - .DownloadCheckSums(); + [TestMethod] + public async Task DownloadCheckSums_BothServicesAreDown() + { + // Main & Mirror source are down + var fakeIHttpProvider = new FakeIHttpProvider(); + var httpClientHelper = new HttpClientHelper(fakeIHttpProvider, _serviceScopeFactory, + new FakeIWebLogger()); - Assert.AreEqual(null, result); - } + // Main & Mirror source are down + var result = + await new ExifToolDownload(httpClientHelper, _appSettings, new FakeIWebLogger()) + .DownloadCheckSums(); - [TestMethod] - public async Task GetExifToolByOs() + Assert.AreEqual(null, result); + } + + [TestMethod] + public async Task GetExifToolByOs() + { + var fakeIHttpProvider = new FakeIHttpProvider(new Dictionary { - var fakeIHttpProvider = new FakeIHttpProvider(new Dictionary + { "https://exiftool.org/checksums.txt", new StringContent(ExampleCheckSum) }, { - { "https://exiftool.org/checksums.txt", new StringContent(ExampleCheckSum) }, - { - "https://exiftool.org/exiftool-11.99_64.zip", - new ByteArrayContent([.. CreateAnExifToolWindows.Bytes]) - }, - { - "https://exiftool.org/Image-ExifTool-11.99.tar.gz", - new ByteArrayContent([.. CreateAnExifToolTarGz.Bytes]) - }, - }); - var httpClientHelper = new HttpClientHelper(fakeIHttpProvider, _serviceScopeFactory, - new FakeIWebLogger()); - - var result = await new ExifToolDownload(httpClientHelper, _appSettings, - new FakeIWebLogger()).DownloadExifTool(_appSettings.IsWindows); - - Assert.IsTrue(result); - - if ( _hostFileSystem.ExistFolder(_exifToolWindowsTempFolderPath) ) + "https://exiftool.org/exiftool-11.99_64.zip", + new ByteArrayContent([.. CreateAnExifToolWindows.Bytes]) + }, { - _hostFileSystem.FolderDelete(_exifToolWindowsTempFolderPath); + "https://exiftool.org/Image-ExifTool-11.99.tar.gz", + new ByteArrayContent([.. CreateAnExifToolTarGz.Bytes]) } + }); + var httpClientHelper = new HttpClientHelper(fakeIHttpProvider, _serviceScopeFactory, + new FakeIWebLogger()); - if ( _hostFileSystem.ExistFolder(_exifToolUnixTempFolderPath) ) - { - _hostFileSystem.FolderDelete(_exifToolUnixTempFolderPath); - } + var result = await new ExifToolDownload(httpClientHelper, _appSettings, + new FakeIWebLogger()).DownloadExifTool(_appSettings.IsWindows); + + Assert.IsTrue(result); + + if ( _hostFileSystem.ExistFolder(_exifToolWindowsTempFolderPath) ) + { + _hostFileSystem.FolderDelete(_exifToolWindowsTempFolderPath); } - private async Task CreateTempFolderWithExifTool(string name = "test temp") + if ( _hostFileSystem.ExistFolder(_exifToolUnixTempFolderPath) ) { - var appSettings = new AppSettings - { - DependenciesFolder = Path.Combine(_createAnImage.BasePath, name) - }; - Directory.CreateDirectory(appSettings.DependenciesFolder); - Directory.CreateDirectory(Path.Combine(appSettings.DependenciesFolder, - "exiftool-unix")); - var stream = StringToStreamHelper.StringToStream("#!/bin/bash"); - try - { - await new StorageHostFullPathFilesystem(new FakeIWebLogger()).WriteStreamAsync( - stream, - Path.Combine(appSettings.DependenciesFolder, "exiftool-unix", "exiftool")); - } - catch ( ArgumentOutOfRangeException e ) - { - Console.WriteLine(e); - throw; - } + _hostFileSystem.FolderDelete(_exifToolUnixTempFolderPath); + } + } - return appSettings; + private async Task CreateTempFolderWithExifTool(string name = "test temp") + { + var appSettings = new AppSettings + { + DependenciesFolder = Path.Combine(_createAnImage.BasePath, name) + }; + Directory.CreateDirectory(appSettings.DependenciesFolder); + Directory.CreateDirectory(Path.Combine(appSettings.DependenciesFolder, + "exiftool-unix")); + var stream = StringToStreamHelper.StringToStream("#!/bin/bash"); + try + { + await new StorageHostFullPathFilesystem(new FakeIWebLogger()).WriteStreamAsync( + stream, + Path.Combine(appSettings.DependenciesFolder, "exiftool-unix", "exiftool")); + } + catch ( ArgumentOutOfRangeException e ) + { + Console.WriteLine(e); + throw; } - private void RemoveTempFolderWithExifTool( - string name = "test temp") + return appSettings; + } + + private void RemoveTempFolderWithExifTool( + string name = "test temp") + { + var path = Path.Combine(_createAnImage.BasePath, name); + if ( _hostFileSystem.ExistFolder(path) ) { - var path = Path.Combine(_createAnImage.BasePath, name); - if ( _hostFileSystem.ExistFolder(path) ) - { - _hostFileSystem.FolderDelete(path); - } + _hostFileSystem.FolderDelete(path); + } + } + + [TestMethod] + public async Task RunChmodOnExifToolUnixExe_TempFolderWithSpace_UnixOnly() + { + if ( _appSettings.IsWindows ) + { + Assert.Inconclusive("This test if for Unix Only"); + return; } - [TestMethod] - public async Task RunChmodOnExifToolUnixExe_TempFolderWithSpace_UnixOnly() + var fakeIHttpProvider = new FakeIHttpProvider(new Dictionary { - if ( _appSettings.IsWindows ) + { "https://exiftool.org/checksums.txt", new StringContent(ExampleCheckSum) }, + { + "https://exiftool.org/exiftool-11.99.zip", + new ByteArrayContent(CreateAnExifToolWindows.Bytes.ToArray()) + }, { - Assert.Inconclusive("This test if for Unix Only"); - return; + "https://exiftool.org/Image-ExifTool-11.99.tar.gz", + new ByteArrayContent(CreateAnExifToolTarGz.Bytes.ToArray()) } + }); + var httpClientHelper = new HttpClientHelper(fakeIHttpProvider, _serviceScopeFactory, + new FakeIWebLogger()); + var appSettings = await CreateTempFolderWithExifTool(); - var fakeIHttpProvider = new FakeIHttpProvider(new Dictionary - { - { "https://exiftool.org/checksums.txt", new StringContent(ExampleCheckSum) }, - { - "https://exiftool.org/exiftool-11.99.zip", - new ByteArrayContent(CreateAnExifToolWindows.Bytes.ToArray()) - }, - { - "https://exiftool.org/Image-ExifTool-11.99.tar.gz", - new ByteArrayContent(CreateAnExifToolTarGz.Bytes.ToArray()) - }, - }); - var httpClientHelper = new HttpClientHelper(fakeIHttpProvider, _serviceScopeFactory, - new FakeIWebLogger()); - var appSettings = await CreateTempFolderWithExifTool(); - - Console.WriteLine(appSettings.DependenciesFolder); - var exifToolDownload = - new ExifToolDownload(httpClientHelper, appSettings, new FakeIWebLogger()); - var result = await exifToolDownload.RunChmodOnExifToolUnixExe(); - Assert.IsTrue(result); - - var lsLah = await Command.Run("ls", "-lah", - Path.Combine(appSettings.DependenciesFolder, "exiftool-unix", "exiftool")).Task; - - Console.WriteLine(lsLah.StandardOutput); - - RemoveTempFolderWithExifTool(); - Assert.IsTrue(lsLah.StandardOutput.StartsWith("-rwxr-xr-x")); + Console.WriteLine(appSettings.DependenciesFolder); + var exifToolDownload = + new ExifToolDownload(httpClientHelper, appSettings, new FakeIWebLogger()); + var result = await exifToolDownload.RunChmodOnExifToolUnixExe(); + Assert.IsTrue(result); + + var lsLah = await Command.Run("ls", "-lah", + Path.Combine(appSettings.DependenciesFolder, "exiftool-unix", "exiftool")).Task; + + Console.WriteLine(lsLah.StandardOutput); + + RemoveTempFolderWithExifTool(); + Assert.IsTrue(lsLah.StandardOutput.StartsWith("-rwxr-xr-x")); + } + + [TestMethod] + public async Task RunChmodOnExifToolUnixExe_Chmod644_UnixOnly() + { + if ( _appSettings.IsWindows ) + { + Console.WriteLine("This test is for unix only"); + Assert.Inconclusive("This test if for Unix Only"); + return; } - [TestMethod] - public async Task RunChmodOnExifToolUnixExe_Chmod644_UnixOnly() + var fakeIHttpProvider = new FakeIHttpProvider(new Dictionary { - if ( _appSettings.IsWindows ) + { "https://exiftool.org/checksums.txt", new StringContent(ExampleCheckSum) }, { - Console.WriteLine("This test is for unix only"); - Assert.Inconclusive("This test if for Unix Only"); - return; + "https://exiftool.org/exiftool-11.99.zip", + new ByteArrayContent(CreateAnExifToolWindows.Bytes.ToArray()) + }, + { + "https://exiftool.org/Image-ExifTool-11.99.tar.gz", + new ByteArrayContent(CreateAnExifToolTarGz.Bytes.ToArray()) } + }); + var httpClientHelper = new HttpClientHelper(fakeIHttpProvider, _serviceScopeFactory, + new FakeIWebLogger()); + await CreateTempFolderWithExifTool("starsky-tmp-dependencies-4835793"); - var fakeIHttpProvider = new FakeIHttpProvider(new Dictionary - { - { "https://exiftool.org/checksums.txt", new StringContent(ExampleCheckSum) }, - { - "https://exiftool.org/exiftool-11.99.zip", - new ByteArrayContent(CreateAnExifToolWindows.Bytes.ToArray()) - }, - { - "https://exiftool.org/Image-ExifTool-11.99.tar.gz", - new ByteArrayContent(CreateAnExifToolTarGz.Bytes.ToArray()) - }, - }); - var httpClientHelper = new HttpClientHelper(fakeIHttpProvider, _serviceScopeFactory, - new FakeIWebLogger()); - await CreateTempFolderWithExifTool("starsky-tmp-dependencies-4835793"); - - // make NOT executable 644 - var cmdResult = await Command.Run("chmod", "644", // not executable! - Path.Combine(_exifToolUnixTempFolderPath, "exiftool")).Task; - - Assert.AreEqual(cmdResult.StandardError, string.Empty); - var exifToolDownload = - new ExifToolDownload(httpClientHelper, _appSettings, new FakeIWebLogger()); - var result = await exifToolDownload.RunChmodOnExifToolUnixExe(); - - RemoveTempFolderWithExifTool("starsky-tmp-dependencies-4835793"); - - Assert.IsTrue(result); - } + // make NOT executable 644 + var cmdResult = await Command.Run("chmod", "644", // not executable! + Path.Combine(_exifToolUnixTempFolderPath, "exiftool")).Task; - [TestMethod] - public async Task DownloadExifTool_Windows() - { - var httpClientHelper = new HttpClientHelper(new FakeIHttpProvider(), - _serviceScopeFactory, new FakeIWebLogger()); + Assert.AreEqual(cmdResult.StandardError, string.Empty); + var exifToolDownload = + new ExifToolDownload(httpClientHelper, _appSettings, new FakeIWebLogger()); + var result = await exifToolDownload.RunChmodOnExifToolUnixExe(); - var result = await new ExifToolDownload(httpClientHelper, _appSettings, - new FakeIWebLogger()).DownloadExifTool(true); + RemoveTempFolderWithExifTool("starsky-tmp-dependencies-4835793"); - Assert.IsFalse(result); - } + Assert.IsTrue(result); + } - [TestMethod] - public async Task DownloadExifTool_Skip_AddSwaggerExportExitAfter() - { - var httpClientHelper = new HttpClientHelper(new FakeIHttpProvider(), - _serviceScopeFactory, new FakeIWebLogger()); + [TestMethod] + public async Task DownloadExifTool_Windows() + { + var httpClientHelper = new HttpClientHelper(new FakeIHttpProvider(), + _serviceScopeFactory, new FakeIWebLogger()); - var appSettings = new AppSettings - { - AddSwaggerExport = true, AddSwaggerExportExitAfter = true - }; - var logger = new FakeIWebLogger(); - var result = await new ExifToolDownload(httpClientHelper, appSettings, logger) - .DownloadExifTool(true); - Assert.IsFalse(result); - Assert.IsTrue(logger.TrackedInformation[0].Item2?.Contains( - "Skipped due true of AddSwaggerExport " + - "and AddSwaggerExportExitAfter setting")); - } + var result = await new ExifToolDownload(httpClientHelper, _appSettings, + new FakeIWebLogger()).DownloadExifTool(true); - [TestMethod] - public async Task DownloadExifTool_Skip_ExiftoolSkipDownloadOnStartup() - { - var httpClientHelper = new HttpClientHelper(new FakeIHttpProvider(), - _serviceScopeFactory, new FakeIWebLogger()); - - var appSettings = new AppSettings { ExiftoolSkipDownloadOnStartup = true, }; - var logger = new FakeIWebLogger(); - var result = await new ExifToolDownload(httpClientHelper, appSettings, logger) - .DownloadExifTool(true); - Assert.IsFalse(result); - Assert.IsTrue(logger.TrackedInformation[0].Item2 - ?.Contains("Skipped due true of ExiftoolSkipDownloadOnStartup setting")); - } + Assert.IsFalse(result); + } - [TestMethod] - public async Task DownloadExifTool_Unix() + [TestMethod] + public async Task DownloadExifTool_Skip_AddSwaggerExportExitAfter() + { + var httpClientHelper = new HttpClientHelper(new FakeIHttpProvider(), + _serviceScopeFactory, new FakeIWebLogger()); + + var appSettings = new AppSettings { - var httpClientHelper = new HttpClientHelper(new FakeIHttpProvider(), - _serviceScopeFactory, new FakeIWebLogger()); - Directory.Delete(_appSettings.DependenciesFolder, true); - var result = - await new ExifToolDownload(httpClientHelper, _appSettings, new FakeIWebLogger()) - .DownloadExifTool(false); - Assert.IsFalse(result); - } + AddSwaggerExport = true, AddSwaggerExportExitAfter = true + }; + var logger = new FakeIWebLogger(); + var result = await new ExifToolDownload(httpClientHelper, appSettings, logger) + .DownloadExifTool(true); + Assert.IsFalse(result); + Assert.IsTrue(logger.TrackedInformation[0].Item2?.Contains( + "Skipped due true of AddSwaggerExport " + + "and AddSwaggerExportExitAfter setting")); + } + + [TestMethod] + public async Task DownloadExifTool_Skip_ExiftoolSkipDownloadOnStartup() + { + var httpClientHelper = new HttpClientHelper(new FakeIHttpProvider(), + _serviceScopeFactory, new FakeIWebLogger()); + + var appSettings = new AppSettings { ExiftoolSkipDownloadOnStartup = true }; + var logger = new FakeIWebLogger(); + var result = await new ExifToolDownload(httpClientHelper, appSettings, logger) + .DownloadExifTool(true); + Assert.IsFalse(result); + Assert.IsTrue(logger.TrackedInformation[0].Item2 + ?.Contains("Skipped due true of ExiftoolSkipDownloadOnStartup setting")); + } + + [TestMethod] + public async Task DownloadExifTool_Unix() + { + var httpClientHelper = new HttpClientHelper(new FakeIHttpProvider(), + _serviceScopeFactory, new FakeIWebLogger()); + Directory.Delete(_appSettings.DependenciesFolder, true); + var result = + await new ExifToolDownload(httpClientHelper, _appSettings, new FakeIWebLogger()) + .DownloadExifTool(false); + Assert.IsFalse(result); + } - [TestMethod] - public async Task DownloadExifTool_Windows_existVerbose() + [TestMethod] + public async Task DownloadExifTool_Windows_existVerbose() + { + var appSettings = new AppSettings { - var appSettings = new AppSettings - { - DependenciesFolder = AppDomain.CurrentDomain.BaseDirectory, Verbose = true - }; - Directory.CreateDirectory(appSettings.DependenciesFolder); - Directory.CreateDirectory(Path.Combine(appSettings.DependenciesFolder, - "exiftool-windows")); - - var debugString = "\n\necho \"Fake ExifTool\"\n\n\n\necho 'test'"; - var stream = StringToStreamHelper.StringToStream( - "#!/bin/bash\n" + debugString + debugString - + debugString + debugString + debugString); - await new StorageHostFullPathFilesystem(new FakeIWebLogger()).WriteStreamAsync(stream, - Path.Combine(appSettings.DependenciesFolder, "exiftool-windows", "exiftool.exe")); - - var httpClientHelper = new HttpClientHelper(new FakeIHttpProvider(), - _serviceScopeFactory, new FakeIWebLogger()); - var logger = new FakeIWebLogger(); - - var result = await new ExifToolDownload(httpClientHelper, appSettings, logger) - .DownloadExifTool(true); - - Assert.IsTrue(result); - Assert.IsTrue(logger.TrackedInformation.FirstOrDefault().Item2? - .Contains("[DownloadExifTool] " + appSettings.DependenciesFolder)); - - Directory.Delete(Path.Combine(appSettings.DependenciesFolder, "exiftool-windows"), - true); - } + DependenciesFolder = AppDomain.CurrentDomain.BaseDirectory, Verbose = true + }; + Directory.CreateDirectory(appSettings.DependenciesFolder); + Directory.CreateDirectory(Path.Combine(appSettings.DependenciesFolder, + "exiftool-windows")); + + var debugString = "\n\necho \"Fake ExifTool\"\n\n\n\necho 'test'"; + var stream = StringToStreamHelper.StringToStream( + "#!/bin/bash\n" + debugString + debugString + + debugString + debugString + debugString); + await new StorageHostFullPathFilesystem(new FakeIWebLogger()).WriteStreamAsync(stream, + Path.Combine(appSettings.DependenciesFolder, "exiftool-windows", "exiftool.exe")); + + var httpClientHelper = new HttpClientHelper(new FakeIHttpProvider(), + _serviceScopeFactory, new FakeIWebLogger()); + var logger = new FakeIWebLogger(); + + var result = await new ExifToolDownload(httpClientHelper, appSettings, logger) + .DownloadExifTool(true); + + Assert.IsTrue(result); + Assert.IsTrue(logger.TrackedInformation.FirstOrDefault().Item2? + .Contains("[DownloadExifTool] " + appSettings.DependenciesFolder)); + + Directory.Delete(Path.Combine(appSettings.DependenciesFolder, "exiftool-windows"), + true); + } - [TestMethod] - public async Task DownloadExifTool_existVerbose_UnixOnly() + [TestMethod] + public async Task DownloadExifTool_existVerbose_UnixOnly() + { + if ( _appSettings.IsWindows ) { - if ( _appSettings.IsWindows ) - { - Console.WriteLine("This test is for unix only"); - Assert.Inconclusive("This test if for Unix Only"); - return; - } + Console.WriteLine("This test is for unix only"); + Assert.Inconclusive("This test if for Unix Only"); + return; + } - var appSettings = await CreateTempFolderWithExifTool("test32"); - appSettings.Verbose = true; - var httpClientHelper = new HttpClientHelper(new FakeIHttpProvider(), - _serviceScopeFactory, new FakeIWebLogger()); - var logger = new FakeIWebLogger(); - var result = await new ExifToolDownload(httpClientHelper, appSettings, logger) - .DownloadExifTool(false, 3); + var appSettings = await CreateTempFolderWithExifTool("test32"); + appSettings.Verbose = true; + var httpClientHelper = new HttpClientHelper(new FakeIHttpProvider(), + _serviceScopeFactory, new FakeIWebLogger()); + var logger = new FakeIWebLogger(); + var result = await new ExifToolDownload(httpClientHelper, appSettings, logger) + .DownloadExifTool(false, 3); - Assert.IsTrue(result); - Assert.IsTrue(logger.TrackedInformation.FirstOrDefault().Item2? - .Contains("[DownloadExifTool] " + appSettings.DependenciesFolder)); + Assert.IsTrue(result); + Assert.IsTrue(logger.TrackedInformation.FirstOrDefault().Item2? + .Contains("[DownloadExifTool] " + appSettings.DependenciesFolder)); - Directory.Delete(appSettings.DependenciesFolder, true); - } + RemoveTempFolderWithExifTool("test32"); + } - [TestMethod] - public async Task StartDownloadForWindows_2Times() + [TestMethod] + public async Task StartDownloadForWindows_2Times() + { + var fakeIHttpProvider = new FakeIHttpProvider(new Dictionary { - var fakeIHttpProvider = new FakeIHttpProvider(new Dictionary + { "https://exiftool.org/checksums.txt", new StringContent(ExampleCheckSum) }, { - { "https://exiftool.org/checksums.txt", new StringContent(ExampleCheckSum) }, - { - "https://exiftool.org/exiftool-11.99_64.zip", - new ByteArrayContent([.. CreateAnExifToolWindows.Bytes]) - }, - { - "https://qdraw.nl/special/mirror/exiftool/exiftool-11.99_64.zip", - new ByteArrayContent([.. CreateAnExifToolWindows.Bytes]) - } - }); - - var httpClientHelper = new HttpClientHelper(fakeIHttpProvider, _serviceScopeFactory, - new FakeIWebLogger()); - var result = - await new ExifToolDownload(httpClientHelper, _appSettings, new FakeIWebLogger()) - .StartDownloadForWindows(); - - Assert.IsTrue(result); - - // And run again - // ByteArray content is Disposed afterward - var fakeIHttpProvider2 = new FakeIHttpProvider(new Dictionary + "https://exiftool.org/exiftool-11.99_64.zip", + new ByteArrayContent([.. CreateAnExifToolWindows.Bytes]) + }, { - { "https://exiftool.org/checksums.txt", new StringContent(ExampleCheckSum) }, - { - "https://exiftool.org/exiftool-11.99_64.zip", - new ByteArrayContent([.. CreateAnExifToolWindows.Bytes]) - } - }); - var httpClientHelper2 = new HttpClientHelper(fakeIHttpProvider2, _serviceScopeFactory, - new FakeIWebLogger()); - var result2 = - await new ExifToolDownload(httpClientHelper2, _appSettings, new FakeIWebLogger()) - .StartDownloadForWindows(); - Assert.IsTrue(result2); + "https://qdraw.nl/special/mirror/exiftool/exiftool-11.99_64.zip", + new ByteArrayContent([.. CreateAnExifToolWindows.Bytes]) + } + }); - _hostFileSystem.FolderDelete(_exifToolWindowsTempFolderPath); - } + var httpClientHelper = new HttpClientHelper(fakeIHttpProvider, _serviceScopeFactory, + new FakeIWebLogger()); + var result = + await new ExifToolDownload(httpClientHelper, _appSettings, new FakeIWebLogger()) + .StartDownloadForWindows(); - [TestMethod] - public async Task StartDownloadForWindows_Fail() + Assert.IsTrue(result); + + // And run again + // ByteArray content is Disposed afterward + var fakeIHttpProvider2 = new FakeIHttpProvider(new Dictionary { - var fakeIHttpProvider = new FakeIHttpProvider(new Dictionary + { "https://exiftool.org/checksums.txt", new StringContent(ExampleCheckSum) }, { - { "https://exiftool.org/checksums.txt", new StringContent(ExampleCheckSum) }, - }); + "https://exiftool.org/exiftool-11.99_64.zip", + new ByteArrayContent([.. CreateAnExifToolWindows.Bytes]) + } + }); + var httpClientHelper2 = new HttpClientHelper(fakeIHttpProvider2, _serviceScopeFactory, + new FakeIWebLogger()); + var result2 = + await new ExifToolDownload(httpClientHelper2, _appSettings, new FakeIWebLogger()) + .StartDownloadForWindows(); + Assert.IsTrue(result2); + + _hostFileSystem.FolderDelete(_exifToolWindowsTempFolderPath); + } + + [TestMethod] + public async Task StartDownloadForWindows_Fail() + { + var fakeIHttpProvider = new FakeIHttpProvider(new Dictionary + { + { "https://exiftool.org/checksums.txt", new StringContent(ExampleCheckSum) } + }); - var httpClientHelper = new HttpClientHelper(fakeIHttpProvider, _serviceScopeFactory, - new FakeIWebLogger()); - var result = await new ExifToolDownload(httpClientHelper, _appSettings, new FakeIWebLogger()) + var httpClientHelper = new HttpClientHelper(fakeIHttpProvider, _serviceScopeFactory, + new FakeIWebLogger()); + var result = + await new ExifToolDownload(httpClientHelper, _appSettings, new FakeIWebLogger()) .StartDownloadForWindows(); - - Assert.IsFalse(result); - } - [TestMethod] - public async Task StartDownloadForUnix_Fail() + Assert.IsFalse(result); + } + + [TestMethod] + public async Task StartDownloadForUnix_Fail() + { + var fakeIHttpProvider = new FakeIHttpProvider(new Dictionary + { + { "https://exiftool.org/checksums.txt", new StringContent(ExampleCheckSum) } + }); + + var logger = new FakeIWebLogger(); + var httpClientHelper = new HttpClientHelper(fakeIHttpProvider, _serviceScopeFactory, + new FakeIWebLogger()); + var result = await new ExifToolDownload(httpClientHelper, _appSettings, logger) + .StartDownloadForUnix(); + + Assert.IsFalse(result); + Assert.AreEqual(2, + logger.TrackedExceptions.Count(p => + p.Item2?.Contains("file is not downloaded") == true)); + } + + [TestMethod] + public async Task StartDownloadForUnix_2Times() + { + var fakeIHttpProvider = new FakeIHttpProvider(new Dictionary { - var fakeIHttpProvider = new FakeIHttpProvider(new Dictionary + { "https://exiftool.org/checksums.txt", new StringContent(ExampleCheckSum) }, { - { "https://exiftool.org/checksums.txt", new StringContent(ExampleCheckSum) }, - }); + "https://exiftool.org/Image-ExifTool-11.99.tar.gz", + new ByteArrayContent(CreateAnExifToolTarGz.Bytes.ToArray()) + } + }); + + _appSettings.Verbose = true; - var logger = new FakeIWebLogger(); - var httpClientHelper = new HttpClientHelper(fakeIHttpProvider, _serviceScopeFactory, - new FakeIWebLogger()); - var result = await new ExifToolDownload(httpClientHelper, _appSettings, logger) + var httpClientHelper = new HttpClientHelper(fakeIHttpProvider, _serviceScopeFactory, + new FakeIWebLogger()); + var result = + await new ExifToolDownload(httpClientHelper, _appSettings, new FakeIWebLogger()) .StartDownloadForUnix(); - - Assert.IsFalse(result); - Assert.AreEqual(2, logger.TrackedExceptions.Count(p => p.Item2?.Contains("file is not downloaded") == true)); - } + Assert.IsTrue(result); - [TestMethod] - public async Task StartDownloadForUnix_2Times() + // And run again + // ByteArray content is Disposed afterward + var fakeIHttpProvider2 = new FakeIHttpProvider(new Dictionary { - var fakeIHttpProvider = new FakeIHttpProvider(new Dictionary + { "https://exiftool.org/checksums.txt", new StringContent(ExampleCheckSum) }, { - { "https://exiftool.org/checksums.txt", new StringContent(ExampleCheckSum) }, - { - "https://exiftool.org/Image-ExifTool-11.99.tar.gz", - new ByteArrayContent(CreateAnExifToolTarGz.Bytes.ToArray()) - } - }); - - _appSettings.Verbose = true; - - var httpClientHelper = new HttpClientHelper(fakeIHttpProvider, _serviceScopeFactory, - new FakeIWebLogger()); - var result = - await new ExifToolDownload(httpClientHelper, _appSettings, new FakeIWebLogger()) - .StartDownloadForUnix(); - Assert.IsTrue(result); - - // And run again - // ByteArray content is Disposed afterward - var fakeIHttpProvider2 = new FakeIHttpProvider(new Dictionary - { - { "https://exiftool.org/checksums.txt", new StringContent(ExampleCheckSum) }, - { - "https://exiftool.org/Image-ExifTool-11.99.tar.gz", - new ByteArrayContent(CreateAnExifToolTarGz.Bytes.ToArray()) - } - }); - var httpClientHelper2 = new HttpClientHelper(fakeIHttpProvider2, _serviceScopeFactory, - new FakeIWebLogger()); - var result2 = - await new ExifToolDownload(httpClientHelper2, _appSettings, new FakeIWebLogger()) - .StartDownloadForUnix(); - Assert.IsTrue(result2); + "https://exiftool.org/Image-ExifTool-11.99.tar.gz", + new ByteArrayContent(CreateAnExifToolTarGz.Bytes.ToArray()) + } + }); + var httpClientHelper2 = new HttpClientHelper(fakeIHttpProvider2, _serviceScopeFactory, + new FakeIWebLogger()); + var result2 = + await new ExifToolDownload(httpClientHelper2, _appSettings, new FakeIWebLogger()) + .StartDownloadForUnix(); + Assert.IsTrue(result2); - _hostFileSystem.FolderDelete(_exifToolUnixTempFolderPath); - } + _hostFileSystem.FolderDelete(_exifToolUnixTempFolderPath); + } - [TestMethod] - public void CheckSha256_Good() + [TestMethod] + public async Task StartDownloadForUnix_WrongHash() + { + var fakeIHttpProvider = new FakeIHttpProvider(new Dictionary { - var fakeIStorage = new FakeIStorage(new List { "/" }, - ["/exiftool.exe"], - new List { CreateAnExifToolTarGz.Bytes.ToArray() }); - - var result2 = - new ExifToolDownload(null!, _appSettings, new FakeIWebLogger(), fakeIStorage) - .CheckSha256("/exiftool.exe", new List { CreateAnExifToolTarGz.Sha256 }); - Assert.IsTrue(result2); - } + { "https://exiftool.org/checksums.txt", new StringContent(ExampleCheckSum) }, + { "https://exiftool.org/Image-ExifTool-11.99.tar.gz", new StringContent("FAIL") } + }); + var logger = new FakeIWebLogger(); + var httpClientHelper = new HttpClientHelper(fakeIHttpProvider, _serviceScopeFactory, + new FakeIWebLogger()); + + var result = + await new ExifToolDownload(httpClientHelper, _appSettings, logger) + .StartDownloadForUnix(); - [TestMethod] - public void CheckSha1_Bad() - { - var fakeIStorage = new FakeIStorage(new List { "/" }, - ["/exiftool.exe"], - new List { CreateAnExifToolTarGz.Bytes.ToArray() }); - - var result2 = - new ExifToolDownload(null!, _appSettings, new FakeIWebLogger(), fakeIStorage) - .CheckSha256("/exiftool.exe", new List { "random_value" }); - Assert.IsFalse(result2); - } + Assert.IsFalse(result); + Assert.AreEqual(1, + logger.TrackedExceptions.Count(p => + p.Item2?.Contains("file is not downloaded") == true)); + } - [TestMethod] - public async Task StartDownloadForUnix_WrongHash() + [TestMethod] + public async Task StartDownloadForWindows_WrongHash() + { + var fakeIHttpProvider = new FakeIHttpProvider(new Dictionary { - var fakeIHttpProvider = new FakeIHttpProvider(new Dictionary - { - { "https://exiftool.org/checksums.txt", new StringContent(ExampleCheckSum) }, - { - "https://exiftool.org/Image-ExifTool-11.99.tar.gz", - new StringContent("FAIL") - } - }); - var logger = new FakeIWebLogger(); - var httpClientHelper = new HttpClientHelper(fakeIHttpProvider, _serviceScopeFactory, - new FakeIWebLogger()); - - var result = - await new ExifToolDownload(httpClientHelper, _appSettings, logger) - .StartDownloadForUnix(); - - Assert.IsFalse(result); - Assert.AreEqual(1, logger.TrackedExceptions.Count(p => p.Item2?.Contains("file is not downloaded") == true)); - } + { "https://exiftool.org/checksums.txt", new StringContent(ExampleCheckSum) }, + { "https://exiftool.org/exiftool-11.99_64.zip", new StringContent("FAIL") } + }); + var httpClientHelper = new HttpClientHelper(fakeIHttpProvider, _serviceScopeFactory, + new FakeIWebLogger()); + var logger = new FakeIWebLogger(); + var result = + await new ExifToolDownload(httpClientHelper, _appSettings, logger) + .StartDownloadForWindows(); + Assert.IsFalse(result); + Assert.IsTrue( + logger.TrackedExceptions.Exists(p => p.Item2?.Contains("Checksum for ") == true)); + } - [TestMethod] - public async Task StartDownloadForWindows_WrongHash() + [TestMethod] + public async Task DownloadForUnix_FromMirrorInsteadOfMainSource() + { + var fakeIHttpProvider = new FakeIHttpProvider(new Dictionary { - var fakeIHttpProvider = new FakeIHttpProvider(new Dictionary { - { "https://exiftool.org/checksums.txt", new StringContent(ExampleCheckSum) }, - { "https://exiftool.org/exiftool-11.99_64.zip", new StringContent("FAIL") } - }); - var httpClientHelper = new HttpClientHelper(fakeIHttpProvider, _serviceScopeFactory, - new FakeIWebLogger()); - var logger = new FakeIWebLogger(); - var result = - await new ExifToolDownload(httpClientHelper, _appSettings, logger) - .StartDownloadForWindows(); - Assert.IsFalse(result); - Assert.IsTrue(logger.TrackedExceptions.Exists(p => p.Item2?.Contains("Checksum for ") == true)); - } + "https://qdraw.nl/special/mirror/exiftool/exiftool-11.99.zip", + new StringContent("FAIL") + }, + { + "https://qdraw.nl/special/mirror/exiftool/Image-ExifTool-11.99.tar.gz", + new StringContent("FAIL") + } + }); + var logger = new FakeIWebLogger(); + var httpClientHelper = new HttpClientHelper(fakeIHttpProvider, _serviceScopeFactory, + logger); + + await new ExifToolDownload(httpClientHelper, _appSettings, logger) + .DownloadForUnix("Image-ExifTool-11.99.tar.gz", + []); + + Assert.IsTrue( + logger.TrackedExceptions.Exists(p => p.Item2?.Contains("Checksum for ") == true)); + Assert.IsTrue( + logger.TrackedExceptions.Exists(p => p.Item2?.Contains("is not valid") == true)); + } - [TestMethod] - public async Task DownloadForUnix_FromMirrorInsteadOfMainSource() + [TestMethod] + public async Task DownloadForWindows_FromMirrorInsteadOfMainSource() + { + var fakeIHttpProvider = new FakeIHttpProvider(new Dictionary { - var fakeIHttpProvider = new FakeIHttpProvider(new Dictionary { - { - "https://qdraw.nl/special/mirror/exiftool/exiftool-11.99.zip", - new StringContent("FAIL") - }, - { - "https://qdraw.nl/special/mirror/exiftool/Image-ExifTool-11.99.tar.gz", - new StringContent("FAIL") - } - }); - var logger = new FakeIWebLogger(); - var httpClientHelper = new HttpClientHelper(fakeIHttpProvider, _serviceScopeFactory, - logger); + "https://qdraw.nl/special/mirror/exiftool/exiftool-11.99_64.zip", + new StringContent("FAIL") + }, + { + "https://qdraw.nl/special/mirror/exiftool/Image-ExifTool-11.99.tar.gz", + new StringContent("FAIL") + } + }); + var httpClientHelper = new HttpClientHelper(fakeIHttpProvider, _serviceScopeFactory, + new FakeIWebLogger()); - await new ExifToolDownload(httpClientHelper, _appSettings, logger) - .DownloadForUnix("Image-ExifTool-11.99.tar.gz", - []); + var logger = new FakeIWebLogger(); + var result = await new ExifToolDownload(httpClientHelper, _appSettings, logger) + .DownloadForWindows("exiftool-11.99_64.zip", []); - Assert.IsTrue(logger.TrackedExceptions.Exists(p => p.Item2?.Contains("Checksum for ") == true)); - Assert.IsTrue(logger.TrackedExceptions.Exists(p => p.Item2?.Contains("is not valid") == true)); - } + Assert.IsFalse(result); + Assert.AreEqual(1, + logger.TrackedExceptions.Count(p => p.Item2?.Contains("Checksum for") == true)); + } - [TestMethod] - public async Task DownloadForWindows_FromMirrorInsteadOfMainSource() - { - var fakeIHttpProvider = new FakeIHttpProvider(new Dictionary - { - { - "https://qdraw.nl/special/mirror/exiftool/exiftool-11.99_64.zip", - new StringContent("FAIL") - }, - { - "https://qdraw.nl/special/mirror/exiftool/Image-ExifTool-11.99.tar.gz", - new StringContent("FAIL") - } - }); - var httpClientHelper = new HttpClientHelper(fakeIHttpProvider, _serviceScopeFactory, - new FakeIWebLogger()); - - var logger = new FakeIWebLogger(); - var result = await new ExifToolDownload(httpClientHelper, _appSettings, logger) - .DownloadForWindows("exiftool-11.99_64.zip", []); - - Assert.IsFalse(result); - Assert.AreEqual(1,logger.TrackedExceptions.Count(p => p.Item2?.Contains("Checksum for") == true)); - } + [TestMethod] + public void GetChecksumsFromTextFile_ToManyShaResults() + { + var fakeIHttpProvider = new FakeIHttpProvider(new Dictionary()); - [TestMethod] - public void GetChecksumsFromTextFile_ToManyShaResults() - { - var fakeIHttpProvider = new FakeIHttpProvider(new Dictionary()); - - const string example = "SHA256(Image-ExifTool-12.94.tar.gz)= d029485b7aff73e1c4806bbaaf87617dd98c5d2762f1d3a033e0ca926d7484e0\n" + - "SHA256(exiftool-12.94_32.zip)= e0521db2115b3ee07f531ed7e3f686c57fca23b742c8f88b387aef6b682a12fe\n" + - "SHA256(exiftool-12.94_64.zip)= 60df34ccc3440e18738304fe294c38b127eb8a88c2316abc1dbd7f634a23ee7a\n" + - "SHA256(ExifTool-12.94.pkg)= 59f96cf7c5250b609ad1c8e56cd7ddccc620b5448a3d8b3f3368f39a580a1059\n" + - "MD5 (Image-ExifTool-12.40.tar.gz) = 72b40d69cf518edebbf5b661465950e7\n" + - "MD5 (exiftool-12.40.zip) = fc834fd43d79da19fcb6461fb791b275\n" + - "MD5 (ExifTool-12.40.dmg) = b30e391a4b53564de60a72f4347cade4\n"; - - var httpClientHelper = new HttpClientHelper(fakeIHttpProvider, _serviceScopeFactory, - new FakeIWebLogger()); - - var exifToolDownload = new ExifToolDownload(httpClientHelper, new AppSettings(), - new FakeIWebLogger(), new FakeIStorage()); - var result = exifToolDownload.GetChecksumsFromTextFile(example, 2); - Assert.AreEqual(0, result.Length); - } + const string example = + "SHA256(Image-ExifTool-12.94.tar.gz)= d029485b7aff73e1c4806bbaaf87617dd98c5d2762f1d3a033e0ca926d7484e0\n" + + "SHA256(exiftool-12.94_32.zip)= e0521db2115b3ee07f531ed7e3f686c57fca23b742c8f88b387aef6b682a12fe\n" + + "SHA256(exiftool-12.94_64.zip)= 60df34ccc3440e18738304fe294c38b127eb8a88c2316abc1dbd7f634a23ee7a\n" + + "SHA256(ExifTool-12.94.pkg)= 59f96cf7c5250b609ad1c8e56cd7ddccc620b5448a3d8b3f3368f39a580a1059\n" + + "MD5 (Image-ExifTool-12.40.tar.gz) = 72b40d69cf518edebbf5b661465950e7\n" + + "MD5 (exiftool-12.40.zip) = fc834fd43d79da19fcb6461fb791b275\n" + + "MD5 (ExifTool-12.40.dmg) = b30e391a4b53564de60a72f4347cade4\n"; + + var httpClientHelper = new HttpClientHelper(fakeIHttpProvider, _serviceScopeFactory, + new FakeIWebLogger()); + + var exifToolDownload = new ExifToolDownload(httpClientHelper, new AppSettings(), + new FakeIWebLogger(), new FakeIStorage()); + var result = exifToolDownload.GetChecksumsFromTextFile(example, 2); + Assert.AreEqual(0, result.Length); + } - [TestMethod] - public void GetChecksumsFromTextFile_Good() - { - var fakeIHttpProvider = new FakeIHttpProvider(new Dictionary()); + [TestMethod] + public void GetChecksumsFromTextFile_Good() + { + var fakeIHttpProvider = new FakeIHttpProvider(new Dictionary()); - var httpClientHelper = new HttpClientHelper(fakeIHttpProvider, _serviceScopeFactory, - new FakeIWebLogger()); + var httpClientHelper = new HttpClientHelper(fakeIHttpProvider, _serviceScopeFactory, + new FakeIWebLogger()); - var exifToolDownload = new ExifToolDownload(httpClientHelper, new AppSettings(), - new FakeIWebLogger(), new FakeIStorage()); - var result = exifToolDownload.GetChecksumsFromTextFile(ExampleCheckSum); - Assert.AreEqual(4, result.Length); - } + var exifToolDownload = new ExifToolDownload(httpClientHelper, new AppSettings(), + new FakeIWebLogger(), new FakeIStorage()); + var result = exifToolDownload.GetChecksumsFromTextFile(ExampleCheckSum); + Assert.AreEqual(4, result.Length); + } - [DataTestMethod] // [Theory] - [DataRow(true)] - [DataRow(false)] - public void MoveFileIfExist_WithFolder(bool outputFolderAlreadyExists) + [DataTestMethod] // [Theory] + [DataRow(true)] + [DataRow(false)] + public void MoveFileIfExist_WithFolder(bool outputFolderAlreadyExists) + { + var storage = new FakeIStorage(); + var fakeIHttpProvider = new FakeIHttpProvider(new Dictionary()); + var httpClientHelper = new HttpClientHelper(fakeIHttpProvider, _serviceScopeFactory, + new FakeIWebLogger()); + var exifToolDownload = new ExifToolDownload(httpClientHelper, new AppSettings(), + new FakeIWebLogger(), storage); + + storage.CreateDirectory("/"); + storage.CreateDirectory("/test"); + storage.CreateDirectory("/test/test"); + storage.CreateDirectory("/test/test/test_01"); + if ( outputFolderAlreadyExists ) { - var storage = new FakeIStorage(); - var fakeIHttpProvider = new FakeIHttpProvider(new Dictionary()); - var httpClientHelper = new HttpClientHelper(fakeIHttpProvider, _serviceScopeFactory, - new FakeIWebLogger()); - var exifToolDownload = new ExifToolDownload(httpClientHelper, new AppSettings(), - new FakeIWebLogger(), storage); - - storage.CreateDirectory("/"); - storage.CreateDirectory("/test"); - storage.CreateDirectory($"/test/test"); - storage.CreateDirectory($"/test/test/test_01"); - if ( outputFolderAlreadyExists ) - { - storage.CreateDirectory("/output"); - } - - exifToolDownload.MoveFileIfExist("/", "test_01", "/", "output" ); - - Assert.IsTrue(storage.ExistFolder("/output")); + storage.CreateDirectory("/output"); } + + exifToolDownload.MoveFileIfExist("/", "test_01", "/", "output"); + + Assert.IsTrue(storage.ExistFolder("/output")); } } diff --git a/starsky/starskytest/starsky.foundation.writemeta/Services/ExifToolServiceTest.cs b/starsky/starskytest/starsky.foundation.writemeta/Services/ExifToolServiceTest.cs index 5baea9d5f3..b69d7cb53f 100644 --- a/starsky/starskytest/starsky.foundation.writemeta/Services/ExifToolServiceTest.cs +++ b/starsky/starskytest/starsky.foundation.writemeta/Services/ExifToolServiceTest.cs @@ -18,7 +18,8 @@ namespace starskytest.starsky.foundation.writemeta.Services; [TestClass] public class ExifToolServiceTest { - private readonly string _exifToolPath = string.Empty; + private static readonly string ExifToolPath = + Path.Join(new CreateAnImage().BasePath, "exiftool-service-test-tmp"); public ExifToolServiceTest() { @@ -27,32 +28,48 @@ public ExifToolServiceTest() return; } + CreateFile(); + } + + private static void CreateFile() + { var stream = StringToStreamHelper.StringToStream("#!/bin/bash\necho Fake ExifTool"); - _exifToolPath = Path.Join(new CreateAnImage().BasePath, "exiftool-tmp"); new StorageHostFullPathFilesystem(new FakeIWebLogger()).WriteStream(stream, - _exifToolPath); + ExifToolPath); var result = Command.Run("chmod", "+x", - _exifToolPath).Task.Result; + ExifToolPath).Task.Result; if ( !result.Success ) { throw new FileNotFoundException(result.StandardError); } } + [ClassCleanup] + public static void CleanExifToolServiceTest() + { + if ( File.Exists(ExifToolPath) ) + { + File.Delete(ExifToolPath); + } + } + private async Task WriteTagsAndRenameThumbnailAsyncUnixPrivateTest() { var storage = new FakeIStorage(new List { "/" }, new List { "/image.jpg" }, new List { CreateAnImage.Bytes.ToArray() }); + CreateFile(); + var service = new ExifToolService(new FakeSelectorStorage(storage), - new AppSettings { ExifToolPath = _exifToolPath }, new FakeIWebLogger()); + new AppSettings { ExifToolPath = ExifToolPath }, new FakeIWebLogger()); var result = await service.WriteTagsAndRenameThumbnailAsync( "/image.jpg", null, ""); - Assert.IsFalse(result.Key); + + CleanExifToolServiceTest(); } [TestMethod] @@ -78,7 +95,7 @@ public async Task WriteTagsAndRenameThumbnailAsync__UnixOnly() [TestMethod] public async Task WriteTagsAndRenameThumbnailAsync_TaskCanceledException__UnixOnly() { - if (new AppSettings().IsWindows) + if ( new AppSettings().IsWindows ) { Assert.Inconclusive("This test is for Unix Only"); return; @@ -93,7 +110,7 @@ public async Task WriteTagsAndRenameThumbnailAsync_TaskCanceledException__UnixOn var service = new ExifToolService( new FakeSelectorStorage(storage), - new AppSettings { ExifToolPath = _exifToolPath }, + new AppSettings { ExifToolPath = ExifToolPath }, new FakeIWebLogger() ); diff --git a/starsky/starskytest/starskytest.csproj b/starsky/starskytest/starskytest.csproj index f2a5d04135..605900cf20 100644 --- a/starsky/starskytest/starskytest.csproj +++ b/starsky/starskytest/starskytest.csproj @@ -21,13 +21,13 @@ - - - - - - - + + + + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -58,6 +58,7 @@ + @@ -151,6 +152,10 @@ PreserveNewest + + + PreserveNewest + From 4ae3e16260f9666ff1d1745fb2569c039844ae99 Mon Sep 17 00:00:00 2001 From: Dion Date: Sun, 8 Dec 2024 11:00:34 +0100 Subject: [PATCH 19/73] rename test folders && auto format --- .../Controllers/AppSettingsControllerTest.cs | 7 +- .../Services/ExportServiceTest.cs | 173 +++++++++--------- .../Services/ThumbnailCleanerTest.cs | 2 +- 3 files changed, 89 insertions(+), 93 deletions(-) diff --git a/starsky/starskytest/Controllers/AppSettingsControllerTest.cs b/starsky/starskytest/Controllers/AppSettingsControllerTest.cs index ee7bc734f4..dee9aa2d90 100644 --- a/starsky/starskytest/Controllers/AppSettingsControllerTest.cs +++ b/starsky/starskytest/Controllers/AppSettingsControllerTest.cs @@ -96,7 +96,7 @@ public async Task UpdateAppSettingsTest_IgnoreWhenEnvIsSet() new UpdateAppSettingsStatusModel { StatusCode = 403 })); controller.ControllerContext.HttpContext = new DefaultHttpContext(); await controller.UpdateAppSettings( - new AppSettingsTransferObject { StorageFolder = "test" }); + new AppSettingsTransferObject { StorageFolder = "test-update-ignore-when-env" }); Assert.AreEqual(403, controller.Response.StatusCode); } @@ -119,7 +119,8 @@ await controller.UpdateAppSettings( [TestMethod] public async Task UpdateAppSettingsTest_StorageFolder_JsonCheck() { - var storage = new FakeIStorage(new List { "test" }); + const string testFolder = "test-update-json-check"; + var storage = new FakeIStorage(new List { testFolder }); Environment.SetEnvironmentVariable("app__storageFolder", string.Empty); var appSettings = new AppSettings @@ -130,7 +131,7 @@ public async Task UpdateAppSettingsTest_StorageFolder_JsonCheck() var controller = new AppSettingsController(appSettings, new UpdateAppSettingsByPath(appSettings, new FakeSelectorStorage(storage))); await controller.UpdateAppSettings( - new AppSettingsTransferObject { Verbose = true, StorageFolder = "test" }); + new AppSettingsTransferObject { Verbose = true, StorageFolder = testFolder }); Assert.IsTrue(storage.ExistFile(appSettings.AppSettingsPath)); diff --git a/starsky/starskytest/starsky.feature.export/Services/ExportServiceTest.cs b/starsky/starskytest/starsky.feature.export/Services/ExportServiceTest.cs index 1e41b9328f..810dd602ae 100644 --- a/starsky/starskytest/starsky.feature.export/Services/ExportServiceTest.cs +++ b/starsky/starskytest/starsky.feature.export/Services/ExportServiceTest.cs @@ -16,73 +16,62 @@ public class ExportServiceTest [TestMethod] public async Task Export_Folder() { - var exportService = new ExportService(new FakeIQuery(new List + var exportService = new ExportService( + new FakeIQuery(new List { - new FileIndexItem("/test") - { - IsDirectory = true - }, - new FileIndexItem("/test/test.jpg") + new("/test") { IsDirectory = true }, new("/test/test.jpg") }), new AppSettings(), - new FakeSelectorStorage(new FakeIStorage(new List{"/test"}, new List - { - "/test/test.jpg" - })), new FakeIWebLogger(), + new FakeSelectorStorage(new FakeIStorage(new List { "/test" }, + new List { "/test/test.jpg" })), new FakeIWebLogger(), new FakeIThumbnailService()); - - var (_,fileIndexResultsList) = await exportService.PreflightAsync(new List { "/test" }.ToArray()); - + + var (_, fileIndexResultsList) = + await exportService.PreflightAsync(new List { "/test" }.ToArray()); + Assert.AreEqual(1, fileIndexResultsList.Count); } - + [TestMethod] public async Task Export_Folder_StackCollection_True() { - var exportService = new ExportService(new FakeIQuery(new List + var exportService = new ExportService( + new FakeIQuery(new List { - new FileIndexItem("/test") - { - IsDirectory = true - }, - new FileIndexItem("/test/test.jpg"), - new FileIndexItem("/test/test.dng") + new("/test") { IsDirectory = true }, + new("/test/test.jpg"), + new("/test/test.dng") }), new AppSettings(), - new FakeSelectorStorage(new FakeIStorage(new List{"/test"}, new List - { - "/test/test.jpg", - "/test/test.dng" - })), new FakeIWebLogger(), + new FakeSelectorStorage(new FakeIStorage(new List { "/test" }, + new List { "/test/test.jpg", "/test/test.dng" })), new FakeIWebLogger(), new FakeIThumbnailService()); - - var (_,fileIndexResultsList) = await exportService.PreflightAsync(new List { "/test/test.jpg" }.ToArray()); - + + var (_, fileIndexResultsList) = + await exportService.PreflightAsync(new List { "/test/test.jpg" }.ToArray()); + Assert.AreEqual(3, fileIndexResultsList.Count); Assert.AreEqual(1, fileIndexResultsList.Count(p => p.FilePath == "/test/test.jpg")); Assert.AreEqual(1, fileIndexResultsList.Count(p => p.FilePath == "/test/test.dng")); } - - + + [TestMethod] public async Task Export_Folder_StackCollection_False() { - var exportService = new ExportService(new FakeIQuery(new List + var exportService = new ExportService( + new FakeIQuery(new List { - new FileIndexItem("/test") - { - IsDirectory = true - }, - new FileIndexItem("/test/test.jpg"), - new FileIndexItem("/test/test.dng") + new("/test") { IsDirectory = true }, + new("/test/test.jpg"), + new("/test/test.dng") }), new AppSettings(), - new FakeSelectorStorage(new FakeIStorage(new List{"/test"}, new List - { - "/test/test.jpg", - "/test/test.dng" - })), new FakeIWebLogger(), + new FakeSelectorStorage(new FakeIStorage(new List { "/test" }, + new List { "/test/test.jpg", "/test/test.dng" })), new FakeIWebLogger(), new FakeIThumbnailService()); - - var (_,fileIndexResultsList) = await exportService.PreflightAsync(new List { "/test/test.jpg" }.ToArray(), false); - + + var (_, fileIndexResultsList) = + await exportService.PreflightAsync(new List { "/test/test.jpg" }.ToArray(), + false); + Assert.AreEqual(1, fileIndexResultsList.Count); Assert.AreEqual(1, fileIndexResultsList.Count(p => p.FilePath == "/test/test.jpg")); Assert.AreEqual(0, fileIndexResultsList.Count(p => p.FilePath == "/test/test.dng")); @@ -91,83 +80,89 @@ public async Task Export_Folder_StackCollection_False() [TestMethod] public async Task Export_Ignore_Deleted_FolderFile() { - var exportService = new ExportService(new FakeIQuery(new List + var exportService = new ExportService( + new FakeIQuery(new List { - new FileIndexItem("/test") - { - IsDirectory = true - }, - new FileIndexItem("/test/test.jpg") - { - Status = FileIndexItem.ExifStatus.Deleted - } + new("/test") { IsDirectory = true }, + new("/test/test.jpg") { Status = FileIndexItem.ExifStatus.Deleted } }), new AppSettings(), // file not included in storage - new FakeSelectorStorage(new FakeIStorage(new List{"/test"})), new FakeIWebLogger(), + new FakeSelectorStorage(new FakeIStorage(new List { "/test" })), + new FakeIWebLogger(), new FakeIThumbnailService()); - - var (_,fileIndexResultsList) = await exportService.PreflightAsync(new List { "/test" }.ToArray()); - + + var (_, fileIndexResultsList) = + await exportService.PreflightAsync(new List { "/test" }.ToArray()); + Assert.AreEqual(0, fileIndexResultsList.Count); } - - + [TestMethod] public async Task Export_Ignore_Deleted_Folder() { - var exportService = new ExportService(new FakeIQuery(new List + var exportService = new ExportService( + new FakeIQuery(new List { - new FileIndexItem("/test") - { - IsDirectory = true - }, - new FileIndexItem("/test/test.jpg") - { - Status = FileIndexItem.ExifStatus.Deleted - } + new("/test") { IsDirectory = true }, + new("/test/test.jpg") { Status = FileIndexItem.ExifStatus.Deleted } }), new AppSettings(), // file not included in storage - new FakeSelectorStorage(new FakeIStorage(new List{"/test"})), new FakeIWebLogger(), + new FakeSelectorStorage(new FakeIStorage(new List { "/test" })), + new FakeIWebLogger(), new FakeIThumbnailService()); - - var (_,fileIndexResultsList) = await exportService.PreflightAsync(new List { "/test/test.jpg" }.ToArray()); - - Assert.AreEqual(0, fileIndexResultsList.Count(p => p.Status == FileIndexItem.ExifStatus.Ok)); - Assert.AreEqual(1, fileIndexResultsList.Count(p => p.Status == FileIndexItem.ExifStatus.NotFoundSourceMissing)); + + var (_, fileIndexResultsList) = + await exportService.PreflightAsync(new List { "/test/test.jpg" }.ToArray()); + + Assert.AreEqual(0, + fileIndexResultsList.Count(p => p.Status == FileIndexItem.ExifStatus.Ok)); + Assert.AreEqual(1, + fileIndexResultsList.Count(p => + p.Status == FileIndexItem.ExifStatus.NotFoundSourceMissing)); } [TestMethod] public async Task ExportService_NotFoundNotInIndex() { - var exportService = new ExportService(new FakeIQuery(), new AppSettings(), new FakeSelectorStorage(), new FakeIWebLogger(), new FakeIThumbnailService()); - var (_, fileIndexResultsList) = await exportService.PreflightAsync(new List { "/test" }.ToArray()); + var exportService = new ExportService(new FakeIQuery(), new AppSettings(), + new FakeSelectorStorage(), new FakeIWebLogger(), new FakeIThumbnailService()); + var (_, fileIndexResultsList) = + await exportService.PreflightAsync(new List { "/test" }.ToArray()); Assert.AreEqual(1, fileIndexResultsList.Count); - Assert.AreEqual(FileIndexItem.ExifStatus.NotFoundNotInIndex, fileIndexResultsList[0].Status); + Assert.AreEqual(FileIndexItem.ExifStatus.NotFoundNotInIndex, + fileIndexResultsList[0].Status); } - + [TestMethod] public async Task ExportService_Thumbnail_True() { - var exportService = new ExportService(new FakeIQuery(), new AppSettings(), new FakeSelectorStorage(), new FakeIWebLogger(), new FakeIThumbnailService()); - var (zipHash, _) = await exportService.PreflightAsync(new List { "/test" }.ToArray(), false, true); + var exportService = new ExportService(new FakeIQuery(), new AppSettings(), + new FakeSelectorStorage(), new FakeIWebLogger(), new FakeIThumbnailService()); + var (zipHash, _) = + await exportService.PreflightAsync(new List { "/test" }.ToArray(), false, true); - Assert.IsTrue( zipHash.StartsWith("TN")); + Assert.IsTrue(zipHash.StartsWith("TN")); } - + [TestMethod] public async Task ExportService_Thumbnail_False() { - var exportService = new ExportService(new FakeIQuery(), new AppSettings(), new FakeSelectorStorage(), new FakeIWebLogger(), new FakeIThumbnailService()); - var (zipHash, _) = await exportService.PreflightAsync(new List { "/test" }.ToArray(), false); + var exportService = new ExportService(new FakeIQuery(), new AppSettings(), + new FakeSelectorStorage(), new FakeIWebLogger(), new FakeIThumbnailService()); + var (zipHash, _) = + await exportService.PreflightAsync(new List { "/test" }.ToArray(), false); - Assert.IsTrue( zipHash.StartsWith("SR")); + Assert.IsTrue(zipHash.StartsWith("SR")); } [TestMethod] public async Task FilePathToFileNameAsync_NotfoundIsNull() { - var exportService = new ExportService(new FakeIQuery(), new AppSettings(), new FakeSelectorStorage(), new FakeIWebLogger(), new FakeIThumbnailService()); - var fileName = await exportService.FilePathToFileNameAsync(new List{"/test/not_found.jpg"}.ToArray(), true); + var exportService = new ExportService(new FakeIQuery(), new AppSettings(), + new FakeSelectorStorage(), new FakeIWebLogger(), new FakeIThumbnailService()); + var fileName = + await exportService.FilePathToFileNameAsync( + new List { "/test/not_found.jpg" }.ToArray(), true); Assert.AreEqual(null, fileName[0]); } } diff --git a/starsky/starskytest/starsky.foundation.thumbnailgeneration/Services/ThumbnailCleanerTest.cs b/starsky/starskytest/starsky.foundation.thumbnailgeneration/Services/ThumbnailCleanerTest.cs index 68982fe7df..7d7f16ce9c 100644 --- a/starsky/starskytest/starsky.foundation.thumbnailgeneration/Services/ThumbnailCleanerTest.cs +++ b/starsky/starskytest/starsky.foundation.thumbnailgeneration/Services/ThumbnailCleanerTest.cs @@ -32,7 +32,7 @@ public ThumbnailCleanerTest() var memoryCache = provider.GetService(); var builder = new DbContextOptionsBuilder(); - builder.UseInMemoryDatabase("test"); + builder.UseInMemoryDatabase(nameof(ThumbnailCleanerTest)); var options = builder.Options; var context = new ApplicationDbContext(options); _query = new Query(context, new AppSettings(), null, null!, memoryCache); From dcc9615c854499bc9a2c9931b63ff258104949db Mon Sep 17 00:00:00 2001 From: Dion Date: Sun, 8 Dec 2024 11:15:01 +0100 Subject: [PATCH 20/73] #1833 split code --- .../GetDependencies/FFMpegDownload.cs | 66 +++++-------------- .../GetDependencies/FfmpegChmod.cs | 28 ++++++++ .../GetDependencies/FfmpegExePath.cs | 25 +++++++ .../Interfaces/IMacCodeSign.cs | 6 ++ .../GetDependencies/MacCodeSign.cs | 28 ++++++-- .../GetDependencies/FfMpegDownloadTest.cs | 8 ++- 6 files changed, 102 insertions(+), 59 deletions(-) create mode 100644 starsky/starsky.foundation.video/GetDependencies/FfmpegChmod.cs create mode 100644 starsky/starsky.foundation.video/GetDependencies/FfmpegExePath.cs create mode 100644 starsky/starsky.foundation.video/GetDependencies/Interfaces/IMacCodeSign.cs diff --git a/starsky/starsky.foundation.video/GetDependencies/FFMpegDownload.cs b/starsky/starsky.foundation.video/GetDependencies/FFMpegDownload.cs index 11ce7d6c87..1c01737cd7 100644 --- a/starsky/starsky.foundation.video/GetDependencies/FFMpegDownload.cs +++ b/starsky/starsky.foundation.video/GetDependencies/FFMpegDownload.cs @@ -1,36 +1,39 @@ -using Medallion.Shell; using starsky.foundation.http.Interfaces; +using starsky.foundation.injection; using starsky.foundation.platform.Architecture; using starsky.foundation.platform.Interfaces; using starsky.foundation.platform.Models; using starsky.foundation.storage.ArchiveFormats; using starsky.foundation.storage.Helpers; -using starsky.foundation.storage.Interfaces; using starsky.foundation.storage.Storage; using starsky.foundation.video.GetDependencies.Interfaces; using starsky.foundation.video.GetDependencies.Models; namespace starsky.foundation.video.GetDependencies; +[Service(typeof(IFfMpegDownload), InjectionLifetime = InjectionLifetime.Scoped)] public class FfMpegDownload : IFfMpegDownload { - private const string FfmpegDependenciesFolder = "ffmpeg"; private readonly AppSettings _appSettings; private readonly FfMpegDownloadIndex _downloadIndex; - private readonly IStorage _hostFileSystemStorage; + private readonly FfmpegChmod _ffmpegChmod; + private readonly FfmpegExePath _ffmpegExePath; + private readonly StorageHostFullPathFilesystem _hostFileSystemStorage; private readonly IHttpClientHelper _httpClientHelper; private readonly IWebLogger _logger; - private readonly MacCodeSign _macCodeSign; + private readonly IMacCodeSign _macCodeSign; public FfMpegDownload(IHttpClientHelper httpClientHelper, AppSettings appSettings, - IWebLogger logger) + IWebLogger logger, IMacCodeSign macCodeSign) { _httpClientHelper = httpClientHelper; _appSettings = appSettings; _hostFileSystemStorage = new StorageHostFullPathFilesystem(logger); _logger = logger; + _macCodeSign = macCodeSign; _downloadIndex = new FfMpegDownloadIndex(_httpClientHelper, _logger); - _macCodeSign = new MacCodeSign(_hostFileSystemStorage, _logger); + _ffmpegExePath = new FfmpegExePath(_appSettings); + _ffmpegChmod = new FfmpegChmod(_hostFileSystemStorage, _logger); } public async Task DownloadFfMpeg() @@ -48,9 +51,8 @@ public async Task DownloadFfMpeg() CreateDirectoryDependenciesFolderIfNotExists(); var currentArchitecture = CurrentArchitecture.GetCurrentRuntimeIdentifier(); - // var currentArchitecture = "osx-x64"; - if ( _hostFileSystemStorage.ExistFile(GetExePath(currentArchitecture)) ) + if ( _hostFileSystemStorage.ExistFile(_ffmpegExePath.GetExePath(currentArchitecture)) ) { return true; } @@ -87,7 +89,7 @@ public async Task DownloadFfMpeg() return null; } - if ( _hostFileSystemStorage.ExistFile(GetExePath(currentArchitecture)) ) + if ( _hostFileSystemStorage.ExistFile(_ffmpegExePath.GetExePath(currentArchitecture)) ) { return true; } @@ -108,10 +110,9 @@ public async Task DownloadFfMpeg() return null; } - new Zipper(_logger).ExtractZip(zipFullFilePath, - Path.Combine(_appSettings.DependenciesFolder, FfmpegDependenciesFolder)); + new Zipper(_logger).ExtractZip(zipFullFilePath, _ffmpegExePath.GetExeParentFolder()); - if ( !_hostFileSystemStorage.ExistFile(GetExePath(currentArchitecture)) ) + if ( !_hostFileSystemStorage.ExistFile(_ffmpegExePath.GetExePath(currentArchitecture)) ) { return false; } @@ -120,21 +121,10 @@ public async Task DownloadFfMpeg() return true; } - private string GetExePath(string currentArchitecture) - { - var exeFile = Path.Combine(_appSettings.DependenciesFolder, FfmpegDependenciesFolder, - "ffmpeg"); - if ( currentArchitecture is "win-x64" or "win-arm64" ) - { - exeFile += ".exe"; - } - - return exeFile; - } private async Task PrepareBeforeRunning(string currentArchitecture) { - var exeFile = GetExePath(currentArchitecture); + var exeFile = _ffmpegExePath.GetExePath(currentArchitecture); if ( !_hostFileSystemStorage.ExistFile(Path.Combine(exeFile)) ) { @@ -146,7 +136,7 @@ private async Task PrepareBeforeRunning(string currentArchitecture) return true; } - if ( !await Chmod(exeFile) ) + if ( !await _ffmpegChmod.Chmod(exeFile) ) { return false; } @@ -159,27 +149,6 @@ private async Task PrepareBeforeRunning(string currentArchitecture) return true; } - private async Task Chmod(string exeFile) - { - if ( !_hostFileSystemStorage.ExistFile("/bin/chmod") ) - { - _logger.LogError("[RunChmodOnFfmpegExe] WARNING: /bin/chmod does not exist"); - return true; - } - - // command.run does not care about the $PATH - var result = await Command.Run("/bin/chmod", "0755", exeFile).Task; - if ( result.Success ) - { - return true; - } - - _logger.LogError( - $"command failed with exit code {result.ExitCode}: {result.StandardError}"); - return false; - } - - private async Task DownloadMirror(List baseUrls, string zipFullFilePath, BinaryIndex binaryIndex, int retryInSeconds = 15) { @@ -198,8 +167,7 @@ private void CreateDirectoryDependenciesFolderIfNotExists() { foreach ( var path in new List { - _appSettings.DependenciesFolder, - Path.Combine(_appSettings.DependenciesFolder, FfmpegDependenciesFolder) + _appSettings.DependenciesFolder, _ffmpegExePath.GetExeParentFolder() } ) { if ( _hostFileSystemStorage.ExistFolder(path) ) diff --git a/starsky/starsky.foundation.video/GetDependencies/FfmpegChmod.cs b/starsky/starsky.foundation.video/GetDependencies/FfmpegChmod.cs new file mode 100644 index 0000000000..cce5fdc6ba --- /dev/null +++ b/starsky/starsky.foundation.video/GetDependencies/FfmpegChmod.cs @@ -0,0 +1,28 @@ +using Medallion.Shell; +using starsky.foundation.platform.Interfaces; +using starsky.foundation.storage.Interfaces; + +namespace starsky.foundation.video.GetDependencies; + +public class FfmpegChmod(IStorage hostFileSystemStorage, IWebLogger logger) +{ + internal async Task Chmod(string exeFile) + { + if ( !hostFileSystemStorage.ExistFile("/bin/chmod") ) + { + logger.LogError("[RunChmodOnFfmpegExe] WARNING: /bin/chmod does not exist"); + return true; + } + + // command.run does not care about the $PATH + var result = await Command.Run("/bin/chmod", "0755", exeFile).Task; + if ( result.Success ) + { + return true; + } + + logger.LogError( + $"command failed with exit code {result.ExitCode}: {result.StandardError}"); + return false; + } +} diff --git a/starsky/starsky.foundation.video/GetDependencies/FfmpegExePath.cs b/starsky/starsky.foundation.video/GetDependencies/FfmpegExePath.cs new file mode 100644 index 0000000000..3d8d577f0e --- /dev/null +++ b/starsky/starsky.foundation.video/GetDependencies/FfmpegExePath.cs @@ -0,0 +1,25 @@ +using starsky.foundation.platform.Models; + +namespace starsky.foundation.video.GetDependencies; + +public class FfmpegExePath(AppSettings appSettings) +{ + private const string FfmpegDependenciesFolder = "ffmpeg"; + + internal string GetExeParentFolder() + { + return Path.Combine(appSettings.DependenciesFolder, FfmpegDependenciesFolder); + } + + internal string GetExePath(string currentArchitecture) + { + var exeFile = Path.Combine(appSettings.DependenciesFolder, FfmpegDependenciesFolder, + "ffmpeg"); + if ( currentArchitecture is "win-x64" or "win-arm64" ) + { + exeFile += ".exe"; + } + + return exeFile; + } +} diff --git a/starsky/starsky.foundation.video/GetDependencies/Interfaces/IMacCodeSign.cs b/starsky/starsky.foundation.video/GetDependencies/Interfaces/IMacCodeSign.cs new file mode 100644 index 0000000000..218b5fe217 --- /dev/null +++ b/starsky/starsky.foundation.video/GetDependencies/Interfaces/IMacCodeSign.cs @@ -0,0 +1,6 @@ +namespace starsky.foundation.video.GetDependencies.Interfaces; + +public interface IMacCodeSign +{ + Task MacCodeSignAndXattrExecutable(string exeFile); +} diff --git a/starsky/starsky.foundation.video/GetDependencies/MacCodeSign.cs b/starsky/starsky.foundation.video/GetDependencies/MacCodeSign.cs index 035ab3b347..08bcf119fb 100644 --- a/starsky/starsky.foundation.video/GetDependencies/MacCodeSign.cs +++ b/starsky/starsky.foundation.video/GetDependencies/MacCodeSign.cs @@ -1,11 +1,24 @@ using Medallion.Shell; +using starsky.foundation.injection; using starsky.foundation.platform.Interfaces; using starsky.foundation.storage.Interfaces; +using starsky.foundation.storage.Storage; +using starsky.foundation.video.GetDependencies.Interfaces; namespace starsky.foundation.video.GetDependencies; -public class MacCodeSign(IStorage hostFileSystemStorage, IWebLogger logger) +[Service(typeof(IMacCodeSign), InjectionLifetime = InjectionLifetime.Scoped)] +public class MacCodeSign : IMacCodeSign { + private readonly IStorage _hostFileSystemStorage; + private readonly IWebLogger _logger; + + public MacCodeSign(ISelectorStorage selectorStorage, IWebLogger logger) + { + _hostFileSystemStorage = selectorStorage.Get(SelectorStorage.StorageServices.HostFilesystem); + _logger = logger; + } + public string CodeSignPath { get; set; } = "/usr/bin/codesign"; public string XattrPath { get; set; } = "/usr/bin/xattr"; @@ -22,9 +35,9 @@ public async Task MacCodeSignAndXattrExecutable(string exeFile) private async Task MacCodeSignExecutable(string exeFile) { - if ( !hostFileSystemStorage.ExistFile(CodeSignPath) ) + if ( !_hostFileSystemStorage.ExistFile(CodeSignPath) ) { - logger.LogError("[RunChmodOnFfmpegExe] WARNING: /usr/bin/codesign does not exist"); + _logger.LogError("[RunChmodOnFfmpegExe] WARNING: /usr/bin/codesign does not exist"); return true; } @@ -35,16 +48,16 @@ private async Task MacCodeSignExecutable(string exeFile) return true; } - logger.LogError( + _logger.LogError( $"codesign Command failed with exit code {result.ExitCode}: {result.StandardError}"); return false; } private async Task MacXattrExecutable(string exeFile) { - if ( !hostFileSystemStorage.ExistFile(XattrPath) ) + if ( !_hostFileSystemStorage.ExistFile(XattrPath) ) { - logger.LogError("[RunChmodOnFfmpegExe] WARNING: /usr/bin/xattr does not exist"); + _logger.LogError("[RunChmodOnFfmpegExe] WARNING: /usr/bin/xattr does not exist"); return true; } @@ -55,8 +68,9 @@ private async Task MacXattrExecutable(string exeFile) return true; } - logger.LogError( + _logger.LogError( $"xattr Command failed with exit code {result.ExitCode}: {result.StandardError}"); return false; } } + diff --git a/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadTest.cs b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadTest.cs index 2cdde112f1..3c83c1f2ac 100644 --- a/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadTest.cs +++ b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadTest.cs @@ -3,7 +3,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using starsky.foundation.http.Services; using starsky.foundation.platform.Models; -using starsky.foundation.platform.Services; using starsky.foundation.storage.Storage; using starsky.foundation.video.GetDependencies; using starskytest.FakeMocks; @@ -13,13 +12,16 @@ namespace starskytest.starsky.foundation.video.GetDependencies; [TestClass] public class FfMpegDownloadTest { - [TestMethod] + // [TestMethod] public async Task DownloadFfMpegTest() { var sut = new FfMpegDownload( new HttpClientHelper(new HttpProvider(new HttpClient()), new StorageHostFullPathFilesystem(new FakeIWebLogger()), new FakeIWebLogger()), - new AppSettings(), new FakeIWebLogger()); + new AppSettings(), new FakeIWebLogger(), + new MacCodeSign( + new FakeSelectorStorage(new StorageHostFullPathFilesystem(new FakeIWebLogger())), + new FakeIWebLogger())); await sut.DownloadFfMpeg(); From d44fae6b2667d872d982eba728451fd1cf1b7824 Mon Sep 17 00:00:00 2001 From: Dion Date: Sun, 8 Dec 2024 12:12:23 +0100 Subject: [PATCH 21/73] #1833 add tests --- .../ArchiveFormats/Zipper.cs | 3 +- .../GetDependencies/FFMpegDownload.cs | 35 ++- .../GetDependencies/FfMpegDownloadIndex.cs | 22 +- .../Interfaces/IFfMpegDownloadIndex.cs | 8 + .../Models/FfmpegBinariesIndex.cs | 13 +- .../Models/FfmpegDownloadStatus.cs | 10 + .../FakeMocks/FakeIFfMpegDownloadIndex.cs | 22 ++ .../starskytest/FakeMocks/FakeIMacCodeSign.cs | 21 ++ .../Helpers/HttpClientHelperTest.cs | 15 ++ .../FfMpegDownloadIndexTest.cs | 90 +++++++ .../GetDependencies/FfMpegDownloadTest.cs | 247 +++++++++++++++++- 11 files changed, 449 insertions(+), 37 deletions(-) create mode 100644 starsky/starsky.foundation.video/GetDependencies/Interfaces/IFfMpegDownloadIndex.cs create mode 100644 starsky/starsky.foundation.video/GetDependencies/Models/FfmpegDownloadStatus.cs create mode 100644 starsky/starskytest/FakeMocks/FakeIFfMpegDownloadIndex.cs create mode 100644 starsky/starskytest/FakeMocks/FakeIMacCodeSign.cs create mode 100644 starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadIndexTest.cs diff --git a/starsky/starsky.foundation.storage/ArchiveFormats/Zipper.cs b/starsky/starsky.foundation.storage/ArchiveFormats/Zipper.cs index d396ddf456..395dccb8ab 100644 --- a/starsky/starsky.foundation.storage/ArchiveFormats/Zipper.cs +++ b/starsky/starsky.foundation.storage/ArchiveFormats/Zipper.cs @@ -72,8 +72,7 @@ public bool ExtractZip(string zipInputFullPath, string storeZipFolderFullPath) } catch ( DirectoryNotFoundException ) { - Console.WriteLine("Directory not found: " + destinationPath); - Directory.GetParent(destinationPath)?.Create(); + Directory.GetParent(destinationPath)!.Create(); entry.ExtractToFile(destinationPath, true); } } diff --git a/starsky/starsky.foundation.video/GetDependencies/FFMpegDownload.cs b/starsky/starsky.foundation.video/GetDependencies/FFMpegDownload.cs index 1c01737cd7..6028b253cd 100644 --- a/starsky/starsky.foundation.video/GetDependencies/FFMpegDownload.cs +++ b/starsky/starsky.foundation.video/GetDependencies/FFMpegDownload.cs @@ -15,7 +15,7 @@ namespace starsky.foundation.video.GetDependencies; public class FfMpegDownload : IFfMpegDownload { private readonly AppSettings _appSettings; - private readonly FfMpegDownloadIndex _downloadIndex; + private readonly IFfMpegDownloadIndex _downloadIndex; private readonly FfmpegChmod _ffmpegChmod; private readonly FfmpegExePath _ffmpegExePath; private readonly StorageHostFullPathFilesystem _hostFileSystemStorage; @@ -24,28 +24,28 @@ public class FfMpegDownload : IFfMpegDownload private readonly IMacCodeSign _macCodeSign; public FfMpegDownload(IHttpClientHelper httpClientHelper, AppSettings appSettings, - IWebLogger logger, IMacCodeSign macCodeSign) + IWebLogger logger, IMacCodeSign macCodeSign, IFfMpegDownloadIndex downloadIndex) { _httpClientHelper = httpClientHelper; _appSettings = appSettings; _hostFileSystemStorage = new StorageHostFullPathFilesystem(logger); _logger = logger; _macCodeSign = macCodeSign; - _downloadIndex = new FfMpegDownloadIndex(_httpClientHelper, _logger); + _downloadIndex = downloadIndex; _ffmpegExePath = new FfmpegExePath(_appSettings); _ffmpegChmod = new FfmpegChmod(_hostFileSystemStorage, _logger); } - public async Task DownloadFfMpeg() + public async Task DownloadFfMpeg() { - if ( _appSettings.FfmpegSkipDownloadOnStartup == true || _appSettings is - { AddSwaggerExport: true, AddSwaggerExportExitAfter: true } ) + if ( _appSettings.FfmpegSkipDownloadOnStartup == true + || _appSettings is { AddSwaggerExport: true, AddSwaggerExportExitAfter: true } ) { var name = _appSettings.FfmpegSkipDownloadOnStartup == true ? "FFMpegSkipDownloadOnStartup" : "AddSwaggerExport and AddSwaggerExportExitAfter"; _logger.LogInformation($"[DownloadFFMpeg] Skipped due true of {name} setting"); - return false; + return FfmpegDownloadStatus.SettingsDisabled; } CreateDirectoryDependenciesFolderIfNotExists(); @@ -54,19 +54,32 @@ public async Task DownloadFfMpeg() if ( _hostFileSystemStorage.ExistFile(_ffmpegExePath.GetExePath(currentArchitecture)) ) { - return true; + return FfmpegDownloadStatus.Ok; } var container = await _downloadIndex.DownloadIndex(); + if ( !container.Success ) + { + _logger.LogError("[FfMpegDownload] Index not found"); + return FfmpegDownloadStatus.DownloadIndexFailed; + } var binaryIndexBaseUrls = GetCurrentArchitectureIndexUrls(container, currentArchitecture); - await Download(binaryIndexBaseUrls, currentArchitecture); + var download = await Download(binaryIndexBaseUrls, currentArchitecture); + if ( download is null or false ) + { + _logger.LogError("[FfMpegDownload] Binaries not found"); + return FfmpegDownloadStatus.DownloadBinariesFailed; + } - await PrepareBeforeRunning(currentArchitecture); + if ( !await PrepareBeforeRunning(currentArchitecture) ) + { + return FfmpegDownloadStatus.PrepareBeforeRunningFailed; + } - return true; + return FfmpegDownloadStatus.Ok; } private static KeyValuePair> GetCurrentArchitectureIndexUrls( diff --git a/starsky/starsky.foundation.video/GetDependencies/FfMpegDownloadIndex.cs b/starsky/starsky.foundation.video/GetDependencies/FfMpegDownloadIndex.cs index ae238e2eb1..4fde6ae746 100644 --- a/starsky/starsky.foundation.video/GetDependencies/FfMpegDownloadIndex.cs +++ b/starsky/starsky.foundation.video/GetDependencies/FfMpegDownloadIndex.cs @@ -1,9 +1,15 @@ +using System.Runtime.CompilerServices; using starsky.foundation.http.Interfaces; +using starsky.foundation.injection; using starsky.foundation.platform.Interfaces; +using starsky.foundation.video.GetDependencies.Interfaces; using starsky.foundation.video.GetDependencies.Models; +[assembly: InternalsVisibleTo("starskytest")] + namespace starsky.foundation.video.GetDependencies; +[Service(typeof(IFfMpegDownloadIndex), InjectionLifetime = InjectionLifetime.Scoped)] public class FfMpegDownloadIndex(IHttpClientHelper httpClientHelper, IWebLogger logger) { private const string QdrawMirrorDomain = "qdraw.nl/special/mirror/ffmpeg"; @@ -13,26 +19,28 @@ public class FfMpegDownloadIndex(IHttpClientHelper httpClientHelper, IWebLogger private static readonly Uri FfMpegApiBasePathMirror = new($"https://{QdrawMirrorDomain}/"); private static readonly List BaseUris = [FfMpegApiBasePath, FfMpegApiBasePathMirror]; - private readonly Uri _ffMpegApiIndex = new($"https://{NetlifyMirrorDomain}/index.json"); - private readonly Uri _ffMpegApiIndexMirror = new($"https://{QdrawMirrorDomain}/index.json"); + internal static readonly Uri FfMpegApiIndex = new($"https://{NetlifyMirrorDomain}/index.json"); + + internal static readonly Uri FfMpegApiIndexMirror = + new($"https://{QdrawMirrorDomain}/index.json"); public async Task DownloadIndex() { - var apiResult = await httpClientHelper.ReadString(_ffMpegApiIndex); + var apiResult = await httpClientHelper.ReadString(FfMpegApiIndex); if ( apiResult.Key ) { - return new FfmpegBinariesContainer(apiResult.Value, _ffMpegApiIndex, BaseUris, + return new FfmpegBinariesContainer(apiResult.Value, FfMpegApiIndex, BaseUris, true); } - apiResult = await httpClientHelper.ReadString(_ffMpegApiIndexMirror); + apiResult = await httpClientHelper.ReadString(FfMpegApiIndexMirror); if ( apiResult.Key ) { - return new FfmpegBinariesContainer(apiResult.Value, _ffMpegApiIndexMirror, + return new FfmpegBinariesContainer(apiResult.Value, FfMpegApiIndexMirror, BaseUris, true); } - logger.LogError("[FfMpegDownload] Index not found"); + logger.LogError("[FfMpegDownloadIndex] Index not found"); return new FfmpegBinariesContainer(string.Empty, null, [], false); } } diff --git a/starsky/starsky.foundation.video/GetDependencies/Interfaces/IFfMpegDownloadIndex.cs b/starsky/starsky.foundation.video/GetDependencies/Interfaces/IFfMpegDownloadIndex.cs new file mode 100644 index 0000000000..47002c2afb --- /dev/null +++ b/starsky/starsky.foundation.video/GetDependencies/Interfaces/IFfMpegDownloadIndex.cs @@ -0,0 +1,8 @@ +using starsky.foundation.video.GetDependencies.Models; + +namespace starsky.foundation.video.GetDependencies.Interfaces; + +public interface IFfMpegDownloadIndex +{ + Task DownloadIndex(); +} diff --git a/starsky/starsky.foundation.video/GetDependencies/Models/FfmpegBinariesIndex.cs b/starsky/starsky.foundation.video/GetDependencies/Models/FfmpegBinariesIndex.cs index 920e1633f1..d2419a74d1 100644 --- a/starsky/starsky.foundation.video/GetDependencies/Models/FfmpegBinariesIndex.cs +++ b/starsky/starsky.foundation.video/GetDependencies/Models/FfmpegBinariesIndex.cs @@ -5,18 +5,23 @@ namespace starsky.foundation.video.GetDependencies.Models; public class BinaryIndex { - public string Architecture { get; set; } - public string FileName { get; set; } - public string Sha256 { get; set; } + public required string Architecture { get; set; } + public required string FileName { get; set; } + public required string Sha256 { get; set; } } public class FfmpegBinariesIndex { - public List Binaries { get; set; } + public required List Binaries { get; set; } } public class FfmpegBinariesContainer { + public FfmpegBinariesContainer() + { + BaseUrls = []; + } + public FfmpegBinariesContainer(string apiResultValue, Uri? indexUrl, List baseUrls, bool success) { diff --git a/starsky/starsky.foundation.video/GetDependencies/Models/FfmpegDownloadStatus.cs b/starsky/starsky.foundation.video/GetDependencies/Models/FfmpegDownloadStatus.cs new file mode 100644 index 0000000000..1e177738bb --- /dev/null +++ b/starsky/starsky.foundation.video/GetDependencies/Models/FfmpegDownloadStatus.cs @@ -0,0 +1,10 @@ +namespace starsky.foundation.video.GetDependencies.Models; + +public enum FfmpegDownloadStatus +{ + Ok, + SettingsDisabled, + DownloadIndexFailed, + DownloadBinariesFailed, + PrepareBeforeRunningFailed +} diff --git a/starsky/starskytest/FakeMocks/FakeIFfMpegDownloadIndex.cs b/starsky/starskytest/FakeMocks/FakeIFfMpegDownloadIndex.cs new file mode 100644 index 0000000000..854d466c27 --- /dev/null +++ b/starsky/starskytest/FakeMocks/FakeIFfMpegDownloadIndex.cs @@ -0,0 +1,22 @@ +using System.Threading.Tasks; +using starsky.foundation.video.GetDependencies.Interfaces; +using starsky.foundation.video.GetDependencies.Models; + +namespace starskytest.FakeMocks; + +public class FakeIFfMpegDownloadIndex : IFfMpegDownloadIndex +{ + private readonly FfmpegBinariesContainer _ffmpegBinariesContainer; + + public FakeIFfMpegDownloadIndex(FfmpegBinariesContainer? ffmpegBinariesContainer = null) + { + _ffmpegBinariesContainer = ffmpegBinariesContainer ?? + new FfmpegBinariesContainer(string.Empty, + null, [], false); + } + + public Task DownloadIndex() + { + return Task.FromResult(_ffmpegBinariesContainer); + } +} diff --git a/starsky/starskytest/FakeMocks/FakeIMacCodeSign.cs b/starsky/starskytest/FakeMocks/FakeIMacCodeSign.cs new file mode 100644 index 0000000000..897ff6c7a3 --- /dev/null +++ b/starsky/starskytest/FakeMocks/FakeIMacCodeSign.cs @@ -0,0 +1,21 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using starsky.foundation.video.GetDependencies.Interfaces; + +namespace starskytest.FakeMocks; + +public class FakeIMacCodeSign : IMacCodeSign +{ + private readonly Dictionary _expectedResults; + + public FakeIMacCodeSign(Dictionary? expectedResults = null) + { + _expectedResults = expectedResults ?? new Dictionary(); + } + + public Task MacCodeSignAndXattrExecutable(string exeFile) + { + _expectedResults.TryGetValue(exeFile, out var result); + return Task.FromResult(result); + } +} diff --git a/starsky/starskytest/starsky.foundation.http/Helpers/HttpClientHelperTest.cs b/starsky/starskytest/starsky.foundation.http/Helpers/HttpClientHelperTest.cs index bcb1131c4a..ad489af84a 100644 --- a/starsky/starskytest/starsky.foundation.http/Helpers/HttpClientHelperTest.cs +++ b/starsky/starskytest/starsky.foundation.http/Helpers/HttpClientHelperTest.cs @@ -60,6 +60,21 @@ public async Task Download_HttpClientHelper_404NotFoundTest() Assert.IsFalse(output); } + [TestMethod] + public async Task Download_HttpClientHelper_Ok_ReadString_Ctor() + { + var fakeHttpMessageHandler = new FakeHttpMessageHandler(); + var httpClient = new HttpClient(fakeHttpMessageHandler); + var httpProvider = new HttpProvider(httpClient); + + var httpClientHelper = + new HttpClientHelper(httpProvider, new FakeIStorage(), new FakeIWebLogger()); + + var output = await httpClientHelper.ReadString("https://qdraw.nl/test"); + + Assert.IsTrue(output.Key); + } + [TestMethod] public async Task Download_HttpClientHelper_HTTP_Not_Download() { diff --git a/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadIndexTest.cs b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadIndexTest.cs new file mode 100644 index 0000000000..4122bbc518 --- /dev/null +++ b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadIndexTest.cs @@ -0,0 +1,90 @@ +using System.Collections.Generic; +using System.Text.Json; +using System.Threading.Tasks; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using starsky.foundation.platform.JsonConverter; +using starsky.foundation.video.GetDependencies; +using starsky.foundation.video.GetDependencies.Models; +using starskytest.FakeMocks; + +namespace starskytest.starsky.foundation.video.GetDependencies; + +[TestClass] +public class FfMpegDownloadIndexTest +{ + private readonly FfmpegBinariesIndex _example; + private readonly FakeIHttpClientHelper _httpClientHelperFirstSource; + private readonly FakeIHttpClientHelper _httpClientHelperSecondSource; + + private readonly FakeIStorage _storage = new(); + + public FfMpegDownloadIndexTest() + { + _example = new FfmpegBinariesIndex + { + Binaries = new List + { + new() + { + Architecture = "win-x64", + FileName = "test.zip", + Sha256 = "test-sha256" + }, + new() + { + Architecture = "osx-x64", + FileName = "test.zip", + Sha256 = "test-sha256" + }, + new() + { + Architecture = "linux-x64", + FileName = "test.zip", + Sha256 = "test-sha256" + } + } + }; + + _httpClientHelperFirstSource = + new FakeIHttpClientHelper(_storage, + new Dictionary> + { + { + FfMpegDownloadIndex.FfMpegApiIndex.ToString(), + new KeyValuePair( + true, + JsonSerializer.Serialize(_example, DefaultJsonSerializer.CamelCase)) + } + }); + + _httpClientHelperSecondSource = + new FakeIHttpClientHelper(_storage, + new Dictionary> + { + { + FfMpegDownloadIndex.FfMpegApiIndexMirror.ToString(), + new KeyValuePair(true, + JsonSerializer.Serialize(_example, DefaultJsonSerializer.CamelCase)) + } + }); + } + + [TestMethod] + [DataRow(1)] + [DataRow(2)] + public async Task FfMpegDownloadIndexTest_WithExampleData_Success(int index) + { + var ffMpegDownloadIndex = index switch + { + 1 => new FfMpegDownloadIndex(_httpClientHelperFirstSource, new FakeIWebLogger()), + 2 => new FfMpegDownloadIndex(_httpClientHelperSecondSource, new FakeIWebLogger()), + _ => null + }; + + var result = await ffMpegDownloadIndex!.DownloadIndex(); + + Assert.IsNotNull(result); + + Assert.AreEqual(_example.Binaries.Count, result.Data?.Binaries.Count); + } +} diff --git a/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadTest.cs b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadTest.cs index 3c83c1f2ac..339f7ca6b3 100644 --- a/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadTest.cs +++ b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadTest.cs @@ -1,10 +1,11 @@ -using System.Net.Http; +using System.Collections.Generic; +using System.Text.Json; using System.Threading.Tasks; using Microsoft.VisualStudio.TestTools.UnitTesting; -using starsky.foundation.http.Services; +using starsky.foundation.platform.JsonConverter; using starsky.foundation.platform.Models; -using starsky.foundation.storage.Storage; using starsky.foundation.video.GetDependencies; +using starsky.foundation.video.GetDependencies.Models; using starskytest.FakeMocks; namespace starskytest.starsky.foundation.video.GetDependencies; @@ -12,19 +13,239 @@ namespace starskytest.starsky.foundation.video.GetDependencies; [TestClass] public class FfMpegDownloadTest { + private const string DependencyFolderName = "FfMpegDownloadTest"; + private readonly FakeIHttpClientHelper _emptyHttpClientHelper; + private readonly FakeIHttpClientHelper _httpClientHelper; + + private readonly FakeIStorage _storage = new(); + + public FfMpegDownloadTest() + { + _emptyHttpClientHelper = + new FakeIHttpClientHelper(_storage, + new Dictionary>()); + + var example = new FfmpegBinariesIndex + { + Binaries = new List + { + new() + { + Architecture = "win-x64", + FileName = "test.zip", + Sha256 = "test-sha256" + }, + new() + { + Architecture = "osx-x64", + FileName = "test.zip", + Sha256 = "test-sha256" + }, + new() + { + Architecture = "linux-x64", + FileName = "test.zip", + Sha256 = "test-sha256" + } + } + }; + + _httpClientHelper = + new FakeIHttpClientHelper(_storage, + new Dictionary> + { + { + FfMpegDownloadIndex.FfMpegApiIndex.ToString(), + new KeyValuePair( + true, + JsonSerializer.Serialize(example, DefaultJsonSerializer.CamelCase)) + } + }); + } + // [TestMethod] - public async Task DownloadFfMpegTest() + // public async Task DownloadFfMpegTest() + // { + // var sut = new FfMpegDownload( + // new HttpClientHelper(new HttpProvider(new HttpClient()), + // new StorageHostFullPathFilesystem(new FakeIWebLogger()), new FakeIWebLogger()), + // new AppSettings(), new FakeIWebLogger(), + // new MacCodeSign( + // new FakeSelectorStorage(new StorageHostFullPathFilesystem(new FakeIWebLogger())), + // new FakeIWebLogger())); + // + // await sut.DownloadFfMpeg(); + // + // Assert.Fail(); + // } + + [TestMethod] + [DataRow("FfmpegSkipDownloadOnStartup")] + [DataRow("AddSwaggerExportAndAddSwaggerExportExitAfter")] + public async Task DownloadFfMpeg_ShouldSkipDueToSettings(string settingName) { - var sut = new FfMpegDownload( - new HttpClientHelper(new HttpProvider(new HttpClient()), - new StorageHostFullPathFilesystem(new FakeIWebLogger()), new FakeIWebLogger()), - new AppSettings(), new FakeIWebLogger(), - new MacCodeSign( - new FakeSelectorStorage(new StorageHostFullPathFilesystem(new FakeIWebLogger())), - new FakeIWebLogger())); + var appSettings = new AppSettings(); + switch ( settingName ) + { + case "FfmpegSkipDownloadOnStartup": + appSettings.FfmpegSkipDownloadOnStartup = true; + break; + case "AddSwaggerExportAndAddSwaggerExportExitAfter": + appSettings.AddSwaggerExport = true; + appSettings.AddSwaggerExportExitAfter = true; + break; + } + + var logger = new FakeIWebLogger(); + var macCodeSign = new FakeIMacCodeSign(); - await sut.DownloadFfMpeg(); + var ffmpegDownload = + new FfMpegDownload(_emptyHttpClientHelper, appSettings, logger, macCodeSign, + new FakeIFfMpegDownloadIndex()); - Assert.Fail(); + var result = await ffmpegDownload.DownloadFfMpeg(); + + Assert.AreEqual(FfmpegDownloadStatus.SettingsDisabled, result); + } + + [TestMethod] + public async Task DownloadFfMpeg_MissingIndex() + { + var appSettings = new AppSettings { DependenciesFolder = DependencyFolderName }; + var logger = new FakeIWebLogger(); + var macCodeSign = new FakeIMacCodeSign(); + + var ffmpegDownload = + new FfMpegDownload(_emptyHttpClientHelper, appSettings, logger, macCodeSign, + new FakeIFfMpegDownloadIndex()); + + var result = await ffmpegDownload.DownloadFfMpeg(); + + Assert.AreEqual(FfmpegDownloadStatus.DownloadIndexFailed, result); } + + [TestMethod] + public async Task DownloadFfMpeg_DownloadBinariesFailed111() + { + var appSettings = new AppSettings { DependenciesFolder = DependencyFolderName }; + var logger = new FakeIWebLogger(); + var macCodeSign = new FakeIMacCodeSign(); + + var ffmpegDownload = + new FfMpegDownload(_httpClientHelper, appSettings, logger, macCodeSign, + new FakeIFfMpegDownloadIndex(new FfmpegBinariesContainer + { + Success = true, + Data = new FfmpegBinariesIndex { Binaries = new List() } + })); + + var result = await ffmpegDownload.DownloadFfMpeg(); + + Assert.AreEqual(FfmpegDownloadStatus.DownloadBinariesFailed, result); + } + + [TestMethod] + public async Task DownloadFfMpeg_DownloadBinariesFailed() + { + var appSettings = new AppSettings { DependenciesFolder = DependencyFolderName }; + var logger = new FakeIWebLogger(); + var macCodeSign = new FakeIMacCodeSign(); + + var ffmpegDownload = + new FfMpegDownload(_httpClientHelper, appSettings, logger, macCodeSign, + new FakeIFfMpegDownloadIndex(new FfmpegBinariesContainer + { + Success = true, + Data = new FfmpegBinariesIndex { Binaries = new List() } + })); + + var result = await ffmpegDownload.DownloadFfMpeg(); + + Assert.AreEqual(FfmpegDownloadStatus.DownloadBinariesFailed, result); + } + + // [TestMethod] + // public async Task Download_ShouldReturnTrueIfFileExists() + // { + // var appSettings = new AppSettings { DependenciesFolder = "test-dependencies" }; + // var logger = new FakeIWebLogger(); + // var macCodeSign = new FakeIMacCodeSign(); + // + // var ffmpegDownload = new FfMpegDownload(_httpClientHelper, appSettings, logger, macCodeSign); + // + // var binaryIndex = new BinaryIndex { FileName = "test.zip", Sha256 = "test-sha256" }; + // var baseUrls = new List { new Uri("http://example.com/") }; + // + // var result = + // await ffmpegDownload.Download( + // new KeyValuePair>(binaryIndex, baseUrls), "win-x64"); + // + // Assert.IsTrue(result); + // } + // + // [TestMethod] + // public async Task Download_ShouldReturnNullIfBinaryIndexIsNull() + // { + // var appSettings = new AppSettings { DependenciesFolder = "test-dependencies" }; + // var logger = new FakeIWebLogger(); + // var httpClientHelper = new FakeHttpClientHelper(); + // var macCodeSign = new FakeMacCodeSign(); + // var hostFileSystemStorage = new FakeStorageHostFullPathFilesystem(logger); + // + // var ffmpegDownload = new FfMpegDownload(httpClientHelper, appSettings, logger, macCodeSign); + // + // var result = + // await ffmpegDownload.Download( + // new KeyValuePair>(null, new List()), "win-x64"); + // + // Assert.IsNull(result); + // } + // + // [TestMethod] + // public async Task PrepareBeforeRunning_ShouldReturnFalseIfFileDoesNotExist() + // { + // var appSettings = new AppSettings { DependenciesFolder = "test-dependencies" }; + // var logger = new FakeIWebLogger(); + // var httpClientHelper = new FakeHttpClientHelper(); + // var macCodeSign = new FakeMacCodeSign(); + // var hostFileSystemStorage = new FakeStorageHostFullPathFilesystem(logger); + // + // var ffmpegDownload = new FfMpegDownload(httpClientHelper, appSettings, logger, macCodeSign); + // + // var result = await ffmpegDownload.PrepareBeforeRunning("win-x64"); + // + // Assert.IsFalse(result); + // } + // + // [TestMethod] + // public async Task PrepareBeforeRunning_ShouldReturnTrueForWindows() + // { + // var appSettings = new AppSettings { DependenciesFolder = "test-dependencies" }; + // var logger = new FakeIWebLogger(); + // var httpClientHelper = new FakeHttpClientHelper(); + // var macCodeSign = new FakeMacCodeSign(); + // var hostFileSystemStorage = new FakeStorageHostFullPathFilesystem(logger); + // + // var ffmpegDownload = new FfMpegDownload(httpClientHelper, appSettings, logger, macCodeSign); + // + // var result = await ffmpegDownload.PrepareBeforeRunning("win-x64"); + // + // Assert.IsTrue(result); + // } + // + // [TestMethod] + // public async Task PrepareBeforeRunning_ShouldReturnTrueForMac() + // { + // var appSettings = new AppSettings { DependenciesFolder = "test-dependencies" }; + // var logger = new FakeIWebLogger(); + // var httpClientHelper = new FakeHttpClientHelper(); + // var macCodeSign = new FakeMacCodeSign(); + // var hostFileSystemStorage = new FakeStorageHostFullPathFilesystem(logger); + // + // var ffmpegDownload = new FfMpegDownload(httpClientHelper, appSettings, logger, macCodeSign); + // + // var result = await ffmpegDownload.PrepareBeforeRunning("osx-x64"); + // + // Assert.IsTrue(result); + // } } From 3d4da56a11e4339f406e2cd230ef3f4001194e9d Mon Sep 17 00:00:00 2001 From: Dion Date: Sun, 8 Dec 2024 13:25:33 +0100 Subject: [PATCH 22/73] #1833 fixes --- .../GetDependencies/FfMpegDownloadIndex.cs | 1 + .../GetDependencies/FfmpegExePath.cs | 3 +- .../GetDependencies/GetVersionString.cs | 18 --------- .../GetDependencies/FfMpegDownloadTest.cs | 40 +++++++++---------- 4 files changed, 23 insertions(+), 39 deletions(-) delete mode 100644 starsky/starsky.foundation.video/GetDependencies/GetVersionString.cs diff --git a/starsky/starsky.foundation.video/GetDependencies/FfMpegDownloadIndex.cs b/starsky/starsky.foundation.video/GetDependencies/FfMpegDownloadIndex.cs index 4fde6ae746..5345f41f80 100644 --- a/starsky/starsky.foundation.video/GetDependencies/FfMpegDownloadIndex.cs +++ b/starsky/starsky.foundation.video/GetDependencies/FfMpegDownloadIndex.cs @@ -11,6 +11,7 @@ namespace starsky.foundation.video.GetDependencies; [Service(typeof(IFfMpegDownloadIndex), InjectionLifetime = InjectionLifetime.Scoped)] public class FfMpegDownloadIndex(IHttpClientHelper httpClientHelper, IWebLogger logger) + : IFfMpegDownloadIndex { private const string QdrawMirrorDomain = "qdraw.nl/special/mirror/ffmpeg"; private const string NetlifyMirrorDomain = "_____starsky-dependencies.netlify.app/ffmpeg"; diff --git a/starsky/starsky.foundation.video/GetDependencies/FfmpegExePath.cs b/starsky/starsky.foundation.video/GetDependencies/FfmpegExePath.cs index 3d8d577f0e..8d0c326d51 100644 --- a/starsky/starsky.foundation.video/GetDependencies/FfmpegExePath.cs +++ b/starsky/starsky.foundation.video/GetDependencies/FfmpegExePath.cs @@ -5,6 +5,7 @@ namespace starsky.foundation.video.GetDependencies; public class FfmpegExePath(AppSettings appSettings) { private const string FfmpegDependenciesFolder = "ffmpeg"; + private const string FfmpegExecutableBaseName = "ffmpeg"; internal string GetExeParentFolder() { @@ -14,7 +15,7 @@ internal string GetExeParentFolder() internal string GetExePath(string currentArchitecture) { var exeFile = Path.Combine(appSettings.DependenciesFolder, FfmpegDependenciesFolder, - "ffmpeg"); + FfmpegExecutableBaseName); if ( currentArchitecture is "win-x64" or "win-arm64" ) { exeFile += ".exe"; diff --git a/starsky/starsky.foundation.video/GetDependencies/GetVersionString.cs b/starsky/starsky.foundation.video/GetDependencies/GetVersionString.cs deleted file mode 100644 index ed1dee42b0..0000000000 --- a/starsky/starsky.foundation.video/GetDependencies/GetVersionString.cs +++ /dev/null @@ -1,18 +0,0 @@ -using starsky.foundation.http.Interfaces; - -namespace starsky.foundation.video.GetDependencies; - -public class GetVersionString -{ - private readonly IHttpClientHelper _httpClientHelper; - - public GetVersionString(IHttpClientHelper httpClientHelper) - { - _httpClientHelper = httpClientHelper; - } - - private async Task GetApi() - { - await _httpClientHelper.ReadString(""); - } -} diff --git a/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadTest.cs b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadTest.cs index 339f7ca6b3..28cc5b7e28 100644 --- a/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadTest.cs +++ b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadTest.cs @@ -125,7 +125,7 @@ public async Task DownloadFfMpeg_MissingIndex() } [TestMethod] - public async Task DownloadFfMpeg_DownloadBinariesFailed111() + public async Task DownloadFfMpeg_DownloadBinariesFail() { var appSettings = new AppSettings { DependenciesFolder = DependencyFolderName }; var logger = new FakeIWebLogger(); @@ -143,26 +143,26 @@ public async Task DownloadFfMpeg_DownloadBinariesFailed111() Assert.AreEqual(FfmpegDownloadStatus.DownloadBinariesFailed, result); } - - [TestMethod] - public async Task DownloadFfMpeg_DownloadBinariesFailed() - { - var appSettings = new AppSettings { DependenciesFolder = DependencyFolderName }; - var logger = new FakeIWebLogger(); - var macCodeSign = new FakeIMacCodeSign(); - - var ffmpegDownload = - new FfMpegDownload(_httpClientHelper, appSettings, logger, macCodeSign, - new FakeIFfMpegDownloadIndex(new FfmpegBinariesContainer - { - Success = true, - Data = new FfmpegBinariesIndex { Binaries = new List() } - })); - var result = await ffmpegDownload.DownloadFfMpeg(); - - Assert.AreEqual(FfmpegDownloadStatus.DownloadBinariesFailed, result); - } + // [TestMethod] + // public async Task DownloadFfMpeg_DownloadBinariesFail() + // { + // var appSettings = new AppSettings { DependenciesFolder = DependencyFolderName }; + // var logger = new FakeIWebLogger(); + // var macCodeSign = new FakeIMacCodeSign(); + // + // var ffmpegDownload = + // new FfMpegDownload(_httpClientHelper, appSettings, logger, macCodeSign, + // new FakeIFfMpegDownloadIndex(new FfmpegBinariesContainer + // { + // Success = true, + // Data = new FfmpegBinariesIndex { Binaries = new List() } + // })); + // + // var result = await ffmpegDownload.DownloadFfMpeg(); + // + // Assert.AreEqual(FfmpegDownloadStatus.DownloadBinariesFailed, result); + // } // [TestMethod] // public async Task Download_ShouldReturnTrueIfFileExists() From 7dd26d869023b46b67eb2c9e0eef5818fcae734b Mon Sep 17 00:00:00 2001 From: Dion Date: Mon, 9 Dec 2024 10:36:36 +0100 Subject: [PATCH 23/73] #1833 change check --- .../starsky.foundation.storage/ArchiveFormats/ZipperTest.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/starsky/starskytest/starsky.foundation.storage/ArchiveFormats/ZipperTest.cs b/starsky/starskytest/starsky.foundation.storage/ArchiveFormats/ZipperTest.cs index 68e80df1d8..deff99d76d 100644 --- a/starsky/starskytest/starsky.foundation.storage/ArchiveFormats/ZipperTest.cs +++ b/starsky/starskytest/starsky.foundation.storage/ArchiveFormats/ZipperTest.cs @@ -61,10 +61,12 @@ public void TestExtractZipMacOs() // Assert Assert.IsNotNull(result); - + foreach ( var entry in CreateAnZipFileMacOs.Content ) { - Assert.IsTrue(hostService.ExistFile(Path.Combine(testOutputFolder, entry))); + var path = Path.Combine(testOutputFolder, entry); + Console.WriteLine(path); + Assert.IsTrue(File.Exists(path)); } hostService.FolderDelete(testOutputFolder); From 45805db263c56153e97059c26379bb012977a55a Mon Sep 17 00:00:00 2001 From: Dion Date: Mon, 9 Dec 2024 12:17:44 +0100 Subject: [PATCH 24/73] #1833 add tests --- .../GetDependencies/FfmpegChmod.cs | 2 +- .../GetDependencies/FfmpegChmodTests.cs | 103 ++++++++++++++++++ .../GetDependencies/FfmpegExePathTests.cs | 40 +++++++ 3 files changed, 144 insertions(+), 1 deletion(-) create mode 100644 starsky/starskytest/starsky.foundation.video/GetDependencies/FfmpegChmodTests.cs create mode 100644 starsky/starskytest/starsky.foundation.video/GetDependencies/FfmpegExePathTests.cs diff --git a/starsky/starsky.foundation.video/GetDependencies/FfmpegChmod.cs b/starsky/starsky.foundation.video/GetDependencies/FfmpegChmod.cs index cce5fdc6ba..3aa53cad45 100644 --- a/starsky/starsky.foundation.video/GetDependencies/FfmpegChmod.cs +++ b/starsky/starsky.foundation.video/GetDependencies/FfmpegChmod.cs @@ -11,7 +11,7 @@ internal async Task Chmod(string exeFile) if ( !hostFileSystemStorage.ExistFile("/bin/chmod") ) { logger.LogError("[RunChmodOnFfmpegExe] WARNING: /bin/chmod does not exist"); - return true; + return false; } // command.run does not care about the $PATH diff --git a/starsky/starskytest/starsky.foundation.video/GetDependencies/FfmpegChmodTests.cs b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfmpegChmodTests.cs new file mode 100644 index 0000000000..53b4eb2eb8 --- /dev/null +++ b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfmpegChmodTests.cs @@ -0,0 +1,103 @@ +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using Medallion.Shell; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using starsky.foundation.platform.Interfaces; +using starsky.foundation.platform.Models; +using starsky.foundation.storage.Helpers; +using starsky.foundation.storage.Interfaces; +using starsky.foundation.storage.Storage; +using starsky.foundation.video.GetDependencies; +using starskytest.FakeCreateAn; +using starskytest.FakeMocks; + +namespace starskytest.starsky.foundation.video.GetDependencies; + +[TestClass] +public class FfmpegChmodTests +{ + private readonly FfmpegChmod _ffmpegChmod; + private readonly FfmpegExePath _ffmpegExePath; + private readonly IStorage _hostFileSystemStorage; + private readonly bool _isWindows; + private readonly IWebLogger _logger; + private readonly string _parentFolder; + + public FfmpegChmodTests() + { + _hostFileSystemStorage = new StorageHostFullPathFilesystem(new FakeIWebLogger()); + _logger = new FakeIWebLogger(); + _ffmpegChmod = new FfmpegChmod(_hostFileSystemStorage, _logger); + + _parentFolder = Path.Combine(new CreateAnImage().BasePath, "FfmpegChmodTests"); + + _ffmpegExePath = new FfmpegExePath(new AppSettings { DependenciesFolder = _parentFolder }); + _isWindows = new AppSettings().IsWindows; + } + + private void CreateFile() + { + _hostFileSystemStorage.CreateDirectory(_ffmpegExePath.GetExeParentFolder()); + var stream = StringToStreamHelper.StringToStream("#!/bin/bash\necho Fake Ffmpeg"); + _hostFileSystemStorage.WriteStream(stream, + _ffmpegExePath.GetExePath("linux-x64")); + } + + private void DeleteFile() + { + _hostFileSystemStorage.FolderDelete(_parentFolder); + } + + [TestMethod] + public async Task Chmod_ShouldReturnFalse_WhenChmodDoesNotExist() + { + var sut = new FfmpegChmod(new FakeIStorage(), new FakeIWebLogger()); + var result = await sut.Chmod(_ffmpegExePath.GetExePath("linux-x64")); + + Assert.IsFalse(result); + } + + [TestMethod] + public async Task Chmod_ShouldReturnTrue_WhenCommandSucceeds() + { + if ( _isWindows ) + { + Assert.Inconclusive("This test is only for Unix-based systems"); + return; + } + + CreateFile(); + + var result = await _ffmpegChmod.Chmod(_ffmpegExePath.GetExePath("linux-x64")); + + var lsLah = await Command.Run("ls", "-lah", + _ffmpegExePath.GetExePath("linux-x64")).Task; + + DeleteFile(); + + Assert.IsTrue(result); + Assert.IsTrue(lsLah.StandardOutput.StartsWith("-rwxr-xr-x")); + } + + [TestMethod] + public async Task Chmod_ShouldReturnFalse_WhenCommandFails() + { + var sut = new FfmpegChmod(new FakeIStorage([], + ["/bin/chmod"]), + new FakeIWebLogger()); + + var result = await sut.Chmod("/_not_found_path/to/ffmpeg"); + Assert.IsFalse(result); + } + + [TestMethod] + public async Task Chmod_ShouldLogError_WhenCommandFails() + { + var result = await _ffmpegChmod.Chmod("/_not_found_path/to/ffmpeg"); + Assert.IsFalse(result); + + Assert.IsTrue(( ( FakeIWebLogger ) _logger ).TrackedExceptions.Any(entry => + entry.Item2?.Contains("command failed with exit code") == true)); + } +} diff --git a/starsky/starskytest/starsky.foundation.video/GetDependencies/FfmpegExePathTests.cs b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfmpegExePathTests.cs new file mode 100644 index 0000000000..dc0dd54557 --- /dev/null +++ b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfmpegExePathTests.cs @@ -0,0 +1,40 @@ +using System.IO; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using starsky.foundation.platform.Models; +using starsky.foundation.video.GetDependencies; + +namespace starskytest.starsky.foundation.video.GetDependencies; + +[TestClass] +public class FfmpegExePathTests +{ + private readonly AppSettings _appSettings; + private readonly FfmpegExePath _ffmpegExePath; + + public FfmpegExePathTests() + { + _appSettings = new AppSettings { DependenciesFolder = "test-dependencies" }; + _ffmpegExePath = new FfmpegExePath(_appSettings); + } + + [TestMethod] + public void GetExeParentFolder_ShouldReturnCorrectPath() + { + var expectedPath = Path.Combine(_appSettings.DependenciesFolder, "ffmpeg"); + var result = _ffmpegExePath.GetExeParentFolder(); + Assert.AreEqual(expectedPath, result); + } + + [TestMethod] + [DataRow("win-x64", "ffmpeg.exe")] + [DataRow("win-arm64", "ffmpeg.exe")] + [DataRow("linux-x64", "ffmpeg")] + [DataRow("osx-x64", "ffmpeg")] + public void GetExePath_ShouldReturnCorrectPath(string architecture, string expectedFileName) + { + var expectedPath = + Path.Combine(_appSettings.DependenciesFolder, "ffmpeg", expectedFileName); + var result = _ffmpegExePath.GetExePath(architecture); + Assert.AreEqual(expectedPath, result); + } +} From 46775f598a22e2592ff4ebe748c0cfeae1cb23a3 Mon Sep 17 00:00:00 2001 From: Dion Date: Mon, 9 Dec 2024 14:09:17 +0100 Subject: [PATCH 25/73] #1833 list files --- .../ArchiveFormats/ZipperTest.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/starsky/starskytest/starsky.foundation.storage/ArchiveFormats/ZipperTest.cs b/starsky/starskytest/starsky.foundation.storage/ArchiveFormats/ZipperTest.cs index deff99d76d..b61ee7afc5 100644 --- a/starsky/starskytest/starsky.foundation.storage/ArchiveFormats/ZipperTest.cs +++ b/starsky/starskytest/starsky.foundation.storage/ArchiveFormats/ZipperTest.cs @@ -62,6 +62,14 @@ public void TestExtractZipMacOs() // Assert Assert.IsNotNull(result); + Console.WriteLine("---"); + foreach ( var dir in Directory.GetFiles(testOutputFolder) ) + { + Console.WriteLine(dir); + } + + Console.WriteLine("---"); + foreach ( var entry in CreateAnZipFileMacOs.Content ) { var path = Path.Combine(testOutputFolder, entry); From 365663dee83801565c0d3fa0d0bf734bb6ce79be Mon Sep 17 00:00:00 2001 From: Dion Date: Mon, 9 Dec 2024 14:27:42 +0100 Subject: [PATCH 26/73] #1833 add create dir --- .../starsky.foundation.storage/ArchiveFormats/ZipperTest.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/starsky/starskytest/starsky.foundation.storage/ArchiveFormats/ZipperTest.cs b/starsky/starskytest/starsky.foundation.storage/ArchiveFormats/ZipperTest.cs index b61ee7afc5..6fb7e0acdc 100644 --- a/starsky/starskytest/starsky.foundation.storage/ArchiveFormats/ZipperTest.cs +++ b/starsky/starskytest/starsky.foundation.storage/ArchiveFormats/ZipperTest.cs @@ -54,7 +54,9 @@ public void TestExtractZipMacOs() Path.Combine(new CreateAnImage().BasePath, "test-folder-zip-folders-mac-os"); var hostService = new StorageHostFullPathFilesystem(new FakeIWebLogger()); + hostService.FolderDelete(testOutputFolder); + hostService.CreateDirectory(testOutputFolder); // Act var result = new Zipper(new FakeIWebLogger()).ExtractZip(zipped, testOutputFolder); @@ -62,13 +64,13 @@ public void TestExtractZipMacOs() // Assert Assert.IsNotNull(result); - Console.WriteLine("---"); + Console.WriteLine("--------------------"); foreach ( var dir in Directory.GetFiles(testOutputFolder) ) { Console.WriteLine(dir); } - Console.WriteLine("---"); + Console.WriteLine("--------------------"); foreach ( var entry in CreateAnZipFileMacOs.Content ) { From 58821f13e44a8e0c3e1f9f4bad0d11d0c5feaec0 Mon Sep 17 00:00:00 2001 From: Dion Date: Mon, 9 Dec 2024 15:07:10 +0100 Subject: [PATCH 27/73] #1833 toList --- .../FakeCreateAn/CreateAnZipFileMacOs/CreateAnZipFileMacOs.cs | 3 +-- .../starsky.foundation.storage/ArchiveFormats/ZipperTest.cs | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/starsky/starskytest/FakeCreateAn/CreateAnZipFileMacOs/CreateAnZipFileMacOs.cs b/starsky/starskytest/FakeCreateAn/CreateAnZipFileMacOs/CreateAnZipFileMacOs.cs index e9b3e364f6..dd37c7888f 100644 --- a/starsky/starskytest/FakeCreateAn/CreateAnZipFileMacOs/CreateAnZipFileMacOs.cs +++ b/starsky/starskytest/FakeCreateAn/CreateAnZipFileMacOs/CreateAnZipFileMacOs.cs @@ -21,6 +21,5 @@ public CreateAnZipFileMacOs() public string FilePath { get; set; } = string.Empty; - public static IEnumerable Content { get; set; } = - new List { "__MACOSX/._ffmpeg" }; + public static List Content { get; set; } = new() { "__MACOSX/._ffmpeg" }; } diff --git a/starsky/starskytest/starsky.foundation.storage/ArchiveFormats/ZipperTest.cs b/starsky/starskytest/starsky.foundation.storage/ArchiveFormats/ZipperTest.cs index 6fb7e0acdc..79155b0265 100644 --- a/starsky/starskytest/starsky.foundation.storage/ArchiveFormats/ZipperTest.cs +++ b/starsky/starskytest/starsky.foundation.storage/ArchiveFormats/ZipperTest.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; using System.IO.Compression; +using System.Linq; using System.Text; using Microsoft.VisualStudio.TestTools.UnitTesting; using starsky.foundation.storage.ArchiveFormats; @@ -72,9 +73,8 @@ public void TestExtractZipMacOs() Console.WriteLine("--------------------"); - foreach ( var entry in CreateAnZipFileMacOs.Content ) + foreach (var path in CreateAnZipFileMacOs.Content.Select(entry => Path.Combine(testOutputFolder, entry))) { - var path = Path.Combine(testOutputFolder, entry); Console.WriteLine(path); Assert.IsTrue(File.Exists(path)); } From c0f1b07bdc0e2993c380ab6f369deb6f0e760698 Mon Sep 17 00:00:00 2001 From: Dion Date: Mon, 9 Dec 2024 15:17:08 +0100 Subject: [PATCH 28/73] #1833 contents --- .../ArchiveFormats/ZipperTest.cs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/starsky/starskytest/starsky.foundation.storage/ArchiveFormats/ZipperTest.cs b/starsky/starskytest/starsky.foundation.storage/ArchiveFormats/ZipperTest.cs index 79155b0265..4e37875838 100644 --- a/starsky/starskytest/starsky.foundation.storage/ArchiveFormats/ZipperTest.cs +++ b/starsky/starskytest/starsky.foundation.storage/ArchiveFormats/ZipperTest.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.IO; using System.IO.Compression; -using System.Linq; using System.Text; using Microsoft.VisualStudio.TestTools.UnitTesting; using starsky.foundation.storage.ArchiveFormats; @@ -73,12 +72,20 @@ public void TestExtractZipMacOs() Console.WriteLine("--------------------"); - foreach (var path in CreateAnZipFileMacOs.Content.Select(entry => Path.Combine(testOutputFolder, entry))) + var contentsInFolder = hostService.GetAllFilesInDirectory(testOutputFolder); + + foreach ( var content in contentsInFolder ) { - Console.WriteLine(path); - Assert.IsTrue(File.Exists(path)); + Console.WriteLine(content); } + // foreach (var path in CreateAnZipFileMacOs.Content.Select(entry => Path.Combine(testOutputFolder, entry))) + // { + // Console.WriteLine(path); + // + // // Assert.IsTrue(File.Exists(path)); + // } + hostService.FolderDelete(testOutputFolder); } From 0e96ff1160fbf434d78992cf9aa3916a1dfb6ba7 Mon Sep 17 00:00:00 2001 From: Dion Date: Mon, 9 Dec 2024 15:26:05 +0100 Subject: [PATCH 29/73] #1833 move chmod to variable && add windows tests --- .../GetDependencies/FfmpegChmod.cs | 5 +-- .../GetDependencies/FfmpegChmodTests.cs | 35 +++++++++++++++++-- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/starsky/starsky.foundation.video/GetDependencies/FfmpegChmod.cs b/starsky/starsky.foundation.video/GetDependencies/FfmpegChmod.cs index 3aa53cad45..79d6ffb8e6 100644 --- a/starsky/starsky.foundation.video/GetDependencies/FfmpegChmod.cs +++ b/starsky/starsky.foundation.video/GetDependencies/FfmpegChmod.cs @@ -6,16 +6,17 @@ namespace starsky.foundation.video.GetDependencies; public class FfmpegChmod(IStorage hostFileSystemStorage, IWebLogger logger) { + public string CmdPath { get; set; } = "/bin/chmod"; internal async Task Chmod(string exeFile) { - if ( !hostFileSystemStorage.ExistFile("/bin/chmod") ) + if ( !hostFileSystemStorage.ExistFile(CmdPath) ) { logger.LogError("[RunChmodOnFfmpegExe] WARNING: /bin/chmod does not exist"); return false; } // command.run does not care about the $PATH - var result = await Command.Run("/bin/chmod", "0755", exeFile).Task; + var result = await Command.Run(CmdPath, "0755", exeFile).Task; if ( result.Success ) { return true; diff --git a/starsky/starskytest/starsky.foundation.video/GetDependencies/FfmpegChmodTests.cs b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfmpegChmodTests.cs index 53b4eb2eb8..66ec2032fc 100644 --- a/starsky/starskytest/starsky.foundation.video/GetDependencies/FfmpegChmodTests.cs +++ b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfmpegChmodTests.cs @@ -5,6 +5,7 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using starsky.foundation.platform.Interfaces; using starsky.foundation.platform.Models; +using starsky.foundation.storage.ArchiveFormats; using starsky.foundation.storage.Helpers; using starsky.foundation.storage.Interfaces; using starsky.foundation.storage.Storage; @@ -42,6 +43,12 @@ private void CreateFile() var stream = StringToStreamHelper.StringToStream("#!/bin/bash\necho Fake Ffmpeg"); _hostFileSystemStorage.WriteStream(stream, _ffmpegExePath.GetExePath("linux-x64")); + + var result = Zipper.ExtractZip([.. CreateAnExifToolWindows.Bytes]); + var (_, item) = result.FirstOrDefault(p => p.Key.Contains("exiftool")); + + _hostFileSystemStorage.WriteStream(new MemoryStream(item), + Path.Combine(_ffmpegExePath.GetExeParentFolder(), "chmod.exe")); } private void DeleteFile() @@ -59,7 +66,7 @@ public async Task Chmod_ShouldReturnFalse_WhenChmodDoesNotExist() } [TestMethod] - public async Task Chmod_ShouldReturnTrue_WhenCommandSucceeds() + public async Task Chmod_ShouldReturnTrue_WhenCommandSucceeds__UnixOnly() { if ( _isWindows ) { @@ -81,8 +88,14 @@ public async Task Chmod_ShouldReturnTrue_WhenCommandSucceeds() } [TestMethod] - public async Task Chmod_ShouldReturnFalse_WhenCommandFails() + public async Task Chmod_ShouldReturnFalse_WhenCommandFails__UnixOnly() { + if ( _isWindows ) + { + Assert.Inconclusive("This test is only for Unix-based systems"); + return; + } + var sut = new FfmpegChmod(new FakeIStorage([], ["/bin/chmod"]), new FakeIWebLogger()); @@ -91,6 +104,24 @@ public async Task Chmod_ShouldReturnFalse_WhenCommandFails() Assert.IsFalse(result); } + [TestMethod] + public async Task Chmod_ShouldReturnFalse_WhenCommandFails__WindowsOnly() + { + if ( !_isWindows ) + { + Assert.Inconclusive("This test is only for Windows systems"); + return; + } + + var path = Path.Combine(_ffmpegExePath.GetExeParentFolder(), "chmod.exe"); + var sut = new FfmpegChmod(new FakeIStorage([], + [path]), + new FakeIWebLogger()) { CmdPath = path }; + + var result = await sut.Chmod("/_not_found_path/to/ffmpeg"); + Assert.IsFalse(result); + } + [TestMethod] public async Task Chmod_ShouldLogError_WhenCommandFails() { From 4e118021c0324aa4f3b9542d465931e54ea22588 Mon Sep 17 00:00:00 2001 From: Dion van Velde Date: Mon, 9 Dec 2024 16:10:51 +0100 Subject: [PATCH 30/73] #1833 windows tests --- .../GetDependencies/FfmpegChmodTests.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/starsky/starskytest/starsky.foundation.video/GetDependencies/FfmpegChmodTests.cs b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfmpegChmodTests.cs index 66ec2032fc..f483d6c0ec 100644 --- a/starsky/starskytest/starsky.foundation.video/GetDependencies/FfmpegChmodTests.cs +++ b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfmpegChmodTests.cs @@ -105,7 +105,7 @@ public async Task Chmod_ShouldReturnFalse_WhenCommandFails__UnixOnly() } [TestMethod] - public async Task Chmod_ShouldReturnFalse_WhenCommandFails__WindowsOnly() + public async Task Chmod_ShouldReturnFalse_WhenCommandSucceed__WindowsOnly() { if ( !_isWindows ) { @@ -113,13 +113,17 @@ public async Task Chmod_ShouldReturnFalse_WhenCommandFails__WindowsOnly() return; } + CreateFile(); + var path = Path.Combine(_ffmpegExePath.GetExeParentFolder(), "chmod.exe"); var sut = new FfmpegChmod(new FakeIStorage([], [path]), new FakeIWebLogger()) { CmdPath = path }; var result = await sut.Chmod("/_not_found_path/to/ffmpeg"); - Assert.IsFalse(result); + Assert.IsTrue(result); + + DeleteFile(); } [TestMethod] From 0b0e0f4ca0aee387accdd8222ade151099f95b43 Mon Sep 17 00:00:00 2001 From: Dion Date: Mon, 9 Dec 2024 16:26:45 +0100 Subject: [PATCH 31/73] #1833 add rename --- .../ArchiveFormats/ZipperTest.cs | 25 ++++--------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/starsky/starskytest/starsky.foundation.storage/ArchiveFormats/ZipperTest.cs b/starsky/starskytest/starsky.foundation.storage/ArchiveFormats/ZipperTest.cs index 4e37875838..6e32544351 100644 --- a/starsky/starskytest/starsky.foundation.storage/ArchiveFormats/ZipperTest.cs +++ b/starsky/starskytest/starsky.foundation.storage/ArchiveFormats/ZipperTest.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; using System.IO; using System.IO.Compression; @@ -64,27 +63,13 @@ public void TestExtractZipMacOs() // Assert Assert.IsNotNull(result); - Console.WriteLine("--------------------"); - foreach ( var dir in Directory.GetFiles(testOutputFolder) ) - { - Console.WriteLine(dir); - } - - Console.WriteLine("--------------------"); + // var outputFile = Directory.GetFiles(Path.Combine(testOutputFolder, "__MACOSX"))[0]; + var outputFile = Path.Combine(testOutputFolder, CreateAnZipFileMacOs.Content[0]); - var contentsInFolder = hostService.GetAllFilesInDirectory(testOutputFolder); - - foreach ( var content in contentsInFolder ) - { - Console.WriteLine(content); - } + // WHY? rename to avoid issue to check if a file exists + File.Copy(outputFile, Path.Combine(testOutputFolder, "__ffmpeg")); - // foreach (var path in CreateAnZipFileMacOs.Content.Select(entry => Path.Combine(testOutputFolder, entry))) - // { - // Console.WriteLine(path); - // - // // Assert.IsTrue(File.Exists(path)); - // } + Assert.IsTrue(Path.Exists(Path.Combine(testOutputFolder, "__ffmpeg"))); hostService.FolderDelete(testOutputFolder); } From fcff2169dac205970e1e6c222c9a18ef72d29bbc Mon Sep 17 00:00:00 2001 From: Dion van Velde Date: Mon, 9 Dec 2024 16:27:47 +0100 Subject: [PATCH 32/73] #1833 exists instead of any --- .../GetDependencies/FfmpegChmodTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/starsky/starskytest/starsky.foundation.video/GetDependencies/FfmpegChmodTests.cs b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfmpegChmodTests.cs index f483d6c0ec..fa79f3eb8f 100644 --- a/starsky/starskytest/starsky.foundation.video/GetDependencies/FfmpegChmodTests.cs +++ b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfmpegChmodTests.cs @@ -132,7 +132,7 @@ public async Task Chmod_ShouldLogError_WhenCommandFails() var result = await _ffmpegChmod.Chmod("/_not_found_path/to/ffmpeg"); Assert.IsFalse(result); - Assert.IsTrue(( ( FakeIWebLogger ) _logger ).TrackedExceptions.Any(entry => + Assert.IsTrue(( ( FakeIWebLogger ) _logger ).TrackedExceptions.Exists(entry => entry.Item2?.Contains("command failed with exit code") == true)); } } From 777963a2d72ef94cf70ac5eedfe12ef556b6f85a Mon Sep 17 00:00:00 2001 From: Dion Date: Mon, 9 Dec 2024 16:47:25 +0100 Subject: [PATCH 33/73] #1833 path seperator --- .../starsky.foundation.storage/ArchiveFormats/ZipperTest.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/starsky/starskytest/starsky.foundation.storage/ArchiveFormats/ZipperTest.cs b/starsky/starskytest/starsky.foundation.storage/ArchiveFormats/ZipperTest.cs index 6e32544351..01a2707474 100644 --- a/starsky/starskytest/starsky.foundation.storage/ArchiveFormats/ZipperTest.cs +++ b/starsky/starskytest/starsky.foundation.storage/ArchiveFormats/ZipperTest.cs @@ -64,7 +64,8 @@ public void TestExtractZipMacOs() Assert.IsNotNull(result); // var outputFile = Directory.GetFiles(Path.Combine(testOutputFolder, "__MACOSX"))[0]; - var outputFile = Path.Combine(testOutputFolder, CreateAnZipFileMacOs.Content[0]); + var outputFile = testOutputFolder + Path.DirectorySeparatorChar + + CreateAnZipFileMacOs.Content[0]; // WHY? rename to avoid issue to check if a file exists File.Copy(outputFile, Path.Combine(testOutputFolder, "__ffmpeg")); From 08338c7727c3da84172d38d904bd81f4d6872ae6 Mon Sep 17 00:00:00 2001 From: Dion Date: Mon, 9 Dec 2024 16:59:47 +0100 Subject: [PATCH 34/73] #1833 update zip --- .../CreateAnZipFileMacOs.cs | 5 ++++- .../CreateAnZipFileMacOs/ExampleData/ffmpeg | 2 ++ .../CreateAnZipFileMacOs/macOsSubfolder.zip | Bin 288 -> 456 bytes .../ArchiveFormats/ZipperTest.cs | 6 +----- 4 files changed, 7 insertions(+), 6 deletions(-) create mode 100644 starsky/starskytest/FakeCreateAn/CreateAnZipFileMacOs/ExampleData/ffmpeg diff --git a/starsky/starskytest/FakeCreateAn/CreateAnZipFileMacOs/CreateAnZipFileMacOs.cs b/starsky/starskytest/FakeCreateAn/CreateAnZipFileMacOs/CreateAnZipFileMacOs.cs index dd37c7888f..5475bcb967 100644 --- a/starsky/starskytest/FakeCreateAn/CreateAnZipFileMacOs/CreateAnZipFileMacOs.cs +++ b/starsky/starskytest/FakeCreateAn/CreateAnZipFileMacOs/CreateAnZipFileMacOs.cs @@ -21,5 +21,8 @@ public CreateAnZipFileMacOs() public string FilePath { get; set; } = string.Empty; - public static List Content { get; set; } = new() { "__MACOSX/._ffmpeg" }; + /// + /// Skip the __MACOSX/.ffmpeg file + /// + public static List Content { get; set; } = new() { "ffmpeg", "__MACOSX/.ffmpeg" }; } diff --git a/starsky/starskytest/FakeCreateAn/CreateAnZipFileMacOs/ExampleData/ffmpeg b/starsky/starskytest/FakeCreateAn/CreateAnZipFileMacOs/ExampleData/ffmpeg new file mode 100644 index 0000000000..53510974bf --- /dev/null +++ b/starsky/starskytest/FakeCreateAn/CreateAnZipFileMacOs/ExampleData/ffmpeg @@ -0,0 +1,2 @@ +#!/bin/bash +echo Fake Ffmpeg \ No newline at end of file diff --git a/starsky/starskytest/FakeCreateAn/CreateAnZipFileMacOs/macOsSubfolder.zip b/starsky/starskytest/FakeCreateAn/CreateAnZipFileMacOs/macOsSubfolder.zip index 6ae1c74a0ad092e6e4ead76695cb19c7ae5b06ec..1f96e0abae04fd7a011c0fe1b0ba332737156316 100644 GIT binary patch delta 197 zcmZ3$bb@)p+9+lgE(Q>|)z%ql#v3$22FM0sHXxanmRpdT9vZ^QzU`kx7mjm-!Mv{R|91 hlNgpXt_G4Y+gKsCq1hDR&B_K+&jf@Z)$AaR3;?aVD0=_^ delta 31 gcmX@Xynt!K+R2=Z@gl5j3_!pLgz-RnHHgCi0Bwr|(f|Me diff --git a/starsky/starskytest/starsky.foundation.storage/ArchiveFormats/ZipperTest.cs b/starsky/starskytest/starsky.foundation.storage/ArchiveFormats/ZipperTest.cs index 01a2707474..2a5bfed8a0 100644 --- a/starsky/starskytest/starsky.foundation.storage/ArchiveFormats/ZipperTest.cs +++ b/starsky/starskytest/starsky.foundation.storage/ArchiveFormats/ZipperTest.cs @@ -63,14 +63,10 @@ public void TestExtractZipMacOs() // Assert Assert.IsNotNull(result); - // var outputFile = Directory.GetFiles(Path.Combine(testOutputFolder, "__MACOSX"))[0]; var outputFile = testOutputFolder + Path.DirectorySeparatorChar + CreateAnZipFileMacOs.Content[0]; - // WHY? rename to avoid issue to check if a file exists - File.Copy(outputFile, Path.Combine(testOutputFolder, "__ffmpeg")); - - Assert.IsTrue(Path.Exists(Path.Combine(testOutputFolder, "__ffmpeg"))); + Assert.IsTrue(Path.Exists(outputFile)); hostService.FolderDelete(testOutputFolder); } From cc3d0c3e62a13c490bc4bf55416ffc7e0b222cdc Mon Sep 17 00:00:00 2001 From: Dion Date: Mon, 9 Dec 2024 18:48:53 +0100 Subject: [PATCH 35/73] #1833 debug --- .../ArchiveFormats/ZipperTest.cs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/starsky/starskytest/starsky.foundation.storage/ArchiveFormats/ZipperTest.cs b/starsky/starskytest/starsky.foundation.storage/ArchiveFormats/ZipperTest.cs index 2a5bfed8a0..83a9b48136 100644 --- a/starsky/starskytest/starsky.foundation.storage/ArchiveFormats/ZipperTest.cs +++ b/starsky/starskytest/starsky.foundation.storage/ArchiveFormats/ZipperTest.cs @@ -1,6 +1,8 @@ +using System; using System.Collections.Generic; using System.IO; using System.IO.Compression; +using System.Linq; using System.Text; using Microsoft.VisualStudio.TestTools.UnitTesting; using starsky.foundation.storage.ArchiveFormats; @@ -58,14 +60,21 @@ public void TestExtractZipMacOs() hostService.CreateDirectory(testOutputFolder); // Act - var result = new Zipper(new FakeIWebLogger()).ExtractZip(zipped, testOutputFolder); + var result = new Zipper(new FakeIWebLogger()).ExtractZip(zipped, + testOutputFolder); // Assert - Assert.IsNotNull(result); + Assert.IsTrue(result); var outputFile = testOutputFolder + Path.DirectorySeparatorChar + CreateAnZipFileMacOs.Content[0]; + Console.WriteLine("Output file:"); + Console.WriteLine(outputFile); + + Console.WriteLine("List content:"); + Console.WriteLine(hostService.GetAllFilesInDirectory(testOutputFolder).ToList()[0]); + Assert.IsTrue(Path.Exists(outputFile)); hostService.FolderDelete(testOutputFolder); From 5ccd6f2aa1908057dc07fe55d254bcab92afff57 Mon Sep 17 00:00:00 2001 From: Dion Date: Mon, 9 Dec 2024 20:42:11 +0100 Subject: [PATCH 36/73] #1833 add tests --- .../GetDependencies/MacCodeSign.cs | 4 +- .../GetDependencies/MacCodeSignTests.cs | 111 ++++++++++++++++++ 2 files changed, 113 insertions(+), 2 deletions(-) create mode 100644 starsky/starskytest/starsky.foundation.video/GetDependencies/MacCodeSignTests.cs diff --git a/starsky/starsky.foundation.video/GetDependencies/MacCodeSign.cs b/starsky/starsky.foundation.video/GetDependencies/MacCodeSign.cs index 08bcf119fb..11da97efa9 100644 --- a/starsky/starsky.foundation.video/GetDependencies/MacCodeSign.cs +++ b/starsky/starsky.foundation.video/GetDependencies/MacCodeSign.cs @@ -33,7 +33,7 @@ public async Task MacCodeSignAndXattrExecutable(string exeFile) return await MacXattrExecutable(exeFile); } - private async Task MacCodeSignExecutable(string exeFile) + internal async Task MacCodeSignExecutable(string exeFile) { if ( !_hostFileSystemStorage.ExistFile(CodeSignPath) ) { @@ -53,7 +53,7 @@ private async Task MacCodeSignExecutable(string exeFile) return false; } - private async Task MacXattrExecutable(string exeFile) + internal async Task MacXattrExecutable(string exeFile) { if ( !_hostFileSystemStorage.ExistFile(XattrPath) ) { diff --git a/starsky/starskytest/starsky.foundation.video/GetDependencies/MacCodeSignTests.cs b/starsky/starskytest/starsky.foundation.video/GetDependencies/MacCodeSignTests.cs new file mode 100644 index 0000000000..bf26dca926 --- /dev/null +++ b/starsky/starskytest/starsky.foundation.video/GetDependencies/MacCodeSignTests.cs @@ -0,0 +1,111 @@ +using System.IO; +using System.Threading.Tasks; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using starsky.foundation.storage.Helpers; +using starsky.foundation.storage.Storage; +using starsky.foundation.video.GetDependencies; +using starskytest.FakeCreateAn; +using starskytest.FakeMocks; + +namespace starskytest.starsky.foundation.video.GetDependencies; + +[TestClass] +public class MacCodeSignTests +{ + private readonly StorageHostFullPathFilesystem _hostFileSystemStorage; + private readonly MacCodeSign _macCodeSign; + private readonly string _testFolder; + private readonly FakeIWebLogger _logger; + + public MacCodeSignTests() + { + _logger = new FakeIWebLogger(); + _hostFileSystemStorage = new StorageHostFullPathFilesystem(_logger); + _macCodeSign = new MacCodeSign(new FakeSelectorStorage(_hostFileSystemStorage), logger); + _testFolder = Path.Combine(new CreateAnImage().BasePath, "MacCodeSignTests"); + Directory.CreateDirectory(_testFolder); + } + + [TestCleanup] + public void Cleanup() + { + Directory.Delete(_testFolder, true); + } + + private async Task CreateSubFiles(int codeSignExitCode, int xattrExitCode) + { + var chmodHelper = new FfmpegChmod(_hostFileSystemStorage, new FakeIWebLogger()); + + var exeFile = Path.Combine(_testFolder, "testExecutable"); + CreateStubFile(exeFile, "#!/bin/bash\necho Fake Executable"); + + + var codeSignPath = Path.Combine(_testFolder, "codesign"); + CreateStubFile(codeSignPath, $"#!/bin/bash\necho codesign\nexit {codeSignExitCode}"); + _macCodeSign.CodeSignPath = codeSignPath; + + var xattrPath = Path.Combine(_testFolder, "xattr"); + CreateStubFile(xattrPath, $"#!/bin/bash\nexit {xattrExitCode}"); + _macCodeSign.XattrPath = xattrPath; + + await chmodHelper.Chmod(exeFile); + await chmodHelper.Chmod(codeSignPath); + await chmodHelper.Chmod(xattrPath); + + return exeFile; + } + + private void CreateStubFile(string path, string content) + { + var stream = StringToStreamHelper.StringToStream(content); + _hostFileSystemStorage.WriteStream(stream, path); + } + + [TestMethod] + [DataRow(0, 0, true)] + [DataRow(1, 0, false)] + [DataRow(0, 1, false)] + [DataRow(1, 1, false)] + public async Task MacCodeSignAndXattrExecutable_ShouldReturnExpectedResult(int codeSignExitCode, + int xattrExitCode, bool expectedResult) + { + // Arrange + var exeFile = await CreateSubFiles(codeSignExitCode, xattrExitCode); + + // Act + var result = await _macCodeSign.MacCodeSignAndXattrExecutable(exeFile); + + // Assert + Assert.AreEqual(expectedResult, result); + } + + [TestMethod] + public async Task MacCodeSignExecutable_ShouldLogError_WhenCodeSignFails() + { + // Arrange + var exeFile = await CreateSubFiles(1, 0); + + // Act + var result = await _macCodeSign.MacCodeSignExecutable(exeFile); + + // Assert + Assert.IsFalse(result); + Assert.IsTrue(_logger.TrackedExceptions.Exists(entry => + entry.Item2?.Contains("codesign Command failed with exit code") == true)); + } + + [TestMethod] + public async Task MacXattrExecutable_ShouldLogError_WhenXattrFails() + { + // Arrange + var exeFile = await CreateSubFiles(0, 1); + + // Act + var result = await _macCodeSign.MacXattrExecutable(exeFile); + + // Assert + Assert.IsFalse(result); + Assert.IsTrue(_logger.TrackedExceptions.Exists(entry => + entry.Item2?.Contains("xattr Command failed with exit code") == true)); + } +} From 3ceb48235d2d7613605716d7dea4c37f4f6bb959 Mon Sep 17 00:00:00 2001 From: Dion Date: Mon, 9 Dec 2024 21:03:30 +0100 Subject: [PATCH 37/73] #1833 build error --- .../GetDependencies/MacCodeSignTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/starsky/starskytest/starsky.foundation.video/GetDependencies/MacCodeSignTests.cs b/starsky/starskytest/starsky.foundation.video/GetDependencies/MacCodeSignTests.cs index bf26dca926..0899084b80 100644 --- a/starsky/starskytest/starsky.foundation.video/GetDependencies/MacCodeSignTests.cs +++ b/starsky/starskytest/starsky.foundation.video/GetDependencies/MacCodeSignTests.cs @@ -21,7 +21,7 @@ public MacCodeSignTests() { _logger = new FakeIWebLogger(); _hostFileSystemStorage = new StorageHostFullPathFilesystem(_logger); - _macCodeSign = new MacCodeSign(new FakeSelectorStorage(_hostFileSystemStorage), logger); + _macCodeSign = new MacCodeSign(new FakeSelectorStorage(_hostFileSystemStorage), _logger); _testFolder = Path.Combine(new CreateAnImage().BasePath, "MacCodeSignTests"); Directory.CreateDirectory(_testFolder); } From b79ca838d51af72e0017d530578e2b2d21b98a4a Mon Sep 17 00:00:00 2001 From: Dion Date: Mon, 9 Dec 2024 21:06:53 +0100 Subject: [PATCH 38/73] #1833 hidden file --- starsky/starsky.foundation.storage/ArchiveFormats/Zipper.cs | 3 +++ .../starsky.foundation.storage/ArchiveFormats/ZipperTest.cs | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/starsky/starsky.foundation.storage/ArchiveFormats/Zipper.cs b/starsky/starsky.foundation.storage/ArchiveFormats/Zipper.cs index 395dccb8ab..756a94c3b2 100644 --- a/starsky/starsky.foundation.storage/ArchiveFormats/Zipper.cs +++ b/starsky/starsky.foundation.storage/ArchiveFormats/Zipper.cs @@ -14,9 +14,11 @@ namespace starsky.foundation.storage.ArchiveFormats; public sealed class Zipper { private readonly StorageHostFullPathFilesystem _hostStorage; + private readonly IWebLogger _logger; public Zipper(IWebLogger logger) { + _logger = logger; _hostStorage = new StorageHostFullPathFilesystem(logger); } @@ -31,6 +33,7 @@ public bool ExtractZip(string zipInputFullPath, string storeZipFolderFullPath) { if ( !File.Exists(zipInputFullPath) ) { + _logger.LogError("[Zipper] Zip file not found: " + zipInputFullPath); return false; } diff --git a/starsky/starskytest/starsky.foundation.storage/ArchiveFormats/ZipperTest.cs b/starsky/starskytest/starsky.foundation.storage/ArchiveFormats/ZipperTest.cs index 83a9b48136..d921dbf82b 100644 --- a/starsky/starskytest/starsky.foundation.storage/ArchiveFormats/ZipperTest.cs +++ b/starsky/starskytest/starsky.foundation.storage/ArchiveFormats/ZipperTest.cs @@ -47,7 +47,7 @@ public void TestExtractZip() } [TestMethod] - public void TestExtractZipMacOs() + public void TestExtractZipMacOsHiddenFiles() { // Arrange var zipped = new CreateAnZipFileMacOs().FilePath; @@ -64,7 +64,7 @@ public void TestExtractZipMacOs() testOutputFolder); // Assert - Assert.IsTrue(result); + Assert.IsNotNull(result); var outputFile = testOutputFolder + Path.DirectorySeparatorChar + CreateAnZipFileMacOs.Content[0]; From 879358b0f4078121c930ce7365b98d20a5154e61 Mon Sep 17 00:00:00 2001 From: Dion Date: Mon, 9 Dec 2024 22:04:42 +0100 Subject: [PATCH 39/73] #1833 actual test on mac os --- .../GetDependencies/MacCodeSignTests.cs | 103 ++++++++++++++++-- 1 file changed, 96 insertions(+), 7 deletions(-) diff --git a/starsky/starskytest/starsky.foundation.video/GetDependencies/MacCodeSignTests.cs b/starsky/starskytest/starsky.foundation.video/GetDependencies/MacCodeSignTests.cs index 0899084b80..989c0e1471 100644 --- a/starsky/starskytest/starsky.foundation.video/GetDependencies/MacCodeSignTests.cs +++ b/starsky/starskytest/starsky.foundation.video/GetDependencies/MacCodeSignTests.cs @@ -1,5 +1,7 @@ +using System; using System.IO; using System.Threading.Tasks; +using Medallion.Shell; using Microsoft.VisualStudio.TestTools.UnitTesting; using starsky.foundation.storage.Helpers; using starsky.foundation.storage.Storage; @@ -13,9 +15,9 @@ namespace starskytest.starsky.foundation.video.GetDependencies; public class MacCodeSignTests { private readonly StorageHostFullPathFilesystem _hostFileSystemStorage; + private readonly FakeIWebLogger _logger; private readonly MacCodeSign _macCodeSign; private readonly string _testFolder; - private readonly FakeIWebLogger _logger; public MacCodeSignTests() { @@ -32,13 +34,20 @@ public void Cleanup() Directory.Delete(_testFolder, true); } - private async Task CreateSubFiles(int codeSignExitCode, int xattrExitCode) + private async Task CreateStubExeFile() { var chmodHelper = new FfmpegChmod(_hostFileSystemStorage, new FakeIWebLogger()); - var exeFile = Path.Combine(_testFolder, "testExecutable"); CreateStubFile(exeFile, "#!/bin/bash\necho Fake Executable"); + await chmodHelper.Chmod(exeFile); + return exeFile; + } + private async Task CreateStubFiles(int codeSignExitCode, int xattrExitCode) + { + var chmodHelper = new FfmpegChmod(_hostFileSystemStorage, new FakeIWebLogger()); + + var exeFile = await CreateStubExeFile(); var codeSignPath = Path.Combine(_testFolder, "codesign"); CreateStubFile(codeSignPath, $"#!/bin/bash\necho codesign\nexit {codeSignExitCode}"); @@ -48,7 +57,6 @@ private async Task CreateSubFiles(int codeSignExitCode, int xattrExitCod CreateStubFile(xattrPath, $"#!/bin/bash\nexit {xattrExitCode}"); _macCodeSign.XattrPath = xattrPath; - await chmodHelper.Chmod(exeFile); await chmodHelper.Chmod(codeSignPath); await chmodHelper.Chmod(xattrPath); @@ -70,7 +78,7 @@ public async Task MacCodeSignAndXattrExecutable_ShouldReturnExpectedResult(int c int xattrExitCode, bool expectedResult) { // Arrange - var exeFile = await CreateSubFiles(codeSignExitCode, xattrExitCode); + var exeFile = await CreateStubFiles(codeSignExitCode, xattrExitCode); // Act var result = await _macCodeSign.MacCodeSignAndXattrExecutable(exeFile); @@ -83,7 +91,7 @@ public async Task MacCodeSignAndXattrExecutable_ShouldReturnExpectedResult(int c public async Task MacCodeSignExecutable_ShouldLogError_WhenCodeSignFails() { // Arrange - var exeFile = await CreateSubFiles(1, 0); + var exeFile = await CreateStubFiles(1, 0); // Act var result = await _macCodeSign.MacCodeSignExecutable(exeFile); @@ -98,7 +106,7 @@ public async Task MacCodeSignExecutable_ShouldLogError_WhenCodeSignFails() public async Task MacXattrExecutable_ShouldLogError_WhenXattrFails() { // Arrange - var exeFile = await CreateSubFiles(0, 1); + var exeFile = await CreateStubFiles(0, 1); // Act var result = await _macCodeSign.MacXattrExecutable(exeFile); @@ -108,4 +116,85 @@ public async Task MacXattrExecutable_ShouldLogError_WhenXattrFails() Assert.IsTrue(_logger.TrackedExceptions.Exists(entry => entry.Item2?.Contains("xattr Command failed with exit code") == true)); } + + [TestMethod] + public async Task MacCodeSignAndXattrExecutable_QuarantineEventsV2_ShouldReturnTrue__MacOnly() + { + if ( !OperatingSystem.IsMacOS() ) + { + Assert.Inconclusive("This test is only applicable on macOS."); + return; + } + + // Arrange + var exeFile = await CreateStubExeFile(); + + var home = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); + + var addResult = await Command.Run("sqlite3", + $"{home}/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV2", + "INSERT INTO LSQuarantineEvent (LSQuarantineEventIdentifier, LSQuarantineTimeStamp, " + + "LSQuarantineAgentBundleIdentifier, LSQuarantineAgentName, LSQuarantineDataURLString, " + + "LSQuarantineSenderName, LSQuarantineSenderAddress, LSQuarantineTypeNumber, " + + "LSQuarantineOriginTitle, LSQuarantineOriginURLString, LSQuarantineOriginAlias) VALUES " + + "('B555DB5F-D82A-408B-B9A6-D4F4012FD520', 570726604.559004, 'com.apple.Safari', 'Safari', " + + "'https://qdraw.nl/test.zip', NULL, NULL, 0, NULL, " + + " 'https://github.com/qdraw/starsky/releases', NULL);" + ).Task; + + Console.WriteLine(addResult.StandardOutput); + Console.WriteLine(addResult.StandardError); + + await Command.Run("xattr", "-w", "com.apple.quarantine", + "\"0081;5f8e2e1e;Safari;B555DB5F-D82A-408B-B9A6-D4F4012FD520\"", + exeFile).Task; + + var xattrBefore = await Command.Run("xattr", "-p", + "com.apple.quarantine", exeFile).Task; + + Console.WriteLine("xattr list:"); + Console.WriteLine(xattrBefore.StandardOutput); + + Assert.AreEqual("\"0081;5f8e2e1e;Safari;B555DB5F-D82A-408B-B9A6-D4F4012FD520\"", + xattrBefore.StandardOutput.Trim()); + + // Act + var result = await _macCodeSign.MacCodeSignAndXattrExecutable(exeFile); + + var xattrAfter = await Command.Run("xattr", "-p", + "com.apple.quarantine", exeFile).Task; + + // Assert + Assert.AreEqual(string.Empty, xattrAfter.StandardOutput); + Assert.IsTrue(result); + + Cleanup(); + } + + [TestMethod] + public async Task MacCodeSignAndXattrExecutable_CodeSign__MacOnly() + { + if ( !OperatingSystem.IsMacOS() ) + { + Assert.Inconclusive("This test is only applicable on macOS."); + return; + } + + // Arrange + var exeFile = await CreateStubExeFile(); + + var codeSignBefore = await Command.Run("codesign", "-dvv", exeFile).Task; + + // Act + var result = await _macCodeSign.MacCodeSignAndXattrExecutable(exeFile); + + var codeSignAfter = await Command.Run("codesign", "-dvv", exeFile).Task; + Console.WriteLine(codeSignAfter.StandardOutput); + Console.WriteLine(codeSignAfter.StandardError); + + // Assert + Assert.IsTrue(result); + Assert.IsTrue(codeSignBefore.StandardError.Contains("code object is not signed at all")); + Assert.IsTrue(codeSignAfter.StandardError.Contains("Identifier=testExecutable")); + } } From 011ce76108b8ea99178b7e1a834ec8bfa63892ad Mon Sep 17 00:00:00 2001 From: Dion Date: Mon, 9 Dec 2024 22:06:03 +0100 Subject: [PATCH 40/73] #1833 no cleanup --- .../GetDependencies/MacCodeSignTests.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/starsky/starskytest/starsky.foundation.video/GetDependencies/MacCodeSignTests.cs b/starsky/starskytest/starsky.foundation.video/GetDependencies/MacCodeSignTests.cs index 989c0e1471..8ef75285fd 100644 --- a/starsky/starskytest/starsky.foundation.video/GetDependencies/MacCodeSignTests.cs +++ b/starsky/starskytest/starsky.foundation.video/GetDependencies/MacCodeSignTests.cs @@ -167,8 +167,6 @@ await Command.Run("xattr", "-w", "com.apple.quarantine", // Assert Assert.AreEqual(string.Empty, xattrAfter.StandardOutput); Assert.IsTrue(result); - - Cleanup(); } [TestMethod] From eda1e39c9d4eca911a8bd9d70cd09540768ec068 Mon Sep 17 00:00:00 2001 From: Dion Date: Mon, 9 Dec 2024 22:33:25 +0100 Subject: [PATCH 41/73] #1833 add not found cases --- .../GetDependencies/FFMpegDownload.cs | 2 +- .../Interfaces/IMacCodeSign.cs | 2 +- .../GetDependencies/MacCodeSign.cs | 20 ++--- .../starskytest/FakeMocks/FakeIMacCodeSign.cs | 8 +- .../GetDependencies/MacCodeSignTests.cs | 82 ++++++++++++++++--- 5 files changed, 88 insertions(+), 26 deletions(-) diff --git a/starsky/starsky.foundation.video/GetDependencies/FFMpegDownload.cs b/starsky/starsky.foundation.video/GetDependencies/FFMpegDownload.cs index 6028b253cd..1caa99c182 100644 --- a/starsky/starsky.foundation.video/GetDependencies/FFMpegDownload.cs +++ b/starsky/starsky.foundation.video/GetDependencies/FFMpegDownload.cs @@ -156,7 +156,7 @@ private async Task PrepareBeforeRunning(string currentArchitecture) if ( currentArchitecture is "osx-x64" or "osx-arm64" ) { - return await _macCodeSign.MacCodeSignAndXattrExecutable(exeFile); + return await _macCodeSign.MacCodeSignAndXattrExecutable(exeFile) == true; } return true; diff --git a/starsky/starsky.foundation.video/GetDependencies/Interfaces/IMacCodeSign.cs b/starsky/starsky.foundation.video/GetDependencies/Interfaces/IMacCodeSign.cs index 218b5fe217..31fca8128c 100644 --- a/starsky/starsky.foundation.video/GetDependencies/Interfaces/IMacCodeSign.cs +++ b/starsky/starsky.foundation.video/GetDependencies/Interfaces/IMacCodeSign.cs @@ -2,5 +2,5 @@ namespace starsky.foundation.video.GetDependencies.Interfaces; public interface IMacCodeSign { - Task MacCodeSignAndXattrExecutable(string exeFile); + Task MacCodeSignAndXattrExecutable(string exeFile); } diff --git a/starsky/starsky.foundation.video/GetDependencies/MacCodeSign.cs b/starsky/starsky.foundation.video/GetDependencies/MacCodeSign.cs index 11da97efa9..00f7c80c6c 100644 --- a/starsky/starsky.foundation.video/GetDependencies/MacCodeSign.cs +++ b/starsky/starsky.foundation.video/GetDependencies/MacCodeSign.cs @@ -15,30 +15,31 @@ public class MacCodeSign : IMacCodeSign public MacCodeSign(ISelectorStorage selectorStorage, IWebLogger logger) { - _hostFileSystemStorage = selectorStorage.Get(SelectorStorage.StorageServices.HostFilesystem); + _hostFileSystemStorage = + selectorStorage.Get(SelectorStorage.StorageServices.HostFilesystem); _logger = logger; } - + public string CodeSignPath { get; set; } = "/usr/bin/codesign"; public string XattrPath { get; set; } = "/usr/bin/xattr"; - public async Task MacCodeSignAndXattrExecutable(string exeFile) + public async Task MacCodeSignAndXattrExecutable(string exeFile) { var result = await MacCodeSignExecutable(exeFile); - if ( !result ) + if ( result is null or false ) { - return false; + return result; } return await MacXattrExecutable(exeFile); } - internal async Task MacCodeSignExecutable(string exeFile) + internal async Task MacCodeSignExecutable(string exeFile) { if ( !_hostFileSystemStorage.ExistFile(CodeSignPath) ) { _logger.LogError("[RunChmodOnFfmpegExe] WARNING: /usr/bin/codesign does not exist"); - return true; + return null; } // command.run does not care about the $PATH @@ -53,12 +54,12 @@ internal async Task MacCodeSignExecutable(string exeFile) return false; } - internal async Task MacXattrExecutable(string exeFile) + internal async Task MacXattrExecutable(string exeFile) { if ( !_hostFileSystemStorage.ExistFile(XattrPath) ) { _logger.LogError("[RunChmodOnFfmpegExe] WARNING: /usr/bin/xattr does not exist"); - return true; + return null; } // command.run does not care about the $PATH @@ -73,4 +74,3 @@ internal async Task MacXattrExecutable(string exeFile) return false; } } - diff --git a/starsky/starskytest/FakeMocks/FakeIMacCodeSign.cs b/starsky/starskytest/FakeMocks/FakeIMacCodeSign.cs index 897ff6c7a3..ae11c003d7 100644 --- a/starsky/starskytest/FakeMocks/FakeIMacCodeSign.cs +++ b/starsky/starskytest/FakeMocks/FakeIMacCodeSign.cs @@ -6,14 +6,14 @@ namespace starskytest.FakeMocks; public class FakeIMacCodeSign : IMacCodeSign { - private readonly Dictionary _expectedResults; + private readonly Dictionary _expectedResults; - public FakeIMacCodeSign(Dictionary? expectedResults = null) + public FakeIMacCodeSign(Dictionary? expectedResults = null) { - _expectedResults = expectedResults ?? new Dictionary(); + _expectedResults = expectedResults ?? new Dictionary(); } - public Task MacCodeSignAndXattrExecutable(string exeFile) + public Task MacCodeSignAndXattrExecutable(string exeFile) { _expectedResults.TryGetValue(exeFile, out var result); return Task.FromResult(result); diff --git a/starsky/starskytest/starsky.foundation.video/GetDependencies/MacCodeSignTests.cs b/starsky/starskytest/starsky.foundation.video/GetDependencies/MacCodeSignTests.cs index 8ef75285fd..aacdc2dccc 100644 --- a/starsky/starskytest/starsky.foundation.video/GetDependencies/MacCodeSignTests.cs +++ b/starsky/starskytest/starsky.foundation.video/GetDependencies/MacCodeSignTests.cs @@ -25,12 +25,27 @@ public MacCodeSignTests() _hostFileSystemStorage = new StorageHostFullPathFilesystem(_logger); _macCodeSign = new MacCodeSign(new FakeSelectorStorage(_hostFileSystemStorage), _logger); _testFolder = Path.Combine(new CreateAnImage().BasePath, "MacCodeSignTests"); + CreateTestFolder(); + } + + private void CreateTestFolder() + { + if ( Directory.Exists(_testFolder) ) + { + return; + } + Directory.CreateDirectory(_testFolder); } [TestCleanup] public void Cleanup() { + if ( !Directory.Exists(_testFolder) ) + { + return; + } + Directory.Delete(_testFolder, true); } @@ -43,23 +58,29 @@ private async Task CreateStubExeFile() return exeFile; } - private async Task CreateStubFiles(int codeSignExitCode, int xattrExitCode) + private async Task CreateStubCodeSignFile(int codeSignExitCode) { var chmodHelper = new FfmpegChmod(_hostFileSystemStorage, new FakeIWebLogger()); - - var exeFile = await CreateStubExeFile(); - var codeSignPath = Path.Combine(_testFolder, "codesign"); CreateStubFile(codeSignPath, $"#!/bin/bash\necho codesign\nexit {codeSignExitCode}"); _macCodeSign.CodeSignPath = codeSignPath; + await chmodHelper.Chmod(codeSignPath); + } + private async Task CreateStubXattrFile(int xattrExitCode) + { + var chmodHelper = new FfmpegChmod(_hostFileSystemStorage, new FakeIWebLogger()); var xattrPath = Path.Combine(_testFolder, "xattr"); CreateStubFile(xattrPath, $"#!/bin/bash\nexit {xattrExitCode}"); _macCodeSign.XattrPath = xattrPath; - - await chmodHelper.Chmod(codeSignPath); await chmodHelper.Chmod(xattrPath); + } + private async Task CreateStubFiles(int codeSignExitCode, int xattrExitCode) + { + var exeFile = await CreateStubExeFile(); + await CreateStubCodeSignFile(codeSignExitCode); + await CreateStubXattrFile(xattrExitCode); return exeFile; } @@ -74,7 +95,8 @@ private void CreateStubFile(string path, string content) [DataRow(1, 0, false)] [DataRow(0, 1, false)] [DataRow(1, 1, false)] - public async Task MacCodeSignAndXattrExecutable_ShouldReturnExpectedResult(int codeSignExitCode, + public async Task MacCodeSignAndXattrExecutable_Status_ShouldReturnExpectedResult( + int codeSignExitCode, int xattrExitCode, bool expectedResult) { // Arrange @@ -87,6 +109,46 @@ public async Task MacCodeSignAndXattrExecutable_ShouldReturnExpectedResult(int c Assert.AreEqual(expectedResult, result); } + [TestMethod] + [DataRow(false, false, null)] + [DataRow(true, false, null)] + [DataRow(false, true, null)] + [DataRow(true, true, true)] + public async Task MacCodeSignAndXattrExecutable_NotFound_ShouldReturnExpectedResult( + bool codeSignExists, + bool xattrExists, bool? expectedResult) + { + Cleanup(); + CreateTestFolder(); + + // Arrange + if ( xattrExists ) + { + await CreateStubXattrFile(0); + } + else + { + _macCodeSign.XattrPath = Path.Combine(_testFolder, "xattr_not_found"); + } + + if ( codeSignExists ) + { + await CreateStubCodeSignFile(0); + } + else + { + _macCodeSign.CodeSignPath = Path.Combine(_testFolder, "codesign_not_found"); + } + + var exeFile = await CreateStubExeFile(); + + // Act + var result = await _macCodeSign.MacCodeSignAndXattrExecutable(exeFile); + + // Assert + Assert.AreEqual(expectedResult, result); + } + [TestMethod] public async Task MacCodeSignExecutable_ShouldLogError_WhenCodeSignFails() { @@ -180,12 +242,12 @@ public async Task MacCodeSignAndXattrExecutable_CodeSign__MacOnly() // Arrange var exeFile = await CreateStubExeFile(); - + var codeSignBefore = await Command.Run("codesign", "-dvv", exeFile).Task; - + // Act var result = await _macCodeSign.MacCodeSignAndXattrExecutable(exeFile); - + var codeSignAfter = await Command.Run("codesign", "-dvv", exeFile).Task; Console.WriteLine(codeSignAfter.StandardOutput); Console.WriteLine(codeSignAfter.StandardError); From e06a3cf8eaeac0007bdb6900cc5270fdd709b7c8 Mon Sep 17 00:00:00 2001 From: Dion Date: Mon, 9 Dec 2024 22:39:50 +0100 Subject: [PATCH 42/73] #1833 check --- .../starsky.foundation.storage/ArchiveFormats/ZipperTest.cs | 6 +++++- starsky/starskytest/starskytest.csproj | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/starsky/starskytest/starsky.foundation.storage/ArchiveFormats/ZipperTest.cs b/starsky/starskytest/starsky.foundation.storage/ArchiveFormats/ZipperTest.cs index d921dbf82b..cf24732e52 100644 --- a/starsky/starskytest/starsky.foundation.storage/ArchiveFormats/ZipperTest.cs +++ b/starsky/starskytest/starsky.foundation.storage/ArchiveFormats/ZipperTest.cs @@ -59,6 +59,9 @@ public void TestExtractZipMacOsHiddenFiles() hostService.FolderDelete(testOutputFolder); hostService.CreateDirectory(testOutputFolder); + Console.WriteLine("Zipped file:" + zipped + " ~ " + File.Exists(zipped)); + Assert.IsTrue(File.Exists(zipped)); + // Act var result = new Zipper(new FakeIWebLogger()).ExtractZip(zipped, testOutputFolder); @@ -73,7 +76,8 @@ public void TestExtractZipMacOsHiddenFiles() Console.WriteLine(outputFile); Console.WriteLine("List content:"); - Console.WriteLine(hostService.GetAllFilesInDirectory(testOutputFolder).ToList()[0]); + Console.WriteLine(hostService.GetAllFilesInDirectory(testOutputFolder).FirstOrDefault()); + Assert.AreEqual(1, hostService.GetAllFilesInDirectory(testOutputFolder).Count()); Assert.IsTrue(Path.Exists(outputFile)); diff --git a/starsky/starskytest/starskytest.csproj b/starsky/starskytest/starskytest.csproj index 605900cf20..b78004fefd 100644 --- a/starsky/starskytest/starskytest.csproj +++ b/starsky/starskytest/starskytest.csproj @@ -154,7 +154,7 @@ - PreserveNewest + Always From 24158195435e64c38db9805bdb725e414a0bca76 Mon Sep 17 00:00:00 2001 From: Dion Date: Mon, 9 Dec 2024 22:42:12 +0100 Subject: [PATCH 43/73] #1833 sonar feedback --- .../GetDependencies/FfmpegChmodTests.cs | 7 +++---- .../Services/ExifToolServiceTest.cs | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/starsky/starskytest/starsky.foundation.video/GetDependencies/FfmpegChmodTests.cs b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfmpegChmodTests.cs index fa79f3eb8f..9440e33b9e 100644 --- a/starsky/starskytest/starsky.foundation.video/GetDependencies/FfmpegChmodTests.cs +++ b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfmpegChmodTests.cs @@ -7,7 +7,6 @@ using starsky.foundation.platform.Models; using starsky.foundation.storage.ArchiveFormats; using starsky.foundation.storage.Helpers; -using starsky.foundation.storage.Interfaces; using starsky.foundation.storage.Storage; using starsky.foundation.video.GetDependencies; using starskytest.FakeCreateAn; @@ -20,7 +19,7 @@ public class FfmpegChmodTests { private readonly FfmpegChmod _ffmpegChmod; private readonly FfmpegExePath _ffmpegExePath; - private readonly IStorage _hostFileSystemStorage; + private readonly StorageHostFullPathFilesystem _hostFileSystemStorage; private readonly bool _isWindows; private readonly IWebLogger _logger; private readonly string _parentFolder; @@ -114,7 +113,7 @@ public async Task Chmod_ShouldReturnFalse_WhenCommandSucceed__WindowsOnly() } CreateFile(); - + var path = Path.Combine(_ffmpegExePath.GetExeParentFolder(), "chmod.exe"); var sut = new FfmpegChmod(new FakeIStorage([], [path]), @@ -122,7 +121,7 @@ public async Task Chmod_ShouldReturnFalse_WhenCommandSucceed__WindowsOnly() var result = await sut.Chmod("/_not_found_path/to/ffmpeg"); Assert.IsTrue(result); - + DeleteFile(); } diff --git a/starsky/starskytest/starsky.foundation.writemeta/Services/ExifToolServiceTest.cs b/starsky/starskytest/starsky.foundation.writemeta/Services/ExifToolServiceTest.cs index b69d7cb53f..26bd9e4406 100644 --- a/starsky/starskytest/starsky.foundation.writemeta/Services/ExifToolServiceTest.cs +++ b/starsky/starskytest/starsky.foundation.writemeta/Services/ExifToolServiceTest.cs @@ -54,7 +54,7 @@ public static void CleanExifToolServiceTest() } } - private async Task WriteTagsAndRenameThumbnailAsyncUnixPrivateTest() + private static async Task WriteTagsAndRenameThumbnailAsyncUnixPrivateTest() { var storage = new FakeIStorage(new List { "/" }, new List { "/image.jpg" }, From 5429de5f7aea5d94b300b6530b84ec03be9c7f15 Mon Sep 17 00:00:00 2001 From: Dion Date: Mon, 9 Dec 2024 22:51:21 +0100 Subject: [PATCH 44/73] #1833 rename action --- .../{macOsSubfolder.zip => ArchiveWithDotFiles.zip} | Bin .../CreateAnZipFileMacOs/CreateAnZipFileMacOs.cs | 2 +- starsky/starskytest/starskytest.csproj | 6 +++--- 3 files changed, 4 insertions(+), 4 deletions(-) rename starsky/starskytest/FakeCreateAn/CreateAnZipFileMacOs/{macOsSubfolder.zip => ArchiveWithDotFiles.zip} (100%) diff --git a/starsky/starskytest/FakeCreateAn/CreateAnZipFileMacOs/macOsSubfolder.zip b/starsky/starskytest/FakeCreateAn/CreateAnZipFileMacOs/ArchiveWithDotFiles.zip similarity index 100% rename from starsky/starskytest/FakeCreateAn/CreateAnZipFileMacOs/macOsSubfolder.zip rename to starsky/starskytest/FakeCreateAn/CreateAnZipFileMacOs/ArchiveWithDotFiles.zip diff --git a/starsky/starskytest/FakeCreateAn/CreateAnZipFileMacOs/CreateAnZipFileMacOs.cs b/starsky/starskytest/FakeCreateAn/CreateAnZipFileMacOs/CreateAnZipFileMacOs.cs index 5475bcb967..ef170da479 100644 --- a/starsky/starskytest/FakeCreateAn/CreateAnZipFileMacOs/CreateAnZipFileMacOs.cs +++ b/starsky/starskytest/FakeCreateAn/CreateAnZipFileMacOs/CreateAnZipFileMacOs.cs @@ -15,7 +15,7 @@ public CreateAnZipFileMacOs() } var path = Path.Combine(dirName, "FakeCreateAn", - "CreateAnZipFileMacOs", "macOsSubfolder.zip"); + "CreateAnZipFileMacOs", "ArchiveWithDotFiles.zip"); FilePath = path; } diff --git a/starsky/starskytest/starskytest.csproj b/starsky/starskytest/starskytest.csproj index b78004fefd..9fa95b386d 100644 --- a/starsky/starskytest/starskytest.csproj +++ b/starsky/starskytest/starskytest.csproj @@ -152,9 +152,9 @@ PreserveNewest - - - Always + + + PreserveNewest From 419ddd73ce114472c737ca6d2a7f18979f9c358a Mon Sep 17 00:00:00 2001 From: Dion Date: Mon, 9 Dec 2024 22:54:42 +0100 Subject: [PATCH 45/73] #1833 add not found test --- .../GetDependencies/FfMpegDownloadIndexTest.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadIndexTest.cs b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadIndexTest.cs index 4122bbc518..72c636ed24 100644 --- a/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadIndexTest.cs +++ b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadIndexTest.cs @@ -87,4 +87,20 @@ public async Task FfMpegDownloadIndexTest_WithExampleData_Success(int index) Assert.AreEqual(_example.Binaries.Count, result.Data?.Binaries.Count); } + + [TestMethod] + public async Task FfMpegDownloadIndexTest_NotFound() + { + // Arrange + var sut = new FfMpegDownloadIndex( + new FakeIHttpClientHelper(new FakeIStorage(), + new Dictionary>()), new FakeIWebLogger()); + + // Act + var result = await sut.DownloadIndex(); + + // Assert + Assert.IsNull(result.Data); + Assert.IsFalse(result.Success); + } } From a0dddba64989b3a258b31146b0ad0d44a75cc4f3 Mon Sep 17 00:00:00 2001 From: Dion Date: Mon, 9 Dec 2024 23:22:17 +0100 Subject: [PATCH 46/73] #1833 add write file --- .../CreateAnZipFileMacOs.cs | 25 +++++++++++++++++++ starsky/starskytest/starskytest.csproj | 4 --- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/starsky/starskytest/FakeCreateAn/CreateAnZipFileMacOs/CreateAnZipFileMacOs.cs b/starsky/starskytest/FakeCreateAn/CreateAnZipFileMacOs/CreateAnZipFileMacOs.cs index ef170da479..8ac1154ac4 100644 --- a/starsky/starskytest/FakeCreateAn/CreateAnZipFileMacOs/CreateAnZipFileMacOs.cs +++ b/starsky/starskytest/FakeCreateAn/CreateAnZipFileMacOs/CreateAnZipFileMacOs.cs @@ -1,4 +1,6 @@ +using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.IO; using System.Reflection; @@ -6,6 +8,22 @@ namespace starskytest.FakeCreateAn.CreateAnZipFileMacOs; public class CreateAnZipFileMacOs { + [SuppressMessage("ReSharper", "StringLiteralTypo")] + private const string Base64ZipString = "UEsDBBQAAAAIAElHQ1mzpFMiXAAAANwAAAARACAAX19NQU" + + "NPU1gvLl9mZm1wZWdVVA0AB4pA/mbuQP5m9EL+ZnV4CwABBPUBAAAEFA" + + "AAAGNgFWNnYGJg8E1MVvAPVohQgAKQGAMn" + + "EBsB8SogBvHvMBAFHENCgqBMkI4pQOyBpoQRIc6fnJ+rl1hQkJOql5uY" + + "nAMUZGMw0K6SVmv3ZdlfW7ZvwafaB8TZiw4" + + "AUEsDBAoAAAAAANqGiVk2DVKQHAAAABwAAAAGABwAZmZtcGVnVVQJAAP" + + "LEldn9BJXZ3V4CwABBPUBAAAEFAAAACMhL2" + + "Jpbi9iYXNoCmVjaG8gRmFrZSBGZm1wZWdQSwECFAMUAAAACABJR0NZs6" + + "RTIlwAAADcAAAAEQAgAAAAAAAAAAAA7YEAA" + + "AAAX19NQUNPU1gvLl9mZm1wZWdVVA0AB4pA/mbuQP5m9EL+ZnV4CwABBP" + + "UBAAAEFAAAAFBLAQIeAwoAAAAAANqGiVk" + + "2DVKQHAAAABwAAAAGABgAAAAAAAEAAACkgasAAABmZm1wZWdVVAUAA8s" + + "SV2d1eAsAAQT1AQAABBQAAABQSwUGAAAAAAI" + + "AAgCrAAAABwEAAAAA"; + public CreateAnZipFileMacOs() { var dirName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); @@ -17,6 +35,13 @@ public CreateAnZipFileMacOs() var path = Path.Combine(dirName, "FakeCreateAn", "CreateAnZipFileMacOs", "ArchiveWithDotFiles.zip"); FilePath = path; + + if ( File.Exists(path) ) + { + return; + } + + File.WriteAllBytes(path, Convert.FromBase64String(Base64ZipString)); } public string FilePath { get; set; } = string.Empty; diff --git a/starsky/starskytest/starskytest.csproj b/starsky/starskytest/starskytest.csproj index 9fa95b386d..895d239b23 100644 --- a/starsky/starskytest/starskytest.csproj +++ b/starsky/starskytest/starskytest.csproj @@ -152,10 +152,6 @@ PreserveNewest - - - PreserveNewest - From c5ae755d756cb0be8176c9abb07965e67322c948 Mon Sep 17 00:00:00 2001 From: Dion Date: Mon, 9 Dec 2024 23:26:06 +0100 Subject: [PATCH 47/73] #1833 windows exclusions --- .../GetDependencies/FfmpegChmodTests.cs | 8 +++++- .../GetDependencies/MacCodeSignTests.cs | 25 ++++++++++++++++--- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/starsky/starskytest/starsky.foundation.video/GetDependencies/FfmpegChmodTests.cs b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfmpegChmodTests.cs index 9440e33b9e..ec57677410 100644 --- a/starsky/starskytest/starsky.foundation.video/GetDependencies/FfmpegChmodTests.cs +++ b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfmpegChmodTests.cs @@ -126,8 +126,14 @@ public async Task Chmod_ShouldReturnFalse_WhenCommandSucceed__WindowsOnly() } [TestMethod] - public async Task Chmod_ShouldLogError_WhenCommandFails() + public async Task Chmod_ShouldLogError_WhenCommandFails__UnixOnly() { + if ( new AppSettings().IsWindows ) + { + Assert.Inconclusive("This test is only applicable on Unix-based systems."); + return; + } + var result = await _ffmpegChmod.Chmod("/_not_found_path/to/ffmpeg"); Assert.IsFalse(result); diff --git a/starsky/starskytest/starsky.foundation.video/GetDependencies/MacCodeSignTests.cs b/starsky/starskytest/starsky.foundation.video/GetDependencies/MacCodeSignTests.cs index aacdc2dccc..cc713f5797 100644 --- a/starsky/starskytest/starsky.foundation.video/GetDependencies/MacCodeSignTests.cs +++ b/starsky/starskytest/starsky.foundation.video/GetDependencies/MacCodeSignTests.cs @@ -3,6 +3,7 @@ using System.Threading.Tasks; using Medallion.Shell; using Microsoft.VisualStudio.TestTools.UnitTesting; +using starsky.foundation.platform.Models; using starsky.foundation.storage.Helpers; using starsky.foundation.storage.Storage; using starsky.foundation.video.GetDependencies; @@ -95,10 +96,16 @@ private void CreateStubFile(string path, string content) [DataRow(1, 0, false)] [DataRow(0, 1, false)] [DataRow(1, 1, false)] - public async Task MacCodeSignAndXattrExecutable_Status_ShouldReturnExpectedResult( + public async Task MacCodeSignAndXattrExecutable_Status_ShouldReturnExpectedResult__UnixOnly( int codeSignExitCode, int xattrExitCode, bool expectedResult) { + if ( new AppSettings().IsWindows ) + { + Assert.Inconclusive("This test is only applicable on Unix-based systems."); + return; + } + // Arrange var exeFile = await CreateStubFiles(codeSignExitCode, xattrExitCode); @@ -114,10 +121,16 @@ public async Task MacCodeSignAndXattrExecutable_Status_ShouldReturnExpectedResul [DataRow(true, false, null)] [DataRow(false, true, null)] [DataRow(true, true, true)] - public async Task MacCodeSignAndXattrExecutable_NotFound_ShouldReturnExpectedResult( + public async Task MacCodeSignAndXattrExecutable_NotFound_ShouldReturnExpectedResult__UnixOnly( bool codeSignExists, bool xattrExists, bool? expectedResult) { + if ( new AppSettings().IsWindows ) + { + Assert.Inconclusive("This test is only applicable on Unix-based systems."); + return; + } + Cleanup(); CreateTestFolder(); @@ -165,8 +178,14 @@ public async Task MacCodeSignExecutable_ShouldLogError_WhenCodeSignFails() } [TestMethod] - public async Task MacXattrExecutable_ShouldLogError_WhenXattrFails() + public async Task MacXattrExecutable_ShouldLogError_WhenXattrFails__UnixOnly() { + if ( new AppSettings().IsWindows ) + { + Assert.Inconclusive("This test is only applicable on Unix-based systems."); + return; + } + // Arrange var exeFile = await CreateStubFiles(0, 1); From 3d1d08e54e214963d6a673928f78e346f8040edd Mon Sep 17 00:00:00 2001 From: Dion Date: Mon, 9 Dec 2024 23:30:28 +0100 Subject: [PATCH 48/73] #1833 add check for parent dir --- .../CreateAnZipFileMacOs/CreateAnZipFileMacOs.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/starsky/starskytest/FakeCreateAn/CreateAnZipFileMacOs/CreateAnZipFileMacOs.cs b/starsky/starskytest/FakeCreateAn/CreateAnZipFileMacOs/CreateAnZipFileMacOs.cs index 8ac1154ac4..be9478f919 100644 --- a/starsky/starskytest/FakeCreateAn/CreateAnZipFileMacOs/CreateAnZipFileMacOs.cs +++ b/starsky/starskytest/FakeCreateAn/CreateAnZipFileMacOs/CreateAnZipFileMacOs.cs @@ -32,8 +32,9 @@ public CreateAnZipFileMacOs() return; } - var path = Path.Combine(dirName, "FakeCreateAn", - "CreateAnZipFileMacOs", "ArchiveWithDotFiles.zip"); + var parentFolder = Path.Combine(dirName, "FakeCreateAn", + "CreateAnZipFileMacOs"); + var path = Path.Combine(parentFolder, "ArchiveWithDotFiles.zip"); FilePath = path; if ( File.Exists(path) ) @@ -41,6 +42,11 @@ public CreateAnZipFileMacOs() return; } + if ( !Directory.Exists(parentFolder) ) + { + Directory.CreateDirectory(parentFolder); + } + File.WriteAllBytes(path, Convert.FromBase64String(Base64ZipString)); } From d2cecda055ba53767bce27b6b1a4e42a2f16c4c2 Mon Sep 17 00:00:00 2001 From: Dion Date: Mon, 9 Dec 2024 23:37:11 +0100 Subject: [PATCH 49/73] #1833 exclude windows --- .../GetDependencies/MacCodeSignTests.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/starsky/starskytest/starsky.foundation.video/GetDependencies/MacCodeSignTests.cs b/starsky/starskytest/starsky.foundation.video/GetDependencies/MacCodeSignTests.cs index cc713f5797..ddf28b91de 100644 --- a/starsky/starskytest/starsky.foundation.video/GetDependencies/MacCodeSignTests.cs +++ b/starsky/starskytest/starsky.foundation.video/GetDependencies/MacCodeSignTests.cs @@ -163,8 +163,14 @@ public async Task MacCodeSignAndXattrExecutable_NotFound_ShouldReturnExpectedRes } [TestMethod] - public async Task MacCodeSignExecutable_ShouldLogError_WhenCodeSignFails() + public async Task MacCodeSignExecutable_ShouldLogError_WhenCodeSignFails__UnixOnly() { + if ( new AppSettings().IsWindows ) + { + Assert.Inconclusive("This test is only applicable on Unix-based systems."); + return; + } + // Arrange var exeFile = await CreateStubFiles(1, 0); From 4aba0a48e1ef5586413c87ac618ad34f82dbda50 Mon Sep 17 00:00:00 2001 From: Dion Date: Tue, 10 Dec 2024 23:20:56 +0100 Subject: [PATCH 50/73] #1833 refactorings --- .../ArchiveFormats/Interfaces/IZipper.cs | 6 + .../ArchiveFormats/Zipper.cs | 5 +- .../Helpers/CheckSha256Helper.cs | 2 + .../GetDependencies/FFMpegDownload.cs | 196 ---------- .../{FfmpegChmod.cs => FfMpegChmod.cs} | 10 +- .../GetDependencies/FfMpegDownload.cs | 113 ++++++ .../GetDependencies/FfMpegDownloadBinaries.cs | 93 +++++ .../{FfmpegExePath.cs => FfMpegExePath.cs} | 0 .../FfMpegPrepareBeforeRunning.cs | 59 +++ .../Interfaces/IFfMpegDownloadBinaries.cs | 10 + .../Interfaces/IFfMpegPrepareBeforeRunning.cs | 6 + .../Interfaces/IFfmpegChmod.cs | 6 + .../Models/FfmpegDownloadStatus.cs | 3 + .../CreateAnZipFileMacOs.cs | 4 + .../FakeMocks/FakeIFfMpegDownloadBinaries.cs | 24 ++ .../FakeIFfMpegPrepareBeforeRunning.cs | 13 + .../starskytest/FakeMocks/FakeIFfmpegChmod.cs | 15 + starsky/starskytest/FakeMocks/FakeIZipper.cs | 41 ++ ...fmpegChmodTests.cs => FfMpegChmodTests.cs} | 18 +- .../FfMpegDownloadBinariesTests.cs | 138 +++++++ .../GetDependencies/FfMpegDownloadTest.cs | 349 +++++++++++------- .../GetDependencies/MacCodeSignTests.cs | 6 +- 22 files changed, 762 insertions(+), 355 deletions(-) create mode 100644 starsky/starsky.foundation.storage/ArchiveFormats/Interfaces/IZipper.cs delete mode 100644 starsky/starsky.foundation.video/GetDependencies/FFMpegDownload.cs rename starsky/starsky.foundation.video/GetDependencies/{FfmpegChmod.cs => FfMpegChmod.cs} (62%) create mode 100644 starsky/starsky.foundation.video/GetDependencies/FfMpegDownload.cs create mode 100644 starsky/starsky.foundation.video/GetDependencies/FfMpegDownloadBinaries.cs rename starsky/starsky.foundation.video/GetDependencies/{FfmpegExePath.cs => FfMpegExePath.cs} (100%) create mode 100644 starsky/starsky.foundation.video/GetDependencies/FfMpegPrepareBeforeRunning.cs create mode 100644 starsky/starsky.foundation.video/GetDependencies/Interfaces/IFfMpegDownloadBinaries.cs create mode 100644 starsky/starsky.foundation.video/GetDependencies/Interfaces/IFfMpegPrepareBeforeRunning.cs create mode 100644 starsky/starsky.foundation.video/GetDependencies/Interfaces/IFfmpegChmod.cs create mode 100644 starsky/starskytest/FakeMocks/FakeIFfMpegDownloadBinaries.cs create mode 100644 starsky/starskytest/FakeMocks/FakeIFfMpegPrepareBeforeRunning.cs create mode 100644 starsky/starskytest/FakeMocks/FakeIFfmpegChmod.cs create mode 100644 starsky/starskytest/FakeMocks/FakeIZipper.cs rename starsky/starskytest/starsky.foundation.video/GetDependencies/{FfmpegChmodTests.cs => FfMpegChmodTests.cs} (88%) create mode 100644 starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadBinariesTests.cs diff --git a/starsky/starsky.foundation.storage/ArchiveFormats/Interfaces/IZipper.cs b/starsky/starsky.foundation.storage/ArchiveFormats/Interfaces/IZipper.cs new file mode 100644 index 0000000000..c2594c5c07 --- /dev/null +++ b/starsky/starsky.foundation.storage/ArchiveFormats/Interfaces/IZipper.cs @@ -0,0 +1,6 @@ +namespace starsky.foundation.storage.ArchiveFormats.Interfaces; + +public interface IZipper +{ + bool ExtractZip(string zipInputFullPath, string storeZipFolderFullPath); +} diff --git a/starsky/starsky.foundation.storage/ArchiveFormats/Zipper.cs b/starsky/starsky.foundation.storage/ArchiveFormats/Zipper.cs index 756a94c3b2..162316797d 100644 --- a/starsky/starsky.foundation.storage/ArchiveFormats/Zipper.cs +++ b/starsky/starsky.foundation.storage/ArchiveFormats/Zipper.cs @@ -3,15 +3,18 @@ using System.Diagnostics.CodeAnalysis; using System.IO; using System.IO.Compression; +using starsky.foundation.injection; using starsky.foundation.platform.Helpers; using starsky.foundation.platform.Interfaces; +using starsky.foundation.storage.ArchiveFormats.Interfaces; using starsky.foundation.storage.Storage; namespace starsky.foundation.storage.ArchiveFormats; [SuppressMessage("Performance", "CA1822:Mark members as static")] [SuppressMessage("ReSharper", "MemberCanBeMadeStatic.Global")] -public sealed class Zipper +[Service(typeof(IZipper), InjectionLifetime = InjectionLifetime.Scoped)] +public sealed class Zipper : IZipper { private readonly StorageHostFullPathFilesystem _hostStorage; private readonly IWebLogger _logger; diff --git a/starsky/starsky.foundation.storage/Helpers/CheckSha256Helper.cs b/starsky/starsky.foundation.storage/Helpers/CheckSha256Helper.cs index 8c00e83316..9433087cfa 100644 --- a/starsky/starsky.foundation.storage/Helpers/CheckSha256Helper.cs +++ b/starsky/starsky.foundation.storage/Helpers/CheckSha256Helper.cs @@ -22,6 +22,8 @@ public bool CheckSha256(string fullFilePath, IEnumerable checkSumOptions var byteHash = hashAlgorithm.ComputeHash(buffer); var hash = BitConverter.ToString(byteHash).Replace("-", string.Empty).ToLowerInvariant(); + + Console.WriteLine(hash); return checkSumOptions.AsEnumerable() .Any(p => p.Equals(hash, StringComparison.InvariantCultureIgnoreCase)); } diff --git a/starsky/starsky.foundation.video/GetDependencies/FFMpegDownload.cs b/starsky/starsky.foundation.video/GetDependencies/FFMpegDownload.cs deleted file mode 100644 index 1caa99c182..0000000000 --- a/starsky/starsky.foundation.video/GetDependencies/FFMpegDownload.cs +++ /dev/null @@ -1,196 +0,0 @@ -using starsky.foundation.http.Interfaces; -using starsky.foundation.injection; -using starsky.foundation.platform.Architecture; -using starsky.foundation.platform.Interfaces; -using starsky.foundation.platform.Models; -using starsky.foundation.storage.ArchiveFormats; -using starsky.foundation.storage.Helpers; -using starsky.foundation.storage.Storage; -using starsky.foundation.video.GetDependencies.Interfaces; -using starsky.foundation.video.GetDependencies.Models; - -namespace starsky.foundation.video.GetDependencies; - -[Service(typeof(IFfMpegDownload), InjectionLifetime = InjectionLifetime.Scoped)] -public class FfMpegDownload : IFfMpegDownload -{ - private readonly AppSettings _appSettings; - private readonly IFfMpegDownloadIndex _downloadIndex; - private readonly FfmpegChmod _ffmpegChmod; - private readonly FfmpegExePath _ffmpegExePath; - private readonly StorageHostFullPathFilesystem _hostFileSystemStorage; - private readonly IHttpClientHelper _httpClientHelper; - private readonly IWebLogger _logger; - private readonly IMacCodeSign _macCodeSign; - - public FfMpegDownload(IHttpClientHelper httpClientHelper, AppSettings appSettings, - IWebLogger logger, IMacCodeSign macCodeSign, IFfMpegDownloadIndex downloadIndex) - { - _httpClientHelper = httpClientHelper; - _appSettings = appSettings; - _hostFileSystemStorage = new StorageHostFullPathFilesystem(logger); - _logger = logger; - _macCodeSign = macCodeSign; - _downloadIndex = downloadIndex; - _ffmpegExePath = new FfmpegExePath(_appSettings); - _ffmpegChmod = new FfmpegChmod(_hostFileSystemStorage, _logger); - } - - public async Task DownloadFfMpeg() - { - if ( _appSettings.FfmpegSkipDownloadOnStartup == true - || _appSettings is { AddSwaggerExport: true, AddSwaggerExportExitAfter: true } ) - { - var name = _appSettings.FfmpegSkipDownloadOnStartup == true - ? "FFMpegSkipDownloadOnStartup" - : "AddSwaggerExport and AddSwaggerExportExitAfter"; - _logger.LogInformation($"[DownloadFFMpeg] Skipped due true of {name} setting"); - return FfmpegDownloadStatus.SettingsDisabled; - } - - CreateDirectoryDependenciesFolderIfNotExists(); - - var currentArchitecture = CurrentArchitecture.GetCurrentRuntimeIdentifier(); - - if ( _hostFileSystemStorage.ExistFile(_ffmpegExePath.GetExePath(currentArchitecture)) ) - { - return FfmpegDownloadStatus.Ok; - } - - var container = await _downloadIndex.DownloadIndex(); - if ( !container.Success ) - { - _logger.LogError("[FfMpegDownload] Index not found"); - return FfmpegDownloadStatus.DownloadIndexFailed; - } - - var binaryIndexBaseUrls = GetCurrentArchitectureIndexUrls(container, - currentArchitecture); - - var download = await Download(binaryIndexBaseUrls, currentArchitecture); - if ( download is null or false ) - { - _logger.LogError("[FfMpegDownload] Binaries not found"); - return FfmpegDownloadStatus.DownloadBinariesFailed; - } - - if ( !await PrepareBeforeRunning(currentArchitecture) ) - { - return FfmpegDownloadStatus.PrepareBeforeRunningFailed; - } - - return FfmpegDownloadStatus.Ok; - } - - private static KeyValuePair> GetCurrentArchitectureIndexUrls( - FfmpegBinariesContainer container, - string currentArchitecture) - { - var sortedData = container.Data?.Binaries.Find(p => - p.Architecture == currentArchitecture); - - return new KeyValuePair>(sortedData, container.BaseUrls); - } - - private async Task Download( - KeyValuePair> binaryIndexKeyValuePair, string currentArchitecture, - int retryInSeconds = 15) - { - var (binaryIndex, baseUrls) = binaryIndexKeyValuePair; - if ( binaryIndex?.FileName == null ) - { - return null; - } - - if ( _hostFileSystemStorage.ExistFile(_ffmpegExePath.GetExePath(currentArchitecture)) ) - { - return true; - } - - var zipFullFilePath = - Path.Combine(_appSettings.DependenciesFolder, binaryIndex.FileName); - - if ( !await DownloadMirror(baseUrls, zipFullFilePath, binaryIndex, retryInSeconds) ) - { - _logger.LogError("Download failed"); - return null; - } - - if ( !new CheckSha256Helper(_hostFileSystemStorage).CheckSha256(zipFullFilePath, - [binaryIndex.Sha256]) ) - { - _logger.LogError("Sha256 check failed"); - return null; - } - - new Zipper(_logger).ExtractZip(zipFullFilePath, _ffmpegExePath.GetExeParentFolder()); - - if ( !_hostFileSystemStorage.ExistFile(_ffmpegExePath.GetExePath(currentArchitecture)) ) - { - return false; - } - - _hostFileSystemStorage.FileDelete(zipFullFilePath); - return true; - } - - - private async Task PrepareBeforeRunning(string currentArchitecture) - { - var exeFile = _ffmpegExePath.GetExePath(currentArchitecture); - - if ( !_hostFileSystemStorage.ExistFile(Path.Combine(exeFile)) ) - { - return false; - } - - if ( currentArchitecture is "win-arm64" or "win-x64" ) - { - return true; - } - - if ( !await _ffmpegChmod.Chmod(exeFile) ) - { - return false; - } - - if ( currentArchitecture is "osx-x64" or "osx-arm64" ) - { - return await _macCodeSign.MacCodeSignAndXattrExecutable(exeFile) == true; - } - - return true; - } - - private async Task DownloadMirror(List baseUrls, string zipFullFilePath, - BinaryIndex binaryIndex, int retryInSeconds = 15) - { - foreach ( var uri in baseUrls.Select(baseUrl => new Uri(baseUrl + binaryIndex.FileName)) ) - { - if ( await _httpClientHelper.Download(uri, zipFullFilePath, retryInSeconds) ) - { - return true; - } - } - - return false; - } - - private void CreateDirectoryDependenciesFolderIfNotExists() - { - foreach ( var path in new List - { - _appSettings.DependenciesFolder, _ffmpegExePath.GetExeParentFolder() - } ) - { - if ( _hostFileSystemStorage.ExistFolder(path) ) - { - continue; - } - - _logger.LogInformation("[FfMpegDownload] Create Directory: " + - path); - _hostFileSystemStorage.CreateDirectory(path); - } - } -} diff --git a/starsky/starsky.foundation.video/GetDependencies/FfmpegChmod.cs b/starsky/starsky.foundation.video/GetDependencies/FfMpegChmod.cs similarity index 62% rename from starsky/starsky.foundation.video/GetDependencies/FfmpegChmod.cs rename to starsky/starsky.foundation.video/GetDependencies/FfMpegChmod.cs index 79d6ffb8e6..98bf42c047 100644 --- a/starsky/starsky.foundation.video/GetDependencies/FfmpegChmod.cs +++ b/starsky/starsky.foundation.video/GetDependencies/FfMpegChmod.cs @@ -1,13 +1,17 @@ using Medallion.Shell; +using starsky.foundation.injection; using starsky.foundation.platform.Interfaces; using starsky.foundation.storage.Interfaces; +using starsky.foundation.video.GetDependencies.Interfaces; namespace starsky.foundation.video.GetDependencies; -public class FfmpegChmod(IStorage hostFileSystemStorage, IWebLogger logger) +[Service(typeof(IFfmpegChmod), InjectionLifetime = InjectionLifetime.Scoped)] +public class FfMpegChmod(IStorage hostFileSystemStorage, IWebLogger logger) : IFfmpegChmod { - public string CmdPath { get; set; } = "/bin/chmod"; - internal async Task Chmod(string exeFile) + internal string CmdPath { get; set; } = "/bin/chmod"; + + public async Task Chmod(string exeFile) { if ( !hostFileSystemStorage.ExistFile(CmdPath) ) { diff --git a/starsky/starsky.foundation.video/GetDependencies/FfMpegDownload.cs b/starsky/starsky.foundation.video/GetDependencies/FfMpegDownload.cs new file mode 100644 index 0000000000..8d5fb05f9b --- /dev/null +++ b/starsky/starsky.foundation.video/GetDependencies/FfMpegDownload.cs @@ -0,0 +1,113 @@ +using starsky.foundation.injection; +using starsky.foundation.platform.Architecture; +using starsky.foundation.platform.Interfaces; +using starsky.foundation.platform.Models; +using starsky.foundation.storage.Interfaces; +using starsky.foundation.storage.Storage; +using starsky.foundation.video.GetDependencies.Interfaces; +using starsky.foundation.video.GetDependencies.Models; + +namespace starsky.foundation.video.GetDependencies; + +[Service(typeof(IFfMpegDownload), InjectionLifetime = InjectionLifetime.Scoped)] +public class FfMpegDownload : IFfMpegDownload +{ + private readonly AppSettings _appSettings; + private readonly IFfMpegDownloadBinaries _downloadBinaries; + private readonly IFfMpegDownloadIndex _downloadIndex; + private readonly FfmpegExePath _ffmpegExePath; + private readonly IStorage _hostFileSystemStorage; + private readonly IWebLogger _logger; + private readonly IFfMpegPrepareBeforeRunning _prepareBeforeRunning; + + public FfMpegDownload(ISelectorStorage selectorStorage, + AppSettings appSettings, + IWebLogger logger, IFfMpegDownloadIndex downloadIndex, + IFfMpegDownloadBinaries downloadBinaries, IFfMpegPrepareBeforeRunning prepareBeforeRunning) + { + _appSettings = appSettings; + _hostFileSystemStorage = + selectorStorage.Get(SelectorStorage.StorageServices.HostFilesystem); + _logger = logger; + _downloadIndex = downloadIndex; + _ffmpegExePath = new FfmpegExePath(_appSettings); + _downloadBinaries = downloadBinaries; + _prepareBeforeRunning = prepareBeforeRunning; + } + + public async Task DownloadFfMpeg() + { + if ( _appSettings.FfmpegSkipDownloadOnStartup == true + || _appSettings is { AddSwaggerExport: true, AddSwaggerExportExitAfter: true } ) + { + var name = _appSettings.FfmpegSkipDownloadOnStartup == true + ? "FFMpegSkipDownloadOnStartup" + : "AddSwaggerExport and AddSwaggerExportExitAfter"; + _logger.LogInformation($"[DownloadFFMpeg] Skipped due true of {name} setting"); + return FfmpegDownloadStatus.SettingsDisabled; + } + + CreateDirectoryDependenciesFolderIfNotExists(); + + var currentArchitecture = CurrentArchitecture.GetCurrentRuntimeIdentifier(); + + if ( _hostFileSystemStorage.ExistFile(_ffmpegExePath.GetExePath(currentArchitecture)) ) + { + return FfmpegDownloadStatus.Ok; + } + + var container = await _downloadIndex.DownloadIndex(); + if ( !container.Success ) + { + _logger.LogError("[FfMpegDownload] Index not found"); + return FfmpegDownloadStatus.DownloadIndexFailed; + } + + var binaryIndexBaseUrls = GetCurrentArchitectureIndexUrls(container, + currentArchitecture); + + var downloadStatus = + await _downloadBinaries.Download(binaryIndexBaseUrls, currentArchitecture); + if ( downloadStatus != FfmpegDownloadStatus.Ok ) + { + _logger.LogError($"[FfMpegDownload] Binaries downloading failed {downloadStatus}"); + return downloadStatus; + } + + if ( !await _prepareBeforeRunning.PrepareBeforeRunning(currentArchitecture) ) + { + return FfmpegDownloadStatus.PrepareBeforeRunningFailed; + } + + return FfmpegDownloadStatus.Ok; + } + + private static KeyValuePair> GetCurrentArchitectureIndexUrls( + FfmpegBinariesContainer container, + string currentArchitecture) + { + var sortedData = container.Data?.Binaries.Find(p => + p.Architecture == currentArchitecture); + + return new KeyValuePair>(sortedData, container.BaseUrls); + } + + + private void CreateDirectoryDependenciesFolderIfNotExists() + { + foreach ( var path in new List + { + _appSettings.DependenciesFolder, _ffmpegExePath.GetExeParentFolder() + } ) + { + if ( _hostFileSystemStorage.ExistFolder(path) ) + { + continue; + } + + _logger.LogInformation("[FfMpegDownload] Create Directory: " + + path); + _hostFileSystemStorage.CreateDirectory(path); + } + } +} diff --git a/starsky/starsky.foundation.video/GetDependencies/FfMpegDownloadBinaries.cs b/starsky/starsky.foundation.video/GetDependencies/FfMpegDownloadBinaries.cs new file mode 100644 index 0000000000..48cd799cd4 --- /dev/null +++ b/starsky/starsky.foundation.video/GetDependencies/FfMpegDownloadBinaries.cs @@ -0,0 +1,93 @@ +using starsky.foundation.http.Interfaces; +using starsky.foundation.injection; +using starsky.foundation.platform.Interfaces; +using starsky.foundation.platform.Models; +using starsky.foundation.storage.ArchiveFormats.Interfaces; +using starsky.foundation.storage.Helpers; +using starsky.foundation.storage.Interfaces; +using starsky.foundation.storage.Storage; +using starsky.foundation.video.GetDependencies.Interfaces; +using starsky.foundation.video.GetDependencies.Models; + +namespace starsky.foundation.video.GetDependencies; + +[Service(typeof(IFfMpegDownloadBinaries), InjectionLifetime = InjectionLifetime.Scoped)] +public class FfMpegDownloadBinaries : IFfMpegDownloadBinaries +{ + private readonly AppSettings _appSettings; + private readonly FfmpegExePath _ffmpegExePath; + private readonly IStorage _hostFileSystemStorage; + private readonly IHttpClientHelper _httpClientHelper; + private readonly IWebLogger _logger; + private readonly IZipper _zipper; + + public FfMpegDownloadBinaries(ISelectorStorage selectorStorage, + IHttpClientHelper httpClientHelper, AppSettings appSettings, IWebLogger logger, + IZipper zipper) + { + _appSettings = appSettings; + _httpClientHelper = httpClientHelper; + _logger = logger; + _ffmpegExePath = new FfmpegExePath(appSettings); + _hostFileSystemStorage = + selectorStorage.Get(SelectorStorage.StorageServices.HostFilesystem); + _zipper = zipper; + } + + public async Task Download( + KeyValuePair> binaryIndexKeyValuePair, string currentArchitecture, + int retryInSeconds = 15) + { + var (binaryIndex, baseUrls) = binaryIndexKeyValuePair; + if ( binaryIndex?.FileName == null ) + { + return FfmpegDownloadStatus.DownloadBinariesFailedMissingFileName; + } + + if ( _hostFileSystemStorage.ExistFile(_ffmpegExePath.GetExePath(currentArchitecture)) ) + { + return FfmpegDownloadStatus.Ok; + } + + var zipFullFilePath = + Path.Combine(_appSettings.DependenciesFolder, binaryIndex.FileName); + + if ( !await DownloadMirror(baseUrls, zipFullFilePath, binaryIndex, retryInSeconds) ) + { + _logger.LogError("Download failed"); + return FfmpegDownloadStatus.DownloadBinariesFailed; + } + + if ( !new CheckSha256Helper(_hostFileSystemStorage).CheckSha256(zipFullFilePath, + [binaryIndex.Sha256]) ) + { + _logger.LogError("Sha256 check failed"); + return FfmpegDownloadStatus.DownloadBinariesFailedSha256Check; + } + + _zipper.ExtractZip(zipFullFilePath, _ffmpegExePath.GetExeParentFolder()); + + if ( !_hostFileSystemStorage.ExistFile(_ffmpegExePath.GetExePath(currentArchitecture)) ) + { + return FfmpegDownloadStatus.DownloadBinariesFailedZipperNotExtracted; + } + + _hostFileSystemStorage.FileDelete(zipFullFilePath); + + return FfmpegDownloadStatus.Ok; + } + + private async Task DownloadMirror(List baseUrls, string zipFullFilePath, + BinaryIndex binaryIndex, int retryInSeconds = 15) + { + foreach ( var uri in baseUrls.Select(baseUrl => new Uri(baseUrl + binaryIndex.FileName)) ) + { + if ( await _httpClientHelper.Download(uri, zipFullFilePath, retryInSeconds) ) + { + return true; + } + } + + return false; + } +} diff --git a/starsky/starsky.foundation.video/GetDependencies/FfmpegExePath.cs b/starsky/starsky.foundation.video/GetDependencies/FfMpegExePath.cs similarity index 100% rename from starsky/starsky.foundation.video/GetDependencies/FfmpegExePath.cs rename to starsky/starsky.foundation.video/GetDependencies/FfMpegExePath.cs diff --git a/starsky/starsky.foundation.video/GetDependencies/FfMpegPrepareBeforeRunning.cs b/starsky/starsky.foundation.video/GetDependencies/FfMpegPrepareBeforeRunning.cs new file mode 100644 index 0000000000..2523b6bd85 --- /dev/null +++ b/starsky/starsky.foundation.video/GetDependencies/FfMpegPrepareBeforeRunning.cs @@ -0,0 +1,59 @@ +using starsky.foundation.injection; +using starsky.foundation.platform.Interfaces; +using starsky.foundation.platform.Models; +using starsky.foundation.storage.Interfaces; +using starsky.foundation.storage.Storage; +using starsky.foundation.video.GetDependencies.Interfaces; + +namespace starsky.foundation.video.GetDependencies; + +[Service(typeof(IFfMpegPrepareBeforeRunning), InjectionLifetime = InjectionLifetime.Scoped)] +public class FfMpegPrepareBeforeRunning : IFfMpegPrepareBeforeRunning +{ + private readonly IFfmpegChmod _ffmpegChmod; + private readonly FfmpegExePath _ffmpegExePath; + private readonly IStorage _hostFileSystemStorage; + private readonly IWebLogger _logger; + private readonly IMacCodeSign _macCodeSign; + + public FfMpegPrepareBeforeRunning(ISelectorStorage selectorStorage, IMacCodeSign macCodeSign, + IFfmpegChmod ffmpegChmod, + AppSettings appSettings, IWebLogger logger) + { + _hostFileSystemStorage = + selectorStorage.Get(SelectorStorage.StorageServices.HostFilesystem); + _ffmpegExePath = new FfmpegExePath(appSettings); + _macCodeSign = macCodeSign; + _ffmpegChmod = ffmpegChmod; + _logger = logger; + } + + public async Task PrepareBeforeRunning(string currentArchitecture) + { + var exeFile = _ffmpegExePath.GetExePath(currentArchitecture); + + if ( !_hostFileSystemStorage.ExistFile(exeFile) ) + { + _logger.LogError($"[FfMpegDownload] exeFile {exeFile} does not exist"); + return false; + } + + if ( currentArchitecture is "win-arm64" or "win-x64" ) + { + return true; + } + + if ( !await _ffmpegChmod.Chmod(exeFile) ) + { + _logger.LogError("[FfMpegDownload] Chmod failed"); + return false; + } + + if ( currentArchitecture is "osx-x64" or "osx-arm64" ) + { + return await _macCodeSign.MacCodeSignAndXattrExecutable(exeFile) == true; + } + + return true; + } +} diff --git a/starsky/starsky.foundation.video/GetDependencies/Interfaces/IFfMpegDownloadBinaries.cs b/starsky/starsky.foundation.video/GetDependencies/Interfaces/IFfMpegDownloadBinaries.cs new file mode 100644 index 0000000000..ae815f5088 --- /dev/null +++ b/starsky/starsky.foundation.video/GetDependencies/Interfaces/IFfMpegDownloadBinaries.cs @@ -0,0 +1,10 @@ +using starsky.foundation.video.GetDependencies.Models; + +namespace starsky.foundation.video.GetDependencies.Interfaces; + +public interface IFfMpegDownloadBinaries +{ + Task Download( + KeyValuePair> binaryIndexKeyValuePair, string currentArchitecture, + int retryInSeconds = 15); +} diff --git a/starsky/starsky.foundation.video/GetDependencies/Interfaces/IFfMpegPrepareBeforeRunning.cs b/starsky/starsky.foundation.video/GetDependencies/Interfaces/IFfMpegPrepareBeforeRunning.cs new file mode 100644 index 0000000000..4ade504251 --- /dev/null +++ b/starsky/starsky.foundation.video/GetDependencies/Interfaces/IFfMpegPrepareBeforeRunning.cs @@ -0,0 +1,6 @@ +namespace starsky.foundation.video.GetDependencies.Interfaces; + +public interface IFfMpegPrepareBeforeRunning +{ + Task PrepareBeforeRunning(string currentArchitecture); +} diff --git a/starsky/starsky.foundation.video/GetDependencies/Interfaces/IFfmpegChmod.cs b/starsky/starsky.foundation.video/GetDependencies/Interfaces/IFfmpegChmod.cs new file mode 100644 index 0000000000..cccbae3672 --- /dev/null +++ b/starsky/starsky.foundation.video/GetDependencies/Interfaces/IFfmpegChmod.cs @@ -0,0 +1,6 @@ +namespace starsky.foundation.video.GetDependencies.Interfaces; + +public interface IFfmpegChmod +{ + Task Chmod(string exeFile); +} diff --git a/starsky/starsky.foundation.video/GetDependencies/Models/FfmpegDownloadStatus.cs b/starsky/starsky.foundation.video/GetDependencies/Models/FfmpegDownloadStatus.cs index 1e177738bb..77a4a3212f 100644 --- a/starsky/starsky.foundation.video/GetDependencies/Models/FfmpegDownloadStatus.cs +++ b/starsky/starsky.foundation.video/GetDependencies/Models/FfmpegDownloadStatus.cs @@ -6,5 +6,8 @@ public enum FfmpegDownloadStatus SettingsDisabled, DownloadIndexFailed, DownloadBinariesFailed, + DownloadBinariesFailedMissingFileName, + DownloadBinariesFailedSha256Check, + DownloadBinariesFailedZipperNotExtracted, PrepareBeforeRunningFailed } diff --git a/starsky/starskytest/FakeCreateAn/CreateAnZipFileMacOs/CreateAnZipFileMacOs.cs b/starsky/starskytest/FakeCreateAn/CreateAnZipFileMacOs/CreateAnZipFileMacOs.cs index be9478f919..7d6017cb98 100644 --- a/starsky/starskytest/FakeCreateAn/CreateAnZipFileMacOs/CreateAnZipFileMacOs.cs +++ b/starsky/starskytest/FakeCreateAn/CreateAnZipFileMacOs/CreateAnZipFileMacOs.cs @@ -1,8 +1,10 @@ using System; using System.Collections.Generic; +using System.Collections.Immutable; using System.Diagnostics.CodeAnalysis; using System.IO; using System.Reflection; +using starsky.foundation.platform.Helpers; namespace starskytest.FakeCreateAn.CreateAnZipFileMacOs; @@ -24,6 +26,8 @@ public class CreateAnZipFileMacOs "SV2d1eAsAAQT1AQAABBQAAABQSwUGAAAAAAI" + "AAgCrAAAABwEAAAAA"; + public static readonly ImmutableArray Bytes = [..Base64Helper.TryParse(Base64ZipString)]; + public CreateAnZipFileMacOs() { var dirName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); diff --git a/starsky/starskytest/FakeMocks/FakeIFfMpegDownloadBinaries.cs b/starsky/starskytest/FakeMocks/FakeIFfMpegDownloadBinaries.cs new file mode 100644 index 0000000000..80a7017c82 --- /dev/null +++ b/starsky/starskytest/FakeMocks/FakeIFfMpegDownloadBinaries.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using starsky.foundation.video.GetDependencies.Interfaces; +using starsky.foundation.video.GetDependencies.Models; + +namespace starskytest.FakeMocks; + +public class FakeIFfMpegDownloadBinaries : IFfMpegDownloadBinaries +{ + private readonly FfmpegDownloadStatus? _status; + + public FakeIFfMpegDownloadBinaries(FfmpegDownloadStatus? status = null) + { + _status = status; + } + + public Task Download( + KeyValuePair> binaryIndexKeyValuePair, string currentArchitecture, + int retryInSeconds = 15) + { + return Task.FromResult(_status ?? FfmpegDownloadStatus.Ok); + } +} diff --git a/starsky/starskytest/FakeMocks/FakeIFfMpegPrepareBeforeRunning.cs b/starsky/starskytest/FakeMocks/FakeIFfMpegPrepareBeforeRunning.cs new file mode 100644 index 0000000000..714dffbe80 --- /dev/null +++ b/starsky/starskytest/FakeMocks/FakeIFfMpegPrepareBeforeRunning.cs @@ -0,0 +1,13 @@ +using System; +using System.Threading.Tasks; +using starsky.foundation.video.GetDependencies.Interfaces; + +namespace starskytest.FakeMocks; + +public class FakeIFfMpegPrepareBeforeRunning : IFfMpegPrepareBeforeRunning +{ + public Task PrepareBeforeRunning(string currentArchitecture) + { + throw new NotImplementedException(); + } +} diff --git a/starsky/starskytest/FakeMocks/FakeIFfmpegChmod.cs b/starsky/starskytest/FakeMocks/FakeIFfmpegChmod.cs new file mode 100644 index 0000000000..5bb26af713 --- /dev/null +++ b/starsky/starskytest/FakeMocks/FakeIFfmpegChmod.cs @@ -0,0 +1,15 @@ +using System.Threading.Tasks; +using starsky.foundation.storage.Interfaces; +using starsky.foundation.video.GetDependencies; +using starsky.foundation.video.GetDependencies.Interfaces; + +namespace starskytest.FakeMocks; + +public class FakeIFfmpegChmod(IStorage hostFileSystemStorage) : IFfmpegChmod +{ + public Task Chmod(string exeFile) + { + return Task.FromResult(hostFileSystemStorage.ExistFile( + new FfMpegChmod(hostFileSystemStorage, new FakeIWebLogger()).CmdPath)); + } +} diff --git a/starsky/starskytest/FakeMocks/FakeIZipper.cs b/starsky/starskytest/FakeMocks/FakeIZipper.cs new file mode 100644 index 0000000000..12ea20777e --- /dev/null +++ b/starsky/starskytest/FakeMocks/FakeIZipper.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using starsky.foundation.storage.ArchiveFormats; +using starsky.foundation.storage.ArchiveFormats.Interfaces; +using starsky.foundation.storage.Interfaces; + +namespace starskytest.FakeMocks; + +public class FakeIZipper : IZipper +{ + private readonly IStorage _storage; + private readonly List> _zipContent; + + public FakeIZipper(List> zipContent, IStorage storage) + { + _storage = storage; + _zipContent = zipContent; + } + + public bool ExtractZip(string zipInputFullPath, string storeZipFolderFullPath) + { + var bytes = _zipContent.FirstOrDefault(p => p.Item1 == zipInputFullPath)?.Item2; + if ( bytes == null ) + { + Console.WriteLine("ExtractZip: " + zipInputFullPath + " not found"); + return false; + } + + foreach ( var values in Zipper.ExtractZip(bytes) ) + { + var outputPath = Path.Combine(storeZipFolderFullPath, values.Key); + Console.WriteLine("ExtractZip: " + zipInputFullPath + " to " + outputPath); + + _storage.WriteStream(new MemoryStream(values.Value), outputPath); + } + + return true; + } +} diff --git a/starsky/starskytest/starsky.foundation.video/GetDependencies/FfmpegChmodTests.cs b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegChmodTests.cs similarity index 88% rename from starsky/starskytest/starsky.foundation.video/GetDependencies/FfmpegChmodTests.cs rename to starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegChmodTests.cs index ec57677410..5d9deca683 100644 --- a/starsky/starskytest/starsky.foundation.video/GetDependencies/FfmpegChmodTests.cs +++ b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegChmodTests.cs @@ -15,20 +15,20 @@ namespace starskytest.starsky.foundation.video.GetDependencies; [TestClass] -public class FfmpegChmodTests +public class FfMpegChmodTests { - private readonly FfmpegChmod _ffmpegChmod; + private readonly FfMpegChmod _ffMpegChmod; private readonly FfmpegExePath _ffmpegExePath; private readonly StorageHostFullPathFilesystem _hostFileSystemStorage; private readonly bool _isWindows; private readonly IWebLogger _logger; private readonly string _parentFolder; - public FfmpegChmodTests() + public FfMpegChmodTests() { _hostFileSystemStorage = new StorageHostFullPathFilesystem(new FakeIWebLogger()); _logger = new FakeIWebLogger(); - _ffmpegChmod = new FfmpegChmod(_hostFileSystemStorage, _logger); + _ffMpegChmod = new FfMpegChmod(_hostFileSystemStorage, _logger); _parentFolder = Path.Combine(new CreateAnImage().BasePath, "FfmpegChmodTests"); @@ -58,7 +58,7 @@ private void DeleteFile() [TestMethod] public async Task Chmod_ShouldReturnFalse_WhenChmodDoesNotExist() { - var sut = new FfmpegChmod(new FakeIStorage(), new FakeIWebLogger()); + var sut = new FfMpegChmod(new FakeIStorage(), new FakeIWebLogger()); var result = await sut.Chmod(_ffmpegExePath.GetExePath("linux-x64")); Assert.IsFalse(result); @@ -75,7 +75,7 @@ public async Task Chmod_ShouldReturnTrue_WhenCommandSucceeds__UnixOnly() CreateFile(); - var result = await _ffmpegChmod.Chmod(_ffmpegExePath.GetExePath("linux-x64")); + var result = await _ffMpegChmod.Chmod(_ffmpegExePath.GetExePath("linux-x64")); var lsLah = await Command.Run("ls", "-lah", _ffmpegExePath.GetExePath("linux-x64")).Task; @@ -95,7 +95,7 @@ public async Task Chmod_ShouldReturnFalse_WhenCommandFails__UnixOnly() return; } - var sut = new FfmpegChmod(new FakeIStorage([], + var sut = new FfMpegChmod(new FakeIStorage([], ["/bin/chmod"]), new FakeIWebLogger()); @@ -115,7 +115,7 @@ public async Task Chmod_ShouldReturnFalse_WhenCommandSucceed__WindowsOnly() CreateFile(); var path = Path.Combine(_ffmpegExePath.GetExeParentFolder(), "chmod.exe"); - var sut = new FfmpegChmod(new FakeIStorage([], + var sut = new FfMpegChmod(new FakeIStorage([], [path]), new FakeIWebLogger()) { CmdPath = path }; @@ -134,7 +134,7 @@ public async Task Chmod_ShouldLogError_WhenCommandFails__UnixOnly() return; } - var result = await _ffmpegChmod.Chmod("/_not_found_path/to/ffmpeg"); + var result = await _ffMpegChmod.Chmod("/_not_found_path/to/ffmpeg"); Assert.IsFalse(result); Assert.IsTrue(( ( FakeIWebLogger ) _logger ).TrackedExceptions.Exists(entry => diff --git a/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadBinariesTests.cs b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadBinariesTests.cs new file mode 100644 index 0000000000..1921db31cf --- /dev/null +++ b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadBinariesTests.cs @@ -0,0 +1,138 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using starsky.foundation.platform.Models; +using starsky.foundation.storage.ArchiveFormats; +using starsky.foundation.video.GetDependencies; +using starsky.foundation.video.GetDependencies.Models; +using starskytest.FakeCreateAn.CreateAnZipFileMacOs; +using starskytest.FakeMocks; + +namespace starskytest.starsky.foundation.video.GetDependencies; + +[TestClass] +public class FfMpegDownloadBinariesTests +{ + private readonly AppSettings _appSettings = new(); + private readonly FakeIHttpClientHelper _httpClientHelper; + private readonly FakeIWebLogger _logger = new(); + private readonly FakeIStorage _storage = new(); + + public FfMpegDownloadBinariesTests() + { + _httpClientHelper = + new FakeIHttpClientHelper(_storage, + new Dictionary> + { + { + "https://qdraw.nl/mock_test.zip", new KeyValuePair( + true, + "VGVzdENvbnRlbnQ=") + } + }); + } + + [TestMethod] + public async Task Download_MissingFileName() + { + var sut = new FfMpegDownloadBinaries(new FakeSelectorStorage(_storage), _httpClientHelper, + _appSettings, _logger, new Zipper(new FakeIWebLogger())); + + var baseUrls = new List { new("https://qdraw.nl/") }; + var binaryIndexKeyValuePair = new KeyValuePair>(null, baseUrls); + + var result = await sut.Download(binaryIndexKeyValuePair, string.Empty); + + Assert.AreEqual(FfmpegDownloadStatus.DownloadBinariesFailedMissingFileName, result); + } + + [TestMethod] + public async Task Download_InvalidDownload() + { + var sut = new FfMpegDownloadBinaries(new FakeSelectorStorage(_storage), _httpClientHelper, + _appSettings, _logger, new Zipper(new FakeIWebLogger())); + + var binaryIndex = new BinaryIndex + { + FileName = "NOT_FOUND.zip", Sha256 = "dummysha256", Architecture = "linux-x64" + }; + var baseUrls = new List { new("https://qdraw.nl/") }; + var binaryIndexKeyValuePair = + new KeyValuePair>(binaryIndex, baseUrls); + + var result = await sut.Download(binaryIndexKeyValuePair, "linux-x64"); + + Assert.AreEqual(FfmpegDownloadStatus.DownloadBinariesFailed, result); + } + + + [TestMethod] + public async Task Download_InvalidShaHash() + { + var sut = new FfMpegDownloadBinaries(new FakeSelectorStorage(_storage), _httpClientHelper, + _appSettings, _logger, new Zipper(new FakeIWebLogger())); + + var binaryIndex = new BinaryIndex + { + FileName = "mock_test.zip", Sha256 = "dummysha256", Architecture = "linux-x64" + }; + var baseUrls = new List { new("https://qdraw.nl/") }; + var binaryIndexKeyValuePair = + new KeyValuePair>(binaryIndex, baseUrls); + + var result = await sut.Download(binaryIndexKeyValuePair, "linux-x64"); + + Assert.AreEqual(FfmpegDownloadStatus.DownloadBinariesFailedSha256Check, result); + } + + [TestMethod] + public async Task Download_DownloadBinariesFailedZipperNotExtracted() + { + var sut = new FfMpegDownloadBinaries(new FakeSelectorStorage(_storage), _httpClientHelper, + _appSettings, _logger, new Zipper(new FakeIWebLogger())); + + var binaryIndex = new BinaryIndex + { + FileName = "mock_test.zip", + Sha256 = "b98fc09ac0df3bbc1ee5e79316604f7462fffdf095c1c676e3c2517773645fe9", + Architecture = "linux-x64" + }; + var baseUrls = new List { new("https://qdraw.nl/") }; + var binaryIndexKeyValuePair = + new KeyValuePair>(binaryIndex, baseUrls); + + var result = await sut.Download(binaryIndexKeyValuePair, "linux-x64"); + + Assert.AreEqual(FfmpegDownloadStatus.DownloadBinariesFailedZipperNotExtracted, result); + } + + [TestMethod] + public async Task Download_DownloadBinariesFailedZipperNotExtracted11() + { + // TODO fix + + var storage = new FakeIStorage(); + var zipper = new FakeIZipper(new List> + { + new("FfMpegDownloadTest/mock_test.zip", + [.. CreateAnZipFileMacOs.Bytes]) + }, storage); + var sut = new FfMpegDownloadBinaries(new FakeSelectorStorage(storage), _httpClientHelper, + _appSettings, _logger, zipper); + + var binaryIndex = new BinaryIndex + { + FileName = "mock_test.zip", + Sha256 = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + Architecture = "linux-x64" + }; + var baseUrls = new List { new("https://qdraw.nl/") }; + var binaryIndexKeyValuePair = + new KeyValuePair>(binaryIndex, baseUrls); + + var result = await sut.Download(binaryIndexKeyValuePair, "linux-x64"); + + Assert.AreEqual(FfmpegDownloadStatus.DownloadBinariesFailedZipperNotExtracted, result); + } +} diff --git a/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadTest.cs b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadTest.cs index 28cc5b7e28..3e5dd7ca19 100644 --- a/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadTest.cs +++ b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadTest.cs @@ -1,11 +1,16 @@ +using System; using System.Collections.Generic; +using System.Linq; using System.Text.Json; using System.Threading.Tasks; using Microsoft.VisualStudio.TestTools.UnitTesting; +using starsky.foundation.platform.Architecture; using starsky.foundation.platform.JsonConverter; using starsky.foundation.platform.Models; +using starsky.foundation.storage.ArchiveFormats; using starsky.foundation.video.GetDependencies; using starsky.foundation.video.GetDependencies.Models; +using starskytest.FakeCreateAn.CreateAnZipFileMacOs; using starskytest.FakeMocks; namespace starskytest.starsky.foundation.video.GetDependencies; @@ -14,41 +19,14 @@ namespace starskytest.starsky.foundation.video.GetDependencies; public class FfMpegDownloadTest { private const string DependencyFolderName = "FfMpegDownloadTest"; - private readonly FakeIHttpClientHelper _emptyHttpClientHelper; + private readonly FfmpegBinariesIndex _exampleFfmpegBinariesIndex; private readonly FakeIHttpClientHelper _httpClientHelper; private readonly FakeIStorage _storage = new(); public FfMpegDownloadTest() { - _emptyHttpClientHelper = - new FakeIHttpClientHelper(_storage, - new Dictionary>()); - - var example = new FfmpegBinariesIndex - { - Binaries = new List - { - new() - { - Architecture = "win-x64", - FileName = "test.zip", - Sha256 = "test-sha256" - }, - new() - { - Architecture = "osx-x64", - FileName = "test.zip", - Sha256 = "test-sha256" - }, - new() - { - Architecture = "linux-x64", - FileName = "test.zip", - Sha256 = "test-sha256" - } - } - }; + _exampleFfmpegBinariesIndex = CreateExampleFile(); _httpClientHelper = new FakeIHttpClientHelper(_storage, @@ -58,11 +36,51 @@ public FfMpegDownloadTest() FfMpegDownloadIndex.FfMpegApiIndex.ToString(), new KeyValuePair( true, - JsonSerializer.Serialize(example, DefaultJsonSerializer.CamelCase)) + JsonSerializer.Serialize(_exampleFfmpegBinariesIndex, + DefaultJsonSerializer.CamelCase)) + }, + { + "https://qdraw.nl/mock_test.zip", new KeyValuePair( + true, + "VGVzdENvbnRlbnQ=") } }); } + private static FfmpegBinariesIndex CreateExampleFile(string sha256 = "invalid-sha256") + { + return new FfmpegBinariesIndex + { + Binaries = + [ + new BinaryIndex + { + Architecture = "win-x64", FileName = "mock_test.zip", Sha256 = sha256 + }, + new BinaryIndex + { + Architecture = "osx-x64", FileName = "mock_test.zip", Sha256 = sha256 + }, + new BinaryIndex + { + Architecture = "linux-x64", FileName = "mock_test.zip", Sha256 = sha256 + }, + new BinaryIndex + { + Architecture = "osx-arm64", FileName = "mock_test.zip", Sha256 = sha256 + }, + new BinaryIndex + { + Architecture = "linux-arm64", FileName = "mock_test.zip", Sha256 = sha256 + }, + new BinaryIndex + { + Architecture = "linux-arm", FileName = "mock_test.zip", Sha256 = sha256 + } + ] + }; + } + // [TestMethod] // public async Task DownloadFfMpegTest() // { @@ -97,11 +115,11 @@ public async Task DownloadFfMpeg_ShouldSkipDueToSettings(string settingName) } var logger = new FakeIWebLogger(); - var macCodeSign = new FakeIMacCodeSign(); var ffmpegDownload = - new FfMpegDownload(_emptyHttpClientHelper, appSettings, logger, macCodeSign, - new FakeIFfMpegDownloadIndex()); + new FfMpegDownload(new FakeSelectorStorage(), appSettings, + logger, new FakeIFfMpegDownloadIndex(), new FakeIFfMpegDownloadBinaries(), + new FakeIFfMpegPrepareBeforeRunning()); var result = await ffmpegDownload.DownloadFfMpeg(); @@ -113,11 +131,12 @@ public async Task DownloadFfMpeg_MissingIndex() { var appSettings = new AppSettings { DependenciesFolder = DependencyFolderName }; var logger = new FakeIWebLogger(); - var macCodeSign = new FakeIMacCodeSign(); var ffmpegDownload = - new FfMpegDownload(_emptyHttpClientHelper, appSettings, logger, macCodeSign, - new FakeIFfMpegDownloadIndex()); + new FfMpegDownload(new FakeSelectorStorage(), appSettings, + logger, + new FakeIFfMpegDownloadIndex(), new FakeIFfMpegDownloadBinaries(), + new FakeIFfMpegPrepareBeforeRunning()); var result = await ffmpegDownload.DownloadFfMpeg(); @@ -129,123 +148,167 @@ public async Task DownloadFfMpeg_DownloadBinariesFail() { var appSettings = new AppSettings { DependenciesFolder = DependencyFolderName }; var logger = new FakeIWebLogger(); - var macCodeSign = new FakeIMacCodeSign(); var ffmpegDownload = - new FfMpegDownload(_httpClientHelper, appSettings, logger, macCodeSign, + new FfMpegDownload(new FakeSelectorStorage(), appSettings, logger, new FakeIFfMpegDownloadIndex(new FfmpegBinariesContainer { Success = true, Data = new FfmpegBinariesIndex { Binaries = new List() } - })); + }), + new FakeIFfMpegDownloadBinaries(FfmpegDownloadStatus + .DownloadBinariesFailedMissingFileName), new FakeIFfMpegPrepareBeforeRunning()); var result = await ffmpegDownload.DownloadFfMpeg(); - Assert.AreEqual(FfmpegDownloadStatus.DownloadBinariesFailed, result); + Assert.AreEqual(FfmpegDownloadStatus.DownloadBinariesFailedMissingFileName, result); } - // [TestMethod] - // public async Task DownloadFfMpeg_DownloadBinariesFail() - // { - // var appSettings = new AppSettings { DependenciesFolder = DependencyFolderName }; - // var logger = new FakeIWebLogger(); - // var macCodeSign = new FakeIMacCodeSign(); - // - // var ffmpegDownload = - // new FfMpegDownload(_httpClientHelper, appSettings, logger, macCodeSign, - // new FakeIFfMpegDownloadIndex(new FfmpegBinariesContainer - // { - // Success = true, - // Data = new FfmpegBinariesIndex { Binaries = new List() } - // })); - // - // var result = await ffmpegDownload.DownloadFfMpeg(); - // - // Assert.AreEqual(FfmpegDownloadStatus.DownloadBinariesFailed, result); - // } + [TestMethod] + public async Task DownloadFfMpeg_FileAlreadyExists() + { + var appSettings = new AppSettings { DependenciesFolder = DependencyFolderName }; + var logger = new FakeIWebLogger(); - // [TestMethod] - // public async Task Download_ShouldReturnTrueIfFileExists() - // { - // var appSettings = new AppSettings { DependenciesFolder = "test-dependencies" }; - // var logger = new FakeIWebLogger(); - // var macCodeSign = new FakeIMacCodeSign(); - // - // var ffmpegDownload = new FfMpegDownload(_httpClientHelper, appSettings, logger, macCodeSign); - // - // var binaryIndex = new BinaryIndex { FileName = "test.zip", Sha256 = "test-sha256" }; - // var baseUrls = new List { new Uri("http://example.com/") }; - // - // var result = - // await ffmpegDownload.Download( - // new KeyValuePair>(binaryIndex, baseUrls), "win-x64"); - // - // Assert.IsTrue(result); - // } - // - // [TestMethod] - // public async Task Download_ShouldReturnNullIfBinaryIndexIsNull() - // { - // var appSettings = new AppSettings { DependenciesFolder = "test-dependencies" }; - // var logger = new FakeIWebLogger(); - // var httpClientHelper = new FakeHttpClientHelper(); - // var macCodeSign = new FakeMacCodeSign(); - // var hostFileSystemStorage = new FakeStorageHostFullPathFilesystem(logger); - // - // var ffmpegDownload = new FfMpegDownload(httpClientHelper, appSettings, logger, macCodeSign); - // - // var result = - // await ffmpegDownload.Download( - // new KeyValuePair>(null, new List()), "win-x64"); - // - // Assert.IsNull(result); - // } - // - // [TestMethod] - // public async Task PrepareBeforeRunning_ShouldReturnFalseIfFileDoesNotExist() - // { - // var appSettings = new AppSettings { DependenciesFolder = "test-dependencies" }; - // var logger = new FakeIWebLogger(); - // var httpClientHelper = new FakeHttpClientHelper(); - // var macCodeSign = new FakeMacCodeSign(); - // var hostFileSystemStorage = new FakeStorageHostFullPathFilesystem(logger); - // - // var ffmpegDownload = new FfMpegDownload(httpClientHelper, appSettings, logger, macCodeSign); - // - // var result = await ffmpegDownload.PrepareBeforeRunning("win-x64"); - // - // Assert.IsFalse(result); - // } - // - // [TestMethod] - // public async Task PrepareBeforeRunning_ShouldReturnTrueForWindows() - // { - // var appSettings = new AppSettings { DependenciesFolder = "test-dependencies" }; - // var logger = new FakeIWebLogger(); - // var httpClientHelper = new FakeHttpClientHelper(); - // var macCodeSign = new FakeMacCodeSign(); - // var hostFileSystemStorage = new FakeStorageHostFullPathFilesystem(logger); - // - // var ffmpegDownload = new FfMpegDownload(httpClientHelper, appSettings, logger, macCodeSign); - // - // var result = await ffmpegDownload.PrepareBeforeRunning("win-x64"); - // - // Assert.IsTrue(result); - // } - // - // [TestMethod] - // public async Task PrepareBeforeRunning_ShouldReturnTrueForMac() - // { - // var appSettings = new AppSettings { DependenciesFolder = "test-dependencies" }; - // var logger = new FakeIWebLogger(); - // var httpClientHelper = new FakeHttpClientHelper(); - // var macCodeSign = new FakeMacCodeSign(); - // var hostFileSystemStorage = new FakeStorageHostFullPathFilesystem(logger); - // - // var ffmpegDownload = new FfMpegDownload(httpClientHelper, appSettings, logger, macCodeSign); - // - // var result = await ffmpegDownload.PrepareBeforeRunning("osx-x64"); - // - // Assert.IsTrue(result); - // } + var storage = new FakeIStorage([], + [ + new FfmpegExePath(appSettings).GetExePath(CurrentArchitecture + .GetCurrentRuntimeIdentifier()) + ]); + + var ffmpegDownload = + new FfMpegDownload(new FakeSelectorStorage(storage), appSettings, + logger, + new FakeIFfMpegDownloadIndex(new FfmpegBinariesContainer + { + Success = true, + Data = new FfmpegBinariesIndex { Binaries = new List() } + }), new FakeIFfMpegDownloadBinaries(), new FakeIFfMpegPrepareBeforeRunning()); + + var result = await ffmpegDownload.DownloadFfMpeg(); + + Assert.AreEqual(FfmpegDownloadStatus.Ok, result); + } + + [TestMethod] + public async Task DownloadFfMpeg_DownloadFail_InvalidShaHash() + { + var appSettings = new AppSettings { DependenciesFolder = DependencyFolderName }; + var logger = new FakeIWebLogger(); + var storage = new FakeIStorage(); + + var ffmpegDownload = + new FfMpegDownload(new FakeSelectorStorage(storage), appSettings, + logger, + new FakeIFfMpegDownloadIndex(new FfmpegBinariesContainer + { + Success = true, + Data = _exampleFfmpegBinariesIndex, + BaseUrls = new List { new("https://qdraw.nl/") } + }), + new FfMpegDownloadBinaries(new FakeSelectorStorage(storage), _httpClientHelper, + appSettings, logger, new Zipper(new FakeIWebLogger())), + new FakeIFfMpegPrepareBeforeRunning()); + + var result = await ffmpegDownload.DownloadFfMpeg(); + + Assert.AreEqual(FfmpegDownloadStatus.DownloadBinariesFailedSha256Check, result); + } + + [TestMethod] + public async Task DownloadFfMpeg_DownloadFail_ZipFileNotFound() + { + var appSettings = new AppSettings { DependenciesFolder = DependencyFolderName }; + var logger = new FakeIWebLogger(); + var storage = new FakeIStorage(); + + var ffmpegDownload = + new FfMpegDownload(new FakeSelectorStorage(storage), appSettings, + logger, + new FakeIFfMpegDownloadIndex(new FfmpegBinariesContainer + { + Success = true, + Data = CreateExampleFile( + "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"), + BaseUrls = new List { new("https://qdraw.nl/") } + }), + new FfMpegDownloadBinaries(new FakeSelectorStorage(storage), _httpClientHelper, + appSettings, logger, new Zipper(new FakeIWebLogger())), + new FakeIFfMpegPrepareBeforeRunning()); + + var result = await ffmpegDownload.DownloadFfMpeg(); + + Assert.AreEqual(FfmpegDownloadStatus.DownloadBinariesFailedZipperNotExtracted, result); + } + + [TestMethod] + public async Task DownloadFfMpeg_PrepareBeforeRunningFail() + { + var appSettings = new AppSettings { DependenciesFolder = DependencyFolderName }; + var logger = new FakeIWebLogger(); + var storage = new FakeIStorage(["/"], + new List { "FfMpegDownloadTest/mock_test.zip" }, + new List { CreateAnZipFileMacOs.Bytes.ToArray() }); + + var zipper = new FakeIZipper(new List> + { + new("FfMpegDownloadTest/mock_test.zip", + [.. CreateAnZipFileMacOs.Bytes]) + }, storage); + var ffmpegDownload = + new FfMpegDownload(new FakeSelectorStorage(storage), appSettings, + logger, + new FakeIFfMpegDownloadIndex(new FfmpegBinariesContainer + { + Success = true, + Data = CreateExampleFile( + "4d116276a8049b9d914c94f2827126d3c99e3cc97f021d3611ac7901d17f8e73"), + BaseUrls = new List { new("https://qdraw.nl/") } + }), new FfMpegDownloadBinaries(new FakeSelectorStorage(storage), _httpClientHelper, + appSettings, logger, zipper), + new FfMpegPrepareBeforeRunning(new FakeSelectorStorage(storage), + new FakeIMacCodeSign(), new FfMpegChmod(storage, logger), appSettings, logger)); + + var result = await ffmpegDownload.DownloadFfMpeg(); + + Assert.AreEqual(FfmpegDownloadStatus.PrepareBeforeRunningFailed, result); + } + + [TestMethod] + public async Task DownloadFfMpeg_AllStages() + { + var appSettings = new AppSettings { DependenciesFolder = DependencyFolderName }; + var logger = new FakeIWebLogger(); + var storage = new FakeIStorage(["/"], + new List { "FfMpegDownloadTest/mock_test.zip", "/bin/chmod" }, + new List + { + CreateAnZipFileMacOs.Bytes.ToArray(), CreateAnZipFileMacOs.Bytes.ToArray() + }); + var zipper = new FakeIZipper(new List> + { + new("FfMpegDownloadTest/mock_test.zip", + [.. CreateAnZipFileMacOs.Bytes]) + }, storage); + var ffmpegDownload = + new FfMpegDownload(new FakeSelectorStorage(storage), appSettings, + logger, + new FakeIFfMpegDownloadIndex(new FfmpegBinariesContainer + { + Success = true, + Data = CreateExampleFile( + "4d116276a8049b9d914c94f2827126d3c99e3cc97f021d3611ac7901d17f8e73"), + BaseUrls = new List { new("https://qdraw.nl/") } + }), new FfMpegDownloadBinaries(new FakeSelectorStorage(storage), _httpClientHelper, + appSettings, logger, zipper), new FfMpegPrepareBeforeRunning( + new FakeSelectorStorage(storage), + new FakeIMacCodeSign(new Dictionary + { + { "FfMpegDownloadTest/ffmpeg/ffmpeg", true } + }), new FakeIFfmpegChmod(storage), appSettings, logger)); + + var result = await ffmpegDownload.DownloadFfMpeg(); + + Assert.AreEqual(FfmpegDownloadStatus.PrepareBeforeRunningFailed, result); + } } diff --git a/starsky/starskytest/starsky.foundation.video/GetDependencies/MacCodeSignTests.cs b/starsky/starskytest/starsky.foundation.video/GetDependencies/MacCodeSignTests.cs index ddf28b91de..3e20ef49c4 100644 --- a/starsky/starskytest/starsky.foundation.video/GetDependencies/MacCodeSignTests.cs +++ b/starsky/starskytest/starsky.foundation.video/GetDependencies/MacCodeSignTests.cs @@ -52,7 +52,7 @@ public void Cleanup() private async Task CreateStubExeFile() { - var chmodHelper = new FfmpegChmod(_hostFileSystemStorage, new FakeIWebLogger()); + var chmodHelper = new FfMpegChmod(_hostFileSystemStorage, new FakeIWebLogger()); var exeFile = Path.Combine(_testFolder, "testExecutable"); CreateStubFile(exeFile, "#!/bin/bash\necho Fake Executable"); await chmodHelper.Chmod(exeFile); @@ -61,7 +61,7 @@ private async Task CreateStubExeFile() private async Task CreateStubCodeSignFile(int codeSignExitCode) { - var chmodHelper = new FfmpegChmod(_hostFileSystemStorage, new FakeIWebLogger()); + var chmodHelper = new FfMpegChmod(_hostFileSystemStorage, new FakeIWebLogger()); var codeSignPath = Path.Combine(_testFolder, "codesign"); CreateStubFile(codeSignPath, $"#!/bin/bash\necho codesign\nexit {codeSignExitCode}"); _macCodeSign.CodeSignPath = codeSignPath; @@ -70,7 +70,7 @@ private async Task CreateStubCodeSignFile(int codeSignExitCode) private async Task CreateStubXattrFile(int xattrExitCode) { - var chmodHelper = new FfmpegChmod(_hostFileSystemStorage, new FakeIWebLogger()); + var chmodHelper = new FfMpegChmod(_hostFileSystemStorage, new FakeIWebLogger()); var xattrPath = Path.Combine(_testFolder, "xattr"); CreateStubFile(xattrPath, $"#!/bin/bash\nexit {xattrExitCode}"); _macCodeSign.XattrPath = xattrPath; From 4328ddfe454cadbb660012901ef10e2d950f2599 Mon Sep 17 00:00:00 2001 From: Dion Date: Tue, 10 Dec 2024 23:21:39 +0100 Subject: [PATCH 51/73] #1833 ok --- .../GetDependencies/FfMpegDownloadTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadTest.cs b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadTest.cs index 3e5dd7ca19..e73abe0595 100644 --- a/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadTest.cs +++ b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadTest.cs @@ -309,6 +309,6 @@ public async Task DownloadFfMpeg_AllStages() var result = await ffmpegDownload.DownloadFfMpeg(); - Assert.AreEqual(FfmpegDownloadStatus.PrepareBeforeRunningFailed, result); + Assert.AreEqual(FfmpegDownloadStatus.Ok, result); } } From 978ce3a431b38bb21e116e005fc5b1b513637f8e Mon Sep 17 00:00:00 2001 From: Dion van Velde Date: Wed, 11 Dec 2024 10:40:16 +0100 Subject: [PATCH 52/73] #1833 win32 errors --- .../GetDependencies/FfMpegDownloadBinaries.cs | 1 + .../GetDependencies/FfMpegDownloadTest.cs | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/starsky/starsky.foundation.video/GetDependencies/FfMpegDownloadBinaries.cs b/starsky/starsky.foundation.video/GetDependencies/FfMpegDownloadBinaries.cs index 48cd799cd4..d844847ef7 100644 --- a/starsky/starsky.foundation.video/GetDependencies/FfMpegDownloadBinaries.cs +++ b/starsky/starsky.foundation.video/GetDependencies/FfMpegDownloadBinaries.cs @@ -69,6 +69,7 @@ public async Task Download( if ( !_hostFileSystemStorage.ExistFile(_ffmpegExePath.GetExePath(currentArchitecture)) ) { + _logger.LogError($"Zipper failed {_ffmpegExePath.GetExePath(currentArchitecture)}"); return FfmpegDownloadStatus.DownloadBinariesFailedZipperNotExtracted; } diff --git a/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadTest.cs b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadTest.cs index e73abe0595..cf596309de 100644 --- a/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadTest.cs +++ b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadTest.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Text.Json; using System.Threading.Tasks; @@ -287,17 +288,23 @@ public async Task DownloadFfMpeg_AllStages() }); var zipper = new FakeIZipper(new List> { - new("FfMpegDownloadTest/mock_test.zip", + new($"FfMpegDownloadTest{Path.DirectorySeparatorChar}mock_test.zip", [.. CreateAnZipFileMacOs.Bytes]) }, storage); + + var hash = "4d116276a8049b9d914c94f2827126d3c99e3cc97f021d3611ac7901d17f8e73"; + if ( appSettings.IsWindows ) + { + hash = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"; + } + var ffmpegDownload = new FfMpegDownload(new FakeSelectorStorage(storage), appSettings, logger, new FakeIFfMpegDownloadIndex(new FfmpegBinariesContainer { Success = true, - Data = CreateExampleFile( - "4d116276a8049b9d914c94f2827126d3c99e3cc97f021d3611ac7901d17f8e73"), + Data = CreateExampleFile(hash), BaseUrls = new List { new("https://qdraw.nl/") } }), new FfMpegDownloadBinaries(new FakeSelectorStorage(storage), _httpClientHelper, appSettings, logger, zipper), new FfMpegPrepareBeforeRunning( From f87b9560dd05e3267d72ef0fe6a82e8ed66b4d0a Mon Sep 17 00:00:00 2001 From: Dion Date: Wed, 11 Dec 2024 11:06:20 +0100 Subject: [PATCH 53/73] #1833 add exampleData --- .../ExampleData/ffmpeg | 2 ++ .../ExampleData/ffmpeg.exe | Bin 0 -> 54450 bytes .../CreateAnZipfileFakeFFMpeg/ffmpeg.zip | Bin 0 -> 15898 bytes 3 files changed, 2 insertions(+) create mode 100644 starsky/starskytest/FakeCreateAn/CreateAnZipfileFakeFFMpeg/ExampleData/ffmpeg create mode 100644 starsky/starskytest/FakeCreateAn/CreateAnZipfileFakeFFMpeg/ExampleData/ffmpeg.exe create mode 100644 starsky/starskytest/FakeCreateAn/CreateAnZipfileFakeFFMpeg/ffmpeg.zip diff --git a/starsky/starskytest/FakeCreateAn/CreateAnZipfileFakeFFMpeg/ExampleData/ffmpeg b/starsky/starskytest/FakeCreateAn/CreateAnZipfileFakeFFMpeg/ExampleData/ffmpeg new file mode 100644 index 0000000000..53510974bf --- /dev/null +++ b/starsky/starskytest/FakeCreateAn/CreateAnZipfileFakeFFMpeg/ExampleData/ffmpeg @@ -0,0 +1,2 @@ +#!/bin/bash +echo Fake Ffmpeg \ No newline at end of file diff --git a/starsky/starskytest/FakeCreateAn/CreateAnZipfileFakeFFMpeg/ExampleData/ffmpeg.exe b/starsky/starskytest/FakeCreateAn/CreateAnZipfileFakeFFMpeg/ExampleData/ffmpeg.exe new file mode 100644 index 0000000000000000000000000000000000000000..f1f1796e0a315e1e6190523489abb099f80d835d GIT binary patch literal 54450 zcmeHw3w&JFdFL5DY#Bc!Fa|-Oj2#(dijCwKGQsJLq>*P}EDajTmcei}l19?RBWai! z*|N(fa%3f*3`*22?Yd3+t2Q{hPMWk%mjsihjf^Qa2_%9h#0ex(^JvC(lQ>zzI)tG8 zf9G)@b7v&1Qnu-Gf4VyNeCIpg`#k49w%;?(3K?TXIA>-UJAsrA7ym!|zhM+FyWxw= z*rSV{U3tRce|BX{ZzSQ2#Rq!gp+0A4sK0+8>FfwQOk1`91SDEjI7v1qPSfFHY;s*( zAUa`B1^}nE3aROEp=4c5;Bg(HD>rD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Mpeg/ffmpeg.zip b/starsky/starskytest/FakeCreateAn/CreateAnZipfileFakeFFMpeg/ffmpeg.zip new file mode 100644 index 0000000000000000000000000000000000000000..10b24bb554e43855cb0e011f418c38bdc3282cfa GIT binary patch literal 15898 zcma*OWmM%rw=IghyG!G4jc=rZ#@!tncXxMaoW>e=cXu}K?(XjH^62lJd+z!3#<-PA zDj8X|W~yo?Bgv{MF9i;P0Rr>2_$x(dfc$qN{3@Y9NI*eGMiw13k ze*_Q19$i}m-D4VC$*Y9|Nr@5~nusDUfpJ?zy%Z@xw;`=@FWeQdhZYn;vSu z-UQxlbhd}PLHTMO;MRWF^O0i8@kw+b80m$Ur#{E?qx(xA`j1$*{c(|-@~s7&hqb>OP`bsLWmR2a~LNxQ$EI|xVrT3SMPX2!Z8uPRf@h_rw57-3nYl8eKt7< zA*gB^`Sur^UR~F+i4py1Jx&IF?OBY~d+q)BGXZXkp=rcP$vxZ~SX9mFcuxGh`uq3q z9I|AXhrKDs2OzIEKLX0@4XBVtmLaI-aTT@@i{)x(J672JsC)w)ie)I&Onv3+6t!w6 zk$#4lAb(=lB67BA=dV+ES0Sn1eu4bqbVpYMF{K5j4GDK3yq!g;RpzhLB9z!t2Is;i zdI%<{Ioe4(e(iAv-bT(JWwMh~wU<9^=_rLVbJ|t*69(DKE_%pK+N#yJJ#Wz;0(D4& z#AcYS<=(pDTb-s2KW{uHbEfy00K)hJGHEy?#O+2k#A`@y!p~hF-Bn%d@e7cyweEq~ zuUj8eLGSuQLeKARkdzRbeTdK_OCTQcXeX2i0urXr@&eEq-Kp4h*NoyP8L5nEw` z+%u3JPZ(G+m|W-UN;EME2@K^$+nM_R$xgKJq2QU^^KNbk2xtHtX56qZ{?_JJ=@0My_+ zOb)}!N8Ud07Vv7fO;Q_ziJU;TcqyT;=1c=NWLCl2L43QKt31sFP>{)fwjgGG?Y82yXH7-ni{-A z&Y5_|-zv8jTxy|Uz!)J@sz`)}(?X!d<^GQ~GG=yriJ@V8z<1o_YlLJ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UdOm1kQiVT>a#&Vk6QT$wE9v@Ody65uJD<9mX&IY&t*z>10gUUmj{$-~8dT(a2 zS3XML$REv-P}5lBfA8YL@x&4tMb zovVmR>l7%m9k=-uF{kt?p)9;(la$=*x&d61(xmx)6OQ$*ISV}GR+^+>UCOGFIV|{_ z{u&yQoQoa|Du|ZR5w0wJHCQFc{dQ2F<^p#bKV3mirI~@Frn&er&2-#Zmp~S*>Chaj zzML?|#@TSd+KzD>MxKnKr7=3}V>}#$LWV_h z@=hULx$er`W;+{lN$Z+Sz@w)ZV_L**v%#_N;sn(Kv{O zyPKz@=DN=clFJ&1Rd+T>Jh< Date: Wed, 11 Dec 2024 11:17:33 +0100 Subject: [PATCH 54/73] #1833 update test --- .../CreateAnZipfileFakeFFMpeg.cs | 39 ++++++++++++++++ .../CreateFakeExifToolWindows/readme.md | 45 ++++++++++++------- .../GetDependencies/FfMpegDownloadTest.cs | 22 +++++---- starsky/starskytest/starskytest.csproj | 4 ++ 4 files changed, 87 insertions(+), 23 deletions(-) create mode 100644 starsky/starskytest/FakeCreateAn/CreateAnZipfileFakeFFMpeg/CreateAnZipfileFakeFFMpeg.cs diff --git a/starsky/starskytest/FakeCreateAn/CreateAnZipfileFakeFFMpeg/CreateAnZipfileFakeFFMpeg.cs b/starsky/starskytest/FakeCreateAn/CreateAnZipfileFakeFFMpeg/CreateAnZipfileFakeFFMpeg.cs new file mode 100644 index 0000000000..897fac3469 --- /dev/null +++ b/starsky/starskytest/FakeCreateAn/CreateAnZipfileFakeFFMpeg/CreateAnZipfileFakeFFMpeg.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.IO; +using System.Reflection; +using starsky.foundation.storage.Storage; +using starskytest.FakeMocks; + +namespace starskytest.FakeCreateAn.CreateAnZipfileFakeFFMpeg; + +public class CreateAnZipfileFakeFfMpeg +{ + public readonly ImmutableArray Bytes = [..Array.Empty()]; + + public CreateAnZipfileFakeFfMpeg() + { + var dirName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); + if ( string.IsNullOrEmpty(dirName) ) + { + return; + } + + var path = Path.Combine(dirName, "FakeCreateAn", + "CreateAnZipfileFakeFFMpeg", "ffmpeg.zip"); + + Bytes = [..StreamToBytes(path)]; + } + + public static List Content { get; set; } = new() { "ffmpeg", "ffmpeg.exe" }; + + private static byte[] StreamToBytes(string path) + { + var input = new StorageHostFullPathFilesystem(new FakeIWebLogger()).ReadStream(path); + using var ms = new MemoryStream(); + input.CopyTo(ms); + input.Dispose(); + return ms.ToArray(); + } +} diff --git a/starsky/starskytest/FakeCreateAn/CreateFakeExifToolWindows/readme.md b/starsky/starskytest/FakeCreateAn/CreateFakeExifToolWindows/readme.md index 2cc857e3bf..8a6ce4e88a 100644 --- a/starsky/starskytest/FakeCreateAn/CreateFakeExifToolWindows/readme.md +++ b/starsky/starskytest/FakeCreateAn/CreateFakeExifToolWindows/readme.md @@ -1,21 +1,36 @@ +# NASM + +`choco install nasm` + +cd "C:\Program Files\NASM" + +``` +.\nasm.exe -fwin64 C:\wsgit\starsky\starsky\starskytest\FakeCreateAn\CreateFakeExifToolWindows\code.asm +``` + +## NASM manual 1. https://www.nasm.us/pub/nasm/releasebuilds/2.12.01rc2/win64/nasm-2.12.01rc2-installer-x64.exe + https://www.nasm.us/ +C:\Users\$username\AppData\Local\bin\NASM> .\nasm.exe -fwin64 Y: +\git\starsky\starsky\starskytest\FakeCreateAn\CreateFakeExifToolWindows\code.asm - C:\Users\$username\AppData\Local\bin\NASM> .\nasm.exe -fwin64 Y:\git\starsky\starsky\starskytest\FakeCreateAn\CreateFakeExifToolWindows\code.asm - - https://sourceforge.net/projects/mingw-w64/files/ - -(e.g., C:\mingw). Install a current version and specify win32 as thread when requested. Additionally, choose the architecture x86_64. - -cd "C:\Program Files\mingw-w64\x86_64-8.1.0-win32-seh-rt_v6-rev0" - - .\gcc.exe C:\Users\$username\Desktop\code.obj - - - C:\Program Files\mingw-w64\x86_64-8.1.0-win32-seh-rt_v6-rev0\mingw64\bin> .\a.exe - - - 7z a -mm=Deflate -mfb=258 -mpass=15 foo.zip exiftool\(-k\).exe +# MINGW64 + +`choco install mingw` + +or https://sourceforge.net/projects/mingw-w64/files/ + +(e.g., C:\mingw). Install a current version and specify win32 as thread when requested. +Additionally, choose the architecture x86_64. + +cd "C:\Program Files\mingw-w64\x86_64-8.1.0-win32-seh-rt_v6-rev0" + +.\gcc.exe C:\Users\$username\Desktop\code.obj + +C:\Program Files\mingw-w64\x86_64-8.1.0-win32-seh-rt_v6-rev0\mingw64\bin> .\a.exe + +7z a -mm=Deflate -mfb=258 -mpass=15 foo.zip exiftool\(-k\).exe \ No newline at end of file diff --git a/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadTest.cs b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadTest.cs index cf596309de..9617c94e76 100644 --- a/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadTest.cs +++ b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadTest.cs @@ -11,6 +11,7 @@ using starsky.foundation.storage.ArchiveFormats; using starsky.foundation.video.GetDependencies; using starsky.foundation.video.GetDependencies.Models; +using starskytest.FakeCreateAn.CreateAnZipfileFakeFFMpeg; using starskytest.FakeCreateAn.CreateAnZipFileMacOs; using starskytest.FakeMocks; @@ -248,12 +249,12 @@ public async Task DownloadFfMpeg_PrepareBeforeRunningFail() var appSettings = new AppSettings { DependenciesFolder = DependencyFolderName }; var logger = new FakeIWebLogger(); var storage = new FakeIStorage(["/"], - new List { "FfMpegDownloadTest/mock_test.zip" }, + new List { $"FfMpegDownloadTest{Path.DirectorySeparatorChar}mock_test.zip" }, new List { CreateAnZipFileMacOs.Bytes.ToArray() }); var zipper = new FakeIZipper(new List> { - new("FfMpegDownloadTest/mock_test.zip", + new($"FfMpegDownloadTest{Path.DirectorySeparatorChar}mock_test.zip", [.. CreateAnZipFileMacOs.Bytes]) }, storage); var ffmpegDownload = @@ -281,23 +282,27 @@ public async Task DownloadFfMpeg_AllStages() var appSettings = new AppSettings { DependenciesFolder = DependencyFolderName }; var logger = new FakeIWebLogger(); var storage = new FakeIStorage(["/"], - new List { "FfMpegDownloadTest/mock_test.zip", "/bin/chmod" }, + new List + { + $"FfMpegDownloadTest{Path.DirectorySeparatorChar}mock_test.zip", "/bin/chmod" + }, new List { - CreateAnZipFileMacOs.Bytes.ToArray(), CreateAnZipFileMacOs.Bytes.ToArray() + new CreateAnZipfileFakeFfMpeg().Bytes.ToArray(), + CreateAnZipFileMacOs.Bytes.ToArray() }); var zipper = new FakeIZipper(new List> { new($"FfMpegDownloadTest{Path.DirectorySeparatorChar}mock_test.zip", - [.. CreateAnZipFileMacOs.Bytes]) + [.. new CreateAnZipfileFakeFfMpeg().Bytes.ToArray()]) }, storage); - var hash = "4d116276a8049b9d914c94f2827126d3c99e3cc97f021d3611ac7901d17f8e73"; + var hash = "31852c0b33f35ff16e96d53be370ce86df92db6d4633ab0a8dae38acbf393ead"; if ( appSettings.IsWindows ) { hash = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"; } - + var ffmpegDownload = new FfMpegDownload(new FakeSelectorStorage(storage), appSettings, logger, @@ -306,7 +311,8 @@ public async Task DownloadFfMpeg_AllStages() Success = true, Data = CreateExampleFile(hash), BaseUrls = new List { new("https://qdraw.nl/") } - }), new FfMpegDownloadBinaries(new FakeSelectorStorage(storage), _httpClientHelper, + }), new FfMpegDownloadBinaries(new FakeSelectorStorage(storage), + _httpClientHelper, appSettings, logger, zipper), new FfMpegPrepareBeforeRunning( new FakeSelectorStorage(storage), new FakeIMacCodeSign(new Dictionary diff --git a/starsky/starskytest/starskytest.csproj b/starsky/starskytest/starskytest.csproj index 895d239b23..1da40d5d8f 100644 --- a/starsky/starskytest/starskytest.csproj +++ b/starsky/starskytest/starskytest.csproj @@ -152,6 +152,10 @@ PreserveNewest + + + PreserveNewest + From 2f8aa1243985f875672191d95dbbe284f42d076c Mon Sep 17 00:00:00 2001 From: Dion van Velde Date: Wed, 11 Dec 2024 11:29:47 +0100 Subject: [PATCH 55/73] #1833 fix tests for windows --- .../GetDependencies/FfMpegDownloadTest.cs | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadTest.cs b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadTest.cs index 9617c94e76..e8098fb665 100644 --- a/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadTest.cs +++ b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadTest.cs @@ -250,13 +250,14 @@ public async Task DownloadFfMpeg_PrepareBeforeRunningFail() var logger = new FakeIWebLogger(); var storage = new FakeIStorage(["/"], new List { $"FfMpegDownloadTest{Path.DirectorySeparatorChar}mock_test.zip" }, - new List { CreateAnZipFileMacOs.Bytes.ToArray() }); + new List { new CreateAnZipfileFakeFfMpeg().Bytes.ToArray() }); var zipper = new FakeIZipper(new List> { new($"FfMpegDownloadTest{Path.DirectorySeparatorChar}mock_test.zip", - [.. CreateAnZipFileMacOs.Bytes]) + [.. new CreateAnZipfileFakeFfMpeg().Bytes]) }, storage); + var ffmpegDownload = new FfMpegDownload(new FakeSelectorStorage(storage), appSettings, logger, @@ -264,7 +265,7 @@ public async Task DownloadFfMpeg_PrepareBeforeRunningFail() { Success = true, Data = CreateExampleFile( - "4d116276a8049b9d914c94f2827126d3c99e3cc97f021d3611ac7901d17f8e73"), + "31852c0b33f35ff16e96d53be370ce86df92db6d4633ab0a8dae38acbf393ead"), BaseUrls = new List { new("https://qdraw.nl/") } }), new FfMpegDownloadBinaries(new FakeSelectorStorage(storage), _httpClientHelper, appSettings, logger, zipper), @@ -273,6 +274,13 @@ public async Task DownloadFfMpeg_PrepareBeforeRunningFail() var result = await ffmpegDownload.DownloadFfMpeg(); + // Chmod does not exist on windows + if ( appSettings.IsWindows ) + { + Assert.AreEqual(FfmpegDownloadStatus.Ok, result); + return; + } + Assert.AreEqual(FfmpegDownloadStatus.PrepareBeforeRunningFailed, result); } @@ -297,11 +305,7 @@ public async Task DownloadFfMpeg_AllStages() [.. new CreateAnZipfileFakeFfMpeg().Bytes.ToArray()]) }, storage); - var hash = "31852c0b33f35ff16e96d53be370ce86df92db6d4633ab0a8dae38acbf393ead"; - if ( appSettings.IsWindows ) - { - hash = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"; - } + const string hash = "31852c0b33f35ff16e96d53be370ce86df92db6d4633ab0a8dae38acbf393ead"; var ffmpegDownload = new FfMpegDownload(new FakeSelectorStorage(storage), appSettings, From fe02d7a354646d4ba585f5b12a17616ceb0f7b3d Mon Sep 17 00:00:00 2001 From: Dion Date: Wed, 11 Dec 2024 11:56:10 +0100 Subject: [PATCH 56/73] #1833 fix for not created --- .../CreateAnZipfileFakeFFMpeg.cs | 12 +- .../CreateAnZipfileFakeFFMpegStaticFile.cs | 274 ++++++++++++++++++ 2 files changed, 285 insertions(+), 1 deletion(-) create mode 100644 starsky/starskytest/FakeCreateAn/CreateAnZipfileFakeFFMpeg/CreateAnZipfileFakeFFMpegStaticFile.cs diff --git a/starsky/starskytest/FakeCreateAn/CreateAnZipfileFakeFFMpeg/CreateAnZipfileFakeFFMpeg.cs b/starsky/starskytest/FakeCreateAn/CreateAnZipfileFakeFFMpeg/CreateAnZipfileFakeFFMpeg.cs index 897fac3469..ea436ea29e 100644 --- a/starsky/starskytest/FakeCreateAn/CreateAnZipfileFakeFFMpeg/CreateAnZipfileFakeFFMpeg.cs +++ b/starsky/starskytest/FakeCreateAn/CreateAnZipfileFakeFFMpeg/CreateAnZipfileFakeFFMpeg.cs @@ -3,6 +3,7 @@ using System.Collections.Immutable; using System.IO; using System.Reflection; +using starsky.foundation.platform.Helpers; using starsky.foundation.storage.Storage; using starskytest.FakeMocks; @@ -23,7 +24,16 @@ public CreateAnZipfileFakeFfMpeg() var path = Path.Combine(dirName, "FakeCreateAn", "CreateAnZipfileFakeFFMpeg", "ffmpeg.zip"); - Bytes = [..StreamToBytes(path)]; + if ( File.Exists(path) ) + { + Bytes = [..StreamToBytes(path)]; + return; + } + + Bytes = + [ + ..Base64Helper.TryParse(CreateAnZipfileFakeFfMpegStaticFile.Base64CreateAnZipFile) + ]; } public static List Content { get; set; } = new() { "ffmpeg", "ffmpeg.exe" }; diff --git a/starsky/starskytest/FakeCreateAn/CreateAnZipfileFakeFFMpeg/CreateAnZipfileFakeFFMpegStaticFile.cs b/starsky/starskytest/FakeCreateAn/CreateAnZipfileFakeFFMpeg/CreateAnZipfileFakeFFMpegStaticFile.cs new file mode 100644 index 0000000000..0bbafbec99 --- /dev/null +++ b/starsky/starskytest/FakeCreateAn/CreateAnZipfileFakeFFMpeg/CreateAnZipfileFakeFFMpegStaticFile.cs @@ -0,0 +1,274 @@ +using System.Diagnostics.CodeAnalysis; + +namespace starskytest.FakeCreateAn.CreateAnZipfileFakeFFMpeg; + +public static class CreateAnZipfileFakeFfMpegStaticFile +{ + [SuppressMessage("ReSharper", "UnusedMember.Local")] + internal const string Base64CreateAnZipFile = + "UEsDBBQACAAIAIFTi1kAAAAAAAAAAB0AAAAGACAAZmZtcGVnVVQNAAcjW1lnkmNZZ5JjWWd1eAsAAQQA" + + "AAAABAAAAABTVtRPyszTT0oszuDlSk3OyFdwS8xOVXBLyy1ITQcAUEsHCNSGBSwfAAAAHQAAAFBLAwQU" + + "AAgACAALWItZAAAAAAAAAACy1AAACgAgAGZmbXBlZy5leGVVVA0AB7diWWeSY1lnkmNZZ3V4CwABBAAA" + + "AAAEAAAAAO19DXhbxZXoyLYcOXYi5ceJE0ijpA44LAl2/nAoaS3bciRQbOGfxAmBa1mWbTWyLKSr2Mny" + + "WgcnJcK4TfvYbnbb/epH0vfSv910Hy2BdluHUAgttIZSmhZK3b+t0vQn8CgvBYrfOTNzf0e2HC8vfa+L" + + "Pl/PnTNn5pw558yZM6N7R9t2HSG5hJA8uCYmC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Y7h" + + "6yhwCz2mA2dgetet7sZ6t2/9urUdkQhWWzjArkAsvKYnsaYvHF0DUlijk/maSMWaijXlvELZgPEy1esO" + + "BWKGCjeLOGjBBhz/ALtMeCC0vWA/RvodA//xy0SHb9UY6fQPTH6Z6lNl62vfDzj3Z8IDK+gykiEjA8bL" + + "VEdk7C/8gfV+xn0PhyMzXNk3bsu2f/zu593Pu5//dz8OnHsI2Y4vHDrZff/nCH23lL7eOeIfaRuJjfSP" + + "DIwcHjkycnRkZOTEyMmRUyOjI2Mj50bSIxdH8MVAH8V1jpSNlI9UjviPtR2LHRs4duTYyLGTx0aPjR0b" + + "P3bxGDnuOO48Xn686rj/eNvx2PGB40eOjxw/eXz0+Njx8eMXj5PPOj6L73jidqQN2qocqRr5ywjlP88H" + + "dcy+07UxAP+edd0k+FdT/DIN/93P/9cffA/fSixUmWwe1xsAvmj991gy8GU7w1sIuVlb61ucNRU3OivW" + + "r123tty5pkdORkNbgr3x0DrIBOLB7i3RXlhUBJxrupS/hnXa1RntXQMrgKgMt35vDfxvT4bpd3RrIuH2" + + "rmCQoSTkQHDPmhhbiMEicBmy8jhcu+HKseQHuwNxkmObFemNdjnpv2QU4/5QhxPCciixaiUUkDMr0Q3L" + + "BBNanpUnGmLeLCOKI4+WdfQm2yMhIG1TizkPeUpRXl5npDcgE5ttE0ixAFrKwFiOlfGBmdxwf+UmCQUI" + + "C5yOcDCUIL+D7q2w5M4FubdCWXNLvVtqqvG4a1t8bj3M72ps9rp8UqN7q1Tr9rvra931NTuJRVeraVKs" + + "nMmx6vxSTUP9dndjc5O+Ru7kNTKh52note6mZqnO5WvCW79U19AobfXVEKuxwSa/z9uMzTWRfLGTdT7X" + + "Vkqrqdnl85FZGsa2hu2txKbLu7c1NO6Utnmbtrmaazy8QoGGUNcC1Gq2+SVXfa1U3eiqB6T168jsqTE2" + + "bSCFU2M0NSCTTaTIhObytejQyByt2FVT07KtxedqdksNLc1bG7z1WyVXIzQxVyeAxgZfw9YWt9TShMX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Cr0S268yDulT07j53" + + "PdmhM32Pt665grRqkF1u9P2tzRDbcVr1tWSnIUbZ1tCselGcvMgu3UzuAg/ORgu5PeMsLO1o9Da7yW5D" + + "VAf/KqTtXpcE7uYOraS+AacDv8vb6IK+kzszB8RszpdEHm+jPJK2TNwzLQe0It4hFB9pN/shXwMPuJpI" + + "0DjqWms8W6tJhxEImOUkZOwHc0CUoU7zGOPOCaIRLO7Sinm4CQKt9bJhBvEPOIRuDeU2Hd/hTDJgPf2g" + + "buKCEEvajopu8fvBYezRhVCgPhLhKxVc3RlWKt+y3KesVFyNwBZGJMa8H8XBlyV6UGU1X4VQYCvab66W" + + "r27a4fLzVQQFUDasuPAzrL0cVgn4kWF0w/0s5V5dccFqK0+qwzVZxSZYnuUGe3tikVC/U4PZVBhbuuU4" + + "VICyqnOqEMM60KG0jLSd5qYBOBu/cZJiMrB5nQOf3cjbBOvoRjt++wNsU/36vDA4JHLDVlxhS1KtDlaO" + + "MFrlPriK/oGu0fOx+gMF++F/QW4bf4w+vxOyf8eB/rumvydvmUcci+dZ5ttz5141d9XcBXhcnKWM5Nqu" + + "LoQ1dikpLHx/Ya6NkNw8S67t/StmFa7I8y64aYXlfdbNK/ItC4A9i8W7AG+sG6DWTSty3le4ecU874IP" + + "LLl5CfC1gWwF9FxEn+1dkFNCyKx5llW2BYW5y69a7lhMiM0ONLz4FFExuRZqzF6EzRRCKxRauAIYKlpB" + + "vAtuKHyn9jze/WgfPOLNSmz06D2LxfLm3DmY8CeV4GY53RyUCG64LM+x53wUS+g/UpCj7BXlvkYsK1d2" + + "7SxP3trVVb7Ft3JljgUq1/K2b56s7dz3ws09cH3WwtvPexaL8N2vnJ/j3e8tl/c407ufy/zgfh6+wwP6" + + "6ncWzbKNcGmrRzua9oNdcx335LjmlgzkRuc6Rl1zbY9dcZbf/byDn5qbbqB7r/HeXvmGRDx4Q1cwuIbt" + + "697A9mJvYE+H3BBeX7lpd3BfV184uhaWJjftVuvtxrhg0waotq58Taw3Ee5f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XZ8zc41FzNu3/6m12Wvv5k6z+pl4Hm2J7PT9Tu1DzBDRlrGOMaPu0" + + "TXLD7jgvz7RfpTghJQqZam2km5v006BpTfF/AFBLBwj5Vyv/jTwAALLUAABQSwECFAMUAAgACACBU4tZ" + + "1IYFLB8AAAAdAAAABgAgAAAAAAAAAAAAtoEAAAAAZmZtcGVnVVQNAAcjW1lnkmNZZ5JjWWd1eAsAAQQA" + + "AAAABAAAAABQSwECFAMUAAgACAALWItZ+Vcr/408AACy1AAACgAgAAAAAAAAAAAA/4FzAAAAZmZtcGVn" + + "LmV4ZVVUDQAHt2JZZ5JjWWeSY1lndXgLAAEEAAAAAAQAAAAAUEsFBgAAAAACAAIArAAAAFg9AAAAAA=="; +} From 7b18326db2f3030892714d020fcdc99b5e6baa46 Mon Sep 17 00:00:00 2001 From: Dion Date: Fri, 13 Dec 2024 10:16:26 +0100 Subject: [PATCH 57/73] #1833 add check && add to file scoped --- .../GetDependencies/MacCodeSign.cs | 5 + .../Helpers/ExifToolCmdHelperTest.cs | 507 +++++++++--------- 2 files changed, 258 insertions(+), 254 deletions(-) diff --git a/starsky/starsky.foundation.video/GetDependencies/MacCodeSign.cs b/starsky/starsky.foundation.video/GetDependencies/MacCodeSign.cs index 00f7c80c6c..26b4587654 100644 --- a/starsky/starsky.foundation.video/GetDependencies/MacCodeSign.cs +++ b/starsky/starsky.foundation.video/GetDependencies/MacCodeSign.cs @@ -42,6 +42,11 @@ public MacCodeSign(ISelectorStorage selectorStorage, IWebLogger logger) return null; } + if ( !_hostFileSystemStorage.ExistFile(exeFile) ) + { + return null; + } + // command.run does not care about the $PATH var result = await Command.Run(CodeSignPath, "--force", "--deep", "-s", "-", exeFile).Task; if ( result.Success ) diff --git a/starsky/starskytest/starsky.foundation.writemeta/Helpers/ExifToolCmdHelperTest.cs b/starsky/starskytest/starsky.foundation.writemeta/Helpers/ExifToolCmdHelperTest.cs index 7126745df2..bb0fc8fc36 100644 --- a/starsky/starskytest/starsky.foundation.writemeta/Helpers/ExifToolCmdHelperTest.cs +++ b/starsky/starskytest/starsky.foundation.writemeta/Helpers/ExifToolCmdHelperTest.cs @@ -9,288 +9,287 @@ using starskytest.FakeMocks; using ExifToolCmdHelper = starsky.foundation.writemeta.Helpers.ExifToolCmdHelper; -namespace starskytest.starsky.foundation.writemeta.Helpers +namespace starskytest.starsky.foundation.writemeta.Helpers; + +[TestClass] +public sealed class ExifToolCmdHelperTest { - [TestClass] - public sealed class ExifToolCmdHelperTest + private readonly AppSettings _appSettings; + + public ExifToolCmdHelperTest() { - private readonly AppSettings _appSettings; + // get the service + _appSettings = new AppSettings(); + } - public ExifToolCmdHelperTest() + [TestMethod] + public void ExifToolCmdHelper_UpdateTest() + { + var updateModel = new FileIndexItem { - // get the service - _appSettings = new AppSettings(); - } - - [TestMethod] - public void ExifToolCmdHelper_UpdateTest() + Tags = "tags", + Description = "Description", + Latitude = 52, + Longitude = 3, + LocationAltitude = 41, + LocationCity = "LocationCity", + LocationState = "LocationState", + LocationCountry = "LocationCountry", + LocationCountryCode = "NLD", + Title = "Title", + ColorClass = ColorClassParser.Color.Trash, + Orientation = FileIndexItem.Rotation.Rotate90Cw, + DateTime = DateTime.Now + }; + var comparedNames = new List { - var updateModel = new FileIndexItem - { - Tags = "tags", - Description = "Description", - Latitude = 52, - Longitude = 3, - LocationAltitude = 41, - LocationCity = "LocationCity", - LocationState = "LocationState", - LocationCountry = "LocationCountry", - LocationCountryCode = "NLD", - Title = "Title", - ColorClass = ColorClassParser.Color.Trash, - Orientation = FileIndexItem.Rotation.Rotate90Cw, - DateTime = DateTime.Now, - }; - var comparedNames = new List - { - nameof(FileIndexItem.Tags).ToLowerInvariant(), - nameof(FileIndexItem.Description).ToLowerInvariant(), - nameof(FileIndexItem.Latitude).ToLowerInvariant(), - nameof(FileIndexItem.Longitude).ToLowerInvariant(), - nameof(FileIndexItem.LocationAltitude).ToLowerInvariant(), - nameof(FileIndexItem.LocationCity).ToLowerInvariant(), - nameof(FileIndexItem.LocationState).ToLowerInvariant(), - nameof(FileIndexItem.LocationCountry).ToLowerInvariant(), - nameof(FileIndexItem.LocationCountryCode).ToLowerInvariant(), - nameof(FileIndexItem.Title).ToLowerInvariant(), - nameof(FileIndexItem.ColorClass).ToLowerInvariant(), - nameof(FileIndexItem.Orientation).ToLowerInvariant(), - nameof(FileIndexItem.DateTime).ToLowerInvariant(), - }; - - var inputSubPaths = new List { "/test.jpg" }; - var storage = new FakeIStorage(new List { "/" }, - new List { "/test.jpg" }, new List()); - - var fakeExifTool = new FakeExifTool(storage, _appSettings); - var helperResult = new ExifToolCmdHelper(fakeExifTool, storage, storage, - new FakeReadMeta(), new FakeIThumbnailQuery(), new FakeIWebLogger()) - .Update(updateModel, inputSubPaths, comparedNames); - - Assert.IsTrue(helperResult.Contains(updateModel.Tags)); - Assert.IsTrue(helperResult.Contains(updateModel.Description)); - Assert.IsTrue( - helperResult.Contains(updateModel.Latitude.ToString(CultureInfo.InvariantCulture))); - Assert.IsTrue( - helperResult.Contains( - updateModel.Longitude.ToString(CultureInfo.InvariantCulture))); - Assert.IsTrue( - helperResult.Contains( - updateModel.LocationAltitude.ToString(CultureInfo.InvariantCulture))); - Assert.IsTrue(helperResult.Contains(updateModel.LocationCity)); - Assert.IsTrue(helperResult.Contains(updateModel.LocationState)); - Assert.IsTrue(helperResult.Contains(updateModel.LocationCountry)); - Assert.IsTrue(helperResult.Contains(updateModel.LocationCountryCode)); - Assert.IsTrue(helperResult.Contains(updateModel.Title)); - } - - [TestMethod] - public void ExifToolCmdHelper_Update_UpdateLocationAltitudeCommandTest() + nameof(FileIndexItem.Tags).ToLowerInvariant(), + nameof(FileIndexItem.Description).ToLowerInvariant(), + nameof(FileIndexItem.Latitude).ToLowerInvariant(), + nameof(FileIndexItem.Longitude).ToLowerInvariant(), + nameof(FileIndexItem.LocationAltitude).ToLowerInvariant(), + nameof(FileIndexItem.LocationCity).ToLowerInvariant(), + nameof(FileIndexItem.LocationState).ToLowerInvariant(), + nameof(FileIndexItem.LocationCountry).ToLowerInvariant(), + nameof(FileIndexItem.LocationCountryCode).ToLowerInvariant(), + nameof(FileIndexItem.Title).ToLowerInvariant(), + nameof(FileIndexItem.ColorClass).ToLowerInvariant(), + nameof(FileIndexItem.Orientation).ToLowerInvariant(), + nameof(FileIndexItem.DateTime).ToLowerInvariant() + }; + + var inputSubPaths = new List { "/test.jpg" }; + var storage = new FakeIStorage(new List { "/" }, + new List { "/test.jpg" }, new List()); + + var fakeExifTool = new FakeExifTool(storage, _appSettings); + var helperResult = new ExifToolCmdHelper(fakeExifTool, storage, storage, + new FakeReadMeta(), new FakeIThumbnailQuery(), new FakeIWebLogger()) + .Update(updateModel, inputSubPaths, comparedNames); + + Assert.IsTrue(helperResult.Contains(updateModel.Tags)); + Assert.IsTrue(helperResult.Contains(updateModel.Description)); + Assert.IsTrue( + helperResult.Contains(updateModel.Latitude.ToString(CultureInfo.InvariantCulture))); + Assert.IsTrue( + helperResult.Contains( + updateModel.Longitude.ToString(CultureInfo.InvariantCulture))); + Assert.IsTrue( + helperResult.Contains( + updateModel.LocationAltitude.ToString(CultureInfo.InvariantCulture))); + Assert.IsTrue(helperResult.Contains(updateModel.LocationCity)); + Assert.IsTrue(helperResult.Contains(updateModel.LocationState)); + Assert.IsTrue(helperResult.Contains(updateModel.LocationCountry)); + Assert.IsTrue(helperResult.Contains(updateModel.LocationCountryCode)); + Assert.IsTrue(helperResult.Contains(updateModel.Title)); + } + + [TestMethod] + public void ExifToolCmdHelper_Update_UpdateLocationAltitudeCommandTest() + { + var updateModel = new FileIndexItem { LocationAltitude = -41 }; + var comparedNames = new List { - var updateModel = new FileIndexItem { LocationAltitude = -41, }; - var comparedNames = new List - { - nameof(FileIndexItem.LocationAltitude).ToLowerInvariant(), - }; + nameof(FileIndexItem.LocationAltitude).ToLowerInvariant() + }; + + var folderPaths = new List { "/" }; + + var inputSubPaths = new List { "/test.jpg" }; + + var storage = + new FakeIStorage(folderPaths, inputSubPaths); + var fakeExifTool = new FakeExifTool(storage, _appSettings); + + var helperResult = new ExifToolCmdHelper(fakeExifTool, + storage, storage, + new FakeReadMeta(), new FakeIThumbnailQuery(), new FakeIWebLogger()) + .Update(updateModel, inputSubPaths, comparedNames); - var folderPaths = new List { "/" }; + Assert.IsTrue(helperResult.Contains("-GPSAltitude=\"-41")); + Assert.IsTrue(helperResult.Contains("gpsaltituderef#=\"1")); + } + + [TestMethod] + public async Task CreateXmpFileIsNotExist_NotCreateFile_jpg() + { + var updateModel = new FileIndexItem { LocationAltitude = -41 }; + var folderPaths = new List { "/" }; + + var inputSubPaths = new List { "/test.jpg" }; + + var storage = + new FakeIStorage(folderPaths, inputSubPaths); + var fakeExifTool = new FakeExifTool(storage, _appSettings); + await new ExifToolCmdHelper(fakeExifTool, + storage, storage, + new FakeReadMeta(), new FakeIThumbnailQuery(), new FakeIWebLogger()) + .CreateXmpFileIsNotExist(updateModel, inputSubPaths); + + Assert.IsFalse(storage.ExistFile("/test.xmp")); + } - var inputSubPaths = new List { "/test.jpg" }; + [TestMethod] + public async Task CreateXmpFileIsNotExist_CreateFile_dng() + { + var updateModel = new FileIndexItem { LocationAltitude = -41 }; + var folderPaths = new List { "/" }; - var storage = - new FakeIStorage(folderPaths, inputSubPaths); - var fakeExifTool = new FakeExifTool(storage, _appSettings); + var inputSubPaths = new List { "/test.dng" }; - var helperResult = new ExifToolCmdHelper(fakeExifTool, - storage, storage, - new FakeReadMeta(), new FakeIThumbnailQuery(), new FakeIWebLogger()) - .Update(updateModel, inputSubPaths, comparedNames); + var storage = + new FakeIStorage(folderPaths, inputSubPaths); + var fakeExifTool = new FakeExifTool(storage, _appSettings); + await new ExifToolCmdHelper(fakeExifTool, + storage, storage, + new FakeReadMeta(), new FakeIThumbnailQuery(), new FakeIWebLogger()) + .CreateXmpFileIsNotExist(updateModel, inputSubPaths); - Assert.IsTrue(helperResult.Contains("-GPSAltitude=\"-41")); - Assert.IsTrue(helperResult.Contains("gpsaltituderef#=\"1")); - } + Assert.IsTrue(storage.ExistFile("/test.xmp")); + } - [TestMethod] - public async Task CreateXmpFileIsNotExist_NotCreateFile_jpg() + [TestMethod] + public async Task UpdateAsync_ShouldUpdate_SkipFileHash() + { + var updateModel = new FileIndexItem { Tags = "tags", Description = "Description" }; + var comparedNames = new List { - var updateModel = new FileIndexItem { LocationAltitude = -41, }; - var folderPaths = new List { "/" }; + nameof(FileIndexItem.Tags).ToLowerInvariant(), + nameof(FileIndexItem.Description).ToLowerInvariant() + }; - var inputSubPaths = new List { "/test.jpg" }; + var storage = new FakeIStorage(new List { "/" }, + new List { "/test.jpg" }, new List()); - var storage = - new FakeIStorage(folderPaths, inputSubPaths); - var fakeExifTool = new FakeExifTool(storage, _appSettings); - await new ExifToolCmdHelper(fakeExifTool, - storage, storage, - new FakeReadMeta(), new FakeIThumbnailQuery(), new FakeIWebLogger()) - .CreateXmpFileIsNotExist(updateModel, inputSubPaths); + var fakeExifTool = new FakeExifTool(storage, _appSettings); + var helperResult = await new ExifToolCmdHelper(fakeExifTool, storage, storage, + new FakeReadMeta(), new FakeIThumbnailQuery(), new FakeIWebLogger()) + .UpdateAsync(updateModel, comparedNames); - Assert.IsFalse(storage.ExistFile("/test.xmp")); - } + Assert.IsTrue(helperResult.Item1.Contains("tags")); + Assert.IsTrue(helperResult.Item1.Contains("Description")); + } - [TestMethod] - public async Task CreateXmpFileIsNotExist_CreateFile_dng() + [TestMethod] + public async Task UpdateAsync_ShouldUpdate_IncludeFileHash() + { + var updateModel = new FileIndexItem { - var updateModel = new FileIndexItem { LocationAltitude = -41, }; - var folderPaths = new List { "/" }; + Tags = "tags", + Description = "Description", + FileHash = "_hash_test" // < - - - - include here + }; + var comparedNames = new List + { + nameof(FileIndexItem.Tags).ToLowerInvariant(), + nameof(FileIndexItem.Description).ToLowerInvariant() + }; + + var storage = new FakeIStorage(new List { "/" }, + new List { "/test.jpg" }, new List()); - var inputSubPaths = new List { "/test.dng" }; + var fakeExifTool = new FakeExifTool(storage, _appSettings); + var helperResult = await new ExifToolCmdHelper(fakeExifTool, storage, storage, + new FakeReadMeta(), new FakeIThumbnailQuery(), new FakeIWebLogger()) + .UpdateAsync(updateModel, comparedNames); - var storage = - new FakeIStorage(folderPaths, inputSubPaths); - var fakeExifTool = new FakeExifTool(storage, _appSettings); - await new ExifToolCmdHelper(fakeExifTool, - storage, storage, - new FakeReadMeta(), new FakeIThumbnailQuery(), new FakeIWebLogger()) - .CreateXmpFileIsNotExist(updateModel, inputSubPaths); + Assert.IsTrue(helperResult.Item1.Contains("tags")); + Assert.IsTrue(helperResult.Item1.Contains("Description")); + } - Assert.IsTrue(storage.ExistFile("/test.xmp")); - } - [TestMethod] - public async Task UpdateAsync_ShouldUpdate_SkipFileHash() + [TestMethod] + public void ExifToolCommandLineArgsImageStabilisation() + { + var updateModel = new FileIndexItem + { + ImageStabilisation = ImageStabilisationType.On // < - - - - include here + }; + var comparedNames = new List { - var updateModel = new FileIndexItem { Tags = "tags", Description = "Description", }; - var comparedNames = new List - { - nameof(FileIndexItem.Tags).ToLowerInvariant(), - nameof(FileIndexItem.Description).ToLowerInvariant(), - }; - - var storage = new FakeIStorage(new List { "/" }, - new List { "/test.jpg" }, new List()); - - var fakeExifTool = new FakeExifTool(storage, _appSettings); - var helperResult = ( await new ExifToolCmdHelper(fakeExifTool, storage, storage, - new FakeReadMeta(), new FakeIThumbnailQuery(), new FakeIWebLogger()) - .UpdateAsync(updateModel, comparedNames) ); - - Assert.IsTrue(helperResult.Item1.Contains("tags")); - Assert.IsTrue(helperResult.Item1.Contains("Description")); - } - - [TestMethod] - public async Task UpdateAsync_ShouldUpdate_IncludeFileHash() + nameof(FileIndexItem.ImageStabilisation).ToLowerInvariant() + }; + + var result = ExifToolCmdHelper.ExifToolCommandLineArgs(updateModel, + comparedNames, true); + + Assert.AreEqual("-json -overwrite_original -ImageStabilization=\"On\"", result); + } + + [TestMethod] + public void ExifToolCommandLineArgsImageStabilisationUnknown() + { + var updateModel = new FileIndexItem { - var updateModel = new FileIndexItem - { - Tags = "tags", - Description = "Description", - FileHash = "_hash_test" // < - - - - include here - }; - var comparedNames = new List - { - nameof(FileIndexItem.Tags).ToLowerInvariant(), - nameof(FileIndexItem.Description).ToLowerInvariant(), - }; - - var storage = new FakeIStorage(new List { "/" }, - new List { "/test.jpg" }, new List()); - - var fakeExifTool = new FakeExifTool(storage, _appSettings); - var helperResult = ( await new ExifToolCmdHelper(fakeExifTool, storage, storage, - new FakeReadMeta(), new FakeIThumbnailQuery(), new FakeIWebLogger()) - .UpdateAsync(updateModel, comparedNames) ); - - Assert.IsTrue(helperResult.Item1.Contains("tags")); - Assert.IsTrue(helperResult.Item1.Contains("Description")); - } - - - [TestMethod] - public void ExifToolCommandLineArgsImageStabilisation() + ImageStabilisation = ImageStabilisationType.Unknown // < - - - - include here + }; + var comparedNames = new List { - var updateModel = new FileIndexItem - { - ImageStabilisation = ImageStabilisationType.On // < - - - - include here - }; - var comparedNames = new List - { - nameof(FileIndexItem.ImageStabilisation).ToLowerInvariant(), - }; - - var result = ExifToolCmdHelper.ExifToolCommandLineArgs(updateModel, - comparedNames, true); - - Assert.AreEqual("-json -overwrite_original -ImageStabilization=\"On\"", result); - } - - [TestMethod] - public void ExifToolCommandLineArgsImageStabilisationUnknown() + nameof(FileIndexItem.ImageStabilisation).ToLowerInvariant() + }; + + var result = ExifToolCmdHelper.ExifToolCommandLineArgs(updateModel, + comparedNames, true); + + Assert.AreEqual(string.Empty, result); + } + + [TestMethod] + public void ExifToolCommandLineArgs_LocationCountryCode() + { + var updateModel = new FileIndexItem { - var updateModel = new FileIndexItem - { - ImageStabilisation = ImageStabilisationType.Unknown // < - - - - include here - }; - var comparedNames = new List - { - nameof(FileIndexItem.ImageStabilisation).ToLowerInvariant(), - }; - - var result = ExifToolCmdHelper.ExifToolCommandLineArgs(updateModel, - comparedNames, true); - - Assert.AreEqual(string.Empty, result); - } - - [TestMethod] - public void ExifToolCommandLineArgs_LocationCountryCode() + LocationCountryCode = "NLD" // < - - - - include here + }; + var comparedNames = new List { - var updateModel = new FileIndexItem - { - LocationCountryCode = "NLD" // < - - - - include here - }; - var comparedNames = new List - { - nameof(FileIndexItem.LocationCountryCode).ToLowerInvariant(), - }; - - var result = ExifToolCmdHelper.ExifToolCommandLineArgs(updateModel, - comparedNames, true); - - Assert.AreEqual( - "-json -overwrite_original -Country-PrimaryLocationCode=\"NLD\" -XMP:CountryCode=\"NLD\"", - result); - } - - - [TestMethod] - public void UpdateSoftwareCommand_True() + nameof(FileIndexItem.LocationCountryCode).ToLowerInvariant() + }; + + var result = ExifToolCmdHelper.ExifToolCommandLineArgs(updateModel, + comparedNames, true); + + Assert.AreEqual( + "-json -overwrite_original -Country-PrimaryLocationCode=\"NLD\" -XMP:CountryCode=\"NLD\"", + result); + } + + + [TestMethod] + public void UpdateSoftwareCommand_True() + { + var updateModel = new FileIndexItem { - var updateModel = new FileIndexItem - { - Software = "Test" // < - - - - include here - }; - var comparedNames = - new List { nameof(FileIndexItem.Software).ToLowerInvariant(), }; - - var result = - ExifToolCmdHelper.UpdateSoftwareCommand(string.Empty, comparedNames, updateModel, - true); - - Assert.AreEqual(" -Software=\"Test\" -CreatorTool=\"Test\" " + - "-HistorySoftwareAgent=\"Test\" -HistoryParameters=\"\" -PMVersion=\"\" ", - result); - } - - [TestMethod] - public void UpdateSoftwareCommand_False() + Software = "Test" // < - - - - include here + }; + var comparedNames = + new List { nameof(FileIndexItem.Software).ToLowerInvariant() }; + + var result = + ExifToolCmdHelper.UpdateSoftwareCommand(string.Empty, comparedNames, updateModel, + true); + + Assert.AreEqual(" -Software=\"Test\" -CreatorTool=\"Test\" " + + "-HistorySoftwareAgent=\"Test\" -HistoryParameters=\"\" -PMVersion=\"\" ", + result); + } + + [TestMethod] + public void UpdateSoftwareCommand_False() + { + var updateModel = new FileIndexItem { - var updateModel = new FileIndexItem - { - Software = "Test" // < - - - - include here - }; - var comparedNames = - new List { nameof(FileIndexItem.Software).ToLowerInvariant(), }; - - var result = - ExifToolCmdHelper.UpdateSoftwareCommand(string.Empty, comparedNames, updateModel, - false); - - Assert.AreEqual(" -Software=\"Starsky\" -CreatorTool=\"Starsky\" " + - "-HistorySoftwareAgent=\"Starsky\" -HistoryParameters=\"\" -PMVersion=\"\" ", - result); - } + Software = "Test" // < - - - - include here + }; + var comparedNames = + new List { nameof(FileIndexItem.Software).ToLowerInvariant() }; + + var result = + ExifToolCmdHelper.UpdateSoftwareCommand(string.Empty, comparedNames, updateModel, + false); + + Assert.AreEqual(" -Software=\"Starsky\" -CreatorTool=\"Starsky\" " + + "-HistorySoftwareAgent=\"Starsky\" -HistoryParameters=\"\" -PMVersion=\"\" ", + result); } } From 3fbc8b818046d43ca1e640bcb2507c009b7e60cb Mon Sep 17 00:00:00 2001 From: Dion Date: Fri, 13 Dec 2024 10:27:53 +0100 Subject: [PATCH 58/73] #1833 shell injection --- .../Helpers/ExifToolTest.cs | 34 +++++++++++++++++-- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/starsky/starskytest/starsky.foundation.writemeta/Helpers/ExifToolTest.cs b/starsky/starskytest/starsky.foundation.writemeta/Helpers/ExifToolTest.cs index 40e784fee1..8b18c6d245 100644 --- a/starsky/starskytest/starsky.foundation.writemeta/Helpers/ExifToolTest.cs +++ b/starsky/starskytest/starsky.foundation.writemeta/Helpers/ExifToolTest.cs @@ -117,11 +117,39 @@ public async Task RunProcessAsync_RunChildObject_UnixOnly() var runner = new StreamToStreamRunner(appSettings, new MemoryStream([]), new FakeIWebLogger()); - var result = await runner.RunProcessAsync(string.Empty, "test / unit test"); + var streamResult = await runner.RunProcessAsync(string.Empty, "test / unit test"); - await StreamToStringHelper.StreamToStringAsync(result, false); + await StreamToStringHelper.StreamToStringAsync(streamResult, false); - Assert.AreEqual(0, result.Length); + Assert.AreEqual(0, streamResult.Length); + + await streamResult.DisposeAsync(); + } + + [TestMethod] + [DataRow("file.txt && dir")] + [DataRow("file.txt | ipconfig")] + [DataRow("file.txt && ipconfig")] + [DataRow("file.txt & powershell -Command \"Get-Process | Out-File output.txt\"")] + [DataRow("file.txt && curl https://qdraw.nl")] + [DataRow("\"file.txt\" && ipconfig")] + public async Task RunProcessAsync_Fuzzing(string argument) + { + var appSettings = new AppSettings { Verbose = true, ExifToolPath = "/bin/sh" }; + if ( appSettings.IsWindows || !File.Exists("/bin/sh") ) + { + Assert.Inconclusive("This test if for Unix Only"); + return; + } + + var runner = new StreamToStreamRunner(appSettings, + new MemoryStream([]), new FakeIWebLogger()); + var streamResult = await runner.RunProcessAsync(argument, "test / unit test"); + + var stringResult = await StreamToStringHelper.StreamToStringAsync(streamResult); + + Assert.AreEqual(0, stringResult.Length); + Assert.AreEqual(string.Empty, stringResult); } [TestMethod] From 4c0b0403d4d1ee0c1604f6bab2ae23c103ec6f07 Mon Sep 17 00:00:00 2001 From: Dion Date: Fri, 13 Dec 2024 10:45:12 +0100 Subject: [PATCH 59/73] #1833 tests --- .../GetDependencies/MacCodeSign.cs | 10 ++++ .../GetDependencies/FfMpegDownloadTest.cs | 55 +++++++++++++------ .../GetDependencies/MacCodeSignTests.cs | 25 +++++++++ 3 files changed, 74 insertions(+), 16 deletions(-) diff --git a/starsky/starsky.foundation.video/GetDependencies/MacCodeSign.cs b/starsky/starsky.foundation.video/GetDependencies/MacCodeSign.cs index 26b4587654..32847e4054 100644 --- a/starsky/starsky.foundation.video/GetDependencies/MacCodeSign.cs +++ b/starsky/starsky.foundation.video/GetDependencies/MacCodeSign.cs @@ -25,6 +25,11 @@ public MacCodeSign(ISelectorStorage selectorStorage, IWebLogger logger) public async Task MacCodeSignAndXattrExecutable(string exeFile) { + if ( !_hostFileSystemStorage.ExistFile(exeFile) ) + { + return null; + } + var result = await MacCodeSignExecutable(exeFile); if ( result is null or false ) { @@ -67,6 +72,11 @@ public MacCodeSign(ISelectorStorage selectorStorage, IWebLogger logger) return null; } + if ( !_hostFileSystemStorage.ExistFile(exeFile) ) + { + return null; + } + // command.run does not care about the $PATH var result = await Command.Run(XattrPath, "-rd", "com.apple.quarantine", exeFile).Task; if ( result.Success ) diff --git a/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadTest.cs b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadTest.cs index e8098fb665..8c4e89a872 100644 --- a/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadTest.cs +++ b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadTest.cs @@ -140,9 +140,30 @@ public async Task DownloadFfMpeg_MissingIndex() new FakeIFfMpegDownloadIndex(), new FakeIFfMpegDownloadBinaries(), new FakeIFfMpegPrepareBeforeRunning()); - var result = await ffmpegDownload.DownloadFfMpeg(); + var resultMissingIndex = await ffmpegDownload.DownloadFfMpeg(); + + Assert.AreEqual(FfmpegDownloadStatus.DownloadIndexFailed, resultMissingIndex); + } + + [TestMethod] + public async Task DownloadFfMpeg_MissingIndex_DownloadBinariesFailedMissingFileName() + { + var appSettings = new AppSettings { DependenciesFolder = DependencyFolderName }; + var logger = new FakeIWebLogger(); + + var ffmpegDownload = + new FfMpegDownload(new FakeSelectorStorage(), appSettings, + logger, + // No Index but it says is succeed + new FakeIFfMpegDownloadIndex(new FfmpegBinariesContainer { Success = true }), + new FfMpegDownloadBinaries(new FakeSelectorStorage(_storage), _httpClientHelper, + appSettings, logger, new Zipper(new FakeIWebLogger())), + new FakeIFfMpegPrepareBeforeRunning()); - Assert.AreEqual(FfmpegDownloadStatus.DownloadIndexFailed, result); + var resultMissingIndex = await ffmpegDownload.DownloadFfMpeg(); + + Assert.AreEqual(FfmpegDownloadStatus.DownloadBinariesFailedMissingFileName, + resultMissingIndex); } [TestMethod] @@ -161,9 +182,10 @@ public async Task DownloadFfMpeg_DownloadBinariesFail() new FakeIFfMpegDownloadBinaries(FfmpegDownloadStatus .DownloadBinariesFailedMissingFileName), new FakeIFfMpegPrepareBeforeRunning()); - var result = await ffmpegDownload.DownloadFfMpeg(); + var resultBinaryFail = await ffmpegDownload.DownloadFfMpeg(); - Assert.AreEqual(FfmpegDownloadStatus.DownloadBinariesFailedMissingFileName, result); + Assert.AreEqual(FfmpegDownloadStatus.DownloadBinariesFailedMissingFileName, + resultBinaryFail); } [TestMethod] @@ -187,9 +209,9 @@ public async Task DownloadFfMpeg_FileAlreadyExists() Data = new FfmpegBinariesIndex { Binaries = new List() } }), new FakeIFfMpegDownloadBinaries(), new FakeIFfMpegPrepareBeforeRunning()); - var result = await ffmpegDownload.DownloadFfMpeg(); + var resultFileAlreadyExists = await ffmpegDownload.DownloadFfMpeg(); - Assert.AreEqual(FfmpegDownloadStatus.Ok, result); + Assert.AreEqual(FfmpegDownloadStatus.Ok, resultFileAlreadyExists); } [TestMethod] @@ -212,9 +234,9 @@ public async Task DownloadFfMpeg_DownloadFail_InvalidShaHash() appSettings, logger, new Zipper(new FakeIWebLogger())), new FakeIFfMpegPrepareBeforeRunning()); - var result = await ffmpegDownload.DownloadFfMpeg(); + var resultInvalidHash = await ffmpegDownload.DownloadFfMpeg(); - Assert.AreEqual(FfmpegDownloadStatus.DownloadBinariesFailedSha256Check, result); + Assert.AreEqual(FfmpegDownloadStatus.DownloadBinariesFailedSha256Check, resultInvalidHash); } [TestMethod] @@ -238,9 +260,10 @@ public async Task DownloadFfMpeg_DownloadFail_ZipFileNotFound() appSettings, logger, new Zipper(new FakeIWebLogger())), new FakeIFfMpegPrepareBeforeRunning()); - var result = await ffmpegDownload.DownloadFfMpeg(); + var resultZipFail = await ffmpegDownload.DownloadFfMpeg(); - Assert.AreEqual(FfmpegDownloadStatus.DownloadBinariesFailedZipperNotExtracted, result); + Assert.AreEqual(FfmpegDownloadStatus.DownloadBinariesFailedZipperNotExtracted, + resultZipFail); } [TestMethod] @@ -257,7 +280,7 @@ public async Task DownloadFfMpeg_PrepareBeforeRunningFail() new($"FfMpegDownloadTest{Path.DirectorySeparatorChar}mock_test.zip", [.. new CreateAnZipfileFakeFfMpeg().Bytes]) }, storage); - + var ffmpegDownload = new FfMpegDownload(new FakeSelectorStorage(storage), appSettings, logger, @@ -272,16 +295,16 @@ public async Task DownloadFfMpeg_PrepareBeforeRunningFail() new FfMpegPrepareBeforeRunning(new FakeSelectorStorage(storage), new FakeIMacCodeSign(), new FfMpegChmod(storage, logger), appSettings, logger)); - var result = await ffmpegDownload.DownloadFfMpeg(); + var resultPrepFail = await ffmpegDownload.DownloadFfMpeg(); // Chmod does not exist on windows if ( appSettings.IsWindows ) { - Assert.AreEqual(FfmpegDownloadStatus.Ok, result); + Assert.AreEqual(FfmpegDownloadStatus.Ok, resultPrepFail); return; } - Assert.AreEqual(FfmpegDownloadStatus.PrepareBeforeRunningFailed, result); + Assert.AreEqual(FfmpegDownloadStatus.PrepareBeforeRunningFailed, resultPrepFail); } [TestMethod] @@ -324,8 +347,8 @@ public async Task DownloadFfMpeg_AllStages() { "FfMpegDownloadTest/ffmpeg/ffmpeg", true } }), new FakeIFfmpegChmod(storage), appSettings, logger)); - var result = await ffmpegDownload.DownloadFfMpeg(); + var resultAllStages = await ffmpegDownload.DownloadFfMpeg(); - Assert.AreEqual(FfmpegDownloadStatus.Ok, result); + Assert.AreEqual(FfmpegDownloadStatus.Ok, resultAllStages); } } diff --git a/starsky/starskytest/starsky.foundation.video/GetDependencies/MacCodeSignTests.cs b/starsky/starskytest/starsky.foundation.video/GetDependencies/MacCodeSignTests.cs index 3e20ef49c4..2ac7f309ed 100644 --- a/starsky/starskytest/starsky.foundation.video/GetDependencies/MacCodeSignTests.cs +++ b/starsky/starskytest/starsky.foundation.video/GetDependencies/MacCodeSignTests.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics.CodeAnalysis; using System.IO; using System.Threading.Tasks; using Medallion.Shell; @@ -282,4 +283,28 @@ public async Task MacCodeSignAndXattrExecutable_CodeSign__MacOnly() Assert.IsTrue(codeSignBefore.StandardError.Contains("code object is not signed at all")); Assert.IsTrue(codeSignAfter.StandardError.Contains("Identifier=testExecutable")); } + + [TestMethod] + [DataRow(nameof(MacCodeSign.MacXattrExecutable))] + [DataRow(nameof(MacCodeSign.MacCodeSignAndXattrExecutable))] + [DataRow(nameof(MacCodeSign.MacCodeSignExecutable))] + [SuppressMessage("ReSharper", "ConvertSwitchStatementToSwitchExpression")] + public async Task NotFound(string serviceName) + { + bool? result = true; + switch ( serviceName ) + { + case nameof(MacCodeSign.MacXattrExecutable): + result = await _macCodeSign.MacXattrExecutable("not-found"); + break; + case nameof(MacCodeSign.MacCodeSignAndXattrExecutable): + result = await _macCodeSign.MacCodeSignAndXattrExecutable("not-found"); + break; + case nameof(MacCodeSign.MacCodeSignExecutable): + result = await _macCodeSign.MacCodeSignExecutable("not-found"); + break; + } + + Assert.IsNull(result); + } } From 1d7463e081b7cb20af25be7185b61f26bc209a73 Mon Sep 17 00:00:00 2001 From: Dion Date: Fri, 13 Dec 2024 11:21:11 +0100 Subject: [PATCH 60/73] #1833 add tests --- .../starskytest/FakeMocks/FakeIMacCodeSign.cs | 17 ++++- .../FfMpegPrepareBeforeRunningTests.cs | 72 +++++++++++++++++++ 2 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegPrepareBeforeRunningTests.cs diff --git a/starsky/starskytest/FakeMocks/FakeIMacCodeSign.cs b/starsky/starskytest/FakeMocks/FakeIMacCodeSign.cs index ae11c003d7..fd3817a839 100644 --- a/starsky/starskytest/FakeMocks/FakeIMacCodeSign.cs +++ b/starsky/starskytest/FakeMocks/FakeIMacCodeSign.cs @@ -1,20 +1,35 @@ using System.Collections.Generic; using System.Threading.Tasks; +using starsky.foundation.storage.Interfaces; +using starsky.foundation.video.GetDependencies; using starsky.foundation.video.GetDependencies.Interfaces; namespace starskytest.FakeMocks; public class FakeIMacCodeSign : IMacCodeSign { - private readonly Dictionary _expectedResults; + private readonly Dictionary _expectedResults = new(); + private readonly IStorage? _storage; public FakeIMacCodeSign(Dictionary? expectedResults = null) { _expectedResults = expectedResults ?? new Dictionary(); } + public FakeIMacCodeSign(IStorage storage) + { + _storage = storage; + } + public Task MacCodeSignAndXattrExecutable(string exeFile) { + if ( _storage?.ExistFile( + new MacCodeSign(new FakeSelectorStorage(_storage), new FakeIWebLogger()) + .CodeSignPath) == true ) + { + return Task.FromResult(( bool? ) true); + } + _expectedResults.TryGetValue(exeFile, out var result); return Task.FromResult(result); } diff --git a/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegPrepareBeforeRunningTests.cs b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegPrepareBeforeRunningTests.cs new file mode 100644 index 0000000000..df6fb57f35 --- /dev/null +++ b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegPrepareBeforeRunningTests.cs @@ -0,0 +1,72 @@ +using System.Threading.Tasks; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using starsky.foundation.platform.Models; +using starsky.foundation.storage.Helpers; +using starsky.foundation.video.GetDependencies; +using starskytest.FakeMocks; + +namespace starskytest.starsky.foundation.video.GetDependencies; + +[TestClass] +public class FfMpegPrepareBeforeRunningTests +{ + private readonly FfMpegPrepareBeforeRunning _ffMpegPrepareBeforeRunning; + private readonly FakeIStorage _storage; + + public FfMpegPrepareBeforeRunningTests() + { + _storage = new FakeIStorage([], ["/"]); + _ffMpegPrepareBeforeRunning = new FfMpegPrepareBeforeRunning( + new FakeSelectorStorage(_storage), + new FakeIMacCodeSign(_storage), + new FakeIFfmpegChmod(_storage), + new AppSettings(), + new FakeIWebLogger()); + } + + private async Task WriteOrDeleteFile(bool fileExists, string path) + { + if ( fileExists ) + { + await _storage.WriteStreamAsync(StringToStreamHelper.StringToStream("1"), path); + } + else + { + _storage.FileDelete(path); + } + } + + [DataTestMethod] + [DataRow("win-x64", true, true, true, true)] + [DataRow("win-x64", true, false, false, true)] // no chmod on win-x64 + [DataRow("win-arm64", true, true, true, true)] + [DataRow("win-arm64", true, false, false, true)] // no chmod on win-arm,64 + [DataRow("linux-x64", true, true, false, true)] // no macCodeSign on linux-x64 + [DataRow("linux-x64", true, true, true, true)] + [DataRow("osx-x64", true, true, false, false)] + [DataRow("osx-x64", true, true, true, true)] + [DataRow("osx-arm64", true, true, false, false)] + [DataRow("osx-arm64", true, true, true, true)] + [DataRow("linux-x64", false, true, true, false)] + public async Task PrepareBeforeRunning_ShouldReturn( + string architecture, bool fileExists, bool chmodSuccess, bool macCodeSignSuccess, + bool expectedResult) + { + // Arrange + var exeFile = new FfmpegExePath(new AppSettings()).GetExePath(architecture); + await WriteOrDeleteFile(fileExists, exeFile); + + var chmodPath = new FfMpegChmod(_storage, new FakeIWebLogger()).CmdPath; + await WriteOrDeleteFile(chmodSuccess, chmodPath); + + var macCodeSign = new MacCodeSign(new FakeSelectorStorage(_storage), new FakeIWebLogger()) + .CodeSignPath; + await WriteOrDeleteFile(macCodeSignSuccess, macCodeSign); + + // Act + var result = await _ffMpegPrepareBeforeRunning.PrepareBeforeRunning(architecture); + + // Assert + Assert.AreEqual(expectedResult, result); + } +} From 86a6d467c23136c9fcba9ba3c8e4d4af948f0e1d Mon Sep 17 00:00:00 2001 From: Dion Date: Fri, 13 Dec 2024 11:26:36 +0100 Subject: [PATCH 61/73] #1833 order --- .../GetDependencies/MacCodeSign.cs | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/starsky/starsky.foundation.video/GetDependencies/MacCodeSign.cs b/starsky/starsky.foundation.video/GetDependencies/MacCodeSign.cs index 32847e4054..5faaba7b3a 100644 --- a/starsky/starsky.foundation.video/GetDependencies/MacCodeSign.cs +++ b/starsky/starsky.foundation.video/GetDependencies/MacCodeSign.cs @@ -10,6 +10,9 @@ namespace starsky.foundation.video.GetDependencies; [Service(typeof(IMacCodeSign), InjectionLifetime = InjectionLifetime.Scoped)] public class MacCodeSign : IMacCodeSign { + private const string CodeSignDefaultPath = "/usr/bin/codesign"; + private const string XattrDefaultPath = "/usr/bin/xattr"; + private readonly IStorage _hostFileSystemStorage; private readonly IWebLogger _logger; @@ -20,8 +23,8 @@ public MacCodeSign(ISelectorStorage selectorStorage, IWebLogger logger) _logger = logger; } - public string CodeSignPath { get; set; } = "/usr/bin/codesign"; - public string XattrPath { get; set; } = "/usr/bin/xattr"; + internal string CodeSignPath { get; set; } = CodeSignDefaultPath; + internal string XattrPath { get; set; } = XattrDefaultPath; public async Task MacCodeSignAndXattrExecutable(string exeFile) { @@ -41,14 +44,15 @@ public MacCodeSign(ISelectorStorage selectorStorage, IWebLogger logger) internal async Task MacCodeSignExecutable(string exeFile) { - if ( !_hostFileSystemStorage.ExistFile(CodeSignPath) ) + if ( !_hostFileSystemStorage.ExistFile(exeFile) ) { - _logger.LogError("[RunChmodOnFfmpegExe] WARNING: /usr/bin/codesign does not exist"); + _logger.LogError($"[MacCodeSignExecutable] WARNING: {exeFile} does not exists"); return null; } - if ( !_hostFileSystemStorage.ExistFile(exeFile) ) + if ( !_hostFileSystemStorage.ExistFile(CodeSignPath) ) { + _logger.LogError("[MacCodeSignExecutable] WARNING: /usr/bin/codesign does not exist"); return null; } @@ -60,20 +64,21 @@ public MacCodeSign(ISelectorStorage selectorStorage, IWebLogger logger) } _logger.LogError( - $"codesign Command failed with exit code {result.ExitCode}: {result.StandardError}"); + $"[MacCodeSignExecutable] codesign Command failed with exit code {result.ExitCode}: {result.StandardError}"); return false; } internal async Task MacXattrExecutable(string exeFile) { - if ( !_hostFileSystemStorage.ExistFile(XattrPath) ) + if ( !_hostFileSystemStorage.ExistFile(exeFile) ) { - _logger.LogError("[RunChmodOnFfmpegExe] WARNING: /usr/bin/xattr does not exist"); + _logger.LogError($"[MacXattrExecutable] WARNING: {exeFile} does not exists"); return null; } - if ( !_hostFileSystemStorage.ExistFile(exeFile) ) + if ( !_hostFileSystemStorage.ExistFile(XattrPath) ) { + _logger.LogError("[MacXattrExecutable] WARNING: /usr/bin/xattr does not exist"); return null; } @@ -85,7 +90,7 @@ public MacCodeSign(ISelectorStorage selectorStorage, IWebLogger logger) } _logger.LogError( - $"xattr Command failed with exit code {result.ExitCode}: {result.StandardError}"); + $"[MacXattrExecutable] xattr Command failed with exit code {result.ExitCode}: {result.StandardError}"); return false; } } From 9a8c921add60359204dd5abae3a863c8905f778f Mon Sep 17 00:00:00 2001 From: Dion Date: Fri, 13 Dec 2024 11:43:11 +0100 Subject: [PATCH 62/73] #1833 fix --- .../GetDependencies/FfMpegChmod.cs | 17 +++++-- .../FfMpegDownloadBackgroundService.cs | 36 ++++++++++++++ starsky/starsky/Startup.cs | 2 + starsky/starsky/starsky.csproj | 7 +-- .../starskytest/FakeMocks/FakeIFfmpegChmod.cs | 2 +- .../GetDependencies/FfMpegChmodTests.cs | 12 ++--- .../GetDependencies/FfMpegDownloadTest.cs | 4 +- .../FfMpegPrepareBeforeRunningTests.cs | 3 +- .../GetDependencies/MacCodeSignTests.cs | 9 ++-- .../ExifToolDownloadBackgroundServiceTest.cs | 47 +++++++++---------- 10 files changed, 96 insertions(+), 43 deletions(-) create mode 100644 starsky/starsky.foundation.video/GetDependencies/FfMpegDownloadBackgroundService.cs diff --git a/starsky/starsky.foundation.video/GetDependencies/FfMpegChmod.cs b/starsky/starsky.foundation.video/GetDependencies/FfMpegChmod.cs index 98bf42c047..73deb63c1e 100644 --- a/starsky/starsky.foundation.video/GetDependencies/FfMpegChmod.cs +++ b/starsky/starsky.foundation.video/GetDependencies/FfMpegChmod.cs @@ -2,20 +2,29 @@ using starsky.foundation.injection; using starsky.foundation.platform.Interfaces; using starsky.foundation.storage.Interfaces; +using starsky.foundation.storage.Storage; using starsky.foundation.video.GetDependencies.Interfaces; namespace starsky.foundation.video.GetDependencies; [Service(typeof(IFfmpegChmod), InjectionLifetime = InjectionLifetime.Scoped)] -public class FfMpegChmod(IStorage hostFileSystemStorage, IWebLogger logger) : IFfmpegChmod +public class FfMpegChmod : IFfmpegChmod { + private readonly IStorage _hostFileSystemStorage; + private readonly IWebLogger _logger; + + public FfMpegChmod(ISelectorStorage selectorStorage, IWebLogger logger) + { + _hostFileSystemStorage = selectorStorage.Get(SelectorStorage.StorageServices.HostFilesystem); + _logger = logger; + } internal string CmdPath { get; set; } = "/bin/chmod"; public async Task Chmod(string exeFile) { - if ( !hostFileSystemStorage.ExistFile(CmdPath) ) + if ( !_hostFileSystemStorage.ExistFile(CmdPath) ) { - logger.LogError("[RunChmodOnFfmpegExe] WARNING: /bin/chmod does not exist"); + _logger.LogError("[RunChmodOnFfmpegExe] WARNING: /bin/chmod does not exist"); return false; } @@ -26,7 +35,7 @@ public async Task Chmod(string exeFile) return true; } - logger.LogError( + _logger.LogError( $"command failed with exit code {result.ExitCode}: {result.StandardError}"); return false; } diff --git a/starsky/starsky.foundation.video/GetDependencies/FfMpegDownloadBackgroundService.cs b/starsky/starsky.foundation.video/GetDependencies/FfMpegDownloadBackgroundService.cs new file mode 100644 index 0000000000..205f87ccdb --- /dev/null +++ b/starsky/starsky.foundation.video/GetDependencies/FfMpegDownloadBackgroundService.cs @@ -0,0 +1,36 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using starsky.foundation.injection; +using starsky.foundation.platform.Interfaces; +using starsky.foundation.platform.Models; +using starsky.foundation.storage.Interfaces; +using starsky.foundation.video.GetDependencies.Interfaces; + +namespace starsky.foundation.video.GetDependencies; + +[Service(typeof(IHostedService), InjectionLifetime = InjectionLifetime.Singleton)] +public sealed class FfMpegDownloadBackgroundService(IServiceScopeFactory serviceScopeFactory) + : BackgroundService +{ + /// + /// Running scoped services + /// @see: https://thinkrethink.net/2018/07/12/injecting-a-scoped-service-into-ihostedservice/ + /// + /// Cancellation Token, but it ignored + /// CompletedTask + protected override async Task ExecuteAsync(CancellationToken stoppingToken) + { + using var scope = serviceScopeFactory.CreateScope(); + var selectorStorage = scope.ServiceProvider.GetRequiredService(); + var appSettings = scope.ServiceProvider.GetRequiredService(); + var logger = scope.ServiceProvider.GetRequiredService(); + var downloadIndex = scope.ServiceProvider.GetRequiredService(); + var downloadBinaries = + scope.ServiceProvider.GetRequiredService(); + var prepareBeforeRunning = + scope.ServiceProvider.GetRequiredService(); + + await new FfMpegDownload(selectorStorage, appSettings, logger, downloadIndex, + downloadBinaries, prepareBeforeRunning).DownloadFfMpeg(); + } +} diff --git a/starsky/starsky/Startup.cs b/starsky/starsky/Startup.cs index 79f1f9c22d..5e07c25009 100644 --- a/starsky/starsky/Startup.cs +++ b/starsky/starsky/Startup.cs @@ -32,6 +32,7 @@ using starsky.foundation.platform.Models; using starsky.foundation.realtime.Extentions; using starsky.foundation.realtime.Model; +using starsky.foundation.video.GetDependencies; using starsky.foundation.webtelemetry.Extensions; using starsky.foundation.webtelemetry.Helpers; using starsky.Helpers; @@ -188,6 +189,7 @@ public void ConfigureServices(IServiceCollection services) services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); + services.AddSingleton(); } /// diff --git a/starsky/starsky/starsky.csproj b/starsky/starsky/starsky.csproj index 1760ea5885..8391701cb4 100644 --- a/starsky/starsky/starsky.csproj +++ b/starsky/starsky/starsky.csproj @@ -59,9 +59,9 @@ 0 - - - + + + @@ -166,6 +166,7 @@ + diff --git a/starsky/starskytest/FakeMocks/FakeIFfmpegChmod.cs b/starsky/starskytest/FakeMocks/FakeIFfmpegChmod.cs index 5bb26af713..12a40785ff 100644 --- a/starsky/starskytest/FakeMocks/FakeIFfmpegChmod.cs +++ b/starsky/starskytest/FakeMocks/FakeIFfmpegChmod.cs @@ -10,6 +10,6 @@ public class FakeIFfmpegChmod(IStorage hostFileSystemStorage) : IFfmpegChmod public Task Chmod(string exeFile) { return Task.FromResult(hostFileSystemStorage.ExistFile( - new FfMpegChmod(hostFileSystemStorage, new FakeIWebLogger()).CmdPath)); + new FfMpegChmod(new FakeSelectorStorage(hostFileSystemStorage), new FakeIWebLogger()).CmdPath)); } } diff --git a/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegChmodTests.cs b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegChmodTests.cs index 5d9deca683..95bf9de13b 100644 --- a/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegChmodTests.cs +++ b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegChmodTests.cs @@ -28,7 +28,7 @@ public FfMpegChmodTests() { _hostFileSystemStorage = new StorageHostFullPathFilesystem(new FakeIWebLogger()); _logger = new FakeIWebLogger(); - _ffMpegChmod = new FfMpegChmod(_hostFileSystemStorage, _logger); + _ffMpegChmod = new FfMpegChmod(new FakeSelectorStorage(_hostFileSystemStorage), _logger); _parentFolder = Path.Combine(new CreateAnImage().BasePath, "FfmpegChmodTests"); @@ -58,7 +58,7 @@ private void DeleteFile() [TestMethod] public async Task Chmod_ShouldReturnFalse_WhenChmodDoesNotExist() { - var sut = new FfMpegChmod(new FakeIStorage(), new FakeIWebLogger()); + var sut = new FfMpegChmod(new FakeSelectorStorage(), new FakeIWebLogger()); var result = await sut.Chmod(_ffmpegExePath.GetExePath("linux-x64")); Assert.IsFalse(result); @@ -95,8 +95,8 @@ public async Task Chmod_ShouldReturnFalse_WhenCommandFails__UnixOnly() return; } - var sut = new FfMpegChmod(new FakeIStorage([], - ["/bin/chmod"]), + var sut = new FfMpegChmod(new FakeSelectorStorage(new FakeIStorage([], + ["/bin/chmod"])), new FakeIWebLogger()); var result = await sut.Chmod("/_not_found_path/to/ffmpeg"); @@ -115,8 +115,8 @@ public async Task Chmod_ShouldReturnFalse_WhenCommandSucceed__WindowsOnly() CreateFile(); var path = Path.Combine(_ffmpegExePath.GetExeParentFolder(), "chmod.exe"); - var sut = new FfMpegChmod(new FakeIStorage([], - [path]), + var sut = new FfMpegChmod(new FakeSelectorStorage(new FakeIStorage([], + [path])), new FakeIWebLogger()) { CmdPath = path }; var result = await sut.Chmod("/_not_found_path/to/ffmpeg"); diff --git a/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadTest.cs b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadTest.cs index 8c4e89a872..aa8605fac9 100644 --- a/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadTest.cs +++ b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadTest.cs @@ -293,7 +293,9 @@ public async Task DownloadFfMpeg_PrepareBeforeRunningFail() }), new FfMpegDownloadBinaries(new FakeSelectorStorage(storage), _httpClientHelper, appSettings, logger, zipper), new FfMpegPrepareBeforeRunning(new FakeSelectorStorage(storage), - new FakeIMacCodeSign(), new FfMpegChmod(storage, logger), appSettings, logger)); + new FakeIMacCodeSign(), + new FfMpegChmod(new FakeSelectorStorage(storage), logger), appSettings, + logger)); var resultPrepFail = await ffmpegDownload.DownloadFfMpeg(); diff --git a/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegPrepareBeforeRunningTests.cs b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegPrepareBeforeRunningTests.cs index df6fb57f35..cb1757a42d 100644 --- a/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegPrepareBeforeRunningTests.cs +++ b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegPrepareBeforeRunningTests.cs @@ -56,7 +56,8 @@ public async Task PrepareBeforeRunning_ShouldReturn( var exeFile = new FfmpegExePath(new AppSettings()).GetExePath(architecture); await WriteOrDeleteFile(fileExists, exeFile); - var chmodPath = new FfMpegChmod(_storage, new FakeIWebLogger()).CmdPath; + var chmodPath = new FfMpegChmod(new FakeSelectorStorage(_storage), new FakeIWebLogger()) + .CmdPath; await WriteOrDeleteFile(chmodSuccess, chmodPath); var macCodeSign = new MacCodeSign(new FakeSelectorStorage(_storage), new FakeIWebLogger()) diff --git a/starsky/starskytest/starsky.foundation.video/GetDependencies/MacCodeSignTests.cs b/starsky/starskytest/starsky.foundation.video/GetDependencies/MacCodeSignTests.cs index 2ac7f309ed..552e14028e 100644 --- a/starsky/starskytest/starsky.foundation.video/GetDependencies/MacCodeSignTests.cs +++ b/starsky/starskytest/starsky.foundation.video/GetDependencies/MacCodeSignTests.cs @@ -53,7 +53,8 @@ public void Cleanup() private async Task CreateStubExeFile() { - var chmodHelper = new FfMpegChmod(_hostFileSystemStorage, new FakeIWebLogger()); + var chmodHelper = new FfMpegChmod(new FakeSelectorStorage(_hostFileSystemStorage), + new FakeIWebLogger()); var exeFile = Path.Combine(_testFolder, "testExecutable"); CreateStubFile(exeFile, "#!/bin/bash\necho Fake Executable"); await chmodHelper.Chmod(exeFile); @@ -62,7 +63,8 @@ private async Task CreateStubExeFile() private async Task CreateStubCodeSignFile(int codeSignExitCode) { - var chmodHelper = new FfMpegChmod(_hostFileSystemStorage, new FakeIWebLogger()); + var chmodHelper = new FfMpegChmod(new FakeSelectorStorage(_hostFileSystemStorage), + new FakeIWebLogger()); var codeSignPath = Path.Combine(_testFolder, "codesign"); CreateStubFile(codeSignPath, $"#!/bin/bash\necho codesign\nexit {codeSignExitCode}"); _macCodeSign.CodeSignPath = codeSignPath; @@ -71,7 +73,8 @@ private async Task CreateStubCodeSignFile(int codeSignExitCode) private async Task CreateStubXattrFile(int xattrExitCode) { - var chmodHelper = new FfMpegChmod(_hostFileSystemStorage, new FakeIWebLogger()); + var chmodHelper = new FfMpegChmod(new FakeSelectorStorage(_hostFileSystemStorage), + new FakeIWebLogger()); var xattrPath = Path.Combine(_testFolder, "xattr"); CreateStubFile(xattrPath, $"#!/bin/bash\nexit {xattrExitCode}"); _macCodeSign.XattrPath = xattrPath; diff --git a/starsky/starskytest/starsky.foundation.writemeta/Services/ExifToolDownloadBackgroundServiceTest.cs b/starsky/starskytest/starsky.foundation.writemeta/Services/ExifToolDownloadBackgroundServiceTest.cs index 68db5dacb0..1803c1c725 100644 --- a/starsky/starskytest/starsky.foundation.writemeta/Services/ExifToolDownloadBackgroundServiceTest.cs +++ b/starsky/starskytest/starsky.foundation.writemeta/Services/ExifToolDownloadBackgroundServiceTest.cs @@ -11,33 +11,32 @@ using starsky.foundation.writemeta.Services; using starskytest.FakeMocks; -namespace starskytest.starsky.foundation.writemeta.Services +namespace starskytest.starsky.foundation.writemeta.Services; + +[TestClass] +public sealed class ExifToolDownloadBackgroundServiceTest { - [TestClass] - public sealed class ExifToolDownloadBackgroundServiceTest + private readonly IServiceScopeFactory _serviceScopeFactory; + + public ExifToolDownloadBackgroundServiceTest() { - private readonly IServiceScopeFactory _serviceScopeFactory; + var services = new ServiceCollection(); + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); - public ExifToolDownloadBackgroundServiceTest() - { - var services = new ServiceCollection(); - services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); + var serviceProvider = services.BuildServiceProvider(); + _serviceScopeFactory = serviceProvider.GetRequiredService(); + } - var serviceProvider = services.BuildServiceProvider(); - _serviceScopeFactory = serviceProvider.GetRequiredService(); - } - - [TestMethod] - public async Task StartAsync() - { - var cancelToken = new CancellationToken(); - await new ExifToolDownloadBackgroundService(_serviceScopeFactory).StartAsync(cancelToken); - Assert.IsNotNull(cancelToken); - } + [TestMethod] + public async Task StartAsync() + { + var cancelToken = new CancellationToken(); + await new ExifToolDownloadBackgroundService(_serviceScopeFactory).StartAsync(cancelToken); + Assert.IsNotNull(cancelToken); } } From d11bbfe7379d78053d434b11ae96b962bce1fc4d Mon Sep 17 00:00:00 2001 From: Dion Date: Fri, 13 Dec 2024 11:51:36 +0100 Subject: [PATCH 63/73] #1833 add arch to foldername --- .../GetDependencies/FfMpegDownload.cs | 8 ++++---- .../GetDependencies/FfMpegDownloadBinaries.cs | 2 +- .../GetDependencies/FfMpegExePath.cs | 9 ++++++--- .../GetDependencies/FfMpegChmodTests.cs | 6 +++--- .../GetDependencies/FfMpegDownloadTest.cs | 5 ++++- .../GetDependencies/FfmpegExePathTests.cs | 5 +++-- 6 files changed, 21 insertions(+), 14 deletions(-) diff --git a/starsky/starsky.foundation.video/GetDependencies/FfMpegDownload.cs b/starsky/starsky.foundation.video/GetDependencies/FfMpegDownload.cs index 8d5fb05f9b..d798c590af 100644 --- a/starsky/starsky.foundation.video/GetDependencies/FfMpegDownload.cs +++ b/starsky/starsky.foundation.video/GetDependencies/FfMpegDownload.cs @@ -47,9 +47,8 @@ public async Task DownloadFfMpeg() return FfmpegDownloadStatus.SettingsDisabled; } - CreateDirectoryDependenciesFolderIfNotExists(); - var currentArchitecture = CurrentArchitecture.GetCurrentRuntimeIdentifier(); + CreateDirectoryDependenciesFolderIfNotExists(currentArchitecture); if ( _hostFileSystemStorage.ExistFile(_ffmpegExePath.GetExePath(currentArchitecture)) ) { @@ -93,11 +92,12 @@ public async Task DownloadFfMpeg() } - private void CreateDirectoryDependenciesFolderIfNotExists() + private void CreateDirectoryDependenciesFolderIfNotExists(string currentArchitecture) { foreach ( var path in new List { - _appSettings.DependenciesFolder, _ffmpegExePath.GetExeParentFolder() + _appSettings.DependenciesFolder, + _ffmpegExePath.GetExeParentFolder(currentArchitecture) } ) { if ( _hostFileSystemStorage.ExistFolder(path) ) diff --git a/starsky/starsky.foundation.video/GetDependencies/FfMpegDownloadBinaries.cs b/starsky/starsky.foundation.video/GetDependencies/FfMpegDownloadBinaries.cs index d844847ef7..a2fb2308cd 100644 --- a/starsky/starsky.foundation.video/GetDependencies/FfMpegDownloadBinaries.cs +++ b/starsky/starsky.foundation.video/GetDependencies/FfMpegDownloadBinaries.cs @@ -65,7 +65,7 @@ public async Task Download( return FfmpegDownloadStatus.DownloadBinariesFailedSha256Check; } - _zipper.ExtractZip(zipFullFilePath, _ffmpegExePath.GetExeParentFolder()); + _zipper.ExtractZip(zipFullFilePath, _ffmpegExePath.GetExeParentFolder(currentArchitecture)); if ( !_hostFileSystemStorage.ExistFile(_ffmpegExePath.GetExePath(currentArchitecture)) ) { diff --git a/starsky/starsky.foundation.video/GetDependencies/FfMpegExePath.cs b/starsky/starsky.foundation.video/GetDependencies/FfMpegExePath.cs index 8d0c326d51..8d4de46637 100644 --- a/starsky/starsky.foundation.video/GetDependencies/FfMpegExePath.cs +++ b/starsky/starsky.foundation.video/GetDependencies/FfMpegExePath.cs @@ -7,14 +7,17 @@ public class FfmpegExePath(AppSettings appSettings) private const string FfmpegDependenciesFolder = "ffmpeg"; private const string FfmpegExecutableBaseName = "ffmpeg"; - internal string GetExeParentFolder() + internal string GetExeParentFolder(string currentArchitecture) { - return Path.Combine(appSettings.DependenciesFolder, FfmpegDependenciesFolder); + return Path.Combine(appSettings.DependenciesFolder, + string.IsNullOrEmpty(currentArchitecture) + ? FfmpegDependenciesFolder + : $"{FfmpegDependenciesFolder}-{currentArchitecture}"); } internal string GetExePath(string currentArchitecture) { - var exeFile = Path.Combine(appSettings.DependenciesFolder, FfmpegDependenciesFolder, + var exeFile = Path.Combine(GetExeParentFolder(currentArchitecture), FfmpegExecutableBaseName); if ( currentArchitecture is "win-x64" or "win-arm64" ) { diff --git a/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegChmodTests.cs b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegChmodTests.cs index 95bf9de13b..ed2b91c905 100644 --- a/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegChmodTests.cs +++ b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegChmodTests.cs @@ -38,7 +38,7 @@ public FfMpegChmodTests() private void CreateFile() { - _hostFileSystemStorage.CreateDirectory(_ffmpegExePath.GetExeParentFolder()); + _hostFileSystemStorage.CreateDirectory(_ffmpegExePath.GetExeParentFolder("linux-x64")); var stream = StringToStreamHelper.StringToStream("#!/bin/bash\necho Fake Ffmpeg"); _hostFileSystemStorage.WriteStream(stream, _ffmpegExePath.GetExePath("linux-x64")); @@ -47,7 +47,7 @@ private void CreateFile() var (_, item) = result.FirstOrDefault(p => p.Key.Contains("exiftool")); _hostFileSystemStorage.WriteStream(new MemoryStream(item), - Path.Combine(_ffmpegExePath.GetExeParentFolder(), "chmod.exe")); + Path.Combine(_ffmpegExePath.GetExeParentFolder("linux-x64"), "chmod.exe")); } private void DeleteFile() @@ -114,7 +114,7 @@ public async Task Chmod_ShouldReturnFalse_WhenCommandSucceed__WindowsOnly() CreateFile(); - var path = Path.Combine(_ffmpegExePath.GetExeParentFolder(), "chmod.exe"); + var path = Path.Combine(_ffmpegExePath.GetExeParentFolder("win-x64"), "chmod.exe"); var sut = new FfMpegChmod(new FakeSelectorStorage(new FakeIStorage([], [path])), new FakeIWebLogger()) { CmdPath = path }; diff --git a/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadTest.cs b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadTest.cs index aa8605fac9..3a88fd0129 100644 --- a/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadTest.cs +++ b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadTest.cs @@ -346,7 +346,10 @@ public async Task DownloadFfMpeg_AllStages() new FakeSelectorStorage(storage), new FakeIMacCodeSign(new Dictionary { - { "FfMpegDownloadTest/ffmpeg/ffmpeg", true } + { + $"FfMpegDownloadTest/ffmpeg-{CurrentArchitecture.GetCurrentRuntimeIdentifier()}/ffmpeg", + true + } }), new FakeIFfmpegChmod(storage), appSettings, logger)); var resultAllStages = await ffmpegDownload.DownloadFfMpeg(); diff --git a/starsky/starskytest/starsky.foundation.video/GetDependencies/FfmpegExePathTests.cs b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfmpegExePathTests.cs index dc0dd54557..5da5acb61f 100644 --- a/starsky/starskytest/starsky.foundation.video/GetDependencies/FfmpegExePathTests.cs +++ b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfmpegExePathTests.cs @@ -21,7 +21,7 @@ public FfmpegExePathTests() public void GetExeParentFolder_ShouldReturnCorrectPath() { var expectedPath = Path.Combine(_appSettings.DependenciesFolder, "ffmpeg"); - var result = _ffmpegExePath.GetExeParentFolder(); + var result = _ffmpegExePath.GetExeParentFolder(string.Empty); Assert.AreEqual(expectedPath, result); } @@ -33,7 +33,8 @@ public void GetExeParentFolder_ShouldReturnCorrectPath() public void GetExePath_ShouldReturnCorrectPath(string architecture, string expectedFileName) { var expectedPath = - Path.Combine(_appSettings.DependenciesFolder, "ffmpeg", expectedFileName); + Path.Combine(_appSettings.DependenciesFolder, $"ffmpeg-{architecture}", + expectedFileName); var result = _ffmpegExePath.GetExePath(architecture); Assert.AreEqual(expectedPath, result); } From f24421eba7b3824325ae1a6bf349251b78bf5224 Mon Sep 17 00:00:00 2001 From: Dion Date: Fri, 13 Dec 2024 11:52:24 +0100 Subject: [PATCH 64/73] #1833 fix __ domain --- .../GetDependencies/FfMpegDownloadIndex.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/starsky/starsky.foundation.video/GetDependencies/FfMpegDownloadIndex.cs b/starsky/starsky.foundation.video/GetDependencies/FfMpegDownloadIndex.cs index 5345f41f80..644313855b 100644 --- a/starsky/starsky.foundation.video/GetDependencies/FfMpegDownloadIndex.cs +++ b/starsky/starsky.foundation.video/GetDependencies/FfMpegDownloadIndex.cs @@ -14,7 +14,7 @@ public class FfMpegDownloadIndex(IHttpClientHelper httpClientHelper, IWebLogger : IFfMpegDownloadIndex { private const string QdrawMirrorDomain = "qdraw.nl/special/mirror/ffmpeg"; - private const string NetlifyMirrorDomain = "_____starsky-dependencies.netlify.app/ffmpeg"; + private const string NetlifyMirrorDomain = "starsky-dependencies.netlify.app/ffmpeg"; private static readonly Uri FfMpegApiBasePath = new($"https://{NetlifyMirrorDomain}/"); private static readonly Uri FfMpegApiBasePathMirror = new($"https://{QdrawMirrorDomain}/"); From 11be84f921457fa6034d7280daaccf9c16fd9d3d Mon Sep 17 00:00:00 2001 From: Dion Date: Fri, 13 Dec 2024 11:57:00 +0100 Subject: [PATCH 65/73] #1833 test --- .../GetDependencies/FfmpegExePathTests.cs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/starsky/starskytest/starsky.foundation.video/GetDependencies/FfmpegExePathTests.cs b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfmpegExePathTests.cs index 5da5acb61f..70defb9c4e 100644 --- a/starsky/starskytest/starsky.foundation.video/GetDependencies/FfmpegExePathTests.cs +++ b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfmpegExePathTests.cs @@ -17,15 +17,21 @@ public FfmpegExePathTests() _ffmpegExePath = new FfmpegExePath(_appSettings); } - [TestMethod] - public void GetExeParentFolder_ShouldReturnCorrectPath() + [DataTestMethod] + [DataRow(null, "ffmpeg")] + [DataRow("", "ffmpeg")] + [DataRow("win-x64", "ffmpeg-win-x64")] + [DataRow("win-arm64", "ffmpeg-win-arm64")] + [DataRow("linux-x64", "ffmpeg-linux-x64")] + [DataRow("osx-x64", "ffmpeg-osx-x64")] + public void GetExeParentFolder_CurrentArchitecture(string arch, string expectedFolder) { - var expectedPath = Path.Combine(_appSettings.DependenciesFolder, "ffmpeg"); - var result = _ffmpegExePath.GetExeParentFolder(string.Empty); + var expectedPath = Path.Combine(_appSettings.DependenciesFolder, expectedFolder); + var result = _ffmpegExePath.GetExeParentFolder(arch); Assert.AreEqual(expectedPath, result); } - [TestMethod] + [DataTestMethod] [DataRow("win-x64", "ffmpeg.exe")] [DataRow("win-arm64", "ffmpeg.exe")] [DataRow("linux-x64", "ffmpeg")] From 3dd53a014ec34c3bd662be668f382ee0fade5dcb Mon Sep 17 00:00:00 2001 From: Dion Date: Fri, 13 Dec 2024 12:02:49 +0100 Subject: [PATCH 66/73] #1833 add test --- .../FfMpegDownloadBackgroundServiceTests.cs | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadBackgroundServiceTests.cs diff --git a/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadBackgroundServiceTests.cs b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadBackgroundServiceTests.cs new file mode 100644 index 0000000000..46dd092aa1 --- /dev/null +++ b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadBackgroundServiceTests.cs @@ -0,0 +1,42 @@ +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using starsky.foundation.platform.Interfaces; +using starsky.foundation.platform.Models; +using starsky.foundation.storage.Interfaces; +using starsky.foundation.video.GetDependencies; +using starsky.foundation.video.GetDependencies.Interfaces; +using starskytest.FakeMocks; + +namespace starskytest.starsky.foundation.video.GetDependencies; + +[TestClass] +public sealed class FfMpegDownloadBackgroundServiceTests +{ + private readonly IServiceScopeFactory _serviceScopeFactory; + + public FfMpegDownloadBackgroundServiceTests() + { + var services = new ServiceCollection(); + services.AddSingleton(new AppSettings { FfmpegSkipDownloadOnStartup = true }); + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + + var serviceProvider = services.BuildServiceProvider(); + _serviceScopeFactory = serviceProvider.GetRequiredService(); + } + + [TestMethod] + public async Task StartAsync() + { + var cancelToken = new CancellationToken(); + await new FfMpegDownloadBackgroundService(_serviceScopeFactory).StartAsync(cancelToken); + Assert.IsNotNull(cancelToken); + } +} From 0ae47863169f13b073215b8180c906171950a5b2 Mon Sep 17 00:00:00 2001 From: Dion Date: Wed, 18 Dec 2024 19:37:02 +0100 Subject: [PATCH 67/73] #1833 add preflight --- .../GetDependencies/FfMpegDownload.cs | 10 +- .../FfMpegDownloadBackgroundService.cs | 7 +- .../GetDependencies/FfMpegExePath.cs | 15 +++ .../FfMpegPreflightRunCheck.cs | 57 +++++++++ .../Interfaces/IFfMpegPreflightRunCheck.cs | 7 ++ .../Models/FfmpegDownloadStatus.cs | 3 +- .../FakeMocks/FakeIFfMpegPreflightRunCheck.cs | 37 ++++++ .../FfMpegDownloadBackgroundServiceTests.cs | 1 + .../GetDependencies/FfMpegDownloadTest.cs | 70 +++++++++-- .../FfMpegPreflightRunCheckTests.cs | 113 ++++++++++++++++++ 10 files changed, 307 insertions(+), 13 deletions(-) create mode 100644 starsky/starsky.foundation.video/GetDependencies/FfMpegPreflightRunCheck.cs create mode 100644 starsky/starsky.foundation.video/GetDependencies/Interfaces/IFfMpegPreflightRunCheck.cs create mode 100644 starsky/starskytest/FakeMocks/FakeIFfMpegPreflightRunCheck.cs create mode 100644 starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegPreflightRunCheckTests.cs diff --git a/starsky/starsky.foundation.video/GetDependencies/FfMpegDownload.cs b/starsky/starsky.foundation.video/GetDependencies/FfMpegDownload.cs index d798c590af..c3f2f2f252 100644 --- a/starsky/starsky.foundation.video/GetDependencies/FfMpegDownload.cs +++ b/starsky/starsky.foundation.video/GetDependencies/FfMpegDownload.cs @@ -18,12 +18,14 @@ public class FfMpegDownload : IFfMpegDownload private readonly FfmpegExePath _ffmpegExePath; private readonly IStorage _hostFileSystemStorage; private readonly IWebLogger _logger; + private readonly IFfMpegPreflightRunCheck _preflightRunCheck; private readonly IFfMpegPrepareBeforeRunning _prepareBeforeRunning; public FfMpegDownload(ISelectorStorage selectorStorage, AppSettings appSettings, IWebLogger logger, IFfMpegDownloadIndex downloadIndex, - IFfMpegDownloadBinaries downloadBinaries, IFfMpegPrepareBeforeRunning prepareBeforeRunning) + IFfMpegDownloadBinaries downloadBinaries, IFfMpegPrepareBeforeRunning prepareBeforeRunning, + IFfMpegPreflightRunCheck preflightRunCheck) { _appSettings = appSettings; _hostFileSystemStorage = @@ -33,6 +35,7 @@ public FfMpegDownload(ISelectorStorage selectorStorage, _ffmpegExePath = new FfmpegExePath(_appSettings); _downloadBinaries = downloadBinaries; _prepareBeforeRunning = prepareBeforeRunning; + _preflightRunCheck = preflightRunCheck; } public async Task DownloadFfMpeg() @@ -78,6 +81,11 @@ public async Task DownloadFfMpeg() return FfmpegDownloadStatus.PrepareBeforeRunningFailed; } + if ( !await _preflightRunCheck.TryRun(currentArchitecture) ) + { + return FfmpegDownloadStatus.PreflightRunCheckFailed; + } + return FfmpegDownloadStatus.Ok; } diff --git a/starsky/starsky.foundation.video/GetDependencies/FfMpegDownloadBackgroundService.cs b/starsky/starsky.foundation.video/GetDependencies/FfMpegDownloadBackgroundService.cs index 205f87ccdb..b05124476f 100644 --- a/starsky/starsky.foundation.video/GetDependencies/FfMpegDownloadBackgroundService.cs +++ b/starsky/starsky.foundation.video/GetDependencies/FfMpegDownloadBackgroundService.cs @@ -29,8 +29,11 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken) scope.ServiceProvider.GetRequiredService(); var prepareBeforeRunning = scope.ServiceProvider.GetRequiredService(); + var preflightBeforeRunning = + scope.ServiceProvider.GetRequiredService(); - await new FfMpegDownload(selectorStorage, appSettings, logger, downloadIndex, - downloadBinaries, prepareBeforeRunning).DownloadFfMpeg(); + var service = new FfMpegDownload(selectorStorage, appSettings, logger, downloadIndex, + downloadBinaries, prepareBeforeRunning, preflightBeforeRunning); + await service.DownloadFfMpeg(); } } diff --git a/starsky/starsky.foundation.video/GetDependencies/FfMpegExePath.cs b/starsky/starsky.foundation.video/GetDependencies/FfMpegExePath.cs index 8d4de46637..516206f934 100644 --- a/starsky/starsky.foundation.video/GetDependencies/FfMpegExePath.cs +++ b/starsky/starsky.foundation.video/GetDependencies/FfMpegExePath.cs @@ -1,3 +1,4 @@ +using starsky.foundation.platform.Architecture; using starsky.foundation.platform.Models; namespace starsky.foundation.video.GetDependencies; @@ -15,6 +16,20 @@ internal string GetExeParentFolder(string currentArchitecture) : $"{FfmpegDependenciesFolder}-{currentArchitecture}"); } + /// + /// Get the path to the ffmpeg executable (assume current architecture) + /// + /// Full path of executable + internal string GetExePath() + { + return GetExePath(CurrentArchitecture + .GetCurrentRuntimeIdentifier()); + } + + /// + /// Get the path to the ffmpeg executable + /// + /// Full path of executable internal string GetExePath(string currentArchitecture) { var exeFile = Path.Combine(GetExeParentFolder(currentArchitecture), diff --git a/starsky/starsky.foundation.video/GetDependencies/FfMpegPreflightRunCheck.cs b/starsky/starsky.foundation.video/GetDependencies/FfMpegPreflightRunCheck.cs new file mode 100644 index 0000000000..ef87b734eb --- /dev/null +++ b/starsky/starsky.foundation.video/GetDependencies/FfMpegPreflightRunCheck.cs @@ -0,0 +1,57 @@ +using Medallion.Shell; +using starsky.foundation.injection; +using starsky.foundation.platform.Architecture; +using starsky.foundation.platform.Interfaces; +using starsky.foundation.platform.Models; +using starsky.foundation.video.GetDependencies.Interfaces; + +namespace starsky.foundation.video.GetDependencies; + +[Service(typeof(IFfMpegPreflightRunCheck), InjectionLifetime = InjectionLifetime.Scoped)] +public class FfMpegPreflightRunCheck(AppSettings appSettings, IWebLogger logger) + : IFfMpegPreflightRunCheck +{ + public async Task TryRun() + { + var currentArchitecture = CurrentArchitecture.GetCurrentRuntimeIdentifier(); + return await TryRun(currentArchitecture); + } + + public async Task TryRun(string currentArchitecture) + { + var exePath = new FfmpegExePath(appSettings).GetExePath(currentArchitecture); + + try + { + var result = await Command.Run(exePath, "-version").Task; + + // Check if the command was successful + if ( result.Success ) + { + var output = result.StandardOutput; + if ( output.Contains("ffmpeg", StringComparison.OrdinalIgnoreCase) ) + { + return true; + } + + logger.LogError($"[{nameof(FfMpegPreflightRunCheck)}] Invalid application"); + } + else + { + logger.LogError($"[{nameof(FfMpegPreflightRunCheck)}] " + + $"Command failed with exit code " + + $"{result.ExitCode}: {result.StandardError}"); + } + + return false; + } + catch ( Exception exception ) + { + logger.LogError($"[{nameof(FfMpegPreflightRunCheck)}] " + + $"An error occurred while checking FFMpeg: " + + $"{exception.Message}"); + + return false; + } + } +} diff --git a/starsky/starsky.foundation.video/GetDependencies/Interfaces/IFfMpegPreflightRunCheck.cs b/starsky/starsky.foundation.video/GetDependencies/Interfaces/IFfMpegPreflightRunCheck.cs new file mode 100644 index 0000000000..5c2824bf9c --- /dev/null +++ b/starsky/starsky.foundation.video/GetDependencies/Interfaces/IFfMpegPreflightRunCheck.cs @@ -0,0 +1,7 @@ +namespace starsky.foundation.video.GetDependencies.Interfaces; + +public interface IFfMpegPreflightRunCheck +{ + Task TryRun(); + Task TryRun(string currentArchitecture); +} diff --git a/starsky/starsky.foundation.video/GetDependencies/Models/FfmpegDownloadStatus.cs b/starsky/starsky.foundation.video/GetDependencies/Models/FfmpegDownloadStatus.cs index 77a4a3212f..200fa85a0a 100644 --- a/starsky/starsky.foundation.video/GetDependencies/Models/FfmpegDownloadStatus.cs +++ b/starsky/starsky.foundation.video/GetDependencies/Models/FfmpegDownloadStatus.cs @@ -9,5 +9,6 @@ public enum FfmpegDownloadStatus DownloadBinariesFailedMissingFileName, DownloadBinariesFailedSha256Check, DownloadBinariesFailedZipperNotExtracted, - PrepareBeforeRunningFailed + PrepareBeforeRunningFailed, + PreflightRunCheckFailed } diff --git a/starsky/starskytest/FakeMocks/FakeIFfMpegPreflightRunCheck.cs b/starsky/starskytest/FakeMocks/FakeIFfMpegPreflightRunCheck.cs new file mode 100644 index 0000000000..89395ed0dc --- /dev/null +++ b/starsky/starskytest/FakeMocks/FakeIFfMpegPreflightRunCheck.cs @@ -0,0 +1,37 @@ +using System.Threading.Tasks; +using starsky.foundation.platform.Architecture; +using starsky.foundation.platform.Models; +using starsky.foundation.storage.Interfaces; +using starsky.foundation.video.GetDependencies; +using starsky.foundation.video.GetDependencies.Interfaces; + +namespace starskytest.FakeMocks; + +public class FakeIFfMpegPreflightRunCheck : IFfMpegPreflightRunCheck +{ + private readonly AppSettings? _appSettings; + private readonly IStorage? _storage; + + public FakeIFfMpegPreflightRunCheck(IStorage? storage = null, AppSettings? appSettings = null) + { + _storage = storage; + _appSettings = appSettings; + } + + public async Task TryRun() + { + var currentArchitecture = CurrentArchitecture.GetCurrentRuntimeIdentifier(); + return await TryRun(currentArchitecture); + } + + public Task TryRun(string currentArchitecture) + { + if ( _appSettings == null || _storage == null ) + { + return Task.FromResult(false); + } + + var exePath = new FfmpegExePath(_appSettings).GetExePath(currentArchitecture); + return Task.FromResult(_storage.ExistFile(exePath)); + } +} diff --git a/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadBackgroundServiceTests.cs b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadBackgroundServiceTests.cs index 46dd092aa1..95a8aaf9b7 100644 --- a/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadBackgroundServiceTests.cs +++ b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadBackgroundServiceTests.cs @@ -27,6 +27,7 @@ public FfMpegDownloadBackgroundServiceTests() services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); + services.AddSingleton(); var serviceProvider = services.BuildServiceProvider(); _serviceScopeFactory = serviceProvider.GetRequiredService(); diff --git a/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadTest.cs b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadTest.cs index 3a88fd0129..b2a4273b59 100644 --- a/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadTest.cs +++ b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadTest.cs @@ -121,7 +121,7 @@ public async Task DownloadFfMpeg_ShouldSkipDueToSettings(string settingName) var ffmpegDownload = new FfMpegDownload(new FakeSelectorStorage(), appSettings, logger, new FakeIFfMpegDownloadIndex(), new FakeIFfMpegDownloadBinaries(), - new FakeIFfMpegPrepareBeforeRunning()); + new FakeIFfMpegPrepareBeforeRunning(), new FakeIFfMpegPreflightRunCheck()); var result = await ffmpegDownload.DownloadFfMpeg(); @@ -138,7 +138,7 @@ public async Task DownloadFfMpeg_MissingIndex() new FfMpegDownload(new FakeSelectorStorage(), appSettings, logger, new FakeIFfMpegDownloadIndex(), new FakeIFfMpegDownloadBinaries(), - new FakeIFfMpegPrepareBeforeRunning()); + new FakeIFfMpegPrepareBeforeRunning(), new FakeIFfMpegPreflightRunCheck()); var resultMissingIndex = await ffmpegDownload.DownloadFfMpeg(); @@ -158,7 +158,7 @@ public async Task DownloadFfMpeg_MissingIndex_DownloadBinariesFailedMissingFileN new FakeIFfMpegDownloadIndex(new FfmpegBinariesContainer { Success = true }), new FfMpegDownloadBinaries(new FakeSelectorStorage(_storage), _httpClientHelper, appSettings, logger, new Zipper(new FakeIWebLogger())), - new FakeIFfMpegPrepareBeforeRunning()); + new FakeIFfMpegPrepareBeforeRunning(), new FakeIFfMpegPreflightRunCheck()); var resultMissingIndex = await ffmpegDownload.DownloadFfMpeg(); @@ -180,7 +180,8 @@ public async Task DownloadFfMpeg_DownloadBinariesFail() Data = new FfmpegBinariesIndex { Binaries = new List() } }), new FakeIFfMpegDownloadBinaries(FfmpegDownloadStatus - .DownloadBinariesFailedMissingFileName), new FakeIFfMpegPrepareBeforeRunning()); + .DownloadBinariesFailedMissingFileName), new FakeIFfMpegPrepareBeforeRunning(), + new FakeIFfMpegPreflightRunCheck()); var resultBinaryFail = await ffmpegDownload.DownloadFfMpeg(); @@ -207,7 +208,8 @@ public async Task DownloadFfMpeg_FileAlreadyExists() { Success = true, Data = new FfmpegBinariesIndex { Binaries = new List() } - }), new FakeIFfMpegDownloadBinaries(), new FakeIFfMpegPrepareBeforeRunning()); + }), new FakeIFfMpegDownloadBinaries(), new FakeIFfMpegPrepareBeforeRunning(), + new FakeIFfMpegPreflightRunCheck()); var resultFileAlreadyExists = await ffmpegDownload.DownloadFfMpeg(); @@ -232,7 +234,7 @@ public async Task DownloadFfMpeg_DownloadFail_InvalidShaHash() }), new FfMpegDownloadBinaries(new FakeSelectorStorage(storage), _httpClientHelper, appSettings, logger, new Zipper(new FakeIWebLogger())), - new FakeIFfMpegPrepareBeforeRunning()); + new FakeIFfMpegPrepareBeforeRunning(), new FakeIFfMpegPreflightRunCheck()); var resultInvalidHash = await ffmpegDownload.DownloadFfMpeg(); @@ -258,7 +260,7 @@ public async Task DownloadFfMpeg_DownloadFail_ZipFileNotFound() }), new FfMpegDownloadBinaries(new FakeSelectorStorage(storage), _httpClientHelper, appSettings, logger, new Zipper(new FakeIWebLogger())), - new FakeIFfMpegPrepareBeforeRunning()); + new FakeIFfMpegPrepareBeforeRunning(), new FakeIFfMpegPreflightRunCheck()); var resultZipFail = await ffmpegDownload.DownloadFfMpeg(); @@ -295,7 +297,7 @@ public async Task DownloadFfMpeg_PrepareBeforeRunningFail() new FfMpegPrepareBeforeRunning(new FakeSelectorStorage(storage), new FakeIMacCodeSign(), new FfMpegChmod(new FakeSelectorStorage(storage), logger), appSettings, - logger)); + logger), new FakeIFfMpegPreflightRunCheck()); var resultPrepFail = await ffmpegDownload.DownloadFfMpeg(); @@ -308,6 +310,55 @@ public async Task DownloadFfMpeg_PrepareBeforeRunningFail() Assert.AreEqual(FfmpegDownloadStatus.PrepareBeforeRunningFailed, resultPrepFail); } + + [TestMethod] + public async Task DownloadFfMpeg_PreflightRunCheckFailed() + { + var appSettings = new AppSettings { DependenciesFolder = DependencyFolderName }; + var logger = new FakeIWebLogger(); + var storage = new FakeIStorage(["/"], + new List + { + $"FfMpegDownloadTest{Path.DirectorySeparatorChar}mock_test.zip", "/bin/chmod" + }, + new List + { + new CreateAnZipfileFakeFfMpeg().Bytes.ToArray(), + CreateAnZipFileMacOs.Bytes.ToArray() + }); + var zipper = new FakeIZipper(new List> + { + new($"FfMpegDownloadTest{Path.DirectorySeparatorChar}mock_test.zip", + [.. new CreateAnZipfileFakeFfMpeg().Bytes.ToArray()]) + }, storage); + + const string hash = "31852c0b33f35ff16e96d53be370ce86df92db6d4633ab0a8dae38acbf393ead"; + + var ffmpegDownload = + new FfMpegDownload(new FakeSelectorStorage(storage), appSettings, + logger, + new FakeIFfMpegDownloadIndex(new FfmpegBinariesContainer + { + Success = true, + Data = CreateExampleFile(hash), + BaseUrls = new List { new("https://qdraw.nl/") } + }), new FfMpegDownloadBinaries(new FakeSelectorStorage(storage), + _httpClientHelper, + appSettings, logger, zipper), new FfMpegPrepareBeforeRunning( + new FakeSelectorStorage(storage), + new FakeIMacCodeSign(new Dictionary + { + { + $"FfMpegDownloadTest/ffmpeg-{CurrentArchitecture.GetCurrentRuntimeIdentifier()}/ffmpeg", + true + } + }), new FakeIFfmpegChmod(storage), appSettings, logger), + new FfMpegPreflightRunCheck(appSettings, new FakeIWebLogger())); + + var resultAllStages = await ffmpegDownload.DownloadFfMpeg(); + + Assert.AreEqual(FfmpegDownloadStatus.PreflightRunCheckFailed, resultAllStages); + } [TestMethod] public async Task DownloadFfMpeg_AllStages() @@ -350,7 +401,8 @@ public async Task DownloadFfMpeg_AllStages() $"FfMpegDownloadTest/ffmpeg-{CurrentArchitecture.GetCurrentRuntimeIdentifier()}/ffmpeg", true } - }), new FakeIFfmpegChmod(storage), appSettings, logger)); + }), new FakeIFfmpegChmod(storage), appSettings, logger), + new FakeIFfMpegPreflightRunCheck(storage, appSettings)); var resultAllStages = await ffmpegDownload.DownloadFfMpeg(); diff --git a/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegPreflightRunCheckTests.cs b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegPreflightRunCheckTests.cs new file mode 100644 index 0000000000..cd9d39d8d6 --- /dev/null +++ b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegPreflightRunCheckTests.cs @@ -0,0 +1,113 @@ +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using starsky.foundation.platform.Architecture; +using starsky.foundation.platform.Interfaces; +using starsky.foundation.platform.Models; +using starsky.foundation.storage.ArchiveFormats; +using starsky.foundation.storage.Helpers; +using starsky.foundation.storage.Storage; +using starsky.foundation.video.GetDependencies; +using starskytest.FakeCreateAn; +using starskytest.FakeCreateAn.CreateAnZipfileFakeFFMpeg; +using starskytest.FakeMocks; + +namespace starskytest.starsky.foundation.video.GetDependencies; + +[TestClass] +public class FfMpegPreflightRunCheckTests +{ + private readonly AppSettings _appSettings; + private readonly string _currentArchitecture; + private readonly FfMpegChmod _ffMpegChmod; + private readonly FfmpegExePath _ffmpegExePath; + private readonly StorageHostFullPathFilesystem _hostFileSystemStorage; + private readonly bool _isWindows; + private readonly IWebLogger _logger; + + public FfMpegPreflightRunCheckTests() + { + _hostFileSystemStorage = new StorageHostFullPathFilesystem(new FakeIWebLogger()); + _logger = new FakeIWebLogger(); + _ffMpegChmod = new FfMpegChmod(new FakeSelectorStorage(_hostFileSystemStorage), _logger); + + var parentFolder = + Path.Combine(new CreateAnImage().BasePath, "FfMpegPreflightRunCheckTests"); + _appSettings = new AppSettings { DependenciesFolder = parentFolder }; + + _ffmpegExePath = new FfmpegExePath(_appSettings); + _currentArchitecture = CurrentArchitecture + .GetCurrentRuntimeIdentifier(); + _isWindows = new AppSettings().IsWindows; + } + + private async Task CreateFile(int exitCode, string echoName, bool enableChmod = true) + { + if ( _hostFileSystemStorage.ExistFolder( + _ffmpegExePath.GetExeParentFolder(_currentArchitecture)) ) + { + _hostFileSystemStorage.FolderDelete( + _ffmpegExePath.GetExeParentFolder(_currentArchitecture)); + } + + _hostFileSystemStorage.CreateDirectory( + _ffmpegExePath.GetExeParentFolder(_currentArchitecture)); + var stream = + StringToStreamHelper.StringToStream( + $"#!/bin/bash\necho Fake {echoName}\nexit {exitCode}"); + await _hostFileSystemStorage.WriteStreamAsync(stream, + _ffmpegExePath.GetExePath(_currentArchitecture)); + if ( enableChmod ) + { + await _ffMpegChmod.Chmod(_ffmpegExePath.GetExePath()); + } + + var result = Zipper.ExtractZip([.. new CreateAnZipfileFakeFfMpeg().Bytes]); + var (_, item) = result.FirstOrDefault(p => p.Key.Contains("ffmpeg.exe")); + + await _hostFileSystemStorage.WriteStreamAsync(new MemoryStream(item), + Path.Combine(_ffmpegExePath.GetExeParentFolder(_currentArchitecture), "ffmpeg.exe")); + } + + [TestMethod] + public async Task TryRun_StatusCodeHappyFlow() + { + await CreateFile(0, "ffmpeg"); + + // Arrange + var ffMpegPreflightRunCheck = new FfMpegPreflightRunCheck(_appSettings, _logger); + + // Act + var result = await ffMpegPreflightRunCheck.TryRun(); + + // Assert + Assert.IsTrue(result); + } + + [DataTestMethod] + [DataRow(0, "ffmpeg", true, true)] + [DataRow(1, "ffmpeg", true, false)] + [DataRow(0, "other_process", true, false)] + [DataRow(0, "ffmpeg", false, false)] + public async Task TryRun_StatusCode(int exitCode, string echoName, bool enableChmod, + bool expectedResult) + { + if ( _isWindows ) + { + Assert.Inconclusive("exit code 1 is not supported on windows"); + return; + } + + await CreateFile(exitCode, echoName, enableChmod); + + // Arrange + var ffMpegPreflightRunCheck = new FfMpegPreflightRunCheck(_appSettings, _logger); + + // Act + var result = await ffMpegPreflightRunCheck.TryRun(); + + // Assert + Assert.AreEqual(expectedResult, result); + } +} From a95133b9aee2f181d89023580ae73770a8446422 Mon Sep 17 00:00:00 2001 From: Dion Date: Thu, 19 Dec 2024 11:05:16 +0100 Subject: [PATCH 68/73] #1833 windows fixxes --- .../GetDependencies/FfMpegDownloadBinaries.cs | 9 ++++--- .../GetDependencies/FfMpegChmodTests.cs | 24 +++++++++++++++---- .../GetDependencies/FfMpegDownloadTest.cs | 4 ++++ 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/starsky/starsky.foundation.video/GetDependencies/FfMpegDownloadBinaries.cs b/starsky/starsky.foundation.video/GetDependencies/FfMpegDownloadBinaries.cs index a2fb2308cd..0ee241c693 100644 --- a/starsky/starsky.foundation.video/GetDependencies/FfMpegDownloadBinaries.cs +++ b/starsky/starsky.foundation.video/GetDependencies/FfMpegDownloadBinaries.cs @@ -39,12 +39,15 @@ public async Task Download( int retryInSeconds = 15) { var (binaryIndex, baseUrls) = binaryIndexKeyValuePair; + if ( binaryIndex?.FileName == null ) { return FfmpegDownloadStatus.DownloadBinariesFailedMissingFileName; } - if ( _hostFileSystemStorage.ExistFile(_ffmpegExePath.GetExePath(currentArchitecture)) ) + var exePath = _ffmpegExePath.GetExePath(currentArchitecture); + + if ( _hostFileSystemStorage.ExistFile(exePath) ) { return FfmpegDownloadStatus.Ok; } @@ -67,9 +70,9 @@ public async Task Download( _zipper.ExtractZip(zipFullFilePath, _ffmpegExePath.GetExeParentFolder(currentArchitecture)); - if ( !_hostFileSystemStorage.ExistFile(_ffmpegExePath.GetExePath(currentArchitecture)) ) + if ( !_hostFileSystemStorage.ExistFile(exePath) ) { - _logger.LogError($"Zipper failed {_ffmpegExePath.GetExePath(currentArchitecture)}"); + _logger.LogError($"Zipper failed {exePath}"); return FfmpegDownloadStatus.DownloadBinariesFailedZipperNotExtracted; } diff --git a/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegChmodTests.cs b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegChmodTests.cs index ed2b91c905..3a4cb8d3e2 100644 --- a/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegChmodTests.cs +++ b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegChmodTests.cs @@ -1,3 +1,4 @@ +using System; using System.IO; using System.Linq; using System.Threading.Tasks; @@ -42,17 +43,29 @@ private void CreateFile() var stream = StringToStreamHelper.StringToStream("#!/bin/bash\necho Fake Ffmpeg"); _hostFileSystemStorage.WriteStream(stream, _ffmpegExePath.GetExePath("linux-x64")); + stream.Dispose(); var result = Zipper.ExtractZip([.. CreateAnExifToolWindows.Bytes]); var (_, item) = result.FirstOrDefault(p => p.Key.Contains("exiftool")); + _hostFileSystemStorage.CreateDirectory(_ffmpegExePath.GetExeParentFolder("win-x64")); + _hostFileSystemStorage.WriteStream(new MemoryStream(item), - Path.Combine(_ffmpegExePath.GetExeParentFolder("linux-x64"), "chmod.exe")); + Path.Combine(_ffmpegExePath.GetExeParentFolder("win-x64"), "chmod.exe")); } private void DeleteFile() { - _hostFileSystemStorage.FolderDelete(_parentFolder); + _hostFileSystemStorage.FileDelete(_ffmpegExePath.GetExePath("win-x64")); + + try + { + _hostFileSystemStorage.FolderDelete(_parentFolder); + } + catch ( UnauthorizedAccessException ) + { + // do nothing + } } [TestMethod] @@ -104,7 +117,7 @@ public async Task Chmod_ShouldReturnFalse_WhenCommandFails__UnixOnly() } [TestMethod] - public async Task Chmod_ShouldReturnFalse_WhenCommandSucceed__WindowsOnly() + public async Task Chmod_ShouldReturnTrue_WhenCommandSucceed__WindowsOnly() { if ( !_isWindows ) { @@ -115,11 +128,14 @@ public async Task Chmod_ShouldReturnFalse_WhenCommandSucceed__WindowsOnly() CreateFile(); var path = Path.Combine(_ffmpegExePath.GetExeParentFolder("win-x64"), "chmod.exe"); + + Console.WriteLine("test> " + path); + var sut = new FfMpegChmod(new FakeSelectorStorage(new FakeIStorage([], [path])), new FakeIWebLogger()) { CmdPath = path }; - var result = await sut.Chmod("/_not_found_path/to/ffmpeg"); + var result = await sut.Chmod(path); Assert.IsTrue(result); DeleteFile(); diff --git a/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadTest.cs b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadTest.cs index b2a4273b59..6ce46b6507 100644 --- a/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadTest.cs +++ b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadTest.cs @@ -60,6 +60,10 @@ private static FfmpegBinariesIndex CreateExampleFile(string sha256 = "invalid-sh Architecture = "win-x64", FileName = "mock_test.zip", Sha256 = sha256 }, new BinaryIndex + { + Architecture = "win-arm64", FileName = "mock_test.zip", Sha256 = sha256 + }, + new BinaryIndex { Architecture = "osx-x64", FileName = "mock_test.zip", Sha256 = sha256 }, From 313fb30c815929d9e37b79964f0485935b3f03e1 Mon Sep 17 00:00:00 2001 From: Dion Date: Thu, 19 Dec 2024 11:11:35 +0100 Subject: [PATCH 69/73] #1833 add extra checks --- .../Services/UpdateBackgroundTaskQueueTest.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/starsky/starskytest/starsky.foundation.worker/Services/UpdateBackgroundTaskQueueTest.cs b/starsky/starskytest/starsky.foundation.worker/Services/UpdateBackgroundTaskQueueTest.cs index c7daa5e1d8..6998f56f63 100644 --- a/starsky/starskytest/starsky.foundation.worker/Services/UpdateBackgroundTaskQueueTest.cs +++ b/starsky/starskytest/starsky.foundation.worker/Services/UpdateBackgroundTaskQueueTest.cs @@ -130,6 +130,11 @@ await backgroundQueue.QueueBackgroundWorkItemAsync(async _ => await Task.Delay(500); } + if ( !isExecuted ) + { + await Task.Delay(500); + } + Assert.IsTrue(isExecuted); await service.StopAsync(CancellationToken.None); From 19a1681e8803ad6c31bd46021e3ed36e5edfd676 Mon Sep 17 00:00:00 2001 From: Dion Date: Thu, 19 Dec 2024 11:30:59 +0100 Subject: [PATCH 70/73] #1833 test --- .../GetDependencies/FfMpegDownloadTest.cs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadTest.cs b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadTest.cs index 6ce46b6507..e36a2a5268 100644 --- a/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadTest.cs +++ b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadTest.cs @@ -305,13 +305,6 @@ public async Task DownloadFfMpeg_PrepareBeforeRunningFail() var resultPrepFail = await ffmpegDownload.DownloadFfMpeg(); - // Chmod does not exist on windows - if ( appSettings.IsWindows ) - { - Assert.AreEqual(FfmpegDownloadStatus.Ok, resultPrepFail); - return; - } - Assert.AreEqual(FfmpegDownloadStatus.PrepareBeforeRunningFailed, resultPrepFail); } From 33a579f1d3848cadb8cad802e3ee5d607ae070c5 Mon Sep 17 00:00:00 2001 From: Dion Date: Thu, 19 Dec 2024 11:40:40 +0100 Subject: [PATCH 71/73] #1833 add storage --- .../GetDependencies/FfMpegDownloadTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadTest.cs b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadTest.cs index e36a2a5268..e1ff286bad 100644 --- a/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadTest.cs +++ b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadTest.cs @@ -301,7 +301,7 @@ public async Task DownloadFfMpeg_PrepareBeforeRunningFail() new FfMpegPrepareBeforeRunning(new FakeSelectorStorage(storage), new FakeIMacCodeSign(), new FfMpegChmod(new FakeSelectorStorage(storage), logger), appSettings, - logger), new FakeIFfMpegPreflightRunCheck()); + logger), new FakeIFfMpegPreflightRunCheck(storage, appSettings)); var resultPrepFail = await ffmpegDownload.DownloadFfMpeg(); From 11c78fe74a9c73447e7d81b34204bf31177c04b0 Mon Sep 17 00:00:00 2001 From: Dion Date: Thu, 19 Dec 2024 13:03:48 +0100 Subject: [PATCH 72/73] #1833 windows --- .../GetDependencies/FfMpegDownloadTest.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadTest.cs b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadTest.cs index e1ff286bad..3a5244fb80 100644 --- a/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadTest.cs +++ b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadTest.cs @@ -22,6 +22,7 @@ public class FfMpegDownloadTest { private const string DependencyFolderName = "FfMpegDownloadTest"; private readonly FfmpegBinariesIndex _exampleFfmpegBinariesIndex; + private readonly bool _isWindows; private readonly FakeIHttpClientHelper _httpClientHelper; private readonly FakeIStorage _storage = new(); @@ -29,6 +30,7 @@ public class FfMpegDownloadTest public FfMpegDownloadTest() { _exampleFfmpegBinariesIndex = CreateExampleFile(); + _isWindows = new AppSettings().IsWindows; _httpClientHelper = new FakeIHttpClientHelper(_storage, @@ -305,6 +307,12 @@ public async Task DownloadFfMpeg_PrepareBeforeRunningFail() var resultPrepFail = await ffmpegDownload.DownloadFfMpeg(); + if ( _isWindows ) + { + Assert.AreEqual(FfmpegDownloadStatus.Ok, resultPrepFail); + return; + } + Assert.AreEqual(FfmpegDownloadStatus.PrepareBeforeRunningFailed, resultPrepFail); } From 0921295f98d7919f8e0cb8825cd1d1a843fa1dcc Mon Sep 17 00:00:00 2001 From: Dion van Velde Date: Sun, 22 Dec 2024 09:50:11 +0000 Subject: [PATCH 73/73] #1833 spacing --- starsky/starsky/starsky.csproj | 4 ++-- starsky/starskytest/starskytest.csproj | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/starsky/starsky/starsky.csproj b/starsky/starsky/starsky.csproj index f7a79d985a..8c5a1f0a3d 100644 --- a/starsky/starsky/starsky.csproj +++ b/starsky/starsky/starsky.csproj @@ -59,8 +59,8 @@ 0 - - + + diff --git a/starsky/starskytest/starskytest.csproj b/starsky/starskytest/starskytest.csproj index 1da40d5d8f..b9bbfa774f 100644 --- a/starsky/starskytest/starskytest.csproj +++ b/starsky/starskytest/starskytest.csproj @@ -21,10 +21,10 @@ - - - - + + + +