修复 保存图片时图片不存在报错的问题

This commit is contained in:
Hakoyu 2023-10-13 22:51:24 +08:00
parent e5e572fde8
commit 171c49012c
4 changed files with 60 additions and 59 deletions

View File

@ -80,6 +80,8 @@ public static class Extensions
/// <param name="path">路径</param>
public static void SaveToPng(this BitmapSource image, string path)
{
if (image is null)
return;
if (path.EndsWith(".png") is false)
path += ".png";
var encoder = new PngBitmapEncoder();

View File

@ -249,52 +249,51 @@ public class ModInfoModel : I18nModel<I18nModInfoModel>
if (I18nHelper.Current.CultureNames.Contains(lang) is false)
I18nHelper.Current.CultureNames.Add(lang);
}
if (I18nHelper.Current.CultureNames.Count > 0)
if (I18nHelper.Current.CultureNames.Count == 0)
return;
I18nHelper.Current.CultureName.Value = I18nHelper.Current.CultureNames.First();
foreach (var i18nData in OtherI18nDatas)
{
I18nHelper.Current.CultureName.Value = I18nHelper.Current.CultureNames.First();
foreach (var i18nData in OtherI18nDatas)
foreach (var food in Foods)
{
foreach (var food in Foods)
var foodI18n = food.I18nDatas[i18nData.Key];
if (i18nData.Value.TryGetValue(food.Id.Value, out var name))
foodI18n.Name.Value = name;
if (i18nData.Value.TryGetValue(food.DescriptionId.Value, out var description))
foodI18n.Description.Value = description;
}
foreach (var lowText in LowTexts)
{
var lowTextI18n = lowText.I18nDatas[i18nData.Key];
if (i18nData.Value.TryGetValue(lowText.Id.Value, out var text))
lowTextI18n.Text.Value = text;
}
foreach (var clickText in ClickTexts)
{
var clickTextI18n = clickText.I18nDatas[i18nData.Key];
if (i18nData.Value.TryGetValue(clickText.Id.Value, out var text))
clickTextI18n.Text.Value = text;
}
foreach (var selectText in SelectTexts)
{
var selectTextI18n = selectText.I18nDatas[i18nData.Key];
if (i18nData.Value.TryGetValue(selectText.Id.Value, out var text))
selectTextI18n.Text.Value = text;
if (i18nData.Value.TryGetValue(selectText.ChooseId.Value, out var choose))
selectTextI18n.Choose.Value = choose;
}
foreach (var pet in Pets)
{
var petI18n = pet.I18nDatas[i18nData.Key];
if (i18nData.Value.TryGetValue(pet.Id.Value, out var name))
petI18n.Name.Value = name;
if (i18nData.Value.TryGetValue(pet.DescriptionId.Value, out var description))
petI18n.Description.Value = description;
foreach (var work in pet.Works)
{
var foodI18n = food.I18nDatas[i18nData.Key];
if (i18nData.Value.TryGetValue(food.Id.Value, out var name))
foodI18n.Name.Value = name;
if (i18nData.Value.TryGetValue(food.DescriptionId.Value, out var description))
foodI18n.Description.Value = description;
}
foreach (var lowText in LowTexts)
{
var lowTextI18n = lowText.I18nDatas[i18nData.Key];
if (i18nData.Value.TryGetValue(lowText.Id.Value, out var text))
lowTextI18n.Text.Value = text;
}
foreach (var clickText in ClickTexts)
{
var clickTextI18n = clickText.I18nDatas[i18nData.Key];
if (i18nData.Value.TryGetValue(clickText.Id.Value, out var text))
clickTextI18n.Text.Value = text;
}
foreach (var selectText in SelectTexts)
{
var selectTextI18n = selectText.I18nDatas[i18nData.Key];
if (i18nData.Value.TryGetValue(selectText.Id.Value, out var text))
selectTextI18n.Text.Value = text;
if (i18nData.Value.TryGetValue(selectText.ChooseId.Value, out var choose))
selectTextI18n.Choose.Value = choose;
}
foreach (var pet in Pets)
{
var petI18n = pet.I18nDatas[i18nData.Key];
if (i18nData.Value.TryGetValue(pet.Id.Value, out var name))
petI18n.Name.Value = name;
if (i18nData.Value.TryGetValue(pet.DescriptionId.Value, out var description))
petI18n.Description.Value = description;
foreach (var work in pet.Works)
{
var workI18n = work.I18nDatas[i18nData.Key];
if (i18nData.Value.TryGetValue(work.Id.Value, out var workName))
workI18n.Name.Value = workName;
}
var workI18n = work.I18nDatas[i18nData.Key];
if (i18nData.Value.TryGetValue(work.Id.Value, out var workName))
workI18n.Name.Value = workName;
}
}
}

View File

@ -200,21 +200,21 @@ public class ModEditWindowVM
if (saveFileDialog.ShowDialog() is true)
{
var pending = PendingBox.Show("保存中".Translate());
try
{
var path = Path.GetDirectoryName(saveFileDialog.FileName);
ModInfo.Value.SaveTo(path);
if (string.IsNullOrWhiteSpace(ModInfo.Value.SourcePath.Value))
ModInfo.Value.SourcePath.Value = path;
pending.Close();
MessageBox.Show(ModEditWindow, "保存成功".Translate());
}
catch (Exception ex)
{
pending.Close();
MessageBox.Show($"保存失败 错误信息:\n{0}".Translate(ex));
return;
}
//try
//{
var path = Path.GetDirectoryName(saveFileDialog.FileName);
ModInfo.Value.SaveTo(path);
if (string.IsNullOrWhiteSpace(ModInfo.Value.SourcePath.Value))
ModInfo.Value.SourcePath.Value = path;
pending.Close();
MessageBox.Show(ModEditWindow, "保存成功".Translate());
//}
//catch (Exception ex)
//{
// pending.Close();
// MessageBox.Show("保存失败 错误信息:\n{0}".Translate(ex));
// return;
//}
}
}

View File

@ -36,7 +36,7 @@
<Button
Grid.Column="1"
Command="{Binding ClearHistoriesCommand}"
Content="清空历史" />
Content="{ll:Str 清空历史}" />
</Grid>
<ListBox
Grid.Row="2"