Screenie/Configuration.cs

66 lines
2.0 KiB
C#
Raw Normal View History

2024-02-18 00:32:45 +00:00
using System.Drawing.Imaging;
using Dalamud.Configuration;
2024-02-18 04:40:58 +00:00
using Scriban;
using Scriban.Parsing;
2024-02-18 00:32:45 +00:00
namespace Screenie;
[Serializable]
public class Configuration : IPluginConfiguration {
public int Version { get; set; } = 1;
public string SaveDirectory = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "Screenie");
public Format SaveFormat = Format.Png;
public int SaveFormatData = 90;
2024-02-18 05:26:53 +00:00
public string SaveFileNameFormat = """
{{ captured_at_local | date.to_string '%Y/%m/[%H.%M.%S]' }}
{{ active_character.name }}
-
{{ location }}
{{- if area }}
({{ area }})
{{- end -}}
""";
2024-02-18 04:40:58 +00:00
private int _templateHashCode;
private Template? _template;
internal Template SaveFileNameTemplate {
get {
var currentHash = this.SaveFileNameFormat.GetHashCode();
if (currentHash == this._templateHashCode && this._template != null) {
return this._template;
}
this._templateHashCode = currentHash;
this._template = Template.Parse(
this.SaveFileNameFormat,
parserOptions: new ParserOptions {
LiquidFunctionsToScriban = true,
}
);
return this._template;
}
}
2024-02-18 00:32:45 +00:00
}
public enum Format {
Png,
2024-02-18 02:36:57 +00:00
WebpLossless,
WebpLossy,
2024-02-18 00:32:45 +00:00
Jpg,
}
public static class FormatExt {
2024-02-18 02:36:57 +00:00
public static ImageFormat? ToImageFormat(this Format format) {
2024-02-18 00:32:45 +00:00
return format switch {
Format.Png => ImageFormat.Png,
2024-02-18 02:36:57 +00:00
Format.WebpLossless => null,
Format.WebpLossy => null,
2024-02-18 00:32:45 +00:00
Format.Jpg => ImageFormat.Jpeg,
_ => throw new ArgumentOutOfRangeException(nameof(format), format, null),
};
}
}