Skip to content
This repository has been archived by the owner on Sep 18, 2023. It is now read-only.

Commit

Permalink
1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Aqua47 authored Jan 12, 2023
1 parent 3a3f575 commit a2a8c68
Show file tree
Hide file tree
Showing 9 changed files with 246 additions and 189 deletions.
5 changes: 2 additions & 3 deletions src/mfm/main/Backup.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static void main(String min, boolean serv, String world) throws IOExcepti
txt = "color 2\n7z a MFMS\\backup\\.7z "+min+"\nexit";
}
else {
if (world == null || world.length() == 0) {
if (Tools.nothing(world)) {
Tools.available(min+"\\saves", false, true);
System.out.println();
System.out.println("Type the world or | all | to do all available");
Expand All @@ -21,8 +21,7 @@ public static void main(String min, boolean serv, String world) throws IOExcepti
if (world.matches("all|a")) {
world = "";
}
txt = "color 2\n7z a MFM\\backup\\"+world+".7z "+min+"\\saves\\"+world+"\nexit";
System.out.println(txt);
txt = "color 2\n\"C:\\Program Files\\7-Zip\\7z.exe\" a MFM\\backup\\"+world+".7z "+min+"\\saves\\"+world+"\nexit";
}
if (world != "0") {
Tools.write7z("temp\\7z_Backup.bat", txt);
Expand Down
60 changes: 54 additions & 6 deletions src/mfm/main/Delete.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package mfm.main;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Comparator;

import mfm.tools.*;

Expand All @@ -16,7 +21,7 @@ public static void main(String com, boolean serv) throws IOException {

//if no command enter a command

if (com == null || com.length() == 0) {
if (Tools.nothing(com)) {
Print.menuDelete(serv);
com = Tools.scan().toLowerCase();
}
Expand All @@ -26,23 +31,66 @@ public static void main(String com, boolean serv) throws IOException {
//command execution

if (com.matches("all|a")) {
Tools.deleteAll(mfms,null);
deleteAll(mfms,null);
}
else if (com.matches("1|ind|indexe|indexes")) {
Tools.deleteAll("MFM\\indexes",null);
Tools.available(mfms+"\\indexes", false, true);
String scan = Tools.scan();
if (scan.matches("a|all")) {
deleteAll(mfms+"\\indexes",null);
} else {
deleteAll(mfms+"\\indexes\\"+scan,null);
}
}
else if (com.matches("2|obj|object|objects")) {
Tools.deleteAll("MFM\\objects",null);
Tools.available(mfms+"\\objects", false, true);
String scan = Tools.scan();
if (scan.matches("a|all")) {
deleteAll(mfms+"\\objects",null);
} else {
deleteAll(mfms+"\\objects\\"+scan,null);
}
}
else if (com.matches("4|logs")) {
Tools.deleteAll(mfms+"\\logs",null);
deleteAll(mfms+"\\logs",null);
}
else if (com.matches("6|backup")) {
Tools.deleteAll(mfms+"\\backup",null);
Tools.available(mfms+"\\backup", false, true);
String scan = Tools.scan();
if (scan.matches("a|all")) {
deleteAll(mfms+"\\backup",null);
} else {
if (!scan.endsWith(".7z")) {
scan = scan+".7z";
}
deleteFile(mfms+"\\backup\\"+scan);
}
}
else {
System.out.println("not a valid command! Type (mfm help) for help!");
}
}
}

private static void deleteAll(String loc, String notThisOne) throws IOException {
Path dir = Paths.get(loc);
if (dir.toFile().exists()) {
Files.walk(dir)
.sorted(Comparator.reverseOrder())
.forEach(path -> {
if (notThisOne != path.toString()) { //check if path is complet so it works
try {
System.out.println("Deleting: " + path);
Files.delete(path);
} catch (IOException e) {
e.printStackTrace();
}
}
});
}
}

private static void deleteFile(String loc) throws IOException {
new File(loc).delete();
}
}
3 changes: 1 addition & 2 deletions src/mfm/main/Indexes.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class Indexes {
public static void main(String min, String ver) throws IOException {
new File("MFM\\indexes\\").mkdirs();
String[] pathnamesP1 = {};
if (ver == null || ver.length() == 0) {
if (Tools.nothing(ver)) {
pathnamesP1 = Tools.available(min+"\\assets\\indexes",true,true);
ver = Tools.scan();
}
Expand Down Expand Up @@ -70,6 +70,5 @@ public static void main(String min, String ver) throws IOException {
Print.time(startTime);
}
}
System.gc();
}
}
11 changes: 9 additions & 2 deletions src/mfm/main/Logs.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,8 @@ public static void main(String min, boolean serv) throws IOException, Interrupte
logNb++;
repeatLog--;
}
Print.timePlay(timeLog);
timePlay(timeLog);
Print.time(startTime);
System.gc();
}

private static String findTime (String line) {
Expand All @@ -73,4 +72,12 @@ private static int calcTime (String time) {
seconds = seconds+(minutes*60)+(hours*3600);
return seconds;
}

private static void timePlay(int timeLog) {
System.out.println("all seconds: "+timeLog);
int minutes = timeLog/60;
int hours = minutes/60;
int days = hours/24;
System.out.println("days:"+days+" hours:"+(hours-(days*60))+" minutes:"+(minutes-(hours*60))+" seconds:"+(timeLog-(minutes*60)));
}
}
3 changes: 1 addition & 2 deletions src/mfm/main/Objects.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class Objects {
public static void main(String min, String ver) throws IOException {
String fileOut = "";
String[] pathnamesP;
if (ver == null || ver.length() == 0) {
if (Tools.nothing(ver)) {
pathnamesP = Tools.available(min+"\\assets\\indexes",true,true);
ver = Tools.scan();
} else {
Expand Down Expand Up @@ -144,7 +144,6 @@ public static void main(String min, String ver) throws IOException {
lec.close();
System.out.println(verjson);
Print.time(startTime);
System.gc();
}
}
}
Expand Down
172 changes: 87 additions & 85 deletions src/mfm/main/Old.java
Original file line number Diff line number Diff line change
@@ -1,85 +1,87 @@
package mfm.main;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;

import mfm.tools.*;

public class Old {
public static void main(String min, String keep) throws IOException {
if (keep == null || keep.length() == 0) {
Tools.available(min+"\\versions",false,true);
System.out.println("Type the version you want to keep!");
keep = Tools.scan();
}

//if keep != 0...

long startTime = System.nanoTime();
Runtime.getRuntime().exec("explorer.exe /select,"+min+"\\versions\\"+keep);
if (keep.lastIndexOf(".") >= 3) {
keep = Tools.removeLast(keep,2);
}
Path indexe = Paths.get("MFM\\indexes\\"+keep+".json");
if (!Files.exists(indexe)) {
Indexes.main(min, keep);
}
Print.bar();
BufferedReader br = new BufferedReader(new FileReader("MFM\\indexes\\"+keep+".json"));
String line = "0";
ArrayList<String> lines = new ArrayList<String>();
ArrayList<String> folders = new ArrayList<String>();
ArrayList<String> sizeS = new ArrayList<String>();
boolean line1 = true;
int start = 0;
while ((line = br.readLine()) != null) {
if (line1 == false) {
start = line.indexOf("{")+10;
}
if (line1 == true) {
start = line.indexOf("{")+47;
line1 = false;
}
lines.add(line.substring(start,start+40));
folders.add(line.substring(start,start+2));
String sizeSt = line.substring(start+50,line.length()-2);
if (sizeSt.endsWith("}")) {
sizeSt = Tools.removeLast(sizeSt,1);
}
sizeS.add(sizeSt);
}
br.close();
String[] pathnames = {"0"};
File file = new File(min+"\\assets\\objects");
pathnames = file.list();
long bytes = 0;
for (String pathname : pathnames) {
String[] pathnames2 = {"0"};
File file2 = new File(min+"\\assets\\objects\\"+pathname);
pathnames2 = file2.list();
for (String pathname2 : pathnames2) {
File path2 = new File(file2+"\\"+pathname2);
int a1 = lines.indexOf(pathname2);
if (a1 == -1) {
Path path = Paths.get(file2+"\\"+pathname2);
try {
bytes += Files.size(path);
} catch (IOException e) {
e.printStackTrace();
}
path2.delete();
System.out.println(path2+" deleted");
}
}
}
System.gc();
Print.size(bytes);
Print.time(startTime);
}
}
package mfm.main;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;

import mfm.tools.*;

public class Old {
public static void main(String min, String keep) throws IOException {
if (Tools.nothing(keep)) {
Tools.available(min+"\\versions",false,true);
System.out.println("Type the version you want to keep!");
keep = Tools.scan();
}
if (keep != "0") { //do nothing if = 0
long startTime = System.nanoTime();
Runtime.getRuntime().exec("explorer.exe /select,"+min+"\\versions\\"+keep);
if (keep.lastIndexOf(".") >= 3) {
keep = Tools.removeLast(keep,2);
}
Path indexe = Paths.get("MFM\\indexes\\"+keep+".json");
if (!Files.exists(indexe)) {
Indexes.main(min, keep);
}
Print.bar();
BufferedReader br = new BufferedReader(new FileReader("MFM\\indexes\\"+keep+".json"));
String line = "0";
ArrayList<String> lines = new ArrayList<String>();
ArrayList<String> folders = new ArrayList<String>();
ArrayList<String> sizeS = new ArrayList<String>();
boolean line1 = true;
int start = 0;
while ((line = br.readLine()) != null) {
if (line1 == false) {
start = line.indexOf("{")+10;
}
if (line1 == true) {
start = line.indexOf("{")+47;
line1 = false;
}
lines.add(line.substring(start,start+40));
folders.add(line.substring(start,start+2));
String sizeSt = line.substring(start+50,line.length()-2);
if (sizeSt.endsWith("}")) {
sizeSt = Tools.removeLast(sizeSt,1);
}
sizeS.add(sizeSt);
}
br.close();
String[] pathnames = {"0"};
File file = new File(min+"\\assets\\objects");
pathnames = file.list();
long bytes = 0;
for (String pathname : pathnames) {
String[] pathnames2 = {"0"};
File file2 = new File(min+"\\assets\\objects\\"+pathname);
pathnames2 = file2.list();
for (String pathname2 : pathnames2) {
File path2 = new File(file2+"\\"+pathname2);
int a1 = lines.indexOf(pathname2);
if (a1 == -1) {
Path path = Paths.get(file2+"\\"+pathname2);
try {
bytes += Files.size(path);
} catch (IOException e) {
e.printStackTrace();
}
path2.delete();
System.out.println(path2+" deleted");
}
}
}
size(bytes);
Print.time(startTime);
}
}

private static void size(long bytes) {
System.out.println(bytes/1048576+" mo "+bytes/1024+" ko "+bytes+" o ");
}
}
Loading

0 comments on commit a2a8c68

Please sign in to comment.