Skip to content
This repository has been archived by the owner on Mar 3, 2022. It is now read-only.

Commit

Permalink
Fix used by another process issue when overriding obsolete language…
Browse files Browse the repository at this point in the history
… pack on Windows
  • Loading branch information
richardhyy committed Jun 2, 2021
1 parent 0a6be67 commit 493cb8a
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/main/java/cc/eumc/eusminerhat/MinerHat.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
import org.bukkit.scheduler.BukkitTask;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.Objects;
Expand Down Expand Up @@ -279,16 +281,20 @@ private void validateDefaultLanguagePacks() throws Exception {
continue;
} else {
String backupName = "" + Timestamp.getSecondsSince1970() + "_bak_" + language + ".json";
Files.move(languageFile.toPath(), languageFile.toPath().resolveSibling(backupName));

Files.copy(languageFile.toPath(), languageFile.toPath().resolveSibling(backupName), StandardCopyOption.REPLACE_EXISTING);
// No translation for this warning message because the language pack has not been loaded yet.
sendWarn(String.format("Language pack %s is not compatible with the current version of MinerHat, " +
"we have written an up-to-date copy for replacement. An backup has been made.", language + ".json"));
}
}

InputStream in = getResource(language + ".json");
Files.copy(Objects.requireNonNull(in), languageFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
OutputStream out = new FileOutputStream(languageFile);
int bytesRead;
byte[] buffer = new byte[4096];
while ((bytesRead = in.read(buffer)) != -1) {
out.write(buffer, 0, bytesRead);
}
}
}
}

0 comments on commit 493cb8a

Please sign in to comment.