Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save to temp to prevent file corruption #388

Merged
merged 1 commit into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion source/creator/core/settings.d
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ void incSettingsLoad() {
Saves settings from settings store
*/
void incSettingsSave() {
write(incSettingsPath(), settings.toString());
// using swp prevent file corruption
string swapPath = incSettingsPath() ~ ".swp";
write(swapPath, settings.toString());
rename(swapPath, incSettingsPath());
}

/**
Expand Down
6 changes: 5 additions & 1 deletion source/creator/io/inpexport.d
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import std.algorithm.sorting;
import std.algorithm.mutation;
import i18n;
import std.exception;
import std.file : rename;

private {
vec2 mapUVCoord(vec2 value, vec2 min, vec2 max) {
Expand Down Expand Up @@ -388,5 +389,8 @@ void incINPExport(Puppet puppet, IncINPExportSettings settings, string file) {
incINPExportFlatten(source);
incINPExportFinalizePacking(source, atlasses);

inWriteINPPuppet(source, file);
// using swp prevent file corruption
string swapPath = file ~ ".export.swp";
inWriteINPPuppet(source, swapPath);
rename(swapPath, file);
}
7 changes: 5 additions & 2 deletions source/creator/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import creator.core.colorbleed;

import std.path;
import std.format;
import std.file : rename;
import i18n;
import std.algorithm.searching;
import inochi2d.core.animation.player;
Expand Down Expand Up @@ -284,8 +285,10 @@ void incSaveProject(string path, string autosaveStamp = "") {
foreach (func; saveCallbacks)
func(incActivePuppet());

// Write the puppet to file
inWriteINPPuppet(incActivePuppet(), finalPath);
// Write the puppet to file, using swp prevent file corruption
string swapPath = finalPath ~ ".swp";
inWriteINPPuppet(incActivePuppet(), swapPath);
rename(swapPath, finalPath);

if (!isAutosave) incReleaseLockfile();
incActivePuppet().resetDrivers();
Expand Down
Loading