📄 localdir.java
字号:
return; //System.exit(0); } dirEntry[i] = new DirEntry(files[i], this); if(dirEntry[i] == null) { System.out.println("\nskipping setDirList, dirEntry[i] is null!"); return; } if(dirEntry[i].file == null) { System.out.println("\nskipping setDirList, dirEntry[i].file is null!"); return; } if(perms != null) { dirEntry[i].setPermission(perms[i]); } if(fSize[i].startsWith("@")) { fSize[i] = fSize[i].substring(1); } dirEntry[i].setFileSize(Long.parseLong(fSize[i])); if(dirEntry[i].file.endsWith("/")) { dirEntry[i].setDirectory(); } else { dirEntry[i].setFile(); } jlm.addElement(dirEntry[i]); } } else { Log.debug("Not a directory: " + path); } } //System.out.println("length: "+dirEntry.length); } jl.setModel(jlm); } // 20011213:rb - Added logic for MSDOS style root dir /** * Change the directory of this connection and update the gui */ public boolean chdir(String p) { if(JFtp.remoteDir == null) { return false; } BasicConnection c = JFtp.remoteDir.getCon(); if((c != null) && (c instanceof FtpConnection)) { FtpConnection con = (FtpConnection) c; //con.setLocalPath(path); SaveSet s = new SaveSet(Settings.login_def, con.getHost(), con.getUsername(), con.getPassword(), Integer.toString(con.getPort()), con.getCachedPWD(), con.getLocalPath()); } if(con.chdirNoRefresh(p)) { path = con.getPWD(); if(con instanceof FilesystemConnection) { JFtp.remoteDir.getCon().setLocalPath(path); } pathChanged = true; gui(false); return true; } //Log.debug("CWD (local) : " + p); return false; } /** * Handles the user events if the ui is unlocked */ public void actionPerformed(ActionEvent e) { if(JFtp.uiBlocked) { return; } if(e.getActionCommand().equals("rm")) { lock(false); if(Settings.getAskToDelete()) { if(!UITool.askToDelete(this)) { unlock(false); return; } } for(int i = 0; i < length; i++) { if(dirEntry[i].selected) { con.removeFileOrDir(dirEntry[i].file); } } unlock(false); fresh(); } else if(e.getActionCommand().equals("mkdir")) { Creator c = new Creator("Create:", con); //fresh(); } else if(e.getActionCommand().equals("cmd")) { RemoteCommand rc = new RemoteCommand(); //fresh(); } else if(e.getActionCommand().equals("cd")) { String tmp = UITool.getPathFromDialog(path); chdir(tmp); } else if(e.getActionCommand().equals("fresh")) { fresh(); } else if(e.getActionCommand().equals("cp")) { Object[] o = jl.getSelectedValues(); if(o == null) { return; } String tmp = UITool.getPathFromDialog(path); if(tmp == null) { return; } if(!tmp.endsWith("/")) { tmp = tmp + "/"; } try { copy(o, path, "", tmp); //fresh(); Log.debug("Copy finished..."); } catch(Exception ex) { ex.printStackTrace(); Log.debug("Copy failed!"); } } else if(e.getActionCommand().equals("zip")) { try { Object[] entry = jl.getSelectedValues(); if(entry == null) { return; } String[] tmp = new String[entry.length]; for(int i = 0; i < tmp.length; i++) { tmp[i] = entry[i].toString(); } NameChooser n = new NameChooser(); String name = n.text.getText(); ZipFileCreator z = new ZipFileCreator(tmp, path, name); fresh(); } catch(Exception ex) { ex.printStackTrace(); } } else if(e.getActionCommand().equals("->")) { blockedTransfer(-2); } else if(e.getActionCommand().equals("<-")) { blockedTransfer(-2); } else if(e.getActionCommand().equals("rn")) { String target = jl.getSelectedValue().toString(); if(target == null) { return; } Renamer r = new Renamer(target, path); fresh(); } else if(e.getSource() == props) { JFtp.statusP.jftp.clearLog(); int x = currentPopup.getPermission(); String tmp; if(x == FtpConnection.R) { tmp = "read only"; } else if(x == FtpConnection.W) { tmp = "read/write"; } else if(x == FtpConnection.DENIED) { tmp = "denied"; } else { tmp = "undefined"; } String msg = "File: " + currentPopup.toString() + "\n" + " Size: " + currentPopup.getFileSize() + " raw size: " + currentPopup.getRawSize() + "\n" + " Symlink: " + currentPopup.isLink() + "\n" + " Directory: " + currentPopup.isDirectory() + "\n" + " Permission: " + tmp + "\n"; Log.debug(msg); } else if(e.getSource() == viewFile) { if(currentPopup.isDirectory()) { Log.debug("This is a directory, not a file."); return; } String url = JFtp.localDir.getPath() + currentPopup.toString(); showContentWindow(url, currentPopup); } else if(e.getSource() == sorter) { sortMode = (String) sorter.getSelectedItem(); fresh(); } else if(e.getActionCommand().equals("cdUp")) { chdir(".."); } } private void copy(Object[] fRaw, String path, String offset, String target) throws Exception { String[] files = new String[fRaw.length]; for(int j = 0; j < fRaw.length; j++) { files[j] = fRaw[j].toString(); } for(int i = 0; i < files.length; i++) { File f = new File(path + offset + files[i]); BufferedInputStream in = null; BufferedOutputStream out = null; byte[] buf = new byte[4096]; if(f.exists() && !f.isDirectory()) { in = new BufferedInputStream(new FileInputStream(path + offset + files[i])); out = new BufferedOutputStream(new FileOutputStream(target + offset + files[i])); int len = 0; while(in != null) { len = in.read(buf); if(len == StreamTokenizer.TT_EOF) { break; } out.write(buf, 0, len); } out.flush(); out.close(); } else if(f.exists()) { if(!files[i].endsWith("/")) { files[i] = files[i] + "/"; } File f2 = new File(target + offset + files[i]); if(!f.exists()) { f.mkdir(); } copy(f.list(), path, offset + files[i], target); } } } /** * Initiate a tranfer with ui locking enabled */ public synchronized void blockedTransfer(int index) { tmpindex = index; Runnable r = new Runnable() { public void run() { // --------------- local ------------------- boolean block = !Settings.getEnableMultiThreading(); if(!(con instanceof FtpConnection)) { block = true; } if(block || Settings.getNoUploadMultiThreading()) { lock(false); } transfer(tmpindex); if(block || Settings.getNoUploadMultiThreading()) { unlock(false); } //{ //JFtp.remoteDir.fresh(); //unlock(false); //} } }; Thread t = new Thread(r); t.start(); } /** * Lock the gui. */ public void lock(boolean first) { JFtp.uiBlocked = true; jl.setEnabled(false); if(!first) { JFtp.remoteDir.lock(true); } } /** * Unlock the gui. */ public void unlock(boolean first) { JFtp.uiBlocked = false; jl.setEnabled(true); if(!first) { JFtp.remoteDir.unlock(true); } } /** * Do a hard UI refresh - do no longer call this directly, use * safeUpdate() instead. */ public void fresh() { if(JFtp.mainFrame != null) { JFtp.mainFrame.setCursor(Cursor.WAIT_CURSOR); } String i = ""; int idx = jl.getSelectedIndex(); if(idx >= 0) { Object o = jl.getSelectedValue(); if(o != null) { i = o.toString(); } } chdir(path);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -