Skip to content

Commit

Permalink
Create backup folder for plugins only when needed
Browse files Browse the repository at this point in the history
Because of MO "overwrite" shenanigans
  • Loading branch information
zilav committed Jan 27, 2018
1 parent 7c8f377 commit 3e40b2d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 35 deletions.
68 changes: 38 additions & 30 deletions frmViewMain.pas
Expand Up @@ -963,38 +963,46 @@ procedure DoRename;
if wbDontSave then
Exit;

if Assigned(FilesToRename) then
for i := 0 to Pred(FilesToRename.Count) do begin
// create backup file
s := FilesToRename.Names[i];
f := wbDataPath + s;
OrgDate := FileAge(f);
t := wbBackupPath + ExtractFileName(s) + '.backup.' + FormatDateTime('yyyy_mm_dd_hh_nn_ss', Now);
if not wbDontBackup then begin
// backup original file
if not RenameFile(f, t) then begin
MessageBox(0, PChar('Could not rename "' + f + '" to "' + t + '".'), 'Error', 0);
Continue;
end;
end else
// remove original file
if not SysUtils.DeleteFile(f) then begin
MessageBox(0, PChar('Could not delete "' + f + '".'), 'Error', 0);
Continue;
end;
// rename temp save file to original
t := f;
s := FilesToRename.ValueFromIndex[i];
f := wbDataPath + s;
if not RenameFile(f, t) then
MessageBox(0, PChar('Could not rename "' + f + '" to "' + t + '".'), 'Error', 0)
else begin
// restore timestamp on a new file
e := ExtractFileExt(t);
if SameText(e, '.esp') or SameText(e, '.esm') or SameText(e, '.esl') or SameText(e, '.ghost') then
FileSetDate(t, OrgDate);
if not Assigned(FilesToRename) then
Exit;

if not wbDontBackup and not DirectoryExists(wbBackupPath) then
if not ForceDirectories(wbBackupPath) then
wbBackupPath := wbDataPath;

for i := 0 to Pred(FilesToRename.Count) do begin
// create backup file
s := FilesToRename.Names[i];
f := wbDataPath + s;
OrgDate := FileAge(f);
t := wbBackupPath + ExtractFileName(s) + '.backup.' + FormatDateTime('yyyy_mm_dd_hh_nn_ss', Now);
if not wbDontBackup then begin
// backup original file
if not RenameFile(f, t) then begin
MessageBox(0, PChar('Could not rename "' + f + '" to "' + t + '".'), 'Error', 0);
Continue;
end;
end else
// remove original file
if not SysUtils.DeleteFile(f) then begin
MessageBox(0, PChar('Could not delete "' + f + '".'), 'Error', 0);
Continue;
end;
// rename temp save file to original
t := f;
s := FilesToRename.ValueFromIndex[i];
f := wbDataPath + s;
if not RenameFile(f, t) then
MessageBox(0, PChar('Could not rename "' + f + '" to "' + t + '".'), 'Error', 0)
else
// restore timestamp on a new file for the games that use timestamps for load order
// all games for now for legacy reasons
{if wbGameMode in [gmTES4, gmFO3, gmFNV] then }begin
e := ExtractFileExt(t);
if SameText(e, '.esp') or SameText(e, '.esm') or SameText(e, '.esl') or SameText(e, '.ghost') then
FileSetDate(t, OrgDate);
end;
end;
end;

procedure TfrmMain.acBackExecute(Sender: TObject);
Expand Down
7 changes: 2 additions & 5 deletions wbInit.pas
Expand Up @@ -406,12 +406,9 @@ procedure DoInitPath(const ParamIndex: Integer);
wbSettingsFileName := ChangeFileExt(wbPluginsFileName, '.'+LowerCase(wbAppName)+'viewsettings');

wbBackupPath := '';
if not (wbDontSave or wbFindCmdLineParam('B', wbBackupPath)) then begin
if not (wbDontSave or wbFindCmdLineParam('B', wbBackupPath)) then
wbBackupPath := wbDataPath + wbAppName + 'Edit Backups\';
if not DirectoryExists(wbBackupPath) then
if not ForceDirectories(wbBackupPath) then
wbBackupPath := wbDataPath;
end;

wbFindCmdLineParam('R', wbLogFile);
end;

Expand Down

0 comments on commit 3e40b2d

Please sign in to comment.