feat:记忆上次被选择的文件夹

This commit is contained in:
ShakeFlower 2025-07-10 17:48:58 +08:00
parent b9d2b0100a
commit ffa321a5fc
5 changed files with 108 additions and 0 deletions

18
App.config Normal file
View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="H5MotaUpdate.Properties.Settings1" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<userSettings>
<H5MotaUpdate.Properties.Settings1>
<setting name="LastSourceFolderPath" serializeAs="String">
<value />
</setting>
<setting name="LastDestFolderPath" serializeAs="String">
<value />
</setting>
</H5MotaUpdate.Properties.Settings1>
</userSettings>
</configuration>

View File

@ -13,4 +13,19 @@
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>
<ItemGroup>
<Compile Update="Properties\Settings.Designer.cs">
<DesignTimeSharedInput>True</DesignTimeSharedInput>
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<None Update="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
</ItemGroup>
</Project>

50
Properties/Settings.Designer.cs generated Normal file
View File

@ -0,0 +1,50 @@
//------------------------------------------------------------------------------
// <auto-generated>
// 此代码由工具生成。
// 运行时版本:4.0.30319.42000
//
// 对此文件的更改可能会导致不正确的行为,并且如果
// 重新生成代码,这些更改将会丢失。
// </auto-generated>
//------------------------------------------------------------------------------
namespace H5MotaUpdate.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.11.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default {
get {
return defaultInstance;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("")]
public string LastSourceFolderPath {
get {
return ((string)(this["LastSourceFolderPath"]));
}
set {
this["LastSourceFolderPath"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("")]
public string LastDestFolderPath {
get {
return ((string)(this["LastDestFolderPath"]));
}
set {
this["LastDestFolderPath"] = value;
}
}
}
}

View File

@ -0,0 +1,12 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="H5MotaUpdate.Properties" GeneratedClassName="Settings1">
<Profiles />
<Settings>
<Setting Name="LastSourceFolderPath" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="LastDestFolderPath" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
</Settings>
</SettingsFile>

View File

@ -91,10 +91,17 @@ namespace H5MotaUpdate.ViewModels
{
using (FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog())
{
// 设置初始路径为上一次选择的路径
folderBrowserDialog.SelectedPath = Properties.Settings.Default.LastSourceFolderPath;
if (folderBrowserDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
SourceRootDirectory = folderBrowserDialog.SelectedPath;
// 保存本次选择的路径
Properties.Settings.Default.LastSourceFolderPath = SourceRootDirectory;
Properties.Settings.Default.Save();
}
VersionString = VersionUtils.GetVersion(SourceRootDirectory);
}
}
@ -106,9 +113,15 @@ namespace H5MotaUpdate.ViewModels
{
using (FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog())
{
// 设置初始路径为上一次选择的路径
folderBrowserDialog.SelectedPath = Properties.Settings.Default.LastDestFolderPath;
if (folderBrowserDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
DestRootDirectory = folderBrowserDialog.SelectedPath;
// 保存本次选择的路径
Properties.Settings.Default.LastDestFolderPath = DestRootDirectory;
Properties.Settings.Default.Save();
}
}
}