-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImageResizeSettings.cs
More file actions
164 lines (146 loc) · 5.14 KB
/
ImageResizeSettings.cs
File metadata and controls
164 lines (146 loc) · 5.14 KB
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Runtime.CompilerServices;
using System.Text.Json;
using ImageResize.Model;
using YukkuriMovieMaker.Plugin;
namespace ImageResize.Settings
{
public class ImageResizeSettings : SettingsBase<ImageResizeSettings>
{
public override string Name => Translate.PluginName;
public override SettingsCategory Category => SettingsCategory.None;
public override bool HasSettingView => true;
public override object? SettingView => new ImageResizeSettingsView();
private ObservableCollection<ResizePreset> _presets = new ObservableCollection<ResizePreset>();
public ObservableCollection<ResizePreset> Presets
{
get => _presets;
set => SetProperty(ref _presets, value);
}
private string _fallbackEncoder = "PNG";
public string FallbackEncoder
{
get => _fallbackEncoder;
set => SetProperty(ref _fallbackEncoder, value);
}
private int _jpegQuality = 90;
public int JpegQuality
{
get => _jpegQuality;
set => SetProperty(ref _jpegQuality, value);
}
private string _pngInterlace = "なし";
public string PngInterlace
{
get => _pngInterlace;
set => SetProperty(ref _pngInterlace, value);
}
private string _tiffCompression = "LZW";
public string TiffCompression
{
get => _tiffCompression;
set => SetProperty(ref _tiffCompression, value);
}
private string _fileNameFormat = "{filename}_resized";
public string FileNameFormat
{
get => _fileNameFormat;
set => SetProperty(ref _fileNameFormat, value);
}
private string _timestampHandling = "元のまま";
public string TimestampHandling
{
get => _timestampHandling;
set => SetProperty(ref _timestampHandling, value);
}
private bool _dontUpscale = true;
public bool DontUpscale
{
get => _dontUpscale;
set => SetProperty(ref _dontUpscale, value);
}
private bool _ignoreOrientation;
public bool IgnoreOrientation
{
get => _ignoreOrientation;
set => SetProperty(ref _ignoreOrientation, value);
}
private bool _overwriteFiles;
public bool OverwriteFiles
{
get => _overwriteFiles;
set => SetProperty(ref _overwriteFiles, value);
}
private bool _removeMetadata = true;
public bool RemoveMetadata
{
get => _removeMetadata;
set => SetProperty(ref _removeMetadata, value);
}
private static string SettingsDirectory => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "YukkuriMovieMaker4", "user", "plugins", "ImageResize");
private static string PresetsFilePath => Path.Combine(SettingsDirectory, "presets.json");
public override void Initialize()
{
LoadPresets();
}
public void LoadPresets()
{
if (File.Exists(PresetsFilePath))
{
try
{
var json = File.ReadAllText(PresetsFilePath);
var presets = JsonSerializer.Deserialize<ObservableCollection<ResizePreset>>(json);
if (presets != null)
{
Presets = presets;
}
else
{
InitializeDefaultPresets();
}
}
catch (Exception)
{
InitializeDefaultPresets();
}
}
else
{
InitializeDefaultPresets();
}
}
public void SavePresets()
{
try
{
Directory.CreateDirectory(SettingsDirectory);
var options = new JsonSerializerOptions { WriteIndented = true };
var json = JsonSerializer.Serialize(Presets, options);
File.WriteAllText(PresetsFilePath, json);
}
catch (Exception)
{
}
}
private void InitializeDefaultPresets()
{
Presets.Clear();
Presets.Add(new ResizePreset { Name = "Default", Width = 1920, Height = 1080 });
SavePresets();
}
protected bool SetProperty<T>(ref T field, T value, [CallerMemberName] string? propertyName = null)
{
if (EqualityComparer<T>.Default.Equals(field, value)) return false;
field = value;
if (propertyName != null)
{
OnPropertyChanged(propertyName);
}
return true;
}
}
}