Fixed regressions

This commit is contained in:
Stef Tervelde
2024-12-14 09:34:54 +01:00
parent adf88f6c51
commit 1b09894f7a
6 changed files with 162 additions and 20 deletions

View File

@@ -17,8 +17,8 @@ repositories{
sourceSets{
main{
java{
srcDirs("../src/", "../generated")
include("processing/mode/java/preproc/**/*")
srcDirs("src/main/java", "../src/", "../generated")
include("processing/mode/java/preproc/**/*", "processing/app/**/*")
}
}
}

View File

@@ -0,0 +1,55 @@
package processing.app;
import java.io.File;
public class Base {
static private final int REVISION = 1294;
static private File settingsOverride;
/**
* @return the current revision number, safe to be used for update checks
*/
static public int getRevision() {
return REVISION;
}
/**
* Get the directory that can store settings. (Library on OS X, App Data or
* something similar on Windows, a dot folder on Linux.) Removed this as a
* preference for 3.0a3 because we need this to be stable, but adding back
* for 4.0 beta 4 so that folks can do 'portable' versions again.
*/
static public File getSettingsFolder() {
File settingsFolder = null;
try {
settingsFolder = Platform.getSettingsFolder();
// create the folder if it doesn't exist already
if (!settingsFolder.exists()) {
if (!settingsFolder.mkdirs()) {
System.err.println("Could not create the folder " + settingsFolder);
}
}
} catch (Exception e) {
System.err.println("Could not get the settings folder");
}
return settingsFolder;
}
static public File getSettingsOverride() {
return settingsOverride;
}
/**
* Convenience method to get a File object for the specified filename inside
* the settings folder. Used to get preferences and recent sketch files.
* @param filename A file inside the settings folder.
* @return filename wrapped as a File object inside the settings folder
*/
static public File getSettingsFile(String filename) {
return new File(getSettingsFolder(), filename);
}
}

View File

@@ -0,0 +1,22 @@
package processing.app;
import java.io.File;
public class Platform {
static public File getSettingsFolder() {
File settingsFolder = null;
String os = System.getProperty("os.name").toLowerCase();
if (os.contains("mac")) {
settingsFolder = new File(System.getProperty("user.home") + "/Library/Processing");
} else if (os.contains("windows")) {
String appData = System.getenv("APPDATA");
if (appData == null) {
appData = System.getProperty("user.home");
}
settingsFolder = new File(appData + "\\Processing");
} else {
settingsFolder = new File(System.getProperty("user.home") + "/.processing");
}
return settingsFolder;
}
}

View File

@@ -0,0 +1,64 @@
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
Part of the Processing project - http://processing.org
Copyright (c) 2014-19 The Processing Foundation
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2
as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package processing.app;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.Properties;
/**
* Storage class for user preferences and environment settings.
* <P>
* This class does not use the Properties class because .properties files use
* ISO 8859-1 encoding, which is highly likely to be a problem when trying to
* save sketch folders and locations. Like the rest of Processing, we use UTF8.
* <p>
* We don't use the Java Preferences API because it would entail writing to
* the registry (on Windows), or an obscure file location (on Mac OS X) and
* make it far more difficult (impossible) to remove the preferences.txt to
* reset them (when they become corrupt), or to find the the file to make
* edits for numerous obscure preferences that are not part of the preferences
* window. If we added a generic editor (e.g. about:config in Mozilla) for
* such things, we could start using the Java Preferences API. But wow, that
* sounds like a lot of work. Not unlike writing this paragraph.
*/
public class Preferences {
static public String get(String attribute /*, String defaultValue */) {
try {
var settingsFile = Base.getSettingsFile("preferences.txt");
var reader = new BufferedReader(new FileReader(settingsFile));
var settings = new Properties();
settings.load(reader);
reader.close();
return settings.getProperty(attribute);
}catch (Exception e) {
return null;
}
}
static public boolean getBoolean(String attribute) {
String value = get(attribute); //, null);
return Boolean.parseBoolean(value);
}
}