Skip to content

Commit

Permalink
Migrate previous icon mappings w/o package name
Browse files Browse the repository at this point in the history
So previous mappings are preserved when updating.
  • Loading branch information
markusfisch committed Jan 19, 2025
1 parent e1a5c05 commit 194c073
Showing 1 changed file with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
Expand All @@ -22,8 +23,18 @@ public static void restore(Context context,
HashMap<String, IconPack.PackAndDrawable> mappings) {
mappings.clear();
try {
boolean migrated = false;

// Migrate previous mappings without package name.
String mappingsFile = getMappingsFile(packageName);
if (!fileExists(context, mappingsFile) &&
fileExists(context, MAPPINGS_FILE)) {
migrated = true;
mappingsFile = MAPPINGS_FILE;
}

BufferedReader reader = new BufferedReader(new InputStreamReader(
context.openFileInput(getMappingsFile(packageName))));
context.openFileInput(mappingsFile)));
String line;
while ((line = reader.readLine()) != null) {
String[] parts = line.split(SEPARATOR);
Expand All @@ -34,6 +45,10 @@ public static void restore(Context context,
parts[1], parts[2]));
}
reader.close();

if (migrated) {
store(context, packageName, mappings);
}
} catch (FileNotFoundException e) {
// Return an empty array.
} catch (IOException e) {
Expand Down Expand Up @@ -73,4 +88,9 @@ private static String getMappingsFile(String packageName) {
}
return sb.toString();
}

private static boolean fileExists(Context context, String fileName) {
File file = context.getFileStreamPath(fileName);
return file != null && file.exists();
}
}

0 comments on commit 194c073

Please sign in to comment.