From 16ece5364c4b170019a7effdcd8c0d889aa73d63 Mon Sep 17 00:00:00 2001 From: benfry Date: Fri, 20 May 2005 04:47:21 +0000 Subject: [PATCH] fixing bugs with non-ascii folders on windows --- app/Base.java | 29 +++++++++++++++++++++++++---- app/Preferences.java | 2 +- build/shared/lib/preferences.txt | 4 ++++ 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/app/Base.java b/app/Base.java index 606c32005..8d8fe9031 100644 --- a/app/Base.java +++ b/app/Base.java @@ -178,7 +178,7 @@ public class Base { static final short kUserDomain = -32763; - static public File getProcessingDataFolder() { + static public File getSettingsFolder() { File dataFolder = null; String pref = Preferences.get("settings.path"); @@ -296,18 +296,39 @@ public class Base { } - static public File getProcessingDataFile(String filename) { - return new File(getProcessingDataFolder(), filename); + static public File getSettingsFile(String filename) { + return new File(getSettingsFolder(), filename); } static public File getBuildFolder() { - File folder = new File(getProcessingDataFolder(), "build"); + String buildPath = Preferences.get("build.path"); + if (buildPath != null) return new File(buildPath); + + File folder = new File(getTempFolder(), "build"); if (!folder.exists()) folder.mkdirs(); return folder; } + /** + * Get the path to the platform's temporary folder, by creating + * a temporary temporary file and getting its parent folder. + */ + static public File getTempFolder() { + try { + File ignored = File.createTempFile("ignored", null); + String tempPath = ignored.getParent(); + ignored.delete(); + return new File(tempPath); + + } catch (Exception e) { + e.printStackTrace(); + } + return null; // TODO could we *really* ever reach this? + } + + /* static public void addBuildFolderToClassPath() { String path = getBuildFolder().getAbsolutePath(); diff --git a/app/Preferences.java b/app/Preferences.java index eb3340ac9..65a5e79be 100644 --- a/app/Preferences.java +++ b/app/Preferences.java @@ -154,7 +154,7 @@ public class Preferences extends JComponent { //File home = new File(System.getProperty("user.home")); //File processingHome = new File(home, "Processing"); //preferencesFile = new File(home, PREFS_FILE); - preferencesFile = Base.getProcessingDataFile(PREFS_FILE); + preferencesFile = Base.getSettingsFile(PREFS_FILE); if (!preferencesFile.exists()) { // create a new preferences file if none exists diff --git a/build/shared/lib/preferences.txt b/build/shared/lib/preferences.txt index c87a7aa2c..205e4e057 100755 --- a/build/shared/lib/preferences.txt +++ b/build/shared/lib/preferences.txt @@ -40,6 +40,10 @@ sketchbook.path.fallback=sketchbook #settings.path=data settings.path.fallback=data +# temporary build path, normally this goes into the default +# "temp" folder for that platform (as defined by java) +# but this can be used to set a specific file in case of problems +#build.path=build # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!