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
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
{
ArrayList<String> lines = new ArrayList<String>();
File f1 = new File(hostsFileLocation);
FileReader fr = new FileReader(f1);
BufferedReader br = new BufferedReader(fr);
fr = new FileReader(f1);
br = new BufferedReader(fr);
String line = null;
boolean containmmm = false;
while ((line = br.readLine()) != null)
@ -36,59 +41,77 @@ class UnixHostReplacer implements HostReplacer {
fr.close();
br.close();
FileWriter fw = new FileWriter(f1);
BufferedWriter out = new BufferedWriter(fw);
fw = new FileWriter(f1);
out = new BufferedWriter(fw);
if (!containmmm) {
out.write(text);
}
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)
{
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
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
{
ArrayList<String> lines = new ArrayList<String>();
File f1 = new File(hostsFileLocation);
FileReader fr = new FileReader(f1);
BufferedReader br = new BufferedReader(fr);
fr = new FileReader(f1);
br = new BufferedReader(fr);
String line = null;
while ((line = br.readLine()) != null)
{
if (!line.contains(text))
if (!line.equals(text))
lines.add(line);
}
fr.close();
br.close();
FileWriter fw = new FileWriter(f1);
BufferedWriter out = new BufferedWriter(fw);
fw = new FileWriter(f1);
out = new BufferedWriter(fw);
for (int i = 0; i < lines.size(); 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)
{
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) {}
}
}
}