提交 765e5687 编写于 作者: C chenjianqiang

区分盘符

上级 6270df93
......@@ -16,16 +16,16 @@ import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.*;
import java.util.List;
import java.util.StringJoiner;
import java.util.stream.Collectors;
public class HostsFrame {
//页面数据
//--系统环境是linux?
private Boolean linuxIs;
//--文件名和文件路径Map
private Map<String, String> fileNameAndPathMap;
//页面组件
//--主面板
......@@ -68,8 +68,8 @@ public class HostsFrame {
String hosts = parseHostsFileAndPath(oldFileName);
FileUtils.writeInFile(hosts, content.toString());
//更新文件名
if(!oldFileName.equals(newFileName)){
FileUtils.singleChange(new File(hosts),new File(parseHostsFileAndPath(newFileName)));
if (!oldFileName.equals(newFileName)) {
FileUtils.singleChange(new File(hosts), new File(parseHostsFileAndPath(newFileName)));
}
});
btn_other_save.addActionListener(eventE -> {
......@@ -239,16 +239,10 @@ public class HostsFrame {
* @return 文件路径文件名称
*/
private String parseHostsFileAndPath(String fileName) {
String hostFileLocation;
if (fileName == null) {
fileName = "hosts";
}
if (linuxIs) {
hostFileLocation = "/etc/";
} else {
hostFileLocation = System.getenv("windir") + "\\system32\\drivers\\etc\\";
}
return hostFileLocation.concat(fileName);
return fileNameAndPathMap.get(fileName);
}
/**
......@@ -319,6 +313,7 @@ public class HostsFrame {
* @return 符合条件的文件列表
*/
private String[] findHostNameList() {
fileNameAndPathMap = new HashMap<>(100);
List<String> collect = parseFiles(parseHostsPath());
if (!linuxIs) {
collect.addAll(parseFiles(HostsConstant.Systems.WIN_D_DIR_AREA_LOCATION));
......@@ -341,8 +336,8 @@ public class HostsFrame {
.map(File::getName)
.filter(f -> StringUtils.isNotBlank(f)
&& f.startsWith(HostsConstant.Systems.MAIN_HOSTS_FILE_NAME)
&& !f.endsWith(HostsConstant.Systems.MAIN_HOSTS_FILE_NAME_NOT_SHOW)
)
&& !f.endsWith(HostsConstant.Systems.MAIN_HOSTS_FILE_NAME_NOT_SHOW))
.peek(p -> fileNameAndPathMap.put(p, hostLocation.concat("\\" + p)))
.collect(Collectors.toList());
}
}
......
......@@ -24,7 +24,7 @@
<depends>com.intellij.modules.platform</depends>
<extensions defaultExtensionNs="com.intellij">
<toolWindow id="Hosts" anchor="right" factoryClass="com.lishihe.hosts.factory.ToolWindowsFactory"
<toolWindow id="Hosts" anchor="bottom" factoryClass="com.lishihe.hosts.factory.ToolWindowsFactory"
secondary="true" canCloseContents="false"/>
</extensions>
</idea-plugin>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册