Skip to content

Commit d49e38f

Browse files
committed
🐛 ISettings 0kb
1 parent 5244009 commit d49e38f

4 files changed

Lines changed: 41 additions & 15 deletions

File tree

src/AssemblyInfo.Constants.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public static partial class AssemblyInfo
2323
/// </summary>
2424
const string ver_for_rc = "9";
2525

26-
public const string FileVersion = $"{Version2}.{ver_for_rc}0{ver_for_preview}.0";
26+
public const string FileVersion = $"{Version2}.{ver_for_rc}1{ver_for_preview}.0";
2727

2828
//public const string InformationalVersion = Version;
2929
//public const string InformationalVersion = $"{Version}-preview.{ver_for_preview}";

src/BD.WTTS.Client.Avalonia/Services.Implementation/UI/Views/Windows/AvaloniaWindowManagerImpl.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public async Task<bool> ShowTaskDialogAsync<TPageViewModel>(
9595
Func<bool>? cancelCloseAction = null,
9696
bool disableScroll = false)
9797
where TPageViewModel : ViewModelBase
98-
{
98+
{
9999
var td = new TaskDialogEx
100100
{
101101
Title = title,

src/BD.WTTS.Client/Settings/Infrastructure/Abstractions/ISettings.cs

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -289,9 +289,14 @@ static bool Load(bool directoryExists,
289289
bool isInvalid = false;
290290
if (writeFile)
291291
{
292-
using var fs = File.Create(settingsFilePath);
292+
using var ms = new MemoryStream();
293293
settings = new();
294-
settings.Save_____(fs);
294+
settings.Save_____(ms);
295+
ms.Position = 0;
296+
using var fs = File.Create(settingsFilePath);
297+
ms.CopyTo(fs);
298+
fs.Flush();
299+
fs.SetLength(fs.Position);
295300
}
296301
else
297302
{
@@ -304,15 +309,20 @@ static bool Load(bool directoryExists,
304309
settings = new();
305310
isInvalid = true;
306311

307-
// 尝试将错误的配置保存为 .json.i.bak 防止启动软件当前配置被覆盖
308-
var settingsFilePath_i_bak = $"{settingsFilePath}.i.bak";
309-
try
310-
{
311-
File.Move(settingsFilePath, settingsFilePath_i_bak);
312-
}
313-
catch
312+
// 尝试将错误的配置保存为 .json.load.bak 防止启动软件当前配置被覆盖
313+
if (!SettingsExtensions.IsZeroFile(settingsFilePath))
314314
{
315+
var settingsFilePath_load_bak = $"{settingsFilePath}.load.bak";
316+
try
317+
{
318+
IOPath.FileIfExistsItDelete(settingsFilePath_load_bak);
319+
File.Move(settingsFilePath,
320+
settingsFilePath_load_bak, true);
321+
}
322+
catch
323+
{
315324

325+
}
316326
}
317327
}
318328
}
@@ -330,6 +340,18 @@ static bool Load(bool directoryExists,
330340

331341
internal static class SettingsExtensions
332342
{
343+
internal static bool IsZeroFile(string filePath, bool @catch = true)
344+
{
345+
try
346+
{
347+
return new FileInfo(filePath).Length == 0;
348+
}
349+
catch
350+
{
351+
return @catch;
352+
}
353+
}
354+
333355
/// <summary>
334356
/// 将实例序列化为字符串
335357
/// </summary>
@@ -420,9 +442,12 @@ public static void TrySave_____<TSettings>(IOptionsMonitor<TSettings> optionsMon
420442

421443
try
422444
{
423-
var settingsFilePath2 = $"{settingsFilePath}.bak";
424-
IOPath.FileTryDelete(settingsFilePath2);
425-
File.Move(settingsFilePath, settingsFilePath2);
445+
if (!SettingsExtensions.IsZeroFile(settingsFilePath))
446+
{
447+
var settingsFilePath2 = $"{settingsFilePath}.save.bak";
448+
IOPath.FileTryDelete(settingsFilePath2);
449+
File.Move(settingsFilePath, settingsFilePath2, true);
450+
}
426451
}
427452
catch (Exception ex)
428453
{

src/BD.WTTS.Client/UI/ViewModels/Windows/Main/MainWindowViewModel.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@ public override async Task Initialize()
174174
b.Append(item);
175175
b.AppendLine(FileEx.JSON);
176176
}
177-
MessageBox.Show(b.ToString(), Strings.Error, icon: MessageBox.Image.Error);
177+
var errorMsg = b.ToString();
178+
MessageBox.Show(errorMsg, Strings.Error, icon: MessageBox.Image.Error);
178179
});
179180
}
180181

0 commit comments

Comments
 (0)