mirror of
https://github.com/AppleCommander/AppleCommander.git
synced 2026-10-25 14:11:01 +00:00
Split Sources into one targeted to FormattedDisk (com.webcodepro.applecommander.storage) and one targeted to FileStore (org.applecommander.source).
This commit is contained in:
1 parent
0d4a2ae438
commit
db86b8dd59
19 files changed
+103
-20
No files matched your search
@@ -34,7 +34,7 @@ import org.apache.tools.ant.Task;
|
||||
import org.applecommander.image.DiskCopyImage;
|
||||
import org.applecommander.image.UniversalDiskImage;
|
||||
import org.applecommander.source.FileSource;
|
||||
import org.applecommander.source.Sources;
|
||||
import com.webcodepro.applecommander.storage.Sources;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
|
||||
@@ -49,7 +49,7 @@ import org.applecommander.hint.Hint;
|
||||
import org.applecommander.source.DataBufferSource;
|
||||
import org.applecommander.source.FileSource;
|
||||
import org.applecommander.source.Source;
|
||||
import org.applecommander.source.Sources;
|
||||
import com.webcodepro.applecommander.storage.Sources;
|
||||
import org.applecommander.util.BackupStrategy;
|
||||
import org.applecommander.util.Information;
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ import com.webcodepro.applecommander.storage.*;
|
||||
import com.webcodepro.applecommander.storage.os.prodos.ProdosFileEntry;
|
||||
import com.webcodepro.applecommander.ui.ac;
|
||||
import org.applecommander.source.Source;
|
||||
import org.applecommander.source.Sources;
|
||||
import com.webcodepro.applecommander.storage.Sources;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@@ -24,7 +24,7 @@ import com.webcodepro.applecommander.storage.Disks;
|
||||
import com.webcodepro.applecommander.storage.FormattedDisk;
|
||||
import io.github.applecommander.acx.base.ReusableCommandOptions;
|
||||
import org.applecommander.source.Source;
|
||||
import org.applecommander.source.Sources;
|
||||
import com.webcodepro.applecommander.storage.Sources;
|
||||
import org.applecommander.util.BackupStrategy;
|
||||
import picocli.CommandLine.Command;
|
||||
import picocli.CommandLine.Option;
|
||||
|
||||
+1
-1
@@ -36,7 +36,7 @@ import org.applecommander.os.dos.OzdosAdapterStrategy;
|
||||
import org.applecommander.os.dos.UnidosAdapterStrategy;
|
||||
import org.applecommander.source.DataBufferSource;
|
||||
import org.applecommander.source.Source;
|
||||
import org.applecommander.source.Sources;
|
||||
import com.webcodepro.applecommander.storage.Sources;
|
||||
import org.applecommander.util.BackupStrategy;
|
||||
import picocli.CommandLine.ArgGroup;
|
||||
import picocli.CommandLine.Command;
|
||||
|
||||
@@ -34,7 +34,7 @@ import io.github.applecommander.acx.base.ReusableCommandOptions;
|
||||
import org.applecommander.device.BlockDevice;
|
||||
import org.applecommander.device.TrackSectorDevice;
|
||||
import org.applecommander.source.Source;
|
||||
import org.applecommander.source.Sources;
|
||||
import com.webcodepro.applecommander.storage.Sources;
|
||||
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -23,7 +23,7 @@ import com.webcodepro.applecommander.storage.DiskFactory;
|
||||
import com.webcodepro.applecommander.storage.Disks;
|
||||
import com.webcodepro.applecommander.storage.FormattedDisk;
|
||||
import org.applecommander.source.Source;
|
||||
import org.applecommander.source.Sources;
|
||||
import com.webcodepro.applecommander.storage.Sources;
|
||||
import picocli.CommandLine.ITypeConverter;
|
||||
import picocli.CommandLine.TypeConversionException;
|
||||
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ package io.github.applecommander.acx.converter;
|
||||
import com.webcodepro.applecommander.storage.DiskFactory;
|
||||
import com.webcodepro.applecommander.storage.Disks;
|
||||
import org.applecommander.source.Source;
|
||||
import org.applecommander.source.Sources;
|
||||
import com.webcodepro.applecommander.storage.Sources;
|
||||
import picocli.CommandLine.ITypeConverter;
|
||||
import picocli.CommandLine.TypeConversionException;
|
||||
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* AppleCommander - An Apple ][ image utility.
|
||||
* Copyright (C) 2025 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 com.webcodepro.applecommander.storage;
|
||||
|
||||
import org.applecommander.source.Source;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/// Sources is a hook into the Source discovery and construction logic.
|
||||
/// Note that this is the LEGACY Sources interface. It will unwrap a SHK/SDK into
|
||||
/// a disk image instead of delivering a `ShrinkitFileStore`. Use the Sources class
|
||||
/// in the `org.applecommander.source` package if making a `FileStore`.
|
||||
public class Sources {
|
||||
private static final List<Source.Factory> FACTORIES;
|
||||
static {
|
||||
FACTORIES = new ArrayList<>();
|
||||
for (Source.Factory factory : ServiceLoader.load(Source.Factory.class)) {
|
||||
FACTORIES.add(factory);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This call is a shim for the AntTask to populate its known factories since ServiceLoader
|
||||
* doesn't appear to work within the Ant classpath.
|
||||
*/
|
||||
public static void setFactories(Source.Factory... factories) {
|
||||
FACTORIES.clear();
|
||||
FACTORIES.addAll(Arrays.asList(factories));
|
||||
}
|
||||
|
||||
/**
|
||||
* Standardized Source creation. Uses the ServiceLoader mechanism to identify
|
||||
* all potential Source factories. Note that this supports a Source being
|
||||
* passed as well (which ensures any wrapping layers are added, such as 2IMG
|
||||
* or DiskCopy).
|
||||
*/
|
||||
public static Optional<Source> create(Object object) {
|
||||
// First: Create source from a generalized object (thus, can be Path, Entry, URL, etc)
|
||||
Optional<Source> source = Optional.empty();
|
||||
if (object instanceof Source objSource) {
|
||||
source = Optional.of(objSource);
|
||||
}
|
||||
else {
|
||||
for (Source.Factory factory : FACTORIES) {
|
||||
source = factory.fromObject(object);
|
||||
if (source.isPresent()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Second: Once we have a source, run a pass again, checking if there is a wrapper we need (2IMG, DiskCopy, etc)
|
||||
if (source.isPresent()) {
|
||||
for (Source.Factory factory : FACTORIES) {
|
||||
Optional<Source> fromSource = factory.fromSource(source.get());
|
||||
if (fromSource.isPresent()) {
|
||||
return fromSource;
|
||||
}
|
||||
}
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -35,7 +35,7 @@ import org.apache.commons.csv.CSVPrinter;
|
||||
import org.applecommander.device.BlockDevice;
|
||||
import org.applecommander.device.TrackSectorDevice;
|
||||
import org.applecommander.source.Source;
|
||||
import org.applecommander.source.Sources;
|
||||
import com.webcodepro.applecommander.storage.Sources;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ package com.webcodepro.applecommander.util.filestreamer;
|
||||
import com.webcodepro.applecommander.storage.*;
|
||||
import com.webcodepro.applecommander.util.GlobGenerator;
|
||||
import org.applecommander.source.Source;
|
||||
import org.applecommander.source.Sources;
|
||||
import com.webcodepro.applecommander.storage.Sources;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -32,15 +32,15 @@ import java.util.Optional;
|
||||
* Source and Factory for an archive or disk in AppleCommander.
|
||||
* <p/>
|
||||
* Typical usage:
|
||||
* {@snippet lang=java:
|
||||
* Optional<Source> sourceOpt = Sources.create(Path.of(filename));
|
||||
* {@snippet lang = java:
|
||||
* import com.webcodepro.applecommander.storage.Sources;Optional<Source> sourceOpt = Sources.create(Path.of(filename));
|
||||
* if (sourceOpt.isPresent()) {
|
||||
* // do something with sourceOpt.get()
|
||||
* System.out.println(sourceOpt.get().getSize());
|
||||
* }
|
||||
* }
|
||||
* // Only happens if the initiating object is not understood
|
||||
* throw new RuntimeException("Unable to create image source");
|
||||
* }
|
||||
*}
|
||||
*/
|
||||
public interface Source extends CapabilityProvider, HintProvider, Container {
|
||||
int getSize();
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
*/
|
||||
package org.applecommander.source;
|
||||
|
||||
import com.webcodepro.applecommander.storage.ShrinkitSourceFactory;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
@@ -29,6 +31,9 @@ public class Sources {
|
||||
static {
|
||||
FACTORIES = new ArrayList<>();
|
||||
for (Source.Factory factory : ServiceLoader.load(Source.Factory.class)) {
|
||||
if (factory instanceof ShrinkitSourceFactory) {
|
||||
continue;
|
||||
}
|
||||
FACTORIES.add(factory);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@ import org.applecommander.filestore.FileEntry;
|
||||
import org.applecommander.filestore.FileStore;
|
||||
import org.applecommander.filestore.FileStoreTestHelper;
|
||||
import org.applecommander.source.Source;
|
||||
import org.applecommander.source.Sources;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -23,7 +23,6 @@ import com.webcodepro.applecommander.storage.FormattedDisk.DiskUsage;
|
||||
import com.webcodepro.applecommander.storage.filters.*;
|
||||
import com.webcodepro.applecommander.testconfig.TestConfig;
|
||||
import org.applecommander.source.Source;
|
||||
import org.applecommander.source.Sources;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@ package com.webcodepro.applecommander.util.filestreamer;
|
||||
|
||||
import com.webcodepro.applecommander.storage.*;
|
||||
import org.applecommander.source.Source;
|
||||
import org.applecommander.source.Sources;
|
||||
import com.webcodepro.applecommander.storage.Sources;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
+1
-1
@@ -52,7 +52,7 @@ import org.applecommander.os.DiskCheck;
|
||||
import org.applecommander.os.DiskOptimizer;
|
||||
import org.applecommander.source.DataBufferSource;
|
||||
import org.applecommander.source.Source;
|
||||
import org.applecommander.source.Sources;
|
||||
import com.webcodepro.applecommander.storage.Sources;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.custom.CTabFolder;
|
||||
import org.eclipse.swt.custom.CTabItem;
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ import com.webcodepro.applecommander.ui.swt.wizard.diskimage.DiskImageWizard;
|
||||
import com.webcodepro.applecommander.util.Host;
|
||||
import com.webcodepro.applecommander.util.TextBundle;
|
||||
import org.applecommander.source.Source;
|
||||
import org.applecommander.source.Sources;
|
||||
import com.webcodepro.applecommander.storage.Sources;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.DisposeEvent;
|
||||
import org.eclipse.swt.events.SelectionAdapter;
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ import com.webcodepro.applecommander.ui.UiBundle;
|
||||
import com.webcodepro.applecommander.ui.swt.wizard.WizardPane;
|
||||
import com.webcodepro.applecommander.util.TextBundle;
|
||||
import org.applecommander.source.Source;
|
||||
import org.applecommander.source.Sources;
|
||||
import com.webcodepro.applecommander.storage.Sources;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
|
||||
Reference in new issue
Block a user