blob: 10246be658f04c1fd876ef69b4d9ee0d9c069e7e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
/*
* GNU AFFERO GENERAL PUBLIC LICENSE
* Version 3, 19 November 2007
* Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
* 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.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
/// <summary>
/// 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
/// </summary>
public static int MaxDegreeOfParallelism
{
get => _maxDegreeOfParallelism;
set => _maxDegreeOfParallelism = value > 0 ? Math.Min(value, Environment.ProcessorCount) : -1;
}
/// <summary>
/// Gets the ParallelOptions with <see cref="MaxDegreeOfParallelism"/> set
/// </summary>
public static ParallelOptions ParallelOptions => new() {MaxDegreeOfParallelism = _maxDegreeOfParallelism};
/// <summary>
/// Gets the ParallelOptions with <see cref="MaxDegreeOfParallelism"/> and the <see cref="CancellationToken"/> set
/// </summary>
public static ParallelOptions GetParallelOptions(CancellationToken token = default)
{
var options = ParallelOptions;
options.CancellationToken = token;
return options;
}
/// <summary>
/// Gets the ParallelOptions with <see cref="MaxDegreeOfParallelism"/> and the <see cref="CancellationToken"/> set
/// </summary>
public static ParallelOptions GetParallelOptions(OperationProgress progress) => GetParallelOptions(progress.Token);
/// <summary>
/// Gets or sets if operations run via CUDA when possible
/// </summary>
public static bool EnableCuda { get; set; }
/// <summary>
/// Gets if we can use cuda on operations
/// </summary>
public static bool CanUseCuda => EnableCuda && CudaInvoke.HasCuda;
/// <summary>
/// Gets or sets the default compression type for layers
/// </summary>
public static LayerCompressionCodec DefaultLayerCompressionCodec { get; set; } = LayerCompressionCodec.Png;
/// <summary>
/// <para>The average resin 1000ml bottle cost, to use when bottle cost is not available.</para>
/// <para>Use 0 to disable.</para>
/// </summary>
public static float AverageResin1000MlBottleCost = 60f;
/// <summary>
/// Gets the default folder to save the settings
/// </summary>
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;
}
}
/// <summary>
/// Gets the default folder to save the settings
/// </summary>
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
}
|