From 4da98dfeac7c54094dbb117d54a0407fd06f3d43 Mon Sep 17 00:00:00 2001 From: Dion Date: Thu, 17 Oct 2024 21:51:03 +0200 Subject: [PATCH 1/8] code smells 18 remove eventListener && reformat argshelper --- .../Helpers/ArgsHelper.cs | 1655 ++++++++--------- .../atoms/drop-area/upload-files.ts | 3 - .../atoms/more-menu/more-menu.spec.tsx | 21 +- .../components/atoms/more-menu/more-menu.tsx | 16 +- 4 files changed, 830 insertions(+), 865 deletions(-) diff --git a/starsky/starsky.foundation.platform/Helpers/ArgsHelper.cs b/starsky/starsky.foundation.platform/Helpers/ArgsHelper.cs index d531e94c27..c2eb96ec7a 100644 --- a/starsky/starsky.foundation.platform/Helpers/ArgsHelper.cs +++ b/starsky/starsky.foundation.platform/Helpers/ArgsHelper.cs @@ -5,1015 +5,1014 @@ using System.IO; using System.Linq; using System.Reflection; +using System.Runtime.InteropServices; using System.Text.RegularExpressions; using starsky.foundation.platform.Interfaces; using starsky.foundation.platform.Models; using starsky.foundation.platform.Services; -namespace starsky.foundation.platform.Helpers +namespace starsky.foundation.platform.Helpers; + +public sealed class ArgsHelper { - public sealed class ArgsHelper + private const string PathCommandLineArgLong = "--path"; + + /// + /// AppSettings + /// + private readonly AppSettings _appSettings = new(); + + /// + /// Console abstraction, use this instead of Console + /// + private readonly IConsole _console = new ConsoleWrapper(); + + /// + /// name of the env__ (__=:) use this order as 'LongNameList' and 'ShortNameList' + /// + public readonly IEnumerable EnvNameList = new List { - // Table of Content - - // -j > free - // -k > free - // -l > free - // -q > free - // -w > free - // -y > free - // -z > free - // --verbose -v - // --databasetype -d - // --connection -c - // --basepath -b - // --thumbnailtempfolder -f - // --tempfolder -tf - // --exiftoolpath -e - // --help -h - // --index -i - // --path -p - // --subpath -s - // --subpathrelative -g - // --thumbnail -t - // --orphanfolder -o - // --move -m - // --all -a - // --recruisive -r - // -rf --readonlyfolders // no need to use in cli/importercli - // -u --structure - // -n --name - // -x --clean - // --colorclass (no shorthand) - - /// - /// Simple injection - /// - public ArgsHelper() + "app__DatabaseType", + "app__DatabaseConnection", + "app__StorageFolder", + "app__ThumbnailTempFolder", + "app__ExifToolPath", + "app__Structure", + "app__subpathrelative", + "app__ExifToolImportXmpCreate", + "app__TempFolder", + "app__DependenciesFolder" + }.AsReadOnly(); + + /// + /// Long input args, use this order as 'ShortNameList' and 'EnvNameList' + /// + public readonly IEnumerable LongNameList = new List { + "--databasetype", + "--connection", + "--basepath", + "--thumbnailtempfolder", + "--exiftoolpath", + "--structure", + "--subpathrelative", + "--clean", + "--tempfolder", + "--dependencies" } + .AsReadOnly(); - /// - /// Use with appSettings - /// - /// appSettings - /// Console log - public ArgsHelper(AppSettings appSettings, IConsole? console = null) + /// + /// short input args, use the same order as 'LongNameList' and 'EnvNameList' + /// + public readonly IEnumerable ShortNameList = new List + { + "-d", + "-c", + "-b", + "-f", + "-e", + "-u", + "-g", + "-x", + "-tf", + "-dep" + }.AsReadOnly(); + // Table of Content + + // -j > free + // -k > free + // -l > free + // -q > free + // -w > free + // -y > free + // -z > free + // --verbose -v + // --databasetype -d + // --connection -c + // --basepath -b + // --thumbnailtempfolder -f + // --tempfolder -tf + // --exiftoolpath -e + // --help -h + // --index -i + // --path -p + // --subpath -s + // --subpathrelative -g + // --thumbnail -t + // --orphanfolder -o + // --move -m + // --all -a + // --recruisive -r + // -rf --readonlyfolders // no need to use in cli/importercli + // -u --structure + // -n --name + // -x --clean + // --colorclass (no shorthand) + + /// + /// Simple injection + /// + public ArgsHelper() + { + } + + /// + /// Use with appSettings + /// + /// appSettings + /// Console log + public ArgsHelper(AppSettings appSettings, IConsole? console = null) + { + _appSettings = appSettings; + if ( console != null ) { - _appSettings = appSettings; - if ( console != null ) - { - _console = console; - } + _console = console; } + } - /// - /// Console abstraction, use this instead of Console - /// - private readonly IConsole _console = new ConsoleWrapper(); - - /// - /// AppSettings - /// - private readonly AppSettings _appSettings = new AppSettings(); - - /// - /// Show debug information - /// - /// input args - /// - public static bool NeedVerbose(IReadOnlyList args) + /// + /// Show debug information + /// + /// input args + /// + public static bool NeedVerbose(IReadOnlyList args) + { + var needDebug = false; + for ( var arg = 0; arg < args.Count; arg++ ) { - var needDebug = false; - for ( var arg = 0; arg < args.Count; arg++ ) + if ( ( args[arg].Equals("--verbose", StringComparison.CurrentCultureIgnoreCase) + || args[arg].Equals("-v", StringComparison.CurrentCultureIgnoreCase) ) + && arg + 1 != args.Count + && bool.TryParse(args[arg + 1], out var needDebugParsed) ) { - if ( ( args[arg].Equals("--verbose", StringComparison.CurrentCultureIgnoreCase) - || args[arg].Equals("-v", StringComparison.CurrentCultureIgnoreCase) ) - && ( arg + 1 ) != args.Count - && bool.TryParse(args[arg + 1], out var needDebugParsed) ) - { - needDebug = needDebugParsed; - } - - if ( ( args[arg].Equals("--verbose", StringComparison.CurrentCultureIgnoreCase) || - args[arg].Equals("-v", StringComparison.CurrentCultureIgnoreCase) ) ) - { - needDebug = true; - } + needDebug = needDebugParsed; } - return needDebug; - } - - /// - /// short input args, use the same order as 'LongNameList' and 'EnvNameList' - /// - public readonly IEnumerable ShortNameList = new List - { - "-d", - "-c", - "-b", - "-f", - "-e", - "-u", - "-g", - "-x", - "-tf", - "-dep" - }.AsReadOnly(); - - /// - /// Long input args, use this order as 'ShortNameList' and 'EnvNameList' - /// - public readonly IEnumerable LongNameList = new List - { - "--databasetype", - "--connection", - "--basepath", - "--thumbnailtempfolder", - "--exiftoolpath", - "--structure", - "--subpathrelative", - "--clean", - "--tempfolder", - "--dependencies" - } - .AsReadOnly(); - - /// - /// name of the env__ (__=:) use this order as 'LongNameList' and 'ShortNameList' - /// - public readonly IEnumerable EnvNameList = new List - { - "app__DatabaseType", - "app__DatabaseConnection", - "app__StorageFolder", - "app__ThumbnailTempFolder", - "app__ExifToolPath", - "app__Structure", - "app__subpathrelative", - "app__ExifToolImportXmpCreate", - "app__TempFolder", - "app__DependenciesFolder" - }.AsReadOnly(); - - /// - /// SetEnvironmentByArgs - /// - /// - public void SetEnvironmentByArgs(IReadOnlyList args) - { - var shortNameList = ShortNameList.ToArray(); - var longNameList = LongNameList.ToArray(); - var envNameList = EnvNameList.ToArray(); - for ( var i = 0; i < ShortNameList.Count(); i++ ) + if ( args[arg].Equals("--verbose", StringComparison.CurrentCultureIgnoreCase) || + args[arg].Equals("-v", StringComparison.CurrentCultureIgnoreCase) ) { - for ( var arg = 0; arg < args.Count; arg++ ) - { - if ( ( args[arg].Equals(longNameList[i], - StringComparison.CurrentCultureIgnoreCase) || - args[arg].Equals(shortNameList[i], - StringComparison.CurrentCultureIgnoreCase) ) && - ( arg + 1 ) != args.Count ) - { - Environment.SetEnvironmentVariable(envNameList[i], args[arg + 1]); - } - } + needDebug = true; } } - /// - /// Set Environment Variables to appSettings (not used in .net core), used by framework app - /// - /// use with _appSettings - public void SetEnvironmentToAppSettings() - { - if ( _appSettings == null ) - { - throw new FieldAccessException("AppSettings cannot be null at start"); - } + return needDebug; + } - var envNameList = EnvNameList.ToArray(); - foreach ( var envUnderscoreName in envNameList ) + /// + /// SetEnvironmentByArgs + /// + /// + public void SetEnvironmentByArgs(IReadOnlyList args) + { + var shortNameList = ShortNameList.ToArray(); + var longNameList = LongNameList.ToArray(); + var envNameList = EnvNameList.ToArray(); + for ( var i = 0; i < ShortNameList.Count(); i++ ) + { + for ( var arg = 0; arg < args.Count; arg++ ) { - var envValue = Environment.GetEnvironmentVariable(envUnderscoreName); - var envName = envUnderscoreName.Replace("app__", string.Empty); - if ( !string.IsNullOrEmpty(envValue) ) + if ( ( args[arg].Equals(longNameList[i], + StringComparison.CurrentCultureIgnoreCase) || + args[arg].Equals(shortNameList[i], + StringComparison.CurrentCultureIgnoreCase) ) && + arg + 1 != args.Count ) { - var propertyObject = _appSettings.GetType().GetProperty(envName); - if ( propertyObject == null ) - { - continue; - } - - var type = propertyObject.PropertyType; - - // for enums - if ( propertyObject.PropertyType.IsEnum ) - { - var envTypedObject = Enum.Parse(type, envValue); - propertyObject.SetValue(_appSettings, envTypedObject, null); - continue; - } - - dynamic envTypedDynamic = Convert.ChangeType(envValue, type); - propertyObject.SetValue(_appSettings, envTypedDynamic, null); + Environment.SetEnvironmentVariable(envNameList[i], args[arg + 1]); } } } + } + /// + /// Set Environment Variables to appSettings (not used in .net core), used by framework app + /// + /// use with _appSettings + public void SetEnvironmentToAppSettings() + { + if ( _appSettings == null ) + { + throw new FieldAccessException("AppSettings cannot be null at start"); + } - /// - /// Based on args get the -h or --help commandline input - /// - /// args input - /// bool, true if --help - public static bool NeedHelp(IReadOnlyList args) + var envNameList = EnvNameList.ToArray(); + foreach ( var envUnderscoreName in envNameList ) { - var needHelp = false; - for ( var arg = 0; arg < args.Count; arg++ ) + var envValue = Environment.GetEnvironmentVariable(envUnderscoreName); + var envName = envUnderscoreName.Replace("app__", string.Empty); + if ( !string.IsNullOrEmpty(envValue) ) { - if ( ( args[arg].Equals("--help", StringComparison.CurrentCultureIgnoreCase) || - args[arg].Equals("-h", StringComparison.CurrentCultureIgnoreCase) ) && - ( arg + 1 ) != args.Count - && bool.TryParse(args[arg + 1], out var needHelp2) && needHelp2 ) + var propertyObject = _appSettings.GetType().GetProperty(envName); + if ( propertyObject == null ) { - needHelp = true; + continue; } - if ( args[arg].Equals("--help", StringComparison.CurrentCultureIgnoreCase) || - args[arg].Equals("-h", StringComparison.CurrentCultureIgnoreCase) ) + var type = propertyObject.PropertyType; + + // for enums + if ( propertyObject.PropertyType.IsEnum ) { - needHelp = true; + var envTypedObject = Enum.Parse(type, envValue); + propertyObject.SetValue(_appSettings, envTypedObject, null); + continue; } - } - return needHelp; + dynamic envTypedDynamic = Convert.ChangeType(envValue, type); + propertyObject.SetValue(_appSettings, envTypedDynamic, null); + } } + } - /// - /// Show Help dialog - /// - /// use appSettings - [SuppressMessage("Usage", - "S2068:password detected here, make sure this is not a hard-coded credential")] - public void NeedHelpShowDialog() + + /// + /// Based on args get the -h or --help commandline input + /// + /// args input + /// bool, true if --help + public static bool NeedHelp(IReadOnlyList args) + { + var needHelp = false; + for ( var arg = 0; arg < args.Count; arg++ ) { - if ( _appSettings == null ) + if ( ( args[arg].Equals("--help", StringComparison.CurrentCultureIgnoreCase) || + args[arg].Equals("-h", StringComparison.CurrentCultureIgnoreCase) ) && + arg + 1 != args.Count + && bool.TryParse(args[arg + 1], out var needHelp2) && needHelp2 ) { - throw new FieldAccessException("AppSettings Cannot be Null"); + needHelp = true; } - _console.WriteLine("Starsky " + _appSettings.ApplicationType + " Cli ~ Help:"); - _console.WriteLine("--help or -h == help (this window)"); - - switch ( _appSettings.ApplicationType ) + if ( args[arg].Equals("--help", StringComparison.CurrentCultureIgnoreCase) || + args[arg].Equals("-h", StringComparison.CurrentCultureIgnoreCase) ) { - case AppSettings.StarskyAppType.Thumbnail: - - _console.WriteLine("-t == enable thumbnail (default true)"); - _console.WriteLine("--path or (short) -p == parameter: (string) ; " + - "'full path', only child items of the database folder are supported," + - "search and replace first part of the filename, '/', use '-p' for current directory "); - _console.WriteLine( - "--subpath or -s == parameter: (string) ; relative path in the database"); - _console.WriteLine( - "--subpathrelative or -g == Overwrite sub-path to use relative days to select a folder" + - ", use for example '1' to select yesterday. (structure is required for this)"); - _console.WriteLine("-p, -s, -g == on of those are required for this feature"); - - _console.WriteLine("recursive is enabled by default"); - break; - case AppSettings.StarskyAppType.MetaThumbnail: - _console.WriteLine("--path or -p == parameter: (string) ; " + - "'full path', only child items of the database folder are supported," + - "search and replace first part of the filename, '/', use '-p' for current directory "); - _console.WriteLine( - "--subpath or -s == parameter: (string) ; relative path in the database"); - _console.WriteLine( - "--subpathrelative or -g == Overwrite sub-path to use relative days to select a folder" + - ", use for example '1' to select yesterday. (structure is required)"); - _console.WriteLine("-p, -s, -g == select one of those before starting"); - - _console.WriteLine("recursive is enabled by default"); - break; - case AppSettings.StarskyAppType.Admin: - _console.WriteLine("--name or -n == string ; username / email"); - _console.WriteLine("--password == string ; password"); - break; - case AppSettings.StarskyAppType.Geo: - // When this change please update ./readme.md - _console.WriteLine("--path or -p == parameter: (string) ; " + - "without addition is current directory, full path (all locations are supported) "); - _console.WriteLine( - "--subpath or -s == parameter: (string) ; relative path in the database "); - _console.WriteLine( - "--subpathrelative or -g == Overwrite subpath to use relative days to select a folder" + - ", use for example '1' to select yesterday. (structure is required)"); - _console.WriteLine("-p, -s, -g == you need to select one of those tags"); - _console.WriteLine("--all or -a == overwrite reverse geotag location tags " + - "(default: false / ignore already taged files) "); - _console.WriteLine( - "--index or -i == parameter: (bool) ; gpx feature to index geo location, default true"); - break; - case AppSettings.StarskyAppType.WebHtml: - // When this change please update ./readme.md - _console.WriteLine( - "--path or -p == parameter: (string) ; full path (select a folder), " + - "use '-p' for current directory"); - _console.WriteLine("--name or -n == parameter: (string) ; name of blog item "); - break; - case AppSettings.StarskyAppType.Importer: - // When this change please update ./readme.md - _console.WriteLine("--path or -p == parameter: (string) ; full path"); - _console.WriteLine( - " can be an folder or file, use '-p' for current directory"); - _console.WriteLine(" for multiple items use dot comma (;) " + - "to split and quotes (\") around the input string"); - _console.WriteLine( - "--move or -m == delete file after importing (default false / copy file)"); - _console.WriteLine("--recursive or -r == Import Directory recursive " + - "(default: false / only the selected folder) "); - _console.WriteLine( - "--structure == overwrite app-settings with file-directory structure " + - "based on exif and filename create datetime"); - _console.WriteLine( - "--index or -i == parameter: (bool) ; indexing, false is always copy," + - " true is check if exist in db, default true"); - _console.WriteLine( - "--clean or -x == true is to add a xmp sidecar file for raws, default true"); - _console.WriteLine( - "--colorclass == update color-class to this number value, default don't change"); - break; - case AppSettings.StarskyAppType.Sync: - // When this change please update ./readme.md - _console.WriteLine("--path or -p == parameter: (string) ; " + - "'full path', only child items of the database folder are supported," + - "search and replace first part of the filename, '/', use '-p' for current directory "); - _console.WriteLine( - "--subpath or -s == parameter: (string) ; relative path in the database"); - _console.WriteLine( - "--subpathrelative or -g == Overwrite sub-path to use relative days to select a folder" + - ", use for example '1' to select yesterday. (structure is required)"); - _console.WriteLine("-p, -s, -g == you need to select one of those tags"); - _console.WriteLine( - "--index or -i == parameter: (bool) ; enable indexing, default true"); - _console.WriteLine( - "--thumbnail or -t == parameter: (bool) ; enable thumbnail, default false"); - _console.WriteLine( - "--clean or -x == parameter: (bool) ; enable checks in thumbnail-temp-folder" + - " if thumbnails are needed, delete unused files"); - _console.WriteLine( - "--orphanfolder or -o == To delete files without a parent folder " + - "(heavy cpu usage), default false"); - _console.WriteLine("--verbose or -v == verbose, more detailed info"); - _console.WriteLine( - "--databasetype or -d == Overwrite EnvironmentVariable for DatabaseType"); - _console.WriteLine( - "--basepath or -b == Overwrite EnvironmentVariable for StorageFolder"); - _console.WriteLine( - "--connection or -c == Overwrite EnvironmentVariable for DatabaseConnection"); - _console.WriteLine( - "--thumbnailtempfolder or -f == Overwrite EnvironmentVariable for ThumbnailTempFolder"); - _console.WriteLine( - "--exiftoolpath or -e == Overwrite EnvironmentVariable for ExifToolPath"); - break; + needHelp = true; } + } - _console.WriteLine("--verbose or -v == verbose, more detailed info"); - _console.WriteLine(" use -v -help to show settings: "); + return needHelp; + } - if ( !_appSettings.IsVerbose() ) - { - return; - } + /// + /// Show Help dialog + /// + /// use appSettings + [SuppressMessage("Usage", + "S2068:password detected here, make sure this is not a hard-coded credential")] + public void NeedHelpShowDialog() + { + if ( _appSettings == null ) + { + throw new FieldAccessException("AppSettings Cannot be Null"); + } - _console.WriteLine(string.Empty); - _console.WriteLine("AppSettings: " + _appSettings.ApplicationType); - _console.WriteLine("Database Type (-d --databasetype) " + _appSettings.DatabaseType); - _console.WriteLine("DatabaseConnection (-c --connection) " + - _appSettings.DatabaseConnection); - _console.WriteLine($"StorageFolder (-b --basepath) {_appSettings.StorageFolder} "); - _console.WriteLine( - $"ThumbnailTempFolder (-f --thumbnailtempfolder) {_appSettings.ThumbnailTempFolder} "); - _console.WriteLine($"ExifToolPath (-e --exiftoolpath) {_appSettings.ExifToolPath} "); - _console.WriteLine("Structure (-u --structure) " + _appSettings.Structure); - _console.WriteLine("CameraTimeZone " + _appSettings.CameraTimeZone); - _console.WriteLine("Name " + _appSettings.Name); - _console.WriteLine($"TempFolder {_appSettings.TempFolder} "); - _console.WriteLine($"BaseDirectoryProject {_appSettings.BaseDirectoryProject} "); - _console.WriteLine("ExiftoolSkipDownloadOnStartup " + - _appSettings.ExiftoolSkipDownloadOnStartup); - _console.WriteLine("GeoFilesSkipDownloadOnStartup " + - _appSettings.GeoFilesSkipDownloadOnStartup); - - _console.WriteLine($"MaxDegreesOfParallelism {_appSettings.MaxDegreesOfParallelism} "); - - // OpenTelemetry - if ( !string.IsNullOrEmpty(_appSettings.OpenTelemetry?.LogsEndpoint) ) - { - _console.WriteLine($"LogsEndpoint {_appSettings.OpenTelemetry.LogsEndpoint} "); - } + _console.WriteLine("Starsky " + _appSettings.ApplicationType + " Cli ~ Help:"); + _console.WriteLine("--help or -h == help (this window)"); - if ( !string.IsNullOrEmpty(_appSettings.OpenTelemetry?.MetricsEndpoint) ) - { - _console.WriteLine( - $"MetricsEndpoint {_appSettings.OpenTelemetry.MetricsEndpoint} "); - } + switch ( _appSettings.ApplicationType ) + { + case AppSettings.StarskyAppType.Thumbnail: - if ( !string.IsNullOrEmpty(_appSettings.OpenTelemetry?.TracesEndpoint) ) - { - _console.WriteLine($"TracesEndpoint {_appSettings.OpenTelemetry.TracesEndpoint} "); - } + _console.WriteLine("-t == enable thumbnail (default true)"); + _console.WriteLine("--path or (short) -p == parameter: (string) ; " + + "'full path', only child items of the database folder are supported," + + "search and replace first part of the filename, '/', use '-p' for current directory "); + _console.WriteLine( + "--subpath or -s == parameter: (string) ; relative path in the database"); + _console.WriteLine( + "--subpathrelative or -g == Overwrite sub-path to use relative days to select a folder" + + ", use for example '1' to select yesterday. (structure is required for this)"); + _console.WriteLine("-p, -s, -g == on of those are required for this feature"); + + _console.WriteLine("recursive is enabled by default"); + break; + case AppSettings.StarskyAppType.MetaThumbnail: + _console.WriteLine("--path or -p == parameter: (string) ; " + + "'full path', only child items of the database folder are supported," + + "search and replace first part of the filename, '/', use '-p' for current directory "); + _console.WriteLine( + "--subpath or -s == parameter: (string) ; relative path in the database"); + _console.WriteLine( + "--subpathrelative or -g == Overwrite sub-path to use relative days to select a folder" + + ", use for example '1' to select yesterday. (structure is required)"); + _console.WriteLine("-p, -s, -g == select one of those before starting"); + + _console.WriteLine("recursive is enabled by default"); + break; + case AppSettings.StarskyAppType.Admin: + _console.WriteLine("--name or -n == string ; username / email"); + _console.WriteLine("--password == string ; password"); + break; + case AppSettings.StarskyAppType.Geo: + // When this change please update ./readme.md + _console.WriteLine("--path or -p == parameter: (string) ; " + + "without addition is current directory, full path (all locations are supported) "); + _console.WriteLine( + "--subpath or -s == parameter: (string) ; relative path in the database "); + _console.WriteLine( + "--subpathrelative or -g == Overwrite subpath to use relative days to select a folder" + + ", use for example '1' to select yesterday. (structure is required)"); + _console.WriteLine("-p, -s, -g == you need to select one of those tags"); + _console.WriteLine("--all or -a == overwrite reverse geotag location tags " + + "(default: false / ignore already taged files) "); + _console.WriteLine( + "--index or -i == parameter: (bool) ; gpx feature to index geo location, default true"); + break; + case AppSettings.StarskyAppType.WebHtml: + // When this change please update ./readme.md + _console.WriteLine( + "--path or -p == parameter: (string) ; full path (select a folder), " + + "use '-p' for current directory"); + _console.WriteLine("--name or -n == parameter: (string) ; name of blog item "); + break; + case AppSettings.StarskyAppType.Importer: + // When this change please update ./readme.md + _console.WriteLine("--path or -p == parameter: (string) ; full path"); + _console.WriteLine( + " can be an folder or file, use '-p' for current directory"); + _console.WriteLine(" for multiple items use dot comma (;) " + + "to split and quotes (\") around the input string"); + _console.WriteLine( + "--move or -m == delete file after importing (default false / copy file)"); + _console.WriteLine("--recursive or -r == Import Directory recursive " + + "(default: false / only the selected folder) "); + _console.WriteLine( + "--structure == overwrite app-settings with file-directory structure " + + "based on exif and filename create datetime"); + _console.WriteLine( + "--index or -i == parameter: (bool) ; indexing, false is always copy," + + " true is check if exist in db, default true"); + _console.WriteLine( + "--clean or -x == true is to add a xmp sidecar file for raws, default true"); + _console.WriteLine( + "--colorclass == update color-class to this number value, default don't change"); + break; + case AppSettings.StarskyAppType.Sync: + // When this change please update ./readme.md + _console.WriteLine("--path or -p == parameter: (string) ; " + + "'full path', only child items of the database folder are supported," + + "search and replace first part of the filename, '/', use '-p' for current directory "); + _console.WriteLine( + "--subpath or -s == parameter: (string) ; relative path in the database"); + _console.WriteLine( + "--subpathrelative or -g == Overwrite sub-path to use relative days to select a folder" + + ", use for example '1' to select yesterday. (structure is required)"); + _console.WriteLine("-p, -s, -g == you need to select one of those tags"); + _console.WriteLine( + "--index or -i == parameter: (bool) ; enable indexing, default true"); + _console.WriteLine( + "--thumbnail or -t == parameter: (bool) ; enable thumbnail, default false"); + _console.WriteLine( + "--clean or -x == parameter: (bool) ; enable checks in thumbnail-temp-folder" + + " if thumbnails are needed, delete unused files"); + _console.WriteLine( + "--orphanfolder or -o == To delete files without a parent folder " + + "(heavy cpu usage), default false"); + _console.WriteLine("--verbose or -v == verbose, more detailed info"); + _console.WriteLine( + "--databasetype or -d == Overwrite EnvironmentVariable for DatabaseType"); + _console.WriteLine( + "--basepath or -b == Overwrite EnvironmentVariable for StorageFolder"); + _console.WriteLine( + "--connection or -c == Overwrite EnvironmentVariable for DatabaseConnection"); + _console.WriteLine( + "--thumbnailtempfolder or -f == Overwrite EnvironmentVariable for ThumbnailTempFolder"); + _console.WriteLine( + "--exiftoolpath or -e == Overwrite EnvironmentVariable for ExifToolPath"); + break; + } - _console.Write("SyncIgnore "); - foreach ( var rule in _appSettings.SyncIgnore ) - { - _console.Write($"{rule}, "); - } + _console.WriteLine("--verbose or -v == verbose, more detailed info"); + _console.WriteLine(" use -v -help to show settings: "); - _console.Write("\n"); + if ( !_appSettings.IsVerbose() ) + { + return; + } - _console.Write("ImportIgnore "); - foreach ( var rule in _appSettings.ImportIgnore ) - { - _console.Write($"{rule}, "); - } + _console.WriteLine(string.Empty); + _console.WriteLine("AppSettings: " + _appSettings.ApplicationType); + _console.WriteLine("Database Type (-d --databasetype) " + _appSettings.DatabaseType); + _console.WriteLine("DatabaseConnection (-c --connection) " + + _appSettings.DatabaseConnection); + _console.WriteLine($"StorageFolder (-b --basepath) {_appSettings.StorageFolder} "); + _console.WriteLine( + $"ThumbnailTempFolder (-f --thumbnailtempfolder) {_appSettings.ThumbnailTempFolder} "); + _console.WriteLine($"ExifToolPath (-e --exiftoolpath) {_appSettings.ExifToolPath} "); + _console.WriteLine("Structure (-u --structure) " + _appSettings.Structure); + _console.WriteLine("CameraTimeZone " + _appSettings.CameraTimeZone); + _console.WriteLine("Name " + _appSettings.Name); + _console.WriteLine($"TempFolder {_appSettings.TempFolder} "); + _console.WriteLine($"BaseDirectoryProject {_appSettings.BaseDirectoryProject} "); + _console.WriteLine("ExiftoolSkipDownloadOnStartup " + + _appSettings.ExiftoolSkipDownloadOnStartup); + _console.WriteLine("GeoFilesSkipDownloadOnStartup " + + _appSettings.GeoFilesSkipDownloadOnStartup); + + _console.WriteLine($"MaxDegreesOfParallelism {_appSettings.MaxDegreesOfParallelism} "); + + // OpenTelemetry + if ( !string.IsNullOrEmpty(_appSettings.OpenTelemetry?.LogsEndpoint) ) + { + _console.WriteLine($"LogsEndpoint {_appSettings.OpenTelemetry.LogsEndpoint} "); + } - _console.Write("\n"); + if ( !string.IsNullOrEmpty(_appSettings.OpenTelemetry?.MetricsEndpoint) ) + { + _console.WriteLine( + $"MetricsEndpoint {_appSettings.OpenTelemetry.MetricsEndpoint} "); + } - if ( _appSettings.ApplicationType == AppSettings.StarskyAppType.Importer ) - { - _console.WriteLine("Create xmp on import (ExifToolImportXmpCreate): " + - _appSettings.ExifToolImportXmpCreate); - } + if ( !string.IsNullOrEmpty(_appSettings.OpenTelemetry?.TracesEndpoint) ) + { + _console.WriteLine($"TracesEndpoint {_appSettings.OpenTelemetry.TracesEndpoint} "); + } - if ( _appSettings.ApplicationType == AppSettings.StarskyAppType.WebFtp ) - { - _console.WriteLine("WebFtp " + _appSettings.WebFtp); - } + _console.Write("SyncIgnore "); + foreach ( var rule in _appSettings.SyncIgnore ) + { + _console.Write($"{rule}, "); + } - if ( _appSettings.ApplicationType == AppSettings.StarskyAppType.Admin ) - { - _console.WriteLine("NoAccountLocalhost " + _appSettings.NoAccountLocalhost); - } + _console.Write("\n"); - _console.WriteLine("-- Appsettings.json locations -- "); + _console.Write("ImportIgnore "); + foreach ( var rule in _appSettings.ImportIgnore ) + { + _console.Write($"{rule}, "); + } - var machineName = Environment.MachineName.ToLowerInvariant(); + _console.Write("\n"); - _console.WriteLine( - "Config is read in this order: (latest is applied over lower numbers)"); - _console.WriteLine( - $"1. {Path.Combine(_appSettings.BaseDirectoryProject, "appsettings.json")}"); - _console.WriteLine( - $"2. {Path.Combine(_appSettings.BaseDirectoryProject, "appsettings.default.json")}"); - _console.WriteLine( - $"3. {Path.Combine(_appSettings.BaseDirectoryProject, "appsettings.patch.json")}"); - _console.WriteLine( - $"4. {Path.Combine(_appSettings.BaseDirectoryProject, "appsettings." + machineName + ".json")}"); - _console.WriteLine( - $"5. {Path.Combine(_appSettings.BaseDirectoryProject, "appsettings." + machineName + ".patch.json")}"); - _console.WriteLine( - $"6. Environment variable: app__appsettingspath: {Environment.GetEnvironmentVariable("app__appsettingspath")}"); - _console.WriteLine("7. Specific environment variables for example app__storageFolder"); + if ( _appSettings.ApplicationType == AppSettings.StarskyAppType.Importer ) + { + _console.WriteLine("Create xmp on import (ExifToolImportXmpCreate): " + + _appSettings.ExifToolImportXmpCreate); + } - AppSpecificHelp(); + if ( _appSettings.ApplicationType == AppSettings.StarskyAppType.WebFtp ) + { + _console.WriteLine("WebFtp " + _appSettings.WebFtp); + } - ShowVersions(); + if ( _appSettings.ApplicationType == AppSettings.StarskyAppType.Admin ) + { + _console.WriteLine("NoAccountLocalhost " + _appSettings.NoAccountLocalhost); } - private void AppSpecificHelp() + _console.WriteLine("-- Appsettings.json locations -- "); + + var machineName = Environment.MachineName.ToLowerInvariant(); + + _console.WriteLine( + "Config is read in this order: (latest is applied over lower numbers)"); + _console.WriteLine( + $"1. {Path.Combine(_appSettings.BaseDirectoryProject, "appsettings.json")}"); + _console.WriteLine( + $"2. {Path.Combine(_appSettings.BaseDirectoryProject, "appsettings.default.json")}"); + _console.WriteLine( + $"3. {Path.Combine(_appSettings.BaseDirectoryProject, "appsettings.patch.json")}"); + _console.WriteLine( + $"4. {Path.Combine(_appSettings.BaseDirectoryProject, "appsettings." + machineName + ".json")}"); + _console.WriteLine( + $"5. {Path.Combine(_appSettings.BaseDirectoryProject, "appsettings." + machineName + ".patch.json")}"); + _console.WriteLine( + $"6. Environment variable: app__appsettingspath: {Environment.GetEnvironmentVariable("app__appsettingspath")}"); + _console.WriteLine("7. Specific environment variables for example app__storageFolder"); + + AppSpecificHelp(); + + ShowVersions(); + } + + private void AppSpecificHelp() + { + switch ( _appSettings.ApplicationType ) { - switch ( _appSettings.ApplicationType ) - { - case AppSettings.StarskyAppType.WebHtml: - _console.WriteLine($"Config for {_appSettings.ApplicationType}"); - if ( _appSettings.PublishProfiles == null ) - { - break; - } + case AppSettings.StarskyAppType.WebHtml: + _console.WriteLine($"Config for {_appSettings.ApplicationType}"); + if ( _appSettings.PublishProfiles == null ) + { + break; + } - foreach ( var publishProfiles in _appSettings.PublishProfiles ) + foreach ( var publishProfiles in _appSettings.PublishProfiles ) + { + _console.WriteLine($"ID: {publishProfiles.Key}"); + foreach ( var publishProfile in publishProfiles.Value ) { - _console.WriteLine($"ID: {publishProfiles.Key}"); - foreach ( var publishProfile in publishProfiles.Value ) - { - _console.WriteLine("--- " + - $"Path: {publishProfile.Path} " + - $"Append: {publishProfile.Append} " + - $"Copy: {publishProfile.Copy} " + - $"Folder: {publishProfile.Folder} " + - $"Prepend: {publishProfile.Prepend} " + - $"Template: {publishProfile.Template} " + - $"ContentType: {publishProfile.ContentType} " + - $"MetaData: {publishProfile.MetaData} " + - $"OverlayMaxWidth: {publishProfile.OverlayMaxWidth} " + - $"SourceMaxWidth: {publishProfile.SourceMaxWidth} "); - } + _console.WriteLine("--- " + + $"Path: {publishProfile.Path} " + + $"Append: {publishProfile.Append} " + + $"Copy: {publishProfile.Copy} " + + $"Folder: {publishProfile.Folder} " + + $"Prepend: {publishProfile.Prepend} " + + $"Template: {publishProfile.Template} " + + $"ContentType: {publishProfile.ContentType} " + + $"MetaData: {publishProfile.MetaData} " + + $"OverlayMaxWidth: {publishProfile.OverlayMaxWidth} " + + $"SourceMaxWidth: {publishProfile.SourceMaxWidth} "); } + } - break; - } + break; } + } + + /// + /// Show in Console the .NET Version (Runtime) and Starsky Version + /// @see: https://stackoverflow.com/a/58136318 + /// + private void ShowVersions() + { + var version = RuntimeInformation.FrameworkDescription; + _console.WriteLine($".NET Version - {version}"); + _console.WriteLine($"Starsky Version - {_appSettings.AppVersion} " + + "- build at: " + + DateAssembly.GetBuildDate(Assembly.GetExecutingAssembly()).ToString( + new CultureInfo("nl-NL"))); + } - /// - /// Show in Console the .NET Version (Runtime) and Starsky Version - /// @see: https://stackoverflow.com/a/58136318 - /// - private void ShowVersions() + /// + /// Default On + /// Based on args get the -i or --index commandline input + /// + /// args input + /// bool, true if --index + public static bool GetIndexMode(IReadOnlyList args) + { + var isIndexMode = true; + + for ( var arg = 0; arg < args.Count; arg++ ) { - var version = System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription; - _console.WriteLine($".NET Version - {version}"); - _console.WriteLine($"Starsky Version - {_appSettings.AppVersion} " + - "- build at: " + - DateAssembly.GetBuildDate(Assembly.GetExecutingAssembly()).ToString( - new CultureInfo("nl-NL"))); + if ( ( args[arg].Equals("--index", StringComparison.CurrentCultureIgnoreCase) || + args[arg].Equals("-i", StringComparison.CurrentCultureIgnoreCase) ) + && arg + 1 != args.Count + && bool.TryParse(args[arg + 1], out var isIndexMode2) ) + { + isIndexMode = isIndexMode2; + } } - /// - /// Default On - /// Based on args get the -i or --index commandline input - /// - /// args input - /// bool, true if --index - public static bool GetIndexMode(IReadOnlyList args) + return isIndexMode; + } + + /// + /// Get multiple path from args + /// + /// args + /// list of fullFilePaths + /// _appSettings is missing + [SuppressMessage("Usage", "S125:Remove this commented out code.", + Justification = "Regex as comment")] + public List GetPathListFormArgs(IReadOnlyList args) + { + if ( _appSettings == null ) { - var isIndexMode = true; + throw new FieldAccessException("AppSettings can't be Null at start"); + } - for ( var arg = 0; arg < args.Count; arg++ ) - { - if ( ( args[arg].Equals("--index", StringComparison.CurrentCultureIgnoreCase) || - args[arg].Equals("-i", StringComparison.CurrentCultureIgnoreCase) ) - && ( arg + 1 ) != args.Count - && bool.TryParse(args[arg + 1], out var isIndexMode2) ) - { - isIndexMode = isIndexMode2; - } - } + var path = GetUserInputPathFromArg(args); - return isIndexMode; + // To use only with -p or --path > current directory + if ( ( args.Contains("-p") || args.Contains(PathCommandLineArgLong) ) && + ( path == string.Empty || path[0] == "-"[0] ) ) + { + path = Directory.GetCurrentDirectory(); } - /// - /// Get multiple path from args - /// - /// args - /// list of fullFilePaths - /// _appSettings is missing - [SuppressMessage("Usage", "S125:Remove this commented out code.", - Justification = "Regex as comment")] - public List GetPathListFormArgs(IReadOnlyList args) + // Ignore quotes at beginning: unescaped ^"|"$ + path = new Regex("^\"|\"$", + RegexOptions.None, TimeSpan.FromMilliseconds(100)) + .Replace(path, string.Empty); + + // split every dot comma but ignore escaped + // non escaped: (? !string.IsNullOrWhiteSpace(p)).ToList(); + } + + /// + /// Get the user input from -p or --path + /// + /// arg list + /// path + private static string GetUserInputPathFromArg(IReadOnlyList args) + { + var path = string.Empty; + for ( var arg = 0; arg < args.Count; arg++ ) { - if ( _appSettings == null ) + if ( ( args[arg].Equals(PathCommandLineArgLong, + StringComparison.CurrentCultureIgnoreCase) || + args[arg].Equals("-p", StringComparison.CurrentCultureIgnoreCase) ) && + arg + 1 != args.Count ) { - throw new FieldAccessException("AppSettings can't be Null at start"); + path = args[arg + 1]; } + } - var path = GetUserInputPathFromArg(args); + return path; + } - // To use only with -p or --path > current directory - if ( ( args.Contains("-p") || args.Contains(PathCommandLineArgLong) ) && - ( path == string.Empty || path[0] == "-"[0] ) ) + /// + /// Get the user input from -p or --password + /// + /// arg list + /// path + public static string GetUserInputPassword(IReadOnlyList args) + { + var path = string.Empty; + for ( var arg = 0; arg < args.Count; arg++ ) + { + if ( ( args[arg].Equals("--password", StringComparison.CurrentCultureIgnoreCase) || + args[arg].Equals("-p", StringComparison.CurrentCultureIgnoreCase) ) && + arg + 1 != args.Count ) { - path = Directory.GetCurrentDirectory(); + path = args[arg + 1]; } - - // Ignore quotes at beginning: unescaped ^"|"$ - path = new Regex("^\"|\"$", - RegexOptions.None, TimeSpan.FromMilliseconds(100)) - .Replace(path, string.Empty); - - // split every dot comma but ignore escaped - // non escaped: (? !string.IsNullOrWhiteSpace(p)).ToList(); } - private const string PathCommandLineArgLong = "--path"; + return path; + } - /// - /// Get the user input from -p or --path - /// - /// arg list - /// path - private static string GetUserInputPathFromArg(IReadOnlyList args) + /// + /// Get output mode + /// + /// arg list + /// path + public static ConsoleOutputMode GetConsoleOutputMode(IReadOnlyList args) + { + var outputMode = ConsoleOutputMode.Default; + for ( var arg = 0; arg < args.Count; arg++ ) { - var path = string.Empty; - for ( var arg = 0; arg < args.Count; arg++ ) + if ( !args[arg].Equals("--output", StringComparison.CurrentCultureIgnoreCase) || + arg + 1 == args.Count ) { - if ( ( args[arg].Equals(PathCommandLineArgLong, - StringComparison.CurrentCultureIgnoreCase) || - args[arg].Equals("-p", StringComparison.CurrentCultureIgnoreCase) ) && - ( arg + 1 ) != args.Count ) - { - path = args[arg + 1]; - } + continue; } - return path; + var outputModeItem = args[arg + 1]; + Enum.TryParse(outputModeItem, true, out outputMode); } - /// - /// Get the user input from -p or --password - /// - /// arg list - /// path - public static string GetUserInputPassword(IReadOnlyList args) + return outputMode; + } + + /// + /// Get the user input from -n or --name + /// + /// arg list + /// name + public static string GetName(IReadOnlyList args) + { + var name = string.Empty; + for ( var arg = 0; arg < args.Count; arg++ ) { - var path = string.Empty; - for ( var arg = 0; arg < args.Count; arg++ ) + if ( ( args[arg].Equals("--name", StringComparison.CurrentCultureIgnoreCase) || + args[arg].Equals("-n", StringComparison.CurrentCultureIgnoreCase) ) && + arg + 1 != args.Count ) { - if ( ( args[arg].Equals("--password", StringComparison.CurrentCultureIgnoreCase) || - args[arg].Equals("-p", StringComparison.CurrentCultureIgnoreCase) ) && - ( arg + 1 ) != args.Count ) - { - path = args[arg + 1]; - } + name = args[arg + 1]; } + } - return path; + return name; + } + + /// + /// Get path from args + /// + /// args + /// convert to subPath style, default=true + /// string path + /// appSettings is missing + public string GetPathFormArgs(IReadOnlyList args, bool dbStyle = true) + { + if ( _appSettings == null ) + { + throw new FieldAccessException("use with _appSettings in ctor"); } - /// - /// Get output mode - /// - /// arg list - /// path - public static ConsoleOutputMode GetConsoleOutputMode(IReadOnlyList args) + var path = GetUserInputPathFromArg(args); + + // To use only with -p or --path > current directory + if ( ( args.Contains("-p") || args.Contains(PathCommandLineArgLong) ) && + ( path == string.Empty || path[0] == "-"[0] ) ) { - var outputMode = ConsoleOutputMode.Default; - for ( var arg = 0; arg < args.Count; arg++ ) + var currentDirectory = Directory.GetCurrentDirectory(); + if ( currentDirectory != _appSettings.BaseDirectoryProject ) { - if ( ( !args[arg].Equals("--output", StringComparison.CurrentCultureIgnoreCase) ) || - ( arg + 1 ) == args.Count ) + path = currentDirectory; + if ( _appSettings.IsVerbose() ) { - continue; + Console.WriteLine($">> currentDirectory: {currentDirectory}"); } - - var outputModeItem = args[arg + 1]; - Enum.TryParse(outputModeItem, true, out outputMode); } + } - return outputMode; + if ( dbStyle ) + { + path = _appSettings.FullPathToDatabaseStyle(path); } - /// - /// Get the user input from -n or --name - /// - /// arg list - /// name - public static string GetName(IReadOnlyList args) + return path; + } + + /// + /// Get --subpath from args + /// + /// args + /// subPath string + public static string GetSubPathFormArgs(IReadOnlyList args) + { + var subPath = "/"; + + for ( var arg = 0; arg < args.Count; arg++ ) { - var name = string.Empty; - for ( var arg = 0; arg < args.Count; arg++ ) + if ( ( args[arg].Equals("--subpath", StringComparison.CurrentCultureIgnoreCase) || + args[arg].Equals("-s", StringComparison.CurrentCultureIgnoreCase) ) && + arg + 1 != args.Count ) { - if ( ( args[arg].Equals("--name", StringComparison.CurrentCultureIgnoreCase) || - args[arg].Equals("-n", StringComparison.CurrentCultureIgnoreCase) ) && - ( arg + 1 ) != args.Count ) - { - name = args[arg + 1]; - } + subPath = args[arg + 1]; } - - return name; } - /// - /// Get path from args - /// - /// args - /// convert to subPath style, default=true - /// string path - /// appSettings is missing - public string GetPathFormArgs(IReadOnlyList args, bool dbStyle = true) + return subPath; + } + + /// + /// Get subPathRelative, so a structured url based on relative datetime + /// + /// args[] + /// relative subPath + /// missing appSettings + public int? GetRelativeValue(IReadOnlyList args) + { + if ( _appSettings == null ) { - if ( _appSettings == null ) - { - throw new FieldAccessException("use with _appSettings in ctor"); - } + throw new FieldAccessException("use with _appSettings in ctor"); + } - var path = GetUserInputPathFromArg(args); + var subPathRelative = string.Empty; - // To use only with -p or --path > current directory - if ( ( args.Contains("-p") || args.Contains(PathCommandLineArgLong) ) && - ( path == string.Empty || path[0] == "-"[0] ) ) + for ( var arg = 0; arg < args.Count; arg++ ) + { + if ( ( args[arg].Equals("--subpathrelative", + StringComparison.InvariantCultureIgnoreCase) || + args[arg].Equals("-g", StringComparison.InvariantCultureIgnoreCase) ) && + arg + 1 != args.Count ) { - var currentDirectory = Directory.GetCurrentDirectory(); - if ( currentDirectory != _appSettings.BaseDirectoryProject ) - { - path = currentDirectory; - if ( _appSettings.IsVerbose() ) - { - Console.WriteLine($">> currentDirectory: {currentDirectory}"); - } - } + subPathRelative = args[arg + 1]; } + } - if ( dbStyle ) - { - path = _appSettings.FullPathToDatabaseStyle(path); - } + if ( string.IsNullOrWhiteSpace(subPathRelative) ) + { + return null; // null + } - return path; + if ( int.TryParse(subPathRelative, out var subPathInt) && subPathInt >= 1 ) + { + subPathInt *= -1; // always in the past } - /// - /// Get --subpath from args - /// - /// args - /// subPath string - public static string GetSubPathFormArgs(IReadOnlyList args) + // Fallback for dates older than 24-11-1854 to avoid a exception. + if ( subPathInt < -60000 ) { - var subPath = "/"; + return null; + } - for ( var arg = 0; arg < args.Count; arg++ ) - { - if ( ( args[arg].Equals("--subpath", StringComparison.CurrentCultureIgnoreCase) || - args[arg].Equals("-s", StringComparison.CurrentCultureIgnoreCase) ) && - ( arg + 1 ) != args.Count ) - { - subPath = args[arg + 1]; - } - } + return subPathInt; + } - return subPath; + /// + /// Know if --subpath or --path + /// + /// input[] + /// bool --path(true), false --subpath + public static bool IsSubPathOrPath(IReadOnlyList args) + { + // To use only with -p or --path > current directory + if ( args.Any(arg => + arg.Equals(PathCommandLineArgLong, + StringComparison.CurrentCultureIgnoreCase) || + arg.Equals("-p", StringComparison.CurrentCultureIgnoreCase)) ) + { + return false; } - /// - /// Get subPathRelative, so a structured url based on relative datetime - /// - /// args[] - /// relative subPath - /// missing appSettings - public int? GetRelativeValue(IReadOnlyList args) + // Detect if a input is a fullPath or a subPath. + for ( var arg = 0; arg < args.Count; arg++ ) { - if ( _appSettings == null ) + if ( ( args[arg].Equals("--subpath", StringComparison.CurrentCultureIgnoreCase) || + args[arg].Equals("-s", StringComparison.CurrentCultureIgnoreCase) ) && + arg + 1 != args.Count ) { - throw new FieldAccessException("use with _appSettings in ctor"); + return true; } + } - var subPathRelative = string.Empty; + return true; + } - for ( int arg = 0; arg < args.Count; arg++ ) - { - if ( ( args[arg].Equals("--subpathrelative", - StringComparison.InvariantCultureIgnoreCase) || - args[arg].Equals("-g", StringComparison.InvariantCultureIgnoreCase) ) && - ( arg + 1 ) != args.Count ) - { - subPathRelative = args[arg + 1]; - } - } + /// + /// Using both options + /// -s = if subPath || -p is path + /// + /// + /// + public string SubPathOrPathValue(IReadOnlyList args) + { + return IsSubPathOrPath(args) ? GetSubPathFormArgs(args) : GetPathFormArgs(args); + } - if ( string.IsNullOrWhiteSpace(subPathRelative) ) - { - return null; // null - } + /// + /// --thumbnail bool + /// + /// args input + /// bool + public static bool GetThumbnail(IReadOnlyList args) + { + var isThumbnail = true; - if ( int.TryParse(subPathRelative, out var subPathInt) && subPathInt >= 1 ) + for ( var arg = 0; arg < args.Count; arg++ ) + { + if ( ( args[arg].Equals("--thumbnail", StringComparison.CurrentCultureIgnoreCase) || + args[arg].Equals("-t", StringComparison.CurrentCultureIgnoreCase) ) + && arg + 1 != args.Count && + bool.TryParse(args[arg + 1], out var isThumbnail2) ) { - subPathInt *= -1; // always in the past + isThumbnail = isThumbnail2; } + } - // Fallback for dates older than 24-11-1854 to avoid a exception. - if ( subPathInt < -60000 ) - { - return null; - } + return isThumbnail; + } - return subPathInt; - } + /// + /// Check for parent/sub items feature + /// + /// args input + /// bool + public bool GetOrphanFolderCheck(IReadOnlyList args) + { + var isOrphanFolderCheck = false; - /// - /// Know if --subpath or --path - /// - /// input[] - /// bool --path(true), false --subpath - public static bool IsSubPathOrPath(IReadOnlyList args) + for ( var arg = 0; arg < args.Count; arg++ ) { - // To use only with -p or --path > current directory - if ( args.Any(arg => - ( arg.Equals(PathCommandLineArgLong, - StringComparison.CurrentCultureIgnoreCase) || - arg.Equals("-p", StringComparison.CurrentCultureIgnoreCase) )) ) + if ( ( args[arg].Equals("--orphanfolder", + StringComparison.CurrentCultureIgnoreCase) || + args[arg].Equals("-o", StringComparison.CurrentCultureIgnoreCase) ) + && arg + 1 != args.Count && + bool.TryParse(args[arg + 1], out var isOrphanFolderCheck2) ) { - return false; - } - - // Detect if a input is a fullPath or a subPath. - for ( int arg = 0; arg < args.Count; arg++ ) - { - if ( ( args[arg].Equals("--subpath", StringComparison.CurrentCultureIgnoreCase) || - args[arg].Equals("-s", StringComparison.CurrentCultureIgnoreCase) ) && - ( arg + 1 ) != args.Count ) - { - return true; - } + isOrphanFolderCheck = isOrphanFolderCheck2; } - - return true; } - /// - /// Using both options - /// -s = if subPath || -p is path - /// - /// - /// - public string SubPathOrPathValue(IReadOnlyList args) + if ( _appSettings.IsVerbose() ) { - return IsSubPathOrPath(args) ? GetSubPathFormArgs(args) : GetPathFormArgs(args); + Console.WriteLine(">> isOrphanFolderCheck " + isOrphanFolderCheck); } - /// - /// --thumbnail bool - /// - /// args input - /// bool - public static bool GetThumbnail(IReadOnlyList args) - { - var isThumbnail = true; - - for ( var arg = 0; arg < args.Count; arg++ ) - { - if ( ( args[arg].Equals("--thumbnail", StringComparison.CurrentCultureIgnoreCase) || - args[arg].Equals("-t", StringComparison.CurrentCultureIgnoreCase) ) - && ( arg + 1 ) != args.Count && - bool.TryParse(args[arg + 1], out var isThumbnail2) ) - { - isThumbnail = isThumbnail2; - } - } + return isOrphanFolderCheck; + } - return isThumbnail; - } + /// + /// Move files + /// + /// args input + /// bool, true=move + public static bool GetMove(IReadOnlyList args) + { + var getMove = false; - /// - /// Check for parent/sub items feature - /// - /// args input - /// bool - public bool GetOrphanFolderCheck(IReadOnlyList args) + for ( var arg = 0; arg < args.Count; arg++ ) { - var isOrphanFolderCheck = false; - - for ( var arg = 0; arg < args.Count; arg++ ) + if ( ( args[arg].Equals("--move", StringComparison.CurrentCultureIgnoreCase) + || args[arg].Equals("-m", StringComparison.CurrentCultureIgnoreCase) ) + && arg + 1 != args.Count && + bool.TryParse(args[arg + 1], out var getMove2) ) { - if ( ( args[arg].Equals("--orphanfolder", - StringComparison.CurrentCultureIgnoreCase) || - args[arg].Equals("-o", StringComparison.CurrentCultureIgnoreCase) ) - && ( arg + 1 ) != args.Count && - bool.TryParse(args[arg + 1], out var isOrphanFolderCheck2) ) - { - isOrphanFolderCheck = isOrphanFolderCheck2; - } + getMove = getMove2; + continue; } - if ( _appSettings.IsVerbose() ) + if ( args[arg].Equals("--move", StringComparison.CurrentCultureIgnoreCase) || + args[arg].Equals("-m", StringComparison.CurrentCultureIgnoreCase) ) { - Console.WriteLine(">> isOrphanFolderCheck " + isOrphanFolderCheck); + getMove = true; } - - return isOrphanFolderCheck; } - /// - /// Move files - /// - /// args input - /// bool, true=move - public static bool GetMove(IReadOnlyList args) - { - var getMove = false; - - for ( var arg = 0; arg < args.Count; arg++ ) - { - if ( ( args[arg].Equals("--move", StringComparison.CurrentCultureIgnoreCase) - || args[arg].Equals("-m", StringComparison.CurrentCultureIgnoreCase) ) - && ( arg + 1 ) != args.Count && - bool.TryParse(args[arg + 1], out var getMove2) ) - { - getMove = getMove2; - continue; - } - - if ( ( args[arg].Equals("--move", StringComparison.CurrentCultureIgnoreCase) || - args[arg].Equals("-m", StringComparison.CurrentCultureIgnoreCase) ) ) - { - getMove = true; - } - } + return getMove; + } - return getMove; - } + /// + /// Get all --all true + /// + /// input args + /// bool + public static bool GetAll(IReadOnlyList args) + { + // default false + var getAll = false; - /// - /// Get all --all true - /// - /// input args - /// bool - public static bool GetAll(IReadOnlyList args) + for ( var arg = 0; arg < args.Count; arg++ ) { - // default false - var getAll = false; - - for ( int arg = 0; arg < args.Count; arg++ ) + if ( args[arg].Equals("--all", StringComparison.CurrentCultureIgnoreCase) || + args[arg].Equals("-a", StringComparison.CurrentCultureIgnoreCase) ) { - if ( ( args[arg].Equals("--all", StringComparison.CurrentCultureIgnoreCase) || - args[arg].Equals("-a", StringComparison.CurrentCultureIgnoreCase) ) ) - { - getAll = true; - } - - if ( ( !args[arg].Equals("--all", - StringComparison.CurrentCultureIgnoreCase) && - !args[arg].Equals("-a", - StringComparison.CurrentCultureIgnoreCase) ) || - ( arg + 1 ) == args.Count ) - { - continue; - } + getAll = true; + } - if ( args[arg + 1].Equals("false", - StringComparison.CurrentCultureIgnoreCase) ) - { - getAll = false; - } + if ( ( !args[arg].Equals("--all", + StringComparison.CurrentCultureIgnoreCase) && + !args[arg].Equals("-a", + StringComparison.CurrentCultureIgnoreCase) ) || + arg + 1 == args.Count ) + { + continue; } - return getAll; + if ( args[arg + 1].Equals("false", + StringComparison.CurrentCultureIgnoreCase) ) + { + getAll = false; + } } - /// - /// Recursive scan for folders - /// - /// input args - /// bool - public static bool NeedRecursive(IReadOnlyList args) - { - bool needRecursive = false; + return getAll; + } + + /// + /// Recursive scan for folders + /// + /// input args + /// bool + public static bool NeedRecursive(IReadOnlyList args) + { + var needRecursive = false; - foreach ( var arg in args ) + foreach ( var arg in args ) + { + if ( arg.Equals("--recursive", StringComparison.CurrentCultureIgnoreCase) || + arg.Equals("-r", StringComparison.CurrentCultureIgnoreCase) ) { - if ( ( arg.Equals("--recursive", StringComparison.CurrentCultureIgnoreCase) || - arg.Equals("-r", StringComparison.CurrentCultureIgnoreCase) ) ) - { - needRecursive = true; - } + needRecursive = true; } - - return needRecursive; } - /// - /// Need to remove caches - /// - /// input args - /// bool - public static bool NeedCleanup(IReadOnlyList args) - { - // -x --clean - bool needCacheCleanup = false; + return needRecursive; + } + + /// + /// Need to remove caches + /// + /// input args + /// bool + public static bool NeedCleanup(IReadOnlyList args) + { + // -x --clean + var needCacheCleanup = false; - foreach ( var arg in args ) + foreach ( var arg in args ) + { + if ( arg.Equals("--clean", StringComparison.CurrentCultureIgnoreCase) || + arg.Equals("-x", StringComparison.CurrentCultureIgnoreCase) ) { - if ( ( arg.Equals("--clean", StringComparison.CurrentCultureIgnoreCase) || - arg.Equals("-x", StringComparison.CurrentCultureIgnoreCase) ) ) - { - needCacheCleanup = true; - } + needCacheCleanup = true; } - - return needCacheCleanup; } - /// - /// Get colorClass value from args - /// - /// input args - /// number, but valid with colorClass - public static int GetColorClass(IReadOnlyList args) - { - // --colorclass - var colorClass = -1; + return needCacheCleanup; + } - for ( var arg = 0; arg < args.Count; arg++ ) - { - if ( !args[arg].Equals("--colorclass", - StringComparison.CurrentCultureIgnoreCase) || - ( arg + 1 ) == args.Count ) - { - continue; - } + /// + /// Get colorClass value from args + /// + /// input args + /// number, but valid with colorClass + public static int GetColorClass(IReadOnlyList args) + { + // --colorclass + var colorClass = -1; - var colorClassString = args[arg + 1]; - var color = ColorClassParser.GetColorClass(colorClassString); - colorClass = ( int ) color; + for ( var arg = 0; arg < args.Count; arg++ ) + { + if ( !args[arg].Equals("--colorclass", + StringComparison.CurrentCultureIgnoreCase) || + arg + 1 == args.Count ) + { + continue; } - return colorClass; + var colorClassString = args[arg + 1]; + var color = ColorClassParser.GetColorClass(colorClassString); + colorClass = ( int ) color; } + + return colorClass; } } diff --git a/starsky/starsky/clientapp/src/components/atoms/drop-area/upload-files.ts b/starsky/starsky/clientapp/src/components/atoms/drop-area/upload-files.ts index ecc8087e2c..d216f25f1a 100644 --- a/starsky/starsky/clientapp/src/components/atoms/drop-area/upload-files.ts +++ b/starsky/starsky/clientapp/src/components/atoms/drop-area/upload-files.ts @@ -1,5 +1,4 @@ import { IFileIndexItem, newIFileIndexItemArray } from "../../../interfaces/IFileIndexItem"; -import { MoreMenuEventCloseConst } from "../more-menu/more-menu"; import { PostSingleFormData } from "./post-single-form-data"; export class UploadFiles { @@ -31,8 +30,6 @@ export class UploadFiles { * Pushing content to the server * @param files FileList */ - // only needed for the more menu - window.dispatchEvent(new CustomEvent(MoreMenuEventCloseConst, { bubbles: false })); const filesList = Array.from(files); diff --git a/starsky/starsky/clientapp/src/components/atoms/more-menu/more-menu.spec.tsx b/starsky/starsky/clientapp/src/components/atoms/more-menu/more-menu.spec.tsx index e887872757..031205d407 100644 --- a/starsky/starsky/clientapp/src/components/atoms/more-menu/more-menu.spec.tsx +++ b/starsky/starsky/clientapp/src/components/atoms/more-menu/more-menu.spec.tsx @@ -1,6 +1,6 @@ -import { act, render, screen } from "@testing-library/react"; +import { render, screen } from "@testing-library/react"; import { useState } from "react"; -import MoreMenu, { MoreMenuEventCloseConst } from "./more-menu"; +import MoreMenu from "./more-menu"; describe("More Menu", () => { it("renders", () => { @@ -51,21 +51,4 @@ describe("More Menu", () => { element.unmount(); }); - - it("turn off using event", (done) => { - const element = render(); - - const menuContext = screen.queryAllByTestId("menu-context")[0]; - - window.addEventListener(MoreMenuEventCloseConst, () => { - expect(menuContext.className).toBe("menu-context menu-context--hide"); - done(); - }); - - act(() => { - window.dispatchEvent(new CustomEvent(MoreMenuEventCloseConst)); - }); - - element.unmount(); - }); }); diff --git a/starsky/starsky/clientapp/src/components/atoms/more-menu/more-menu.tsx b/starsky/starsky/clientapp/src/components/atoms/more-menu/more-menu.tsx index bd115587d0..d49509a046 100644 --- a/starsky/starsky/clientapp/src/components/atoms/more-menu/more-menu.tsx +++ b/starsky/starsky/clientapp/src/components/atoms/more-menu/more-menu.tsx @@ -1,4 +1,4 @@ -import React, { useEffect } from "react"; +import React from "react"; import useGlobalSettings from "../../../hooks/use-global-settings"; import localization from "../../../localization/localization.json"; import { Language } from "../../../shared/language"; @@ -9,8 +9,6 @@ type MoreMenuPropTypes = { setEnableMoreMenu: React.Dispatch; }; -export const MoreMenuEventCloseConst = "CLOSE_MORE_MENU"; - const MoreMenu: React.FunctionComponent = ({ children, enableMoreMenu, @@ -22,18 +20,6 @@ const MoreMenu: React.FunctionComponent = ({ const offMoreMenu = () => setEnableMoreMenu(false); - // todo: Should refactor to avoid the usage in upload files - // don't use MoreMenuEventCloseConst in upload files - useEffect(() => { - // Bind the event listener - window.addEventListener(MoreMenuEventCloseConst, offMoreMenu); - - return () => { - // Unbind the event listener on clean up - window.removeEventListener(MoreMenuEventCloseConst, offMoreMenu); - }; - }); - return ( <>