/*
* GNU AFFERO GENERAL PUBLIC LICENSE
* Version 3, 19 November 2007
* Copyright (C) 2007 Free Software Foundation, Inc.
* Everyone is permitted to copy and distribute verbatim copies
* of this license document, but changing it is not allowed.
*/
using Emgu.CV.Cuda;
using System;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using UVtools.Core.Layers;
using UVtools.Core.Operations;
namespace UVtools.Core;
public static class CoreSettings
{
#region Members
private static int _maxDegreeOfParallelism = -1;
#endregion
#region Properties
public static CultureInfo OptimalCultureInfo
{
get
{
var cultureInfo = (CultureInfo)CultureInfo.CurrentCulture.Clone();
cultureInfo.NumberFormat.CurrencyDecimalSeparator = CultureInfo.InvariantCulture.NumberFormat.CurrencyDecimalSeparator;
cultureInfo.NumberFormat.CurrencyGroupSeparator = CultureInfo.InvariantCulture.NumberFormat.CurrencyGroupSeparator;
cultureInfo.NumberFormat.NumberDecimalSeparator = CultureInfo.InvariantCulture.NumberFormat.NumberDecimalSeparator;
cultureInfo.NumberFormat.NumberGroupSeparator = CultureInfo.InvariantCulture.NumberFormat.NumberGroupSeparator;
cultureInfo.NumberFormat.PercentDecimalSeparator = CultureInfo.InvariantCulture.NumberFormat.PercentDecimalSeparator;
cultureInfo.NumberFormat.PercentGroupSeparator = CultureInfo.InvariantCulture.NumberFormat.PercentGroupSeparator;
return cultureInfo;
}
}
///
/// Gets or sets the maximum number of concurrent tasks enabled by this ParallelOptions instance.
/// Less or equal to 0 will set to auto number
/// 1 = Single thread
/// n = Multi threads
///
public static int MaxDegreeOfParallelism
{
get => _maxDegreeOfParallelism;
set => _maxDegreeOfParallelism = value > 0 ? Math.Min(value, Environment.ProcessorCount) : -1;
}
///
/// Gets the ParallelOptions with set
///
public static ParallelOptions ParallelOptions => new() {MaxDegreeOfParallelism = _maxDegreeOfParallelism};
///
/// Gets the ParallelOptions with set to 1 for debug purposes
///
public static ParallelOptions ParallelDebugOptions => new() { MaxDegreeOfParallelism = 1 };
///
/// Gets the ParallelOptions with and the set
///
public static ParallelOptions GetParallelOptions(CancellationToken token = default)
{
var options = ParallelOptions;
options.CancellationToken = token;
return options;
}
///
/// Gets the ParallelOptions with and the set
///
public static ParallelOptions GetParallelOptions(OperationProgress progress) => GetParallelOptions(progress.Token);
///
/// Gets or sets if operations run via CUDA when possible
///
public static bool EnableCuda { get; set; }
///
/// Gets if we can use cuda on operations
///
public static bool CanUseCuda => EnableCuda && CudaInvoke.HasCuda;
///
/// Gets or sets the default compression type for layers
///
public static LayerCompressionCodec DefaultLayerCompressionCodec { get; set; } = LayerCompressionCodec.Lz4;
///
/// The average resin 1000ml bottle cost, to use when bottle cost is not available.
/// Use 0 to disable.
///
public static float AverageResin1000MlBottleCost = 60f;
///
/// Gets the default folder to save the settings
///
public static string DefaultSettingsFolder
{
get
{
var folder = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
if (string.IsNullOrWhiteSpace(folder)) folder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
if (string.IsNullOrWhiteSpace(folder)) folder = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
if (string.IsNullOrWhiteSpace(folder)) folder = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
var path = Path.Combine(folder, About.Software);
return path;
}
}
///
/// Gets the default folder to save the settings
///
public static string DefaultSettingsFolderAndEnsureCreation
{
get
{
var path = DefaultSettingsFolder;
try
{
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
}
catch (Exception e)
{
Debug.WriteLine(e);
}
return path;
}
}
#endregion
}