Fix /sub delete permission error on windows

This commit is contained in:
ME1312 2018-03-14 03:01:44 -04:00
parent bddbb692cd
commit bb7cfa9e57
28 changed files with 36 additions and 90 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1459,8 +1459,6 @@
</dd>
<dt><span class="memberNameLink"><a href="net/ME1312/SubServers/Host/Library/Log/Logger.html#message">message</a></span> - Variable in class net.ME1312.SubServers.Host.Library.Log.<a href="net/ME1312/SubServers/Host/Library/Log/Logger.html" title="class in net.ME1312.SubServers.Host.Library.Log">Logger</a></dt>
<dd>&nbsp;</dd>
<dt><span class="memberNameLink"><a href="net/ME1312/SubServers/Host/Network/Packet/PacketExDeleteServer.html#move-java.io.File-java.io.File-">move(File, File)</a></span> - Method in class net.ME1312.SubServers.Host.Network.Packet.<a href="net/ME1312/SubServers/Host/Network/Packet/PacketExDeleteServer.html" title="class in net.ME1312.SubServers.Host.Network.Packet">PacketExDeleteServer</a></dt>
<dd>&nbsp;</dd>
</dl>
<a name="I:N">
<!-- -->

View File

@ -17,7 +17,7 @@
catch(err) {
}
//-->
var methods = {"i0":10,"i1":10,"i2":10,"i3":10};
var methods = {"i0":10,"i1":10,"i2":10};
var tabs = {65535:["t0","All Methods"],2:["t2","Instance Methods"],8:["t4","Concrete Methods"]};
var altColor = "altColor";
var rowColor = "rowColor";
@ -177,11 +177,6 @@ implements <a href="../../../../../../net/ME1312/SubServers/Host/Network/PacketI
<div class="block">Get Packet Version</div>
</td>
</tr>
<tr id="i3" class="rowColor">
<td class="colFirst"><code>void</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../../net/ME1312/SubServers/Host/Network/Packet/PacketExDeleteServer.html#move-java.io.File-java.io.File-">move</a></span>(java.io.File&nbsp;from,
java.io.File&nbsp;to)</code>&nbsp;</td>
</tr>
</table>
<ul class="blockList">
<li class="blockList"><a name="methods.inherited.from.class.java.lang.Object">
@ -288,7 +283,7 @@ implements <a href="../../../../../../net/ME1312/SubServers/Host/Network/PacketI
<a name="getVersion--">
<!-- -->
</a>
<ul class="blockList">
<ul class="blockListLast">
<li class="blockList">
<h4>getVersion</h4>
<pre>public&nbsp;<a href="../../../../../../net/ME1312/SubServers/Host/Library/Version/Version.html" title="class in net.ME1312.SubServers.Host.Library.Version">Version</a>&nbsp;getVersion()</pre>
@ -304,16 +299,6 @@ implements <a href="../../../../../../net/ME1312/SubServers/Host/Network/PacketI
</dl>
</li>
</ul>
<a name="move-java.io.File-java.io.File-">
<!-- -->
</a>
<ul class="blockListLast">
<li class="blockList">
<h4>move</h4>
<pre>public&nbsp;void&nbsp;move(java.io.File&nbsp;from,
java.io.File&nbsp;to)</pre>
</li>
</ul>
</li>
</ul>
</li>

Binary file not shown.

Binary file not shown.

View File

@ -151,7 +151,8 @@ public class InternalHost extends Host {
else to.delete();
}
to.mkdirs();
Files.move(from, to);
Util.copyDirectory(from, to);
Util.deleteDirectory(from);
}
} catch (Exception e) {
e.printStackTrace();
@ -195,7 +196,8 @@ public class InternalHost extends Host {
else to.delete();
}
to.mkdirs();
Files.move(from, to);
Util.copyDirectory(from, to);
Util.deleteDirectory(from);
}
} catch (Exception e) {
e.printStackTrace();

View File

@ -387,47 +387,4 @@ public class InternalSubCreator extends SubCreator {
writer.write(content);
writer.close();
}
private void copyFolder(File source, File destination) {
if (source.isDirectory()) {
if (!destination.exists()) {
destination.mkdirs();
}
String files[] = source.list();
for (String file : files) {
File srcFile = new File(source, file);
File destFile = new File(destination, file);
copyFolder(srcFile, destFile);
}
} else {
InputStream in = null;
OutputStream out = null;
try {
in = new FileInputStream(source);
out = new FileOutputStream(destination);
byte[] buffer = new byte[1024];
int length;
while ((length = in.read(buffer)) > 0) {
out.write(buffer, 0, length);
}
} catch (Exception e) {
try {
in.close();
} catch (IOException e1) {
e1.printStackTrace();
}
try {
out.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
}
}

View File

@ -199,6 +199,9 @@ public final class Util {
while ((length = in.read(buffer)) > 0) {
out.write(buffer, 0, length);
}
in.close();
out.close();
} catch (Exception e) {
try {
if (in != null) in.close();

View File

@ -128,10 +128,10 @@ public class Version implements Serializable, Comparable<Version> {
/*
* The internal toString() method
* new Version(new Version("1.0.0"), VersionType.PRE_ALPHA, "7") would return:
* 5 1.0.0 0 7 9
* 5 1.0.0 0 7
*/
private String toInternalString() {
String str = type.id + ' ' + string + ' ' + '9';
String str = type.id + ' ' + string;
if (parent != null) str = parent.toInternalString()+' '+str;
return str;
}

View File

@ -138,7 +138,9 @@ public final class SubPlugin extends BungeeCord implements Listener {
try {
if (file.isDirectory()) {
if (new UniversalFile(dir, "Recently Deleted:" + file.getName() + ":info.json").exists()) {
JSONObject json = new JSONObject(Util.readAll(new FileReader(new UniversalFile(dir, "Recently Deleted:" + file.getName() + ":info.json"))));
FileReader reader = new FileReader(new UniversalFile(dir, "Recently Deleted:" + file.getName() + ":info.json"));
JSONObject json = new JSONObject(Util.readAll(reader));
reader.close();
if (json.keySet().contains("Timestamp")) {
if (TimeUnit.MILLISECONDS.toDays(Calendar.getInstance().getTime().getTime() - json.getLong("Timestamp")) >= 7) {
Util.deleteDirectory(file);

Binary file not shown.

View File

@ -195,6 +195,9 @@ public final class Util {
while ((length = in.read(buffer)) > 0) {
out.write(buffer, 0, length);
}
in.close();
out.close();
} catch (Exception e) {
try {
if (in != null) in.close();

View File

@ -128,10 +128,10 @@ public class Version implements Serializable, Comparable<Version> {
/*
* The internal toString() method
* new Version(new Version("1.0.0"), VersionType.PRE_ALPHA, "7") would return:
* 5 1.0.0 0 7 9
* 5 1.0.0 0 7
*/
private String toInternalString() {
String str = type.id + ' ' + string + ' ' + '9';
String str = type.id + ' ' + string;
if (parent != null) str = parent.toInternalString()+' '+str;
return str;
}

Binary file not shown.

View File

@ -126,7 +126,8 @@ public final class ExHost {
try {
if (file.isDirectory()) {
if (new UniversalFile(dir, "Recently Deleted:" + file.getName() + ":info.json").exists()) {
JSONObject json = new JSONObject(Util.readAll(new FileReader(new UniversalFile(dir, "Recently Deleted:" + file.getName() + ":info.json"))));
FileReader reader = new FileReader(new UniversalFile(dir, "Recently Deleted:" + file.getName() + ":info.json"));
JSONObject json = new JSONObject(Util.readAll(reader));
if (json.keySet().contains("Timestamp")) {
if (TimeUnit.MILLISECONDS.toDays(Calendar.getInstance().getTime().getTime() - json.getLong("Timestamp")) >= 7) {
Util.deleteDirectory(file);

View File

@ -402,7 +402,9 @@ public class SubCreator {
private void generateProperties(File dir, int port) throws IOException {
File file = new File(dir, "server.properties");
if (!file.exists()) file.createNewFile();
String content = Util.readAll(new BufferedReader(new InputStreamReader(new FileInputStream(file)))).replace("server-port=", "server-port=" + port).replace("server-ip=", "server-ip=" + host.config.get().getSection("Settings").getRawString("Server-Bind"));
FileInputStream is = new FileInputStream(file);
String content = Util.readAll(new BufferedReader(new InputStreamReader(is))).replace("server-port=", "server-port=" + port).replace("server-ip=", "server-ip=" + host.config.get().getSection("Settings").getRawString("Server-Bind"));
is.close();
file.delete();
PrintWriter writer = new PrintWriter(file, "UTF-8");
writer.write(content);

View File

@ -196,6 +196,9 @@ public final class Util {
while ((length = in.read(buffer)) > 0) {
out.write(buffer, 0, length);
}
in.close();
out.close();
} catch (Exception e) {
try {
if (in != null) in.close();

View File

@ -128,10 +128,10 @@ public class Version implements Serializable, Comparable<Version> {
/*
* The internal toString() method
* new Version(new Version("1.0.0"), VersionType.PRE_ALPHA, "7") would return:
* 5 1.0.0 0 7 9
* 5 1.0.0 0 7
*/
private String toInternalString() {
String str = type.id + ' ' + string + ' ' + '9';
String str = type.id + ' ' + string;
if (parent != null) str = parent.toInternalString()+' '+str;
return str;
}

View File

@ -87,7 +87,8 @@ public class PacketExDeleteServer implements PacketIn, PacketOut {
else to.delete();
}
to.mkdirs();
move(from, to);
Util.copyDirectory(from, to);
Util.deleteDirectory(from);
}
} catch (Exception e) {
e.printStackTrace();
@ -116,18 +117,4 @@ public class PacketExDeleteServer implements PacketIn, PacketOut {
public Version getVersion() {
return new Version("2.11.0a");
}
public void move(File from, File to) {
if (from.isDirectory()) {
to.mkdir();
for (File file : from.listFiles()) move(file, new File(to, file.getName()));
from.delete();
} else {
try {
Files.move(from.toPath(), to.toPath());
} catch (IOException e) {
e.printStackTrace();
}
}
}
}

Binary file not shown.

View File

@ -193,6 +193,9 @@ public final class Util {
while ((length = in.read(buffer)) > 0) {
out.write(buffer, 0, length);
}
in.close();
out.close();
} catch (Exception e) {
try {
if (in != null) in.close();

View File

@ -128,10 +128,10 @@ public class Version implements Serializable, Comparable<Version> {
/*
* The internal toString() method
* new Version(new Version("1.0.0"), VersionType.PRE_ALPHA, "7") would return:
* 5 1.0.0 0 7 9
* 5 1.0.0 0 7
*/
private String toInternalString() {
String str = type.id + ' ' + string + ' ' + '9';
String str = type.id + ' ' + string;
if (parent != null) str = parent.toInternalString()+' '+str;
return str;
}