⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 osrelativedmethods.java

📁 pso源程序
💻 JAVA
字号:
/**
 * Description: The os-relatived variables and methods.
 *
 * @ Author        Create/Modi     Note
 * Xiaofeng Xie    Oct. 24, 2002
 * Xiaofeng Xie    Apr. 12, 2003    xiaofengxie@tsinghua.org.cn
 *
 * @version 1.0
 */

package Global.system;

import java.io.*;
import java.net.*;

import Global.define.*;
import Global.methods.*;
import Global.system.io.*;

public class OSRelativedMethods {
  static public final String OS_WIN_KEY = "win";
  static public final String OS_LINUX_KEY = "linux";
  static public final String OS_UNIX_KEY = "unix";

  static public final String PROCESS_HANDLER_WIN = GlobalPath.LibPATH+BasicTag.FILE_SEP_TAG+"ToStart -w";
  static public final String PROCESS_HANDLER_UNIX = "";

  static public String getOSName() {
    return System.getProperty("os.name");
  }

  static public String getFirstHostName() {
    String hostName = getHostName();
    String[] names = GlobalString.tokenize(hostName, ".");
    return names[0];
  }

  static public String getHostName() {
    try {
      return InetAddress.getLocalHost().getHostName();
    } catch (Exception e) {
      return "";
    }
  }

  static public void copyDirectory(String src, String obj) throws Exception {
    String cmdLine = "";
    if(isInWindows()) {
      cmdLine = "xcopy /S /Q \""+src+"\" \""+obj+"\"";
    } else {
      cmdLine = "cp -Rf "+src+" "+(new File(obj).getParent());
    }
    ProcMethod.runAlienProcess(cmdLine);
  }

  static public String getDiskName(String absolutePath) {
    String osName = getOSName();
    if(osName.substring(0, 3).equalsIgnoreCase(OS_WIN_KEY)) {
      int colonIndex = absolutePath.indexOf(":");
      return absolutePath.substring(0, colonIndex+1)+BasicTag.RETURN_TAG;
    } else {
      return "";
    }
  }

  static public String getProcessHandlerName() {
    String osName = getOSName();
    if(osName.substring(0, 3).equalsIgnoreCase(OS_WIN_KEY)) {
      return PROCESS_HANDLER_WIN;
    } else {
      return PROCESS_HANDLER_UNIX;
    }
  }

  static public boolean isInWindows() {
    String osName = getOSName();
    return (osName.substring(0, 3).equalsIgnoreCase(OS_WIN_KEY));
  }

  static public String chmodToExec(String fileName) {
    if(!isInWindows()) {
      return "chmod +x "+fileName+BasicTag.RETURN_TAG;
    }
    return "";
  }

  static public String getTextEditorName() {
    String osName = getOSName();
    if(osName.substring(0, 3).equalsIgnoreCase(OS_WIN_KEY)) {
      return "notepad";
    } else {
      return "textedit";
    }
  }
  static public int createRunBatObj(String commandLine, boolean isPause) throws Exception {
    return createRunBatObj(commandLine, ".", isPause);
  }

  static public int createRunBatObj(String commandLine, String workPath, boolean isPause) throws Exception {
    return createRunBatObj(commandLine, workPath, null, isPause);
  }

  static public int createRunBatObj(String commandLine, String workPath, String logFileStr, boolean isPause) throws Exception {
    File newFilePath = new File(workPath);
    newFilePath.mkdirs();
    String batTxt = "";
    String diskName = getDiskName(newFilePath.getAbsolutePath());
    if(diskName!="") {
      batTxt += "@Echo off"+BasicTag.RETURN_TAG;
      batTxt +=diskName;
    }
    batTxt += "cd "+newFilePath.getPath()+BasicTag.RETURN_TAG;
    batTxt += commandLine;
    //***For log file***
    if(logFileStr!=null) {
      batTxt += " > "+logFileStr;
    }
    batTxt += BasicTag.RETURN_TAG;
    if (isPause) batTxt += "pause";

    File outputFile = GlobalFile.createTempFile("Run", SuffixTag.BAT_SUFFIX);
    GlobalFile.saveStringToFile(batTxt, outputFile.getAbsolutePath());
    int returnValue = ProcMethod.runAlienProcess(outputFile.getAbsolutePath());
    outputFile.deleteOnExit();
    return returnValue;
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -