move location of themes from "mods" to "themes" folder.
parent
019c50116d
commit
66581d7889
5
Makefile
5
Makefile
|
@ -145,9 +145,12 @@ M1.%: clean $(EXE) release/Magarena/mods/felt_theme.zip
|
|||
release/Magarena/translations \
|
||||
Magarena-1.$*/Magarena
|
||||
cp \
|
||||
release/Magarena/mods/felt_theme.zip \
|
||||
release/Magarena/mods/*.txt \
|
||||
Magarena-1.$*/Magarena/mods
|
||||
mkdir -p Magarena-1.$*/Magarena/themes
|
||||
cp \
|
||||
release/Magarena/mods/felt_theme.zip \
|
||||
Magarena-1.$*/Magarena/themes
|
||||
-zip -r Magarena-1.$*.zip Magarena-1.$*
|
||||
echo "preparing Mac dist"
|
||||
cp -r Magarena.app Magarena-1.$*.app
|
||||
|
|
|
@ -22,10 +22,10 @@ import magic.utility.FileIO;
|
|||
import magic.utility.MagicFileSystem;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.io.IOCase;
|
||||
import org.apache.commons.io.filefilter.DirectoryFileFilter;
|
||||
import org.apache.commons.io.filefilter.FileFilterUtils;
|
||||
import org.apache.commons.io.filefilter.IOFileFilter;
|
||||
import org.apache.commons.io.filefilter.NameFileFilter;
|
||||
import org.apache.commons.io.filefilter.WildcardFileFilter;
|
||||
|
||||
public class ImportWorker extends SwingWorker<Boolean, Void> {
|
||||
|
||||
|
@ -42,6 +42,7 @@ public class ImportWorker extends SwingWorker<Boolean, Void> {
|
|||
private static final String _S10 = "- card images...";
|
||||
private static final String _S11 = "There was problem during the import process.";
|
||||
private static final String _S12 = "Please see the following file for more details -";
|
||||
private static final String _S13 = "- mods...";
|
||||
|
||||
private static final String OK_STRING = String.format("%s\n", UiString.get(_S3));
|
||||
private static final String FAIL_STRING = String.format("%s\n", UiString.get(_S1));
|
||||
|
@ -63,6 +64,7 @@ public class ImportWorker extends SwingWorker<Boolean, Void> {
|
|||
if (!isCancelled()) { importPlayerProfiles(); }
|
||||
if (!isCancelled()) { importCustomDecks(); }
|
||||
if (!isCancelled()) { importAvatars(); }
|
||||
if (!isCancelled()) { importThemes(); }
|
||||
if (!isCancelled()) { importMods(); }
|
||||
if (!isCancelled()) { importCardImages(); }
|
||||
if (!isCancelled()) { updateNewCardsLog(); }
|
||||
|
@ -123,12 +125,46 @@ public class ImportWorker extends SwingWorker<Boolean, Void> {
|
|||
setProgressNote(OK_STRING);
|
||||
}
|
||||
|
||||
/**
|
||||
* If imported version does not have an existing "themes" folder then
|
||||
* copies any existing "*_theme" folders or files from "mods" to "themes".
|
||||
*/
|
||||
private void migrateModThemes() throws IOException {
|
||||
final Path targetPath = MagicFileSystem.getDataPath(MagicFileSystem.DataPath.THEMES);
|
||||
File[] modThemes = importDataPath.resolve("mods").toFile().listFiles(MagicFileSystem.THEME_FILE_FILTER);
|
||||
for (File themeFile : modThemes) {
|
||||
if (themeFile.isDirectory()) {
|
||||
FileUtils.copyDirectoryToDirectory(themeFile, targetPath.toFile());
|
||||
} else {
|
||||
FileUtils.copyFileToDirectory(themeFile, targetPath.toFile());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Merges "themes" folder and sub-folders.
|
||||
* If file already exists then imported version takes precedence.
|
||||
* (see also {@link migrateModThemes})
|
||||
*/
|
||||
private void importThemes() throws IOException {
|
||||
setProgressNote(UiString.get(_S4));
|
||||
final String directoryName = "themes";
|
||||
final Path targetPath = MagicFileSystem.getDataPath(MagicFileSystem.DataPath.THEMES);
|
||||
final Path sourcePath = importDataPath.resolve(directoryName);
|
||||
if (sourcePath.toFile().exists()) {
|
||||
FileUtils.copyDirectory(sourcePath.toFile(), targetPath.toFile());
|
||||
} else {
|
||||
migrateModThemes();
|
||||
}
|
||||
setProgressNote(OK_STRING);
|
||||
}
|
||||
|
||||
/**
|
||||
* Merges "mods" folder and sub-folders.
|
||||
* If file already exists then imported version takes precedence.
|
||||
*/
|
||||
private void importMods() throws IOException {
|
||||
setProgressNote(UiString.get(_S4));
|
||||
setProgressNote(UiString.get(_S13));
|
||||
final String directoryName = "mods";
|
||||
final Path sourcePath = importDataPath.resolve(directoryName);
|
||||
if (sourcePath.toFile().exists()) {
|
||||
|
@ -140,15 +176,17 @@ public class ImportWorker extends SwingWorker<Boolean, Void> {
|
|||
|
||||
/**
|
||||
* Creates a filter that returns everything in the "mods" folder except
|
||||
* predefined cubes which are distributed with each new release.
|
||||
* the specified cubes which are distributed with each new release and
|
||||
* any existing themes which are now found in the "themes" folder.
|
||||
*/
|
||||
private FileFilter getModsFileFilter() {
|
||||
final String[] excludedCubes = new String[]{
|
||||
"legacy_cube.txt", "modern_cube.txt", "standard_cube.txt", "extended_cube.txt", "ubeefx_cube.txt"
|
||||
};
|
||||
final IOFileFilter excludedFiles = new NameFileFilter(excludedCubes, IOCase.INSENSITIVE);
|
||||
final IOFileFilter excludeFilter = FileFilterUtils.notFileFilter(excludedFiles);
|
||||
return FileFilterUtils.or(DirectoryFileFilter.DIRECTORY, excludeFilter);
|
||||
final IOFileFilter cubesFilter = new NameFileFilter(excludedCubes, IOCase.INSENSITIVE);
|
||||
final IOFileFilter excludeCubes = FileFilterUtils.notFileFilter(cubesFilter);
|
||||
final IOFileFilter excludeThemes = FileFilterUtils.notFileFilter(new WildcardFileFilter("*_theme*"));
|
||||
return FileFilterUtils.and(excludeCubes, excludeThemes);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,28 +2,14 @@ package magic.ui.theme;
|
|||
|
||||
import java.awt.Color;
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import magic.data.GeneralConfig;
|
||||
import magic.ui.MagicImages;
|
||||
import magic.utility.MagicFileSystem;
|
||||
import magic.utility.MagicFileSystem.DataPath;
|
||||
|
||||
public class ThemeFactory {
|
||||
|
||||
private static final String THEME_ZIP = "_theme.zip";
|
||||
private static final String THEME_FOLDER = "_theme";
|
||||
|
||||
// Must be before instance!
|
||||
private static final FileFilter THEME_FILE_FILTER = new FileFilter() {
|
||||
@Override
|
||||
public boolean accept(final File file) {
|
||||
return (file.isFile() && file.getName().endsWith(THEME_ZIP)) ||
|
||||
(file.isDirectory() && file.getName().endsWith(THEME_FOLDER));
|
||||
}
|
||||
};
|
||||
|
||||
private static final ThemeFactory INSTANCE = new ThemeFactory();
|
||||
|
||||
private final List<Theme> themes = new ArrayList<>();
|
||||
|
@ -41,13 +27,13 @@ public class ThemeFactory {
|
|||
}
|
||||
|
||||
private void loadCustomExternalThemes() {
|
||||
final File[] files = MagicFileSystem.getDataPath(DataPath.MODS).toFile().listFiles(THEME_FILE_FILTER);
|
||||
final File[] files = MagicFileSystem.getThemes();
|
||||
if (files != null) {
|
||||
for (final File file : files) {
|
||||
final String name = file.getName();
|
||||
int index = name.indexOf(THEME_ZIP);
|
||||
int index = name.indexOf(MagicFileSystem.THEME_ZIP);
|
||||
if (index < 0) {
|
||||
index = name.indexOf(THEME_FOLDER);
|
||||
index = name.indexOf(MagicFileSystem.THEME_FOLDER);
|
||||
}
|
||||
themes.add(new CustomTheme(file, name.substring(0, index)));
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package magic.utility;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FilenameFilter;
|
||||
|
@ -83,7 +84,8 @@ public final class MagicFileSystem {
|
|||
SAVED_GAMES("saved_games"),
|
||||
TRANSLATIONS("translations"),
|
||||
IMAGES("images"),
|
||||
REPORTS("reports")
|
||||
REPORTS("reports"),
|
||||
THEMES("themes")
|
||||
;
|
||||
|
||||
private final Path directoryPath;
|
||||
|
@ -99,6 +101,13 @@ public final class MagicFileSystem {
|
|||
|
||||
}
|
||||
|
||||
// for identifying themes in "themes" folder.
|
||||
public static final String THEME_ZIP = "_theme.zip";
|
||||
public static final String THEME_FOLDER = "_theme";
|
||||
public static final FileFilter THEME_FILE_FILTER = (final File file) ->
|
||||
(file.isFile() && file.getName().endsWith(THEME_ZIP)) ||
|
||||
(file.isDirectory() && file.getName().endsWith(THEME_FOLDER));
|
||||
|
||||
/**
|
||||
* Returns the main data directory.
|
||||
* <p>
|
||||
|
@ -299,4 +308,8 @@ public final class MagicFileSystem {
|
|||
return true;
|
||||
}
|
||||
|
||||
public static File[] getThemes() {
|
||||
return getDataPath(DataPath.THEMES).toFile().listFiles(THEME_FILE_FILTER);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue