Skip to content

Commit

Permalink
Added protection against problems with folders in Windows if the file…
Browse files Browse the repository at this point in the history
… name has a space before the extension (fix #596)
  • Loading branch information
Serg-Norseman committed Sep 12, 2024
1 parent 43c557b commit 522c77e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions locales/help_enu/gkhHistory.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ <h1>Change log</h1>

<p>
<b>??.??.2024 [v2.32.0 &amp; v3.8.0]</b><ul>
<li>Added protection against problems with folders in Windows if the file name has a space before the extension.
<li>Added statistics type on parents' ages at child's birth.
<li>Fixed a frequent error saving images to cache "A generic error occurred in GDI+".
<li>Added the feature to save trees to PDF files.
Expand Down
1 change: 1 addition & 0 deletions locales/help_rus/gkhHistory.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ <h1>История версий</h1>

<p>
<b>??.??.2024 [v2.32.0 &amp; v3.8.0]</b><ul>
<li>Добавлена защита от проблем с папками в Windows, если в имени файла перед расширением есть пробел.
<li>Добавлен тип статистики по возрастам родителей при рождении ребенка.
<li>Исправлена частая ошибка сохранения изображений в кэш "A generic error occurred in GDI+".
<li>Добавлена возможность сохранения диаграмм деревьев в PDF-файлы.
Expand Down
17 changes: 17 additions & 0 deletions projects/GKCore/GKCore/BaseContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1539,10 +1539,27 @@ private void RemoveOldestBackups(string fileName, string bakPath)
}
}

private static string CheckFileName(string fileName)
{
// Control of possible folder management problems in Windows
// if there is a space before the dot in the file name
// (the folder cannot be deleted, copied, renamed, moved).
string purePath = Path.GetDirectoryName(fileName);
string pureFileName = Path.GetFileNameWithoutExtension(fileName);
string ext = Path.GetExtension(fileName);
if (pureFileName.EndsWith(" ")) {
pureFileName = pureFileName.TrimEnd();
fileName = Path.Combine(purePath, Path.ChangeExtension(pureFileName, ext));
}
return fileName;
}

private void FileSave(string fileName, string password)
{
string oldFileName = fFileName;

fileName = CheckFileName(fileName);

switch (GlobalOptions.Instance.FileBackup) {
case FileBackup.fbNone:
break;
Expand Down

0 comments on commit 522c77e

Please sign in to comment.