-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. 支持记忆窗口位置、尺寸和状态 2. 支持保存上一次选择的输入输出格式 3. 更换滚动条样式,优化 UI 细节 4. 修复因缺少依赖项导致转换失败的 bug
- Loading branch information
Showing
12 changed files
with
511 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Windows; | ||
using Tomlet; | ||
using Tomlet.Attributes; | ||
using Tomlet.Models; | ||
|
||
namespace OpenSvip.GUI.Config | ||
{ | ||
public class AppConfig | ||
{ | ||
private const string CONFIG_FOLDER = "Config"; | ||
|
||
private const string CONFIG_FILENAME = "Configurations.toml"; | ||
|
||
private static readonly string ActualConfigFolder = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), CONFIG_FOLDER); | ||
|
||
private static readonly string ActualConfigFile = Path.Combine(ActualConfigFolder, CONFIG_FILENAME); | ||
|
||
[TomlProperty("Restoration")] | ||
public Properties Properties { get; set; } = new Properties(); | ||
|
||
[TomlProperty("Preference")] | ||
public Settings Settings { get; set; } = new Settings(); | ||
|
||
static AppConfig() | ||
{ | ||
TomletMain.RegisterMapper( | ||
rect => new TomlArray { rect.Left, rect.Top, rect.Width, rect.Height }, | ||
tomlValue => | ||
{ | ||
if (!(tomlValue is TomlArray tomlArray)) | ||
{ | ||
return new Rect(); | ||
} | ||
try | ||
{ | ||
var arr = tomlArray.Select(val => ((TomlDouble)val).Value).ToArray(); | ||
return new Rect(arr[0], arr[1], arr[2], arr[3]); | ||
} | ||
catch | ||
{ | ||
return new Rect(); | ||
} | ||
}); | ||
} | ||
|
||
public static AppConfig LoadFromFile() | ||
{ | ||
try | ||
{ | ||
var stream = new FileStream(ActualConfigFile, FileMode.Open, FileAccess.Read); | ||
var reader = new StreamReader(stream); | ||
var config = TomletMain.To<AppConfig>(reader.ReadToEnd()); | ||
reader.Close(); | ||
stream.Close(); | ||
return config; | ||
} | ||
catch | ||
{ | ||
return new AppConfig(); | ||
} | ||
} | ||
|
||
public void SaveToFile() | ||
{ | ||
try | ||
{ | ||
Directory.CreateDirectory(ActualConfigFolder); | ||
var stream = new FileStream(ActualConfigFile, FileMode.Create, FileAccess.Write); | ||
var writer = new StreamWriter(stream); | ||
writer.Write(TomletMain.TomlStringFrom(this)); | ||
writer.Flush(); | ||
stream.Flush(); | ||
writer.Close(); | ||
stream.Close(); | ||
} | ||
catch | ||
{ | ||
// ignored | ||
} | ||
} | ||
} | ||
|
||
public class Information | ||
{ | ||
public string Version { get; set; } = "1.0.6 (Preview)"; | ||
|
||
public string FrameworkVersion { get; set; } = "1.2.2"; | ||
|
||
public string Author { get; set; } = "YQ之神"; | ||
|
||
public string AuthorHomePage { get; set; } = "https://space.bilibili.com/102844209"; | ||
|
||
public string GitHubRepository { get; set; } = "https://github.com/yqzhishen/opensvip"; | ||
} | ||
|
||
[TomlDoNotInlineObject] | ||
public class Properties | ||
{ | ||
public Rect MainRestoreBounds { get; set; } = new Rect(); | ||
|
||
public WindowState MainWindowState { get; set; } = WindowState.Normal; | ||
} | ||
|
||
public class Settings | ||
{ | ||
public string ImportPluginId { get; set; } | ||
|
||
public string ExportPluginId { get; set; } | ||
|
||
public bool AutoDetectFormat { get; set; } = true; | ||
|
||
public bool AutoResetTasks { get; set; } = true; | ||
|
||
public bool AutoExtension { get; set; } = true; | ||
|
||
public bool OpenExportFolder { get; set; } = false; | ||
|
||
public OverwriteOptions OverwriteOption { get; set; } = OverwriteOptions.Overwrite; | ||
|
||
public ExportPaths DefaultExportPath { get; set; } = ExportPaths.Unset; | ||
|
||
public string[] CustomExportPaths { get; set; } = Array.Empty<string>(); | ||
} | ||
|
||
public enum OverwriteOptions | ||
{ | ||
Overwrite, Skip, Ask | ||
} | ||
|
||
public enum ExportPaths | ||
{ | ||
Unset, Source, Desktop, Custom | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.