Skip to content

Commit

Permalink
added OpenAs command
Browse files Browse the repository at this point in the history
code refactor
  • Loading branch information
trol73 committed Jul 9, 2018
1 parent 30e4086 commit 9712a9b
Show file tree
Hide file tree
Showing 95 changed files with 789 additions and 669 deletions.
1 change: 1 addition & 0 deletions res/runtime/dictionary.properties
Expand Up @@ -387,6 +387,7 @@ EjectDrive.label = Eject drive
EjectDrive.tooltip = Safely remove drive
file_menu = File
file_menu.open_with = Open with
file_menu.open_as = Open as
mark_menu = Mark
view_menu = View
view_menu.show_hide_columns = Show/Hide columns
Expand Down
1 change: 1 addition & 0 deletions res/runtime/dictionary_ru_RU.properties
Expand Up @@ -372,6 +372,7 @@ FocusPrevious.label = Перейти к предыдущему компонен
FocusNext.label = Перейти к следующему компоненту
file_menu = Файл
file_menu.open_with = Открыть с помощью
file_menu.open_as = Open как
mark_menu = Выделение
view_menu = Вид
view_menu.show_hide_columns = Показать/скрыть столбцы
Expand Down
6 changes: 3 additions & 3 deletions src/main/com/mucommander/TrolCommander.java
Expand Up @@ -767,7 +767,7 @@ public boolean execute(LauncherTask task, boolean force) {
*/
@SuppressWarnings({"unchecked"})
public static void main(String args[]) throws IOException {
if (OsFamily.getCurrent() == OsFamily.MAC_OS_X) {
if (OsFamily.MAC_OS_X.isCurrent()) {
System.setProperty("com.apple.mrj.application.apple.menu.about.name", "trolCommander");
// disable openGL in javaFX (used for HtmlViewer) as it cashes JVM under vmWare
System.setProperty("prism.order", "sw");
Expand Down Expand Up @@ -821,7 +821,7 @@ public static void main(String args[]) throws IOException {
LauncherTask taskRegisterArchives = new RegisterArchiveProtocolsTask(helper);
LauncherTask taskRegisterNetwork = new RegisterNetworkProtocolsTask(helper);
LauncherTask taskRegisterOtherProtocols = new RegisterOtherProtocolsTask(helper);
LauncherTask taskLoadEnviroment = new LoadEnvironmentTask(helper);
LauncherTask taskLoadEnvironment = new LoadEnvironmentTask(helper);

List<LauncherTask> tasks = new LinkedList<>();
// tasks.add(taskPrepareLogger);
Expand Down Expand Up @@ -853,7 +853,7 @@ public static void main(String args[]) throws IOException {
tasks.add(taskRegisterArchives);
tasks.add(taskRegisterNetwork);
tasks.add(taskRegisterOtherProtocols);
tasks.add(taskLoadEnviroment);
tasks.add(taskLoadEnvironment);
//System.out.println("Execute tasks");

if (processors <= 1 ) {
Expand Down
8 changes: 5 additions & 3 deletions src/main/com/mucommander/adb/AdbUtils.java
Expand Up @@ -93,7 +93,8 @@ private static AbstractFile getAdbPath() {
path = null;
}
if (path != null) {
AbstractFile result = FileFactory.getFile(path + (OsFamily.getCurrent() == OsFamily.WINDOWS ? "\\platform-tools\\adb.exe" : "/platform-tools/adb"));
String adb = path + (OsFamily.WINDOWS .isCurrent() ? "\\platform-tools\\adb.exe" : "/platform-tools/adb");
AbstractFile result = FileFactory.getFile(adb);
if (result != null && result.exists() && !result.isDirectory()) {
return result.getParent();
}
Expand All @@ -104,12 +105,13 @@ private static AbstractFile getAdbPath() {
path = null;
}
if (path != null) {
AbstractFile result = FileFactory.getFile(path + (OsFamily.getCurrent() == OsFamily.WINDOWS ? "\\adb.exe" : "/adb"));
String adb = path + (OsFamily.getCurrent() == OsFamily.WINDOWS ? "\\adb.exe" : "/adb");
AbstractFile result = FileFactory.getFile(adb);
if (result != null && result.exists() && !result.isDirectory()) {
return result.getParent();
}
}
if (OsFamily.getCurrent() == OsFamily.MAC_OS_X) {
if (OsFamily.MAC_OS_X.isCurrent()) {
String defaultPath = System.getProperty("user.home") + "/Library/Android/sdk/platform-tools/adb";
AbstractFile result = FileFactory.getFile(defaultPath);
if (result != null && result.exists() && !result.isDirectory()) {
Expand Down
103 changes: 62 additions & 41 deletions src/main/com/mucommander/cache/WindowsStorage.java
Expand Up @@ -40,7 +40,7 @@ public class WindowsStorage {
public static class Record {
public final int left, top, width, height;

public Record(String s) {
Record(String s) {
String[] val = s.split(",");
this.left = Integer.parseInt(val[0].trim());
this.top = Integer.parseInt(val[1].trim());
Expand All @@ -60,7 +60,7 @@ public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj == null || !(obj instanceof Record)) {
if (!(obj instanceof Record)) {
return false;
}
Record rec = (Record)obj;
Expand All @@ -77,7 +77,7 @@ public void apply(Window window) {
window.setSize(width, height);
}

public void applyPos(Window window) {
void applyPos(Window window) {
window.setLocation(left, top);
}
}
Expand Down Expand Up @@ -171,56 +171,77 @@ private Map<String, Record> getRecords() {


private void load(AbstractFile file) throws IOException {
BufferedReader reader = null;
try {
reader = new BufferedReader(new InputStreamReader(file.getInputStream()));
try (BufferedReader reader = new BufferedReader(new InputStreamReader(file.getInputStream()))) {
String line;
while ( (line = reader.readLine() ) != null) {
line = line.trim();
if (line.isEmpty() || line.startsWith("#")) {
continue;
}
int index = line.indexOf('=');
if (index < 0) {
continue;
}
String key = line.substring(0, index);
String val = line.substring(index + 1);
try {
records.put(key, new Record(val));
} catch (Exception e) {
e.printStackTrace();
}
while ((line = reader.readLine()) != null) {
loadRecord(line.trim());
}
}
// BufferedReader reader = null;
// try {
// reader = new BufferedReader(new InputStreamReader(file.getInputStream()));
// String line;
// while ( (line = reader.readLine() ) != null) {
// line = line.trim();
// if (line.isEmpty() || line.startsWith("#")) {
// continue;
// }
// int index = line.indexOf('=');
// if (index < 0) {
// continue;
// }
// String key = line.substring(0, index);
// String val = line.substring(index + 1);
// try {
// records.put(key, new Record(val));
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
// } catch (Exception e) {
// e.printStackTrace();
// } finally {
// if (reader != null) {
// reader.close();
// }
// }
}

private void loadRecord(String line) {
if (line.isEmpty() || line.startsWith("#")) {
return;
}
int index = line.indexOf('=');
if (index < 0) {
return;
}
String key = line.substring(0, index);
String val = line.substring(index + 1);
try {
records.put(key, new Record(val));
} catch (Exception e) {
e.printStackTrace();
} finally {
if (reader != null) {
reader.close();
}
}
}

private void save(AbstractFile file) throws IOException {
BufferedWriter writer = null;
try {
writer = new BufferedWriter(new OutputStreamWriter(file.getOutputStream()));
for (String key : records.keySet()) {
if (key == null) {
continue;

private void save(AbstractFile file) throws IOException {
try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(file.getOutputStream()))) {
for (String key : getRecords().keySet()) {
if (key != null) {
saveRecord(writer, key, records.get(key));
}
writer.write(key);
writer.write('=');
writer.write(records.get(key).toString());
writer.write('\n');
}
} finally {
if (writer != null) {
writer.close();
}
}
}

private void saveRecord(Writer writer, String key, Record record) throws IOException {
writer.write(key);
writer.write('=');
writer.write(record.toString());
writer.write('\n');
}

/**
* Returns the path to the history file.
* <p>
Expand Down
2 changes: 1 addition & 1 deletion src/main/com/mucommander/commons/DummyDecoratedFile.java
Expand Up @@ -17,7 +17,7 @@ public class DummyDecoratedFile extends DummyFile {

static {
String prefix = "file://" + FileURL.LOCALHOST;
LOCAL_FILE_PREFIX = OsFamily.getCurrent().equals(OsFamily.WINDOWS) ? prefix + '/' : prefix;
LOCAL_FILE_PREFIX = OsFamily.WINDOWS.isCurrent() ? prefix + '/' : prefix;
}

public DummyDecoratedFile(FileURL url) {
Expand Down
12 changes: 10 additions & 2 deletions src/main/com/mucommander/commons/file/FileFactory.java
Expand Up @@ -712,15 +712,23 @@ public static AbstractFile wrapArchive(AbstractFile file) throws IOException {
// the filename contains a dot '.' character, since most of the time this method is called with a filename that
// doesn't match any of the filters.
if (filename.indexOf('.') >= 0) {
ArchiveFormatProvider provider;
if ((provider = getArchiveFormatProvider(filename)) != null) {
ArchiveFormatProvider provider = getArchiveFormatProvider(filename);
if (provider != null) {
return provider.getFile(file);
}
}

return file;
}

/**
* Same as wrapArchive(AbstractFile) but using the given extension rather than the file's extension.
*/
public static AbstractFile wrapArchive(AbstractFile file, String extension) throws IOException {
ArchiveFormatProvider provider = getArchiveFormatProvider(file.getBaseName() + extension);
return provider != null ? provider.getFile(file) : file;
}


/**
* Returns the default {@link com.mucommander.commons.file.icon.FileIconProvider} instance. The default provider class
Expand Down
5 changes: 3 additions & 2 deletions src/main/com/mucommander/commons/file/FileURL.java
Expand Up @@ -866,7 +866,7 @@ public boolean portEquals(FileURL url) {
* @return <code>true</code> if the path of this URL and the given URL are equal
*/
public boolean pathEquals(FileURL url) {
boolean isCaseSensitiveOS = !(OsFamily.getCurrent().equals(OsFamily.WINDOWS) || OsFamily.getCurrent().equals(OsFamily.OS_2));
boolean isCaseSensitiveOS = !(OsFamily.WINDOWS.isCurrent() || OsFamily.OS_2.isCurrent());

String path1 = isCaseSensitiveOS ? this.getPath() : this.getPath().toLowerCase();
String path2 = isCaseSensitiveOS ? url.getPath() : url.getPath().toLowerCase();
Expand Down Expand Up @@ -1014,8 +1014,9 @@ public boolean equals(Object o) {
* @return true if both FileURL instances are equal
*/
public boolean equals(Object o, boolean compareCredentials, boolean compareProperties) {
if (o == null || !(o instanceof FileURL))
if (!(o instanceof FileURL)) {
return false;
}

FileURL url = (FileURL)o;

Expand Down
Expand Up @@ -28,7 +28,7 @@
public class MountedDriveFilter extends AbstractFileFilter {
@Override
public boolean accept(AbstractFile file) {
if (file == null || OsFamily.getCurrent() != OsFamily.MAC_OS_X) {
if (file == null || !OsFamily.MAC_OS_X.isCurrent()) {
return false;
}
for (AbstractFile f : LocalFile.getVolumes() ) {
Expand Down
Expand Up @@ -80,7 +80,7 @@ private static String buildCommandLine(AvrdudeConfiguration config, Operation op
if (config.avrdudeLocation != null) {
cmd = config.avrdudeLocation;
} else {
cmd = OsFamily.getCurrent() == OsFamily.WINDOWS ? "avrdude.exe" : "avrdude";
cmd = OsFamily.WINDOWS.isCurrent() ? "avrdude.exe" : "avrdude";
}
cmd += " -p " + config.deviceName;
if (config.baudrate != null) {
Expand Down
10 changes: 8 additions & 2 deletions src/main/com/mucommander/commons/runtime/OsVersion.java
Expand Up @@ -111,7 +111,10 @@ public enum OsVersion implements ComparableRuntimeProperty {
MAC_OS_X_10_11("10.11"),

/** Mac OS X 10.12 (Sierra) */
MAC_OS_X_10_12("10.12");
MAC_OS_X_10_12("10.12"),

/** Mac OS X 10.13 (High Sierra) */
MAC_OS_X_10_13("10.13");



Expand Down Expand Up @@ -208,6 +211,9 @@ static OsVersion parseSystemProperty(String osVersionProp, String osNameProp, Os
}
// Mac OS X versions
if (osFamily == OsFamily.MAC_OS_X) {
if (osVersionProp.startsWith("10.13"))
return MAC_OS_X_10_13;

if (osVersionProp.startsWith("10.12"))
return MAC_OS_X_10_12;

Expand Down Expand Up @@ -248,7 +254,7 @@ static OsVersion parseSystemProperty(String osVersionProp, String osNameProp, Os
return MAC_OS_X_10_0;

// Newer version we don't know of yet, assume latest supported OS version
return MAC_OS_X_10_12;
return MAC_OS_X_10_13;
}

return OsVersion.UNKNOWN_VERSION;
Expand Down
4 changes: 2 additions & 2 deletions src/main/com/mucommander/desktop/DefaultDesktopAdapter.java
Expand Up @@ -146,7 +146,7 @@ public String getDefaultShell() {


private String getDefaultShellPath() {
if (OsFamily.getCurrent() == OsFamily.WINDOWS) {
if (OsFamily.WINDOWS.isCurrent()) {
return "cmd.exe";
}
if (defaultShell == null) {
Expand All @@ -165,7 +165,7 @@ private String getDefaultShellPath() {

public String getDefaultTerminalShellCommand() {
String path = getDefaultShellPath();
if (OsFamily.getCurrent() != OsFamily.WINDOWS) {
if (!OsFamily.WINDOWS.isCurrent()) {
return path + " --login";
}
return path;
Expand Down
Expand Up @@ -44,7 +44,7 @@ public String toString() {

@Override
public boolean isAvailable() {
return OsFamily.getCurrent().equals(OsFamily.MAC_OS_X);
return OsFamily.MAC_OS_X.isCurrent();
}

@Override
Expand Down
Expand Up @@ -42,7 +42,7 @@ public void init(boolean install) throws DesktopInitialisationException {

@Override
public boolean isAvailable() {
return OsFamily.getCurrent().equals(OsFamily.WINDOWS);
return OsFamily.WINDOWS.isCurrent();
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/main/com/mucommander/job/FindFileJob.java
Expand Up @@ -161,8 +161,7 @@ public void setup(String fileMask, String fileContent, boolean searchSubdirs, bo
this.searchSubdirectories = searchSubdirs;
this.searchArchives = searchArchives;
this.ignoreHidden = ignoreHidden;
IOCase filterCase = OsFamily.getCurrent() == OsFamily.MAC_OS_X || OsFamily.getCurrent() == OsFamily.WINDOWS ?
IOCase.INSENSITIVE : IOCase.SENSITIVE;
IOCase filterCase = OsFamily.MAC_OS_X.isCurrent() || OsFamily.WINDOWS.isCurrent() ? IOCase.INSENSITIVE : IOCase.SENSITIVE;

if (fileMask.contains(",")) {
String masks[] = fileMask.split(",");
Expand Down
4 changes: 2 additions & 2 deletions src/main/com/mucommander/job/MakeDirectoryFileJob.java
Expand Up @@ -156,7 +156,7 @@ protected boolean processFile(AbstractFile file, Object recurseParams) {
boolean needAdminPermissions = e instanceof FileAccessDeniedException;
int action;
if (needAdminPermissions && !mkfileMode) {
if (OsFamily.getCurrent() == OsFamily.MAC_OS_X) {
if (OsFamily.MAC_OS_X.isCurrent()) {
if (!mkfileMode) {
tryMkDirAsAdministrator(file.getAbsolutePath(), null);
}
Expand Down Expand Up @@ -196,7 +196,7 @@ protected boolean processFile(AbstractFile file, Object recurseParams) {
}

private void tryMkDirAsAdministrator(String path, String password) {
if (OsFamily.getCurrent() == OsFamily.MAC_OS_X) {
if (OsFamily.MAC_OS_X.isCurrent()) {
AppleScript.execute("do shell script \"mkdir -p + '" + path + "' \" with administrator privileges", new StringBuilder());
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/com/mucommander/tools/FileMergeTool.java
Expand Up @@ -27,7 +27,7 @@ public class FileMergeTool extends ExternalTool {

@Override
public boolean isActive() {
return OsFamily.getCurrent() == OsFamily.MAC_OS_X;
return OsFamily.MAC_OS_X.isCurrent();
}

@Override
Expand Down

0 comments on commit 9712a9b

Please sign in to comment.