mirror of
https://github.com/AppleCommander/AppleCommander.git
synced 2026-11-22 18:25:20 +00:00
Merge pull request #351 from AppleCommander/feature/filestore-creation-options
Adding configuration options for file store creation. This change als…
This commit is contained in:
16 files changed
+400
-74
No files matched your search
+95
-27
@@ -25,22 +25,26 @@ import javafx.beans.property.SimpleObjectProperty;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.RadioButton;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.layout.GridPane;
|
||||
import javafx.scene.layout.Pane;
|
||||
import org.applecommander.filestore.FileStore;
|
||||
import org.applecommander.filestore.FileStoreFactory;
|
||||
import org.applecommander.filestore.FileStoreOrganization;
|
||||
import org.applecommander.filestore.FileStores;
|
||||
import javafx.scene.layout.VBox;
|
||||
import org.applecommander.filestore.*;
|
||||
import org.applecommander.javafx.FXControls;
|
||||
import org.applecommander.javafx.filter.CharacterRestrictionFilter;
|
||||
import org.applecommander.javafx.filter.CompositeFilter;
|
||||
import org.applecommander.javafx.filter.FixedLengthFilter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.UnaryOperator;
|
||||
|
||||
public class CreateFileStoreWizard extends WizardDialog<CreateFileStoreWizard.WizardPage> {
|
||||
private final ObjectProperty<FileStoreFactory> fileStoreFactoryProperty = new SimpleObjectProperty<>();
|
||||
private final ObjectProperty<FileStoreOrganization> fileStoreOrganizationProperty = new SimpleObjectProperty<>();
|
||||
private Map<String,ConfigurationOption> configurationOptions = Collections.emptyMap();
|
||||
|
||||
public CreateFileStoreWizard() {
|
||||
super();
|
||||
@@ -50,7 +54,7 @@ public class CreateFileStoreWizard extends WizardDialog<CreateFileStoreWizard.Wi
|
||||
public List<FileStore> getFileStores() {
|
||||
FileStoreFactory factory = fileStoreFactoryProperty.get();
|
||||
FileStoreOrganization organization = fileStoreOrganizationProperty.get();
|
||||
return List.of(factory.create(organization));
|
||||
return List.of(factory.create(organization, configurationOptions));
|
||||
}
|
||||
|
||||
public BooleanBinding createNextPageBinding() {
|
||||
@@ -76,6 +80,7 @@ public class CreateFileStoreWizard extends WizardDialog<CreateFileStoreWizard.Wi
|
||||
.label("Choose an image type to create:")
|
||||
.radioButton(factories, FileStoreFactory::getName, fileStoreFactoryProperty)
|
||||
.get(),
|
||||
WizardPage.OPTIONS, new VBox(),
|
||||
WizardPage.ORGANIZATION, FXControls.vertical()
|
||||
.label("Choose the image organization:")
|
||||
.radioButton(FileStoreOrganization.values(), FileStoreOrganization::getDescription,
|
||||
@@ -126,32 +131,95 @@ public class CreateFileStoreWizard extends WizardDialog<CreateFileStoreWizard.Wi
|
||||
}
|
||||
|
||||
public WizardPage nextPage() {
|
||||
return switch (currentPageProperty().get()) {
|
||||
case FILESTORE -> {
|
||||
FileStoreFactory factory = fileStoreFactoryProperty.get();
|
||||
if (factory.getFileStoreOrganizations().size() == 1) {
|
||||
yield WizardPage.SUMMARY;
|
||||
}
|
||||
// Set up the organization window
|
||||
Pane pane = getWizardPage(WizardPage.ORGANIZATION);
|
||||
for (Node node : pane.getChildren()) {
|
||||
if (node instanceof RadioButton radio) {
|
||||
if (radio.getUserData() instanceof FileStoreOrganization organization) {
|
||||
boolean found = factory.getFileStoreOrganizations().contains(organization);
|
||||
radio.setVisible(found);
|
||||
radio.setManaged(found);
|
||||
}
|
||||
}
|
||||
}
|
||||
yield WizardPage.ORGANIZATION;
|
||||
}
|
||||
// Simple path
|
||||
WizardPage nextPage = switch (currentPageProperty().get()) {
|
||||
case FILESTORE -> WizardPage.OPTIONS;
|
||||
case OPTIONS -> WizardPage.ORGANIZATION;
|
||||
case ORGANIZATION -> WizardPage.SUMMARY;
|
||||
case SUMMARY -> null;
|
||||
};
|
||||
// Now check reality!
|
||||
FileStoreFactory factory = fileStoreFactoryProperty.get();
|
||||
if (nextPage == WizardPage.OPTIONS) {
|
||||
if (factory.getConfigurationOptions().isEmpty()) {
|
||||
nextPage = WizardPage.ORGANIZATION;
|
||||
}
|
||||
else {
|
||||
setupCustomOptionsPage();
|
||||
}
|
||||
}
|
||||
if (nextPage == WizardPage.ORGANIZATION) {
|
||||
if (factory.getFileStoreOrganizations().size() == 1) {
|
||||
nextPage = WizardPage.SUMMARY;
|
||||
}
|
||||
else {
|
||||
setupOrganizationPage();
|
||||
}
|
||||
}
|
||||
return nextPage;
|
||||
}
|
||||
|
||||
/// Dynamically set up the (custom) options page. Note that we "specially" put a VBox place-holder
|
||||
/// into the Wizard itself. We just reuse that VBox, but repopulate it each traversal.
|
||||
public void setupCustomOptionsPage() {
|
||||
FileStoreFactory factory = fileStoreFactoryProperty.get();
|
||||
VBox vbox = (VBox) getWizardPage(WizardPage.OPTIONS);
|
||||
vbox.getChildren().clear();
|
||||
vbox.setSpacing(10);
|
||||
vbox.setPadding(new Insets(10));
|
||||
// Note that we must be careful and use the same copy since the configuration options contain the values as well.
|
||||
configurationOptions = factory.getConfigurationOptions();
|
||||
for (ConfigurationOption option : configurationOptions.values()) {
|
||||
Label label = new Label();
|
||||
label.setText(option.getPrompt() + ":");
|
||||
TextInputControl field = null;
|
||||
if (option.getMaxLength() > 50) {
|
||||
field = new TextArea(option.getValue());
|
||||
} else {
|
||||
field = new TextField(option.getValue());
|
||||
}
|
||||
List<UnaryOperator<TextFormatter.Change>> filters = new ArrayList<>();
|
||||
if (option.getMaxLength() > 0) {
|
||||
filters.add(new FixedLengthFilter(option.getMaxLength()));
|
||||
}
|
||||
if (option.getCharacterRestrictions() != null) {
|
||||
filters.add(new CharacterRestrictionFilter(option.getCharacterRestrictions()));
|
||||
}
|
||||
field.setTextFormatter(new TextFormatter<>(new CompositeFilter(filters)));
|
||||
final TextInputControl textInputControl = field;
|
||||
field.textProperty().addListener((_, _, newText) -> {
|
||||
if (!option.getValidatorFn().test(newText)) {
|
||||
textInputControl.setStyle("-fx-border-color: red;");
|
||||
}
|
||||
else {
|
||||
textInputControl.setStyle("");
|
||||
option.setValue(newText);
|
||||
}
|
||||
});
|
||||
if (option.getNotes() != null && !option.getNotes().isEmpty()) {
|
||||
field.setTooltip(new Tooltip(option.getNotes()));
|
||||
}
|
||||
vbox.getChildren().addAll(label, field);
|
||||
}
|
||||
}
|
||||
|
||||
/// Configure the organization page to only show those that apply.
|
||||
public void setupOrganizationPage() {
|
||||
FileStoreFactory factory = fileStoreFactoryProperty.get();
|
||||
Pane pane = getWizardPage(WizardPage.ORGANIZATION);
|
||||
for (Node node : pane.getChildren()) {
|
||||
if (node instanceof RadioButton radio) {
|
||||
if (radio.getUserData() instanceof FileStoreOrganization organization) {
|
||||
boolean found = factory.getFileStoreOrganizations().contains(organization);
|
||||
radio.setVisible(found);
|
||||
radio.setManaged(found);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// All possible pages in the new file store wizard.
|
||||
public enum WizardPage {
|
||||
FILESTORE, ORGANIZATION, SUMMARY
|
||||
FILESTORE, OPTIONS, ORGANIZATION, SUMMARY
|
||||
}
|
||||
}
|
||||
@@ -19,12 +19,14 @@
|
||||
*/
|
||||
package org.applecommander.archive.zip;
|
||||
|
||||
import org.applecommander.filestore.ConfigurationOption;
|
||||
import org.applecommander.filestore.FileStoreFactory;
|
||||
import org.applecommander.filestore.FileStoreOrganization;
|
||||
import org.applecommander.source.Source;
|
||||
import org.applecommander.util.DataBuffer;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ZipFileStoreFactory implements FileStoreFactory {
|
||||
public static final int ZIP_SIGNATURE = 0x504b0304; // "PK.."
|
||||
@@ -49,7 +51,7 @@ public class ZipFileStoreFactory implements FileStoreFactory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZipFileStore create(FileStoreOrganization fileStoreOrganization) {
|
||||
public ZipFileStore create(FileStoreOrganization fileStoreOrganization, Map<String, ConfigurationOption> options) {
|
||||
Source source = fileStoreOrganization.createSource("zip");
|
||||
return new ZipFileStore(source);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,161 @@
|
||||
/*
|
||||
* AppleCommander - An Apple ][ image utility.
|
||||
* Copyright (C) 2026 by Robert Greene and others
|
||||
* robgreene at users.sourceforge.net
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* 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 org.applecommander.filestore;
|
||||
|
||||
import org.applecommander.ui.CharacterMapper;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
/// Represents a single configuration option for file store creation. The intent is that this
|
||||
/// class represents how the field is configured as well as the value.
|
||||
public class ConfigurationOption {
|
||||
private final CharacterMapper characterRestrictions;
|
||||
private final Predicate<String> validatorFn;
|
||||
private final int minLength;
|
||||
private final int maxLength;
|
||||
private final String prompt;
|
||||
private final String notes;
|
||||
private String value;
|
||||
|
||||
ConfigurationOption(CharacterMapper characterRestrictions, Predicate<String> validatorFn,
|
||||
int minLength, int maxLength, String prompt, String notes, String defaultValue) {
|
||||
this.characterRestrictions = characterRestrictions;
|
||||
this.validatorFn = validatorFn;
|
||||
this.minLength = minLength;
|
||||
this.maxLength = maxLength;
|
||||
this.prompt = prompt;
|
||||
this.notes = notes;
|
||||
this.value = defaultValue;
|
||||
}
|
||||
|
||||
public CharacterMapper getCharacterRestrictions() {
|
||||
return characterRestrictions;
|
||||
}
|
||||
public Predicate<String> getValidatorFn() {
|
||||
return validatorFn;
|
||||
}
|
||||
public int getMinLength() {
|
||||
return minLength;
|
||||
}
|
||||
public int getMaxLength() {
|
||||
return maxLength;
|
||||
}
|
||||
public String getPrompt() {
|
||||
return prompt;
|
||||
}
|
||||
public String getNotes() {
|
||||
return notes;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
public void setValue(String value) {
|
||||
value = characterRestrictions.map(value);
|
||||
if (!validatorFn.test(value)) {
|
||||
throw new RuntimeException("field failed validation");
|
||||
}
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/// Extract the given option value with optional default.
|
||||
public static String getValidatedValue(Map<String,ConfigurationOption> options, String key, String defaultValue) {
|
||||
if (options.containsKey(key)) {
|
||||
return options.get(key).getValue();
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private Map<String,ConfigurationOption> options = new HashMap<>();
|
||||
|
||||
private Builder() {
|
||||
}
|
||||
|
||||
public OptionBuilder next(String id) {
|
||||
return new OptionBuilder(this, id);
|
||||
}
|
||||
public Map<String,ConfigurationOption> done() {
|
||||
return Collections.unmodifiableMap(options);
|
||||
}
|
||||
}
|
||||
public static class OptionBuilder {
|
||||
private final Builder parent;
|
||||
private final String id;
|
||||
private CharacterMapper characterRestrictions = CharacterMapper.ANYTHING;
|
||||
private Predicate<String> validatorFn;
|
||||
private int minLength = 1;
|
||||
private int maxLength = -1;
|
||||
private String prompt;
|
||||
private String notes;
|
||||
private String defaultValue;
|
||||
|
||||
private OptionBuilder(Builder parent, String id) {
|
||||
Objects.requireNonNull(id);
|
||||
this.parent = parent;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public OptionBuilder enforceLength(int minLength, int maxLength) {
|
||||
assert minLength > 0 && (maxLength == -1 || maxLength >= minLength);
|
||||
this.minLength = minLength;
|
||||
this.maxLength = maxLength;
|
||||
return this;
|
||||
}
|
||||
public OptionBuilder restrictions(CharacterMapper characterRestrictions) {
|
||||
Objects.requireNonNull(characterRestrictions);
|
||||
this.characterRestrictions = characterRestrictions;
|
||||
return this;
|
||||
}
|
||||
public OptionBuilder prompt(String prompt) {
|
||||
Objects.requireNonNull(prompt);
|
||||
this.prompt = prompt;
|
||||
return this;
|
||||
}
|
||||
public OptionBuilder notes(String notes) {
|
||||
Objects.requireNonNull(notes);
|
||||
this.notes = notes;
|
||||
return this;
|
||||
}
|
||||
public OptionBuilder defaultValue(String defaultValue) {
|
||||
Objects.requireNonNull(defaultValue);
|
||||
this.defaultValue = defaultValue;
|
||||
return this;
|
||||
}
|
||||
public Builder add() {
|
||||
if (validatorFn == null) {
|
||||
validatorFn = Objects::nonNull;
|
||||
if (minLength > 0) validatorFn = validatorFn.and(s -> s.length() >= minLength);
|
||||
if (maxLength != -1) validatorFn = validatorFn.and(s -> s.length() <= maxLength);
|
||||
}
|
||||
parent.options.put(id, new ConfigurationOption(characterRestrictions, validatorFn, minLength, maxLength,
|
||||
prompt, notes, defaultValue));
|
||||
return parent;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,10 +27,7 @@ import org.applecommander.image.NibbleImage;
|
||||
import org.applecommander.image.WozImage;
|
||||
import org.applecommander.source.Source;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/// The FileStoreFactory inspects a given Source to see if it matches any known file store(s).
|
||||
@@ -64,7 +61,10 @@ public interface FileStoreFactory {
|
||||
default List<FileStoreOrganization> getFileStoreOrganizations() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
default FileStore create(FileStoreOrganization fileStoreOrganization) {
|
||||
default Map<String,ConfigurationOption> getConfigurationOptions() {
|
||||
return Map.of();
|
||||
}
|
||||
default FileStore create(FileStoreOrganization fileStoreOrganization, Map<String,ConfigurationOption> options) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ package org.applecommander.os.gamedos;
|
||||
|
||||
import org.applecommander.device.SectorOrder;
|
||||
import org.applecommander.device.TrackSectorDevice;
|
||||
import org.applecommander.filestore.ConfigurationOption;
|
||||
import org.applecommander.filestore.FileStoreFactory;
|
||||
import org.applecommander.filestore.FileStoreOrganization;
|
||||
import org.applecommander.util.DataBuffer;
|
||||
@@ -29,6 +30,7 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
@@ -61,7 +63,7 @@ public class GamedosFileStoreFactory implements FileStoreFactory,GamedosConstant
|
||||
}
|
||||
|
||||
@Override
|
||||
public GamedosFileStore create(FileStoreOrganization fileStoreOrganization) {
|
||||
public GamedosFileStore create(FileStoreOrganization fileStoreOrganization, Map<String,ConfigurationOption> options) {
|
||||
Objects.requireNonNull(fileStoreOrganization);
|
||||
TrackSectorDevice device = fileStoreOrganization.createTrackSectorDevice().request(SectorOrder.DOS);
|
||||
try (InputStream inputStream = GamedosFileStoreFactory.class.getResourceAsStream("/files/gamedos-track0.bin")) {
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
package org.applecommander.os.pascal;
|
||||
|
||||
import org.applecommander.capability.Capability;
|
||||
import org.applecommander.ui.CharacterMapper;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@@ -81,4 +82,23 @@ public interface PascalConstants {
|
||||
/// Pascal DATA file type maps into ProDOS PDA (Pascal Data).
|
||||
int PDA = 0x05;
|
||||
|
||||
/// Per the Apple Pascal documentation:
|
||||
///
|
||||
/// * Lower-case are translated to upper-case.
|
||||
/// * Spaces and non-printing characters are removed from the filename.
|
||||
/// * You should not include dollar sign (`$`), left square bracket (`[`),
|
||||
/// equals sign (`=`), or question mark (`?`).
|
||||
CharacterMapper FILE_NAME_MAPPER = CharacterMapper.builder()
|
||||
.mapRange(0x21, 0x7e, true, '$', '[', '=', '?')
|
||||
.build();
|
||||
|
||||
/// Per the Apple Pascal documentation: (inferred)
|
||||
///
|
||||
/// * Lower-case are translated to upper-case.
|
||||
/// * Spaces and non-printing characters are removed from the volume name.
|
||||
/// * You should not include equals sign (`=`), or dollar sign (`$`),
|
||||
/// question mark (`?`), or comma (`,`).
|
||||
CharacterMapper VOLUME_NAME_MAPPER = CharacterMapper.builder()
|
||||
.mapRange(0x21, 0x7e, true, '=', '$', '?', ',')
|
||||
.build();
|
||||
}
|
||||
@@ -26,7 +26,6 @@ import org.applecommander.filestore.FileStore;
|
||||
import org.applecommander.filestore.WritableFileEntry;
|
||||
import org.applecommander.os.SequentialAllocator;
|
||||
import org.applecommander.transfer.ProdosAttributes;
|
||||
import org.applecommander.ui.CharacterMapper;
|
||||
import org.applecommander.util.Container;
|
||||
import org.applecommander.util.DataBuffer;
|
||||
|
||||
@@ -36,16 +35,6 @@ import java.util.Optional;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class PascalFileEntry implements WritableFileEntry, PascalConstants {
|
||||
/// Per the Apple Pascal documentation:
|
||||
///
|
||||
/// * Lower-case are translated to upper-case.
|
||||
/// * Spaces and non-printing characters are removed from the filename.
|
||||
/// * You should not include dollar sign (`$`), left square bracket (`[`),
|
||||
/// equals sign (`=`), or question mark (`?`).
|
||||
public static final CharacterMapper NAME_MAPPER = CharacterMapper.builder()
|
||||
.mapRange((char)0x21, (char)0x7e, true, '$', '[', '=', '?')
|
||||
.build();
|
||||
|
||||
private final BlockDevice device;
|
||||
private final PascalDirectory parent;
|
||||
private final int offset;
|
||||
@@ -100,7 +89,7 @@ public class PascalFileEntry implements WritableFileEntry, PascalConstants {
|
||||
/// Sets the name of this file. Uses the `NAME_MAPPER` to fix characters.
|
||||
/// This method only errors if, after applying the rules, the string is empty.
|
||||
public void setName(String name) {
|
||||
String fixedName = NAME_MAPPER.map(name);
|
||||
String fixedName = FILE_NAME_MAPPER.map(name);
|
||||
if (fixedName.isEmpty()) {
|
||||
throw new IllegalArgumentException("Illegal name '" + name + "'");
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ public class PascalFileStore extends ChangeRegistry<FileStore.FileStoreChangeEve
|
||||
.left("Name").string(PascalFileEntry::getName, PascalFileEntry::setName)
|
||||
.editInLine()
|
||||
.maxLength(FILE_NAME_LENGTH)
|
||||
.characterRestriction(PascalFileEntry.NAME_MAPPER)
|
||||
.characterRestriction(PascalConstants.FILE_NAME_MAPPER)
|
||||
.done()
|
||||
.right("Offset").integer(PascalFileEntry::getOffset, "%d").mode(DisplayMode.DETAIL).done()
|
||||
.left("Type").string(PascalFileEntry::getType, PascalFileEntry::setType).mode(DisplayMode.DETAIL)
|
||||
|
||||
@@ -22,6 +22,7 @@ package org.applecommander.os.pascal;
|
||||
import com.webcodepro.applecommander.storage.DiskConstants;
|
||||
import org.applecommander.device.BlockDevice;
|
||||
import org.applecommander.device.SectorOrder;
|
||||
import org.applecommander.filestore.ConfigurationOption;
|
||||
import org.applecommander.filestore.FileStoreFactory;
|
||||
import org.applecommander.filestore.FileStoreOrganization;
|
||||
import org.applecommander.util.DataBuffer;
|
||||
@@ -30,9 +31,14 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import static org.applecommander.filestore.ConfigurationOption.getValidatedValue;
|
||||
|
||||
public class PascalFileStoreFactory implements FileStoreFactory, PascalConstants {
|
||||
public static final String VOLUME_NAME_FIELD = "volname";
|
||||
public static final String VOLUME_NAME_DEFAULT = "NEWDISK";
|
||||
public static final List<FileStoreOrganization> VALID_ORGANIZATIONS = List.of(
|
||||
FileStoreOrganization.DISK_16SECTOR_DO,
|
||||
FileStoreOrganization.DISK_16SECTOR_PO,
|
||||
@@ -67,7 +73,19 @@ public class PascalFileStoreFactory implements FileStoreFactory, PascalConstants
|
||||
}
|
||||
|
||||
@Override
|
||||
public PascalFileStore create(FileStoreOrganization fileStoreOrganization) {
|
||||
public Map<String,ConfigurationOption> getConfigurationOptions() {
|
||||
return ConfigurationOption.builder()
|
||||
.next(VOLUME_NAME_FIELD)
|
||||
.restrictions(VOLUME_NAME_MAPPER)
|
||||
.enforceLength(1, VOLUME_NAME_LENGTH)
|
||||
.prompt("Volume Name")
|
||||
.defaultValue(VOLUME_NAME_DEFAULT)
|
||||
.add()
|
||||
.done();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PascalFileStore create(FileStoreOrganization fileStoreOrganization, Map<String,ConfigurationOption> options) {
|
||||
Objects.requireNonNull(fileStoreOrganization);
|
||||
BlockDevice blockDevice = fileStoreOrganization.createBlockDevice();
|
||||
try (InputStream inputStream = PascalFileStoreFactory.class.getResourceAsStream("/files/pascal-1.3-boot.bin")) {
|
||||
@@ -75,7 +93,8 @@ public class PascalFileStoreFactory implements FileStoreFactory, PascalConstants
|
||||
byte[] bootBlocks = inputStream.readAllBytes();
|
||||
blockDevice.writeRange(0, DataBuffer.wrap(bootBlocks));
|
||||
PascalFileStore fileStore = new PascalFileStore(blockDevice);
|
||||
fileStore.getRootDirectory().initVolumeHeader("NEW.DISK");
|
||||
String volumeName = getValidatedValue(options, VOLUME_NAME_FIELD, VOLUME_NAME_DEFAULT);
|
||||
fileStore.getRootDirectory().initVolumeHeader(volumeName);
|
||||
return fileStore;
|
||||
}
|
||||
catch (IOException ex) {
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
package org.applecommander.os.rdos;
|
||||
|
||||
import org.applecommander.capability.Capability;
|
||||
import org.applecommander.ui.CharacterMapper;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@@ -34,4 +35,8 @@ public interface RDOSConstants {
|
||||
int FIRST_BLOCK_OFFSET = 0x1e;
|
||||
|
||||
Set<Capability> CAPABILITIES = Set.of(Capability.WRITE_FILES, Capability.CREATE_FILES, Capability.DELETE_FILES);
|
||||
|
||||
CharacterMapper FILE_NAME_MAPPER = CharacterMapper.builder()
|
||||
.mapRange(0x20, 0x7f, true)
|
||||
.build();
|
||||
}
|
||||
@@ -118,7 +118,8 @@ public class RDOSFileStore extends ChangeRegistry<FileStore.FileStoreChangeEvent
|
||||
.option("T", "Text")
|
||||
.done()
|
||||
.right("Blocks").integer(RDOSFileEntry::getBlocks, "%03d").done()
|
||||
.left("Name").string(RDOSFileEntry::getName, RDOSFileEntry::setName).maxLength(NAME_LENGTH).done()
|
||||
.left("Name").string(RDOSFileEntry::getName, RDOSFileEntry::setName).maxLength(NAME_LENGTH)
|
||||
.characterRestriction(FILE_NAME_MAPPER).done()
|
||||
.right("Length").integer(RDOSFileEntry::getSize, "%,d").done()
|
||||
.right("First Block").integer(RDOSFileEntry::getFirstBlock, "%03d").done()
|
||||
.right("Address").integer(RDOSFileEntry::getAddress, "$%04X", RDOSFileEntry::setAddress)
|
||||
|
||||
@@ -21,6 +21,7 @@ package org.applecommander.os.rdos;
|
||||
|
||||
import com.webcodepro.applecommander.storage.DiskConstants;
|
||||
import org.applecommander.device.*;
|
||||
import org.applecommander.filestore.ConfigurationOption;
|
||||
import org.applecommander.filestore.FileStoreFactory;
|
||||
import org.applecommander.filestore.FileStoreOrganization;
|
||||
import org.applecommander.util.DataBuffer;
|
||||
@@ -28,10 +29,9 @@ import org.applecommander.util.DataBuffer;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
import static org.applecommander.filestore.ConfigurationOption.getValidatedValue;
|
||||
|
||||
public class RDOSFileStoreFactory implements FileStoreFactory, RDOSConstants {
|
||||
/// Simple directory marker to determine sector order
|
||||
@@ -42,6 +42,18 @@ public class RDOSFileStoreFactory implements FileStoreFactory, RDOSConstants {
|
||||
FileStoreOrganization.DISK_16SECTOR_PO,
|
||||
FileStoreOrganization.DISK_16SECTOR_NIB
|
||||
);
|
||||
public static final String STARTUP_FILE_NAME_FIELD = "startup_file_name";
|
||||
public static final String STARTUP_FILE_NAME = "SYSTEMBOOT";
|
||||
public static final String STARTUP_CONTENT_FIELD = "startup_content";
|
||||
public static final String STARTUP_CONTENT_DEFAULT = """
|
||||
PR#0
|
||||
IN#0
|
||||
TEXT
|
||||
HOME
|
||||
&CAT
|
||||
PRINT
|
||||
PRINT "WELCOME TO RDOS!"
|
||||
""";
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
@@ -68,7 +80,34 @@ public class RDOSFileStoreFactory implements FileStoreFactory, RDOSConstants {
|
||||
}
|
||||
|
||||
@Override
|
||||
public RDOSFileStore create(FileStoreOrganization fileStoreOrganization) {
|
||||
public Map<String,ConfigurationOption> getConfigurationOptions() {
|
||||
return ConfigurationOption.builder()
|
||||
.next(STARTUP_FILE_NAME_FIELD)
|
||||
.restrictions(FILE_NAME_MAPPER)
|
||||
.enforceLength(1, NAME_LENGTH)
|
||||
.prompt("Startup File Name")
|
||||
.notes("""
|
||||
RDOS allows customization of the startup file. It doesn't appear that
|
||||
the type of file can be customized (always a text file) but the name
|
||||
doesn't have to be 'SYSTEMBOOT'.
|
||||
""")
|
||||
.defaultValue(STARTUP_FILE_NAME)
|
||||
.add()
|
||||
.next(STARTUP_CONTENT_FIELD)
|
||||
.enforceLength(1, 200)
|
||||
.prompt("Startup Contents")
|
||||
.notes("""
|
||||
Please enter the contents of the startup file. It appears that
|
||||
RDOS must have PR#0 and IN#0 at the beginning. Multiple lines
|
||||
are joined by a colon so the startup is a single line long.
|
||||
""")
|
||||
.defaultValue(STARTUP_CONTENT_DEFAULT)
|
||||
.add()
|
||||
.done();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RDOSFileStore create(FileStoreOrganization fileStoreOrganization, Map<String,ConfigurationOption> options) {
|
||||
Objects.requireNonNull(fileStoreOrganization);
|
||||
TrackSectorDevice device = fileStoreOrganization.createTrackSectorDevice();
|
||||
BlockDevice blockDevice = new TrackSectorToBlockAdapter(device.request(SectorOrder.PRODOS),
|
||||
@@ -79,20 +118,25 @@ public class RDOSFileStoreFactory implements FileStoreFactory, RDOSConstants {
|
||||
byte[] disk = inputStream.readAllBytes();
|
||||
blockDevice.writeRange(0, DataBuffer.wrap(disk));
|
||||
RDOSFileStore fileStore = new RDOSFileStore(blockDevice, RDOSVersionAdapter.RDOS33);
|
||||
RDOSFileEntry systemboot = fileStore.getRootDirectory().createFile("SYSTEMBOOT");
|
||||
systemboot.setType("T");
|
||||
systemboot.setAddress(0xb100);
|
||||
// FIXME: Text file has to have high bit set. (Should fit in with the text handling)
|
||||
byte[] systembootContent = """
|
||||
PR#0:IN#0:TEXT:HOME:&CAT:PRINT:PRINT "WELCOME TO RDOS!"
|
||||
""".getBytes();
|
||||
String startupName = getValidatedValue(options, STARTUP_FILE_NAME_FIELD, STARTUP_FILE_NAME);
|
||||
RDOSFileEntry startup = fileStore.getRootDirectory().createFile(startupName);
|
||||
startup.setType("T");
|
||||
startup.setAddress(0xb100);
|
||||
// FIXME: Text file has to have high bit set. (Should fit in with the text handling). Must have $8D at end.
|
||||
String content = getValidatedValue(options, STARTUP_CONTENT_FIELD, STARTUP_CONTENT_DEFAULT);
|
||||
content = String.join(":", content.split("[\r\n]")) + "\r";
|
||||
byte[] systembootContent = content.getBytes();
|
||||
for (int i = 0; i < systembootContent.length; i++) {
|
||||
if (systembootContent[i] == '\n') {
|
||||
systembootContent[i] = '\r';
|
||||
}
|
||||
systembootContent[i] = (byte)(systembootContent[i] | 0x80);
|
||||
}
|
||||
systemboot.setDataFork(DataBuffer.wrap(systembootContent));
|
||||
startup.setDataFork(DataBuffer.wrap(systembootContent));
|
||||
// Need to copy the entry to 0xF60 (track 0, sector F, offset 0x60)
|
||||
DataBuffer block = blockDevice.readBlock(15);
|
||||
block.put(0x60, startup.readEntry());
|
||||
blockDevice.writeBlock(15, block);
|
||||
return fileStore;
|
||||
}
|
||||
catch (IOException ex) {
|
||||
|
||||
@@ -39,6 +39,10 @@ import java.util.Set;
|
||||
/// ```
|
||||
/// ... yields a `$12AF` output.
|
||||
public class CharacterMapper {
|
||||
public static final CharacterMapper ANYTHING = CharacterMapper.builder()
|
||||
.mapRange(0x00, 0xff, false)
|
||||
.build();
|
||||
|
||||
private final String fromChars;
|
||||
private final String toChars;
|
||||
|
||||
@@ -71,12 +75,13 @@ public class CharacterMapper {
|
||||
private final StringBuilder toChars = new StringBuilder();
|
||||
|
||||
/// Add a range of characters with (optional) exclusions in the range.
|
||||
public Builder mapRange(char first, char last, boolean forceUppercase, char... excludedChars) {
|
||||
public Builder mapRange(int first, int last, boolean forceUppercase, char... excludedChars) {
|
||||
Set<Character> exclusions = new HashSet<>();
|
||||
for (char excludedChar : excludedChars) exclusions.add(excludedChar);
|
||||
|
||||
StringBuilder string = new StringBuilder();
|
||||
for (char ch = first; ch <= last; ch++) {
|
||||
for (int i = first; i <= last; i++) {
|
||||
char ch = (char) i;
|
||||
if (!exclusions.contains(ch)) {
|
||||
string.append(ch);
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ import org.applecommander.util.DataBuffer;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
@@ -72,7 +73,7 @@ public class GamedosTest implements GamedosConstants {
|
||||
@Test
|
||||
public void testCreateAndWrite() {
|
||||
// Create a disk
|
||||
GamedosFileStore fileStore = FileStores.get(GamedosFileStoreFactory.class).create(FileStoreOrganization.DISK_16SECTOR_DO);
|
||||
GamedosFileStore fileStore = FileStores.get(GamedosFileStoreFactory.class).create(FileStoreOrganization.DISK_16SECTOR_DO, Map.of());
|
||||
assertNotNull(fileStore);
|
||||
|
||||
// Get the root directory and verify there are no files
|
||||
@@ -128,7 +129,7 @@ public class GamedosTest implements GamedosConstants {
|
||||
@Test
|
||||
public void fillDirectoryEntries() {
|
||||
// Create a disk
|
||||
GamedosFileStore fileStore = FileStores.get(GamedosFileStoreFactory.class).create(FileStoreOrganization.DISK_16SECTOR_DO);
|
||||
GamedosFileStore fileStore = FileStores.get(GamedosFileStoreFactory.class).create(FileStoreOrganization.DISK_16SECTOR_DO, Map.of());
|
||||
assertNotNull(fileStore);
|
||||
|
||||
// Get the root directory
|
||||
@@ -159,7 +160,7 @@ public class GamedosTest implements GamedosConstants {
|
||||
@Test
|
||||
public void fillDisk() {
|
||||
// Create a disk
|
||||
GamedosFileStore fileStore = FileStores.get(GamedosFileStoreFactory.class).create(FileStoreOrganization.DISK_16SECTOR_DO);
|
||||
GamedosFileStore fileStore = FileStores.get(GamedosFileStoreFactory.class).create(FileStoreOrganization.DISK_16SECTOR_DO, Map.of());
|
||||
assertNotNull(fileStore);
|
||||
|
||||
// Get the root directory
|
||||
|
||||
@@ -29,19 +29,26 @@ import org.applecommander.usage.BlockUsage;
|
||||
import org.applecommander.util.DataBuffer;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class PascalTest implements PascalConstants {
|
||||
@Test
|
||||
public void testCreateAndWrite() {
|
||||
PascalFileStoreFactory factory = FileStores.get(PascalFileStoreFactory.class);
|
||||
var options = factory.getConfigurationOptions();
|
||||
options.get(PascalFileStoreFactory.VOLUME_NAME_FIELD).setValue("TESTVOL");
|
||||
|
||||
// Create a disk
|
||||
PascalFileStore fileStore = FileStores.get(PascalFileStoreFactory.class).create(FileStoreOrganization.DISK_16SECTOR_PO);
|
||||
PascalFileStore fileStore = FileStores.get(PascalFileStoreFactory.class).create(FileStoreOrganization.DISK_16SECTOR_PO, options);
|
||||
assertNotNull(fileStore);
|
||||
|
||||
// Get the root directory and verify there are no files
|
||||
PascalDirectory directory = fileStore.getRootDirectory();
|
||||
assertNotNull(directory);
|
||||
assertEquals(0, directory.getFiles().size());
|
||||
assertEquals("TESTVOL", directory.getName());
|
||||
|
||||
// Create and verify the first file.
|
||||
final byte[] textContents = "THIS IS A THE FILE DATA.".getBytes();
|
||||
@@ -91,7 +98,7 @@ public class PascalTest implements PascalConstants {
|
||||
@Test
|
||||
public void fillDirectoryEntries() {
|
||||
// Create a disk
|
||||
PascalFileStore fileStore = FileStores.get(PascalFileStoreFactory.class).create(FileStoreOrganization.DISK_16SECTOR_PO);
|
||||
PascalFileStore fileStore = FileStores.get(PascalFileStoreFactory.class).create(FileStoreOrganization.DISK_16SECTOR_PO, Map.of());
|
||||
assertNotNull(fileStore);
|
||||
|
||||
// Get the root directory
|
||||
@@ -121,7 +128,7 @@ public class PascalTest implements PascalConstants {
|
||||
@Test
|
||||
public void fillDisk() {
|
||||
// Create a disk
|
||||
PascalFileStore fileStore = FileStores.get(PascalFileStoreFactory.class).create(FileStoreOrganization.DISK_16SECTOR_PO);
|
||||
PascalFileStore fileStore = FileStores.get(PascalFileStoreFactory.class).create(FileStoreOrganization.DISK_16SECTOR_PO, Map.of());
|
||||
assertNotNull(fileStore);
|
||||
|
||||
// Get the root directory
|
||||
|
||||
@@ -30,13 +30,15 @@ import org.applecommander.usage.BlockUsage;
|
||||
import org.applecommander.util.DataBuffer;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class RDOSTest implements RDOSConstants {
|
||||
@Test
|
||||
public void testCreateAndWrite() {
|
||||
// Create a disk
|
||||
RDOSFileStore fileStore = FileStores.get(RDOSFileStoreFactory.class).create(FileStoreOrganization.DISK_16SECTOR_DO);
|
||||
RDOSFileStore fileStore = FileStores.get(RDOSFileStoreFactory.class).create(FileStoreOrganization.DISK_16SECTOR_DO, Map.of());
|
||||
assertNotNull(fileStore);
|
||||
|
||||
// Get the root directory and verify there are no files
|
||||
@@ -97,7 +99,7 @@ public class RDOSTest implements RDOSConstants {
|
||||
@Test
|
||||
public void fillDirectoryEntries() {
|
||||
// Create a disk
|
||||
RDOSFileStore fileStore = FileStores.get(RDOSFileStoreFactory.class).create(FileStoreOrganization.DISK_16SECTOR_DO);
|
||||
RDOSFileStore fileStore = FileStores.get(RDOSFileStoreFactory.class).create(FileStoreOrganization.DISK_16SECTOR_DO, Map.of());
|
||||
assertNotNull(fileStore);
|
||||
|
||||
// Get the root directory
|
||||
@@ -129,7 +131,7 @@ public class RDOSTest implements RDOSConstants {
|
||||
@Test
|
||||
public void fillDisk() {
|
||||
// Create a disk
|
||||
RDOSFileStore fileStore = FileStores.get(RDOSFileStoreFactory.class).create(FileStoreOrganization.DISK_16SECTOR_DO);
|
||||
RDOSFileStore fileStore = FileStores.get(RDOSFileStoreFactory.class).create(FileStoreOrganization.DISK_16SECTOR_DO, Map.of());
|
||||
assertNotNull(fileStore);
|
||||
|
||||
// Get the root directory
|
||||
|
||||
Reference in new issue
Block a user