diff options
Diffstat (limited to 'app/src/main/java/com/wireguard/android/configStore/FileConfigStore.java')
-rw-r--r-- | app/src/main/java/com/wireguard/android/configStore/FileConfigStore.java | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/app/src/main/java/com/wireguard/android/configStore/FileConfigStore.java b/app/src/main/java/com/wireguard/android/configStore/FileConfigStore.java index 654cb48f..184dd6d5 100644 --- a/app/src/main/java/com/wireguard/android/configStore/FileConfigStore.java +++ b/app/src/main/java/com/wireguard/android/configStore/FileConfigStore.java @@ -8,6 +8,7 @@ package com.wireguard.android.configStore; import android.content.Context; import android.util.Log; +import com.wireguard.android.R; import com.wireguard.config.Config; import com.wireguard.config.ParseException; @@ -17,6 +18,7 @@ import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.nio.charset.StandardCharsets; +import java.util.Locale; import java.util.Set; import java9.util.stream.Collectors; @@ -40,7 +42,8 @@ public final class FileConfigStore implements ConfigStore { Log.d(TAG, "Creating configuration for tunnel " + name); final File file = fileFor(name); if (!file.createNewFile()) - throw new IOException("Configuration file " + file.getName() + " already exists"); + throw new IOException(String.format(Locale.getDefault(), + context.getResources().getString(R.string.config_file_exists_error), file.getName())); try (final FileOutputStream stream = new FileOutputStream(file, false)) { stream.write(config.toWgQuickString().getBytes(StandardCharsets.UTF_8)); } @@ -52,7 +55,8 @@ public final class FileConfigStore implements ConfigStore { Log.d(TAG, "Deleting configuration for tunnel " + name); final File file = fileFor(name); if (!file.delete()) - throw new IOException("Cannot delete configuration file " + file.getName()); + throw new IOException(String.format(Locale.getDefault(), + context.getResources().getString(R.string.config_delete_error), file.getName())); } @Override @@ -80,11 +84,13 @@ public final class FileConfigStore implements ConfigStore { final File file = fileFor(name); final File replacementFile = fileFor(replacement); if (!replacementFile.createNewFile()) - throw new IOException("Configuration for " + replacement + " already exists"); + throw new IOException(String.format(Locale.getDefault(), + context.getResources().getString(R.string.config_exists_error), replacement)); if (!file.renameTo(replacementFile)) { if (!replacementFile.delete()) Log.w(TAG, "Couldn't delete marker file for new name " + replacement); - throw new IOException("Cannot rename configuration file " + file.getName()); + throw new IOException(String.format(Locale.getDefault(), + context.getResources().getString(R.string.config_rename_error), file.getName())); } } @@ -93,7 +99,8 @@ public final class FileConfigStore implements ConfigStore { Log.d(TAG, "Saving configuration for tunnel " + name); final File file = fileFor(name); if (!file.isFile()) - throw new FileNotFoundException("Configuration file " + file.getName() + " not found"); + throw new FileNotFoundException(String.format(Locale.getDefault(), + context.getResources().getString(R.string.config_not_found_error), file.getName())); try (final FileOutputStream stream = new FileOutputStream(file, false)) { stream.write(config.toWgQuickString().getBytes(StandardCharsets.UTF_8)); } |