fix for windows

This commit is contained in:
sirjonasxx 2018-06-20 19:10:58 +02:00
parent 2b9c553c9c
commit a0638d4da1
2 changed files with 52 additions and 18 deletions

11
G-Earth.iml Normal file
View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -16,14 +16,19 @@ class UnixHostReplacer implements HostReplacer {
@Override @Override
public void addRedirect(String original, String redirect) { public void addRedirect(String original, String redirect) {
String text = redirect + " " + original; String text = redirect + " " + original + "\t# G-Earth replacement";
FileReader fr = null;
BufferedReader br = null;
FileWriter fw = null;
BufferedWriter out = null;
try try
{ {
ArrayList<String> lines = new ArrayList<String>(); ArrayList<String> lines = new ArrayList<String>();
File f1 = new File(hostsFileLocation); File f1 = new File(hostsFileLocation);
FileReader fr = new FileReader(f1); fr = new FileReader(f1);
BufferedReader br = new BufferedReader(fr); br = new BufferedReader(fr);
String line = null; String line = null;
boolean containmmm = false; boolean containmmm = false;
while ((line = br.readLine()) != null) while ((line = br.readLine()) != null)
@ -36,59 +41,77 @@ class UnixHostReplacer implements HostReplacer {
fr.close(); fr.close();
br.close(); br.close();
FileWriter fw = new FileWriter(f1); fw = new FileWriter(f1);
BufferedWriter out = new BufferedWriter(fw); out = new BufferedWriter(fw);
if (!containmmm) { if (!containmmm) {
out.write(text); out.write(text);
} }
for (int i = 0; i < lines.size(); i++) { for (int i = 0; i < lines.size(); i++) {
out.write("\n"+ lines.get(i)); out.write(System.getProperty("line.separator")+ lines.get(i));
} }
out.flush();
out.close();
} }
catch (Exception ex) catch (Exception ex)
{ {
ex.printStackTrace(); ex.printStackTrace();
} }
finally {
try {
if (fr != null) fr.close();
if (br != null) br.close();
if (fw != null) fw.close();
if (out != null) out.close();
}
catch (Exception e) {}
}
} }
@Override @Override
public void removeRedirect(String original, String redirect) { public void removeRedirect(String original, String redirect) {
String text = redirect + " " + original; String text = redirect + " " + original + "\t# G-Earth replacement";
FileReader fr = null;
BufferedReader br = null;
FileWriter fw = null;
BufferedWriter out = null;
try try
{ {
ArrayList<String> lines = new ArrayList<String>(); ArrayList<String> lines = new ArrayList<String>();
File f1 = new File(hostsFileLocation); File f1 = new File(hostsFileLocation);
FileReader fr = new FileReader(f1); fr = new FileReader(f1);
BufferedReader br = new BufferedReader(fr); br = new BufferedReader(fr);
String line = null; String line = null;
while ((line = br.readLine()) != null) while ((line = br.readLine()) != null)
{ {
if (!line.contains(text)) if (!line.equals(text))
lines.add(line); lines.add(line);
} }
fr.close(); fr.close();
br.close(); br.close();
FileWriter fw = new FileWriter(f1); fw = new FileWriter(f1);
BufferedWriter out = new BufferedWriter(fw); out = new BufferedWriter(fw);
for (int i = 0; i < lines.size(); i++) { for (int i = 0; i < lines.size(); i++) {
out.write(lines.get(i)); out.write(lines.get(i));
if (i != lines.size() - 1) out.write("\n"); if (i != lines.size() - 1) out.write(System.getProperty("line.separator"));
} }
out.flush();
out.close();
} }
catch (Exception ex) catch (Exception ex)
{ {
ex.printStackTrace(); ex.printStackTrace();
} }
finally {
try {
if (fr != null) fr.close();
if (br != null) br.close();
if (fw != null) fw.close();
if (out != null) out.close();
}
catch (Exception e) {}
}
} }
} }