Skip to content

Commit f8cf00e

Browse files
author
Swamp Ig
committed
Ensure backup dir always created.
1 parent 2a68977 commit f8cf00e

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

SaveGameFixer.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -403,12 +403,7 @@ private void WriteLogMessage(string logMessage, bool debugMsg = false)
403403
#else
404404
string dbg = string.Empty;
405405
#endif
406-
if (backupDir == null)
407-
{
408-
backupDir = Path.Combine(KSPUtil.ApplicationRootPath, string.Format("saves_backup{1}{0:yyyyMMdd-HHmmss}", DateTime.Now, Path.DirectorySeparatorChar));
409-
Directory.CreateDirectory(backupDir);
410-
logFile = Path.Combine(backupDir, "backup.log");
411-
}
406+
CreateBackupDir();
412407

413408
StringBuilder sb = new StringBuilder();
414409

@@ -427,12 +422,23 @@ private void WriteLogMessage(string logMessage, bool debugMsg = false)
427422
File.AppendAllText(logFile, sb.ToString());
428423
}
429424

425+
private void CreateBackupDir()
426+
{
427+
if (backupDir == null)
428+
{
429+
backupDir = Path.Combine(KSPUtil.ApplicationRootPath, string.Format("saves_backup{1}{0:yyyyMMdd-HHmmss}", DateTime.Now, Path.DirectorySeparatorChar));
430+
Directory.CreateDirectory(backupDir);
431+
logFile = Path.Combine(backupDir, "backup.log");
432+
}
433+
}
434+
430435
private void BackupAndReplace(string file, ConfigNode config, bool needsBackup, bool needsSave)
431436
{
432437
#if !DEBUG
433438
if (needsBackup)
434439
#endif
435440
{
441+
CreateBackupDir();
436442

437443
string relPath = file.Substring(savesRoot.Length, file.Length - savesRoot.Length);
438444

0 commit comments

Comments
 (0)