From db52973f973e5b3f8f1b25b009964102f3e292e8 Mon Sep 17 00:00:00 2001 From: Doublestrike Date: Mon, 21 May 2012 12:19:43 +0000 Subject: [PATCH] Consolidated preference files and main.properties under res/preferences/. Updated methods to make change smoothly without losing old preferences. --- .gitattributes | 2 + .gitignore | 1 + forge.properties | 2 +- res/preferences/editor.preferences | 32 +++++++++ res/preferences/main.properties | 69 +++++++++++++++++++ .../java/forge/gui/deckeditor/SEditorIO.java | 27 +++++++- .../forge/properties/ForgePreferences.java | 29 +++++++- .../java/forge/properties/ForgeProps.java | 2 +- .../java/forge/properties/NewConstants.java | 10 +-- 9 files changed, 164 insertions(+), 10 deletions(-) create mode 100644 res/preferences/editor.preferences create mode 100644 res/preferences/main.properties diff --git a/.gitattributes b/.gitattributes index af89608b1fc..980f4c760d0 100644 --- a/.gitattributes +++ b/.gitattributes @@ -11067,6 +11067,8 @@ res/pics_product/tournamentpacks/SHM.jpg -text res/pics_product/tournamentpacks/TMP.jpg -text res/pics_product/tournamentpacks/TSP.jpg -text res/pics_product/tournamentpacks/USG.jpg -text +res/preferences/editor.preferences -text +res/preferences/main.properties -text res/product-images.txt -text res/quest/all-prices.txt svneol=native#text/plain res/quest/bazaar/ape_pet_l1.txt -text diff --git a/.gitignore b/.gitignore index c348b8c8e8d..48847faaeed 100644 --- a/.gitignore +++ b/.gitignore @@ -358,6 +358,7 @@ res/pics/booster res/pics/icons res/pics/tokens/*.jpg res/pics_product/*.jpg +res/preferences/forge.preferences res/quest/data res/quest/quest.preferences res/quest/questData.dat diff --git a/forge.properties b/forge.properties index 27f98ca1aab..e6f0c145c8c 100644 --- a/forge.properties +++ b/forge.properties @@ -43,4 +43,4 @@ # this link includes the main properties file. you can move/rename etc. the res-folder. you just have to change # this single line -main--transparent-properties=res/main.properties \ No newline at end of file +main--transparent-properties=res/preferences/main.properties diff --git a/res/preferences/editor.preferences b/res/preferences/editor.preferences new file mode 100644 index 00000000000..e205c2da6de --- /dev/null +++ b/res/preferences/editor.preferences @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/res/preferences/main.properties b/res/preferences/main.properties new file mode 100644 index 00000000000..0d6c7b62185 --- /dev/null +++ b/res/preferences/main.properties @@ -0,0 +1,69 @@ +program/howToReportBugsURL=http://tinyurl.com/3zzrnyb +program/cardforgeURL=http://cardforge.org + +showdeck/2color=false +showdeck/3color=false +showdeck/4color=false +showdeck/5color=false + +tokens--file=AllTokens.txt +mtg-data--file=mtg-data.txt + +decks--file=all-decks2 +booster-decks--file=booster-deck +decks-dir--file=../decks + +card-pictures--file=card-pictures.txt +token-images--file=token-images.txt +card-pictures_a--file=../pics_link/card-pictures_a.txt +card-pictures_b--file=../pics_link/card-pictures_b.txt +card-pictures_c--file=../pics_link/card-pictures_c.txt +card-pictures_d--file=../pics_link/card-pictures_d.txt +card-pictures_e--file=../pics_link/card-pictures_e.txt +card-pictures_f--file=../pics_link/card-pictures_f.txt +card-pictures_g--file=../pics_link/card-pictures_g.txt +card-pictures_h--file=../pics_link/card-pictures_h.txt +card-pictures_i--file=../pics_link/card-pictures_i.txt +card-pictures_j--file=../pics_link/card-pictures_j.txt +card-pictures_k--file=../pics_link/card-pictures_k.txt +card-pictures_l--file=../pics_link/card-pictures_l.txt +card-pictures_m--file=../pics_link/card-pictures_m.txt +card-pictures_n--file=../pics_link/card-pictures_n.txt +card-pictures_o--file=../pics_link/card-pictures_o.txt +card-pictures_p--file=../pics_link/card-pictures_p.txt +card-pictures_q--file=../pics_link/card-pictures_q.txt +card-pictures_r--file=../pics_link/card-pictures_r.txt +card-pictures_s--file=../pics_link/card-pictures_s.txt +card-pictures_t--file=../pics_link/card-pictures_t.txt +card-pictures_u--file=../pics_link/card-pictures_u.txt +card-pictures_v--file=../pics_link/card-pictures_v.txt +card-pictures_w--file=../pics_link/card-pictures_w.txt +card-pictures_x--file=../pics_link/card-pictures_x.txt +card-pictures_y--file=../pics_link/card-pictures_y.txt +card-pictures_z--file=../pics_link/card-pictures_z.txt +card-pictures_other--file=../pics_link/card-pictures_other.txt +card-pictures_token_hq--file=../pics_link/card-pictures_token.txt +cards--file=cards.txt +cardsfolder--file=../cardsfolder +removed-cards--file=removedCards.txt + +regular/common--file=common.txt +regular/uncommon--file=uncommon.txt +regular/rare--file=rare.txt + +name-mutator--file=name-mutator.txt + +quest--properties=../quest/quest.properties +draft--properties=../draft/draft.properties + +lang--transparent-properties=../lang/lang.properties + +image/base--file=../pics +image/token--file=../pics/tokens +image/icon--file=../pics/icons +image/product--file=../pics_product +pics/booster/images--file=../quest/booster-images.txt + +quest/opponent/icons--file=../quest/quest-opponent-icons.txt +quest/pet/icons--file=../quest/quest-pet-shop-icons.txt +quest/pet/tokens--file=../quest/quest-pet-token-images.txt diff --git a/src/main/java/forge/gui/deckeditor/SEditorIO.java b/src/main/java/forge/gui/deckeditor/SEditorIO.java index 568556cc2cf..9037d0103c3 100644 --- a/src/main/java/forge/gui/deckeditor/SEditorIO.java +++ b/src/main/java/forge/gui/deckeditor/SEditorIO.java @@ -1,7 +1,10 @@ package forge.gui.deckeditor; +import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; +import java.io.InputStream; +import java.io.OutputStream; import java.util.HashMap; import java.util.Iterator; import java.util.Map; @@ -179,7 +182,7 @@ public class SEditorIO { */ private static void save() throws Exception { final XMLOutputFactory out = XMLOutputFactory.newInstance(); - final XMLEventWriter writer = out.createXMLEventWriter(new FileOutputStream(NewConstants.PREFERENCES_FILE_EDITOR)); + final XMLEventWriter writer = out.createXMLEventWriter(new FileOutputStream(NewConstants.PREFS_EDITOR_FILE)); writer.add(EVENT_FACTORY.createStartDocument()); writer.add(NEWLINE); @@ -232,8 +235,28 @@ public class SEditorIO { } private static void load() throws Exception { + // Preferences files have been consolidated into res/preferences/. + // This code is here temporarily to facilitate this transfer. + // After a while, this can be deleted. Doublestrike 21-5-12 + final File oldFile = new File("editor.preferences"); + if (oldFile.exists()) { + final File newFile = new File(NewConstants.PREFS_EDITOR_FILE); + final InputStream in = new FileInputStream(oldFile); + final OutputStream out = new FileOutputStream(newFile); + + byte[] buf = new byte[1024]; + int len; + while ((len = in.read(buf)) > 0) { + out.write(buf, 0, len); + } + in.close(); + out.close(); + + oldFile.delete(); + } // END TEMPORARY CONSOLIDATION FACILITATION + final XMLInputFactory inputFactory = XMLInputFactory.newInstance(); - final String fileAddress = NewConstants.PREFERENCES_FILE_EDITOR; + final String fileAddress = NewConstants.PREFS_EDITOR_FILE; final XMLEventReader reader = inputFactory.createXMLEventReader(new FileInputStream(fileAddress)); PREFS.clear(); diff --git a/src/main/java/forge/properties/ForgePreferences.java b/src/main/java/forge/properties/ForgePreferences.java index 17f2f1fc67c..4b7fe5a247c 100644 --- a/src/main/java/forge/properties/ForgePreferences.java +++ b/src/main/java/forge/properties/ForgePreferences.java @@ -19,10 +19,15 @@ package forge.properties; import java.io.BufferedReader; import java.io.BufferedWriter; +import java.io.File; +import java.io.FileInputStream; import java.io.FileNotFoundException; +import java.io.FileOutputStream; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import java.util.HashMap; import java.util.Map; @@ -145,7 +150,27 @@ public class ForgePreferences { public ForgePreferences() { preferenceValues = new HashMap(); try { - final BufferedReader input = new BufferedReader(new FileReader(NewConstants.PREFERENCE_FILE)); + // Preferences files have been consolidated into res/prefs/. + // This code is here temporarily to facilitate this transfer. + // After a while, this can be deleted. Doublestrike 21-5-12 + final File oldFile = new File("forge.preferences"); + if (oldFile.exists()) { + final File newFile = new File(NewConstants.PREFS_GLOBAL_FILE); + final InputStream in = new FileInputStream(oldFile); + final OutputStream out = new FileOutputStream(newFile); + + byte[] buf = new byte[1024]; + int len; + while ((len = in.read(buf)) > 0) { + out.write(buf, 0, len); + } + in.close(); + out.close(); + + oldFile.delete(); + } // END TEMPORARY CONSOLIDATION FACILITATION + + final BufferedReader input = new BufferedReader(new FileReader(NewConstants.PREFS_GLOBAL_FILE)); String line = null; while ((line = input.readLine()) != null) { if (line.startsWith("#") || (line.length() == 0)) { @@ -170,7 +195,7 @@ public class ForgePreferences { BufferedWriter writer = null; try { - writer = new BufferedWriter(new FileWriter(NewConstants.PREFERENCE_FILE)); + writer = new BufferedWriter(new FileWriter(NewConstants.PREFS_GLOBAL_FILE)); for (FPref key : FPref.values()) { writer.write(key + "=" + getPref(key)); writer.newLine(); diff --git a/src/main/java/forge/properties/ForgeProps.java b/src/main/java/forge/properties/ForgeProps.java index b721151bd32..2151d9151a1 100644 --- a/src/main/java/forge/properties/ForgeProps.java +++ b/src/main/java/forge/properties/ForgeProps.java @@ -44,7 +44,7 @@ public class ForgeProps { static { TreeProperties p; try { - p = new TreeProperties("forge.properties"); + p = new TreeProperties(NewConstants.PREFS_MAIN_PROPERTIES_FILE); p.rethrow(); } catch (final IOException ex) { ErrorViewer.showError(ex); diff --git a/src/main/java/forge/properties/NewConstants.java b/src/main/java/forge/properties/NewConstants.java index b0f09dfa2b4..54c7d184765 100644 --- a/src/main/java/forge/properties/NewConstants.java +++ b/src/main/java/forge/properties/NewConstants.java @@ -43,10 +43,12 @@ public final class NewConstants { /** Constant CARDFORGE_URL = "program/cardforgeURL". */ public static final String CARDFORGE_URL = "program/cardforgeURL"; - /** Constant PREFERENCE_FILE = "forge.preferences". */ - public static final String PREFERENCE_FILE = "forge.preferences"; - /** Constant PREFERENCE_FILE = "forge.preferences". */ - public static final String PREFERENCES_FILE_EDITOR = "editor.preferences"; + /** Constant PREFS_GLOBAL_FILE = "forge.preferences". */ + public static final String PREFS_GLOBAL_FILE = "res/preferences/forge.preferences"; + /** Constant PREFS_GLOBAL_FILE = "editor.preferences". */ + public static final String PREFS_EDITOR_FILE = "res/preferences/editor.preferences"; + /** */ + public static final String PREFS_MAIN_PROPERTIES_FILE = "res/preferences/main.properties"; /** Constant LAYOUT_DIR = "res/layouts/". */ public static final String LAYOUT_DIR = "res/layouts/";